pax_global_header 0000666 0000000 0000000 00000000064 14027334066 0014517 g ustar 00root root 0000000 0000000 52 comment=141d30bba9ae95deee53c4ead9af57de47be1942
delaunator-5.0.0/ 0000775 0000000 0000000 00000000000 14027334066 0013657 5 ustar 00root root 0000000 0000000 delaunator-5.0.0/.gitignore 0000664 0000000 0000000 00000000112 14027334066 0015641 0 ustar 00root root 0000000 0000000 node_modules
tmp
*.log
yarn.lock
coverage
delaunator.js
delaunator.min.js
delaunator-5.0.0/.travis.yml 0000664 0000000 0000000 00000000055 14027334066 0015770 0 ustar 00root root 0000000 0000000 language: node_js
node_js:
- "12"
- "14"
delaunator-5.0.0/LICENSE 0000664 0000000 0000000 00000001342 14027334066 0014664 0 ustar 00root root 0000000 0000000 ISC License
Copyright (c) 2017, Mapbox
Permission to use, copy, modify, and/or distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright notice
and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.
delaunator-5.0.0/README.md 0000664 0000000 0000000 00000013707 14027334066 0015146 0 ustar 00root root 0000000 0000000 # Delaunator [](https://travis-ci.org/mapbox/delaunator) [](https://github.com/mourner/projects) [](https://unpkg.com/delaunator)
An incredibly fast JavaScript library for
[Delaunay triangulation](https://en.wikipedia.org/wiki/Delaunay_triangulation) of 2D points.
- [Interactive Demo](https://mapbox.github.io/delaunator/demo.html)
- [Guide to data structures](https://mapbox.github.io/delaunator/)
### Projects based on Delaunator
- [d3-delaunay](https://github.com/d3/d3-delaunay) for Voronoi diagrams, search, traversal and rendering (a part of [D3](https://d3js.org)).
- [d3-geo-voronoi](https://github.com/Fil/d3-geo-voronoi) for Delaunay triangulations and Voronoi diagrams on a sphere (e.g. for geographic locations).
### Ports to other languages
- [delaunator-rs](https://github.com/mourner/delaunator-rs) (Rust)
- [fogleman/delaunay](https://github.com/fogleman/delaunay) (Go)
- [delaunator-cpp](https://github.com/abellgithub/delaunator-cpp) (C++)
- [delaunator-sharp](https://github.com/nol1fe/delaunator-sharp) (C#)
- [delaunator-ruby](https://github.com/hendrixfan/delaunator-ruby) (Ruby)
- [Delaunator-Python](https://github.com/HakanSeven12/Delaunator-Python) (Python)
- [hx-delaunator](https://github.com/dmitryhryppa/hx-delaunator) (Haxe)
- [ricardomatias/delaunator](https://github.com/ricardomatias/delaunator) (Kotlin)
## Example
```js
const points = [[168, 180], [168, 178], [168, 179], [168, 181], [168, 183], ...];
const delaunay = Delaunator.from(points);
console.log(delaunay.triangles);
// [623, 636, 619, 636, 444, 619, ...]
```
## Install
Install with NPM (`npm install delaunator`) or Yarn (`yarn add delaunator`), then:
```js
// import as an ES module
import Delaunator from 'delaunator';
// or require in Node / Browserify
const Delaunator = require('delaunator');
```
Or use a browser build directly:
```html
```
## API Reference
#### Delaunator.from(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.
#### new Delaunator(coords)
Constructs a delaunay triangulation object given an array of point coordinates of the form:
`[x0, y0, x1, y1, ...]` (use a typed array for best performance).
#### delaunay.triangles
A `Uint32Array` 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:
```js
for (let i = 0; i < triangles.length; i += 3) {
coordinates.push([
points[triangles[i]],
points[triangles[i + 1]],
points[triangles[i + 2]]
]);
}
```
#### delaunay.halfedges
A `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.
#### delaunay.hull
A `Uint32Array` array of indices that reference points on the convex hull of the input data, counter-clockwise.
#### delaunay.coords
An array of input coordinates in the form `[x0, y0, x1, y1, ....]`,
of the type provided in the constructor (or `Float64Array` if you used `Delaunator.from`).
#### delaunay.update()
Updates the triangulation if you modified `delaunay.coords` values in place, avoiding expensive memory allocations.
Useful for iterative relaxation algorithms such as [Lloyd's](https://en.wikipedia.org/wiki/Lloyd%27s_algorithm).
## Performance
Benchmark results against other Delaunay JS libraries
(`npm run bench` on Macbook Pro Retina 15" 2017, Node v10.10.0):
| uniform 100k | gauss 100k | grid 100k | degen 100k | uniform 1 million | gauss 1 million | grid 1 million | degen 1 million
:-- | --: | --: | --: | --: | --: | --: | --: | --:
**delaunator** | 82ms | 61ms | 66ms | 25ms | 1.07s | 950ms | 830ms | 278ms
[faster‑delaunay](https://github.com/Bathlamos/delaunay-triangulation) | 473ms | 411ms | 272ms | 68ms | 4.27s | 4.62s | 4.3s | 810ms
[incremental‑delaunay](https://github.com/mikolalysenko/incremental-delaunay) | 547ms | 505ms | 172ms | 528ms | 5.9s | 6.08s | 2.11s | 6.09s
[d3‑voronoi](https://github.com/d3/d3-voronoi) | 972ms | 909ms | 358ms | 720ms | 15.04s | 13.86s | 5.55s | 11.13s
[delaunay‑fast](https://github.com/ironwallaby/delaunay) | 3.8s | 4s | 12.57s | timeout | 132s | 138s | 399s | timeout
[delaunay](https://github.com/darkskyapp/delaunay) | 4.85s | 5.73s | 15.05s | timeout | 156s | 178s | 326s | timeout
[delaunay‑triangulate](https://github.com/mikolalysenko/delaunay-triangulate) | 2.24s | 2.04s | OOM | 1.51s | OOM | OOM | OOM | OOM
[cdt2d](https://github.com/mikolalysenko/cdt2d) | 45s | 51s | 118s | 17s | timeout | timeout | timeout | timeout
## Papers
The algorithm is based on ideas from the following papers:
- [A simple sweep-line Delaunay triangulation algorithm](http://www.academicpub.org/jao/paperInfo.aspx?paperid=15630), 2013, Liu Yonghe, Feng Jinming and Shao Yuehong
- [S-hull: a fast radial sweep-hull routine for Delaunay triangulation](http://www.s-hull.org/paper/s_hull.pdf), 2010, David Sinclair
- [A faster circle-sweep Delaunay triangulation algorithm](http://cglab.ca/~biniaz/papers/Sweep%20Circle.pdf), 2011, Ahmad Biniaz and Gholamhossein Dastghaibyfard
delaunator-5.0.0/bench.js 0000664 0000000 0000000 00000004237 14027334066 0015302 0 ustar 00root root 0000000 0000000 /* eslint no-unused-vars: 0 */
import Delaunator from './index.js';
// import fasterDelaunay from 'faster-delaunay';
// import incrementalDelaunay from 'incremental-delaunay';
// import delaunayFast from 'delaunay-fast';
// import delaunaySlow from 'delaunay';
// import {voronoi} from 'd3-voronoi';
// import delaunayTriangulate from 'delaunay-triangulate';
// import cdt2d from 'cdt2d';
function triangulate(points) {
Delaunator.from(points);
// fasterDelaunay(points).triangulate();
// voronoi()(points);
// incrementalDelaunay(points);
// delaunayFast.triangulate(points);
// delaunaySlow.triangulate(points);
// delaunayTriangulate(points);
// cdt2d(points);
}
const distributions = [uniform, gaussian, grid, degenerate];
const counts = [20000, 100000, 200000, 500000, 1000000];
for (const generate of distributions) {
console.log(`${generate.name}:`);
// warmup
triangulate(generate(counts[0]));
triangulate(generate(counts[1]));
for (let i = 0; i < counts.length; i++) {
const c = counts[i];
const points = generate(c);
console.time(c);
triangulate(points);
console.timeEnd(c);
}
}
function uniform(count) {
const points = [];
for (let i = 0; i < count; i++) {
points.push([Math.random() * 1e3, Math.random() * 1e3]);
}
return points;
}
function grid(count) {
const points = [];
const size = Math.sqrt(count);
for (let i = 0; i < size; i++) {
for (let j = 0; j < size; j++) {
points.push([i, j]);
}
}
return points;
}
function gaussian(count) {
const points = [];
for (let i = 0; i < count; i++) {
points.push([pseudoNormal() * 1e3, pseudoNormal() * 1e3]);
}
return points;
}
function degenerate(count) {
const points = [[0, 0]];
for (let i = 0; i < count; i++) {
const angle = 2 * Math.PI * i / count;
points.push([1e10 * Math.sin(angle), 1e10 * Math.cos(angle)]);
}
return points;
}
function pseudoNormal() {
const v = Math.random() + Math.random() + Math.random() + Math.random() + Math.random() + Math.random();
return Math.min(0.5 * (v - 3) / 3, 1);
}
delaunator-5.0.0/delaunator.png 0000664 0000000 0000000 00000562477 14027334066 0016550 0 ustar 00root root 0000000 0000000 PNG
IHDR + n PLTEGpLLtLui}LcLLcjiL\LSLLL~xh|L楽LiLjL泀LLMMMLɡhLL𰖥NLLLحjLLMzL䮸LՕeLkMۍµLLwL|vjwL恕»VLeLL`iLwL斑LVhLfꔟ^LLnLLLL}LlLiLL{eLLzŁLLLLL棟bLjxL`oLLLLLfrwL_rcxLqLLLVNrLL}LML}LpLLLLj}LMoVLLLuLLLLLLYLLLQLLbLjLLLLLLmLLwLfLLLLLLz3 tRNS .EgӄH8| IDATx[H͠RUMhضNS,Fq}}0;guuummm}}}ccssk|Ƕﯯ<ðvvO[EH)}_T0pO
03m'SԀڢ:}CWFY;+0O4<6NN0KRJV8U^67ǡ>}ocaG.)bj;I5c{(ۇ=΅