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

Incorrect size for `voronoi.circumcenters` array. #103

Closed vchizhov closed 4 years ago

vchizhov commented 4 years ago

The circumcenters array is allocated as: Float64Array(delaunay.points.length * 2);. Instead the size should be based on the number of triangles. Note that the number of triangles may be as high as 2*vertex_count - 5, which far exceeds delaunay.points.length (the multiplication by 2 in the allocation is for the (x,y) coordinates so that's not the 2 factor that we are looking for).

mourner commented 4 years ago

The delaunay.points array is also interleaved x, y, so its length is also double the vertex count, evening things out. I agree this might look a little unintuitive in the code though.

vchizhov commented 4 years ago

@mourner So point.length is not the point count but instead 2 * point_count? Then I guess it should work. It's still probably better to just plug in the number of triangles there - would take less memory, and it will be more obvious that this is not a bug.