function makeDots(polygon, numPoints, options) {
options = Object.assign({
maxIterations: numPoints * 50,
distance: null,
edgeDistance: options.distance
},options);
numPoints = Math.floor(numPoints)
let xMin = Infinity,
yMin = Infinity,
xMax = -Infinity,
yMax = -Infinity
polygon.forEach(p => {
if (p[0]<xMin) xMin = p[0]
if (p[0]>xMax) xMax = p[0]
if (p[1]<yMin) yMin = p[1]
if (p[1]>yMax) yMax = p[1]
});
let width = xMax - xMin
let height = yMax - yMin
options.distance = options.distance || Math.min(width, height) / numPoints / 4
options.edgeDistance = options.edgeDistance || options.distance
let points = [];
outer:
for (let i=0; i<options.maxIterations; i++) {
let p = [xMin + Math.random() * width, yMin + Math.random() * height]
if (d3.polygonContains(polygon, p)) {
for (let j=0; j<points.length; j++) {
let dx = p[0]-points[j][0],
dy = p[1]-points[j][1]
if (Math.sqrt(dx*dx+dy*dy) < options.distance) continue outer;
}
for (let j=0; j<polygon.length-1; j++) {
if (distPointEdge(p, polygon[j], polygon[j+1]) < options.edgeDistance) continue outer;
}
points.push(p);
if (points.length == numPoints) break;
}
}
points.complete = (points.length >= numPoints)
return points
}