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

voronoi.update? #74

Closed mbostock closed 5 years ago

mbostock commented 5 years ago

How is delaunay.update supposed to interact with delaunay.voronoi? I assume you are expected to call delaunay.voronoi again after calling delaunay.update, but it’d be nice if there were an equivalent voronoi.update method.

mourner commented 5 years ago

Yeah, adding an update method would allow us to avoid repeated allocation of these two arrays:

https://github.com/d3/d3-delaunay/blob/86be03cbd6ddab360bb441402900fb4956375b09/src/voronoi.js#L8-L9

triangles may slightly vary from update to update, but is close to the max (2 * numPoints - 5), so we could do the same trick as Delaunator — allocate a maximum length circumcenters array as a private property and then expose a trimmed one as voronoi.circumcenters, referencing the same memory (with subarray).

mbostock commented 5 years ago

Works great! ❤️

https://observablehq.com/@mbostock/meandering-voronoi