d3-delaunay

repository·main·Indexed 20 days ago

https://github.com/d3/d3-delaunay

A high-performance JavaScript library for computing Voronoi diagrams from 2D points, built upon the Delaunator Delaunay triangulation engine. It provides the Delaunay class for computing triangulations and spatial queries, and the Voronoi class for generating clipped Voronoi diagrams.

Tokens
388
Snippets
2
Records
3
Agent score
21%

What's inside d3-delaunay

  1. Overview of d3-delaunay

    main
    d3-delaunay is a high-performance JavaScript library used to compute the Voronoi diagram of a set of two-dimensional points. It leverages the Delaunator library to perform fast Delaunay triangulation using sweep algorithms, then constructs the Voronoi diagram by connecting the circumcenters of adjacent triangles.
  2. Create a Voronoi diagram with Voronoi

    main

    The Voronoi class is used to compute Voronoi diagrams. It is typically instantiated from an existing Delaunay triangulation. You can define the bounding box for the diagram to ensure cells are clipped correctly.

    import { Delaunay, Voronoi } from "d3-delaunay";
    
    const points = [[0, 0], [1, 0], [0, 1]];
    const delaunay = Delaunay.from(points);
    const voronoi = Voronoi.from(delaunay).extent([[0, 0], [1, 1]]);
  3. Create a Delaunay triangulation with Delaunay

    main

    The Delaunay class is the primary entrypoint for computing Delaunay triangulations. It takes an array of points (typically an array of arrays, e.g., [[x0, y0], [x1, y1], ...]) and computes the triangulation. It provides methods for spatial queries, finding neighbors, and generating Voronoi diagrams.

    import { Delaunay } from "d3-delaunay";
    
    const points = [[0, 0], [1, 0], [0, 1]];
    const delaunay = Delaunay.from(points);