@math.gl/polygon 4.0.0 → 4.0.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/dist/cut-by-grid.d.ts +1 -2
- package/dist/cut-by-grid.js +194 -228
- package/dist/cut-by-mercator-bounds.d.ts +1 -2
- package/dist/cut-by-mercator-bounds.js +124 -124
- package/dist/earcut.d.ts +1 -2
- package/dist/earcut.js +577 -490
- package/dist/index.cjs +16 -36
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +7 -8
- package/dist/index.js +1 -1
- package/dist/lineclip.d.ts +1 -2
- package/dist/lineclip.js +163 -114
- package/dist/polygon-utils.d.ts +5 -6
- package/dist/polygon-utils.js +124 -107
- package/dist/polygon.d.ts +2 -3
- package/dist/polygon.js +61 -49
- package/dist/utils.d.ts +0 -1
- package/dist/utils.js +26 -34
- package/package.json +5 -5
- package/dist/cut-by-grid.d.ts.map +0 -1
- package/dist/cut-by-grid.js.map +0 -1
- package/dist/cut-by-mercator-bounds.d.ts.map +0 -1
- package/dist/cut-by-mercator-bounds.js.map +0 -1
- package/dist/earcut.d.ts.map +0 -1
- package/dist/earcut.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lineclip.d.ts.map +0 -1
- package/dist/lineclip.js.map +0 -1
- package/dist/polygon-utils.d.ts.map +0 -1
- package/dist/polygon-utils.js.map +0 -1
- package/dist/polygon.d.ts.map +0 -1
- package/dist/polygon.js.map +0 -1
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js.map +0 -1
package/dist/earcut.js
CHANGED
|
@@ -1,557 +1,644 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
let outerNode = linkedList(positions, 0, outerLen, dim, true, areas && areas[0], plane);
|
|
7
|
-
const triangles = [];
|
|
8
|
-
if (!outerNode || outerNode.next === outerNode.prev) return triangles;
|
|
9
|
-
let invSize;
|
|
10
|
-
let maxX;
|
|
11
|
-
let maxY;
|
|
12
|
-
let minX;
|
|
13
|
-
let minY;
|
|
14
|
-
let x;
|
|
15
|
-
let y;
|
|
16
|
-
if (hasHoles) outerNode = eliminateHoles(positions, holeIndices, outerNode, dim, areas, plane);
|
|
1
|
+
/*
|
|
2
|
+
Adapted from https://github.com/mapbox/earcut to allow passing in
|
|
3
|
+
of outline and hole areas using the `areas` parameter. As the
|
|
4
|
+
areas are calcuted as part of classifying the polygon rings
|
|
5
|
+
we can pass them in again to avoid recomputation
|
|
17
6
|
|
|
18
|
-
|
|
19
|
-
minX = maxX = positions[0];
|
|
20
|
-
minY = maxY = positions[1];
|
|
7
|
+
ISC License
|
|
21
8
|
|
|
22
|
-
|
|
23
|
-
x = positions[i];
|
|
24
|
-
y = positions[i + 1];
|
|
25
|
-
if (x < minX) minX = x;
|
|
26
|
-
if (y < minY) minY = y;
|
|
27
|
-
if (x > maxX) maxX = x;
|
|
28
|
-
if (y > maxY) maxY = y;
|
|
29
|
-
}
|
|
9
|
+
Copyright (c) 2016, Mapbox
|
|
30
10
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
11
|
+
Permission to use, copy, modify, and/or distribute this software for any purpose
|
|
12
|
+
with or without fee is hereby granted, provided that the above copyright notice
|
|
13
|
+
and this permission notice appear in all copies.
|
|
34
14
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
16
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
17
|
+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
18
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
19
|
+
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
20
|
+
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
|
21
|
+
THIS SOFTWARE.
|
|
38
22
|
|
|
23
|
+
*/
|
|
24
|
+
import { getPolygonSignedArea, DimIndex } from "./polygon-utils.js";
|
|
25
|
+
/**
|
|
26
|
+
* Computes a triangulation of a polygon
|
|
27
|
+
* @param positions a flat array of the vertex positions that define the polygon.
|
|
28
|
+
* @param holeIndices an array of hole indices if any (e.g. [5, 8] for a 12-vertex input would mean one hole with vertices 5–7 and another with 8–11).
|
|
29
|
+
* @param dim the number of elements in each vertex. Size `2` will interpret `positions` as `[x0, y0, x1, y1, ...]` and size `3` will interpret `positions` as `[x0, y0, z0, x1, y1, z1, ...]`. Default `2`.
|
|
30
|
+
* @param areas areas of outer polygon and holes as computed by `getPolygonSignedArea()`. Can be optionally supplied to speed up triangulation
|
|
31
|
+
* @returns array of indices into the `positions` array that describes the triangulation of the polygon
|
|
32
|
+
* Adapted from https://github.com/mapbox/earcut
|
|
33
|
+
*/
|
|
34
|
+
export function earcut(positions, holeIndices, dim = 2, areas, plane = 'xy') {
|
|
35
|
+
const hasHoles = holeIndices && holeIndices.length;
|
|
36
|
+
const outerLen = hasHoles ? holeIndices[0] * dim : positions.length;
|
|
37
|
+
let outerNode = linkedList(positions, 0, outerLen, dim, true, areas && areas[0], plane);
|
|
38
|
+
const triangles = [];
|
|
39
|
+
if (!outerNode || outerNode.next === outerNode.prev)
|
|
40
|
+
return triangles;
|
|
41
|
+
let invSize;
|
|
42
|
+
let maxX;
|
|
43
|
+
let maxY;
|
|
44
|
+
let minX;
|
|
45
|
+
let minY;
|
|
46
|
+
let x;
|
|
47
|
+
let y;
|
|
48
|
+
if (hasHoles)
|
|
49
|
+
outerNode = eliminateHoles(positions, holeIndices, outerNode, dim, areas, plane);
|
|
50
|
+
// if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
|
|
51
|
+
if (positions.length > 80 * dim) {
|
|
52
|
+
minX = maxX = positions[0];
|
|
53
|
+
minY = maxY = positions[1];
|
|
54
|
+
for (let i = dim; i < outerLen; i += dim) {
|
|
55
|
+
x = positions[i];
|
|
56
|
+
y = positions[i + 1];
|
|
57
|
+
if (x < minX)
|
|
58
|
+
minX = x;
|
|
59
|
+
if (y < minY)
|
|
60
|
+
minY = y;
|
|
61
|
+
if (x > maxX)
|
|
62
|
+
maxX = x;
|
|
63
|
+
if (y > maxY)
|
|
64
|
+
maxY = y;
|
|
65
|
+
}
|
|
66
|
+
// minX, minY and invSize are later used to transform coords into integers for z-order calculation
|
|
67
|
+
invSize = Math.max(maxX - minX, maxY - minY);
|
|
68
|
+
invSize = invSize !== 0 ? 32767 / invSize : 0;
|
|
69
|
+
}
|
|
70
|
+
earcutLinked(outerNode, triangles, dim, minX, minY, invSize, 0);
|
|
71
|
+
return triangles;
|
|
72
|
+
}
|
|
73
|
+
// create a circular doubly linked list from polygon points in the specified winding order
|
|
39
74
|
function linkedList(data, start, end, dim, clockwise, area, plane) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
last = last.next;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return last;
|
|
75
|
+
let i;
|
|
76
|
+
let last;
|
|
77
|
+
if (area === undefined) {
|
|
78
|
+
area = getPolygonSignedArea(data, { start, end, size: dim, plane });
|
|
79
|
+
}
|
|
80
|
+
let i0 = DimIndex[plane[0]];
|
|
81
|
+
let i1 = DimIndex[plane[1]];
|
|
82
|
+
// Note that the signed area calculation in math.gl
|
|
83
|
+
// has the opposite sign to that which was originally
|
|
84
|
+
// present in earcut, thus the `< 0` is reversed
|
|
85
|
+
if (clockwise === area < 0) {
|
|
86
|
+
for (i = start; i < end; i += dim)
|
|
87
|
+
last = insertNode(i, data[i + i0], data[i + i1], last);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
for (i = end - dim; i >= start; i -= dim)
|
|
91
|
+
last = insertNode(i, data[i + i0], data[i + i1], last);
|
|
92
|
+
}
|
|
93
|
+
if (last && equals(last, last.next)) {
|
|
94
|
+
removeNode(last);
|
|
95
|
+
last = last.next;
|
|
96
|
+
}
|
|
97
|
+
return last;
|
|
67
98
|
}
|
|
68
|
-
|
|
99
|
+
// eliminate colinear or duplicate points
|
|
69
100
|
function filterPoints(start, end) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
101
|
+
if (!start)
|
|
102
|
+
return start;
|
|
103
|
+
if (!end)
|
|
104
|
+
end = start;
|
|
105
|
+
let p = start;
|
|
106
|
+
let again;
|
|
107
|
+
do {
|
|
108
|
+
again = false;
|
|
109
|
+
if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
|
|
110
|
+
removeNode(p);
|
|
111
|
+
p = end = p.prev;
|
|
112
|
+
if (p === p.next)
|
|
113
|
+
break;
|
|
114
|
+
again = true;
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
p = p.next;
|
|
118
|
+
}
|
|
119
|
+
} while (again || p !== end);
|
|
120
|
+
return end;
|
|
89
121
|
}
|
|
90
|
-
|
|
122
|
+
// main ear slicing loop which triangulates a polygon (given as a linked list)
|
|
91
123
|
function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
124
|
+
if (!ear)
|
|
125
|
+
return;
|
|
126
|
+
// interlink polygon nodes in z-order
|
|
127
|
+
if (!pass && invSize)
|
|
128
|
+
indexCurve(ear, minX, minY, invSize);
|
|
129
|
+
let stop = ear;
|
|
130
|
+
let prev;
|
|
131
|
+
let next;
|
|
132
|
+
// iterate through ears, slicing them one by one
|
|
133
|
+
while (ear.prev !== ear.next) {
|
|
134
|
+
prev = ear.prev;
|
|
135
|
+
next = ear.next;
|
|
136
|
+
if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
|
|
137
|
+
// cut off the triangle
|
|
138
|
+
triangles.push((prev.i / dim) | 0);
|
|
139
|
+
triangles.push((ear.i / dim) | 0);
|
|
140
|
+
triangles.push((next.i / dim) | 0);
|
|
141
|
+
removeNode(ear);
|
|
142
|
+
// skipping the next vertex leads to less sliver triangles
|
|
143
|
+
ear = next.next;
|
|
144
|
+
stop = next.next;
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
ear = next;
|
|
148
|
+
// if we looped through the whole remaining polygon and can't find any more ears
|
|
149
|
+
if (ear === stop) {
|
|
150
|
+
// try filtering points and slicing again
|
|
151
|
+
if (!pass) {
|
|
152
|
+
earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);
|
|
153
|
+
// if this didn't work, try curing all small self-intersections locally
|
|
154
|
+
}
|
|
155
|
+
else if (pass === 1) {
|
|
156
|
+
ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
|
|
157
|
+
earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
|
|
158
|
+
// as a last resort, try splitting the remaining polygon into two
|
|
159
|
+
}
|
|
160
|
+
else if (pass === 2) {
|
|
161
|
+
splitEarcut(ear, triangles, dim, minX, minY, invSize);
|
|
162
|
+
}
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
125
165
|
}
|
|
126
|
-
}
|
|
127
166
|
}
|
|
128
|
-
|
|
167
|
+
// check whether a polygon node forms a valid ear with adjacent nodes
|
|
129
168
|
function isEar(ear) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
p
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
169
|
+
const a = ear.prev;
|
|
170
|
+
const b = ear;
|
|
171
|
+
const c = ear.next;
|
|
172
|
+
if (area(a, b, c) >= 0)
|
|
173
|
+
return false; // reflex, can't be an ear
|
|
174
|
+
// now make sure we don't have other points inside the potential ear
|
|
175
|
+
const ax = a.x;
|
|
176
|
+
const bx = b.x;
|
|
177
|
+
const cx = c.x;
|
|
178
|
+
const ay = a.y;
|
|
179
|
+
const by = b.y;
|
|
180
|
+
const cy = c.y;
|
|
181
|
+
// triangle bbox; min & max are calculated like this for speed
|
|
182
|
+
const x0 = ax < bx ? (ax < cx ? ax : cx) : bx < cx ? bx : cx;
|
|
183
|
+
const y0 = ay < by ? (ay < cy ? ay : cy) : by < cy ? by : cy;
|
|
184
|
+
const x1 = ax > bx ? (ax > cx ? ax : cx) : bx > cx ? bx : cx;
|
|
185
|
+
const y1 = ay > by ? (ay > cy ? ay : cy) : by > cy ? by : cy;
|
|
186
|
+
let p = c.next;
|
|
187
|
+
while (p !== a) {
|
|
188
|
+
if (p.x >= x0 &&
|
|
189
|
+
p.x <= x1 &&
|
|
190
|
+
p.y >= y0 &&
|
|
191
|
+
p.y <= y1 &&
|
|
192
|
+
pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) &&
|
|
193
|
+
area(p.prev, p, p.next) >= 0)
|
|
194
|
+
return false;
|
|
195
|
+
p = p.next;
|
|
196
|
+
}
|
|
197
|
+
return true;
|
|
152
198
|
}
|
|
153
|
-
|
|
154
199
|
function isEarHashed(ear, minX, minY, invSize) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
200
|
+
const a = ear.prev;
|
|
201
|
+
const b = ear;
|
|
202
|
+
const c = ear.next;
|
|
203
|
+
if (area(a, b, c) >= 0)
|
|
204
|
+
return false; // reflex, can't be an ear
|
|
205
|
+
const ax = a.x;
|
|
206
|
+
const bx = b.x;
|
|
207
|
+
const cx = c.x;
|
|
208
|
+
const ay = a.y;
|
|
209
|
+
const by = b.y;
|
|
210
|
+
const cy = c.y;
|
|
211
|
+
// triangle bbox; min & max are calculated like this for speed
|
|
212
|
+
const x0 = ax < bx ? (ax < cx ? ax : cx) : bx < cx ? bx : cx;
|
|
213
|
+
const y0 = ay < by ? (ay < cy ? ay : cy) : by < cy ? by : cy;
|
|
214
|
+
const x1 = ax > bx ? (ax > cx ? ax : cx) : bx > cx ? bx : cx;
|
|
215
|
+
const y1 = ay > by ? (ay > cy ? ay : cy) : by > cy ? by : cy;
|
|
216
|
+
// z-order range for the current triangle bbox;
|
|
217
|
+
const minZ = zOrder(x0, y0, minX, minY, invSize);
|
|
218
|
+
const maxZ = zOrder(x1, y1, minX, minY, invSize);
|
|
219
|
+
let p = ear.prevZ;
|
|
220
|
+
let n = ear.nextZ;
|
|
221
|
+
// look for points inside the triangle in both directions
|
|
222
|
+
while (p && p.z >= minZ && n && n.z <= maxZ) {
|
|
223
|
+
if (p.x >= x0 &&
|
|
224
|
+
p.x <= x1 &&
|
|
225
|
+
p.y >= y0 &&
|
|
226
|
+
p.y <= y1 &&
|
|
227
|
+
p !== a &&
|
|
228
|
+
p !== c &&
|
|
229
|
+
pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) &&
|
|
230
|
+
area(p.prev, p, p.next) >= 0)
|
|
231
|
+
return false;
|
|
232
|
+
p = p.prevZ;
|
|
233
|
+
if (n.x >= x0 &&
|
|
234
|
+
n.x <= x1 &&
|
|
235
|
+
n.y >= y0 &&
|
|
236
|
+
n.y <= y1 &&
|
|
237
|
+
n !== a &&
|
|
238
|
+
n !== c &&
|
|
239
|
+
pointInTriangle(ax, ay, bx, by, cx, cy, n.x, n.y) &&
|
|
240
|
+
area(n.prev, n, n.next) >= 0)
|
|
241
|
+
return false;
|
|
242
|
+
n = n.nextZ;
|
|
243
|
+
}
|
|
244
|
+
// look for remaining points in decreasing z-order
|
|
245
|
+
while (p && p.z >= minZ) {
|
|
246
|
+
if (p.x >= x0 &&
|
|
247
|
+
p.x <= x1 &&
|
|
248
|
+
p.y >= y0 &&
|
|
249
|
+
p.y <= y1 &&
|
|
250
|
+
p !== a &&
|
|
251
|
+
p !== c &&
|
|
252
|
+
pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) &&
|
|
253
|
+
area(p.prev, p, p.next) >= 0)
|
|
254
|
+
return false;
|
|
255
|
+
p = p.prevZ;
|
|
256
|
+
}
|
|
257
|
+
// look for remaining points in increasing z-order
|
|
258
|
+
while (n && n.z <= maxZ) {
|
|
259
|
+
if (n.x >= x0 &&
|
|
260
|
+
n.x <= x1 &&
|
|
261
|
+
n.y >= y0 &&
|
|
262
|
+
n.y <= y1 &&
|
|
263
|
+
n !== a &&
|
|
264
|
+
n !== c &&
|
|
265
|
+
pointInTriangle(ax, ay, bx, by, cx, cy, n.x, n.y) &&
|
|
266
|
+
area(n.prev, n, n.next) >= 0)
|
|
267
|
+
return false;
|
|
268
|
+
n = n.nextZ;
|
|
269
|
+
}
|
|
270
|
+
return true;
|
|
192
271
|
}
|
|
193
|
-
|
|
272
|
+
// go through all polygon nodes and cure small local self-intersections
|
|
194
273
|
function cureLocalIntersections(start, triangles, dim) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
274
|
+
let p = start;
|
|
275
|
+
do {
|
|
276
|
+
const a = p.prev;
|
|
277
|
+
const b = p.next.next;
|
|
278
|
+
if (!equals(a, b) &&
|
|
279
|
+
intersects(a, p, p.next, b) &&
|
|
280
|
+
locallyInside(a, b) &&
|
|
281
|
+
locallyInside(b, a)) {
|
|
282
|
+
triangles.push((a.i / dim) | 0);
|
|
283
|
+
triangles.push((p.i / dim) | 0);
|
|
284
|
+
triangles.push((b.i / dim) | 0);
|
|
285
|
+
// remove two nodes involved
|
|
286
|
+
removeNode(p);
|
|
287
|
+
removeNode(p.next);
|
|
288
|
+
p = start = b;
|
|
289
|
+
}
|
|
290
|
+
p = p.next;
|
|
291
|
+
} while (p !== start);
|
|
292
|
+
return filterPoints(p);
|
|
214
293
|
}
|
|
215
|
-
|
|
294
|
+
// try splitting polygon into two and triangulate them independently
|
|
216
295
|
function splitEarcut(start, triangles, dim, minX, minY, invSize) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
296
|
+
// look for a valid diagonal that divides the polygon into two
|
|
297
|
+
let a = start;
|
|
298
|
+
do {
|
|
299
|
+
let b = a.next.next;
|
|
300
|
+
while (b !== a.prev) {
|
|
301
|
+
if (a.i !== b.i && isValidDiagonal(a, b)) {
|
|
302
|
+
// split the polygon in two by the diagonal
|
|
303
|
+
let c = splitPolygon(a, b);
|
|
304
|
+
// filter colinear points around the cuts
|
|
305
|
+
a = filterPoints(a, a.next);
|
|
306
|
+
c = filterPoints(c, c.next);
|
|
307
|
+
// run earcut on each half
|
|
308
|
+
earcutLinked(a, triangles, dim, minX, minY, invSize, 0);
|
|
309
|
+
earcutLinked(c, triangles, dim, minX, minY, invSize, 0);
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
b = b.next;
|
|
313
|
+
}
|
|
314
|
+
a = a.next;
|
|
315
|
+
} while (a !== start);
|
|
237
316
|
}
|
|
238
|
-
|
|
317
|
+
// link every hole into the outer loop, producing a single-ring polygon without holes
|
|
239
318
|
function eliminateHoles(data, holeIndices, outerNode, dim, areas, plane) {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
return outerNode;
|
|
319
|
+
const queue = [];
|
|
320
|
+
let i;
|
|
321
|
+
let len;
|
|
322
|
+
let start;
|
|
323
|
+
let end;
|
|
324
|
+
let list;
|
|
325
|
+
for (i = 0, len = holeIndices.length; i < len; i++) {
|
|
326
|
+
start = holeIndices[i] * dim;
|
|
327
|
+
end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
|
|
328
|
+
list = linkedList(data, start, end, dim, false, areas && areas[i + 1], plane);
|
|
329
|
+
if (list === list.next)
|
|
330
|
+
list.steiner = true;
|
|
331
|
+
queue.push(getLeftmost(list));
|
|
332
|
+
}
|
|
333
|
+
queue.sort(compareX);
|
|
334
|
+
// process holes from left to right
|
|
335
|
+
for (i = 0; i < queue.length; i++) {
|
|
336
|
+
outerNode = eliminateHole(queue[i], outerNode);
|
|
337
|
+
}
|
|
338
|
+
return outerNode;
|
|
262
339
|
}
|
|
263
|
-
|
|
264
340
|
function compareX(a, b) {
|
|
265
|
-
|
|
341
|
+
return a.x - b.x;
|
|
266
342
|
}
|
|
267
|
-
|
|
343
|
+
// find a bridge between vertices that connects hole with an outer ring and and link it
|
|
268
344
|
function eliminateHole(hole, outerNode) {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
return filterPoints(bridge, bridge.next);
|
|
345
|
+
const bridge = findHoleBridge(hole, outerNode);
|
|
346
|
+
if (!bridge) {
|
|
347
|
+
return outerNode;
|
|
348
|
+
}
|
|
349
|
+
const bridgeReverse = splitPolygon(bridge, hole);
|
|
350
|
+
// filter collinear points around the cuts
|
|
351
|
+
filterPoints(bridgeReverse, bridgeReverse.next);
|
|
352
|
+
return filterPoints(bridge, bridge.next);
|
|
278
353
|
}
|
|
279
|
-
|
|
354
|
+
// David Eberly's algorithm for finding a bridge between hole and outer polygon
|
|
280
355
|
function findHoleBridge(hole, outerNode) {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
356
|
+
let p = outerNode;
|
|
357
|
+
const hx = hole.x;
|
|
358
|
+
const hy = hole.y;
|
|
359
|
+
let qx = -Infinity;
|
|
360
|
+
let m;
|
|
361
|
+
// find a segment intersected by a ray from the hole's leftmost point to the left;
|
|
362
|
+
// segment's endpoint with lesser x will be potential connection point
|
|
363
|
+
do {
|
|
364
|
+
if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
|
|
365
|
+
const x = p.x + ((hy - p.y) * (p.next.x - p.x)) / (p.next.y - p.y);
|
|
366
|
+
if (x <= hx && x > qx) {
|
|
367
|
+
qx = x;
|
|
368
|
+
m = p.x < p.next.x ? p : p.next;
|
|
369
|
+
if (x === hx)
|
|
370
|
+
return m; // hole touches outer segment; pick leftmost endpoint
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
p = p.next;
|
|
374
|
+
} while (p !== outerNode);
|
|
375
|
+
if (!m)
|
|
376
|
+
return null;
|
|
377
|
+
// look for points inside the triangle of hole point, segment intersection and endpoint;
|
|
378
|
+
// if there are no points found, we have a valid connection;
|
|
379
|
+
// otherwise choose the point of the minimum angle with the ray as connection point
|
|
380
|
+
const stop = m;
|
|
381
|
+
const mx = m.x;
|
|
382
|
+
const my = m.y;
|
|
383
|
+
let tanMin = Infinity;
|
|
384
|
+
let tan;
|
|
385
|
+
p = m;
|
|
386
|
+
do {
|
|
387
|
+
if (hx >= p.x &&
|
|
388
|
+
p.x >= mx &&
|
|
389
|
+
hx !== p.x &&
|
|
390
|
+
pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {
|
|
391
|
+
tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
|
|
392
|
+
if (locallyInside(p, hole) &&
|
|
393
|
+
(tan < tanMin ||
|
|
394
|
+
(tan === tanMin && (p.x > m.x || (p.x === m.x && sectorContainsSector(m, p)))))) {
|
|
395
|
+
m = p;
|
|
396
|
+
tanMin = tan;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
p = p.next;
|
|
400
|
+
} while (p !== stop);
|
|
401
|
+
return m;
|
|
323
402
|
}
|
|
324
|
-
|
|
403
|
+
// whether sector in vertex m contains sector in vertex p in the same coordinates
|
|
325
404
|
function sectorContainsSector(m, p) {
|
|
326
|
-
|
|
405
|
+
return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
|
|
327
406
|
}
|
|
328
|
-
|
|
407
|
+
// interlink polygon nodes in z-order
|
|
329
408
|
function indexCurve(start, minX, minY, invSize) {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
sortLinked(p);
|
|
409
|
+
let p = start;
|
|
410
|
+
do {
|
|
411
|
+
if (p.z === 0)
|
|
412
|
+
p.z = zOrder(p.x, p.y, minX, minY, invSize);
|
|
413
|
+
p.prevZ = p.prev;
|
|
414
|
+
p.nextZ = p.next;
|
|
415
|
+
p = p.next;
|
|
416
|
+
} while (p !== start);
|
|
417
|
+
p.prevZ.nextZ = null;
|
|
418
|
+
p.prevZ = null;
|
|
419
|
+
sortLinked(p);
|
|
342
420
|
}
|
|
343
|
-
|
|
421
|
+
// Simon Tatham's linked list merge sort algorithm
|
|
422
|
+
// http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
|
|
344
423
|
function sortLinked(list) {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
424
|
+
let e;
|
|
425
|
+
let i;
|
|
426
|
+
let inSize = 1;
|
|
427
|
+
let numMerges;
|
|
428
|
+
let p;
|
|
429
|
+
let pSize;
|
|
430
|
+
let q;
|
|
431
|
+
let qSize;
|
|
432
|
+
let tail;
|
|
433
|
+
do {
|
|
434
|
+
p = list;
|
|
435
|
+
list = null;
|
|
436
|
+
tail = null;
|
|
437
|
+
numMerges = 0;
|
|
438
|
+
while (p) {
|
|
439
|
+
numMerges++;
|
|
440
|
+
q = p;
|
|
441
|
+
pSize = 0;
|
|
442
|
+
for (i = 0; i < inSize; i++) {
|
|
443
|
+
pSize++;
|
|
444
|
+
q = q.nextZ;
|
|
445
|
+
if (!q)
|
|
446
|
+
break;
|
|
447
|
+
}
|
|
448
|
+
qSize = inSize;
|
|
449
|
+
while (pSize > 0 || (qSize > 0 && q)) {
|
|
450
|
+
if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
|
|
451
|
+
e = p;
|
|
452
|
+
p = p.nextZ;
|
|
453
|
+
pSize--;
|
|
454
|
+
}
|
|
455
|
+
else {
|
|
456
|
+
e = q;
|
|
457
|
+
q = q.nextZ;
|
|
458
|
+
qSize--;
|
|
459
|
+
}
|
|
460
|
+
if (tail)
|
|
461
|
+
tail.nextZ = e;
|
|
462
|
+
else
|
|
463
|
+
list = e;
|
|
464
|
+
e.prevZ = tail;
|
|
465
|
+
tail = e;
|
|
466
|
+
}
|
|
467
|
+
p = q;
|
|
383
468
|
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
p = q;
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
tail.nextZ = null;
|
|
394
|
-
inSize *= 2;
|
|
395
|
-
} while (numMerges > 1);
|
|
396
|
-
|
|
397
|
-
return list;
|
|
469
|
+
tail.nextZ = null;
|
|
470
|
+
inSize *= 2;
|
|
471
|
+
} while (numMerges > 1);
|
|
472
|
+
return list;
|
|
398
473
|
}
|
|
399
|
-
|
|
474
|
+
// z-order of a point given coords and inverse of the longer side of data bbox
|
|
400
475
|
function zOrder(x, y, minX, minY, invSize) {
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
476
|
+
// coords are transformed into non-negative 15-bit integer range
|
|
477
|
+
x = ((x - minX) * invSize) | 0;
|
|
478
|
+
y = ((y - minY) * invSize) | 0;
|
|
479
|
+
x = (x | (x << 8)) & 0x00ff00ff;
|
|
480
|
+
x = (x | (x << 4)) & 0x0f0f0f0f;
|
|
481
|
+
x = (x | (x << 2)) & 0x33333333;
|
|
482
|
+
x = (x | (x << 1)) & 0x55555555;
|
|
483
|
+
y = (y | (y << 8)) & 0x00ff00ff;
|
|
484
|
+
y = (y | (y << 4)) & 0x0f0f0f0f;
|
|
485
|
+
y = (y | (y << 2)) & 0x33333333;
|
|
486
|
+
y = (y | (y << 1)) & 0x55555555;
|
|
487
|
+
return x | (y << 1);
|
|
412
488
|
}
|
|
413
|
-
|
|
489
|
+
// find the leftmost node of a polygon ring
|
|
414
490
|
function getLeftmost(start) {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
return leftmost;
|
|
491
|
+
let p = start;
|
|
492
|
+
let leftmost = start;
|
|
493
|
+
do {
|
|
494
|
+
if (p.x < leftmost.x || (p.x === leftmost.x && p.y < leftmost.y))
|
|
495
|
+
leftmost = p;
|
|
496
|
+
p = p.next;
|
|
497
|
+
} while (p !== start);
|
|
498
|
+
return leftmost;
|
|
424
499
|
}
|
|
425
|
-
|
|
500
|
+
// check if a point lies within a convex triangle
|
|
426
501
|
function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
|
|
427
|
-
|
|
502
|
+
return ((cx - px) * (ay - py) >= (ax - px) * (cy - py) &&
|
|
503
|
+
(ax - px) * (by - py) >= (bx - px) * (ay - py) &&
|
|
504
|
+
(bx - px) * (cy - py) >= (cx - px) * (by - py));
|
|
428
505
|
}
|
|
429
|
-
|
|
506
|
+
// check if a diagonal between two polygon nodes is valid (lies in polygon interior)
|
|
430
507
|
function isValidDiagonal(a, b) {
|
|
431
|
-
|
|
508
|
+
return (a.next.i !== b.i &&
|
|
509
|
+
a.prev.i !== b.i &&
|
|
510
|
+
!intersectsPolygon(a, b) && // dones't intersect other edges
|
|
511
|
+
((locallyInside(a, b) &&
|
|
512
|
+
locallyInside(b, a) &&
|
|
513
|
+
middleInside(a, b) && // locally visible
|
|
514
|
+
(area(a.prev, a, b.prev) || area(a, b.prev, b))) || // does not create opposite-facing sectors
|
|
515
|
+
(equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0))); // special zero-length case
|
|
432
516
|
}
|
|
433
|
-
|
|
517
|
+
// signed area of a triangle
|
|
434
518
|
function area(p, q, r) {
|
|
435
|
-
|
|
519
|
+
return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
|
|
436
520
|
}
|
|
437
|
-
|
|
521
|
+
// check if two points are equal
|
|
438
522
|
function equals(p1, p2) {
|
|
439
|
-
|
|
523
|
+
return p1.x === p2.x && p1.y === p2.y;
|
|
440
524
|
}
|
|
441
|
-
|
|
525
|
+
// check if two segments intersect
|
|
442
526
|
function intersects(p1, q1, p2, q2) {
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
527
|
+
const o1 = sign(area(p1, q1, p2));
|
|
528
|
+
const o2 = sign(area(p1, q1, q2));
|
|
529
|
+
const o3 = sign(area(p2, q2, p1));
|
|
530
|
+
const o4 = sign(area(p2, q2, q1));
|
|
531
|
+
if (o1 !== o2 && o3 !== o4)
|
|
532
|
+
return true; // general case
|
|
533
|
+
if (o1 === 0 && onSegment(p1, p2, q1))
|
|
534
|
+
return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
|
|
535
|
+
if (o2 === 0 && onSegment(p1, q2, q1))
|
|
536
|
+
return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
|
|
537
|
+
if (o3 === 0 && onSegment(p2, p1, q2))
|
|
538
|
+
return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
|
|
539
|
+
if (o4 === 0 && onSegment(p2, q1, q2))
|
|
540
|
+
return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
|
|
541
|
+
return false;
|
|
453
542
|
}
|
|
454
|
-
|
|
543
|
+
// for collinear points p, q, r, check if point q lies on segment pr
|
|
455
544
|
function onSegment(p, q, r) {
|
|
456
|
-
|
|
545
|
+
return (q.x <= Math.max(p.x, r.x) &&
|
|
546
|
+
q.x >= Math.min(p.x, r.x) &&
|
|
547
|
+
q.y <= Math.max(p.y, r.y) &&
|
|
548
|
+
q.y >= Math.min(p.y, r.y));
|
|
457
549
|
}
|
|
458
|
-
|
|
459
550
|
function sign(num) {
|
|
460
|
-
|
|
551
|
+
return num > 0 ? 1 : num < 0 ? -1 : 0;
|
|
461
552
|
}
|
|
462
|
-
|
|
553
|
+
// check if a polygon diagonal intersects any polygon segments
|
|
463
554
|
function intersectsPolygon(a, b) {
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
555
|
+
let p = a;
|
|
556
|
+
do {
|
|
557
|
+
if (p.i !== a.i &&
|
|
558
|
+
p.next.i !== a.i &&
|
|
559
|
+
p.i !== b.i &&
|
|
560
|
+
p.next.i !== b.i &&
|
|
561
|
+
intersects(p, p.next, a, b))
|
|
562
|
+
return true;
|
|
563
|
+
p = p.next;
|
|
564
|
+
} while (p !== a);
|
|
565
|
+
return false;
|
|
472
566
|
}
|
|
473
|
-
|
|
567
|
+
// check if a polygon diagonal is locally inside the polygon
|
|
474
568
|
function locallyInside(a, b) {
|
|
475
|
-
|
|
569
|
+
return area(a.prev, a, a.next) < 0
|
|
570
|
+
? area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0
|
|
571
|
+
: area(a, b, a.prev) < 0 || area(a, a.next, b) < 0;
|
|
476
572
|
}
|
|
477
|
-
|
|
573
|
+
// check if the middle point of a polygon diagonal is inside the polygon
|
|
478
574
|
function middleInside(a, b) {
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
575
|
+
let p = a;
|
|
576
|
+
let inside = false;
|
|
577
|
+
const px = (a.x + b.x) / 2;
|
|
578
|
+
const py = (a.y + b.y) / 2;
|
|
579
|
+
do {
|
|
580
|
+
if (p.y > py !== p.next.y > py &&
|
|
581
|
+
p.next.y !== p.y &&
|
|
582
|
+
px < ((p.next.x - p.x) * (py - p.y)) / (p.next.y - p.y) + p.x)
|
|
583
|
+
inside = !inside;
|
|
584
|
+
p = p.next;
|
|
585
|
+
} while (p !== a);
|
|
586
|
+
return inside;
|
|
490
587
|
}
|
|
491
|
-
|
|
588
|
+
// link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
|
|
589
|
+
// if one belongs to the outer ring and another to a hole, it merges it into a single ring
|
|
492
590
|
function splitPolygon(a, b) {
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
591
|
+
const a2 = new Vertex(a.i, a.x, a.y);
|
|
592
|
+
const b2 = new Vertex(b.i, b.x, b.y);
|
|
593
|
+
const an = a.next;
|
|
594
|
+
const bp = b.prev;
|
|
595
|
+
a.next = b;
|
|
596
|
+
b.prev = a;
|
|
597
|
+
a2.next = an;
|
|
598
|
+
an.prev = a2;
|
|
599
|
+
b2.next = a2;
|
|
600
|
+
a2.prev = b2;
|
|
601
|
+
bp.next = b2;
|
|
602
|
+
b2.prev = bp;
|
|
603
|
+
return b2;
|
|
506
604
|
}
|
|
507
|
-
|
|
605
|
+
// create a node and optionally link it with previous one (in a circular doubly linked list)
|
|
508
606
|
function insertNode(i, x, y, last) {
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
return p;
|
|
607
|
+
const p = new Vertex(i, x, y);
|
|
608
|
+
if (!last) {
|
|
609
|
+
p.prev = p;
|
|
610
|
+
p.next = p;
|
|
611
|
+
}
|
|
612
|
+
else {
|
|
613
|
+
p.next = last.next;
|
|
614
|
+
p.prev = last;
|
|
615
|
+
last.next.prev = p;
|
|
616
|
+
last.next = p;
|
|
617
|
+
}
|
|
618
|
+
return p;
|
|
522
619
|
}
|
|
523
|
-
|
|
524
620
|
function removeNode(p) {
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
621
|
+
p.next.prev = p.prev;
|
|
622
|
+
p.prev.next = p.next;
|
|
623
|
+
if (p.prevZ)
|
|
624
|
+
p.prevZ.nextZ = p.nextZ;
|
|
625
|
+
if (p.nextZ)
|
|
626
|
+
p.nextZ.prevZ = p.prevZ;
|
|
529
627
|
}
|
|
530
|
-
|
|
531
628
|
class Vertex {
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
_defineProperty(this, "nextZ", null);
|
|
548
|
-
|
|
549
|
-
_defineProperty(this, "steiner", false);
|
|
550
|
-
|
|
551
|
-
this.i = i;
|
|
552
|
-
this.x = x;
|
|
553
|
-
this.y = y;
|
|
554
|
-
}
|
|
555
|
-
|
|
629
|
+
constructor(i, x, y) {
|
|
630
|
+
// previous and next vertex nodes in a polygon ring
|
|
631
|
+
this.prev = null;
|
|
632
|
+
this.next = null;
|
|
633
|
+
// z-order curve value
|
|
634
|
+
this.z = 0;
|
|
635
|
+
// previous and next nodes in z-order
|
|
636
|
+
this.prevZ = null;
|
|
637
|
+
this.nextZ = null;
|
|
638
|
+
// indicates whether this is a steiner point
|
|
639
|
+
this.steiner = false;
|
|
640
|
+
this.i = i;
|
|
641
|
+
this.x = x;
|
|
642
|
+
this.y = y;
|
|
643
|
+
}
|
|
556
644
|
}
|
|
557
|
-
//# sourceMappingURL=earcut.js.map
|