Public
Edited
Feb 10, 2024
Insert cell
Insert cell
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
purgedPoints = purgeSolo(points)
Insert cell
function purgeSolo(pts) {
let ptSource = pts;
let points = [];

let found = true;

while (found) {
found = false;
points = [];

ptSource.forEach((p) => {
if (p.connected.length > 1) {
points.push(p);
} else {
found = true;
}
});
ptSource = points;
}

return points;
}
Insert cell
Insert cell
delaunay = genDelaunay()
Insert cell
hull = (delaunay) => {
const { hull, triangles } = delaunay;
const s = new Set(hull);
return (i) => {
const a = triangles[i];
if (!s.has(a)) return false;
const j = hull.indexOf(a);
const b = triangles[i % 3 === 2 ? i - 2 : i + 1];
return hull[(j + 1) % hull.length] === b;
};
}
Insert cell
function* urquhartEdges(delaunay, score = euclidean2) {
const { halfedges, triangles } = delaunay;
const n = triangles.length;
const removed = new Uint8Array(n);
for (let e = 0; e < n; e += 3) {
const p0 = triangles[e],
p1 = triangles[e + 1],
p2 = triangles[e + 2];
const p01 = score(p0, p1),
p12 = score(p1, p2),
p20 = score(p2, p0);
removed[
p20 > p01 && p20 > p12
? Math.max(e + 2, halfedges[e + 2])
: p12 > p01 && p12 > p20
? Math.max(e + 1, halfedges[e + 1])
: Math.max(e, halfedges[e])
] = 1;
}
for (let e = 0; e < n; ++e) {
if (e > halfedges[e] && !removed[e])
yield [triangles[e], triangles[e % 3 === 2 ? e - 2 : e + 1]];
}
}
Insert cell
function euclidean2(i, j) {
return (
(delaunay.points[i * 2] - delaunay.points[j * 2]) ** 2 +
(delaunay.points[i * 2 + 1] - delaunay.points[j * 2 + 1]) ** 2
);
}
Insert cell
genDelaunay=() => d3.Delaunay.from(
Array.from(pick2d(800, 800, 100, "normal"), (d) => d.map((x) => x + 20))
)
Insert cell
height = 800
Insert cell
width = 800
Insert cell
d3 = require("d3-delaunay@5")
Insert cell
import { pick2d } from "@fil/2d-point-distributions"
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more