Published
Edited
Jun 24, 2019
3 forks
51 stars
Insert cell
Insert cell
Insert cell
{
replay;
const {triangles, halfedges} = delaunay;
const queue = new FlatQueue();
const onEdge = new Uint8Array(halfedges.length);
const visited = new Uint8Array(points.length);
function addToQueue(i) {
onEdge[i] = 1;
visited[triangles[i]] = 1;

const p0 = points[triangles[i]];
const p1 = points[triangles[i % 3 === 2 ? i - 2 : i + 1]];
const r = circumcircles.r[i];
const x = circumcircles.x[i];
const y = circumcircles.y[i];
const [x0, y0] = p0;
const [x1, y1] = p1;

const area = (y - y0) * (x1 - x) - (x - x0) * (y1 - y);
const cx = (x0 + x1) / 2;
const cy = (y0 + y1) / 2;
const d = Math.sqrt(Math.pow(cx - x, 2) + Math.pow(cy - y, 2));
// if the center of a circumcircle on the edge lies outside the advancing polygon,
// or inside but less than 0.2 circumradiuses away from the edge, queue it for collapsing
if (area >= 0 || d / r < 0.2)
queue.push(i, -r);
}
for (let i = 0; i < halfedges.length; i++) {
if (halfedges[i] === -1) addToQueue(i); // start with convex hull edges
}
const ctx = DOM.context2d(width, height);

yield draw(ctx, queue, onEdge);
while (true) {
await Promises.delay(100);
const i = queue.pop();
if (i === undefined) break;
const i1 = halfedges[i % 3 === 2 ? i - 2 : i + 1];
const i2 = halfedges[i % 3 === 0 ? i + 2 : i - 1];
if (!visited[triangles[i1]] && i1 !== -1) {
addToQueue(i1);
addToQueue(i2);
onEdge[i] = 0;
}
yield draw(ctx, queue, onEdge);
}
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more