in packages/charts/src/utils/d3-delaunay/index.ts [866:926]
_init() {
const {
delaunay: { points, hull, triangles },
vectors,
} = this;
// Compute circumcenters.
const circumcenters = (this.circumcenters = this._circumcenters.subarray(0, (triangles.length / 3) * 2));
for (let i = 0, j = 0, n = triangles.length, x, y; i < n; i += 3, j += 2) {
const t1 = triangles[i] * 2;
const t2 = triangles[i + 1] * 2;
const t3 = triangles[i + 2] * 2;
const x1 = points[t1];
const y1 = points[t1 + 1];
const x2 = points[t2];
const y2 = points[t2 + 1];
const x3 = points[t3];
const y3 = points[t3 + 1];
const dx = x2 - x1;
const dy = y2 - y1;
const ex = x3 - x1;
const ey = y3 - y1;
const bl = dx * dx + dy * dy;
const cl = ex * ex + ey * ey;
const ab = (dx * ey - dy * ex) * 2;
if (!ab) {
// degenerate case (collinear diagram)
x = (x1 + x3) / 2 - 1e8 * ey;
y = (y1 + y3) / 2 + 1e8 * ex;
} else if (Math.abs(ab) < 1e-8) {
// almost equal points (degenerate triangle)
x = (x1 + x3) / 2;
y = (y1 + y3) / 2;
} else {
const d = 1 / ab;
x = x1 + (ey * bl - dy * cl) * d;
y = y1 + (dx * cl - ex * bl) * d;
}
circumcenters[j] = x;
circumcenters[j + 1] = y;
}
// Compute exterior cell rays.
let h = hull[hull.length - 1];
let p0,
p1 = h * 4;
let x0,
x1 = points[2 * h];
let y0,
y1 = points[2 * h + 1];
vectors.fill(0);
for (let i = 0; i < hull.length; ++i) {
h = hull[i];
(p0 = p1), (x0 = x1), (y0 = y1);
(p1 = h * 4), (x1 = points[2 * h]), (y1 = points[2 * h + 1]);
vectors[p0 + 2] = vectors[p1] = y0 - y1;
vectors[p0 + 3] = vectors[p1 + 1] = x1 - x0;
}
}