@math.gl/geometry 5.0.0-beta.1 → 5.0.0-beta.2

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/index.cjs CHANGED
@@ -67,6 +67,7 @@ __export(index_exports, {
67
67
  clipPolygon: () => clipPolygon,
68
68
  clipPolyline: () => clipPolyline,
69
69
  clipTriangleMesh: () => clipTriangleMesh,
70
+ composeAttributeProvenance: () => composeAttributeProvenance,
70
71
  compressTextureCoordinates: () => compressTextureCoordinates,
71
72
  computeEigenDecomposition: () => computeEigenDecomposition,
72
73
  computeVertexNormals: () => computeVertexNormals,
@@ -113,6 +114,7 @@ __export(index_exports, {
113
114
  octPack: () => octPack,
114
115
  octPackFloat: () => octPackFloat,
115
116
  octUnpack: () => octUnpack,
117
+ qualifySurfaceTransition: () => qualifySurfaceTransition,
116
118
  subdividePolyline: () => subdividePolyline,
117
119
  subdivideTriangleMesh: () => subdivideTriangleMesh,
118
120
  transformGeometry: () => transformGeometry,
@@ -2515,6 +2517,24 @@ var Polygon = class {
2515
2517
 
2516
2518
  // dist/polygon/earcut.js
2517
2519
  function earcut(positions, holeIndices, dim = 2, areas, plane = "xy") {
2520
+ const savedIndex = vertexPoolIndex;
2521
+ const savedQueue = activeHoleQueue;
2522
+ if (!holeQueues[callDepth])
2523
+ holeQueues[callDepth] = [];
2524
+ activeHoleQueue = holeQueues[callDepth];
2525
+ callDepth++;
2526
+ try {
2527
+ return triangulate(positions, holeIndices, dim, areas, plane);
2528
+ } finally {
2529
+ activeHoleQueue.length = 0;
2530
+ activeHoleQueue = savedQueue;
2531
+ vertexPoolIndex = savedIndex;
2532
+ callDepth--;
2533
+ if (callDepth === 0 && vertexPool.length > 65536)
2534
+ vertexPool.length = 0;
2535
+ }
2536
+ }
2537
+ function triangulate(positions, holeIndices, dim, areas, plane) {
2518
2538
  const hasHoles = holeIndices && holeIndices.length;
2519
2539
  const outerLen = hasHoles ? holeIndices[0] * dim : positions.length;
2520
2540
  let outerNode = linkedList(positions, 0, outerLen, dim, true, areas && areas[0], plane);
@@ -2531,11 +2551,13 @@ function earcut(positions, holeIndices, dim = 2, areas, plane = "xy") {
2531
2551
  if (hasHoles)
2532
2552
  outerNode = eliminateHoles(positions, holeIndices, outerNode, dim, areas, plane);
2533
2553
  if (positions.length > 80 * dim) {
2534
- minX = maxX = positions[0];
2535
- minY = maxY = positions[1];
2554
+ const i0 = DimIndex[plane[0]];
2555
+ const i1 = DimIndex[plane[1]];
2556
+ minX = maxX = positions[i0];
2557
+ minY = maxY = positions[i1];
2536
2558
  for (let i = dim; i < outerLen; i += dim) {
2537
- x = positions[i];
2538
- y = positions[i + 1];
2559
+ x = positions[i + i0];
2560
+ y = positions[i + i1];
2539
2561
  if (x < minX)
2540
2562
  minX = x;
2541
2563
  if (y < minY)
@@ -2548,23 +2570,44 @@ function earcut(positions, holeIndices, dim = 2, areas, plane = "xy") {
2548
2570
  invSize = Math.max(maxX - minX, maxY - minY);
2549
2571
  invSize = invSize !== 0 ? 32767 / invSize : 0;
2550
2572
  }
2551
- earcutLinked(outerNode, triangles, dim, minX, minY, invSize, 0);
2573
+ earcutLinked(outerNode, triangles, minX, minY, invSize, 0);
2552
2574
  return triangles;
2553
2575
  }
2554
2576
  function linkedList(data, start, end, dim, clockwise, area2, plane) {
2577
+ if (start >= end)
2578
+ return null;
2555
2579
  let i;
2556
2580
  let last;
2581
+ const i0 = DimIndex[plane[0]];
2582
+ const i1 = DimIndex[plane[1]];
2557
2583
  if (area2 === void 0) {
2558
- area2 = getPolygonSignedArea(data, { start, end, size: dim, plane });
2559
- }
2560
- let i0 = DimIndex[plane[0]];
2561
- let i1 = DimIndex[plane[1]];
2562
- if (clockwise === area2 < 0) {
2584
+ let sum = 0;
2585
+ let previousX = data[end - dim + i0];
2586
+ let previousY = data[end - dim + i1];
2587
+ for (i = start; i < end; i += dim) {
2588
+ const x = data[i + i0];
2589
+ const y = data[i + i1];
2590
+ sum += (x - previousX) * (y + previousY);
2591
+ last = insertNode(i / dim, x, y, last);
2592
+ previousX = x;
2593
+ previousY = y;
2594
+ }
2595
+ if (last && clockwise !== sum / 2 < 0) {
2596
+ let node = last;
2597
+ do {
2598
+ const next = node.next;
2599
+ node.next = node.prev;
2600
+ node.prev = next;
2601
+ node = next;
2602
+ } while (node !== last);
2603
+ last = last.prev;
2604
+ }
2605
+ } else if (clockwise === area2 < 0) {
2563
2606
  for (i = start; i < end; i += dim)
2564
- last = insertNode(i, data[i + i0], data[i + i1], last);
2607
+ last = insertNode(i / dim, data[i + i0], data[i + i1], last);
2565
2608
  } else {
2566
2609
  for (i = end - dim; i >= start; i -= dim)
2567
- last = insertNode(i, data[i + i0], data[i + i1], last);
2610
+ last = insertNode(i / dim, data[i + i0], data[i + i1], last);
2568
2611
  }
2569
2612
  if (last && equals2(last, last.next)) {
2570
2613
  removeNode(last);
@@ -2593,7 +2636,7 @@ function filterPoints(start, end) {
2593
2636
  } while (again || p !== end);
2594
2637
  return end;
2595
2638
  }
2596
- function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
2639
+ function earcutLinked(ear, triangles, minX, minY, invSize, pass) {
2597
2640
  if (!ear)
2598
2641
  return;
2599
2642
  if (!pass && invSize)
@@ -2605,9 +2648,9 @@ function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
2605
2648
  prev = ear.prev;
2606
2649
  next = ear.next;
2607
2650
  if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
2608
- triangles.push(prev.i / dim | 0);
2609
- triangles.push(ear.i / dim | 0);
2610
- triangles.push(next.i / dim | 0);
2651
+ triangles.push(prev.i);
2652
+ triangles.push(ear.i);
2653
+ triangles.push(next.i);
2611
2654
  removeNode(ear);
2612
2655
  ear = next.next;
2613
2656
  stop = next.next;
@@ -2616,12 +2659,12 @@ function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
2616
2659
  ear = next;
2617
2660
  if (ear === stop) {
2618
2661
  if (!pass) {
2619
- earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);
2662
+ earcutLinked(filterPoints(ear), triangles, minX, minY, invSize, 1);
2620
2663
  } else if (pass === 1) {
2621
- ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
2622
- earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
2664
+ ear = cureLocalIntersections(filterPoints(ear), triangles);
2665
+ earcutLinked(ear, triangles, minX, minY, invSize, 2);
2623
2666
  } else if (pass === 2) {
2624
- splitEarcut(ear, triangles, dim, minX, minY, invSize);
2667
+ splitEarcut(ear, triangles, minX, minY, invSize);
2625
2668
  }
2626
2669
  break;
2627
2670
  }
@@ -2691,15 +2734,15 @@ function isEarHashed(ear, minX, minY, invSize) {
2691
2734
  }
2692
2735
  return true;
2693
2736
  }
2694
- function cureLocalIntersections(start, triangles, dim) {
2737
+ function cureLocalIntersections(start, triangles) {
2695
2738
  let p = start;
2696
2739
  do {
2697
2740
  const a = p.prev;
2698
2741
  const b = p.next.next;
2699
2742
  if (!equals2(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
2700
- triangles.push(a.i / dim | 0);
2701
- triangles.push(p.i / dim | 0);
2702
- triangles.push(b.i / dim | 0);
2743
+ triangles.push(a.i);
2744
+ triangles.push(p.i);
2745
+ triangles.push(b.i);
2703
2746
  removeNode(p);
2704
2747
  removeNode(p.next);
2705
2748
  p = start = b;
@@ -2708,7 +2751,7 @@ function cureLocalIntersections(start, triangles, dim) {
2708
2751
  } while (p !== start);
2709
2752
  return filterPoints(p);
2710
2753
  }
2711
- function splitEarcut(start, triangles, dim, minX, minY, invSize) {
2754
+ function splitEarcut(start, triangles, minX, minY, invSize) {
2712
2755
  let a = start;
2713
2756
  do {
2714
2757
  let b = a.next.next;
@@ -2717,8 +2760,8 @@ function splitEarcut(start, triangles, dim, minX, minY, invSize) {
2717
2760
  let c = splitPolygon(a, b);
2718
2761
  a = filterPoints(a, a.next);
2719
2762
  c = filterPoints(c, c.next);
2720
- earcutLinked(a, triangles, dim, minX, minY, invSize, 0);
2721
- earcutLinked(c, triangles, dim, minX, minY, invSize, 0);
2763
+ earcutLinked(a, triangles, minX, minY, invSize, 0);
2764
+ earcutLinked(c, triangles, minX, minY, invSize, 0);
2722
2765
  return;
2723
2766
  }
2724
2767
  b = b.next;
@@ -2727,7 +2770,8 @@ function splitEarcut(start, triangles, dim, minX, minY, invSize) {
2727
2770
  } while (a !== start);
2728
2771
  }
2729
2772
  function eliminateHoles(data, holeIndices, outerNode, dim, areas, plane) {
2730
- const queue = [];
2773
+ const queue = activeHoleQueue;
2774
+ queue.length = 0;
2731
2775
  let i;
2732
2776
  let len;
2733
2777
  let start;
@@ -2737,6 +2781,8 @@ function eliminateHoles(data, holeIndices, outerNode, dim, areas, plane) {
2737
2781
  start = holeIndices[i] * dim;
2738
2782
  end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
2739
2783
  list = linkedList(data, start, end, dim, false, areas && areas[i + 1], plane);
2784
+ if (!list)
2785
+ continue;
2740
2786
  if (list === list.next)
2741
2787
  list.steiner = true;
2742
2788
  queue.push(getLeftmost(list));
@@ -2949,8 +2995,8 @@ function middleInside(a, b) {
2949
2995
  return inside;
2950
2996
  }
2951
2997
  function splitPolygon(a, b) {
2952
- const a2 = new Vertex(a.i, a.x, a.y);
2953
- const b2 = new Vertex(b.i, b.x, b.y);
2998
+ const a2 = allocateVertex(a.i, a.x, a.y);
2999
+ const b2 = allocateVertex(b.i, b.x, b.y);
2954
3000
  const an = a.next;
2955
3001
  const bp = b.prev;
2956
3002
  a.next = b;
@@ -2964,7 +3010,7 @@ function splitPolygon(a, b) {
2964
3010
  return b2;
2965
3011
  }
2966
3012
  function insertNode(i, x, y, last) {
2967
- const p = new Vertex(i, x, y);
3013
+ const p = allocateVertex(i, x, y);
2968
3014
  if (!last) {
2969
3015
  p.prev = p;
2970
3016
  p.next = p;
@@ -2984,6 +3030,24 @@ function removeNode(p) {
2984
3030
  if (p.nextZ)
2985
3031
  p.nextZ.prevZ = p.prevZ;
2986
3032
  }
3033
+ var vertexPool = [];
3034
+ var vertexPoolIndex = 0;
3035
+ var holeQueues = [];
3036
+ var activeHoleQueue = [];
3037
+ var callDepth = 0;
3038
+ function allocateVertex(i, x, y) {
3039
+ let vertex2 = vertexPool[vertexPoolIndex];
3040
+ if (!vertex2)
3041
+ vertexPool[vertexPoolIndex] = vertex2 = new Vertex(i, x, y);
3042
+ vertexPoolIndex++;
3043
+ vertex2.i = i;
3044
+ vertex2.x = x;
3045
+ vertex2.y = y;
3046
+ vertex2.prev = vertex2.next = vertex2.prevZ = vertex2.nextZ = null;
3047
+ vertex2.z = 0;
3048
+ vertex2.steiner = false;
3049
+ return vertex2;
3050
+ }
2987
3051
  var Vertex = class {
2988
3052
  constructor(i, x, y) {
2989
3053
  this.prev = null;
@@ -3561,7 +3625,7 @@ var FACE_WEIGHTS = [
3561
3625
  [0.25, 0.25, 0.5]
3562
3626
  ];
3563
3627
  function subdivideTriangleMesh(mesh, options) {
3564
- const { transform, tolerance, refinement = "transform-error", size = 2, targetSize = size, maxEdgeLength = Infinity, maxDepth = 10, maxVertices = 65536, maxTriangles = 131072 } = options;
3628
+ const { transform, tolerance, errorMetric, refinement = "transform-error", size = 2, targetSize = size, maxEdgeLength = Infinity, maxDepth = 10, maxVertices = 65536, maxTriangles = 131072 } = options;
3565
3629
  validateOptions();
3566
3630
  const vertices = [];
3567
3631
  let faces2 = [];
@@ -3608,7 +3672,7 @@ function subdivideTriangleMesh(mesh, options) {
3608
3672
  faces2 = refined;
3609
3673
  }
3610
3674
  function validateOptions() {
3611
- if (typeof transform !== "function" || refinement !== "transform-error" && refinement !== "source-edge" || refinement === "transform-error" && (tolerance === void 0 || !Number.isFinite(tolerance) || tolerance <= 0) || refinement === "source-edge" && (tolerance !== void 0 || !Number.isFinite(maxEdgeLength)) || size !== 2 && size !== 3 || targetSize !== 2 && targetSize !== 3 || !(maxEdgeLength > 0) || !Number.isFinite(maxEdgeLength) && maxEdgeLength !== Infinity || !Number.isInteger(maxDepth) || maxDepth < 0 || maxDepth > 30 || !validLimit(maxVertices) || !validLimit(maxTriangles) || !Number.isSafeInteger(mesh.positions.length) || mesh.positions.length < 0 || mesh.positions.length % size !== 0 || !Number.isSafeInteger(mesh.indices.length) || mesh.indices.length < 0 || mesh.indices.length % 3 !== 0)
3675
+ if (typeof transform !== "function" || errorMetric !== void 0 && typeof errorMetric !== "function" || refinement !== "transform-error" && refinement !== "source-edge" || refinement === "transform-error" && (tolerance === void 0 || !Number.isFinite(tolerance) || tolerance <= 0) || refinement === "source-edge" && (tolerance !== void 0 || errorMetric !== void 0 || !Number.isFinite(maxEdgeLength)) || size !== 2 && size !== 3 || targetSize !== 2 && targetSize !== 3 || !(maxEdgeLength > 0) || !Number.isFinite(maxEdgeLength) && maxEdgeLength !== Infinity || !Number.isInteger(maxDepth) || maxDepth < 0 || maxDepth > 30 || !validLimit(maxVertices) || !validLimit(maxTriangles) || !Number.isSafeInteger(mesh.positions.length) || mesh.positions.length < 0 || mesh.positions.length % size !== 0 || !Number.isSafeInteger(mesh.indices.length) || mesh.indices.length < 0 || mesh.indices.length % 3 !== 0)
3612
3676
  throw new RangeError("Invalid triangle mesh subdivision options or input lengths");
3613
3677
  if (mesh.positions.length / size > maxVertices || mesh.indices.length / 3 > maxTriangles) {
3614
3678
  throw new RangeError("Input mesh exceeds subdivision limits");
@@ -3627,7 +3691,14 @@ function subdivideTriangleMesh(mesh, options) {
3627
3691
  function error(points, weights) {
3628
3692
  const source = blend(points.map((p) => p.source), weights);
3629
3693
  const linearTarget = blend(points.map((p) => p.target), weights);
3630
- return Math.hypot(...project(source).map((value, i) => value - linearTarget[i]));
3694
+ const exact = project(source);
3695
+ if (!errorMetric)
3696
+ return Math.hypot(...exact.map((value2, i) => value2 - linearTarget[i]));
3697
+ const value = errorMetric({ source, exact, interpolated: linearTarget });
3698
+ if (!Number.isFinite(value) || value < 0) {
3699
+ throw new RangeError("errorMetric must return a finite nonnegative value");
3700
+ }
3701
+ return value;
3631
3702
  }
3632
3703
  function needsRefinement(face) {
3633
3704
  const points = face.vertices.map((index) => vertices[index]);
@@ -6449,4 +6520,171 @@ function segmentBounds(start, end, radius) {
6449
6520
  }
6450
6521
  return { minimum, maximum };
6451
6522
  }
6523
+
6524
+ // dist/utils/compose-attribute-provenance.js
6525
+ function composeAttributeProvenance(parent, child, options = {}) {
6526
+ const limit = options.maxVertices ?? 65536;
6527
+ if (!Number.isSafeInteger(limit) || limit < 0 || limit > 4294967295)
6528
+ throw new RangeError("Invalid provenance vertex limit");
6529
+ validate(parent);
6530
+ validate(child, parent.sourceVertexIndices.length / 3);
6531
+ if (child.sourceVertexIndices.length / 3 > limit)
6532
+ throw new RangeError("Provenance composition exceeded maxVertices");
6533
+ const indices = new Uint32Array(child.sourceVertexIndices.length);
6534
+ const weights = new Float64Array(indices.length);
6535
+ for (let vertex2 = 0; vertex2 < indices.length / 3; vertex2++) {
6536
+ const contributors = /* @__PURE__ */ new Map();
6537
+ for (let j = 0; j < 3; j++) {
6538
+ const weight = child.sourceVertexWeights[3 * vertex2 + j];
6539
+ if (!weight)
6540
+ continue;
6541
+ const intermediate = child.sourceVertexIndices[3 * vertex2 + j];
6542
+ for (let k = 0; k < 3; k++) {
6543
+ const w = weight * parent.sourceVertexWeights[3 * intermediate + k];
6544
+ if (!w)
6545
+ continue;
6546
+ const index = parent.sourceVertexIndices[3 * intermediate + k];
6547
+ contributors.set(index, (contributors.get(index) ?? 0) + w);
6548
+ }
6549
+ }
6550
+ if (contributors.size > 3)
6551
+ throw new RangeError("Composed vertex spans multiple source triangles");
6552
+ const sum = Array.from(contributors.values()).reduce((a, b) => a + b, 0);
6553
+ let slot = 3 * vertex2;
6554
+ for (const [index, weight] of contributors) {
6555
+ indices[slot] = index;
6556
+ weights[slot++] = weight / sum;
6557
+ }
6558
+ }
6559
+ return { sourceVertexIndices: indices, sourceVertexWeights: weights };
6560
+ }
6561
+ function validate(p, count = 4294967296) {
6562
+ if (!Number.isSafeInteger(p.sourceVertexIndices.length) || p.sourceVertexIndices.length < 0 || p.sourceVertexIndices.length % 3 || p.sourceVertexIndices.length !== p.sourceVertexWeights.length)
6563
+ throw new RangeError("Invalid provenance lengths");
6564
+ for (let i = 0; i < p.sourceVertexIndices.length; i += 3) {
6565
+ let sum = 0;
6566
+ for (let j = 0; j < 3; j++) {
6567
+ const w = p.sourceVertexWeights[i + j], index = p.sourceVertexIndices[i + j];
6568
+ if (!Number.isFinite(w) || w < 0 || w > 1 || w > 0 && (!Number.isSafeInteger(index) || index < 0 || index >= count))
6569
+ throw new RangeError("Invalid provenance contributor");
6570
+ sum += w;
6571
+ }
6572
+ if (Math.abs(sum - 1) > 1e-10)
6573
+ throw new RangeError("Provenance weights must sum to one");
6574
+ }
6575
+ }
6576
+
6577
+ // dist/utils/qualify-surface-transition.js
6578
+ function qualifySurfaceTransition(mesh, targetPositions, options = {}) {
6579
+ const from = Array.from(mesh.positions), to = Array.from(targetPositions), indices = Array.from(mesh.indices), count = from.length / 3, maxChecks = options.maxChecks ?? 1e6;
6580
+ if (!from.length || from.length % 3 || to.length !== from.length || !indices.length || indices.length % 3 || !from.every(Number.isFinite) || !to.every(Number.isFinite) || !indices.every((i) => Number.isSafeInteger(i) && i >= 0 && i < count) || !Number.isSafeInteger(maxChecks) || maxChecks < 0)
6581
+ throw new RangeError("Invalid surface transition mesh or budget");
6582
+ let scale = 0;
6583
+ for (const positions of [from, to])
6584
+ for (let i = 0; i < indices.length; i += 3)
6585
+ for (let j = 0; j < 3; j++) {
6586
+ const a = indices[i + j] * 3, b = indices[i + (j + 1) % 3] * 3;
6587
+ scale = Math.max(scale, Math.hypot(positions[b] - positions[a], positions[b + 1] - positions[a + 1]));
6588
+ }
6589
+ const margin = options.minimumDoubleArea ?? scale * scale * 1e-12;
6590
+ if (!Number.isFinite(margin) || margin <= 0)
6591
+ throw new RangeError("Expected positive finite area margin");
6592
+ let checks = 0;
6593
+ const tick = () => {
6594
+ if (++checks > maxChecks)
6595
+ throw new RangeError("Surface qualification exceeded maxChecks");
6596
+ };
6597
+ const edges = /* @__PURE__ */ new Map(), used = new Set(indices);
6598
+ let minimum = Infinity;
6599
+ const orientation = (a, b, c, t) => {
6600
+ const edge = (v2, k) => (from[3 * v2 + k] - from[3 * a + k]) * (1 - t) + (to[3 * v2 + k] - to[3 * a + k]) * t;
6601
+ return edge(b, 0) * edge(c, 1) - edge(b, 1) * edge(c, 0);
6602
+ };
6603
+ const minimumOrientation = (a, b, c) => {
6604
+ tick();
6605
+ return quadraticMinimum((t) => orientation(a, b, c, t));
6606
+ };
6607
+ for (let i = 0; i < indices.length; i += 3) {
6608
+ const tri = indices.slice(i, i + 3);
6609
+ const area2 = minimumOrientation(tri[0], tri[1], tri[2]);
6610
+ if (area2 < margin)
6611
+ throw new RangeError("Triangle collapses or reverses during transition");
6612
+ minimum = Math.min(minimum, area2);
6613
+ for (let j = 0; j < 3; j++) {
6614
+ const a = tri[j], b = tri[(j + 1) % 3], key = a < b ? `${a}:${b}` : `${b}:${a}`, edge = edges.get(key);
6615
+ if (edge) {
6616
+ if (edge.faces !== 1 || edge.a !== b || edge.b !== a)
6617
+ throw new RangeError("Expected oriented manifold edges");
6618
+ edge.faces++;
6619
+ } else
6620
+ edges.set(key, { a, b, faces: 1 });
6621
+ }
6622
+ }
6623
+ const next = /* @__PURE__ */ new Map();
6624
+ for (const edge of edges.values())
6625
+ if (edge.faces === 1) {
6626
+ if (next.has(edge.a))
6627
+ throw new RangeError("Nonmanifold boundary");
6628
+ next.set(edge.a, edge.b);
6629
+ }
6630
+ if (!next.size || used.size !== count || used.size - edges.size + indices.length / 3 !== 1)
6631
+ throw new RangeError("Expected a triangulated disk without unused vertices");
6632
+ const start = next.keys().next().value, boundary = [];
6633
+ const visitedBoundary = /* @__PURE__ */ new Set();
6634
+ let v = start;
6635
+ do {
6636
+ if (visitedBoundary.has(v) || !next.has(v))
6637
+ throw new RangeError("Expected one boundary cycle");
6638
+ visitedBoundary.add(v);
6639
+ boundary.push(v);
6640
+ v = next.get(v);
6641
+ } while (v !== start);
6642
+ if (boundary.length !== next.size)
6643
+ throw new RangeError("Multiple boundary cycles");
6644
+ for (let i = 0; i < boundary.length; i++) {
6645
+ const a = boundary[i], b = boundary[(i + 1) % boundary.length];
6646
+ for (let j = i + 1; j < boundary.length; j++) {
6647
+ tick();
6648
+ const c = boundary[j];
6649
+ const separation = quadraticMinimum((t) => {
6650
+ const dx = (from[3 * c] - from[3 * a]) * (1 - t) + (to[3 * c] - to[3 * a]) * t, dy = (from[3 * c + 1] - from[3 * a + 1]) * (1 - t) + (to[3 * c + 1] - to[3 * a + 1]) * t;
6651
+ return dx * dx + dy * dy;
6652
+ });
6653
+ if (separation < margin)
6654
+ throw new RangeError("Boundary vertices meet during transition");
6655
+ }
6656
+ for (const c of boundary)
6657
+ if (c !== a && c !== b && minimumOrientation(a, b, c) < -margin * 1e-3)
6658
+ throw new RangeError("Boundary is not convex throughout transition");
6659
+ }
6660
+ const neighbors = Array.from({ length: count }, () => []);
6661
+ for (const { a, b } of edges.values()) {
6662
+ neighbors[a].push(b);
6663
+ neighbors[b].push(a);
6664
+ }
6665
+ const seen = /* @__PURE__ */ new Set([start]), queue = [start];
6666
+ for (let i = 0; i < queue.length; i++)
6667
+ for (const n of neighbors[queue[i]])
6668
+ if (!seen.has(n)) {
6669
+ seen.add(n);
6670
+ queue.push(n);
6671
+ }
6672
+ if (seen.size !== count)
6673
+ throw new RangeError("Disconnected surface mesh");
6674
+ return {
6675
+ scope: "convex-xy-disk-linear",
6676
+ minimumProjectedDoubleArea: minimum,
6677
+ boundary: new Uint32Array(boundary)
6678
+ };
6679
+ }
6680
+ function quadraticMinimum(value) {
6681
+ const f = value(0), g = value(1), h = value(0.5), a = 2 * (f + g - 2 * h), b = g - f - a;
6682
+ if (![f, g, h, a, b].every(Number.isFinite))
6683
+ throw new RangeError("Nonfinite surface orientation polynomial");
6684
+ const t = a > 0 ? -b / (2 * a) : -1;
6685
+ const result = Math.min(f, g, t > 0 && t < 1 ? value(t) : Infinity);
6686
+ if (!Number.isFinite(result))
6687
+ throw new RangeError("Nonfinite surface orientation");
6688
+ return result;
6689
+ }
6452
6690
  //# sourceMappingURL=index.cjs.map