cells = {
const uniform =
Math.abs(
d3.polygonArea([
[3 + width / 2, 3],
[width - 3, 3],
[width - 3, height - 3],
[3, height - 3]
])
) / points.length;
for (let t = 0; t < 2000; t++) {
const cells = powerDiagram(points);
for (let i = 0; i < cells.length; i++) {
const c = cells[i];
c.area = Math.abs(d3.polygonArea(c));
}
const minA = cells.length === points.length;
const A = d3.median(points, d => d[2]);
for (let i = 0; i < points.length; i++) points[i][2] += 1000;
for (let i = 0; i < cells.length; i++) {
const c = cells[i],
p = c.site.originalObject;
p.cell = c;
p[2] = (p[2] - 1000 - A) * 0.5;
p.stress = Math.log(c.area / uniform);
p[2] -= 400 * p.stress;
const [x, y] = d3.polygonCentroid([...c]);
if (isFinite(x) && isFinite(y)) {
p.centroid = [x, y];
const dx = x - p[0],
dy = y - p[1];
p[0] += dx * 0.6;
p[1] += dy * 0.6;
mutable debug = { t, points, centroid: [x, y] };
} else {
mutable debug = p;
}
}
chart.plot();
yield;
if (!running) return yield d3.polygonArea(cells[9]);
}
}