{"id":10730,"library":"delaunator","title":"Delaunator","description":"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.","status":"active","version":"5.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/mapbox/delaunator","tags":["javascript","delaunay triangulation","computational geometry","algorithms","typescript"],"install":[{"cmd":"npm install delaunator","lang":"bash","label":"npm"},{"cmd":"yarn add delaunator","lang":"bash","label":"yarn"},{"cmd":"pnpm add delaunator","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"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.","wrong":"const Delaunator = require('delaunator');","symbol":"Delaunator","correct":"import Delaunator from 'delaunator';"},{"note":"`from` is a static method on the default export `Delaunator`, not a named export itself.","wrong":"import { from } from 'delaunator';","symbol":"Delaunator.from","correct":"import Delaunator from 'delaunator';\nconst points = [[0, 0], [1, 1]];\nconst delaunay = Delaunator.from(points);"},{"note":"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.","wrong":"import { Delaunator } from 'delaunator';","symbol":"Delaunator (type)","correct":"import type Delaunator from 'delaunator';"}],"quickstart":{"code":"import Delaunator from 'delaunator';\n\nconst coords = new Float64Array([\n    377, 479, 453, 434, 326, 387, 444, 359, 511, 389,\n    586, 429, 470, 315, 622, 493, 627, 367, 570, 314\n]);\n\nconst delaunay = new Delaunator(coords);\n\nconsole.log('Triangle vertex indices:', delaunay.triangles);\nconsole.log('Half-edge indices for traversal:', delaunay.halfedges);\nconsole.log('Convex hull point indices (counter-clockwise):', delaunay.hull);\n\n// Example: Retrieve the coordinates of the first triangle\nif (delaunay.triangles.length >= 3) {\n    const i0 = delaunay.triangles[0];\n    const i1 = delaunay.triangles[1];\n    const i2 = delaunay.triangles[2];\n    const triangleCoords = [\n        [coords[2 * i0], coords[2 * i0 + 1]],\n        [coords[2 * i1], coords[2 * i1 + 1]],\n        [coords[2 * i2], coords[2 * i2 + 1]]\n    ];\n    console.log('Coordinates of the first triangle:', triangleCoords);\n}","lang":"typescript","description":"This example initializes Delaunator with a flat array of coordinates and logs the resulting triangle, half-edge, and convex hull indices, demonstrating basic usage."},"warnings":[{"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.","message":"Delaunator 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.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Configure your build tools (e.g., Babel) to transpile `node_modules/delaunator` if you need to support environments without modern JavaScript features.","message":"Transpilation 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.","severity":"breaking","affected_versions":">=5.0.0"},{"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.","message":"The `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.","severity":"breaking","affected_versions":">=3.0.1"},{"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.","message":"First-class TypeScript types are now shipped directly with the `delaunator` package, rendering the separate `@types/delaunator` package obsolete and unnecessary.","severity":"deprecated","affected_versions":">=5.1.0"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":"always"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"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.","error":"ReferenceError: require is not defined"},{"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>`).","cause":"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).","error":"SyntaxError: Cannot use import statement outside a module"},{"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) { /* ... */ }`.","cause":"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`.","error":"TypeError: delaunay.hull.next is not a function"},{"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\"`).","cause":"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.","error":"TS2307: Cannot find module 'delaunator' or its corresponding type declarations."}],"ecosystem":"npm"}