poly-extrude 0.20.3 → 0.20.5
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/poly-extrude.js +4511 -4547
- package/dist/poly-extrude.js.map +1 -1
- package/dist/poly-extrude.min.js +2 -2
- package/dist/poly-extrude.mjs +194 -230
- package/dist/poly-extrude.mjs.map +1 -1
- package/dist/polyline.d.ts +5 -4
- package/dist/polyline.js +40 -23
- package/dist/polyline.js.map +1 -1
- package/package.json +1 -1
- package/readme.md +1 -0
- package/src/polyline.ts +50 -31
package/dist/poly-extrude.mjs
CHANGED
@@ -1,29 +1,62 @@
|
|
1
1
|
/*!
|
2
|
-
* poly-extrude v0.20.
|
2
|
+
* poly-extrude v0.20.5
|
3
3
|
*/
|
4
|
-
|
4
|
+
function _defineProperties(target, props) {
|
5
|
+
for (var i = 0; i < props.length; i++) {
|
6
|
+
var descriptor = props[i];
|
7
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
8
|
+
descriptor.configurable = true;
|
9
|
+
if ("value" in descriptor) descriptor.writable = true;
|
10
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
11
|
+
}
|
12
|
+
}
|
5
13
|
|
6
|
-
|
14
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
15
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
16
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
17
|
+
Object.defineProperty(Constructor, "prototype", {
|
18
|
+
writable: false
|
19
|
+
});
|
20
|
+
return Constructor;
|
21
|
+
}
|
22
|
+
|
23
|
+
function _inheritsLoose(subClass, superClass) {
|
24
|
+
subClass.prototype = Object.create(superClass.prototype);
|
25
|
+
subClass.prototype.constructor = subClass;
|
26
|
+
|
27
|
+
_setPrototypeOf(subClass, superClass);
|
28
|
+
}
|
7
29
|
|
8
|
-
|
30
|
+
function _setPrototypeOf(o, p) {
|
31
|
+
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
32
|
+
o.__proto__ = p;
|
33
|
+
return o;
|
34
|
+
};
|
35
|
+
return _setPrototypeOf(o, p);
|
36
|
+
}
|
9
37
|
|
10
38
|
function earcut(data, holeIndices, dim) {
|
11
|
-
dim
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
39
|
+
if (dim === void 0) {
|
40
|
+
dim = 2;
|
41
|
+
}
|
42
|
+
|
43
|
+
var hasHoles = holeIndices && holeIndices.length;
|
44
|
+
var outerLen = hasHoles ? holeIndices[0] * dim : data.length;
|
45
|
+
var outerNode = linkedList(data, 0, outerLen, dim, true);
|
46
|
+
var triangles = [];
|
16
47
|
if (!outerNode || outerNode.next === outerNode.prev) return triangles;
|
17
|
-
var minX, minY,
|
48
|
+
var minX, minY, invSize;
|
18
49
|
if (hasHoles) outerNode = eliminateHoles(data, holeIndices, outerNode, dim); // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
|
19
50
|
|
20
51
|
if (data.length > 80 * dim) {
|
21
|
-
minX =
|
22
|
-
minY =
|
52
|
+
minX = Infinity;
|
53
|
+
minY = Infinity;
|
54
|
+
var maxX = -Infinity;
|
55
|
+
var maxY = -Infinity;
|
23
56
|
|
24
57
|
for (var i = dim; i < outerLen; i += dim) {
|
25
|
-
x = data[i];
|
26
|
-
y = data[i + 1];
|
58
|
+
var x = data[i];
|
59
|
+
var y = data[i + 1];
|
27
60
|
if (x < minX) minX = x;
|
28
61
|
if (y < minY) minY = y;
|
29
62
|
if (x > maxX) maxX = x;
|
@@ -39,17 +72,16 @@ function earcut(data, holeIndices, dim) {
|
|
39
72
|
return triangles;
|
40
73
|
} // create a circular doubly linked list from polygon points in the specified winding order
|
41
74
|
|
42
|
-
|
43
75
|
function linkedList(data, start, end, dim, clockwise) {
|
44
|
-
var
|
76
|
+
var last;
|
45
77
|
|
46
78
|
if (clockwise === signedArea(data, start, end, dim) > 0) {
|
47
|
-
for (i = start; i < end; i += dim) {
|
48
|
-
last = insertNode(i, data[i], data[i + 1], last);
|
79
|
+
for (var i = start; i < end; i += dim) {
|
80
|
+
last = insertNode(i / dim | 0, data[i], data[i + 1], last);
|
49
81
|
}
|
50
82
|
} else {
|
51
|
-
for (
|
52
|
-
last = insertNode(
|
83
|
+
for (var _i = end - dim; _i >= start; _i -= dim) {
|
84
|
+
last = insertNode(_i / dim | 0, data[_i], data[_i + 1], last);
|
53
85
|
}
|
54
86
|
}
|
55
87
|
|
@@ -89,19 +121,15 @@ function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
|
|
89
121
|
if (!ear) return; // interlink polygon nodes in z-order
|
90
122
|
|
91
123
|
if (!pass && invSize) indexCurve(ear, minX, minY, invSize);
|
92
|
-
var stop = ear,
|
93
|
-
prev,
|
94
|
-
next; // iterate through ears, slicing them one by one
|
124
|
+
var stop = ear; // iterate through ears, slicing them one by one
|
95
125
|
|
96
126
|
while (ear.prev !== ear.next) {
|
97
|
-
prev = ear.prev;
|
98
|
-
next = ear.next;
|
127
|
+
var prev = ear.prev;
|
128
|
+
var next = ear.next;
|
99
129
|
|
100
130
|
if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
|
101
|
-
// cut off the triangle
|
102
|
-
|
103
|
-
triangles.push(ear.i / dim | 0);
|
104
|
-
triangles.push(next.i / dim | 0);
|
131
|
+
triangles.push(prev.i, ear.i, next.i); // cut off the triangle
|
132
|
+
|
105
133
|
removeNode(ear); // skipping the next vertex leads to less sliver triangles
|
106
134
|
|
107
135
|
ear = next.next;
|
@@ -116,7 +144,7 @@ function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
|
|
116
144
|
if (!pass) {
|
117
145
|
earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1); // if this didn't work, try curing all small self-intersections locally
|
118
146
|
} else if (pass === 1) {
|
119
|
-
ear = cureLocalIntersections(filterPoints(ear), triangles
|
147
|
+
ear = cureLocalIntersections(filterPoints(ear), triangles);
|
120
148
|
earcutLinked(ear, triangles, dim, minX, minY, invSize, 2); // as a last resort, try splitting the remaining polygon into two
|
121
149
|
} else if (pass === 2) {
|
122
150
|
splitEarcut(ear, triangles, dim, minX, minY, invSize);
|
@@ -140,16 +168,16 @@ function isEar(ear) {
|
|
140
168
|
cx = c.x,
|
141
169
|
ay = a.y,
|
142
170
|
by = b.y,
|
143
|
-
cy = c.y; // triangle bbox
|
171
|
+
cy = c.y; // triangle bbox
|
144
172
|
|
145
|
-
var x0 = ax
|
146
|
-
y0 = ay
|
147
|
-
x1 = ax
|
148
|
-
y1 = ay
|
173
|
+
var x0 = Math.min(ax, bx, cx),
|
174
|
+
y0 = Math.min(ay, by, cy),
|
175
|
+
x1 = Math.max(ax, bx, cx),
|
176
|
+
y1 = Math.max(ay, by, cy);
|
149
177
|
var p = c.next;
|
150
178
|
|
151
179
|
while (p !== a) {
|
152
|
-
if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 &&
|
180
|
+
if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && pointInTriangleExceptFirst(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0) return false;
|
153
181
|
p = p.next;
|
154
182
|
}
|
155
183
|
|
@@ -167,12 +195,12 @@ function isEarHashed(ear, minX, minY, invSize) {
|
|
167
195
|
cx = c.x,
|
168
196
|
ay = a.y,
|
169
197
|
by = b.y,
|
170
|
-
cy = c.y; // triangle bbox
|
198
|
+
cy = c.y; // triangle bbox
|
171
199
|
|
172
|
-
var x0 = ax
|
173
|
-
y0 = ay
|
174
|
-
x1 = ax
|
175
|
-
y1 = ay
|
200
|
+
var x0 = Math.min(ax, bx, cx),
|
201
|
+
y0 = Math.min(ay, by, cy),
|
202
|
+
x1 = Math.max(ax, bx, cx),
|
203
|
+
y1 = Math.max(ay, by, cy); // z-order range for the current triangle bbox;
|
176
204
|
|
177
205
|
var minZ = zOrder(x0, y0, minX, minY, invSize),
|
178
206
|
maxZ = zOrder(x1, y1, minX, minY, invSize);
|
@@ -180,21 +208,21 @@ function isEarHashed(ear, minX, minY, invSize) {
|
|
180
208
|
n = ear.nextZ; // look for points inside the triangle in both directions
|
181
209
|
|
182
210
|
while (p && p.z >= minZ && n && n.z <= maxZ) {
|
183
|
-
if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c &&
|
211
|
+
if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c && pointInTriangleExceptFirst(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0) return false;
|
184
212
|
p = p.prevZ;
|
185
|
-
if (n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c &&
|
213
|
+
if (n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c && pointInTriangleExceptFirst(ax, ay, bx, by, cx, cy, n.x, n.y) && area(n.prev, n, n.next) >= 0) return false;
|
186
214
|
n = n.nextZ;
|
187
215
|
} // look for remaining points in decreasing z-order
|
188
216
|
|
189
217
|
|
190
218
|
while (p && p.z >= minZ) {
|
191
|
-
if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c &&
|
219
|
+
if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c && pointInTriangleExceptFirst(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0) return false;
|
192
220
|
p = p.prevZ;
|
193
221
|
} // look for remaining points in increasing z-order
|
194
222
|
|
195
223
|
|
196
224
|
while (n && n.z <= maxZ) {
|
197
|
-
if (n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c &&
|
225
|
+
if (n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c && pointInTriangleExceptFirst(ax, ay, bx, by, cx, cy, n.x, n.y) && area(n.prev, n, n.next) >= 0) return false;
|
198
226
|
n = n.nextZ;
|
199
227
|
}
|
200
228
|
|
@@ -202,7 +230,7 @@ function isEarHashed(ear, minX, minY, invSize) {
|
|
202
230
|
} // go through all polygon nodes and cure small local self-intersections
|
203
231
|
|
204
232
|
|
205
|
-
function cureLocalIntersections(start, triangles
|
233
|
+
function cureLocalIntersections(start, triangles) {
|
206
234
|
var p = start;
|
207
235
|
|
208
236
|
do {
|
@@ -210,9 +238,7 @@ function cureLocalIntersections(start, triangles, dim) {
|
|
210
238
|
b = p.next.next;
|
211
239
|
|
212
240
|
if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
|
213
|
-
triangles.push(a.i
|
214
|
-
triangles.push(p.i / dim | 0);
|
215
|
-
triangles.push(b.i / dim | 0); // remove two nodes involved
|
241
|
+
triangles.push(a.i, p.i, b.i); // remove two nodes involved
|
216
242
|
|
217
243
|
removeNode(p);
|
218
244
|
removeNode(p.next);
|
@@ -255,32 +281,40 @@ function splitEarcut(start, triangles, dim, minX, minY, invSize) {
|
|
255
281
|
|
256
282
|
|
257
283
|
function eliminateHoles(data, holeIndices, outerNode, dim) {
|
258
|
-
var queue = []
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
for (i = 0, len = holeIndices.length; i < len; i++) {
|
266
|
-
start = holeIndices[i] * dim;
|
267
|
-
end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
|
268
|
-
list = linkedList(data, start, end, dim, false);
|
284
|
+
var queue = [];
|
285
|
+
|
286
|
+
for (var i = 0, len = holeIndices.length; i < len; i++) {
|
287
|
+
var start = holeIndices[i] * dim;
|
288
|
+
var end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
|
289
|
+
var list = linkedList(data, start, end, dim, false);
|
269
290
|
if (list === list.next) list.steiner = true;
|
270
291
|
queue.push(getLeftmost(list));
|
271
292
|
}
|
272
293
|
|
273
|
-
queue.sort(
|
294
|
+
queue.sort(compareXYSlope); // process holes from left to right
|
274
295
|
|
275
|
-
for (
|
276
|
-
outerNode = eliminateHole(queue[
|
296
|
+
for (var _i2 = 0; _i2 < queue.length; _i2++) {
|
297
|
+
outerNode = eliminateHole(queue[_i2], outerNode);
|
277
298
|
}
|
278
299
|
|
279
300
|
return outerNode;
|
280
301
|
}
|
281
302
|
|
282
|
-
function
|
283
|
-
|
303
|
+
function compareXYSlope(a, b) {
|
304
|
+
var result = a.x - b.x; // when the left-most point of 2 holes meet at a vertex, sort the holes counterclockwise so that when we find
|
305
|
+
// the bridge to the outer shell is always the point that they meet at.
|
306
|
+
|
307
|
+
if (result === 0) {
|
308
|
+
result = a.y - b.y;
|
309
|
+
|
310
|
+
if (result === 0) {
|
311
|
+
var aSlope = (a.next.y - a.y) / (a.next.x - a.x);
|
312
|
+
var bSlope = (b.next.y - b.y) / (b.next.x - b.x);
|
313
|
+
result = aSlope - bSlope;
|
314
|
+
}
|
315
|
+
}
|
316
|
+
|
317
|
+
return result;
|
284
318
|
} // find a bridge between vertices that connects hole with an outer ring and and link it
|
285
319
|
|
286
320
|
|
@@ -299,15 +333,18 @@ function eliminateHole(hole, outerNode) {
|
|
299
333
|
|
300
334
|
|
301
335
|
function findHoleBridge(hole, outerNode) {
|
302
|
-
var p = outerNode
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
336
|
+
var p = outerNode;
|
337
|
+
var hx = hole.x;
|
338
|
+
var hy = hole.y;
|
339
|
+
var qx = -Infinity;
|
340
|
+
var m; // find a segment intersected by a ray from the hole's leftmost point to the left;
|
307
341
|
// segment's endpoint with lesser x will be potential connection point
|
342
|
+
// unless they intersect at a vertex, then choose the vertex
|
343
|
+
|
344
|
+
if (equals(hole, p)) return p;
|
308
345
|
|
309
346
|
do {
|
310
|
-
if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
|
347
|
+
if (equals(hole, p.next)) return p.next;else if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
|
311
348
|
var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
|
312
349
|
|
313
350
|
if (x <= hx && x > qx) {
|
@@ -316,7 +353,6 @@ function findHoleBridge(hole, outerNode) {
|
|
316
353
|
if (x === hx) return m; // hole touches outer segment; pick leftmost endpoint
|
317
354
|
}
|
318
355
|
}
|
319
|
-
|
320
356
|
p = p.next;
|
321
357
|
} while (p !== outerNode);
|
322
358
|
|
@@ -324,16 +360,15 @@ function findHoleBridge(hole, outerNode) {
|
|
324
360
|
// if there are no points found, we have a valid connection;
|
325
361
|
// otherwise choose the point of the minimum angle with the ray as connection point
|
326
362
|
|
327
|
-
var stop = m
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
tan;
|
363
|
+
var stop = m;
|
364
|
+
var mx = m.x;
|
365
|
+
var my = m.y;
|
366
|
+
var tanMin = Infinity;
|
332
367
|
p = m;
|
333
368
|
|
334
369
|
do {
|
335
370
|
if (hx >= p.x && p.x >= mx && hx !== p.x && pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {
|
336
|
-
tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
|
371
|
+
var tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
|
337
372
|
|
338
373
|
if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
|
339
374
|
m = p;
|
@@ -371,34 +406,28 @@ function indexCurve(start, minX, minY, invSize) {
|
|
371
406
|
|
372
407
|
|
373
408
|
function sortLinked(list) {
|
374
|
-
var
|
375
|
-
|
376
|
-
q,
|
377
|
-
e,
|
378
|
-
tail,
|
379
|
-
numMerges,
|
380
|
-
pSize,
|
381
|
-
qSize,
|
382
|
-
inSize = 1;
|
409
|
+
var numMerges;
|
410
|
+
var inSize = 1;
|
383
411
|
|
384
412
|
do {
|
385
|
-
p = list;
|
413
|
+
var p = list;
|
414
|
+
var e = void 0;
|
386
415
|
list = null;
|
387
|
-
tail = null;
|
416
|
+
var tail = null;
|
388
417
|
numMerges = 0;
|
389
418
|
|
390
419
|
while (p) {
|
391
420
|
numMerges++;
|
392
|
-
q = p;
|
393
|
-
pSize = 0;
|
421
|
+
var q = p;
|
422
|
+
var pSize = 0;
|
394
423
|
|
395
|
-
for (i = 0; i < inSize; i++) {
|
424
|
+
for (var i = 0; i < inSize; i++) {
|
396
425
|
pSize++;
|
397
426
|
q = q.nextZ;
|
398
427
|
if (!q) break;
|
399
428
|
}
|
400
429
|
|
401
|
-
qSize = inSize;
|
430
|
+
var qSize = inSize;
|
402
431
|
|
403
432
|
while (pSize > 0 || qSize > 0 && q) {
|
404
433
|
if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
|
@@ -458,6 +487,11 @@ function getLeftmost(start) {
|
|
458
487
|
|
459
488
|
function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
|
460
489
|
return (cx - px) * (ay - py) >= (ax - px) * (cy - py) && (ax - px) * (by - py) >= (bx - px) * (ay - py) && (bx - px) * (cy - py) >= (cx - px) * (by - py);
|
490
|
+
} // check if a point lies within a convex triangle but false if its equal to the first point of the triangle
|
491
|
+
|
492
|
+
|
493
|
+
function pointInTriangleExceptFirst(ax, ay, bx, by, cx, cy, px, py) {
|
494
|
+
return !(ax === px && ay === py) && pointInTriangle(ax, ay, bx, by, cx, cy, px, py);
|
461
495
|
} // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
|
462
496
|
|
463
497
|
|
@@ -525,10 +559,10 @@ function locallyInside(a, b) {
|
|
525
559
|
|
526
560
|
|
527
561
|
function middleInside(a, b) {
|
528
|
-
var p = a
|
529
|
-
|
530
|
-
|
531
|
-
|
562
|
+
var p = a;
|
563
|
+
var inside = false;
|
564
|
+
var px = (a.x + b.x) / 2;
|
565
|
+
var py = (a.y + b.y) / 2;
|
532
566
|
|
533
567
|
do {
|
534
568
|
if (p.y > py !== p.next.y > py && p.next.y !== p.y && px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x) inside = !inside;
|
@@ -541,8 +575,8 @@ function middleInside(a, b) {
|
|
541
575
|
|
542
576
|
|
543
577
|
function splitPolygon(a, b) {
|
544
|
-
var a2 =
|
545
|
-
b2 =
|
578
|
+
var a2 = createNode(a.i, a.x, a.y),
|
579
|
+
b2 = createNode(b.i, b.x, b.y),
|
546
580
|
an = a.next,
|
547
581
|
bp = b.prev;
|
548
582
|
a.next = b;
|
@@ -558,7 +592,7 @@ function splitPolygon(a, b) {
|
|
558
592
|
|
559
593
|
|
560
594
|
function insertNode(i, x, y, last) {
|
561
|
-
var p =
|
595
|
+
var p = createNode(i, x, y);
|
562
596
|
|
563
597
|
if (!last) {
|
564
598
|
p.prev = p;
|
@@ -580,50 +614,25 @@ function removeNode(p) {
|
|
580
614
|
if (p.nextZ) p.nextZ.prevZ = p.prevZ;
|
581
615
|
}
|
582
616
|
|
583
|
-
function
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
617
|
+
function createNode(i, x, y) {
|
618
|
+
return {
|
619
|
+
i: i,
|
620
|
+
// vertex index in coordinates array
|
621
|
+
x: x,
|
622
|
+
y: y,
|
623
|
+
// vertex coordinates
|
624
|
+
prev: null,
|
625
|
+
// previous and next vertex nodes in a polygon ring
|
626
|
+
next: null,
|
627
|
+
z: 0,
|
628
|
+
// z-order curve value
|
629
|
+
prevZ: null,
|
630
|
+
// previous and next nodes in z-order
|
631
|
+
nextZ: null,
|
632
|
+
steiner: false // indicates whether this is a steiner point
|
592
633
|
|
593
|
-
|
594
|
-
|
595
|
-
this.prevZ = null;
|
596
|
-
this.nextZ = null; // indicates whether this is a steiner point
|
597
|
-
|
598
|
-
this.steiner = false;
|
634
|
+
};
|
599
635
|
} // return a percentage difference between the polygon area and its triangulation area;
|
600
|
-
// used to verify correctness of triangulation
|
601
|
-
|
602
|
-
|
603
|
-
earcut.deviation = function (data, holeIndices, dim, triangles) {
|
604
|
-
var hasHoles = holeIndices && holeIndices.length;
|
605
|
-
var outerLen = hasHoles ? holeIndices[0] * dim : data.length;
|
606
|
-
var polygonArea = Math.abs(signedArea(data, 0, outerLen, dim));
|
607
|
-
|
608
|
-
if (hasHoles) {
|
609
|
-
for (var i = 0, len = holeIndices.length; i < len; i++) {
|
610
|
-
var start = holeIndices[i] * dim;
|
611
|
-
var end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
|
612
|
-
polygonArea -= Math.abs(signedArea(data, start, end, dim));
|
613
|
-
}
|
614
|
-
}
|
615
|
-
|
616
|
-
var trianglesArea = 0;
|
617
|
-
|
618
|
-
for (i = 0; i < triangles.length; i += 3) {
|
619
|
-
var a = triangles[i] * dim;
|
620
|
-
var b = triangles[i + 1] * dim;
|
621
|
-
var c = triangles[i + 2] * dim;
|
622
|
-
trianglesArea += Math.abs((data[a] - data[c]) * (data[b + 1] - data[a + 1]) - (data[a] - data[b]) * (data[c + 1] - data[a + 1]));
|
623
|
-
}
|
624
|
-
|
625
|
-
return polygonArea === 0 && trianglesArea === 0 ? 0 : Math.abs((trianglesArea - polygonArea) / polygonArea);
|
626
|
-
};
|
627
636
|
|
628
637
|
function signedArea(data, start, end, dim) {
|
629
638
|
var sum = 0;
|
@@ -636,68 +645,6 @@ function signedArea(data, start, end, dim) {
|
|
636
645
|
return sum;
|
637
646
|
} // turn a polygon in a multi-dimensional array form (e.g. as in GeoJSON) into a form Earcut accepts
|
638
647
|
|
639
|
-
|
640
|
-
earcut.flatten = function (data) {
|
641
|
-
var dim = data[0][0].length,
|
642
|
-
result = {
|
643
|
-
vertices: [],
|
644
|
-
holes: [],
|
645
|
-
dimensions: dim
|
646
|
-
},
|
647
|
-
holeIndex = 0;
|
648
|
-
|
649
|
-
for (var i = 0; i < data.length; i++) {
|
650
|
-
for (var j = 0; j < data[i].length; j++) {
|
651
|
-
for (var d = 0; d < dim; d++) {
|
652
|
-
result.vertices.push(data[i][j][d]);
|
653
|
-
}
|
654
|
-
}
|
655
|
-
|
656
|
-
if (i > 0) {
|
657
|
-
holeIndex += data[i - 1].length;
|
658
|
-
result.holes.push(holeIndex);
|
659
|
-
}
|
660
|
-
}
|
661
|
-
|
662
|
-
return result;
|
663
|
-
};
|
664
|
-
|
665
|
-
var earcut$1 = earcut$2.exports;
|
666
|
-
|
667
|
-
function _defineProperties(target, props) {
|
668
|
-
for (var i = 0; i < props.length; i++) {
|
669
|
-
var descriptor = props[i];
|
670
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
671
|
-
descriptor.configurable = true;
|
672
|
-
if ("value" in descriptor) descriptor.writable = true;
|
673
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
674
|
-
}
|
675
|
-
}
|
676
|
-
|
677
|
-
function _createClass(Constructor, protoProps, staticProps) {
|
678
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
679
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
680
|
-
Object.defineProperty(Constructor, "prototype", {
|
681
|
-
writable: false
|
682
|
-
});
|
683
|
-
return Constructor;
|
684
|
-
}
|
685
|
-
|
686
|
-
function _inheritsLoose(subClass, superClass) {
|
687
|
-
subClass.prototype = Object.create(superClass.prototype);
|
688
|
-
subClass.prototype.constructor = subClass;
|
689
|
-
|
690
|
-
_setPrototypeOf(subClass, superClass);
|
691
|
-
}
|
692
|
-
|
693
|
-
function _setPrototypeOf(o, p) {
|
694
|
-
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
695
|
-
o.__proto__ = p;
|
696
|
-
return o;
|
697
|
-
};
|
698
|
-
return _setPrototypeOf(o, p);
|
699
|
-
}
|
700
|
-
|
701
648
|
// code copy from https://github.com/mrdoob/three.js/blob/dev/src/math/Quaternion.js
|
702
649
|
// import { clamp } from './MathUtils.js';
|
703
650
|
var Quaternion = /*#__PURE__*/function () {
|
@@ -2033,7 +1980,7 @@ function extrudePolygons(polygons, opts) {
|
|
2033
1980
|
validatePolygon(polygon, true);
|
2034
1981
|
const result = flatVertices(polygon, options);
|
2035
1982
|
result.polygon = polygon;
|
2036
|
-
const triangles = earcut
|
1983
|
+
const triangles = earcut(result.flatVertices, result.holes, 2);
|
2037
1984
|
generateTopAndBottom$1(result, triangles, options);
|
2038
1985
|
generateSides$1(result, options);
|
2039
1986
|
result.position = new Float32Array(result.points);
|
@@ -2179,7 +2126,7 @@ function simplePolygon(polygon, options = {}) {
|
|
2179
2126
|
uv[++uvIndex] = c[1];
|
2180
2127
|
}
|
2181
2128
|
}
|
2182
|
-
const triangles = earcut
|
2129
|
+
const triangles = earcut(flatVertices, holes, 2);
|
2183
2130
|
const normal = generateNormal(triangles, points);
|
2184
2131
|
return {
|
2185
2132
|
normal,
|
@@ -2490,15 +2437,17 @@ function expandLine(line, options) {
|
|
2490
2437
|
points.push(points[len2 - 2], points[len2 - 1]);
|
2491
2438
|
}
|
2492
2439
|
};
|
2493
|
-
const equal = (p1, p2) => {
|
2494
|
-
return p1[0] === p2[0] && p1[1] === p2[1];
|
2495
|
-
};
|
2496
2440
|
let i = 0;
|
2497
|
-
let preleftline, prerightline;
|
2441
|
+
let pre, preleftline, prerightline;
|
2498
2442
|
while (i < len) {
|
2499
2443
|
let p0;
|
2500
2444
|
let p1 = line[i], p2 = line[i + 1];
|
2501
|
-
const
|
2445
|
+
const current = p1;
|
2446
|
+
if (pre && equal(pre, current)) {
|
2447
|
+
repeatVertex();
|
2448
|
+
i++;
|
2449
|
+
continue;
|
2450
|
+
}
|
2502
2451
|
// last vertex
|
2503
2452
|
if (i === len - 1) {
|
2504
2453
|
p1 = line[len - 2];
|
@@ -2506,7 +2455,7 @@ function expandLine(line, options) {
|
|
2506
2455
|
if (equal(p1, p2)) {
|
2507
2456
|
for (let j = line.indexOf(p1); j >= 0; j--) {
|
2508
2457
|
const p = line[j];
|
2509
|
-
if (!equal(p,
|
2458
|
+
if (!equal(p, current)) {
|
2510
2459
|
p1 = p;
|
2511
2460
|
break;
|
2512
2461
|
}
|
@@ -2517,7 +2466,7 @@ function expandLine(line, options) {
|
|
2517
2466
|
if (equal(p1, p2)) {
|
2518
2467
|
for (let j = line.indexOf(p2); j < len; j++) {
|
2519
2468
|
const p = line[j];
|
2520
|
-
if (!equal(p,
|
2469
|
+
if (!equal(p, current)) {
|
2521
2470
|
p2 = p;
|
2522
2471
|
break;
|
2523
2472
|
}
|
@@ -2525,17 +2474,17 @@ function expandLine(line, options) {
|
|
2525
2474
|
}
|
2526
2475
|
}
|
2527
2476
|
if (equal(p1, p2)) {
|
2477
|
+
console.error('not find next vertex:index:', i, line);
|
2528
2478
|
repeatVertex();
|
2529
2479
|
i++;
|
2530
2480
|
continue;
|
2531
2481
|
}
|
2532
2482
|
let dy = p2[1] - p1[1], dx = p2[0] - p1[0];
|
2533
|
-
let
|
2483
|
+
let rangle = 0;
|
2534
2484
|
const rad = Math.atan2(dy, dx);
|
2535
2485
|
const angle = radToDeg(rad);
|
2536
2486
|
if (i === 0 || i === len - 1) {
|
2537
|
-
|
2538
|
-
rAngle -= 90;
|
2487
|
+
rangle = angle - 90;
|
2539
2488
|
}
|
2540
2489
|
else {
|
2541
2490
|
// 至少3个顶点才会触发
|
@@ -2550,6 +2499,7 @@ function expandLine(line, options) {
|
|
2550
2499
|
}
|
2551
2500
|
}
|
2552
2501
|
if (equal(p0, p2) || equal(p0, p1) || equal(p1, p2)) {
|
2502
|
+
console.error('not find pre vertex:index:', i, line);
|
2553
2503
|
repeatVertex();
|
2554
2504
|
i++;
|
2555
2505
|
continue;
|
@@ -2559,8 +2509,7 @@ function expandLine(line, options) {
|
|
2559
2509
|
const angle1 = radToDeg(rad1);
|
2560
2510
|
// 平行,回头路
|
2561
2511
|
if (Math.abs(Math.abs(angle1 - angle) - 180) <= 0.0001) {
|
2562
|
-
|
2563
|
-
rAngle -= 90;
|
2512
|
+
rangle = angle - 90;
|
2564
2513
|
}
|
2565
2514
|
else {
|
2566
2515
|
TEMPV1.x = p0[0] - p1[0];
|
@@ -2571,18 +2520,29 @@ function expandLine(line, options) {
|
|
2571
2520
|
console.error('has repeat vertex,the index:', i);
|
2572
2521
|
}
|
2573
2522
|
const vAngle = getAngle$1(TEMPV1, TEMPV2);
|
2574
|
-
|
2523
|
+
if (Math.abs(vAngle) <= 1) {
|
2524
|
+
rangle = angle - 90;
|
2525
|
+
}
|
2526
|
+
else {
|
2527
|
+
rangle = angle - vAngle / 2;
|
2528
|
+
}
|
2575
2529
|
}
|
2576
2530
|
}
|
2577
|
-
const rRad = degToRad(
|
2578
|
-
const p3 =
|
2531
|
+
const rRad = degToRad(rangle);
|
2532
|
+
const p3 = current;
|
2579
2533
|
const x = Math.cos(rRad) + p3[0], y = Math.sin(rRad) + p3[1];
|
2580
2534
|
const p4 = [x, y];
|
2581
2535
|
const [leftline, rightline] = translateLine(p1, p2, radius);
|
2536
|
+
if (!leftline || !rightline) {
|
2537
|
+
console.error('translateLine line eror,the index:', i, line);
|
2538
|
+
i++;
|
2539
|
+
continue;
|
2540
|
+
}
|
2582
2541
|
let op1 = lineIntersection(leftline[0], leftline[1], p3, p4);
|
2583
2542
|
let op2 = lineIntersection(rightline[0], rightline[1], p3, p4);
|
2584
2543
|
// 平行,回头路
|
2585
2544
|
if (!op1 || !op2) {
|
2545
|
+
console.error('not find Intersection,the index:', i, line);
|
2586
2546
|
const len1 = points.length;
|
2587
2547
|
const point1 = points[len1 - 2];
|
2588
2548
|
const point2 = points[len1 - 1];
|
@@ -2593,14 +2553,14 @@ function expandLine(line, options) {
|
|
2593
2553
|
op1 = [point1[0], point1[1]];
|
2594
2554
|
op2 = [point2[0], point2[1]];
|
2595
2555
|
}
|
2596
|
-
op1[2] =
|
2597
|
-
op2[2] =
|
2556
|
+
op1[2] = current[2] || 0;
|
2557
|
+
op2[2] = current[2] || 0;
|
2598
2558
|
// const [op1, op2] = calOffsetPoint(rRad, radius, p1);
|
2599
2559
|
points.push(op1, op2);
|
2600
2560
|
let needCut = false;
|
2601
2561
|
if (cutCorner) {
|
2602
2562
|
const bufferRadius = radius * 2;
|
2603
|
-
if (distance(
|
2563
|
+
if (distance(current, op1) > bufferRadius || distance(current, op2) > bufferRadius) {
|
2604
2564
|
needCut = true;
|
2605
2565
|
}
|
2606
2566
|
}
|
@@ -2609,11 +2569,11 @@ function expandLine(line, options) {
|
|
2609
2569
|
if (distance(op1, p0) < distance(op2, p0)) {
|
2610
2570
|
cutPoint = op2;
|
2611
2571
|
}
|
2612
|
-
const dy = cutPoint[1] -
|
2572
|
+
const dy = cutPoint[1] - current[1], dx = cutPoint[0] - current[0];
|
2613
2573
|
const cutAngle = Math.atan2(dy, dx) / Math.PI * 180;
|
2614
2574
|
const cutRad = degToRad(cutAngle);
|
2615
|
-
const x1 = Math.cos(cutRad) * radius +
|
2616
|
-
const y1 = Math.sin(cutRad) * radius +
|
2575
|
+
const x1 = Math.cos(cutRad) * radius + current[0];
|
2576
|
+
const y1 = Math.sin(cutRad) * radius + current[1];
|
2617
2577
|
const v1 = [x1, y1];
|
2618
2578
|
const hcutangle = cutAngle + 90;
|
2619
2579
|
// console.log(i, cutAngle, hcutangle);
|
@@ -2633,8 +2593,8 @@ function expandLine(line, options) {
|
|
2633
2593
|
}
|
2634
2594
|
let cross1 = lineIntersection(preline[0], preline[1], v1, v2);
|
2635
2595
|
let cross2 = lineIntersection(currentLine[0], currentLine[1], v1, v2);
|
2636
|
-
cross1[2] =
|
2637
|
-
cross2[2] =
|
2596
|
+
cross1[2] = current[2] || 0;
|
2597
|
+
cross2[2] = current[2] || 0;
|
2638
2598
|
const repeatPoint = cutPoint === op1 ? op2 : op1;
|
2639
2599
|
appendArray.push(cross1, cross2);
|
2640
2600
|
repeatArray.push(repeatPoint, [...repeatPoint]);
|
@@ -2651,10 +2611,14 @@ function expandLine(line, options) {
|
|
2651
2611
|
}
|
2652
2612
|
preleftline = leftline;
|
2653
2613
|
prerightline = rightline;
|
2614
|
+
pre = current;
|
2654
2615
|
i++;
|
2655
2616
|
}
|
2656
2617
|
return { offsetPoints: points, leftPoints, rightPoints, line };
|
2657
2618
|
}
|
2619
|
+
function equal(p1, p2) {
|
2620
|
+
return p1[0] === p2[0] && p1[1] === p2[1];
|
2621
|
+
}
|
2658
2622
|
const getAngle$1 = ({ x: x1, y: y1 }, { x: x2, y: y2 }) => {
|
2659
2623
|
const dot = x1 * x2 + y1 * y2;
|
2660
2624
|
const det = x1 * y2 - y1 * x2;
|
@@ -4840,7 +4804,7 @@ function generateStartAndEnd(result, polygon, options) {
|
|
4840
4804
|
flatVertices[++pIndex] = c[1];
|
4841
4805
|
}
|
4842
4806
|
}
|
4843
|
-
const triangles = earcut
|
4807
|
+
const triangles = earcut(flatVertices, holes, 2);
|
4844
4808
|
const { points, normal, uv, indices, startPoints, endPoints, polygonLen } = result;
|
4845
4809
|
pIndex = 0;
|
4846
4810
|
let uIndex = 0;
|