earcut 2.0.6 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.npmignore +3 -2
- package/LICENSE +1 -1
- package/README.md +53 -16
- package/dist/earcut.dev.js +649 -0
- package/dist/earcut.min.js +1 -0
- package/earcut.sublime-workspace +882 -157
- package/package.json +16 -11
- package/src/earcut.js +79 -18
- package/bench/basic.js +0 -15
- package/bench/bench.js +0 -28
- package/test/fixtures/bad-hole.json +0 -6
- package/test/fixtures/building.json +0 -1
- package/test/fixtures/degenerate.json +0 -1
- package/test/fixtures/dude.json +0 -5
- package/test/fixtures/empty-square.json +0 -4
- package/test/fixtures/hole-touching-outer.json +0 -1
- package/test/fixtures/issue16.json +0 -14
- package/test/fixtures/issue17.json +0 -13
- package/test/fixtures/issue29.json +0 -4
- package/test/fixtures/issue34.json +0 -10
- package/test/fixtures/issue35.json +0 -32
- package/test/fixtures/outside-ring.json +0 -1
- package/test/fixtures/self-touching.json +0 -1
- package/test/fixtures/simplified-us-border.json +0 -1
- package/test/fixtures/steiner.json +0 -7
- package/test/fixtures/touching-holes.json +0 -1
- package/test/fixtures/water-huge.json +0 -195
- package/test/fixtures/water-huge2.json +0 -445
- package/test/fixtures/water.json +0 -12
- package/test/fixtures/water2.json +0 -10
- package/test/fixtures/water3.json +0 -8
- package/test/fixtures/water3b.json +0 -5
- package/test/fixtures/water4.json +0 -8
- package/test/test.js +0 -124
- package/viz/index.html +0 -16
- package/viz/viz.js +0 -115
package/.npmignore
CHANGED
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -6,6 +6,7 @@ The fastest and smallest JavaScript polygon triangulation library. 2.5KB gzipped
|
|
|
6
6
|
[](https://coveralls.io/r/mapbox/earcut?branch=master)
|
|
7
7
|
[](http://isitmaintained.com/project/mapbox/earcut "Average time to resolve an issue")
|
|
8
8
|
[](http://isitmaintained.com/project/mapbox/earcut "Percentage of issues still open")
|
|
9
|
+
[](https://github.com/mourner/projects)
|
|
9
10
|
|
|
10
11
|
#### The algorithm
|
|
11
12
|
|
|
@@ -29,10 +30,10 @@ Some benchmarks using Node 0.12:
|
|
|
29
30
|
|
|
30
31
|
(ops/sec) | pts | earcut | libtess | poly2tri | pnltri | polyk
|
|
31
32
|
------------------| ---- | --------- | -------- | -------- | --------- | ------
|
|
32
|
-
OSM building | 15 |
|
|
33
|
-
dude shape | 94 | _35,
|
|
33
|
+
OSM building | 15 | _795,935_ | _50,640_ | _61,501_ | _122,966_ | _175,570_
|
|
34
|
+
dude shape | 94 | _35,658_ | _10,339_ | _8,784_ | _11,172_ | _13,557_
|
|
34
35
|
holed dude shape | 104 | _28,319_ | _8,883_ | _7,494_ | _2,130_ | n/a
|
|
35
|
-
complex OSM water | 2523 |
|
|
36
|
+
complex OSM water | 2523 | _543_ | _77.54_ | failure | failure | n/a
|
|
36
37
|
huge OSM water | 5667 | _95_ | _29.30_ | failure | failure | n/a
|
|
37
38
|
|
|
38
39
|
The original use case it was created for is [Mapbox GL](https://www.mapbox.com/mapbox-gl), WebGL-based interactive maps.
|
|
@@ -46,12 +47,12 @@ and earcut is not precise enough, take a look at [libtess.js](https://github.com
|
|
|
46
47
|
var triangles = earcut([10,0, 0,50, 60,60, 70,10]); // returns [1,0,3, 3,2,1]
|
|
47
48
|
```
|
|
48
49
|
|
|
49
|
-
Signature: `earcut(
|
|
50
|
+
Signature: `earcut(vertices[, holes, dimensions = 2])`.
|
|
50
51
|
|
|
51
|
-
* `
|
|
52
|
-
* `
|
|
52
|
+
* `vertices` is a flat array of vertice coordinates like `[x0,y0, x1,y1, x2,y2, ...]`.
|
|
53
|
+
* `holes` is an array of hole _indices_ if any
|
|
53
54
|
(e.g. `[5, 8]` for a 12-vertice input would mean one hole with vertices 5–7 and another with 8–11).
|
|
54
|
-
* `
|
|
55
|
+
* `dimensions` is the number of coordinates per vertice in the input array (`2` by default).
|
|
55
56
|
|
|
56
57
|
Each group of three vertice indices in the resulting array forms a triangle.
|
|
57
58
|
|
|
@@ -65,10 +66,24 @@ earcut([10,0,1, 0,50,2, 60,60,3, 70,10,4], null, 3);
|
|
|
65
66
|
// [1,0,3, 3,2,1]
|
|
66
67
|
```
|
|
67
68
|
|
|
69
|
+
If you pass a single vertice as a hole, Earcut treats it as a Steiner point.
|
|
70
|
+
|
|
68
71
|
If your input is a multi-dimensional array (e.g. [GeoJSON Polygon](http://geojson.org/geojson-spec.html#polygon)),
|
|
69
|
-
you can convert it to the format expected by Earcut with
|
|
72
|
+
you can convert it to the format expected by Earcut with `earcut.flatten`:
|
|
70
73
|
|
|
71
|
-
|
|
74
|
+
```js
|
|
75
|
+
var data = earcut.flatten(geojson.geometry.coordinates);
|
|
76
|
+
var triangles = earcut(data.vertices, data.holes, data.dimensions);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
After getting a triangulation, you can verify its correctness with `earcut.deviation`:
|
|
80
|
+
|
|
81
|
+
```js
|
|
82
|
+
var deviation = earcut.deviation(vertices, holes, dimensions, triangles);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Returns the relative difference between the total area of triangles and the area of the input polygon.
|
|
86
|
+
`0` means the triangulation is fully correct.
|
|
72
87
|
|
|
73
88
|
#### Install
|
|
74
89
|
|
|
@@ -78,13 +93,10 @@ NPM and Browserify:
|
|
|
78
93
|
npm install earcut
|
|
79
94
|
```
|
|
80
95
|
|
|
81
|
-
Browser builds:
|
|
96
|
+
Browser builds on CDN:
|
|
82
97
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
npm run build-dev # builds dist/earcut.dev.js, a dev version with a source map
|
|
86
|
-
npm run build-min # builds dist/earcut.min.js, a minified production build
|
|
87
|
-
```
|
|
98
|
+
- [development build](https://npmcdn.com/earcut@2.0.8/dist/earcut.dev.js)
|
|
99
|
+
- [minified production build](https://npmcdn.com/earcut@2.0.8/dist/earcut.min.js)
|
|
88
100
|
|
|
89
101
|
Running tests:
|
|
90
102
|
|
|
@@ -97,10 +109,35 @@ npm test
|
|
|
97
109
|
#### Ports to other languages
|
|
98
110
|
|
|
99
111
|
- [mapbox/earcut.hpp](https://github.com/mapbox/earcut.hpp) (C++11)
|
|
100
|
-
- [Cawfree/earcut-j](https://github.com/Cawfree/earcut-j) (Java)
|
|
112
|
+
- [Cawfree/earcut-j](https://github.com/Cawfree/earcut-j) (Java, outdated)
|
|
101
113
|
|
|
102
114
|
#### Changelog
|
|
103
115
|
|
|
116
|
+
##### 2.1.1 (Mar 17, 2016)
|
|
117
|
+
|
|
118
|
+
- Fixed a rare race condition where the split routine would choose bad diagonals.
|
|
119
|
+
- Fixed a rare race condition in the "cure local intersections" routine.
|
|
120
|
+
- Fixed a rare race condition where a hole that shares a point with the outer ring would be handled incorrectly.
|
|
121
|
+
- Fixed a bug where a closing point wouldn't be filtered as duplicate, sometimes breaking triangulation.
|
|
122
|
+
|
|
123
|
+
##### 2.1.0 (Mar 11, 2016)
|
|
124
|
+
|
|
125
|
+
- Added `earcut.deviation` function for verifying correctness of triangulation.
|
|
126
|
+
- Added `earcut.flatten` function for converting GeoJSON-like input into a format Earcut expects.
|
|
127
|
+
|
|
128
|
+
##### 2.0.9 (Mar 10, 2016)
|
|
129
|
+
|
|
130
|
+
- Fixed a rare race condition where a hole would be handled incorrectly.
|
|
131
|
+
|
|
132
|
+
##### 2.0.8 (Jan 19, 2016)
|
|
133
|
+
|
|
134
|
+
- Fixed a rare race condition with a hole touching outer ring.
|
|
135
|
+
|
|
136
|
+
##### 2.0.7 (Nov 18, 2015)
|
|
137
|
+
|
|
138
|
+
- Changed the algorithm to avoid filtering colinear/duplicate vertices unless it can't triangulate the polygon otherwise.
|
|
139
|
+
Improves performance on simpler shapes and fixes some 3D use cases.
|
|
140
|
+
|
|
104
141
|
##### 2.0.6 (Oct 26, 2015)
|
|
105
142
|
|
|
106
143
|
- Improved robustness and reliability of the triangulation algorithm.
|