d3-delaunay icon indicating copy to clipboard operation
d3-delaunay copied to clipboard

convenience delaunay.edges() function?

Open Fil opened this issue 3 years ago • 0 comments

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()
  ];

Fil avatar May 29 '22 09:05 Fil