mst = (delaunay, score = euclidean2) => {
const { points, triangles } = delaunay;
const set = new Uint8Array(points.length / 2);
const tree = new Set();
const heap = [];
const bisect = bisector(([v]) => -v).left;
function heap_insert(x, v) {
heap.splice(bisect(heap, -v), 0, [v, x]);
}
function heap_pop() {
return heap.length && heap.pop()[1];
}
set[0] = 1;
for (const i of delaunay.neighbors(0)) {
heap_insert([0, i], score(points, 0, i));
}
let edge;
while ((edge = heap_pop())) {
const [i, j] = edge;
if (set[j]) continue;
set[j] = 1;
tree.add(`${[i, j].sort()}`);
for (const k of delaunay.neighbors(j)) {
if (set[k]) continue;
heap_insert([j, k], score(points, j, k));
}
}
return (i) => {
const a = triangles[i];
const b = triangles[i % 3 === 2 ? i - 2 : i + 1];
return tree.has(`${[a, b].sort()}`);
};
}