@math.gl/geometry 5.0.0-beta.11 → 5.0.0-beta.12

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.
Files changed (56) hide show
  1. package/dist/arrow/index.cjs +926 -0
  2. package/dist/arrow/index.cjs.map +6 -0
  3. package/dist/arrow/index.d.ts +3 -0
  4. package/dist/arrow/index.d.ts.map +1 -0
  5. package/dist/arrow/index.js +6 -0
  6. package/dist/arrow/index.js.map +1 -0
  7. package/dist/arrow/stream-tessellate.d.ts +34 -0
  8. package/dist/arrow/stream-tessellate.d.ts.map +1 -0
  9. package/dist/arrow/stream-tessellate.js +171 -0
  10. package/dist/arrow/stream-tessellate.js.map +1 -0
  11. package/dist/arrow/tessellate.d.ts +31 -0
  12. package/dist/arrow/tessellate.d.ts.map +1 -0
  13. package/dist/arrow/tessellate.js +102 -0
  14. package/dist/arrow/tessellate.js.map +1 -0
  15. package/dist/color/index.cjs +3 -108
  16. package/dist/color/index.cjs.map +3 -3
  17. package/dist/color/index.d.ts +2 -3
  18. package/dist/color/index.d.ts.map +1 -1
  19. package/dist/color/index.js +1 -1
  20. package/dist/color/index.js.map +1 -1
  21. package/dist/culling/index.cjs +3 -1
  22. package/dist/culling/index.cjs.map +1 -1
  23. package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.d.ts +4 -1
  24. package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.d.ts.map +1 -1
  25. package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.js +9 -2
  26. package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.js.map +1 -1
  27. package/dist/index.cjs +625 -523
  28. package/dist/index.cjs.map +2 -2
  29. package/dist/index.d.ts +1 -1
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js.map +1 -1
  32. package/dist/polygon/earcut.d.ts +12 -1
  33. package/dist/polygon/earcut.d.ts.map +1 -1
  34. package/dist/polygon/earcut.js +855 -630
  35. package/dist/polygon/earcut.js.map +1 -1
  36. package/dist/polygon/index.d.ts +1 -0
  37. package/dist/polygon/index.d.ts.map +1 -1
  38. package/dist/polygon/index.js.map +1 -1
  39. package/package.json +16 -3
  40. package/{dist/color/color-lut-types.js → src/arrow/index.ts} +3 -2
  41. package/src/arrow/stream-tessellate.ts +209 -0
  42. package/src/arrow/tessellate.ts +133 -0
  43. package/src/color/index.ts +3 -3
  44. package/src/culling/lib/algorithms/oriented-bounding-box-quaternion.ts +8 -2
  45. package/src/index.ts +14 -13
  46. package/src/polygon/earcut.ts +946 -668
  47. package/src/polygon/index.ts +1 -0
  48. package/dist/color/color-lut-types.d.ts +0 -16
  49. package/dist/color/color-lut-types.d.ts.map +0 -1
  50. package/dist/color/color-lut-types.js.map +0 -1
  51. package/dist/color/sample-lut.d.ts +0 -13
  52. package/dist/color/sample-lut.d.ts.map +0 -1
  53. package/dist/color/sample-lut.js +0 -132
  54. package/dist/color/sample-lut.js.map +0 -1
  55. package/src/color/color-lut-types.ts +0 -19
  56. package/src/color/sample-lut.ts +0 -175
package/dist/index.cjs CHANGED
@@ -2431,14 +2431,14 @@ var DimIndex = {
2431
2431
  function getPolygonSignedArea(points, options = {}) {
2432
2432
  const { start = 0, end = points.length, plane = "xy" } = options;
2433
2433
  const dim = options.size || 2;
2434
- let area2 = 0;
2434
+ let area = 0;
2435
2435
  const i0 = DimIndex[plane[0]];
2436
2436
  const i1 = DimIndex[plane[1]];
2437
2437
  for (let i = start, j = end - dim; i < end; i += dim) {
2438
- area2 += (points[i + i0] - points[j + i0]) * (points[i + i1] + points[j + i1]);
2438
+ area += (points[i + i0] - points[j + i0]) * (points[i + i1] + points[j + i1]);
2439
2439
  j = i;
2440
2440
  }
2441
- return area2 / 2;
2441
+ return area / 2;
2442
2442
  }
2443
2443
  function forEachSegmentInPolygon(points, visitor, options = {}) {
2444
2444
  const { start = 0, end = points.length, size = 2, isClosed } = options;
@@ -2486,14 +2486,14 @@ function getWindingDirection(signedArea) {
2486
2486
  }
2487
2487
  function getPolygonSignedAreaPoints(points, options = {}) {
2488
2488
  const { start = 0, end = points.length, plane = "xy" } = options;
2489
- let area2 = 0;
2489
+ let area = 0;
2490
2490
  const i0 = DimIndex[plane[0]];
2491
2491
  const i1 = DimIndex[plane[1]];
2492
2492
  for (let i = start, j = end - 1; i < end; ++i) {
2493
- area2 += (points[i][i0] - points[j][i0]) * (points[i][i1] + points[j][i1]);
2493
+ area += (points[i][i0] - points[j][i0]) * (points[i][i1] + points[j][i1]);
2494
2494
  j = i;
2495
2495
  }
2496
- return area2 / 2;
2496
+ return area / 2;
2497
2497
  }
2498
2498
  function forEachSegmentInPolygonPoints(points, visitor, options = {}) {
2499
2499
  const { start = 0, end = points.length, isClosed } = options;
@@ -2579,546 +2579,646 @@ var Polygon = class {
2579
2579
  };
2580
2580
 
2581
2581
  // dist/polygon/earcut.js
2582
- function earcut(positions, holeIndices, dim = 2, areas, plane = "xy") {
2583
- const savedIndex = vertexPoolIndex;
2584
- const savedQueue = activeHoleQueue;
2585
- if (!holeQueues[callDepth])
2586
- holeQueues[callDepth] = [];
2587
- activeHoleQueue = holeQueues[callDepth];
2582
+ function earcut(positions, holeIndices, dim = 2, areas, plane = "xy", options = {}) {
2583
+ if (!triangulators[callDepth])
2584
+ triangulators[callDepth] = createTriangulator();
2585
+ const triangulate = triangulators[callDepth];
2588
2586
  callDepth++;
2589
2587
  try {
2590
- return triangulate(positions, holeIndices, dim, areas, plane);
2588
+ return triangulate(positions, holeIndices, dim, areas, plane, options);
2591
2589
  } finally {
2592
- activeHoleQueue.length = 0;
2593
- activeHoleQueue = savedQueue;
2594
- vertexPoolIndex = savedIndex;
2595
2590
  callDepth--;
2596
- if (callDepth === 0 && vertexPool.length > 65536)
2597
- vertexPool.length = 0;
2598
2591
  }
2599
2592
  }
2600
- function triangulate(positions, holeIndices, dim, areas, plane) {
2601
- const hasHoles = holeIndices && holeIndices.length;
2602
- const outerLen = hasHoles ? holeIndices[0] * dim : positions.length;
2603
- let outerNode = linkedList(positions, 0, outerLen, dim, true, areas && areas[0], plane);
2604
- const triangles = [];
2605
- if (!outerNode || outerNode.next === outerNode.prev)
2593
+ var triangulators = [];
2594
+ var callDepth = 0;
2595
+ function createTriangulator() {
2596
+ let balanceTriangles = false;
2597
+ const steiners = /* @__PURE__ */ new Set();
2598
+ const splitStack = [];
2599
+ let filteredOut = false;
2600
+ function triangulate(data, holeIndices, dim, areas, plane) {
2601
+ const hasHoles = holeIndices && holeIndices.length;
2602
+ const outerLen = hasHoles ? holeIndices[0] * dim : data.length;
2603
+ if (steiners.size)
2604
+ steiners.clear();
2605
+ let outerNode = linkedList(data, 0, outerLen, dim, true, areas && areas[0], plane);
2606
+ const triangles = [];
2607
+ if (!outerNode || outerNode.next === outerNode.prev)
2608
+ return triangles;
2609
+ let minX = 0, minY = 0, invSize = 0;
2610
+ if (hasHoles)
2611
+ outerNode = eliminateHoles(data, holeIndices, outerNode, dim, areas, plane);
2612
+ if (data.length > 80 * dim) {
2613
+ const i0 = DimIndex[plane[0]], i1 = DimIndex[plane[1]];
2614
+ minX = data[i0];
2615
+ minY = data[i1];
2616
+ let maxX = minX;
2617
+ let maxY = minY;
2618
+ for (let i = dim; i < outerLen; i += dim) {
2619
+ const x = data[i + i0];
2620
+ const y = data[i + i1];
2621
+ if (x < minX)
2622
+ minX = x;
2623
+ if (y < minY)
2624
+ minY = y;
2625
+ if (x > maxX)
2626
+ maxX = x;
2627
+ if (y > maxY)
2628
+ maxY = y;
2629
+ }
2630
+ invSize = Math.max(maxX - minX, maxY - minY);
2631
+ invSize = invSize !== 0 ? 32767 / invSize : 0;
2632
+ }
2633
+ earcutLinked(outerNode, triangles, minX, minY, invSize);
2634
+ while (splitStack.length)
2635
+ earcutLinked(
2636
+ /** @type {Node} */
2637
+ splitStack.pop(),
2638
+ triangles,
2639
+ minX,
2640
+ minY,
2641
+ invSize
2642
+ );
2606
2643
  return triangles;
2607
- let invSize;
2608
- let maxX;
2609
- let maxY;
2610
- let minX;
2611
- let minY;
2612
- let x;
2613
- let y;
2614
- if (hasHoles)
2615
- outerNode = eliminateHoles(positions, holeIndices, outerNode, dim, areas, plane);
2616
- if (positions.length > 80 * dim) {
2644
+ }
2645
+ function linkedList(data, start, end, dim, clockwise, area2, plane) {
2646
+ if (start >= end)
2647
+ return null;
2648
+ let i;
2649
+ let last;
2617
2650
  const i0 = DimIndex[plane[0]];
2618
2651
  const i1 = DimIndex[plane[1]];
2619
- minX = maxX = positions[i0];
2620
- minY = maxY = positions[i1];
2621
- for (let i = dim; i < outerLen; i += dim) {
2622
- x = positions[i + i0];
2623
- y = positions[i + i1];
2624
- if (x < minX)
2625
- minX = x;
2626
- if (y < minY)
2627
- minY = y;
2628
- if (x > maxX)
2629
- maxX = x;
2630
- if (y > maxY)
2631
- maxY = y;
2632
- }
2633
- invSize = Math.max(maxX - minX, maxY - minY);
2634
- invSize = invSize !== 0 ? 32767 / invSize : 0;
2635
- }
2636
- earcutLinked(outerNode, triangles, minX, minY, invSize, 0);
2637
- return triangles;
2638
- }
2639
- function linkedList(data, start, end, dim, clockwise, area2, plane) {
2640
- if (start >= end)
2641
- return null;
2642
- let i;
2643
- let last;
2644
- const i0 = DimIndex[plane[0]];
2645
- const i1 = DimIndex[plane[1]];
2646
- if (area2 === void 0) {
2647
- let sum = 0;
2648
- let previousX = data[end - dim + i0];
2649
- let previousY = data[end - dim + i1];
2650
- for (i = start; i < end; i += dim) {
2651
- const x = data[i + i0];
2652
- const y = data[i + i1];
2653
- sum += (x - previousX) * (y + previousY);
2654
- last = insertNode(i / dim, x, y, last);
2655
- previousX = x;
2656
- previousY = y;
2657
- }
2658
- if (last && clockwise !== sum / 2 < 0) {
2659
- let node = last;
2660
- do {
2661
- const next = node.next;
2662
- node.next = node.prev;
2663
- node.prev = next;
2664
- node = next;
2665
- } while (node !== last);
2666
- last = last.prev;
2667
- }
2668
- } else if (clockwise === area2 < 0) {
2669
- for (i = start; i < end; i += dim)
2670
- last = insertNode(i / dim, data[i + i0], data[i + i1], last);
2671
- } else {
2672
- for (i = end - dim; i >= start; i -= dim)
2673
- last = insertNode(i / dim, data[i + i0], data[i + i1], last);
2674
- }
2675
- if (last && equals2(last, last.next)) {
2676
- removeNode(last);
2677
- last = last.next;
2678
- }
2679
- return last;
2680
- }
2681
- function filterPoints(start, end) {
2682
- if (!start)
2683
- return start;
2684
- if (!end)
2685
- end = start;
2686
- let p = start;
2687
- let again;
2688
- do {
2689
- again = false;
2690
- if (!p.steiner && (equals2(p, p.next) || area(p.prev, p, p.next) === 0)) {
2691
- removeNode(p);
2692
- p = end = p.prev;
2693
- if (p === p.next)
2694
- break;
2695
- again = true;
2652
+ if (area2 === void 0) {
2653
+ let sum = 0;
2654
+ let previousX = data[end - dim + i0];
2655
+ let previousY = data[end - dim + i1];
2656
+ for (i = start; i < end; i += dim) {
2657
+ const x = data[i + i0];
2658
+ const y = data[i + i1];
2659
+ sum += (x - previousX) * (y + previousY);
2660
+ last = insertNode(i / dim, x, y, last);
2661
+ previousX = x;
2662
+ previousY = y;
2663
+ }
2664
+ if (last && clockwise !== sum / 2 < 0) {
2665
+ let node = last;
2666
+ do {
2667
+ const next = node.next;
2668
+ node.next = node.prev;
2669
+ node.prev = next;
2670
+ node = next;
2671
+ } while (node !== last);
2672
+ last = last.prev;
2673
+ }
2674
+ } else if (clockwise === area2 < 0) {
2675
+ for (i = start; i < end; i += dim)
2676
+ last = insertNode(i / dim, data[i + i0], data[i + i1], last);
2696
2677
  } else {
2697
- p = p.next;
2698
- }
2699
- } while (again || p !== end);
2700
- return end;
2701
- }
2702
- function earcutLinked(ear, triangles, minX, minY, invSize, pass) {
2703
- if (!ear)
2704
- return;
2705
- if (!pass && invSize)
2706
- indexCurve(ear, minX, minY, invSize);
2707
- let stop = ear;
2708
- let prev;
2709
- let next;
2710
- while (ear.prev !== ear.next) {
2711
- prev = ear.prev;
2712
- next = ear.next;
2713
- if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
2714
- triangles.push(prev.i);
2715
- triangles.push(ear.i);
2716
- triangles.push(next.i);
2717
- removeNode(ear);
2718
- ear = next.next;
2719
- stop = next.next;
2720
- continue;
2721
- }
2722
- ear = next;
2723
- if (ear === stop) {
2724
- if (!pass) {
2725
- earcutLinked(filterPoints(ear), triangles, minX, minY, invSize, 1);
2726
- } else if (pass === 1) {
2727
- ear = cureLocalIntersections(filterPoints(ear), triangles);
2728
- earcutLinked(ear, triangles, minX, minY, invSize, 2);
2729
- } else if (pass === 2) {
2730
- splitEarcut(ear, triangles, minX, minY, invSize);
2678
+ for (i = end - dim; i >= start; i -= dim)
2679
+ last = insertNode(i / dim, data[i + i0], data[i + i1], last);
2680
+ }
2681
+ if (last && equals3(last, last.next)) {
2682
+ removeNode(last);
2683
+ last = last.next;
2684
+ }
2685
+ return last;
2686
+ }
2687
+ function filterPoints(start, end = start) {
2688
+ const full = end === start;
2689
+ let p = start, again;
2690
+ do {
2691
+ again = false;
2692
+ if (p !== p.next && (steiners.size === 0 || !steiners.has(p)) && (equals3(p, p.next) || area(p.prev, p, p.next) === 0)) {
2693
+ if (full || p === end)
2694
+ end = p.prev;
2695
+ filteredOut = true;
2696
+ removeNode(p);
2697
+ p = p.prev;
2698
+ again = true;
2699
+ } else if (full || p !== end) {
2700
+ p = p.next;
2701
+ again = !full;
2702
+ }
2703
+ } while (again || p !== end);
2704
+ return end;
2705
+ }
2706
+ function earcutLinked(ear, triangles, minX, minY, invSize) {
2707
+ if (invSize)
2708
+ indexCurve(ear, minX, minY, invSize);
2709
+ let stop = ear, cured = false, convex = invSize ? isConvex(ear) : false;
2710
+ while (ear.prev !== ear.next) {
2711
+ const prev = ear.prev;
2712
+ const next = ear.next;
2713
+ if (area(prev, ear, next) < 0 && (convex || (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)))) {
2714
+ triangles.push(prev.i, ear.i, next.i);
2715
+ removeNode(ear);
2716
+ ear = balanceTriangles ? next.next : next;
2717
+ stop = ear;
2718
+ continue;
2719
+ }
2720
+ convex = false;
2721
+ ear = next;
2722
+ if (ear === stop) {
2723
+ filteredOut = false;
2724
+ ear = filterPoints(ear);
2725
+ if (filteredOut) {
2726
+ stop = ear;
2727
+ continue;
2728
+ }
2729
+ if (!cured) {
2730
+ ear = cureLocalIntersections(ear, triangles);
2731
+ stop = ear;
2732
+ cured = true;
2733
+ continue;
2734
+ }
2735
+ splitEarcut(ear);
2736
+ break;
2731
2737
  }
2732
- break;
2733
2738
  }
2734
2739
  }
2735
- }
2736
- function isEar(ear) {
2737
- const a = ear.prev;
2738
- const b = ear;
2739
- const c = ear.next;
2740
- if (area(a, b, c) >= 0)
2741
- return false;
2742
- const ax = a.x;
2743
- const bx = b.x;
2744
- const cx = c.x;
2745
- const ay = a.y;
2746
- const by = b.y;
2747
- const cy = c.y;
2748
- const x0 = ax < bx ? ax < cx ? ax : cx : bx < cx ? bx : cx;
2749
- const y0 = ay < by ? ay < cy ? ay : cy : by < cy ? by : cy;
2750
- const x1 = ax > bx ? ax > cx ? ax : cx : bx > cx ? bx : cx;
2751
- const y1 = ay > by ? ay > cy ? ay : cy : by > cy ? by : cy;
2752
- let p = c.next;
2753
- while (p !== a) {
2754
- 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)
2755
- return false;
2756
- p = p.next;
2757
- }
2758
- return true;
2759
- }
2760
- function isEarHashed(ear, minX, minY, invSize) {
2761
- const a = ear.prev;
2762
- const b = ear;
2763
- const c = ear.next;
2764
- if (area(a, b, c) >= 0)
2765
- return false;
2766
- const ax = a.x;
2767
- const bx = b.x;
2768
- const cx = c.x;
2769
- const ay = a.y;
2770
- const by = b.y;
2771
- const cy = c.y;
2772
- const x0 = ax < bx ? ax < cx ? ax : cx : bx < cx ? bx : cx;
2773
- const y0 = ay < by ? ay < cy ? ay : cy : by < cy ? by : cy;
2774
- const x1 = ax > bx ? ax > cx ? ax : cx : bx > cx ? bx : cx;
2775
- const y1 = ay > by ? ay > cy ? ay : cy : by > cy ? by : cy;
2776
- const minZ = zOrder(x0, y0, minX, minY, invSize);
2777
- const maxZ = zOrder(x1, y1, minX, minY, invSize);
2778
- let p = ear.prevZ;
2779
- let n = ear.nextZ;
2780
- while (p && p.z >= minZ && n && n.z <= maxZ) {
2781
- 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)
2782
- return false;
2783
- p = p.prevZ;
2784
- 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)
2785
- return false;
2786
- n = n.nextZ;
2740
+ function isConvex(start) {
2741
+ let p = start;
2742
+ do {
2743
+ if (area(p.prev, p, p.next) >= 0)
2744
+ return false;
2745
+ p = p.next;
2746
+ } while (p !== start);
2747
+ return true;
2787
2748
  }
2788
- while (p && p.z >= minZ) {
2789
- 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)
2790
- return false;
2791
- p = p.prevZ;
2749
+ function isEar(ear) {
2750
+ const a = ear.prev, b = ear, c = ear.next, ax = a.x, bx = b.x, cx = c.x, ay = a.y, by = b.y, cy = c.y, x0 = Math.min(ax, bx, cx), y0 = Math.min(ay, by, cy), x1 = Math.max(ax, bx, cx), y1 = Math.max(ay, by, cy);
2751
+ let p = c.next;
2752
+ while (p !== a) {
2753
+ if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && !(ax === p.x && ay === p.y) && pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0)
2754
+ return false;
2755
+ p = p.next;
2756
+ }
2757
+ return true;
2792
2758
  }
2793
- while (n && n.z <= maxZ) {
2794
- 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)
2795
- return false;
2796
- n = n.nextZ;
2759
+ function isEarHashed(ear, minX, minY, invSize) {
2760
+ const a = ear.prev, b = ear, c = ear.next, ax = a.x, bx = b.x, cx = c.x, ay = a.y, by = b.y, cy = c.y, x0 = Math.min(ax, bx, cx), y0 = Math.min(ay, by, cy), x1 = Math.max(ax, bx, cx), y1 = Math.max(ay, by, cy), minZ = zOrder(x0, y0, minX, minY, invSize), maxZ = zOrder(x1, y1, minX, minY, invSize);
2761
+ let p = ear.prevZ;
2762
+ while (p && p.z >= minZ) {
2763
+ if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== c && !(ax === p.x && ay === p.y) && pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0)
2764
+ return false;
2765
+ p = p.prevZ;
2766
+ }
2767
+ let n = ear.nextZ;
2768
+ while (n && n.z <= maxZ) {
2769
+ if (n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== c && !(ax === n.x && ay === n.y) && pointInTriangle(ax, ay, bx, by, cx, cy, n.x, n.y) && area(n.prev, n, n.next) >= 0)
2770
+ return false;
2771
+ n = n.nextZ;
2772
+ }
2773
+ return true;
2797
2774
  }
2798
- return true;
2799
- }
2800
- function cureLocalIntersections(start, triangles) {
2801
- let p = start;
2802
- do {
2803
- const a = p.prev;
2804
- const b = p.next.next;
2805
- if (!equals2(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
2806
- triangles.push(a.i);
2807
- triangles.push(p.i);
2808
- triangles.push(b.i);
2809
- removeNode(p);
2810
- removeNode(p.next);
2811
- p = start = b;
2812
- }
2813
- p = p.next;
2814
- } while (p !== start);
2815
- return filterPoints(p);
2816
- }
2817
- function splitEarcut(start, triangles, minX, minY, invSize) {
2818
- let a = start;
2819
- do {
2820
- let b = a.next.next;
2821
- while (b !== a.prev) {
2822
- if (a.i !== b.i && isValidDiagonal(a, b)) {
2823
- let c = splitPolygon(a, b);
2824
- a = filterPoints(a, a.next);
2825
- c = filterPoints(c, c.next);
2826
- earcutLinked(a, triangles, minX, minY, invSize, 0);
2827
- earcutLinked(c, triangles, minX, minY, invSize, 0);
2828
- return;
2829
- }
2830
- b = b.next;
2831
- }
2832
- a = a.next;
2833
- } while (a !== start);
2834
- }
2835
- function eliminateHoles(data, holeIndices, outerNode, dim, areas, plane) {
2836
- const queue = activeHoleQueue;
2837
- queue.length = 0;
2838
- let i;
2839
- let len;
2840
- let start;
2841
- let end;
2842
- let list;
2843
- for (i = 0, len = holeIndices.length; i < len; i++) {
2844
- start = holeIndices[i] * dim;
2845
- end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
2846
- list = linkedList(data, start, end, dim, false, areas && areas[i + 1], plane);
2847
- if (!list)
2848
- continue;
2849
- if (list === list.next)
2850
- list.steiner = true;
2851
- queue.push(getLeftmost(list));
2852
- }
2853
- queue.sort(compareX);
2854
- for (i = 0; i < queue.length; i++) {
2855
- outerNode = eliminateHole(queue[i], outerNode);
2856
- }
2857
- return outerNode;
2858
- }
2859
- function compareX(a, b) {
2860
- return a.x - b.x;
2861
- }
2862
- function eliminateHole(hole, outerNode) {
2863
- const bridge = findHoleBridge(hole, outerNode);
2864
- if (!bridge) {
2865
- return outerNode;
2866
- }
2867
- const bridgeReverse = splitPolygon(bridge, hole);
2868
- filterPoints(bridgeReverse, bridgeReverse.next);
2869
- return filterPoints(bridge, bridge.next);
2870
- }
2871
- function findHoleBridge(hole, outerNode) {
2872
- let p = outerNode;
2873
- const hx = hole.x;
2874
- const hy = hole.y;
2875
- let qx = -Infinity;
2876
- let m;
2877
- do {
2878
- if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
2879
- const x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
2880
- if (x <= hx && x > qx) {
2881
- qx = x;
2882
- m = p.x < p.next.x ? p : p.next;
2883
- if (x === hx)
2884
- return m;
2775
+ function cureLocalIntersections(start, triangles) {
2776
+ let p = start;
2777
+ let cured = false;
2778
+ do {
2779
+ const a = p.prev, b = p.next.next;
2780
+ if (intersects(a, p, p.next, b, false) && locallyInside(a, b) && locallyInside(b, a)) {
2781
+ triangles.push(a.i, p.i, b.i);
2782
+ removeNode(p);
2783
+ removeNode(p.next);
2784
+ p = start = b;
2785
+ cured = true;
2885
2786
  }
2886
- }
2887
- p = p.next;
2888
- } while (p !== outerNode);
2889
- if (!m)
2890
- return null;
2891
- const stop = m;
2892
- const mx = m.x;
2893
- const my = m.y;
2894
- let tanMin = Infinity;
2895
- let tan;
2896
- p = m;
2897
- do {
2898
- 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)) {
2899
- tan = Math.abs(hy - p.y) / (hx - p.x);
2900
- if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
2901
- m = p;
2902
- tanMin = tan;
2787
+ p = p.next;
2788
+ } while (p !== start);
2789
+ return cured ? filterPoints(p) : p;
2790
+ }
2791
+ function splitEarcut(start) {
2792
+ let a = start;
2793
+ do {
2794
+ let b = a.next.next;
2795
+ while (b !== a.prev) {
2796
+ if (a.i !== b.i && isValidDiagonal(a, b)) {
2797
+ let c = splitPolygon(a, b);
2798
+ a = filterPoints(a, a.next);
2799
+ c = filterPoints(c, c.next);
2800
+ splitStack.push(c, a);
2801
+ return;
2802
+ }
2803
+ b = b.next;
2903
2804
  }
2805
+ a = a.next;
2806
+ } while (a !== start);
2807
+ }
2808
+ let indexActive = false;
2809
+ function eliminateHoles(data, holeIndices, outerNode, dim, areas, plane) {
2810
+ const queue = holeQueue;
2811
+ for (let i = 0, len = holeIndices.length; i < len; i++) {
2812
+ const start = holeIndices[i] * dim;
2813
+ const end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
2814
+ const list = (
2815
+ /** @type {Node} */
2816
+ linkedList(data, start, end, dim, false, areas && areas[i + 1], plane)
2817
+ );
2818
+ if (!list)
2819
+ continue;
2820
+ if (list === list.next)
2821
+ steiners.add(list);
2822
+ queue.push(getLeftmost(list));
2823
+ }
2824
+ queue.sort(compareXYSlope);
2825
+ buildBlockIndex(data.length / dim, holeIndices.length);
2826
+ indexSegment(outerNode, outerNode);
2827
+ indexActive = true;
2828
+ for (let i = 0; i < queue.length; i++) {
2829
+ outerNode = eliminateHole(queue[i], outerNode);
2830
+ }
2831
+ indexActive = false;
2832
+ return filterPoints(outerNode);
2833
+ }
2834
+ function compareXYSlope(a, b) {
2835
+ return a.x - b.x || a.y - b.y || (a.next.y - a.y) / (a.next.x - a.x) - (b.next.y - b.y) / (b.next.x - b.x);
2836
+ }
2837
+ function eliminateHole(hole, outerNode) {
2838
+ const bridge = findHoleBridge(hole, outerNode);
2839
+ if (!bridge) {
2840
+ return outerNode;
2841
+ }
2842
+ const bridgeReverse = splitPolygon(bridge, hole);
2843
+ const bridge2 = bridgeReverse.next;
2844
+ indexSegment(bridge, bridge2.next);
2845
+ filterPoints(bridgeReverse.prev, bridgeReverse);
2846
+ const a = bridge.prev;
2847
+ if (area(a, bridge, hole) === 0 && (a.x - bridge.x) * (hole.x - bridge.x) + (a.y - bridge.y) * (hole.y - bridge.y) < 0)
2848
+ return bridge;
2849
+ return filterPoints(bridge, bridge.next);
2850
+ }
2851
+ const K = 16;
2852
+ let blockBBox = new Float64Array(0);
2853
+ let numBlocks = 0;
2854
+ const blockHead = [];
2855
+ const blockStop = [];
2856
+ function buildBlockIndex(maxNodes, numHoles) {
2857
+ const maxBlocks = Math.ceil((maxNodes + 2 * numHoles) / K) + numHoles + 2;
2858
+ if (blockBBox.length < maxBlocks * 4)
2859
+ blockBBox = new Float64Array(maxBlocks * 4);
2860
+ numBlocks = 0;
2861
+ }
2862
+ function indexSegment(head, stop) {
2863
+ let p = head;
2864
+ do {
2865
+ const b = numBlocks++;
2866
+ blockHead[b] = p;
2867
+ let minX = p.x, minY = p.y, maxX = p.x, maxY = p.y;
2868
+ let k = 0;
2869
+ do {
2870
+ const c = p.next;
2871
+ p.z = b;
2872
+ if (c.x < minX)
2873
+ minX = c.x;
2874
+ if (c.x > maxX)
2875
+ maxX = c.x;
2876
+ if (c.y < minY)
2877
+ minY = c.y;
2878
+ if (c.y > maxY)
2879
+ maxY = c.y;
2880
+ p = c;
2881
+ } while (++k < K && p !== stop);
2882
+ blockStop[b] = p;
2883
+ const g = b * 4;
2884
+ blockBBox[g] = minX;
2885
+ blockBBox[g + 1] = minY;
2886
+ blockBBox[g + 2] = maxX;
2887
+ blockBBox[g + 3] = maxY;
2888
+ } while (p !== stop);
2889
+ }
2890
+ function growBlock(head, tail) {
2891
+ const g = head.z * 4;
2892
+ if (tail.x < blockBBox[g])
2893
+ blockBBox[g] = tail.x;
2894
+ if (tail.y < blockBBox[g + 1])
2895
+ blockBBox[g + 1] = tail.y;
2896
+ if (tail.x > blockBBox[g + 2])
2897
+ blockBBox[g + 2] = tail.x;
2898
+ if (tail.y > blockBBox[g + 3])
2899
+ blockBBox[g + 3] = tail.y;
2900
+ }
2901
+ function liveBlockStop(b) {
2902
+ let stop = blockStop[b];
2903
+ while (stop.prev.next !== stop)
2904
+ stop = stop.next;
2905
+ blockStop[b] = stop;
2906
+ return stop;
2907
+ }
2908
+ function liveBlockHead(b) {
2909
+ let head = blockHead[b];
2910
+ while (head.prev.next !== head)
2911
+ head = head.next;
2912
+ blockHead[b] = head;
2913
+ return head;
2914
+ }
2915
+ function findHoleBridge(hole, outerNode) {
2916
+ let p = outerNode;
2917
+ const hx = hole.x;
2918
+ const hy = hole.y;
2919
+ let qx = -Infinity;
2920
+ let m;
2921
+ if (equals3(hole, p))
2922
+ return p;
2923
+ for (let b = 0, g = 0; b < numBlocks; b++, g += 4) {
2924
+ if (hy < blockBBox[g + 1] || hy > blockBBox[g + 3] || blockBBox[g] > hx || blockBBox[g + 2] <= qx)
2925
+ continue;
2926
+ const stop = liveBlockStop(b);
2927
+ p = liveBlockHead(b);
2928
+ do {
2929
+ if (equals3(hole, p.next))
2930
+ return p.next;
2931
+ else if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
2932
+ const x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
2933
+ if (x <= hx && x > qx) {
2934
+ qx = x;
2935
+ m = p.x < p.next.x ? p : p.next;
2936
+ if (x === hx)
2937
+ return m;
2938
+ }
2939
+ }
2940
+ p = p.next;
2941
+ } while (p !== stop);
2904
2942
  }
2905
- p = p.next;
2906
- } while (p !== stop);
2907
- return m;
2908
- }
2909
- function sectorContainsSector(m, p) {
2910
- return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
2911
- }
2912
- function indexCurve(start, minX, minY, invSize) {
2913
- let p = start;
2914
- do {
2915
- if (p.z === 0)
2943
+ if (!m)
2944
+ return null;
2945
+ const mx = m.x;
2946
+ const my = m.y;
2947
+ const tminY = Math.min(hy, my);
2948
+ const tmaxY = Math.max(hy, my);
2949
+ let tanMin = Infinity;
2950
+ for (let b = 0, g = 0; b < numBlocks; b++, g += 4) {
2951
+ if (blockBBox[g + 2] < mx || blockBBox[g] > hx || blockBBox[g + 3] < tminY || blockBBox[g + 1] > tmaxY)
2952
+ continue;
2953
+ const stop = liveBlockStop(b);
2954
+ p = liveBlockHead(b);
2955
+ do {
2956
+ 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)) {
2957
+ const tan = Math.abs(hy - p.y) / (hx - p.x);
2958
+ if ((locallyInside(p, hole) || p.y === hy && p.next.y === hy && p.next.x > hx) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
2959
+ m = p;
2960
+ tanMin = tan;
2961
+ }
2962
+ }
2963
+ p = p.next;
2964
+ } while (p !== stop);
2965
+ }
2966
+ return m;
2967
+ }
2968
+ function sectorContainsSector(m, p) {
2969
+ return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
2970
+ }
2971
+ const sortArr = [];
2972
+ let sortBuf = [];
2973
+ let zArr = new Uint32Array(0);
2974
+ let zBuf = new Uint32Array(0);
2975
+ const counts = new Uint32Array(256);
2976
+ function indexCurve(start, minX, minY, invSize) {
2977
+ let p = start;
2978
+ let n = 0;
2979
+ do {
2916
2980
  p.z = zOrder(p.x, p.y, minX, minY, invSize);
2917
- p.prevZ = p.prev;
2918
- p.nextZ = p.next;
2919
- p = p.next;
2920
- } while (p !== start);
2921
- p.prevZ.nextZ = null;
2922
- p.prevZ = null;
2923
- sortLinked(p);
2924
- }
2925
- function sortLinked(list) {
2926
- let e;
2927
- let i;
2928
- let inSize = 1;
2929
- let numMerges;
2930
- let p;
2931
- let pSize;
2932
- let q;
2933
- let qSize;
2934
- let tail;
2935
- do {
2936
- p = list;
2937
- list = null;
2938
- tail = null;
2939
- numMerges = 0;
2940
- while (p) {
2941
- numMerges++;
2942
- q = p;
2943
- pSize = 0;
2944
- for (i = 0; i < inSize; i++) {
2945
- pSize++;
2946
- q = q.nextZ;
2947
- if (!q)
2948
- break;
2949
- }
2950
- qSize = inSize;
2951
- while (pSize > 0 || qSize > 0 && q) {
2952
- if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
2953
- e = p;
2954
- p = p.nextZ;
2955
- pSize--;
2956
- } else {
2957
- e = q;
2958
- q = q.nextZ;
2959
- qSize--;
2981
+ sortArr[n++] = p;
2982
+ p = p.next;
2983
+ } while (p !== start);
2984
+ sortNodes(n);
2985
+ let prev = null;
2986
+ for (let i = 0; i < n; i++) {
2987
+ const node = sortArr[i];
2988
+ node.prevZ = prev;
2989
+ if (prev)
2990
+ prev.nextZ = node;
2991
+ prev = node;
2992
+ }
2993
+ prev.nextZ = null;
2994
+ sortArr.fill(
2995
+ /** @type {Node} */
2996
+ /** @type {unknown} */
2997
+ null,
2998
+ 0,
2999
+ n
3000
+ );
3001
+ sortBuf.fill(
3002
+ /** @type {Node} */
3003
+ /** @type {unknown} */
3004
+ null,
3005
+ 0,
3006
+ n
3007
+ );
3008
+ }
3009
+ function sortNodes(n) {
3010
+ if (n <= 32) {
3011
+ for (let i = 1; i < n; i++) {
3012
+ const node = sortArr[i], z = node.z;
3013
+ let j = i - 1;
3014
+ while (j >= 0 && sortArr[j].z > z) {
3015
+ sortArr[j + 1] = sortArr[j];
3016
+ j--;
2960
3017
  }
2961
- if (tail)
2962
- tail.nextZ = e;
2963
- else
2964
- list = e;
2965
- e.prevZ = tail;
2966
- tail = e;
3018
+ sortArr[j + 1] = node;
2967
3019
  }
2968
- p = q;
2969
- }
2970
- tail.nextZ = null;
2971
- inSize *= 2;
2972
- } while (numMerges > 1);
2973
- return list;
2974
- }
2975
- function zOrder(x, y, minX, minY, invSize) {
2976
- x = (x - minX) * invSize | 0;
2977
- y = (y - minY) * invSize | 0;
2978
- x = (x | x << 8) & 16711935;
2979
- x = (x | x << 4) & 252645135;
2980
- x = (x | x << 2) & 858993459;
2981
- x = (x | x << 1) & 1431655765;
2982
- y = (y | y << 8) & 16711935;
2983
- y = (y | y << 4) & 252645135;
2984
- y = (y | y << 2) & 858993459;
2985
- y = (y | y << 1) & 1431655765;
2986
- return x | y << 1;
2987
- }
2988
- function getLeftmost(start) {
2989
- let p = start;
2990
- let leftmost = start;
2991
- do {
2992
- if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y)
2993
- leftmost = p;
2994
- p = p.next;
2995
- } while (p !== start);
2996
- return leftmost;
2997
- }
2998
- function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
2999
- 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);
3000
- }
3001
- function isValidDiagonal(a, b) {
3002
- return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && // dones't intersect other edges
3003
- (locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && // locally visible
3004
- (area(a.prev, a, b.prev) || area(a, b.prev, b)) || // does not create opposite-facing sectors
3005
- equals2(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0);
3006
- }
3007
- function area(p, q, r) {
3008
- return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
3009
- }
3010
- function equals2(p1, p2) {
3011
- return p1.x === p2.x && p1.y === p2.y;
3012
- }
3013
- function intersects(p1, q1, p2, q2) {
3014
- const o1 = sign(area(p1, q1, p2));
3015
- const o2 = sign(area(p1, q1, q2));
3016
- const o3 = sign(area(p2, q2, p1));
3017
- const o4 = sign(area(p2, q2, q1));
3018
- if (o1 !== o2 && o3 !== o4)
3019
- return true;
3020
- if (o1 === 0 && onSegment(p1, p2, q1))
3021
- return true;
3022
- if (o2 === 0 && onSegment(p1, q2, q1))
3023
- return true;
3024
- if (o3 === 0 && onSegment(p2, p1, q2))
3025
- return true;
3026
- if (o4 === 0 && onSegment(p2, q1, q2))
3027
- return true;
3028
- return false;
3029
- }
3030
- function onSegment(p, q, r) {
3031
- return q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) && q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y);
3032
- }
3033
- function sign(num) {
3034
- return num > 0 ? 1 : num < 0 ? -1 : 0;
3035
- }
3036
- function intersectsPolygon(a, b) {
3037
- let p = a;
3038
- do {
3039
- if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i && intersects(p, p.next, a, b))
3020
+ return;
3021
+ }
3022
+ if (zArr.length < n) {
3023
+ zArr = new Uint32Array(n);
3024
+ zBuf = new Uint32Array(n);
3025
+ sortBuf = new Array(n);
3026
+ }
3027
+ for (let i = 0; i < n; i++)
3028
+ zArr[i] = sortArr[i].z;
3029
+ radixPass(n, sortArr, zArr, sortBuf, zBuf, 0);
3030
+ radixPass(n, sortBuf, zBuf, sortArr, zArr, 8);
3031
+ radixPass(n, sortArr, zArr, sortBuf, zBuf, 16);
3032
+ radixPass(n, sortBuf, zBuf, sortArr, zArr, 24);
3033
+ }
3034
+ function radixPass(n, src, srcZ, dst, dstZ, shift) {
3035
+ counts.fill(0);
3036
+ for (let i = 0; i < n; i++)
3037
+ counts[srcZ[i] >>> shift & 255]++;
3038
+ let sum = 0;
3039
+ for (let b = 0; b < 256; b++) {
3040
+ const c = counts[b];
3041
+ counts[b] = sum;
3042
+ sum += c;
3043
+ }
3044
+ for (let i = 0; i < n; i++) {
3045
+ const z = srcZ[i];
3046
+ const pos = counts[z >>> shift & 255]++;
3047
+ dst[pos] = src[i];
3048
+ dstZ[pos] = z;
3049
+ }
3050
+ }
3051
+ function zOrder(x, y, minX, minY, invSize) {
3052
+ x = (x - minX) * invSize | 0;
3053
+ y = (y - minY) * invSize | 0;
3054
+ x = (x | x << 8) & 16711935;
3055
+ x = (x | x << 4) & 252645135;
3056
+ x = (x | x << 2) & 858993459;
3057
+ x = (x | x << 1) & 1431655765;
3058
+ y = (y | y << 8) & 16711935;
3059
+ y = (y | y << 4) & 252645135;
3060
+ y = (y | y << 2) & 858993459;
3061
+ y = (y | y << 1) & 1431655765;
3062
+ return x | y << 1;
3063
+ }
3064
+ function getLeftmost(start) {
3065
+ let p = start, leftmost = start;
3066
+ do {
3067
+ if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y)
3068
+ leftmost = p;
3069
+ p = p.next;
3070
+ } while (p !== start);
3071
+ return leftmost;
3072
+ }
3073
+ function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
3074
+ 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);
3075
+ }
3076
+ function isValidDiagonal(a, b) {
3077
+ const zeroLength = equals3(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0;
3078
+ return a.next.i !== b.i && (zeroLength || locallyInside(a, b) && locallyInside(b, a) && // // locally visible
3079
+ (area(a.prev, a, b.prev) !== 0 || area(a, b.prev, b) !== 0)) && // no opposite-facing sectors
3080
+ !intersectsPolygon(a, b) && (zeroLength || middleInside(a, b));
3081
+ }
3082
+ function area(p, q, r) {
3083
+ return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
3084
+ }
3085
+ function equals3(p1, p2) {
3086
+ return p1.x === p2.x && p1.y === p2.y;
3087
+ }
3088
+ function intersects(p1, q1, p2, q2, includeBoundary = true) {
3089
+ const o1 = area(p1, q1, p2);
3090
+ const o2 = area(p1, q1, q2);
3091
+ const o3 = area(p2, q2, p1);
3092
+ const o4 = area(p2, q2, q1);
3093
+ if ((o1 > 0 && o2 < 0 || o1 < 0 && o2 > 0) && (o3 > 0 && o4 < 0 || o3 < 0 && o4 > 0))
3040
3094
  return true;
3041
- p = p.next;
3042
- } while (p !== a);
3043
- return false;
3044
- }
3045
- function locallyInside(a, b) {
3046
- return area(a.prev, a, a.next) < 0 ? area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0 : area(a, b, a.prev) < 0 || area(a, a.next, b) < 0;
3047
- }
3048
- function middleInside(a, b) {
3049
- let p = a;
3050
- let inside = false;
3051
- const px = (a.x + b.x) / 2;
3052
- const py = (a.y + b.y) / 2;
3053
- do {
3054
- 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)
3055
- inside = !inside;
3056
- p = p.next;
3057
- } while (p !== a);
3058
- return inside;
3059
- }
3060
- function splitPolygon(a, b) {
3061
- const a2 = allocateVertex(a.i, a.x, a.y);
3062
- const b2 = allocateVertex(b.i, b.x, b.y);
3063
- const an = a.next;
3064
- const bp = b.prev;
3065
- a.next = b;
3066
- b.prev = a;
3067
- a2.next = an;
3068
- an.prev = a2;
3069
- b2.next = a2;
3070
- a2.prev = b2;
3071
- bp.next = b2;
3072
- b2.prev = bp;
3073
- return b2;
3074
- }
3075
- function insertNode(i, x, y, last) {
3076
- const p = allocateVertex(i, x, y);
3077
- if (!last) {
3078
- p.prev = p;
3079
- p.next = p;
3080
- } else {
3081
- p.next = last.next;
3082
- p.prev = last;
3083
- last.next.prev = p;
3084
- last.next = p;
3085
- }
3086
- return p;
3087
- }
3088
- function removeNode(p) {
3089
- p.next.prev = p.prev;
3090
- p.prev.next = p.next;
3091
- if (p.prevZ)
3092
- p.prevZ.nextZ = p.nextZ;
3093
- if (p.nextZ)
3094
- p.nextZ.prevZ = p.prevZ;
3095
- }
3096
- var vertexPool = [];
3097
- var vertexPoolIndex = 0;
3098
- var holeQueues = [];
3099
- var activeHoleQueue = [];
3100
- var callDepth = 0;
3101
- function allocateVertex(i, x, y) {
3102
- let vertex2 = vertexPool[vertexPoolIndex];
3103
- if (!vertex2)
3104
- vertexPool[vertexPoolIndex] = vertex2 = new Vertex(i, x, y);
3105
- vertexPoolIndex++;
3106
- vertex2.i = i;
3107
- vertex2.x = x;
3108
- vertex2.y = y;
3109
- vertex2.prev = vertex2.next = vertex2.prevZ = vertex2.nextZ = null;
3110
- vertex2.z = 0;
3111
- vertex2.steiner = false;
3112
- return vertex2;
3095
+ if (!includeBoundary)
3096
+ return false;
3097
+ if (o1 === 0 && onSegment(p1, p2, q1))
3098
+ return true;
3099
+ if (o2 === 0 && onSegment(p1, q2, q1))
3100
+ return true;
3101
+ if (o3 === 0 && onSegment(p2, p1, q2))
3102
+ return true;
3103
+ if (o4 === 0 && onSegment(p2, q1, q2))
3104
+ return true;
3105
+ return false;
3106
+ }
3107
+ function onSegment(p, q, r) {
3108
+ return q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) && q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y);
3109
+ }
3110
+ function intersectsPolygon(a, b) {
3111
+ const minX = Math.min(a.x, b.x);
3112
+ const maxX = Math.max(a.x, b.x);
3113
+ const minY = Math.min(a.y, b.y);
3114
+ const maxY = Math.max(a.y, b.y);
3115
+ let p = a;
3116
+ do {
3117
+ const n = p.next;
3118
+ if (p.x > maxX && n.x > maxX || p.x < minX && n.x < minX || p.y > maxY && n.y > maxY || p.y < minY && n.y < minY) {
3119
+ p = n;
3120
+ continue;
3121
+ }
3122
+ if (p.i !== a.i && n.i !== a.i && p.i !== b.i && n.i !== b.i && intersects(p, n, a, b))
3123
+ return true;
3124
+ p = n;
3125
+ } while (p !== a);
3126
+ return false;
3127
+ }
3128
+ function locallyInside(a, b) {
3129
+ return area(a.prev, a, a.next) < 0 ? area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0 : area(a, b, a.prev) < 0 || area(a, a.next, b) < 0;
3130
+ }
3131
+ function middleInside(a, b) {
3132
+ let p = a;
3133
+ let inside = false;
3134
+ const px = (a.x + b.x) / 2;
3135
+ const py = (a.y + b.y) / 2;
3136
+ do {
3137
+ const n = p.next;
3138
+ if (p.y > py !== n.y > py && px < (n.x - p.x) * (py - p.y) / (n.y - p.y) + p.x)
3139
+ inside = !inside;
3140
+ p = n;
3141
+ } while (p !== a);
3142
+ return inside;
3143
+ }
3144
+ function splitPolygon(a, b) {
3145
+ const a2 = createNode(a.i, a.x, a.y), b2 = createNode(b.i, b.x, b.y), an = a.next, bp = b.prev;
3146
+ a.next = b;
3147
+ b.prev = a;
3148
+ a2.next = an;
3149
+ an.prev = a2;
3150
+ b2.next = a2;
3151
+ a2.prev = b2;
3152
+ bp.next = b2;
3153
+ b2.prev = bp;
3154
+ return b2;
3155
+ }
3156
+ function insertNode(i, x, y, last) {
3157
+ const p = createNode(i, x, y);
3158
+ if (!last) {
3159
+ p.prev = p;
3160
+ p.next = p;
3161
+ } else {
3162
+ p.next = last.next;
3163
+ p.prev = last;
3164
+ last.next.prev = p;
3165
+ last.next = p;
3166
+ }
3167
+ return p;
3168
+ }
3169
+ function removeNode(p) {
3170
+ p.next.prev = p.prev;
3171
+ p.prev.next = p.next;
3172
+ if (p.prevZ)
3173
+ p.prevZ.nextZ = p.nextZ;
3174
+ if (p.nextZ)
3175
+ p.nextZ.prevZ = p.prevZ;
3176
+ if (indexActive)
3177
+ growBlock(p.prev, p.next);
3178
+ }
3179
+ function createNode(i, x, y) {
3180
+ let vertex2 = vertexPool[vertexPoolIndex];
3181
+ if (!vertex2)
3182
+ vertexPool[vertexPoolIndex] = vertex2 = new Vertex(i, x, y);
3183
+ vertexPoolIndex++;
3184
+ vertex2.i = i;
3185
+ vertex2.x = x;
3186
+ vertex2.y = y;
3187
+ vertex2.prev = vertex2.next = vertex2.prevZ = vertex2.nextZ = null;
3188
+ vertex2.z = 0;
3189
+ return vertex2;
3190
+ }
3191
+ const vertexPool = [];
3192
+ let vertexPoolIndex = 0;
3193
+ const holeQueue = [];
3194
+ return (positions, holeIndices, dim, areas, plane, options) => {
3195
+ try {
3196
+ balanceTriangles = options.triangulation === "balanced";
3197
+ return triangulate(positions, holeIndices, dim, areas, plane);
3198
+ } finally {
3199
+ vertexPoolIndex = 0;
3200
+ indexActive = false;
3201
+ filteredOut = false;
3202
+ steiners.clear();
3203
+ splitStack.length = holeQueue.length = blockHead.length = blockStop.length = 0;
3204
+ numBlocks = 0;
3205
+ if (vertexPool.length > 65536 || blockBBox.length > 65536 * 4 || zArr.length > 65536) {
3206
+ vertexPool.length = sortArr.length = sortBuf.length = 0;
3207
+ blockBBox = new Float64Array(0);
3208
+ zArr = new Uint32Array(0);
3209
+ zBuf = new Uint32Array(0);
3210
+ }
3211
+ }
3212
+ };
3113
3213
  }
3114
3214
  var Vertex = class {
3215
+ /** Initialize a node; links are assigned before the first read. */
3115
3216
  constructor(i, x, y) {
3116
3217
  this.prev = null;
3117
3218
  this.next = null;
3118
3219
  this.z = 0;
3119
3220
  this.prevZ = null;
3120
3221
  this.nextZ = null;
3121
- this.steiner = false;
3122
3222
  this.i = i;
3123
3223
  this.x = x;
3124
3224
  this.y = y;
@@ -4252,12 +4352,12 @@ function cross3(a, b, p) {
4252
4352
  function validateRegion(region) {
4253
4353
  if (!Array.isArray(region) || region.length < 3 || region.length > 1024 || Array.from(region).some((p) => !Array.isArray(p) || p.length !== 2 || !Array.from(p).every(Number.isFinite)))
4254
4354
  throw new RangeError("Invalid convex clipping region");
4255
- let area2 = 0;
4355
+ let area = 0;
4256
4356
  for (let i = 1; i + 1 < region.length; i++)
4257
- area2 += cross3(region[0], region[i], region[i + 1]);
4258
- if (!Number.isFinite(area2) || area2 === 0)
4357
+ area += cross3(region[0], region[i], region[i + 1]);
4358
+ if (!Number.isFinite(area) || area === 0)
4259
4359
  throw new RangeError("Degenerate clipping region");
4260
- const result = area2 > 0 ? Array.from(region) : Array.from(region).reverse();
4360
+ const result = area > 0 ? Array.from(region) : Array.from(region).reverse();
4261
4361
  for (let i = 0; i < result.length; i++) {
4262
4362
  const a = result[i], b = result[(i + 1) % result.length];
4263
4363
  if (a[0] === b[0] && a[1] === b[1] || result.some((p) => cross3(a, b, p) < 0))
@@ -6589,7 +6689,9 @@ function getOrientedBoundingBoxQuaternion(box) {
6589
6689
  const x = new import_core22.Vector3(box.halfAxes.getColumn(0)).normalize();
6590
6690
  const y = new import_core22.Vector3(box.halfAxes.getColumn(1)).normalize();
6591
6691
  const z = new import_core22.Vector3(box.halfAxes.getColumn(2)).normalize();
6592
- return new import_core22.Quaternion().fromMatrix3(new import_core22.Matrix3([...x, ...y, ...z]));
6692
+ if (box.halfAxes.determinant() < 0)
6693
+ z.negate();
6694
+ return new import_core22.Quaternion().fromMatrix3(new import_core22.Matrix3([...x, ...y, ...z])).normalize();
6593
6695
  }
6594
6696
  function makeOrientedBoundingBoxFromQuaternion(center, halfSize, quaternion, result = new OrientedBoundingBox()) {
6595
6697
  const halfAxes = new import_core22.Matrix3().fromQuaternion(quaternion);
@@ -7313,10 +7415,10 @@ function qualifySurfaceTransition(mesh, targetPositions, options = {}) {
7313
7415
  };
7314
7416
  for (let i = 0; i < indices.length; i += 3) {
7315
7417
  const tri = indices.slice(i, i + 3);
7316
- const area2 = minimumOrientation(tri[0], tri[1], tri[2]);
7317
- if (area2 < margin)
7418
+ const area = minimumOrientation(tri[0], tri[1], tri[2]);
7419
+ if (area < margin)
7318
7420
  throw new RangeError("Triangle collapses or reverses during transition");
7319
- minimum = Math.min(minimum, area2);
7421
+ minimum = Math.min(minimum, area);
7320
7422
  for (let j = 0; j < 3; j++) {
7321
7423
  const a = tri[j], b = tri[(j + 1) % 3], key = a < b ? `${a}:${b}` : `${b}:${a}`, edge = edges.get(key);
7322
7424
  if (edge) {