Socket
Socket
Sign inDemoInstall

delaunator

Package Overview
Dependencies
0
Maintainers
183
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    delaunator

A really fast JavaScript library for Delaunay triangulation of 2D points


Version published
Weekly downloads
2.9M
decreased by-1.77%
Maintainers
183
Install size
35.6 kB
Created
Weekly downloads
 

Package description

What is delaunator?

The delaunator npm package is a fast library for Delaunay triangulation of 2D points. It is used to triangulate a set of points into a mesh of triangles, which is a fundamental operation in many geometric algorithms. The package is particularly useful in graphics, geographical information systems (GIS), and for performing various computational geometry tasks.

What are delaunator's main functionalities?

Triangulation

This feature allows you to perform Delaunay triangulation on an array of points. The 'triangles' property of the resulting object contains the indices of the points that form the triangles.

const Delaunator = require('delaunator');
const points = [[0, 0], [1, 0], [1, 1], [0, 1]];
const delaunay = Delaunator.from(points);
console.log(delaunay.triangles);

Hull

This feature provides the convex hull of the input points as an array of point indices that are in the hull. The hull is the outermost 'shell' of the triangulation.

const Delaunator = require('delaunator');
const points = [[0, 0], [1, 0], [1, 1], [0, 1]];
const delaunay = Delaunator.from(points);
console.log(delaunay.hull);

Coordinates Conversion

Delaunator can also take a flat array of coordinates and perform triangulation. This is useful when working with data that is not already structured as an array of points.

const Delaunator = require('delaunator');
const coords = [0, 0, 1, 0, 1, 1, 0, 1];
const delaunay = Delaunator.from(coords);
console.log(delaunay.triangles);

Other packages similar to delaunator

Readme

Source

delaunator

A really fast JavaScript library for Delaunay triangulation of 2D points.

Build Status

Interactive Demo

Example

var points = [[168, 180], [168, 178], [168, 179], [168, 181], [168, 183], ...];

var delaunay = new Delaunator(points);
console.log(delaunay.triangles);
// [623, 636, 619,  636, 444, 619, ...]

API Reference

new Delaunator(points[, getX, getY])

Constructs a delaunay triangulation object given an array of points ([x, y] by default). getX and getY are optional functions of the form (point) => value for custom point formats. Duplicate points are skipped.

delaunay.triangles

A flat Int32Array array of triangle vertex indices (each group of three numbers forms a triangle). All triangles are directed counterclockwise.

To get the coordinates of all triangles, use:

for (var i = 0; i < triangles.length; i += 3) {
    coordinates.push([
        points[triangles[i]],
        points[triangles[i + 1]],
        points[triangles[i + 2]]
    ]);
}
delaunay.halfedges

A flat Int32Array array of triangle half-edge indices that allows you to traverse the triangulation. i-th half-edge in the array corresponds to vertex triangles[i] the half-edge is coming from. halfedges[i] is the index of a twin half-edge in an adjacent triangle (or -1 for outer half-edges on the convex hull).

The flat array-based data structures might be counterintuitive, but they're one of the key reasons this library is fast.

Performance

Benchmark results against four fastest other libraries (bench.js on Macbook Pro Retina mid-2012, Node v7.9.0):

Uniform distribution
library10,00020,00050,000100,000200,000500,0001,000,000
delaunator25ms32ms105ms168ms350ms974ms2.46s
faster-delaunay78ms140ms328ms776ms1.74s3.87s6.99s
incremental-delaunay81ms154ms428ms874ms1.74s4.3s9.03s
d3-voronoi154ms250ms534ms1.19s2.7s7.37s18.36s
delaunay-fast136ms386ms1.18s3.03s7.95s28.2s76.96s
Gaussian distribution
library10,00020,00050,000100,000200,000500,0001,000,000
delaunator24ms27ms109ms170ms327ms941ms2.03s
faster-delaunay76ms172ms291ms692ms1.19s3.46s6.36s
incremental-delaunay74ms154ms410ms806ms1.67s4.27s8.3s
d3-voronoi164ms264ms522ms1.16s2.67s7.64s18.62s
delaunay-fast152ms340ms1.19s3.2s8.37s30.03s82.05s

Papers

The algorithm is based on ideas from the following papers:

Keywords

FAQs

Last updated on 27 Nov 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc