Published
Edited
Mar 14, 2022
1 fork
Importers
25 stars
Also listed in…
Algorithms
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
polygon = d3.json(
`https://raw.githubusercontent.com/LingDong-/interesting-polygon-archive/master/json/${poly}.json`
)
Insert cell
positions = polygon.flat(1)
Insert cell
constrains = {
let z = 0;
return polygon
.map(function(ring, i) {
const c = ring.map((d, i) => [z + i, z + ((i + 1) % ring.length)]);
z += ring.length;
return c;
})
.flat();
}
Insert cell
constrained = {
const del = d3.Delaunay.from(positions);
const con = new Constrainautor(del._delaunator);

con.constrainAll(constrains);
return del;
}
Insert cell
function holedPolygonContains(polygon, c) {
return (
d3.polygonContains(polygon[0], c) &&
!polygon.slice(1).some(ring => d3.polygonContains(ring, c))
);
}
Insert cell
d3 = require("d3@7")
Insert cell
Constrainautor = require("@kninnug/constrainautor")
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