Delaunator

5.1.0 · active · verified Sun Apr 19

Delaunator is an incredibly fast and robust JavaScript library designed for generating Delaunay triangulations of 2D points. Currently stable at version 5.1.0, it maintains an active release cadence, consistently delivering performance enhancements and numerical robustness. A key differentiator is its exceptional speed, validated through extensive benchmarks, and its ability to handle degenerate floating-point inputs reliably by integrating `robust-predicates`. It serves as a foundational component for other critical computational geometry libraries like `d3-delaunay` and `d3-geo-voronoi`, extending its utility to Voronoi diagrams and geographic applications. As of v5.0.0, it transitioned to ES Modules by default, necessitating Node.js v12+ environments, and v5.1.0 introduced first-class TypeScript types, making the separate `@types/delaunator` package obsolete.

Common errors

Warnings

Install

Imports

Quickstart

This example initializes Delaunator with a flat array of coordinates and logs the resulting triangle, half-edge, and convex hull indices, demonstrating basic usage.

import Delaunator from 'delaunator';

const coords = new Float64Array([
    377, 479, 453, 434, 326, 387, 444, 359, 511, 389,
    586, 429, 470, 315, 622, 493, 627, 367, 570, 314
]);

const delaunay = new Delaunator(coords);

console.log('Triangle vertex indices:', delaunay.triangles);
console.log('Half-edge indices for traversal:', delaunay.halfedges);
console.log('Convex hull point indices (counter-clockwise):', delaunay.hull);

// Example: Retrieve the coordinates of the first triangle
if (delaunay.triangles.length >= 3) {
    const i0 = delaunay.triangles[0];
    const i1 = delaunay.triangles[1];
    const i2 = delaunay.triangles[2];
    const triangleCoords = [
        [coords[2 * i0], coords[2 * i0 + 1]],
        [coords[2 * i1], coords[2 * i1 + 1]],
        [coords[2 * i2], coords[2 * i2 + 1]]
    ];
    console.log('Coordinates of the first triangle:', triangleCoords);
}

view raw JSON →