Registry / data / delaunator

delaunator

JSON →
library1.0.4jsnpmunverified

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.

npm install delaunator
INSTALL
IMPORT
SIG · DELAUNATOR
D
delaunator
datajavascriptv1.0.4
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Delaunator
import Delaunator from 'delaunator';
const Delaunator = require('delaunator');
Since v5.0.0, Delaunator is an ES Module by default, requiring Node.js v12+ or a module-aware bundler. CommonJS `require` will fail unless transpiled or configured.
Delaunator.from
import Delaunator from 'delaunator'; const points = [[0, 0], [1, 1]]; const delaunay = Delaunator.from(points);
import { from } from 'delaunator';
`from` is a static method on the default export `Delaunator`, not a named export itself.
Delaunator (type)
import type Delaunator from 'delaunator';
import { Delaunator } from 'delaunator';
For TypeScript, `Delaunator` is a default export for both value and type. Using `import type` is preferred for type-only imports. Since v5.1.0, `@types/delaunator` is no longer needed.

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); }
Debug
Known issues
breakingDelaunator now exposes itself as an ES Module by default (`"type": "module"`), which means CommonJS `require()` is no longer directly supported. This requires Node.js v12+ or a compatible build setup.
fix
Use `import Delaunator from 'delaunator';` for ESM environments. For older Node.js or CommonJS projects, you might need to transpile your code or configure your bundler to handle ESM dependencies.
affects: >=5.0.0
breakingTranspilation of the library itself has been removed. This means native support for older browsers like IE11 is no longer provided out-of-the-box. Consumers needing support for such environments must transpile `delaunator` in their build process.
fix
Configure your build tools (e.g., Babel) to transpile `node_modules/delaunator` if you need to support environments without modern JavaScript features.
affects: >=5.0.0
breakingThe `delaunay.hull` API changed from a linked list structure to a `Uint32Array` of point indices. While previously undocumented, downstream libraries like `d3-delaunay` depended on the old structure, making this a breaking change for some users.
fix
Access convex hull points as an ordered array of indices, `delaunay.hull`, instead of attempting to traverse a linked list structure. Update any code that iterated through `hull` via `.next` properties.
affects: >=3.0.1
deprecatedFirst-class TypeScript types are now shipped directly with the `delaunator` package, rendering the separate `@types/delaunator` package obsolete and unnecessary.
fix
Uninstall `@types/delaunator` from your project (`npm uninstall @types/delaunator` or `yarn remove @types/delaunator`). The types are now automatically included when you install `delaunator` itself.
affects: >=5.1.0
gotchaThe input coordinate format differs between the constructor `new Delaunator(coords)` (which expects a flat array `[x0, y0, x1, y1, ...]`) and the static factory method `Delaunator.from(points)` (which expects an array of arrays `[[x0, y0], [x1, y1], ...]`). Using the wrong format will lead to incorrect triangulations or errors.
fix
Ensure you are using the correct input format for the method you choose. For `new Delaunator()`, provide a flat array or `Float64Array`. For `Delaunator.from()`, provide an array of point arrays, or customize with `getX` and `getY` accessors.
affects: always
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to use CommonJS `require()` syntax in an ES Module environment (e.g., Node.js with `"type": "module"` in `package.json`) after Delaunator v5.0.0.
fix
Change your import statement to `import Delaunator from 'delaunator';`. Ensure your project is set up to handle ES Modules, or use a bundler if targeting older environments.
SyntaxError: Cannot use import statement outside a module
Attempting to use an ES Module `import` statement in a CommonJS context (e.g., Node.js without `"type": "module"` or an old browser script tag).
fix
For Node.js, add `"type": "module"` to your `package.json`. For browsers, use a bundler (like Webpack or Rollup) to transpile to a compatible format, or load via `<script type="module">` for modern browsers, or use the UMD build (`<script src="https://unpkg.com/delaunator/delaunator.min.js"></script>`).
TypeError: delaunay.hull.next is not a function
Using code that expects the pre-v3.0.1 linked-list `hull` API with Delaunator v3.0.1 or later, where `hull` became a `Uint32Array`.
fix
Update your code to iterate over `delaunay.hull` as a `Uint32Array` of point indices instead of traversing a linked list. E.g., `for (const i of delaunay.hull) { /* ... */ }`.
TS2307: Cannot find module 'delaunator' or its corresponding type declarations.
TypeScript compiler cannot find type definitions for `delaunator`. This could happen if `@types/delaunator` is missing in versions prior to 5.1.0, or if TypeScript configuration is incorrect.
fix
If using Delaunator < 5.1.0, install `@types/delaunator` (`npm install -D @types/delaunator`). If using v5.1.0+, ensure `@types/delaunator` is uninstalled and your `tsconfig.json` `moduleResolution` is set appropriately (e.g., `"node16"` or `"bundler"`).
Upgrade
Version history
1.0.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
10
OpenAI (training)
1
Resources