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

convenience delaunay.edges() function? #135

Open Fil opened 2 years ago

Fil commented 2 years ago

Currently to get a list of all edges (say to reproduce "links" in d3-voronoi) you need to write something like:

{
  const { halfedges, triangles, hull } = d3.Delaunay.from(points);
  return [
    ...Array.from(hull, (i, k) => [i, hull[(k + 1) % hull.length]]),
    ...Array.from(halfedges, (i, j) => i > j ? [[triangles[i], triangles[j]]] : []).flat()
  ].map(([i, j]) => ({ source: points[i], target: points[j] }));
}

What about making this into a convenience method delaunay.edges:

  [
    ...Array.from(hull, (i, k) => [i, hull[(k + 1) % hull.length]]),
    ...Array.from(halfedges, (i, j) => i > j ? [[triangles[i], triangles[j]]] : []).flat()
  ];