function quadTreeCircleGenerator(maxRadius, padding,x0, x1, y0, y1) {
const quadtree = d3.quadtree()
.extent([[x0,y0],[x1,y1]])
const searchRadius = maxRadius * 2;
function f(k) {
var bestX, bestY, bestDistance = 0;
for (let i = 0; i < k; ++i) {
const x = (x1 - x0) * Math.random() + x0;
const y = (y1 - y0) * Math.random() + y0;
const xmin = x - searchRadius;
const xmax = x + searchRadius;
const ymin = y - searchRadius;
const ymax = y + searchRadius;
var minDistance = maxRadius;
quadtree.visit((node, x1, y1, x2, y2) => {
if (!node.length) {
var p = node.data;
var dsquared = distanceSquared(x, y, p[0], p[1]);
if (dsquared < p[2] * p[2] ) return minDistance = 0, true;
var d = Math.sqrt(dsquared) - p[2];
if (d < minDistance) minDistance = d;
}
return !minDistance || x1 >= xmax || x2 <= xmin || y1 >= ymax || y2 <= ymin;
});
if ((minDistance > bestDistance) && (minDistance > 0)) {
bestX = x;
bestY = y;
bestDistance = minDistance;
}
}
const best = [bestX, bestY, bestDistance]
quadtree.add(best)
return best;
}
f.quadtree = quadtree;
return f;
}