earcut 2.2.3 → 3.0.0

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/README.md CHANGED
@@ -1,9 +1,8 @@
1
1
  ## Earcut
2
2
 
3
- The fastest and smallest JavaScript polygon triangulation library. 2.5KB gzipped.
3
+ The fastest and smallest JavaScript polygon triangulation library. 3KB gzipped.
4
4
 
5
- [![Build Status](https://travis-ci.org/mapbox/earcut.svg?branch=master)](https://travis-ci.org/mapbox/earcut)
6
- [![Coverage Status](https://coveralls.io/repos/mapbox/earcut/badge.svg?branch=master)](https://coveralls.io/r/mapbox/earcut?branch=master)
5
+ [![Node](https://github.com/mapbox/earcut/actions/workflows/node.yml/badge.svg)](https://github.com/mapbox/earcut/actions/workflows/node.yml)
7
6
  [![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
7
  [![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
8
  [![](https://img.shields.io/badge/simply-awesome-brightgreen.svg)](https://github.com/mourner/projects)
@@ -44,7 +43,7 @@ and earcut is not precise enough, take a look at [libtess.js](https://github.com
44
43
  #### Usage
45
44
 
46
45
  ```js
47
- var triangles = earcut([10,0, 0,50, 60,60, 70,10]); // returns [1,0,3, 3,2,1]
46
+ const triangles = earcut([10,0, 0,50, 60,60, 70,10]); // returns [1,0,3, 3,2,1]
48
47
  ```
49
48
 
50
49
  Signature: `earcut(vertices[, holes, dimensions = 2])`.
@@ -52,7 +51,7 @@ Signature: `earcut(vertices[, holes, dimensions = 2])`.
52
51
  * `vertices` is a flat array of vertex coordinates like `[x0,y0, x1,y1, x2,y2, ...]`.
53
52
  * `holes` is an array of hole _indices_ if any
54
53
  (e.g. `[5, 8]` for a 12-vertex input would mean one hole with vertices 5–7 and another with 8–11).
55
- * `dimensions` is the number of coordinates per vertex in the input array (`2` by default).
54
+ * `dimensions` is the number of coordinates per vertex in the input array (`2` by default). Only two are used for triangulation (`x` and `y`), and the rest are ignored.
56
55
 
57
56
  Each group of three vertex indices in the resulting array forms a triangle.
58
57
 
@@ -68,18 +67,20 @@ earcut([10,0,1, 0,50,2, 60,60,3, 70,10,4], null, 3);
68
67
 
69
68
  If you pass a single vertex as a hole, Earcut treats it as a Steiner point.
70
69
 
70
+ Note that Earcut is a **2D** triangulation algorithm, and handles 3D data as if it was projected onto the XY plane (with Z component ignored).
71
+
71
72
  If your input is a multi-dimensional array (e.g. [GeoJSON Polygon](http://geojson.org/geojson-spec.html#polygon)),
72
73
  you can convert it to the format expected by Earcut with `earcut.flatten`:
73
74
 
74
75
  ```js
75
- var data = earcut.flatten(geojson.geometry.coordinates);
76
- var triangles = earcut(data.vertices, data.holes, data.dimensions);
76
+ const data = earcut.flatten(geojson.geometry.coordinates);
77
+ const triangles = earcut(data.vertices, data.holes, data.dimensions);
77
78
  ```
78
79
 
79
80
  After getting a triangulation, you can verify its correctness with `earcut.deviation`:
80
81
 
81
82
  ```js
82
- var deviation = earcut.deviation(vertices, holes, dimensions, triangles);
83
+ const deviation = earcut.deviation(vertices, holes, dimensions, triangles);
83
84
  ```
84
85
 
85
86
  Returns the relative difference between the total area of triangles and the area of the input polygon.
@@ -87,21 +88,24 @@ Returns the relative difference between the total area of triangles and the area
87
88
 
88
89
  #### Install
89
90
 
90
- NPM and Browserify:
91
+ Install with NPM: `npm install earcut`, then import as a module:
91
92
 
92
- ```bash
93
- npm install earcut
93
+ ```js
94
+ import earcut from 'earcut';
94
95
  ```
95
96
 
96
- Browser builds on CDN:
97
+ Or use as a module directly in the browser with [jsDelivr](https://www.jsdelivr.com/esm):
97
98
 
98
- - [development build](https://unpkg.com/earcut@2.2.2/dist/earcut.dev.js)
99
- - [minified production build](https://unpkg.com/earcut@2.2.2/dist/earcut.min.js)
99
+ ```html
100
+ <script type="module">
101
+ import earcut from 'https://cdn.jsdelivr.net/npm/earcut/+esm';
102
+ </script>
103
+ ```
100
104
 
101
- Running tests:
105
+ Alternatively, there's a UMD browser bundle with an `earcut` global variable (exposing the main function as `earcut.default`):
102
106
 
103
- ```bash
104
- npm test
107
+ ```html
108
+ <script src="https://cdn.jsdelivr.net/npm/earcut/dist/earcut.min.js"></script>
105
109
  ```
106
110
 
107
111
  ![](https://cloud.githubusercontent.com/assets/25395/5778431/e8ec0c10-9da3-11e4-8d4e-a2ced6a7d2b7.png)
@@ -109,138 +113,8 @@ npm test
109
113
  #### Ports to other languages
110
114
 
111
115
  - [mapbox/earcut.hpp](https://github.com/mapbox/earcut.hpp) (C++11)
116
+ - [JaffaKetchup/dart_earcut](https://github.com/JaffaKetchup/dart_earcut) (Dart)
112
117
  - [earcut4j/earcut4j](https://github.com/earcut4j/earcut4j) (Java)
113
118
  - [the3deers/earcut-java](https://github.com/the3deers/earcut-java) (Java)
114
119
  - [Larpon/earcut](https://github.com/Larpon/earcut) (V)
115
120
  - [Cawfree/earcut-j](https://github.com/Cawfree/earcut-j) (Java, outdated)
116
-
117
- #### Changelog
118
-
119
- ##### 2.2.2 (Jan 21, 2020)
120
-
121
- - Fixed yet another rare race condition when a hole shared an edge with an outer ring.
122
-
123
- ##### 2.2.1 (Sep 19, 2019)
124
-
125
- - Fixed another rare case with touching holes.
126
-
127
- ##### 2.2.0 (Sep 18, 2019)
128
-
129
- - Fixed a handful of rare race conditions.
130
-
131
- ##### 2.1.5 (Feb 5, 2019)
132
-
133
- - Fixed a race condition with coincident holes that could lead to bad triangulation.
134
-
135
- ##### 2.1.4 (Dec 4, 2018)
136
-
137
- - Fixed a race condition that could lead to a freeze on degenerate input.
138
-
139
- ##### 2.1.3 (Jan 4, 2018)
140
-
141
- - Improved performance for bigger inputs (5-12%).
142
-
143
- ##### 2.1.2 (Oct 23, 2017)
144
-
145
- - Fixed a few race conditions where bad input would cause an error.
146
-
147
- ##### 2.1.1 (Mar 17, 2016)
148
-
149
- - Fixed a rare race condition where the split routine would choose bad diagonals.
150
- - Fixed a rare race condition in the "cure local intersections" routine.
151
- - Fixed a rare race condition where a hole that shares a point with the outer ring would be handled incorrectly.
152
- - Fixed a bug where a closing point wouldn't be filtered as duplicate, sometimes breaking triangulation.
153
-
154
- ##### 2.1.0 (Mar 11, 2016)
155
-
156
- - Added `earcut.deviation` function for verifying correctness of triangulation.
157
- - Added `earcut.flatten` function for converting GeoJSON-like input into a format Earcut expects.
158
-
159
- ##### 2.0.9 (Mar 10, 2016)
160
-
161
- - Fixed a rare race condition where a hole would be handled incorrectly.
162
-
163
- ##### 2.0.8 (Jan 19, 2016)
164
-
165
- - Fixed a rare race condition with a hole touching outer ring.
166
-
167
- ##### 2.0.7 (Nov 18, 2015)
168
-
169
- - Changed the algorithm to avoid filtering colinear/duplicate vertices unless it can't triangulate the polygon otherwise.
170
- Improves performance on simpler shapes and fixes some 3D use cases.
171
-
172
- ##### 2.0.6 (Oct 26, 2015)
173
-
174
- - Improved robustness and reliability of the triangulation algorithm.
175
- - Improved performance by up to 15%.
176
- - Significantly improved source code clarity.
177
-
178
- ##### 2.0.5 (Oct 12, 2015)
179
-
180
- - Fixed a z-curve hashing bug that could lead to unexpected results in very rare cases involving shapes with lots of points.
181
-
182
- ##### 2.0.4 (Oct 8, 2015)
183
-
184
- - Fixed one more extremely rare race condition, lol!
185
-
186
- ##### 2.0.3 (Oct 8, 2015)
187
-
188
- - Fixed yet another rare race condition (multiple holes connected with colinear bridges).
189
- - Fixed crash on empty input.
190
-
191
- ##### 2.0.2 (Jul 8, 2015)
192
-
193
- - Fixed one more rare race condition with a holed polygon.
194
-
195
- ##### 2.0.1 (May 11, 2015)
196
-
197
- - Added Steiner points support.
198
-
199
- ##### 2.0.0 (Apr 30, 2015)
200
-
201
- - **Breaking**: changed the API to accept a flat input array of vertices with hole indices and return triangle indices.
202
- It makes the indexed output much faster than it was before (up to 30%) and improves memory footprint.
203
-
204
- ##### 1.4.2 (Mar 18, 2015)
205
-
206
- - Fixed another rare edge case with a tiny hole in a huge polygon.
207
-
208
- ##### 1.4.1 (Mar 17, 2015)
209
-
210
- - Fixed a rare edge case that led to incomplete triangulation.
211
-
212
- ##### 1.4.0 (Mar 9, 2015)
213
-
214
- - Fixed indexed output to produce indices not multiplied by dimension and work with any number of dimensions.
215
-
216
- ##### 1.3.0 (Feb 24, 2015)
217
-
218
- - Added a second argument to `earcut` that switches output format to flat vertex and index arrays if set to `true`.
219
-
220
- ##### 1.2.3 (Feb 10, 2015)
221
-
222
- - Improved performance (especially on recent v8) by avoiding `Array` `push` with multiple arguments.
223
-
224
- ##### 1.2.2 (Jan 27, 2015)
225
-
226
- - Significantly improved performance for polygons with self-intersections
227
- (e.g. big OSM water polygons are now handled 2-3x faster)
228
-
229
- ##### 1.2.1 (Jan 26, 2015)
230
-
231
- - Significantly improved performance on polygons with high number of vertices
232
- by using z-order curve hashing for vertex lookup.
233
- - Slightly improved overall performance with better point filtering.
234
-
235
- ##### 1.1.0 (Jan 21, 2015)
236
-
237
- - Improved performance on polygons with holes by switching from Held to Eberly hole elimination algorithm
238
- - More robustness fixes and tests
239
-
240
- ##### 1.0.1 &mdash; 1.0.6 (Jan 20, 2015)
241
-
242
- - Various robustness improvements and fixes.
243
-
244
- ##### 1.0.0 (Jan 18, 2015)
245
-
246
- - Initial release.