poly-extrude 0.14.0 → 0.16.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.
@@ -1,29 +1,62 @@
1
1
  /*!
2
- * poly-extrude v0.14.0
2
+ * poly-extrude v0.16.0
3
3
  */
4
- var earcut$2 = {exports: {}};
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
- earcut$2.exports = earcut;
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
+ }
7
22
 
8
- earcut$2.exports["default"] = earcut;
23
+ function _inheritsLoose(subClass, superClass) {
24
+ subClass.prototype = Object.create(superClass.prototype);
25
+ subClass.prototype.constructor = subClass;
26
+
27
+ _setPrototypeOf(subClass, superClass);
28
+ }
29
+
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 = dim || 2;
12
- var hasHoles = holeIndices && holeIndices.length,
13
- outerLen = hasHoles ? holeIndices[0] * dim : data.length,
14
- outerNode = linkedList(data, 0, outerLen, dim, true),
15
- triangles = [];
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, maxX, maxY, x, y, invSize;
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 = maxX = data[0];
22
- minY = maxY = data[1];
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 i, last;
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 (i = end - dim; i >= start; i -= dim) {
52
- last = insertNode(i, data[i], data[i + 1], last);
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
- triangles.push(prev.i / dim | 0);
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, dim);
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; min & max are calculated like this for speed
171
+ cy = c.y; // triangle bbox
144
172
 
145
- var x0 = ax < bx ? ax < cx ? ax : cx : bx < cx ? bx : cx,
146
- y0 = ay < by ? ay < cy ? ay : cy : by < cy ? by : cy,
147
- x1 = ax > bx ? ax > cx ? ax : cx : bx > cx ? bx : cx,
148
- y1 = ay > by ? ay > cy ? ay : cy : by > cy ? by : cy;
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 && pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0) return false;
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; min & max are calculated like this for speed
198
+ cy = c.y; // triangle bbox
171
199
 
172
- var x0 = ax < bx ? ax < cx ? ax : cx : bx < cx ? bx : cx,
173
- y0 = ay < by ? ay < cy ? ay : cy : by < cy ? by : cy,
174
- x1 = ax > bx ? ax > cx ? ax : cx : bx > cx ? bx : cx,
175
- y1 = ay > by ? ay > cy ? ay : cy : by > cy ? by : cy; // z-order range for the current triangle bbox;
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 && pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0) return false;
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 && pointInTriangle(ax, ay, bx, by, cx, cy, n.x, n.y) && area(n.prev, n, n.next) >= 0) return false;
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 && pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0) return false;
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 && pointInTriangle(ax, ay, bx, by, cx, cy, n.x, n.y) && area(n.prev, n, n.next) >= 0) return false;
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, dim) {
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 / dim | 0);
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
- i,
260
- len,
261
- start,
262
- end,
263
- list;
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(compareX); // process holes from left to right
294
+ queue.sort(compareXYSlope); // process holes from left to right
274
295
 
275
- for (i = 0; i < queue.length; i++) {
276
- outerNode = eliminateHole(queue[i], outerNode);
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 compareX(a, b) {
283
- return a.x - b.x;
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
- hx = hole.x,
304
- hy = hole.y,
305
- qx = -Infinity,
306
- m; // find a segment intersected by a ray from the hole's leftmost point to the left;
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
- mx = m.x,
329
- my = m.y,
330
- tanMin = Infinity,
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 i,
375
- p,
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
- inside = false,
530
- px = (a.x + b.x) / 2,
531
- py = (a.y + b.y) / 2;
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 = new Node(a.i, a.x, a.y),
545
- b2 = new Node(b.i, b.x, b.y),
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 = new Node(i, x, y);
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 Node(i, x, y) {
584
- // vertex index in coordinates array
585
- this.i = i; // vertex coordinates
586
-
587
- this.x = x;
588
- this.y = y; // previous and next vertex nodes in a polygon ring
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
589
633
 
590
- this.prev = null;
591
- this.next = null; // z-order curve value
592
-
593
- this.z = 0; // previous and next nodes in z-order
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 () {
@@ -1963,7 +1910,7 @@ function calLineDistance(line) {
1963
1910
  }
1964
1911
 
1965
1912
  function extrudePolygons(polygons, options) {
1966
- options = Object.assign({}, { depth: 2 }, options);
1913
+ options = Object.assign({}, { depth: 2, top: true }, options);
1967
1914
  const results = polygons.map(polygon => {
1968
1915
  for (let i = 0, len = polygon.length; i < len; i++) {
1969
1916
  const ring = polygon[i];
@@ -1982,8 +1929,8 @@ function extrudePolygons(polygons, options) {
1982
1929
  }
1983
1930
  const result = flatVertices(polygon, options);
1984
1931
  result.polygon = polygon;
1985
- const triangles = earcut$1(result.flatVertices, result.holes, 2);
1986
- generateTopAndBottom$1(result, triangles);
1932
+ const triangles = earcut(result.flatVertices, result.holes, 2);
1933
+ generateTopAndBottom$1(result, triangles, options);
1987
1934
  generateSides$1(result, options);
1988
1935
  result.position = new Float32Array(result.points);
1989
1936
  result.indices = new Uint32Array(result.indices);
@@ -1995,18 +1942,24 @@ function extrudePolygons(polygons, options) {
1995
1942
  result.polygons = polygons;
1996
1943
  return result;
1997
1944
  }
1998
- function generateTopAndBottom$1(result, triangles) {
1945
+ function generateTopAndBottom$1(result, triangles, options) {
1999
1946
  const indices = [];
2000
1947
  const { count } = result;
1948
+ const top = options.top;
2001
1949
  for (let i = 0, len = triangles.length; i < len; i += 3) {
2002
1950
  // top
2003
1951
  const a = triangles[i], b = triangles[i + 1], c = triangles[i + 2];
2004
- indices[i] = a;
2005
- indices[i + 1] = b;
2006
- indices[i + 2] = c;
1952
+ if (top) {
1953
+ indices[i] = a;
1954
+ indices[i + 1] = b;
1955
+ indices[i + 2] = c;
1956
+ }
2007
1957
  // bottom
2008
- const idx = len + i;
1958
+ let idx = len + i;
2009
1959
  const a1 = count + a, b1 = count + b, c1 = count + c;
1960
+ if (!top) {
1961
+ idx = i;
1962
+ }
2010
1963
  indices[idx] = a1;
2011
1964
  indices[idx + 1] = b1;
2012
1965
  indices[idx + 2] = c1;
@@ -4430,5 +4383,5 @@ function plane(width, height, devideW, devideH) {
4430
4383
  };
4431
4384
  }
4432
4385
 
4433
- export { cylinder, expandLine, expandPaths, expandTubes, extrudePolygons, extrudePolylines, extrudeSlopes, leftOnLine, plane };
4386
+ export { cylinder, expandLine, expandPaths, expandTubes, extrudePolygons, extrudePolylines, extrudeSlopes, isClockwise, leftOnLine, merge, plane };
4434
4387
  //# sourceMappingURL=poly-extrude.mjs.map