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 CHANGED
@@ -1,4 +1,5 @@
1
1
  coverage
2
- node_modules
3
- dist
4
2
  *.log
3
+ test
4
+ bench
5
+ viz
package/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2015, Mapbox
1
+ Copyright (c) 2016, Mapbox
2
2
 
3
3
  Permission to use, copy, modify, and/or distribute this software for any purpose
4
4
  with or without fee is hereby granted, provided that the above copyright notice
package/README.md CHANGED
@@ -6,6 +6,7 @@ The fastest and smallest JavaScript polygon triangulation library. 2.5KB gzipped
6
6
  [![Coverage Status](https://coveralls.io/repos/mapbox/earcut/badge.svg?branch=master)](https://coveralls.io/r/mapbox/earcut?branch=master)
7
7
  [![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/mapbox/earcut.svg)](http://isitmaintained.com/project/mapbox/earcut "Average time to resolve an issue")
8
8
  [![Percentage of issues still open](http://isitmaintained.com/badge/open/mapbox/earcut.svg)](http://isitmaintained.com/project/mapbox/earcut "Percentage of issues still open")
9
+ [![](https://img.shields.io/badge/simply-awesome-brightgreen.svg)](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 | _743,130_ | _50,640_ | _61,501_ | _122,966_ | _175,570_
33
- dude shape | 94 | _35,039_ | _10,339_ | _8,784_ | _11,172_ | _13,557_
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 | _597_ | _77.54_ | failure | failure | n/a
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(coords[, holeIndices, numDimensions = 2])`.
50
+ Signature: `earcut(vertices[, holes, dimensions = 2])`.
50
51
 
51
- * `coords` is a flat array of vertice coordinates like `[x0,y0, x1,y1, x2,y2, ...]`.
52
- * `holeIndices` is an array of hole indices if any
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
- * `numDimensions` is the number of coordinates per vertice in the input array (`2` by default).
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 [a couple lines of codes](viz/viz.js#L99-L115).
72
+ you can convert it to the format expected by Earcut with `earcut.flatten`:
70
73
 
71
- If you pass a single vertice as a hole, Earcut treats it as a Steiner point.
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
- ```bash
84
- npm install
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.