d3 / d3-delaunay

Compute the Voronoi diagram of a set of two-dimensional points.
https://d3js.org/d3-delaunay
ISC License
611 stars 57 forks source link

Iterate over each voronoi lines #91

Closed Allakazan closed 5 years ago

Allakazan commented 5 years ago

I'm making a procedural street pattern with Delaunay, and using voronoi.cellPolygons() to get each polygon. But this give me duplicated lines.

There's a way to iterate over each line separately ? Thanks !

mbostock commented 5 years ago

There is no method for iterating over the edges, but you can use voronoi.render to render all of the edges as a mesh, and you can look at the source if you want to access the edges directly yourself.

https://github.com/d3/d3-delaunay/blob/b7df1f24b5817e03fce0178c3e8174ca70f23be6/src/voronoi.js#L75-L101

Fil commented 5 years ago

This notebook might clarify how this can be done: https://observablehq.com/d/045ae1b3e80973dc

Fil commented 5 years ago

A much simpler method is to use voronoi.render().split(/M/).slice(1) https://observablehq.com/d/58f6cc721fa26757