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

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 (140) hide show
  1. package/README.md +61 -0
  2. package/THIRD-PARTY-NOTICES.md +1 -1
  3. package/dist/color/color-lut-types.d.ts +16 -0
  4. package/dist/color/color-lut-types.d.ts.map +1 -0
  5. package/dist/color/color-lut-types.js +5 -0
  6. package/dist/color/color-lut-types.js.map +1 -0
  7. package/dist/color/index.cjs +132 -0
  8. package/dist/color/index.cjs.map +6 -0
  9. package/dist/color/index.d.ts +4 -0
  10. package/dist/color/index.d.ts.map +1 -0
  11. package/dist/color/index.js +5 -0
  12. package/dist/color/index.js.map +1 -0
  13. package/dist/color/sample-lut.d.ts +13 -0
  14. package/dist/color/sample-lut.d.ts.map +1 -0
  15. package/dist/color/sample-lut.js +132 -0
  16. package/dist/color/sample-lut.js.map +1 -0
  17. package/dist/culling/bounds.d.ts +20 -0
  18. package/dist/culling/bounds.d.ts.map +1 -0
  19. package/dist/culling/bounds.js +121 -0
  20. package/dist/culling/bounds.js.map +1 -0
  21. package/dist/culling/frustum-planes.d.ts +5 -0
  22. package/dist/culling/frustum-planes.d.ts.map +1 -0
  23. package/dist/culling/frustum-planes.js +37 -0
  24. package/dist/culling/frustum-planes.js.map +1 -0
  25. package/dist/culling/geometric-queries.d.ts +34 -0
  26. package/dist/culling/geometric-queries.d.ts.map +1 -0
  27. package/dist/culling/geometric-queries.js +208 -0
  28. package/dist/culling/geometric-queries.js.map +1 -0
  29. package/dist/culling/index.cjs +944 -508
  30. package/dist/culling/index.cjs.map +3 -3
  31. package/dist/culling/index.d.ts +7 -1
  32. package/dist/culling/index.d.ts.map +1 -1
  33. package/dist/culling/index.js +4 -0
  34. package/dist/culling/index.js.map +1 -1
  35. package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +3 -3
  36. package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.d.ts.map +1 -1
  37. package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.js +25 -8
  38. package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -1
  39. package/dist/culling/lib/culling-volume.d.ts +3 -0
  40. package/dist/culling/lib/culling-volume.d.ts.map +1 -1
  41. package/dist/culling/lib/culling-volume.js +7 -0
  42. package/dist/culling/lib/culling-volume.js.map +1 -1
  43. package/dist/culling/lib/ray.d.ts +5 -0
  44. package/dist/culling/lib/ray.d.ts.map +1 -1
  45. package/dist/culling/lib/ray.js +21 -0
  46. package/dist/culling/lib/ray.js.map +1 -1
  47. package/dist/culling/screen-ray.d.ts +22 -0
  48. package/dist/culling/screen-ray.d.ts.map +1 -0
  49. package/dist/culling/screen-ray.js +55 -0
  50. package/dist/culling/screen-ray.js.map +1 -0
  51. package/dist/curves/adaptive-sampling.d.ts +16 -0
  52. package/dist/curves/adaptive-sampling.d.ts.map +1 -0
  53. package/dist/curves/adaptive-sampling.js +59 -0
  54. package/dist/curves/adaptive-sampling.js.map +1 -0
  55. package/dist/curves/index.d.ts +4 -0
  56. package/dist/curves/index.d.ts.map +1 -1
  57. package/dist/curves/index.js +2 -0
  58. package/dist/curves/index.js.map +1 -1
  59. package/dist/curves/parallel-transport.d.ts +12 -0
  60. package/dist/curves/parallel-transport.d.ts.map +1 -0
  61. package/dist/curves/parallel-transport.js +83 -0
  62. package/dist/curves/parallel-transport.js.map +1 -0
  63. package/dist/index.cjs +1922 -817
  64. package/dist/index.cjs.map +3 -3
  65. package/dist/index.d.ts +15 -3
  66. package/dist/index.d.ts.map +1 -1
  67. package/dist/index.js +8 -1
  68. package/dist/index.js.map +1 -1
  69. package/dist/lighting/index.cjs +175 -0
  70. package/dist/lighting/index.cjs.map +6 -0
  71. package/dist/lighting/index.d.ts +4 -0
  72. package/dist/lighting/index.d.ts.map +1 -0
  73. package/dist/lighting/index.js +5 -0
  74. package/dist/lighting/index.js.map +1 -0
  75. package/dist/lighting/lighting-types.d.ts +16 -0
  76. package/dist/lighting/lighting-types.d.ts.map +1 -0
  77. package/dist/lighting/lighting-types.js +5 -0
  78. package/dist/lighting/lighting-types.js.map +1 -0
  79. package/dist/lighting/photometry.d.ts +36 -0
  80. package/dist/lighting/photometry.d.ts.map +1 -0
  81. package/dist/lighting/photometry.js +181 -0
  82. package/dist/lighting/photometry.js.map +1 -0
  83. package/dist/polygon/earcut.d.ts.map +1 -1
  84. package/dist/polygon/earcut.js +100 -34
  85. package/dist/polygon/earcut.js.map +1 -1
  86. package/dist/polygon/index.d.ts +2 -0
  87. package/dist/polygon/index.d.ts.map +1 -1
  88. package/dist/polygon/index.js +1 -0
  89. package/dist/polygon/index.js.map +1 -1
  90. package/dist/polygon/pole-of-inaccessibility.d.ts +21 -0
  91. package/dist/polygon/pole-of-inaccessibility.d.ts.map +1 -0
  92. package/dist/polygon/pole-of-inaccessibility.js +285 -0
  93. package/dist/polygon/pole-of-inaccessibility.js.map +1 -0
  94. package/dist/polygon/subdivide-triangle-mesh.d.ts +10 -0
  95. package/dist/polygon/subdivide-triangle-mesh.d.ts.map +1 -1
  96. package/dist/polygon/subdivide-triangle-mesh.js +13 -3
  97. package/dist/polygon/subdivide-triangle-mesh.js.map +1 -1
  98. package/dist/utils/compose-attribute-provenance.d.ts +13 -0
  99. package/dist/utils/compose-attribute-provenance.d.ts.map +1 -0
  100. package/dist/utils/compose-attribute-provenance.js +63 -0
  101. package/dist/utils/compose-attribute-provenance.js.map +1 -0
  102. package/dist/utils/project-bounds.d.ts +44 -0
  103. package/dist/utils/project-bounds.d.ts.map +1 -0
  104. package/dist/utils/project-bounds.js +93 -0
  105. package/dist/utils/project-bounds.js.map +1 -0
  106. package/dist/utils/project-texture-coordinates.d.ts +19 -0
  107. package/dist/utils/project-texture-coordinates.d.ts.map +1 -0
  108. package/dist/utils/project-texture-coordinates.js +49 -0
  109. package/dist/utils/project-texture-coordinates.js.map +1 -0
  110. package/dist/utils/qualify-surface-transition.d.ts +21 -0
  111. package/dist/utils/qualify-surface-transition.d.ts.map +1 -0
  112. package/dist/utils/qualify-surface-transition.js +140 -0
  113. package/dist/utils/qualify-surface-transition.js.map +1 -0
  114. package/package.json +15 -3
  115. package/src/color/color-lut-types.ts +19 -0
  116. package/src/color/index.ts +6 -0
  117. package/src/color/sample-lut.ts +175 -0
  118. package/src/culling/bounds.ts +152 -0
  119. package/src/culling/frustum-planes.ts +41 -0
  120. package/src/culling/geometric-queries.ts +299 -0
  121. package/src/culling/index.ts +39 -1
  122. package/src/culling/lib/bounding-volumes/axis-aligned-bounding-box.ts +26 -8
  123. package/src/culling/lib/culling-volume.ts +9 -1
  124. package/src/culling/lib/ray.ts +21 -0
  125. package/src/culling/screen-ray.ts +75 -0
  126. package/src/curves/adaptive-sampling.ts +85 -0
  127. package/src/curves/index.ts +4 -0
  128. package/src/curves/parallel-transport.ts +104 -0
  129. package/src/index.ts +51 -0
  130. package/src/lighting/index.ts +10 -0
  131. package/src/lighting/lighting-types.ts +20 -0
  132. package/src/lighting/photometry.ts +264 -0
  133. package/src/polygon/earcut.ts +98 -37
  134. package/src/polygon/index.ts +6 -0
  135. package/src/polygon/pole-of-inaccessibility.ts +330 -0
  136. package/src/polygon/subdivide-triangle-mesh.ts +22 -2
  137. package/src/utils/compose-attribute-provenance.ts +74 -0
  138. package/src/utils/project-bounds.ts +154 -0
  139. package/src/utils/project-texture-coordinates.ts +67 -0
  140. package/src/utils/qualify-surface-transition.ts +169 -0
package/dist/index.cjs CHANGED
@@ -35,6 +35,7 @@ __export(index_exports, {
35
35
  CurveArcLength: () => CurveArcLength,
36
36
  CylinderGeometry: () => CylinderGeometry,
37
37
  CylinderShape: () => CylinderShape,
38
+ DEFAULT_POLE_SEARCH_SEGMENT_TESTS: () => DEFAULT_POLE_SEARCH_SEGMENT_TESTS,
38
39
  GL: () => GL,
39
40
  GLType: () => GLType,
40
41
  GL_PRIMITIVE: () => GL_PRIMITIVE,
@@ -64,35 +65,59 @@ __export(index_exports, {
64
65
  TruncatedConeGeometry: () => TruncatedConeGeometry,
65
66
  _PerspectiveFrustum: () => PerspectiveFrustum,
66
67
  _PerspectiveOffCenterFrustum: () => PerspectiveOffCenterFrustum,
68
+ boundsContainsBounds: () => boundsContainsBounds,
69
+ boundsContainsPoint: () => boundsContainsPoint,
70
+ boundsIntersect: () => boundsIntersect,
71
+ boundsIntersectSphere: () => boundsIntersectSphere,
72
+ clampPointToBounds: () => clampPointToBounds,
67
73
  clipPolygon: () => clipPolygon,
68
74
  clipPolyline: () => clipPolyline,
69
75
  clipTriangleMesh: () => clipTriangleMesh,
76
+ composeAttributeProvenance: () => composeAttributeProvenance,
70
77
  compressTextureCoordinates: () => compressTextureCoordinates,
71
78
  computeEigenDecomposition: () => computeEigenDecomposition,
79
+ computeParallelTransportFrames: () => computeParallelTransportFrames,
72
80
  computeVertexNormals: () => computeVertexNormals,
73
81
  concatTypedArrays: () => concatTypedArrays,
82
+ createEmptyBounds: () => createEmptyBounds,
74
83
  cutPolygonByGrid: () => cutPolygonByGrid,
75
84
  cutPolygonByMercatorBounds: () => cutPolygonByMercatorBounds,
76
85
  cutPolylineByGrid: () => cutPolylineByGrid,
77
86
  cutPolylineByMercatorBounds: () => cutPolylineByMercatorBounds,
78
87
  decodeRGB565: () => decodeRGB565,
79
88
  decompressTextureCoordinates: () => decompressTextureCoordinates,
89
+ distanceToRay: () => distanceToRay,
80
90
  earcut: () => earcut,
81
91
  emod: () => emod,
82
92
  encodeRGB565: () => encodeRGB565,
93
+ expandBounds: () => expandBounds,
94
+ expandBoundsByPoint: () => expandBoundsByPoint,
95
+ extractFrustumPlanes: () => extractFrustumPlanes,
83
96
  forEachSegmentInPolygon: () => forEachSegmentInPolygon,
97
+ getClosestPointOnRay: () => getClosestPointOnRay,
84
98
  getClosestPointOnTriangle: () => getClosestPointOnTriangle,
85
99
  getClosestPointsOnSegments: () => getClosestPointsOnSegments,
100
+ getClosestPointsRaySegment: () => getClosestPointsRaySegment,
86
101
  getClosestPointsSegmentTriangle: () => getClosestPointsSegmentTriangle,
87
102
  getDegenerateTriangles: () => getDegenerateTriangles,
88
103
  getOrientedBoundingBoxQuaternion: () => getOrientedBoundingBoxQuaternion,
104
+ getPoleOfInaccessibility: () => getPoleOfInaccessibility,
89
105
  getPolygonSignedArea: () => getPolygonSignedArea,
90
106
  getPolygonWindingDirection: () => getPolygonWindingDirection,
107
+ getRayPoint: () => getRayPoint,
108
+ getTriangleArea: () => getTriangleArea,
109
+ getTriangleBarycentric: () => getTriangleBarycentric,
110
+ getTriangleNormal: () => getTriangleNormal,
91
111
  interpolatePackedAttributes: () => interpolatePackedAttributes,
112
+ interpolateTriangleAttribute: () => interpolateTriangleAttribute,
113
+ intersectBounds: () => intersectBounds,
92
114
  intersectOrientedBoxes2D: () => intersectOrientedBoxes2D,
115
+ intersectPlaneSegment: () => intersectPlaneSegment,
93
116
  intersectRayBounds: () => intersectRayBounds,
94
117
  intersectRayTriangle: () => intersectRayTriangle,
118
+ isEmptyBounds: () => isEmptyBounds,
95
119
  isGeometry: () => isGeometry,
120
+ isTriangleFrontFacing: () => isTriangleFrontFacing,
96
121
  makeAttributeIterator: () => makeAttributeIterator,
97
122
  makeAxisAlignedBoundingBoxFromPoints: () => makeAxisAlignedBoundingBoxFromPoints,
98
123
  makeBoundingSphereFromPoints: () => makeBoundingSphereFromPoints,
@@ -113,9 +138,18 @@ __export(index_exports, {
113
138
  octPack: () => octPack,
114
139
  octPackFloat: () => octPackFloat,
115
140
  octUnpack: () => octUnpack,
141
+ projectBounds: () => projectBounds,
142
+ projectTextureCoordinates: () => projectTextureCoordinates,
143
+ qualifySurfaceTransition: () => qualifySurfaceTransition,
144
+ sampleCurveAdaptive: () => sampleCurveAdaptive,
145
+ spheresIntersect: () => spheresIntersect,
116
146
  subdividePolyline: () => subdividePolyline,
117
147
  subdivideTriangleMesh: () => subdivideTriangleMesh,
118
148
  transformGeometry: () => transformGeometry,
149
+ transformRay: () => transformRay,
150
+ triangleContainsPoint: () => triangleContainsPoint,
151
+ triangleIntersectsBounds: () => triangleIntersectsBounds,
152
+ unionBounds: () => unionBounds,
119
153
  unpackIndexedGeometry: () => unpackIndexedGeometry,
120
154
  validateQueryDistance: () => validateQueryDistance,
121
155
  validateQueryPoint: () => validateQueryPoint,
@@ -263,10 +297,10 @@ var HingeTree = class {
263
297
  * Output may alias the inputs: angles and root transform are snapshotted first.
264
298
  * Finite inputs that overflow during composition throw; output may then be partial.
265
299
  */
266
- evaluate(angles, output = new Float64Array(this.panelCount * 16), rootTransform) {
300
+ evaluate(angles, output2 = new Float64Array(this.panelCount * 16), rootTransform) {
267
301
  if (angles.length !== this.panelCount)
268
302
  throw new RangeError("Expected one angle per panel");
269
- if (!(output instanceof Float64Array) || output.length !== this.panelCount * 16) {
303
+ if (!(output2 instanceof Float64Array) || output2.length !== this.panelCount * 16) {
270
304
  throw new RangeError("Expected 16 Float64 values per panel");
271
305
  }
272
306
  for (let i = 0; i < angles.length; i++) {
@@ -291,16 +325,16 @@ var HingeTree = class {
291
325
  this.world.copy(this.root);
292
326
  else {
293
327
  for (let i = 0; i < 16; i++)
294
- this.world[i] = output[joint.parent * 16 + i];
328
+ this.world[i] = output2[joint.parent * 16 + i];
295
329
  }
296
330
  this.world.multiplyRight(this.local);
297
331
  for (let i = 0; i < 16; i++) {
298
332
  if (!Number.isFinite(this.world[i]))
299
333
  throw new RangeError("Hinge transform overflow");
300
- output[index * 16 + i] = this.world[i];
334
+ output2[index * 16 + i] = this.world[i];
301
335
  }
302
336
  }
303
- return output;
337
+ return output2;
304
338
  }
305
339
  };
306
340
  function copyVector(vector) {
@@ -321,10 +355,10 @@ function validateRigidTransform(matrix) {
321
355
  throw new RangeError("Expected an affine rigid transform");
322
356
  for (let a = 0; a < 3; a++) {
323
357
  for (let b = a; b < 3; b++) {
324
- let dot4 = 0;
358
+ let dot6 = 0;
325
359
  for (let row = 0; row < 3; row++)
326
- dot4 += matrix[a * 4 + row] * matrix[b * 4 + row];
327
- if (Math.abs(dot4 - (a === b ? 1 : 0)) > tolerance) {
360
+ dot6 += matrix[a * 4 + row] * matrix[b * 4 + row];
361
+ if (Math.abs(dot6 - (a === b ? 1 : 0)) > tolerance) {
328
362
  throw new RangeError("Rigid transforms cannot scale or shear");
329
363
  }
330
364
  }
@@ -480,9 +514,9 @@ var CapsuleGeometry = class extends Geometry {
480
514
  const deltaRadius = radiusTop - radiusBottom;
481
515
  if (Math.abs(deltaRadius) >= height) {
482
516
  const topWins = radiusTop >= radiusBottom;
483
- const radius = topWins ? radiusTop : radiusBottom;
517
+ const radius2 = topWins ? radiusTop : radiusBottom;
484
518
  const center = topWins ? height / 2 : -height / 2;
485
- addSphereRings(rings, center, radius, ncap * 2);
519
+ addSphereRings(rings, center, radius2, ncap * 2);
486
520
  } else {
487
521
  const sinSlope = deltaRadius / height;
488
522
  const radialNormal = Math.sqrt(1 - sinSlope * sinSlope);
@@ -501,11 +535,11 @@ var CapsuleGeometry = class extends Geometry {
501
535
  }
502
536
  for (let i = 1; i <= nvertical; i++) {
503
537
  const t = i / nvertical;
504
- const radius = radiusBottom + deltaRadius * t;
538
+ const radius2 = radiusBottom + deltaRadius * t;
505
539
  const center = bottomCenter + height * t;
506
540
  rings.push({
507
- radius: radius * radialNormal,
508
- y: center + radius * sideNormalY,
541
+ radius: radius2 * radialNormal,
542
+ y: center + radius2 * sideNormalY,
509
543
  normalRadius: radialNormal,
510
544
  normalY: sideNormalY
511
545
  });
@@ -535,14 +569,14 @@ var CapsuleGeometry = class extends Geometry {
535
569
  });
536
570
  }
537
571
  };
538
- function addSphereRings(rings, center, radius, segments) {
572
+ function addSphereRings(rings, center, radius2, segments) {
539
573
  for (let i = 0; i <= segments; i++) {
540
574
  const angle = -Math.PI / 2 + i / segments * Math.PI;
541
575
  const normalRadius = Math.cos(angle);
542
576
  const normalY = Math.sin(angle);
543
577
  rings.push({
544
- radius: radius * normalRadius,
545
- y: center + radius * normalY,
578
+ radius: radius2 * normalRadius,
579
+ y: center + radius2 * normalY,
546
580
  normalRadius,
547
581
  normalY
548
582
  });
@@ -567,16 +601,16 @@ var TruncatedConeGeometry = class extends Geometry {
567
601
  const stride = nradial + 1;
568
602
  const slope = (bottomRadius - topRadius) / height;
569
603
  const normalScale = 1 / Math.hypot(1, slope);
570
- const addRing = (radius, y, normalRadius, normalY, v) => {
604
+ const addRing = (radius2, y, normalRadius, normalY, v) => {
571
605
  const ring = positions.length / 3 / stride;
572
606
  for (let radial2 = 0; radial2 <= nradial; radial2++) {
573
607
  const u = radial2 / nradial;
574
608
  const angle = u * Math.PI * 2;
575
609
  const sin = Math.sin(angle);
576
610
  const cos = Math.cos(angle);
577
- const point = orient([sin * radius, y, cos * radius], verticalAxis);
611
+ const point2 = orient([sin * radius2, y, cos * radius2], verticalAxis);
578
612
  const normal = orient([sin * normalRadius, normalY, cos * normalRadius], verticalAxis);
579
- positions.push(...point);
613
+ positions.push(...point2);
580
614
  normals.push(...normal);
581
615
  texCoords.push(u, v);
582
616
  }
@@ -600,8 +634,8 @@ var TruncatedConeGeometry = class extends Geometry {
600
634
  }
601
635
  for (let vertical = 0; vertical <= nvertical; vertical++) {
602
636
  const v = vertical / nvertical;
603
- const radius = bottomRadius + (topRadius - bottomRadius) * v;
604
- const ring = addRing(radius, (v - 0.5) * height, normalScale, slope * normalScale, v);
637
+ const radius2 = bottomRadius + (topRadius - bottomRadius) * v;
638
+ const ring = addRing(radius2, (v - 0.5) * height, normalScale, slope * normalScale, v);
605
639
  if (previous !== void 0 && !(bottomCap && vertical === 0))
606
640
  connect(previous, ring);
607
641
  previous = ring;
@@ -653,8 +687,8 @@ var CylinderGeometry = class extends TruncatedConeGeometry {
653
687
  };
654
688
  var ConeGeometry = class extends TruncatedConeGeometry {
655
689
  constructor(props = {}) {
656
- const { radius = 0.5, topCap = false, bottomCap = true } = props;
657
- super({ ...props, topRadius: 0, bottomRadius: radius, topCap, bottomCap });
690
+ const { radius: radius2 = 0.5, topCap = false, bottomCap = true } = props;
691
+ super({ ...props, topRadius: 0, bottomRadius: radius2, topCap, bottomCap });
658
692
  }
659
693
  };
660
694
 
@@ -707,8 +741,8 @@ var PlaneGeometry = class extends Geometry {
707
741
  // dist/geometries/sphere-geometry.js
708
742
  var SphereGeometry = class extends Geometry {
709
743
  constructor(props = {}) {
710
- const { radius = 0.5, nlat = 10, nlong = 10 } = props;
711
- assertPositive(radius, "radius");
744
+ const { radius: radius2 = 0.5, nlat = 10, nlong = 10 } = props;
745
+ assertPositive(radius2, "radius");
712
746
  assertSegments(nlat, "nlat", 2);
713
747
  assertSegments(nlong, "nlong", 3);
714
748
  const rings = [];
@@ -716,7 +750,7 @@ var SphereGeometry = class extends Geometry {
716
750
  const angle = -Math.PI / 2 + latitude / nlat * Math.PI;
717
751
  const normalRadius = Math.cos(angle);
718
752
  const normalY = Math.sin(angle);
719
- rings.push({ radius: radius * normalRadius, y: radius * normalY, normalRadius, normalY });
753
+ rings.push({ radius: radius2 * normalRadius, y: radius2 * normalY, normalRadius, normalY });
720
754
  }
721
755
  const mesh = makeSurfaceOfRevolution(rings, nlong);
722
756
  super({
@@ -736,8 +770,8 @@ var SphereGeometry = class extends Geometry {
736
770
  // dist/geometries/ico-sphere-geometry.js
737
771
  var IcoSphereGeometry = class extends Geometry {
738
772
  constructor(props = {}) {
739
- const { radius = 0.5, iterations = 0 } = props;
740
- assertPositive(radius, "radius");
773
+ const { radius: radius2 = 0.5, iterations = 0 } = props;
774
+ assertPositive(radius2, "radius");
741
775
  assertSegments(iterations, "iterations", 0);
742
776
  if (iterations > 8)
743
777
  throw new Error("iterations must be <= 8");
@@ -793,7 +827,7 @@ var IcoSphereGeometry = class extends Geometry {
793
827
  const texCoords = [];
794
828
  for (const face of faces2) {
795
829
  for (const normal of face) {
796
- positions.push(normal[0] * radius, normal[1] * radius, normal[2] * radius);
830
+ positions.push(normal[0] * radius2, normal[1] * radius2, normal[2] * radius2);
797
831
  normals.push(...normal);
798
832
  texCoords.push(0.5 + Math.atan2(normal[0], normal[2]) / (2 * Math.PI), 0.5 - Math.asin(normal[1]) / Math.PI);
799
833
  }
@@ -817,12 +851,12 @@ function normalize(vector) {
817
851
 
818
852
  // dist/geometries/primitive-mesh-builder.js
819
853
  var FULL_CIRCLE = Math.PI * 2;
820
- function radial(angle, direction = 1) {
821
- return [Math.cos(angle) * direction, 0, -Math.sin(angle) * direction];
854
+ function radial(angle, direction2 = 1) {
855
+ return [Math.cos(angle) * direction2, 0, -Math.sin(angle) * direction2];
822
856
  }
823
- function vertex(radius, height, angle, normal, textureCoordinates) {
857
+ function vertex(radius2, height, angle, normal, textureCoordinates) {
824
858
  return {
825
- position: [radius * Math.cos(angle), height, -radius * Math.sin(angle)],
859
+ position: [radius2 * Math.cos(angle), height, -radius2 * Math.sin(angle)],
826
860
  normal,
827
861
  textureCoordinates: textureCoordinates ?? [(Math.cos(angle) + 1) / 2, (Math.sin(angle) + 1) / 2]
828
862
  };
@@ -851,12 +885,12 @@ var PrimitiveMeshBuilder = class {
851
885
  addTriangle(first, second, third, indices) {
852
886
  const firstEdge = second.position.map((value, index) => value - first.position[index]);
853
887
  const secondEdge = third.position.map((value, index) => value - first.position[index]);
854
- const cross4 = [
888
+ const cross6 = [
855
889
  firstEdge[1] * secondEdge[2] - firstEdge[2] * secondEdge[1],
856
890
  firstEdge[2] * secondEdge[0] - firstEdge[0] * secondEdge[2],
857
891
  firstEdge[0] * secondEdge[1] - firstEdge[1] * secondEdge[0]
858
892
  ];
859
- const orientation = cross4.reduce((sum, value, index) => sum + value * (first.normal[index] + second.normal[index] + third.normal[index]), 0);
893
+ const orientation = cross6.reduce((sum, value, index) => sum + value * (first.normal[index] + second.normal[index] + third.normal[index]), 0);
860
894
  this.indices.push(...orientation < 0 ? [indices[0], indices[2], indices[1]] : indices);
861
895
  }
862
896
  triangle(first, second, third) {
@@ -889,8 +923,8 @@ var PrimitiveMeshBuilder = class {
889
923
  // dist/geometries/prism-geometry.js
890
924
  var PrismGeometry = class extends Geometry {
891
925
  constructor(props = {}) {
892
- const { radius = 1, height = 1, sides = 6, startAngle = 0 } = props;
893
- assertPositive(radius, "radius");
926
+ const { radius: radius2 = 1, height = 1, sides = 6, startAngle = 0 } = props;
927
+ assertPositive(radius2, "radius");
894
928
  assertPositive(height, "height");
895
929
  validateArc(sides, startAngle, FULL_CIRCLE);
896
930
  const mesh = new PrimitiveMeshBuilder();
@@ -899,15 +933,15 @@ var PrismGeometry = class extends Geometry {
899
933
  const secondAngle = startAngle + (segment + 1) * FULL_CIRCLE / sides;
900
934
  const normal = radial((firstAngle + secondAngle) / 2);
901
935
  const secondCornerAngle = segment === sides - 1 ? startAngle : secondAngle;
902
- mesh.quad(vertex(radius, -height / 2, firstAngle, normal, [segment / sides, 0]), vertex(radius, height / 2, firstAngle, normal, [segment / sides, 1]), vertex(radius, height / 2, secondCornerAngle, normal, [(segment + 1) / sides, 1]), vertex(radius, -height / 2, secondCornerAngle, normal, [(segment + 1) / sides, 0]));
903
- for (const direction of [-1, 1]) {
904
- const capNormal = [0, direction, 0];
936
+ mesh.quad(vertex(radius2, -height / 2, firstAngle, normal, [segment / sides, 0]), vertex(radius2, height / 2, firstAngle, normal, [segment / sides, 1]), vertex(radius2, height / 2, secondCornerAngle, normal, [(segment + 1) / sides, 1]), vertex(radius2, -height / 2, secondCornerAngle, normal, [(segment + 1) / sides, 0]));
937
+ for (const direction2 of [-1, 1]) {
938
+ const capNormal = [0, direction2, 0];
905
939
  const center = {
906
- position: [0, direction * height / 2, 0],
940
+ position: [0, direction2 * height / 2, 0],
907
941
  normal: capNormal,
908
942
  textureCoordinates: [0.5, 0.5]
909
943
  };
910
- mesh.triangle(center, vertex(radius, direction * height / 2, firstAngle, capNormal), vertex(radius, direction * height / 2, secondCornerAngle, capNormal));
944
+ mesh.triangle(center, vertex(radius2, direction2 * height / 2, firstAngle, capNormal), vertex(radius2, direction2 * height / 2, secondCornerAngle, capNormal));
911
945
  }
912
946
  }
913
947
  super(mesh.getProps(props));
@@ -928,39 +962,39 @@ var RingGeometry = class extends Geometry {
928
962
  for (let segment = 0; segment < segments; segment++) {
929
963
  const firstAngle = startAngle + segment * sweepAngle / segments;
930
964
  const secondAngle = segment === segments - 1 ? sweepAngle === FULL_CIRCLE ? startAngle : startAngle + sweepAngle : startAngle + (segment + 1) * sweepAngle / segments;
931
- const makeCapVertex = (radius, height2, angle, normal) => vertex(radius, height2, angle, normal, [
932
- (radius * Math.cos(angle) / outerRadius + 1) / 2,
933
- (radius * Math.sin(angle) / outerRadius + 1) / 2
965
+ const makeCapVertex = (radius2, height2, angle, normal) => vertex(radius2, height2, angle, normal, [
966
+ (radius2 * Math.cos(angle) / outerRadius + 1) / 2,
967
+ (radius2 * Math.sin(angle) / outerRadius + 1) / 2
934
968
  ]);
935
- for (const direction of [-1, 1]) {
936
- const normal = [0, direction, 0];
937
- mesh.quad(makeCapVertex(innerRadius, direction * height / 2, firstAngle, normal), makeCapVertex(outerRadius, direction * height / 2, firstAngle, normal), makeCapVertex(outerRadius, direction * height / 2, secondAngle, normal), makeCapVertex(innerRadius, direction * height / 2, secondAngle, normal));
969
+ for (const direction2 of [-1, 1]) {
970
+ const normal = [0, direction2, 0];
971
+ mesh.quad(makeCapVertex(innerRadius, direction2 * height / 2, firstAngle, normal), makeCapVertex(outerRadius, direction2 * height / 2, firstAngle, normal), makeCapVertex(outerRadius, direction2 * height / 2, secondAngle, normal), makeCapVertex(innerRadius, direction2 * height / 2, secondAngle, normal));
938
972
  }
939
- for (const [radius, direction] of [
973
+ for (const [radius2, direction2] of [
940
974
  [innerRadius, -1],
941
975
  [outerRadius, 1]
942
976
  ]) {
943
- mesh.quad(vertex(radius, -height / 2, firstAngle, radial(firstAngle, direction), [
977
+ mesh.quad(vertex(radius2, -height / 2, firstAngle, radial(firstAngle, direction2), [
944
978
  segment / segments,
945
979
  0
946
- ]), vertex(radius, height / 2, firstAngle, radial(firstAngle, direction), [
980
+ ]), vertex(radius2, height / 2, firstAngle, radial(firstAngle, direction2), [
947
981
  segment / segments,
948
982
  1
949
- ]), vertex(radius, height / 2, secondAngle, radial(secondAngle, direction), [
983
+ ]), vertex(radius2, height / 2, secondAngle, radial(secondAngle, direction2), [
950
984
  (segment + 1) / segments,
951
985
  1
952
- ]), vertex(radius, -height / 2, secondAngle, radial(secondAngle, direction), [
986
+ ]), vertex(radius2, -height / 2, secondAngle, radial(secondAngle, direction2), [
953
987
  (segment + 1) / segments,
954
988
  0
955
989
  ]));
956
990
  }
957
991
  }
958
992
  if (sweepAngle < FULL_CIRCLE) {
959
- for (const [angle, direction] of [
993
+ for (const [angle, direction2] of [
960
994
  [startAngle, -1],
961
995
  [startAngle + sweepAngle, 1]
962
996
  ]) {
963
- const normal = [-Math.sin(angle) * direction, 0, -Math.cos(angle) * direction];
997
+ const normal = [-Math.sin(angle) * direction2, 0, -Math.cos(angle) * direction2];
964
998
  mesh.quad(vertex(innerRadius, -height / 2, angle, normal, [0, 0]), vertex(outerRadius, -height / 2, angle, normal, [1, 0]), vertex(outerRadius, height / 2, angle, normal, [1, 1]), vertex(innerRadius, height / 2, angle, normal, [0, 1]));
965
999
  }
966
1000
  }
@@ -1072,8 +1106,8 @@ var TorusGeometry = class extends ParametricGeometry {
1072
1106
  periodicU: arc === Math.PI * 2,
1073
1107
  periodicV: true,
1074
1108
  sample: (u, v) => {
1075
- const theta = startAngle + u * arc, phi = v * Math.PI * 2, radius = majorRadius + minorRadius * Math.cos(phi);
1076
- return [radius * Math.cos(theta), minorRadius * Math.sin(phi), -radius * Math.sin(theta)];
1109
+ const theta = startAngle + u * arc, phi = v * Math.PI * 2, radius2 = majorRadius + minorRadius * Math.cos(phi);
1110
+ return [radius2 * Math.cos(theta), minorRadius * Math.sin(phi), -radius2 * Math.sin(theta)];
1077
1111
  },
1078
1112
  normal: (u, v) => [
1079
1113
  Math.cos(v * Math.PI * 2) * Math.cos(startAngle + u * arc),
@@ -1087,25 +1121,25 @@ var TorusGeometry = class extends ParametricGeometry {
1087
1121
  const normals = Array.from(this.attributes["NORMAL"].value);
1088
1122
  const textureCoordinates = Array.from(this.attributes["TEXCOORD_0"].value);
1089
1123
  const indices = Array.from(this.indices.value);
1090
- for (const [angle, direction] of [
1124
+ for (const [angle, direction2] of [
1091
1125
  [startAngle, -1],
1092
1126
  [startAngle + arc, 1]
1093
1127
  ]) {
1094
- const normal = [-Math.sin(angle) * direction, 0, -Math.cos(angle) * direction];
1128
+ const normal = [-Math.sin(angle) * direction2, 0, -Math.cos(angle) * direction2];
1095
1129
  const centerIndex = positions.length / 3;
1096
1130
  positions.push(majorRadius * Math.cos(angle), 0, -majorRadius * Math.sin(angle));
1097
1131
  normals.push(...normal);
1098
1132
  textureCoordinates.push(0.5, 0.5);
1099
1133
  for (let minorSegment = 0; minorSegment <= minorSegments; minorSegment++) {
1100
1134
  const tubeAngle = minorSegment % minorSegments * Math.PI * 2 / minorSegments;
1101
- const boundaryOffset = (minorSegment * (majorSegments + 1) + (direction < 0 ? 0 : majorSegments)) * 3;
1135
+ const boundaryOffset = (minorSegment * (majorSegments + 1) + (direction2 < 0 ? 0 : majorSegments)) * 3;
1102
1136
  positions.push(...surfacePositions.slice(boundaryOffset, boundaryOffset + 3));
1103
1137
  normals.push(...normal);
1104
1138
  textureCoordinates.push((Math.cos(tubeAngle) + 1) / 2, (Math.sin(tubeAngle) + 1) / 2);
1105
1139
  if (minorSegment < minorSegments) {
1106
1140
  const firstIndex = centerIndex + minorSegment + 1;
1107
1141
  const secondIndex = firstIndex + 1;
1108
- indices.push(centerIndex, ...direction > 0 ? [secondIndex, firstIndex] : [firstIndex, secondIndex]);
1142
+ indices.push(centerIndex, ...direction2 > 0 ? [secondIndex, firstIndex] : [firstIndex, secondIndex]);
1109
1143
  }
1110
1144
  }
1111
1145
  }
@@ -1160,8 +1194,8 @@ var LatheGeometry = class extends ParametricGeometry {
1160
1194
  vSegments: profile.length - 1,
1161
1195
  periodicU: phiLength === Math.PI * 2,
1162
1196
  sample: (u, v) => {
1163
- const { i, t } = section(v), radius = profile[i][0] * (1 - t) + profile[i + 1][0] * t, height = profile[i][1] * (1 - t) + profile[i + 1][1] * t, theta = phiStart + u * phiLength;
1164
- return [radius * Math.cos(theta), height, -radius * Math.sin(theta)];
1197
+ const { i, t } = section(v), radius2 = profile[i][0] * (1 - t) + profile[i + 1][0] * t, height = profile[i][1] * (1 - t) + profile[i + 1][1] * t, theta = phiStart + u * phiLength;
1198
+ return [radius2 * Math.cos(theta), height, -radius2 * Math.sin(theta)];
1165
1199
  },
1166
1200
  normal: (u, v) => {
1167
1201
  const { i, t } = section(v), n = profileNormals[i].map((value, axis) => value * (1 - t) + profileNormals[i + 1][axis] * t), theta = phiStart + u * phiLength;
@@ -1680,26 +1714,26 @@ function transformGeometry(geometry, matrix) {
1680
1714
  const positions = new Float64Array(mesh.count * 3);
1681
1715
  const source = mesh.attributes[mesh.position].value;
1682
1716
  for (let i = 0; i < mesh.count; i++) {
1683
- const point = transform.transformAsPoint([source[i * 3], source[i * 3 + 1], source[i * 3 + 2]]);
1684
- positions.set(point, i * 3);
1717
+ const point2 = transform.transformAsPoint([source[i * 3], source[i * 3 + 1], source[i * 3 + 2]]);
1718
+ positions.set(point2, i * 3);
1685
1719
  }
1686
1720
  attributes[mesh.position] = { size: 3, value: positions };
1687
1721
  if (normalName) {
1688
1722
  const input = mesh.attributes[normalName];
1689
1723
  if (input.size !== 3)
1690
1724
  throw new RangeError("Normals must have size 3");
1691
- const output = new Float64Array(mesh.count * 3);
1725
+ const output2 = new Float64Array(mesh.count * 3);
1692
1726
  for (let i = 0; i < mesh.count; i++) {
1693
1727
  const value = normalizedLinearCombination(cofactors, Array.from(input.value.slice(i * 3, i * 3 + 3)), scales.map((v) => -Math.log(v)));
1694
- output.set(value.map((v) => determinant < 0 ? -v : v), i * 3);
1728
+ output2.set(value.map((v) => determinant < 0 ? -v : v), i * 3);
1695
1729
  }
1696
- attributes[normalName] = { size: 3, value: output };
1730
+ attributes[normalName] = { size: 3, value: output2 };
1697
1731
  }
1698
1732
  if (tangentName) {
1699
1733
  const input = mesh.attributes[tangentName];
1700
1734
  if (input.size !== 4)
1701
1735
  throw new RangeError("Tangents must have size 4");
1702
- const output = new Float64Array(mesh.count * 4);
1736
+ const output2 = new Float64Array(mesh.count * 4);
1703
1737
  for (let i = 0; i < mesh.count; i++) {
1704
1738
  const value = normalizedLinearCombination(basis, Array.from(input.value.slice(i * 4, i * 4 + 3)), scales.map(Math.log));
1705
1739
  if (normalName) {
@@ -1709,10 +1743,10 @@ function transformGeometry(geometry, matrix) {
1709
1743
  value[axis] -= projection * n[axis];
1710
1744
  }
1711
1745
  const length = Math.hypot(...value);
1712
- output.set(value.map((v) => length ? v / length : 0), i * 4);
1713
- output[i * 4 + 3] = input.value[i * 4 + 3] * (determinant < 0 ? -1 : 1);
1746
+ output2.set(value.map((v) => length ? v / length : 0), i * 4);
1747
+ output2[i * 4 + 3] = input.value[i * 4 + 3] * (determinant < 0 ? -1 : 1);
1714
1748
  }
1715
- attributes[tangentName] = { size: 4, value: output };
1749
+ attributes[tangentName] = { size: 4, value: output2 };
1716
1750
  }
1717
1751
  const indices = mesh.indices.slice();
1718
1752
  if (determinant < 0)
@@ -1972,8 +2006,8 @@ function interpolatePackedAttributes(source, provenance, options) {
1972
2006
  }
1973
2007
  const sourceCount = source.byteLength / byteStride;
1974
2008
  const input = new DataView(source.buffer, source.byteOffset, source.byteLength);
1975
- const output = new Uint8Array(outputBytes);
1976
- const result = new DataView(output.buffer);
2009
+ const output2 = new Uint8Array(outputBytes);
2010
+ const result = new DataView(output2.buffer);
1977
2011
  for (let vertex2 = 0; vertex2 < outputCount; vertex2++) {
1978
2012
  let sum = 0;
1979
2013
  let firstSource = -1;
@@ -1994,7 +2028,7 @@ function interpolatePackedAttributes(source, provenance, options) {
1994
2028
  if (firstSource < 0 || Math.abs(sum - 1) > 1e-10) {
1995
2029
  throw new RangeError("Interpolation weights must sum to one");
1996
2030
  }
1997
- output.set(source.subarray(firstSource * byteStride, (firstSource + 1) * byteStride), vertex2 * byteStride);
2031
+ output2.set(source.subarray(firstSource * byteStride, (firstSource + 1) * byteStride), vertex2 * byteStride);
1998
2032
  for (const attribute of attributes) {
1999
2033
  for (let component = 0; component < attribute.size; component++) {
2000
2034
  const offset = attribute.byteOffset + component * BYTE_SIZES[attribute.type];
@@ -2023,7 +2057,7 @@ function interpolatePackedAttributes(source, provenance, options) {
2023
2057
  }
2024
2058
  }
2025
2059
  }
2026
- return output;
2060
+ return output2;
2027
2061
  }
2028
2062
  function validateInterpolation(interpolation) {
2029
2063
  if (interpolation !== "linear" && interpolation !== "flat") {
@@ -2082,11 +2116,11 @@ function writeComponent(view, offset, type, value, littleEndian) {
2082
2116
 
2083
2117
  // dist/curves/curve.js
2084
2118
  var Curve = class {
2085
- constructor(dimension) {
2086
- if (dimension !== 2 && dimension !== 3) {
2119
+ constructor(dimension2) {
2120
+ if (dimension2 !== 2 && dimension2 !== 3) {
2087
2121
  throw new RangeError("Curve points must have two or three coordinates");
2088
2122
  }
2089
- this.dimension = dimension;
2123
+ this.dimension = dimension2;
2090
2124
  }
2091
2125
  getPoint(t, result = new Array(this.dimension)) {
2092
2126
  validateParameter(t);
@@ -2113,10 +2147,10 @@ var Curve = class {
2113
2147
  getPoints(divisions = 64) {
2114
2148
  validateDivisions(divisions);
2115
2149
  const points = new Float64Array((divisions + 1) * this.dimension);
2116
- const point = new Array(this.dimension);
2150
+ const point2 = new Array(this.dimension);
2117
2151
  for (let i = 0; i <= divisions; i++) {
2118
- this.getPoint(i / divisions, point);
2119
- points.set(point, i * this.dimension);
2152
+ this.getPoint(i / divisions, point2);
2153
+ points.set(point2, i * this.dimension);
2120
2154
  }
2121
2155
  return points;
2122
2156
  }
@@ -2124,14 +2158,14 @@ var Curve = class {
2124
2158
  function copyPoints(points) {
2125
2159
  if (!points.length)
2126
2160
  throw new RangeError("Invalid number of curve control points");
2127
- const dimension = points[0].length;
2128
- if (dimension !== 2 && dimension !== 3) {
2161
+ const dimension2 = points[0].length;
2162
+ if (dimension2 !== 2 && dimension2 !== 3) {
2129
2163
  throw new RangeError("Curve points must have two or three coordinates");
2130
2164
  }
2131
- return points.map((point) => {
2132
- if (point.length !== dimension)
2165
+ return points.map((point2) => {
2166
+ if (point2.length !== dimension2)
2133
2167
  throw new RangeError("Control point dimensions must match");
2134
- return Array.from(point, (value) => {
2168
+ return Array.from(point2, (value) => {
2135
2169
  if (!Number.isFinite(value))
2136
2170
  throw new RangeError("Control coordinates must be finite");
2137
2171
  return value;
@@ -2148,8 +2182,8 @@ function validateDivisions(divisions) {
2148
2182
  throw new RangeError("divisions must be a positive safe integer");
2149
2183
  }
2150
2184
  }
2151
- function validateResult(result, dimension) {
2152
- if (result.length < dimension)
2185
+ function validateResult(result, dimension2) {
2186
+ if (result.length < dimension2)
2153
2187
  throw new RangeError("Result buffer is too short");
2154
2188
  }
2155
2189
 
@@ -2241,7 +2275,7 @@ var CatmullRomCurve = class extends Curve {
2241
2275
  if (options.tension !== void 0 && mode !== "uniform") {
2242
2276
  throw new RangeError("tension is only supported for uniform splines");
2243
2277
  }
2244
- const point = (index) => {
2278
+ const point2 = (index) => {
2245
2279
  if (this.closed)
2246
2280
  return data[(index + data.length) % data.length];
2247
2281
  if (index < 0)
@@ -2253,10 +2287,10 @@ var CatmullRomCurve = class extends Curve {
2253
2287
  };
2254
2288
  this.segments = [];
2255
2289
  for (let s = 0; s < data.length - (this.closed ? 0 : 1); s++) {
2256
- const p0 = point(s - 1);
2257
- const p1 = point(s);
2258
- const p2 = point(s + 1);
2259
- const p3 = point(s + 2);
2290
+ const p0 = point2(s - 1);
2291
+ const p1 = point2(s);
2292
+ const p2 = point2(s + 1);
2293
+ const p3 = point2(s + 2);
2260
2294
  const interval = (a, b) => {
2261
2295
  const distance = Math.hypot(...a.map((x, i) => b[i] - x));
2262
2296
  return distance ** (mode === "chordal" ? 1 : 0.5);
@@ -2333,23 +2367,144 @@ var CurveArcLength = class {
2333
2367
  getSpacedPoints(divisions = 64) {
2334
2368
  validateDivisions(divisions);
2335
2369
  const points = new Float64Array((divisions + 1) * this.curve.dimension);
2336
- const point = new Array(this.curve.dimension);
2370
+ const point2 = new Array(this.curve.dimension);
2337
2371
  for (let i = 0; i <= divisions; i++) {
2338
- this.getPointAt(i / divisions, point);
2339
- points.set(point, i * this.curve.dimension);
2372
+ this.getPointAt(i / divisions, point2);
2373
+ points.set(point2, i * this.curve.dimension);
2340
2374
  }
2341
2375
  return points;
2342
2376
  }
2343
2377
  };
2344
2378
 
2379
+ // dist/curves/adaptive-sampling.js
2380
+ function sampleCurveAdaptive(curve, options) {
2381
+ const { tolerance, maxDepth = 16, maxPoints = 65536 } = options;
2382
+ if (!Number.isFinite(tolerance) || tolerance <= 0 || !Number.isInteger(maxDepth) || maxDepth < 0 || maxDepth > 30 || !Number.isSafeInteger(maxPoints) || maxPoints < 2)
2383
+ throw new RangeError("Invalid adaptive sampling budget");
2384
+ const parameters = [0], positions = [...curve.getPoint(0)];
2385
+ let converged = true, maxSampledError = 0;
2386
+ const stack = [{ t0: 0, t1: 1, a: curve.getPoint(0), b: curve.getPoint(1), depth: 0 }];
2387
+ while (stack.length) {
2388
+ const segment = stack.pop();
2389
+ const { t0, t1, a, b, depth } = segment;
2390
+ const localEdge = b.map((x, i) => x - a[i]);
2391
+ const samples = [0.25, 0.5, 0.75].map((f) => curve.getPoint(t0 + (t1 - t0) * f));
2392
+ const localSamples = samples.map((point2) => point2.map((x, i) => x - a[i]));
2393
+ const local = [...localEdge, ...localSamples.flat()].every(Number.isFinite);
2394
+ const scale = local ? Math.max(...localEdge.map(Math.abs), ...localSamples.flat().map(Math.abs), Number.MIN_VALUE) : Math.max(...a.map(Math.abs), ...b.map(Math.abs), ...samples.flat().map(Math.abs));
2395
+ const edge = local ? localEdge.map((x) => x / scale) : b.map((x, i) => x / scale - a[i] / scale);
2396
+ const squared = edge.reduce((sum, x) => sum + x * x, 0);
2397
+ const measuredError = Math.max(...samples.map((p, sampleIndex) => {
2398
+ const offset = local ? localSamples[sampleIndex].map((x) => x / scale) : p.map((x, i) => x / scale - a[i] / scale);
2399
+ const t = squared ? Math.max(0, Math.min(1, edge.reduce((sum, x, i) => sum + x * offset[i], 0) / squared)) : 0;
2400
+ return Math.hypot(...offset.map((x, i) => x - t * edge[i])) * scale;
2401
+ }));
2402
+ const error = Number.isFinite(measuredError) ? measuredError : Infinity;
2403
+ if (error > tolerance && depth < maxDepth && parameters.length + stack.length + 2 <= maxPoints) {
2404
+ const mid = (t0 + t1) / 2;
2405
+ stack.push({ t0: mid, t1, a: samples[1], b, depth: depth + 1 });
2406
+ stack.push({ t0, t1: mid, a, b: samples[1], depth: depth + 1 });
2407
+ } else {
2408
+ if (error > tolerance)
2409
+ converged = false;
2410
+ maxSampledError = Math.max(maxSampledError, error);
2411
+ parameters.push(t1);
2412
+ positions.push(...b);
2413
+ }
2414
+ }
2415
+ return {
2416
+ parameters: new Float64Array(parameters),
2417
+ positions: new Float64Array(positions),
2418
+ converged,
2419
+ maxSampledError
2420
+ };
2421
+ }
2422
+
2423
+ // dist/curves/parallel-transport.js
2424
+ var sub = (a, b) => a.map((x, i) => x - b[i]);
2425
+ var dot = (a, b) => a.reduce((sum, x, i) => sum + x * b[i], 0);
2426
+ var cross2 = (a, b) => [
2427
+ a[1] * b[2] - a[2] * b[1],
2428
+ a[2] * b[0] - a[0] * b[2],
2429
+ a[0] * b[1] - a[1] * b[0]
2430
+ ];
2431
+ var unit = (a) => {
2432
+ const length = Math.hypot(...a);
2433
+ if (!length)
2434
+ throw new RangeError("Cannot construct a frame for a stationary path");
2435
+ return a.map((x) => x / length);
2436
+ };
2437
+ function rotate(v, axis, angle) {
2438
+ const c = Math.cos(angle), s = Math.sin(angle), d = dot(axis, v), k = cross2(axis, v);
2439
+ return v.map((x, i) => x * c + k[i] * s + axis[i] * d * (1 - c));
2440
+ }
2441
+ function computeParallelTransportFrames(points, options = {}) {
2442
+ if (points.length < 2 || points.some((p) => p.length !== 3 || Array.from(p).some((x) => !Number.isFinite(x))))
2443
+ throw new RangeError("Expected at least two finite 3D points");
2444
+ const data = points.map((p) => Array.from(p)), n = data.length, closed = options.closed ?? false;
2445
+ if (closed && (n < 4 || Math.hypot(...sub(data[0], data[n - 1])) !== 0))
2446
+ throw new RangeError("A closed path must repeat its first point");
2447
+ const tangent = new Array(n);
2448
+ const edges = new Array(n - 1);
2449
+ let last;
2450
+ for (let i = 0; i < n - 1; i++) {
2451
+ const edge = sub(data[i + 1], data[i]);
2452
+ if (Math.hypot(...edge) > 0)
2453
+ last = edges[i] = unit(edge);
2454
+ }
2455
+ if (!last)
2456
+ throw new RangeError("Cannot construct a frame for a stationary path");
2457
+ tangent[n - 1] = last;
2458
+ for (let i = n - 2; i >= 0; i--) {
2459
+ last = edges[i] ?? last;
2460
+ tangent[i] = last;
2461
+ }
2462
+ if (closed)
2463
+ tangent[n - 1] = [...tangent[0]];
2464
+ const t = tangent[0];
2465
+ let initial = options.initialNormal ? Array.from(options.initialNormal) : [0, 0, 0];
2466
+ if (options.initialNormal && (initial.length !== 3 || initial.some((x) => !Number.isFinite(x))))
2467
+ throw new RangeError("Invalid initial normal");
2468
+ if (!options.initialNormal) {
2469
+ initial = [0, 0, 0];
2470
+ initial[t.map(Math.abs).indexOf(Math.min(...t.map(Math.abs)))] = 1;
2471
+ }
2472
+ initial = unit(initial);
2473
+ const perpendicular = cross2(t, initial);
2474
+ if (Math.hypot(...perpendicular) <= 1e-12) {
2475
+ throw new RangeError("Initial normal must not be parallel to the tangent");
2476
+ }
2477
+ const normals = [unit(cross2(perpendicular, t))];
2478
+ for (let i = 1; i < n; i++) {
2479
+ const axis = cross2(tangent[i - 1], tangent[i]), length = Math.hypot(...axis), cosine = Math.max(-1, Math.min(1, dot(tangent[i - 1], tangent[i])));
2480
+ let normal = normals[i - 1];
2481
+ if (length > 1e-12)
2482
+ normal = rotate(normal, axis.map((x) => x / length), Math.atan2(length, cosine));
2483
+ normals.push(unit(normal.map((x, j) => x - dot(normal, tangent[i]) * tangent[i][j])));
2484
+ }
2485
+ if (closed) {
2486
+ const mismatch = Math.atan2(dot(tangent[0], cross2(normals[n - 1], normals[0])), dot(normals[n - 1], normals[0]));
2487
+ const lengths = [0];
2488
+ for (let i = 1; i < n; i++)
2489
+ lengths.push(lengths[i - 1] + Math.hypot(...sub(data[i], data[i - 1])));
2490
+ for (let i = 1; i < n; i++)
2491
+ normals[i] = rotate(normals[i], tangent[i], mismatch * lengths[i] / lengths[n - 1]);
2492
+ }
2493
+ return {
2494
+ tangents: new Float64Array(tangent.flat()),
2495
+ normals: new Float64Array(normals.flat()),
2496
+ binormals: new Float64Array(normals.flatMap((normal, i) => cross2(tangent[i], normal)))
2497
+ };
2498
+ }
2499
+
2345
2500
  // dist/polygon/polygon.js
2346
2501
  var import_core6 = require("@math.gl/core");
2347
2502
 
2348
2503
  // dist/polygon/polygon-utils.js
2349
2504
  var import_core5 = require("@math.gl/core");
2350
- function modifyPolygonWindingDirection(points, direction, options = {}) {
2505
+ function modifyPolygonWindingDirection(points, direction2, options = {}) {
2351
2506
  const windingDirection = getPolygonWindingDirection(points, options);
2352
- if (windingDirection !== direction) {
2507
+ if (windingDirection !== direction2) {
2353
2508
  reversePolygon(points, options);
2354
2509
  return true;
2355
2510
  }
@@ -2401,9 +2556,9 @@ function reversePolygon(points, options) {
2401
2556
  }
2402
2557
  }
2403
2558
  }
2404
- function modifyPolygonWindingDirectionPoints(points, direction, options = {}) {
2559
+ function modifyPolygonWindingDirectionPoints(points, direction2, options = {}) {
2405
2560
  const currentDirection = getPolygonWindingDirectionPoints(points, options);
2406
- if (currentDirection !== direction) {
2561
+ if (currentDirection !== direction2) {
2407
2562
  points.reverse();
2408
2563
  return true;
2409
2564
  }
@@ -2505,16 +2660,34 @@ var Polygon = class {
2505
2660
  * @param direction Requested winding direction.
2506
2661
  * @return Returns true if the winding direction was changed.
2507
2662
  */
2508
- modifyWindingDirection(direction) {
2663
+ modifyWindingDirection(direction2) {
2509
2664
  if (this.isFlatArray) {
2510
- return modifyPolygonWindingDirection(this.points, direction, this.options);
2665
+ return modifyPolygonWindingDirection(this.points, direction2, this.options);
2511
2666
  }
2512
- return modifyPolygonWindingDirectionPoints(this.points, direction, this.options);
2667
+ return modifyPolygonWindingDirectionPoints(this.points, direction2, this.options);
2513
2668
  }
2514
2669
  };
2515
2670
 
2516
2671
  // dist/polygon/earcut.js
2517
2672
  function earcut(positions, holeIndices, dim = 2, areas, plane = "xy") {
2673
+ const savedIndex = vertexPoolIndex;
2674
+ const savedQueue = activeHoleQueue;
2675
+ if (!holeQueues[callDepth])
2676
+ holeQueues[callDepth] = [];
2677
+ activeHoleQueue = holeQueues[callDepth];
2678
+ callDepth++;
2679
+ try {
2680
+ return triangulate(positions, holeIndices, dim, areas, plane);
2681
+ } finally {
2682
+ activeHoleQueue.length = 0;
2683
+ activeHoleQueue = savedQueue;
2684
+ vertexPoolIndex = savedIndex;
2685
+ callDepth--;
2686
+ if (callDepth === 0 && vertexPool.length > 65536)
2687
+ vertexPool.length = 0;
2688
+ }
2689
+ }
2690
+ function triangulate(positions, holeIndices, dim, areas, plane) {
2518
2691
  const hasHoles = holeIndices && holeIndices.length;
2519
2692
  const outerLen = hasHoles ? holeIndices[0] * dim : positions.length;
2520
2693
  let outerNode = linkedList(positions, 0, outerLen, dim, true, areas && areas[0], plane);
@@ -2531,11 +2704,13 @@ function earcut(positions, holeIndices, dim = 2, areas, plane = "xy") {
2531
2704
  if (hasHoles)
2532
2705
  outerNode = eliminateHoles(positions, holeIndices, outerNode, dim, areas, plane);
2533
2706
  if (positions.length > 80 * dim) {
2534
- minX = maxX = positions[0];
2535
- minY = maxY = positions[1];
2707
+ const i0 = DimIndex[plane[0]];
2708
+ const i1 = DimIndex[plane[1]];
2709
+ minX = maxX = positions[i0];
2710
+ minY = maxY = positions[i1];
2536
2711
  for (let i = dim; i < outerLen; i += dim) {
2537
- x = positions[i];
2538
- y = positions[i + 1];
2712
+ x = positions[i + i0];
2713
+ y = positions[i + i1];
2539
2714
  if (x < minX)
2540
2715
  minX = x;
2541
2716
  if (y < minY)
@@ -2548,23 +2723,44 @@ function earcut(positions, holeIndices, dim = 2, areas, plane = "xy") {
2548
2723
  invSize = Math.max(maxX - minX, maxY - minY);
2549
2724
  invSize = invSize !== 0 ? 32767 / invSize : 0;
2550
2725
  }
2551
- earcutLinked(outerNode, triangles, dim, minX, minY, invSize, 0);
2726
+ earcutLinked(outerNode, triangles, minX, minY, invSize, 0);
2552
2727
  return triangles;
2553
2728
  }
2554
2729
  function linkedList(data, start, end, dim, clockwise, area2, plane) {
2730
+ if (start >= end)
2731
+ return null;
2555
2732
  let i;
2556
2733
  let last;
2734
+ const i0 = DimIndex[plane[0]];
2735
+ const i1 = DimIndex[plane[1]];
2557
2736
  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) {
2737
+ let sum = 0;
2738
+ let previousX = data[end - dim + i0];
2739
+ let previousY = data[end - dim + i1];
2740
+ for (i = start; i < end; i += dim) {
2741
+ const x = data[i + i0];
2742
+ const y = data[i + i1];
2743
+ sum += (x - previousX) * (y + previousY);
2744
+ last = insertNode(i / dim, x, y, last);
2745
+ previousX = x;
2746
+ previousY = y;
2747
+ }
2748
+ if (last && clockwise !== sum / 2 < 0) {
2749
+ let node = last;
2750
+ do {
2751
+ const next = node.next;
2752
+ node.next = node.prev;
2753
+ node.prev = next;
2754
+ node = next;
2755
+ } while (node !== last);
2756
+ last = last.prev;
2757
+ }
2758
+ } else if (clockwise === area2 < 0) {
2563
2759
  for (i = start; i < end; i += dim)
2564
- last = insertNode(i, data[i + i0], data[i + i1], last);
2760
+ last = insertNode(i / dim, data[i + i0], data[i + i1], last);
2565
2761
  } else {
2566
2762
  for (i = end - dim; i >= start; i -= dim)
2567
- last = insertNode(i, data[i + i0], data[i + i1], last);
2763
+ last = insertNode(i / dim, data[i + i0], data[i + i1], last);
2568
2764
  }
2569
2765
  if (last && equals2(last, last.next)) {
2570
2766
  removeNode(last);
@@ -2593,7 +2789,7 @@ function filterPoints(start, end) {
2593
2789
  } while (again || p !== end);
2594
2790
  return end;
2595
2791
  }
2596
- function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
2792
+ function earcutLinked(ear, triangles, minX, minY, invSize, pass) {
2597
2793
  if (!ear)
2598
2794
  return;
2599
2795
  if (!pass && invSize)
@@ -2605,9 +2801,9 @@ function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
2605
2801
  prev = ear.prev;
2606
2802
  next = ear.next;
2607
2803
  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);
2804
+ triangles.push(prev.i);
2805
+ triangles.push(ear.i);
2806
+ triangles.push(next.i);
2611
2807
  removeNode(ear);
2612
2808
  ear = next.next;
2613
2809
  stop = next.next;
@@ -2616,12 +2812,12 @@ function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
2616
2812
  ear = next;
2617
2813
  if (ear === stop) {
2618
2814
  if (!pass) {
2619
- earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);
2815
+ earcutLinked(filterPoints(ear), triangles, minX, minY, invSize, 1);
2620
2816
  } else if (pass === 1) {
2621
- ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
2622
- earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
2817
+ ear = cureLocalIntersections(filterPoints(ear), triangles);
2818
+ earcutLinked(ear, triangles, minX, minY, invSize, 2);
2623
2819
  } else if (pass === 2) {
2624
- splitEarcut(ear, triangles, dim, minX, minY, invSize);
2820
+ splitEarcut(ear, triangles, minX, minY, invSize);
2625
2821
  }
2626
2822
  break;
2627
2823
  }
@@ -2691,15 +2887,15 @@ function isEarHashed(ear, minX, minY, invSize) {
2691
2887
  }
2692
2888
  return true;
2693
2889
  }
2694
- function cureLocalIntersections(start, triangles, dim) {
2890
+ function cureLocalIntersections(start, triangles) {
2695
2891
  let p = start;
2696
2892
  do {
2697
2893
  const a = p.prev;
2698
2894
  const b = p.next.next;
2699
2895
  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);
2896
+ triangles.push(a.i);
2897
+ triangles.push(p.i);
2898
+ triangles.push(b.i);
2703
2899
  removeNode(p);
2704
2900
  removeNode(p.next);
2705
2901
  p = start = b;
@@ -2708,7 +2904,7 @@ function cureLocalIntersections(start, triangles, dim) {
2708
2904
  } while (p !== start);
2709
2905
  return filterPoints(p);
2710
2906
  }
2711
- function splitEarcut(start, triangles, dim, minX, minY, invSize) {
2907
+ function splitEarcut(start, triangles, minX, minY, invSize) {
2712
2908
  let a = start;
2713
2909
  do {
2714
2910
  let b = a.next.next;
@@ -2717,8 +2913,8 @@ function splitEarcut(start, triangles, dim, minX, minY, invSize) {
2717
2913
  let c = splitPolygon(a, b);
2718
2914
  a = filterPoints(a, a.next);
2719
2915
  c = filterPoints(c, c.next);
2720
- earcutLinked(a, triangles, dim, minX, minY, invSize, 0);
2721
- earcutLinked(c, triangles, dim, minX, minY, invSize, 0);
2916
+ earcutLinked(a, triangles, minX, minY, invSize, 0);
2917
+ earcutLinked(c, triangles, minX, minY, invSize, 0);
2722
2918
  return;
2723
2919
  }
2724
2920
  b = b.next;
@@ -2727,7 +2923,8 @@ function splitEarcut(start, triangles, dim, minX, minY, invSize) {
2727
2923
  } while (a !== start);
2728
2924
  }
2729
2925
  function eliminateHoles(data, holeIndices, outerNode, dim, areas, plane) {
2730
- const queue = [];
2926
+ const queue = activeHoleQueue;
2927
+ queue.length = 0;
2731
2928
  let i;
2732
2929
  let len;
2733
2930
  let start;
@@ -2737,6 +2934,8 @@ function eliminateHoles(data, holeIndices, outerNode, dim, areas, plane) {
2737
2934
  start = holeIndices[i] * dim;
2738
2935
  end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
2739
2936
  list = linkedList(data, start, end, dim, false, areas && areas[i + 1], plane);
2937
+ if (!list)
2938
+ continue;
2740
2939
  if (list === list.next)
2741
2940
  list.steiner = true;
2742
2941
  queue.push(getLeftmost(list));
@@ -2949,8 +3148,8 @@ function middleInside(a, b) {
2949
3148
  return inside;
2950
3149
  }
2951
3150
  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);
3151
+ const a2 = allocateVertex(a.i, a.x, a.y);
3152
+ const b2 = allocateVertex(b.i, b.x, b.y);
2954
3153
  const an = a.next;
2955
3154
  const bp = b.prev;
2956
3155
  a.next = b;
@@ -2964,7 +3163,7 @@ function splitPolygon(a, b) {
2964
3163
  return b2;
2965
3164
  }
2966
3165
  function insertNode(i, x, y, last) {
2967
- const p = new Vertex(i, x, y);
3166
+ const p = allocateVertex(i, x, y);
2968
3167
  if (!last) {
2969
3168
  p.prev = p;
2970
3169
  p.next = p;
@@ -2984,6 +3183,24 @@ function removeNode(p) {
2984
3183
  if (p.nextZ)
2985
3184
  p.nextZ.prevZ = p.prevZ;
2986
3185
  }
3186
+ var vertexPool = [];
3187
+ var vertexPoolIndex = 0;
3188
+ var holeQueues = [];
3189
+ var activeHoleQueue = [];
3190
+ var callDepth = 0;
3191
+ function allocateVertex(i, x, y) {
3192
+ let vertex2 = vertexPool[vertexPoolIndex];
3193
+ if (!vertex2)
3194
+ vertexPool[vertexPoolIndex] = vertex2 = new Vertex(i, x, y);
3195
+ vertexPoolIndex++;
3196
+ vertex2.i = i;
3197
+ vertex2.x = x;
3198
+ vertex2.y = y;
3199
+ vertex2.prev = vertex2.next = vertex2.prevZ = vertex2.nextZ = null;
3200
+ vertex2.z = 0;
3201
+ vertex2.steiner = false;
3202
+ return vertex2;
3203
+ }
2987
3204
  var Vertex = class {
2988
3205
  constructor(i, x, y) {
2989
3206
  this.prev = null;
@@ -3147,6 +3364,234 @@ function bitCode(p, bbox) {
3147
3364
  return code;
3148
3365
  }
3149
3366
 
3367
+ // dist/polygon/pole-of-inaccessibility.js
3368
+ var MAX_GRID_CELLS_PER_AXIS = 64;
3369
+ var MIN_RELATIVE_PRECISION = 1e-6;
3370
+ var DEFAULT_POLE_SEARCH_SEGMENT_TESTS = 5e6;
3371
+ function getPoleOfInaccessibility(polygon, precision, budget = {
3372
+ segmentTests: DEFAULT_POLE_SEARCH_SEGMENT_TESTS
3373
+ }) {
3374
+ const outline = polygon[0];
3375
+ if (!outline || outline.length === 0) {
3376
+ return null;
3377
+ }
3378
+ const vertexCount = countFiniteVertices(polygon);
3379
+ if (vertexCount < 0) {
3380
+ return null;
3381
+ }
3382
+ const box = getRingBox(outline);
3383
+ const width = box.right - box.left;
3384
+ const height = box.top - box.bottom;
3385
+ if (width === 0 || height === 0) {
3386
+ return null;
3387
+ }
3388
+ const longSide = Math.max(width, height);
3389
+ const minTolerance = longSide * MIN_RELATIVE_PRECISION;
3390
+ const tolerance = Math.max(Number.isFinite(precision) && precision > 0 ? precision : 0, minTolerance);
3391
+ const search = new PoleSearch(polygon, vertexCount, budget);
3392
+ const [centroidX, centroidY] = getAreaCentroid(polygon[0]);
3393
+ if (!search.score(centroidX, centroidY, 0)) {
3394
+ return null;
3395
+ }
3396
+ if (!search.score(box.left + width / 2, box.bottom + height / 2, 0)) {
3397
+ return search.bestPoint();
3398
+ }
3399
+ const side = Math.max(Math.min(width, height), longSide / MAX_GRID_CELLS_PER_AXIS);
3400
+ const columns = Math.ceil(width / side);
3401
+ const rows = Math.ceil(height / side);
3402
+ for (let column = 0; column < columns; column++) {
3403
+ for (let row = 0; row < rows; row++) {
3404
+ const x = box.left + (column + 0.5) * side;
3405
+ const y = box.bottom + (row + 0.5) * side;
3406
+ if (!search.score(x, y, side / 2)) {
3407
+ return search.bestPoint();
3408
+ }
3409
+ }
3410
+ }
3411
+ search.refine(tolerance, minTolerance);
3412
+ return search.bestPoint();
3413
+ }
3414
+ function countFiniteVertices(polygon) {
3415
+ let count = 0;
3416
+ for (const ring of polygon) {
3417
+ for (const point2 of ring) {
3418
+ if (!Number.isFinite(point2[0]) || !Number.isFinite(point2[1])) {
3419
+ return -1;
3420
+ }
3421
+ }
3422
+ count += ring.length;
3423
+ }
3424
+ return count;
3425
+ }
3426
+ function getRingBox(ring) {
3427
+ let left = Infinity;
3428
+ let bottom = Infinity;
3429
+ let right = -Infinity;
3430
+ let top = -Infinity;
3431
+ for (const point2 of ring) {
3432
+ left = Math.min(left, point2[0]);
3433
+ right = Math.max(right, point2[0]);
3434
+ bottom = Math.min(bottom, point2[1]);
3435
+ top = Math.max(top, point2[1]);
3436
+ }
3437
+ return { left, bottom, right, top };
3438
+ }
3439
+ function getAreaCentroid(ring) {
3440
+ let twiceArea = 0;
3441
+ let sumX = 0;
3442
+ let sumY = 0;
3443
+ let previous = ring[ring.length - 1];
3444
+ for (const current of ring) {
3445
+ const cross6 = previous[0] * current[1] - current[0] * previous[1];
3446
+ twiceArea += cross6;
3447
+ sumX += (previous[0] + current[0]) * cross6;
3448
+ sumY += (previous[1] + current[1]) * cross6;
3449
+ previous = current;
3450
+ }
3451
+ if (twiceArea === 0) {
3452
+ return [ring[0][0], ring[0][1]];
3453
+ }
3454
+ return [sumX / (3 * twiceArea), sumY / (3 * twiceArea)];
3455
+ }
3456
+ var PoleSearch = class {
3457
+ constructor(polygon, vertexCount, budget) {
3458
+ this.centerX = [];
3459
+ this.centerY = [];
3460
+ this.halfSide = [];
3461
+ this.reach = [];
3462
+ this.heap = [];
3463
+ this.bestX = NaN;
3464
+ this.bestY = NaN;
3465
+ this.bestDistance = -Infinity;
3466
+ this.polygon = polygon;
3467
+ this.vertexCount = vertexCount;
3468
+ this.budget = budget;
3469
+ }
3470
+ /** The best point so far, or null if no scored point is inside the polygon. */
3471
+ bestPoint() {
3472
+ return this.bestDistance > 0 ? [this.bestX, this.bestY] : null;
3473
+ }
3474
+ /**
3475
+ * Scores the square centered at (x, y), keeps its center if it is the best so far, and queues
3476
+ * the square if it has area. Returns false, without scoring, when the budget cannot pay.
3477
+ */
3478
+ score(x, y, half) {
3479
+ if (this.budget.segmentTests < this.vertexCount) {
3480
+ return false;
3481
+ }
3482
+ this.budget.segmentTests -= this.vertexCount;
3483
+ const distance = getSignedOutlineDistance(this.polygon, x, y);
3484
+ if (distance > this.bestDistance) {
3485
+ this.bestX = x;
3486
+ this.bestY = y;
3487
+ this.bestDistance = distance;
3488
+ }
3489
+ if (half > 0) {
3490
+ this.enqueue(x, y, half, distance + half * Math.SQRT2);
3491
+ }
3492
+ return true;
3493
+ }
3494
+ /**
3495
+ * Splits the most promising squares until none can beat the best point by `tolerance`. While no
3496
+ * scored point is inside the polygon, `tolerance` does not apply: the search continues while a
3497
+ * square can hold an inside point and is larger than `minTolerance`.
3498
+ */
3499
+ refine(tolerance, minTolerance) {
3500
+ while (this.heap.length > 0) {
3501
+ const index = this.dequeue();
3502
+ const reach = this.reach[index];
3503
+ if (this.bestDistance > 0 ? reach - this.bestDistance <= tolerance : reach <= 0) {
3504
+ return;
3505
+ }
3506
+ if (this.bestDistance <= 0 && this.halfSide[index] * Math.SQRT2 <= minTolerance) {
3507
+ continue;
3508
+ }
3509
+ const quarter = this.halfSide[index] / 2;
3510
+ const x = this.centerX[index];
3511
+ const y = this.centerY[index];
3512
+ if (!this.score(x - quarter, y - quarter, quarter) || !this.score(x + quarter, y - quarter, quarter) || !this.score(x - quarter, y + quarter, quarter) || !this.score(x + quarter, y + quarter, quarter)) {
3513
+ return;
3514
+ }
3515
+ }
3516
+ }
3517
+ enqueue(x, y, half, reach) {
3518
+ const index = this.reach.length;
3519
+ this.centerX.push(x);
3520
+ this.centerY.push(y);
3521
+ this.halfSide.push(half);
3522
+ this.reach.push(reach);
3523
+ const { heap } = this;
3524
+ let slot = heap.length;
3525
+ heap.push(index);
3526
+ while (slot > 0) {
3527
+ const parentSlot = slot - 1 >> 1;
3528
+ if (this.reach[heap[parentSlot]] >= reach) {
3529
+ break;
3530
+ }
3531
+ heap[slot] = heap[parentSlot];
3532
+ slot = parentSlot;
3533
+ }
3534
+ heap[slot] = index;
3535
+ }
3536
+ dequeue() {
3537
+ const { heap, reach } = this;
3538
+ const top = heap[0];
3539
+ const moved = heap.pop();
3540
+ const size = heap.length;
3541
+ if (size === 0) {
3542
+ return top;
3543
+ }
3544
+ let slot = 0;
3545
+ for (; ; ) {
3546
+ let next = slot * 2 + 1;
3547
+ if (next >= size) {
3548
+ break;
3549
+ }
3550
+ if (next + 1 < size && reach[heap[next + 1]] > reach[heap[next]]) {
3551
+ next += 1;
3552
+ }
3553
+ if (reach[heap[next]] <= reach[moved]) {
3554
+ break;
3555
+ }
3556
+ heap[slot] = heap[next];
3557
+ slot = next;
3558
+ }
3559
+ heap[slot] = moved;
3560
+ return top;
3561
+ }
3562
+ };
3563
+ function getSignedOutlineDistance(polygon, x, y) {
3564
+ let nearestSquared = Infinity;
3565
+ let crossings = 0;
3566
+ for (const ring of polygon) {
3567
+ let start = ring[ring.length - 1];
3568
+ for (const end of ring) {
3569
+ if (start[1] <= y !== end[1] <= y) {
3570
+ const t = (y - start[1]) / (end[1] - start[1]);
3571
+ if (start[0] + t * (end[0] - start[0]) > x) {
3572
+ crossings++;
3573
+ }
3574
+ }
3575
+ nearestSquared = Math.min(nearestSquared, getSquaredSegmentDistance(x, y, start, end));
3576
+ start = end;
3577
+ }
3578
+ }
3579
+ if (nearestSquared === 0) {
3580
+ return 0;
3581
+ }
3582
+ const distance = Math.sqrt(nearestSquared);
3583
+ return crossings % 2 === 1 ? distance : -distance;
3584
+ }
3585
+ function getSquaredSegmentDistance(x, y, start, end) {
3586
+ const edgeX = end[0] - start[0];
3587
+ const edgeY = end[1] - start[1];
3588
+ const lengthSquared = edgeX * edgeX + edgeY * edgeY;
3589
+ const along = lengthSquared === 0 ? 0 : Math.max(0, Math.min(1, ((x - start[0]) * edgeX + (y - start[1]) * edgeY) / lengthSquared));
3590
+ const offsetX = start[0] + along * edgeX - x;
3591
+ const offsetY = start[1] + along * edgeY - y;
3592
+ return offsetX * offsetX + offsetY * offsetY;
3593
+ }
3594
+
3150
3595
  // dist/polygon/cut-by-grid.js
3151
3596
  function cutPolylineByGrid(positions, options) {
3152
3597
  const { size = 2, broken = false, gridResolution = 10, gridOffset = [0, 0], startIndex = 0, endIndex = positions.length } = options || {};
@@ -3476,16 +3921,16 @@ function subdividePolyline(input, options) {
3476
3921
  throw new RangeError("Transform returned nonfinite coordinates");
3477
3922
  return { source, target, fraction };
3478
3923
  }
3479
- function append(point, segment) {
3924
+ function append(point2, segment) {
3480
3925
  if (segmentIndices.length >= maxVertices) {
3481
3926
  throw new RangeError("Polyline subdivision exceeded maxVertices");
3482
3927
  }
3483
- for (const value of point.source)
3928
+ for (const value of point2.source)
3484
3929
  sourcePositions.push(value);
3485
- for (const value of point.target)
3930
+ for (const value of point2.target)
3486
3931
  positions.push(value);
3487
3932
  segmentIndices.push(segment);
3488
- segmentFractions.push(point.fraction);
3933
+ segmentFractions.push(point2.fraction);
3489
3934
  }
3490
3935
  function sampledSource(sampler, fraction) {
3491
3936
  const value = sampler.sample(fraction);
@@ -3505,10 +3950,10 @@ function subdividePolyline(input, options) {
3505
3950
  let error = 0;
3506
3951
  let midpoint;
3507
3952
  for (const fraction of [0.25, 0.5, 0.75]) {
3508
- const point = interpolate(a, b, fraction, sampler);
3953
+ const point2 = interpolate(a, b, fraction, sampler);
3509
3954
  if (fraction === 0.5)
3510
- midpoint = point;
3511
- const delta = point.target.map((value, i) => value - (a.target[i] * (1 - fraction) + b.target[i] * fraction));
3955
+ midpoint = point2;
3956
+ const delta = point2.target.map((value, i) => value - (a.target[i] * (1 - fraction) + b.target[i] * fraction));
3512
3957
  error = Math.max(error, Math.hypot(...delta));
3513
3958
  }
3514
3959
  const sourceLength = sampler ? sampler.length * (b.fraction - a.fraction) : Math.hypot(...a.source.map((value, i) => value - b.source[i]));
@@ -3561,7 +4006,7 @@ var FACE_WEIGHTS = [
3561
4006
  [0.25, 0.25, 0.5]
3562
4007
  ];
3563
4008
  function subdivideTriangleMesh(mesh, options) {
3564
- const { transform, tolerance, refinement = "transform-error", size = 2, targetSize = size, maxEdgeLength = Infinity, maxDepth = 10, maxVertices = 65536, maxTriangles = 131072 } = options;
4009
+ const { transform, tolerance, errorMetric, refinement = "transform-error", size = 2, targetSize = size, maxEdgeLength = Infinity, maxDepth = 10, maxVertices = 65536, maxTriangles = 131072 } = options;
3565
4010
  validateOptions();
3566
4011
  const vertices = [];
3567
4012
  let faces2 = [];
@@ -3608,7 +4053,7 @@ function subdivideTriangleMesh(mesh, options) {
3608
4053
  faces2 = refined;
3609
4054
  }
3610
4055
  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)
4056
+ 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
4057
  throw new RangeError("Invalid triangle mesh subdivision options or input lengths");
3613
4058
  if (mesh.positions.length / size > maxVertices || mesh.indices.length / 3 > maxTriangles) {
3614
4059
  throw new RangeError("Input mesh exceeds subdivision limits");
@@ -3627,7 +4072,14 @@ function subdivideTriangleMesh(mesh, options) {
3627
4072
  function error(points, weights) {
3628
4073
  const source = blend(points.map((p) => p.source), weights);
3629
4074
  const linearTarget = blend(points.map((p) => p.target), weights);
3630
- return Math.hypot(...project(source).map((value, i) => value - linearTarget[i]));
4075
+ const exact = project(source);
4076
+ if (!errorMetric)
4077
+ return Math.hypot(...exact.map((value2, i) => value2 - linearTarget[i]));
4078
+ const value = errorMetric({ source, exact, interpolated: linearTarget });
4079
+ if (!Number.isFinite(value) || value < 0) {
4080
+ throw new RangeError("errorMetric must return a finite nonnegative value");
4081
+ }
4082
+ return value;
3631
4083
  }
3632
4084
  function needsRefinement(face) {
3633
4085
  const points = face.vertices.map((index) => vertices[index]);
@@ -3670,7 +4122,7 @@ function subdivideTriangleMesh(mesh, options) {
3670
4122
  midpoints.set(key, index);
3671
4123
  return index;
3672
4124
  }
3673
- function splitFace(face, output, splitEdges, midpoints) {
4125
+ function splitFace(face, output2, splitEdges, midpoints) {
3674
4126
  const [a, b, c] = face.vertices;
3675
4127
  const ab = splitEdges.has(edgeKey(a, b)) ? midpoint(a, b, midpoints) : -1;
3676
4128
  const bc = splitEdges.has(edgeKey(b, c)) ? midpoint(b, c, midpoints) : -1;
@@ -3703,9 +4155,9 @@ function subdivideTriangleMesh(mesh, options) {
3703
4155
  }
3704
4156
  }
3705
4157
  function emit(x, y, z) {
3706
- if (output.length >= maxTriangles)
4158
+ if (output2.length >= maxTriangles)
3707
4159
  throw new RangeError("Triangle mesh subdivision exceeded maxTriangles");
3708
- output.push({ vertices: [x, y, z], sourceTriangle: face.sourceTriangle });
4160
+ output2.push({ vertices: [x, y, z], sourceTriangle: face.sourceTriangle });
3709
4161
  }
3710
4162
  }
3711
4163
  function buildResult() {
@@ -3768,8 +4220,8 @@ function clipTriangleMesh(mesh, options) {
3768
4220
  const positions = [], indices = [], sourceVertexIndices = [], sourceVertexWeights = [];
3769
4221
  const sourceTriangleIndices = [], periodicCopies = [];
3770
4222
  let intersections = 0;
3771
- for (let triangle = 0; triangle < inputIndices.length / 3; triangle++) {
3772
- const originalIndices = inputIndices.slice(triangle * 3, triangle * 3 + 3);
4223
+ for (let triangle2 = 0; triangle2 < inputIndices.length / 3; triangle2++) {
4224
+ const originalIndices = inputIndices.slice(triangle2 * 3, triangle2 * 3 + 3);
3773
4225
  const vertices = originalIndices.map((index, j) => ({
3774
4226
  position: source.slice(index * size, index * size + size),
3775
4227
  weights: [0, 1, 2].map((k) => Number(k === j))
@@ -3801,7 +4253,7 @@ function clipTriangleMesh(mesh, options) {
3801
4253
  const clipped = [];
3802
4254
  for (let i = 0; i < polygon.length; i++) {
3803
4255
  const p = polygon[i], q = polygon[(i + 1) % polygon.length];
3804
- const dp = cross2(a, b, p.position), dq = cross2(a, b, q.position);
4256
+ const dp = cross3(a, b, p.position), dq = cross3(a, b, q.position);
3805
4257
  if (dp >= 0)
3806
4258
  clipped.push(p);
3807
4259
  if (dp < 0 !== dq < 0) {
@@ -3817,7 +4269,7 @@ function clipTriangleMesh(mesh, options) {
3817
4269
  }
3818
4270
  for (let j = 1; j + 1 < polygon.length; j++) {
3819
4271
  const face = [polygon[0], polygon[j], polygon[j + 1]];
3820
- if (cross2(face[0].position, face[1].position, face[2].position) === 0)
4272
+ if (cross3(face[0].position, face[1].position, face[2].position) === 0)
3821
4273
  continue;
3822
4274
  if (positions.length / size + 3 > maxVertices || indices.length / 3 + 1 > maxTriangles)
3823
4275
  throw new RangeError("Mesh clipping exceeded output limits");
@@ -3827,7 +4279,7 @@ function clipTriangleMesh(mesh, options) {
3827
4279
  sourceVertexIndices.push(...originalIndices);
3828
4280
  sourceVertexWeights.push(...vertex2.weights);
3829
4281
  }
3830
- sourceTriangleIndices.push(triangle);
4282
+ sourceTriangleIndices.push(triangle2);
3831
4283
  periodicCopies.push(copy2);
3832
4284
  }
3833
4285
  }
@@ -3842,7 +4294,7 @@ function clipTriangleMesh(mesh, options) {
3842
4294
  periodicCopies: new Int32Array(periodicCopies)
3843
4295
  };
3844
4296
  }
3845
- function cross2(a, b, p) {
4297
+ function cross3(a, b, p) {
3846
4298
  const result = (b[0] - a[0]) * (p[1] - a[1]) - (b[1] - a[1]) * (p[0] - a[0]);
3847
4299
  if (!Number.isFinite(result))
3848
4300
  throw new RangeError("Unrepresentable clipping arithmetic");
@@ -3853,13 +4305,13 @@ function validateRegion(region) {
3853
4305
  throw new RangeError("Invalid convex clipping region");
3854
4306
  let area2 = 0;
3855
4307
  for (let i = 1; i + 1 < region.length; i++)
3856
- area2 += cross2(region[0], region[i], region[i + 1]);
4308
+ area2 += cross3(region[0], region[i], region[i + 1]);
3857
4309
  if (!Number.isFinite(area2) || area2 === 0)
3858
4310
  throw new RangeError("Degenerate clipping region");
3859
4311
  const result = area2 > 0 ? Array.from(region) : Array.from(region).reverse();
3860
4312
  for (let i = 0; i < result.length; i++) {
3861
4313
  const a = result[i], b = result[(i + 1) % result.length];
3862
- if (a[0] === b[0] && a[1] === b[1] || result.some((p) => cross2(a, b, p) < 0))
4314
+ if (a[0] === b[0] && a[1] === b[1] || result.some((p) => cross3(a, b, p) < 0))
3863
4315
  throw new RangeError("Clip region must be convex");
3864
4316
  }
3865
4317
  return result;
@@ -3902,15 +4354,25 @@ var AxisAlignedBoundingBox = class _AxisAlignedBoundingBox {
3902
4354
  return this === right || Boolean(right) && this.minimum.equals(right.minimum) && this.maximum.equals(right.maximum);
3903
4355
  }
3904
4356
  /**
3905
- * Applies a 4x4 affine transformation matrix to a bounding sphere.
3906
- * @param transform The transformation matrix to apply to the bounding sphere.
3907
- * @returns itself, i.e. the modified BoundingVolume.
4357
+ * Transforms an AABB by a finite affine matrix, rebuilding all bounds and extents.
4358
+ * @param transform The affine transformation matrix.
4359
+ * @returns itself, i.e. the modified bounding box.
3908
4360
  */
3909
4361
  transform(transform) {
3910
- this.center.transformAsPoint(transform);
3911
- this.halfDiagonal.transform(transform);
3912
- this.minimum.transform(transform);
3913
- this.maximum.transform(transform);
4362
+ if (transform.length !== 16 || transform.some((x) => !Number.isFinite(x)) || transform[3] !== 0 || transform[7] !== 0 || transform[11] !== 0 || transform[15] !== 1) {
4363
+ throw new RangeError("Expected a finite affine matrix");
4364
+ }
4365
+ const center = this.minimum.clone().add(this.maximum).scale(0.5);
4366
+ const extent = this.maximum.clone().subtract(this.minimum).scale(0.5);
4367
+ if (extent.some((x) => x < 0))
4368
+ throw new RangeError("Bounds must be ordered");
4369
+ center.transformAsPoint(transform);
4370
+ for (let row = 0; row < 3; row++) {
4371
+ this.halfDiagonal[row] = Math.abs(transform[row]) * extent[0] + Math.abs(transform[row + 4]) * extent[1] + Math.abs(transform[row + 8]) * extent[2];
4372
+ }
4373
+ this.center.copy(center);
4374
+ this.minimum.copy(center).subtract(this.halfDiagonal);
4375
+ this.maximum.copy(center).add(this.halfDiagonal);
3914
4376
  return this;
3915
4377
  }
3916
4378
  /**
@@ -3930,12 +4392,12 @@ var AxisAlignedBoundingBox = class _AxisAlignedBoundingBox {
3930
4392
  return "intersecting";
3931
4393
  }
3932
4394
  /** Computes the estimated distance from the closest point on a bounding box to a point. */
3933
- distanceTo(point) {
3934
- return Math.sqrt(this.distanceSquaredTo(point));
4395
+ distanceTo(point2) {
4396
+ return Math.sqrt(this.distanceSquaredTo(point2));
3935
4397
  }
3936
4398
  /** Computes the estimated distance squared from the closest point on a bounding box to a point. */
3937
- distanceSquaredTo(point) {
3938
- const offset = scratchVector.from(point).subtract(this.center);
4399
+ distanceSquaredTo(point2) {
4400
+ const offset = scratchVector.from(point2).subtract(this.center);
3939
4401
  const { halfDiagonal } = this;
3940
4402
  let distanceSquared = 0;
3941
4403
  let d;
@@ -3962,15 +4424,15 @@ var scratchVector4 = new import_core8.Vector3();
3962
4424
  var scratchVector22 = new import_core8.Vector3();
3963
4425
  var BoundingSphere = class _BoundingSphere {
3964
4426
  /** Creates a bounding sphere */
3965
- constructor(center = [0, 0, 0], radius = 0) {
4427
+ constructor(center = [0, 0, 0], radius2 = 0) {
3966
4428
  this.radius = -0;
3967
4429
  this.center = new import_core8.Vector3();
3968
- this.fromCenterRadius(center, radius);
4430
+ this.fromCenterRadius(center, radius2);
3969
4431
  }
3970
4432
  /** Sets the bounding sphere from `center` and `radius`. */
3971
- fromCenterRadius(center, radius) {
4433
+ fromCenterRadius(center, radius2) {
3972
4434
  this.center.from(center);
3973
- this.radius = radius;
4435
+ this.radius = radius2;
3974
4436
  return this;
3975
4437
  }
3976
4438
  /**
@@ -4012,11 +4474,11 @@ var BoundingSphere = class _BoundingSphere {
4012
4474
  return this;
4013
4475
  }
4014
4476
  /** Computes a bounding sphere by enlarging the provided sphere to contain the provided point. */
4015
- expand(point) {
4016
- const scratchPoint = scratchVector4.from(point);
4017
- const radius = scratchPoint.subtract(this.center).magnitude();
4018
- if (radius > this.radius) {
4019
- this.radius = radius;
4477
+ expand(point2) {
4478
+ const scratchPoint = scratchVector4.from(point2);
4479
+ const radius2 = scratchPoint.subtract(this.center).magnitude();
4480
+ if (radius2 > this.radius) {
4481
+ this.radius = radius2;
4020
4482
  }
4021
4483
  return this;
4022
4484
  }
@@ -4034,26 +4496,26 @@ var BoundingSphere = class _BoundingSphere {
4034
4496
  return this;
4035
4497
  }
4036
4498
  /** Computes the estimated distance squared from the closest point on a bounding sphere to a point. */
4037
- distanceSquaredTo(point) {
4038
- const d = this.distanceTo(point);
4499
+ distanceSquaredTo(point2) {
4500
+ const d = this.distanceTo(point2);
4039
4501
  return d * d;
4040
4502
  }
4041
4503
  /** Computes the estimated distance from the closest point on a bounding sphere to a point. */
4042
- distanceTo(point) {
4043
- const scratchPoint = scratchVector4.from(point);
4504
+ distanceTo(point2) {
4505
+ const scratchPoint = scratchVector4.from(point2);
4044
4506
  const delta = scratchPoint.subtract(this.center);
4045
4507
  return Math.max(0, delta.len() - this.radius);
4046
4508
  }
4047
4509
  /** Determines which side of a plane a sphere is located. */
4048
4510
  intersectPlane(plane) {
4049
4511
  const center = this.center;
4050
- const radius = this.radius;
4512
+ const radius2 = this.radius;
4051
4513
  const normal = plane.normal;
4052
4514
  const distanceToPlane = normal.dot(center) + plane.distance;
4053
- if (distanceToPlane < -radius) {
4515
+ if (distanceToPlane < -radius2) {
4054
4516
  return "outside";
4055
4517
  }
4056
- if (distanceToPlane < radius) {
4518
+ if (distanceToPlane < radius2) {
4057
4519
  return "intersecting";
4058
4520
  }
4059
4521
  return "inside";
@@ -4129,16 +4591,16 @@ var OrientedBoundingBox = class _OrientedBoundingBox {
4129
4591
  return "intersecting";
4130
4592
  }
4131
4593
  /** Computes the estimated distance from the closest point on a bounding box to a point. */
4132
- distanceTo(point) {
4133
- return Math.sqrt(this.distanceSquaredTo(point));
4594
+ distanceTo(point2) {
4595
+ return Math.sqrt(this.distanceSquaredTo(point2));
4134
4596
  }
4135
4597
  /**
4136
4598
  * Computes the estimated distance squared from the closest point
4137
4599
  * on a bounding box to a point.
4138
4600
  * See Geometric Tools for Computer Graphics 10.4.2
4139
4601
  */
4140
- distanceSquaredTo(point) {
4141
- const offset = scratchOffset.from(point).subtract(this.center);
4602
+ distanceSquaredTo(point2) {
4603
+ const offset = scratchOffset.from(point2).subtract(this.center);
4142
4604
  const halfAxes = this.halfAxes;
4143
4605
  const u = halfAxes.getColumn(0, scratchVectorU);
4144
4606
  const v = halfAxes.getColumn(1, scratchVectorV);
@@ -4180,7 +4642,7 @@ var OrientedBoundingBox = class _OrientedBoundingBox {
4180
4642
  * on the bounding box from position in direction.
4181
4643
  */
4182
4644
  // eslint-disable-next-line max-statements
4183
- computePlaneDistances(position, direction, result = [-0, -0]) {
4645
+ computePlaneDistances(position, direction2, result = [-0, -0]) {
4184
4646
  let minDist = Number.POSITIVE_INFINITY;
4185
4647
  let maxDist = Number.NEGATIVE_INFINITY;
4186
4648
  const center = this.center;
@@ -4190,42 +4652,42 @@ var OrientedBoundingBox = class _OrientedBoundingBox {
4190
4652
  const w = halfAxes.getColumn(2, scratchVectorW);
4191
4653
  const corner = scratchCorner.copy(u).add(v).add(w).add(center);
4192
4654
  const toCenter = scratchToCenter.copy(corner).subtract(position);
4193
- let mag = direction.dot(toCenter);
4655
+ let mag = direction2.dot(toCenter);
4194
4656
  minDist = Math.min(mag, minDist);
4195
4657
  maxDist = Math.max(mag, maxDist);
4196
4658
  corner.copy(center).add(u).add(v).subtract(w);
4197
4659
  toCenter.copy(corner).subtract(position);
4198
- mag = direction.dot(toCenter);
4660
+ mag = direction2.dot(toCenter);
4199
4661
  minDist = Math.min(mag, minDist);
4200
4662
  maxDist = Math.max(mag, maxDist);
4201
4663
  corner.copy(center).add(u).subtract(v).add(w);
4202
4664
  toCenter.copy(corner).subtract(position);
4203
- mag = direction.dot(toCenter);
4665
+ mag = direction2.dot(toCenter);
4204
4666
  minDist = Math.min(mag, minDist);
4205
4667
  maxDist = Math.max(mag, maxDist);
4206
4668
  corner.copy(center).add(u).subtract(v).subtract(w);
4207
4669
  toCenter.copy(corner).subtract(position);
4208
- mag = direction.dot(toCenter);
4670
+ mag = direction2.dot(toCenter);
4209
4671
  minDist = Math.min(mag, minDist);
4210
4672
  maxDist = Math.max(mag, maxDist);
4211
4673
  center.copy(corner).subtract(u).add(v).add(w);
4212
4674
  toCenter.copy(corner).subtract(position);
4213
- mag = direction.dot(toCenter);
4675
+ mag = direction2.dot(toCenter);
4214
4676
  minDist = Math.min(mag, minDist);
4215
4677
  maxDist = Math.max(mag, maxDist);
4216
4678
  center.copy(corner).subtract(u).add(v).subtract(w);
4217
4679
  toCenter.copy(corner).subtract(position);
4218
- mag = direction.dot(toCenter);
4680
+ mag = direction2.dot(toCenter);
4219
4681
  minDist = Math.min(mag, minDist);
4220
4682
  maxDist = Math.max(mag, maxDist);
4221
4683
  center.copy(corner).subtract(u).subtract(v).add(w);
4222
4684
  toCenter.copy(corner).subtract(position);
4223
- mag = direction.dot(toCenter);
4685
+ mag = direction2.dot(toCenter);
4224
4686
  minDist = Math.min(mag, minDist);
4225
4687
  maxDist = Math.max(mag, maxDist);
4226
4688
  center.copy(corner).subtract(u).subtract(v).subtract(w);
4227
4689
  toCenter.copy(corner).subtract(position);
4228
- mag = direction.dot(toCenter);
4690
+ mag = direction2.dot(toCenter);
4229
4691
  minDist = Math.min(mag, minDist);
4230
4692
  maxDist = Math.max(mag, maxDist);
4231
4693
  result[0] = minDist;
@@ -4254,6 +4716,9 @@ var OrientedBoundingBox = class _OrientedBoundingBox {
4254
4716
  };
4255
4717
 
4256
4718
  // dist/culling/lib/culling-volume.js
4719
+ var import_core13 = require("@math.gl/core");
4720
+
4721
+ // dist/culling/frustum-planes.js
4257
4722
  var import_core12 = require("@math.gl/core");
4258
4723
 
4259
4724
  // dist/culling/lib/plane.js
@@ -4274,10 +4739,10 @@ var Plane = class _Plane {
4274
4739
  return this;
4275
4740
  }
4276
4741
  /** Creates a plane from a normal and a point on the plane. */
4277
- fromPointNormal(point, normal) {
4278
- point = scratchPosition.from(point);
4742
+ fromPointNormal(point2, normal) {
4743
+ point2 = scratchPosition.from(point2);
4279
4744
  this.normal.from(normal).normalize();
4280
- const distance = -this.normal.dot(point);
4745
+ const distance = -this.normal.dot(point2);
4281
4746
  this.distance = distance;
4282
4747
  return this;
4283
4748
  }
@@ -4299,17 +4764,17 @@ var Plane = class _Plane {
4299
4764
  /** Computes the signed shortest distance of a point to a plane.
4300
4765
  * The sign of the distance determines which side of the plane the point is on.
4301
4766
  */
4302
- getPointDistance(point) {
4303
- return this.normal.dot(point) + this.distance;
4767
+ getPointDistance(point2) {
4768
+ return this.normal.dot(point2) + this.distance;
4304
4769
  }
4305
4770
  /** Transforms the plane by the given transformation matrix. */
4306
4771
  transform(matrix4) {
4307
4772
  const normal = scratchNormal2.copy(this.normal).transformAsVector(matrix4).normalize();
4308
- const point = this.normal.scale(-this.distance).transform(matrix4);
4309
- return this.fromPointNormal(point, normal);
4773
+ const point2 = this.normal.scale(-this.distance).transform(matrix4);
4774
+ return this.fromPointNormal(point2, normal);
4310
4775
  }
4311
- projectPointOntoPlane(point, result = [0, 0, 0]) {
4312
- const scratchPoint = scratchPosition.from(point);
4776
+ projectPointOntoPlane(point2, result = [0, 0, 0]) {
4777
+ const scratchPoint = scratchPosition.from(point2);
4313
4778
  const pointDistance = this.getPointDistance(scratchPoint);
4314
4779
  const scaledNormal = scratchNormal2.copy(this.normal).scale(pointDistance);
4315
4780
  return scratchPoint.subtract(scaledNormal).to(result);
@@ -4323,9 +4788,9 @@ var Plane = class _Plane {
4323
4788
  */
4324
4789
  intersectWithRay(ray, result = new import_core11.Vector3()) {
4325
4790
  const origin = ray.origin;
4326
- const direction = ray.direction;
4791
+ const direction2 = ray.direction;
4327
4792
  const normal = this.normal;
4328
- const denominator = normal.dot(direction);
4793
+ const denominator = normal.dot(direction2);
4329
4794
  if (Math.abs(denominator) < import_core11._MathUtils.EPSILON15) {
4330
4795
  return void 0;
4331
4796
  }
@@ -4333,14 +4798,45 @@ var Plane = class _Plane {
4333
4798
  if (t < 0) {
4334
4799
  return void 0;
4335
4800
  }
4336
- return result.copy(direction).multiplyByScalar(t).add(origin);
4801
+ return result.copy(direction2).multiplyByScalar(t).add(origin);
4337
4802
  }
4338
4803
  };
4339
4804
 
4805
+ // dist/culling/frustum-planes.js
4806
+ function extractFrustumPlanes(matrix, options = {}) {
4807
+ if (matrix.length !== 16 || Array.from(matrix).some((x2) => !Number.isFinite(x2)))
4808
+ throw new RangeError("Expected a finite view-projection matrix");
4809
+ const [near, far] = (0, import_core12.getProjectionDepthRange)(options);
4810
+ const low = Math.min(near, far), high = Math.max(near, far);
4811
+ const row = (i) => [matrix[i], matrix[i + 4], matrix[i + 8], matrix[i + 12]];
4812
+ const x = row(0), y = row(1), z = row(2), w = row(3);
4813
+ const combine = (a, b, factor) => a.map((v, i) => v + factor * b[i]);
4814
+ const lo = combine(z, w, -low), hi = w.map((v, i) => high * v - z[i]);
4815
+ const coefficients = [
4816
+ combine(w, x, 1),
4817
+ combine(w, x, -1),
4818
+ combine(w, y, 1),
4819
+ combine(w, y, -1),
4820
+ ...options.reversedDepth ? [hi, lo] : [lo, hi]
4821
+ ];
4822
+ const planes = [];
4823
+ for (const [a, b, c, d] of coefficients) {
4824
+ const length = Math.hypot(a, b, c);
4825
+ if (length === 0) {
4826
+ if (d < 0)
4827
+ throw new RangeError("Empty clipping volume");
4828
+ } else
4829
+ planes.push(new Plane([a / length, b / length, c / length], d / length));
4830
+ }
4831
+ if (planes.length < 4)
4832
+ throw new RangeError("Degenerate clipping volume");
4833
+ return planes;
4834
+ }
4835
+
4340
4836
  // dist/culling/lib/culling-volume.js
4341
- var faces = [new import_core12.Vector3([1, 0, 0]), new import_core12.Vector3([0, 1, 0]), new import_core12.Vector3([0, 0, 1])];
4342
- var scratchPlaneCenter = new import_core12.Vector3();
4343
- var scratchPlaneNormal = new import_core12.Vector3();
4837
+ var faces = [new import_core13.Vector3([1, 0, 0]), new import_core13.Vector3([0, 1, 0]), new import_core13.Vector3([0, 0, 1])];
4838
+ var scratchPlaneCenter = new import_core13.Vector3();
4839
+ var scratchPlaneNormal = new import_core13.Vector3();
4344
4840
  var CullingVolume = class _CullingVolume {
4345
4841
  /**
4346
4842
  * Create a new `CullingVolume` bounded by an array of clipping planed
@@ -4356,7 +4852,7 @@ var CullingVolume = class _CullingVolume {
4356
4852
  fromBoundingSphere(boundingSphere) {
4357
4853
  this.planes.length = 2 * faces.length;
4358
4854
  const center = boundingSphere.center;
4359
- const radius = boundingSphere.radius;
4855
+ const radius2 = boundingSphere.radius;
4360
4856
  let planeIndex = 0;
4361
4857
  for (const faceNormal of faces) {
4362
4858
  let plane0 = this.planes[planeIndex];
@@ -4367,15 +4863,21 @@ var CullingVolume = class _CullingVolume {
4367
4863
  if (!plane1) {
4368
4864
  plane1 = this.planes[planeIndex + 1] = new Plane();
4369
4865
  }
4370
- const plane0Center = scratchPlaneCenter.copy(faceNormal).scale(-radius).add(center);
4866
+ const plane0Center = scratchPlaneCenter.copy(faceNormal).scale(-radius2).add(center);
4371
4867
  plane0.fromPointNormal(plane0Center, faceNormal);
4372
- const plane1Center = scratchPlaneCenter.copy(faceNormal).scale(radius).add(center);
4868
+ const plane1Center = scratchPlaneCenter.copy(faceNormal).scale(radius2).add(center);
4373
4869
  const negatedFaceNormal = scratchPlaneNormal.copy(faceNormal).negate();
4374
4870
  plane1.fromPointNormal(plane1Center, negatedFaceNormal);
4375
4871
  planeIndex += 2;
4376
4872
  }
4377
4873
  return this;
4378
4874
  }
4875
+ /** Replace planes from a view-projection matrix; validates before mutating. */
4876
+ fromViewProjection(matrix, options = {}) {
4877
+ const planes = extractFrustumPlanes(matrix, options);
4878
+ this.planes.splice(0, this.planes.length, ...planes);
4879
+ return this;
4880
+ }
4379
4881
  /** Determines whether a bounding volume intersects the culling volume. */
4380
4882
  computeVisibility(boundingVolume) {
4381
4883
  let intersect2 = "inside";
@@ -4401,7 +4903,7 @@ var CullingVolume = class _CullingVolume {
4401
4903
  * and that plane check can be skipped.
4402
4904
  */
4403
4905
  computeVisibilityWithPlaneMask(boundingVolume, parentPlaneMask) {
4404
- (0, import_core12.assert)(Number.isFinite(parentPlaneMask), "parentPlaneMask is required.");
4906
+ (0, import_core13.assert)(Number.isFinite(parentPlaneMask), "parentPlaneMask is required.");
4405
4907
  if (parentPlaneMask === _CullingVolume.MASK_OUTSIDE || parentPlaneMask === _CullingVolume.MASK_INSIDE) {
4406
4908
  return parentPlaneMask;
4407
4909
  }
@@ -4428,127 +4930,580 @@ CullingVolume.MASK_INSIDE = 0;
4428
4930
  CullingVolume.MASK_INDETERMINATE = 2147483647;
4429
4931
 
4430
4932
  // dist/culling/lib/ray.js
4431
- var import_core13 = require("@math.gl/core");
4432
- var Ray = class {
4433
- /**
4434
- * Creates a new ray that extends infinitely from the provided origin in the provided direction.
4435
- *
4436
- * @param [origin=Vector3] The origin of the ray.
4437
- * @param [direction=Vector3] The direction of the ray.
4438
- */
4439
- constructor(origin, direction) {
4440
- if (origin)
4441
- origin = origin.clone();
4442
- else
4443
- origin = new import_core13.Vector3();
4444
- if (direction)
4445
- direction = direction.clone().normalize();
4446
- else
4447
- direction = new import_core13.Vector3();
4448
- this.origin = origin;
4449
- this.direction = direction;
4450
- }
4451
- };
4452
-
4453
- // dist/culling/lib/shapes/implicit-shape.js
4454
4933
  var import_core14 = require("@math.gl/core");
4455
- var ImplicitShapeBase = class {
4456
- constructor(matrix) {
4457
- this.matrix = new import_core14.Matrix4();
4458
- if (matrix)
4459
- this.matrix.copy(matrix);
4460
- validateAffineMatrix(this.matrix);
4461
- this.inverseMatrix = this.matrix.clone().invert();
4462
- }
4463
- equals(shape) {
4464
- if (this.type !== shape.type)
4465
- return false;
4466
- for (let i = 0; i < 16; i++)
4467
- if (this.matrix[i] !== shape.matrix[i])
4468
- return false;
4469
- return true;
4470
- }
4471
- transform(transform) {
4472
- const next = new import_core14.Matrix4().copy(transform);
4473
- validateAffineMatrix(next);
4474
- this.matrix.multiplyLeft(next);
4475
- validateAffineMatrix(this.matrix);
4476
- this.inverseMatrix.copy(this.matrix).invert();
4477
- return this;
4478
- }
4479
- containsPoint(point) {
4480
- return this.containsLocalPoint(this.inverseMatrix.transformAsPoint(point));
4481
- }
4482
- distanceSquaredTo(point) {
4483
- const distance = this.distanceTo(point);
4484
- return distance * distance;
4934
+
4935
+ // dist/culling/queries.js
4936
+ function validateQueryPoint(point2, dimension2) {
4937
+ if (point2.length !== dimension2)
4938
+ throw new RangeError("Query dimension must match the index");
4939
+ for (let i = 0; i < dimension2; i++) {
4940
+ if (!Number.isFinite(point2[i]))
4941
+ throw new RangeError("Coordinates must be finite");
4485
4942
  }
4486
- /** Exact for rigid/uniform transforms; conservative estimate for non-uniform scale or shear. */
4487
- distanceTo(point) {
4488
- const localPoint = this.inverseMatrix.transformAsPoint(point);
4489
- const localDistance = this.distanceToLocalPoint(localPoint);
4490
- const scales = this.matrix.getScale();
4491
- return localDistance * Math.min(scales[0], scales[1], scales[2]);
4943
+ }
4944
+ function validateQueryDistance(distance) {
4945
+ if (Number.isNaN(distance) || distance < 0)
4946
+ throw new RangeError("Distance must be nonnegative");
4947
+ }
4948
+ function normalizeQueryDirection(direction2, dimension2) {
4949
+ validateQueryPoint(direction2, dimension2);
4950
+ const scale = Math.max(...Array.from(direction2, Math.abs));
4951
+ if (scale === 0)
4952
+ throw new RangeError("Ray direction must be nonzero");
4953
+ const scaled = Array.from(direction2, (x) => x / scale);
4954
+ const length = Math.hypot(...scaled);
4955
+ return scaled.map((x) => x / length);
4956
+ }
4957
+ function intersectRayBounds(origin, direction2, minimum, maximum, maxT = Infinity) {
4958
+ const dimension2 = origin.length;
4959
+ if (dimension2 !== 2 && dimension2 !== 3)
4960
+ throw new RangeError("Bounds must be 2D or 3D");
4961
+ validateQueryPoint(origin, dimension2);
4962
+ validateQueryPoint(direction2, dimension2);
4963
+ validateQueryPoint(minimum, dimension2);
4964
+ validateQueryPoint(maximum, dimension2);
4965
+ validateQueryDistance(maxT);
4966
+ let near = 0, far = maxT, nonzero = false;
4967
+ for (let i = 0; i < dimension2; i++) {
4968
+ if (minimum[i] > maximum[i])
4969
+ throw new RangeError("Bounds must be ordered");
4970
+ nonzero || (nonzero = direction2[i] !== 0);
4492
4971
  }
4493
- intersectPlane(plane) {
4494
- const maximum = this.getSupportPoint(plane.normal);
4495
- const minimum = this.getSupportPoint([-plane.normal[0], -plane.normal[1], -plane.normal[2]]);
4496
- const maxDistance = plane.getPointDistance(maximum);
4497
- const minDistance = plane.getPointDistance(minimum);
4498
- if (minDistance > 0)
4499
- return "inside";
4500
- if (maxDistance < 0)
4501
- return "outside";
4502
- return "intersecting";
4972
+ if (!nonzero)
4973
+ throw new RangeError("Ray direction must be nonzero");
4974
+ for (let i = 0; i < dimension2; i++) {
4975
+ if (direction2[i] === 0) {
4976
+ if (origin[i] < minimum[i] || origin[i] > maximum[i])
4977
+ return null;
4978
+ continue;
4979
+ }
4980
+ let a = (minimum[i] - origin[i]) / direction2[i];
4981
+ let b = (maximum[i] - origin[i]) / direction2[i];
4982
+ if (a > b)
4983
+ [a, b] = [b, a];
4984
+ near = Math.max(near, a);
4985
+ far = Math.min(far, b);
4986
+ if (near > far)
4987
+ return null;
4503
4988
  }
4504
- intersectRay(ray) {
4505
- const localOrigin = this.inverseMatrix.transformAsPoint(ray.origin);
4506
- const localDirection = this.inverseMatrix.transformAsVector(ray.direction);
4507
- const hit = this.intersectLocalRay(localOrigin, localDirection);
4508
- if (!hit || hit.distance < 0)
4509
- return void 0;
4510
- const point = new import_core14.Vector3(ray.direction).scale(hit.distance).add(ray.origin);
4511
- const inverse = this.inverseMatrix;
4512
- const normal = new import_core14.Vector3(inverse[0] * hit.normal[0] + inverse[1] * hit.normal[1] + inverse[2] * hit.normal[2], inverse[4] * hit.normal[0] + inverse[5] * hit.normal[1] + inverse[6] * hit.normal[2], inverse[8] * hit.normal[0] + inverse[9] * hit.normal[1] + inverse[10] * hit.normal[2]).normalize();
4513
- return { distance: hit.distance, point, normal, entering: ray.direction.dot(normal) < 0 };
4989
+ return Number.isFinite(near) ? near : null;
4990
+ }
4991
+ function intersectRayTriangle(origin, direction2, a, b, c, options = {}) {
4992
+ for (const point2 of [origin, direction2, a, b, c])
4993
+ validateQueryPoint(point2, 3);
4994
+ if (direction2[0] === 0 && direction2[1] === 0 && direction2[2] === 0) {
4995
+ throw new RangeError("Ray direction must be nonzero");
4514
4996
  }
4515
- getAxisAlignedBoundingBox() {
4516
- const minimum = new import_core14.Vector3();
4517
- const maximum = new import_core14.Vector3();
4518
- for (let axis = 0; axis < 3; axis++) {
4519
- const direction = [0, 0, 0];
4520
- direction[axis] = 1;
4521
- maximum[axis] = this.getSupportPoint(direction)[axis];
4522
- direction[axis] = -1;
4523
- minimum[axis] = this.getSupportPoint(direction)[axis];
4997
+ const maxT = options.maxT ?? Infinity;
4998
+ validateQueryDistance(maxT);
4999
+ const e1 = [b[0] - a[0], b[1] - a[1], b[2] - a[2]];
5000
+ const e2 = [c[0] - a[0], c[1] - a[1], c[2] - a[2]];
5001
+ const p = cross4(direction2, e2);
5002
+ const determinant = dot2(e1, p);
5003
+ if (determinant === 0 || options.backfaceCulling && determinant < 0)
5004
+ return null;
5005
+ const offset = [origin[0] - a[0], origin[1] - a[1], origin[2] - a[2]];
5006
+ const u = dot2(offset, p) / determinant;
5007
+ if (u < 0 || u > 1)
5008
+ return null;
5009
+ const q = cross4(offset, e1);
5010
+ const v = dot2(direction2, q) / determinant;
5011
+ if (v < 0 || u + v > 1)
5012
+ return null;
5013
+ const t = dot2(e2, q) / determinant;
5014
+ if (!Number.isFinite(t) || t < 0 || t > maxT)
5015
+ return null;
5016
+ return { t: Math.max(0, t), barycentric: [1 - u - v, u, v] };
5017
+ }
5018
+ function getClosestPointOnTriangle(point2, a, b, c) {
5019
+ for (const value of [point2, a, b, c])
5020
+ validateQueryPoint(value, 3);
5021
+ const ab = [b[0] - a[0], b[1] - a[1], b[2] - a[2]];
5022
+ const ac = [c[0] - a[0], c[1] - a[1], c[2] - a[2]];
5023
+ const ap = [point2[0] - a[0], point2[1] - a[1], point2[2] - a[2]];
5024
+ const aa = dot2(ab, ab), bb = dot2(ac, ac), cc = dot2(ab, ac);
5025
+ const denominator = aa * bb - cc * cc;
5026
+ if (denominator > 0 && Number.isFinite(denominator)) {
5027
+ const u = (bb * dot2(ap, ab) - cc * dot2(ap, ac)) / denominator;
5028
+ const v = (aa * dot2(ap, ac) - cc * dot2(ap, ab)) / denominator;
5029
+ if (u >= 0 && v >= 0 && u + v <= 1) {
5030
+ return [
5031
+ a[0] + u * ab[0] + v * ac[0],
5032
+ a[1] + u * ab[1] + v * ac[1],
5033
+ a[2] + u * ab[2] + v * ac[2]
5034
+ ];
4524
5035
  }
4525
- return new AxisAlignedBoundingBox(minimum, maximum);
4526
- }
4527
- getBoundingSphere() {
4528
- const box = this.getAxisAlignedBoundingBox();
4529
- if (!box)
4530
- return void 0;
4531
- return new BoundingSphere().fromCornerPoints(box.minimum, box.maximum);
4532
5036
  }
4533
- getSupportPoint(worldDirection) {
4534
- const matrix = this.matrix;
4535
- const localDirection = [
4536
- matrix[0] * worldDirection[0] + matrix[1] * worldDirection[1] + matrix[2] * worldDirection[2],
4537
- matrix[4] * worldDirection[0] + matrix[5] * worldDirection[1] + matrix[6] * worldDirection[2],
4538
- matrix[8] * worldDirection[0] + matrix[9] * worldDirection[1] + matrix[10] * worldDirection[2]
5037
+ let best = [a[0], a[1], a[2]];
5038
+ let distance = Infinity;
5039
+ for (const [start, end] of [
5040
+ [a, b],
5041
+ [b, c],
5042
+ [c, a]
5043
+ ]) {
5044
+ const edge = [end[0] - start[0], end[1] - start[1], end[2] - start[2]];
5045
+ const offset = [point2[0] - start[0], point2[1] - start[1], point2[2] - start[2]];
5046
+ const squared = dot2(edge, edge);
5047
+ const t = squared > 0 ? Math.max(0, Math.min(1, dot2(offset, edge) / squared)) : 0;
5048
+ const candidate = [
5049
+ start[0] + t * edge[0],
5050
+ start[1] + t * edge[1],
5051
+ start[2] + t * edge[2]
4539
5052
  ];
4540
- return new import_core14.Vector3(this.supportLocal(localDirection)).transform(this.matrix);
4541
- }
4542
- };
4543
- function validateAffineMatrix(matrix) {
4544
- if (matrix.length !== 16 || matrix.some((value) => !Number.isFinite(value))) {
4545
- throw new Error("Shape matrix must contain 16 finite values");
4546
- }
4547
- if (Math.abs(matrix[3]) > 1e-12 || Math.abs(matrix[7]) > 1e-12 || Math.abs(matrix[11]) > 1e-12 || Math.abs(matrix[15] - 1) > 1e-12) {
4548
- throw new Error("Shape matrix must be affine");
5053
+ const d = Math.hypot(point2[0] - candidate[0], point2[1] - candidate[1], point2[2] - candidate[2]);
5054
+ if (d < distance) {
5055
+ distance = d;
5056
+ best = candidate;
5057
+ }
4549
5058
  }
4550
- if (Math.abs(new import_core14.Matrix4().copy(matrix).determinant()) < 1e-15)
4551
- throw new Error("Shape matrix must be invertible");
5059
+ return best;
5060
+ }
5061
+ function getClosestPointsOnSegments(a0, a1, b0, b1) {
5062
+ const frame = queryFrame([a0, a1, b0, b1]);
5063
+ const pair2 = closestSegments(...frame.points);
5064
+ const pointA = interpolatePoint(a0, a1, pair2.fractionA);
5065
+ const pointB = interpolatePoint(b0, b1, pair2.fractionB);
5066
+ return {
5067
+ distance: finiteDistance(pointA, pointB),
5068
+ pointA,
5069
+ pointB,
5070
+ fractionA: pair2.fractionA,
5071
+ fractionB: pair2.fractionB
5072
+ };
5073
+ }
5074
+ function getClosestPointsSegmentTriangle(start, end, a, b, c) {
5075
+ const frame = queryFrame([start, end, a, b, c]);
5076
+ const [s, e, va, vb, vc] = frame.points;
5077
+ const direction2 = subtract(e, s);
5078
+ if (direction2.some((value) => value !== 0)) {
5079
+ const hit = intersectRayTriangle(s, direction2, va, vb, vc, { maxT: 1 });
5080
+ if (hit) {
5081
+ const point2 = interpolatePoint(start, end, hit.t);
5082
+ return { distance: 0, segmentPoint: point2, trianglePoint: [...point2], segmentFraction: hit.t };
5083
+ }
5084
+ }
5085
+ let best = { distance: Infinity, segmentFraction: 0, trianglePoint: va };
5086
+ const consider = (point2, trianglePoint2, segmentFraction) => {
5087
+ const distance = Math.hypot(...subtract(point2, trianglePoint2));
5088
+ if (distance < best.distance || distance === best.distance && segmentFraction < best.segmentFraction)
5089
+ best = { distance, segmentFraction, trianglePoint: trianglePoint2 };
5090
+ };
5091
+ consider(s, getClosestPointOnTriangle(s, va, vb, vc), 0);
5092
+ consider(e, getClosestPointOnTriangle(e, va, vb, vc), 1);
5093
+ for (const [v0, v1] of [
5094
+ [va, vb],
5095
+ [vb, vc],
5096
+ [vc, va]
5097
+ ]) {
5098
+ const pair2 = closestSegments(s, e, v0, v1);
5099
+ consider(interpolatePoint(s, e, pair2.fractionA), interpolatePoint(v0, v1, pair2.fractionB), pair2.fractionA);
5100
+ }
5101
+ const trianglePoint = best.trianglePoint.map((value, axis) => Math.max(Math.min(a[axis], b[axis], c[axis]), Math.min(Math.max(a[axis], b[axis], c[axis]), start[axis] + value * frame.scale)));
5102
+ if (!trianglePoint.every(Number.isFinite))
5103
+ throw new RangeError("Closest-point result overflow");
5104
+ const segmentPoint = interpolatePoint(start, end, best.segmentFraction);
5105
+ return {
5106
+ distance: finiteDistance(segmentPoint, trianglePoint),
5107
+ segmentPoint,
5108
+ trianglePoint,
5109
+ segmentFraction: best.segmentFraction
5110
+ };
5111
+ }
5112
+ function queryFrame(input) {
5113
+ input.forEach((point2) => validateQueryPoint(point2, 3));
5114
+ const offsets = input.map((point2) => subtract(point2, input[0]));
5115
+ let scale = 0;
5116
+ for (const offset of offsets)
5117
+ for (const value of offset) {
5118
+ if (!Number.isFinite(value))
5119
+ throw new RangeError("Closest-point coordinate span overflow");
5120
+ scale = Math.max(scale, Math.abs(value));
5121
+ }
5122
+ scale || (scale = 1);
5123
+ return { points: offsets.map((point2) => point2.map((value) => value / scale)), scale };
5124
+ }
5125
+ function closestSegments(a0, a1, b0, b1) {
5126
+ const da = subtract(a1, a0), db = subtract(b1, b0);
5127
+ const lengthA = Math.hypot(...da), lengthB = Math.hypot(...db);
5128
+ const ua = da.map((value) => lengthA ? value / lengthA : 0);
5129
+ const ub = db.map((value) => lengthB ? value / lengthB : 0);
5130
+ let best = { distance: Infinity, fractionA: 0, fractionB: 0 };
5131
+ const consider = (fractionA, fractionB) => {
5132
+ const distance = Math.hypot(...subtract(interpolatePoint(a0, a1, fractionA), interpolatePoint(b0, b1, fractionB)));
5133
+ if (distance < best.distance || distance === best.distance && (fractionA < best.fractionA || fractionA === best.fractionA && fractionB < best.fractionB))
5134
+ best = { distance, fractionA, fractionB };
5135
+ };
5136
+ for (const t of [0, 1]) {
5137
+ consider(t, lengthB ? clampUnit(dot2(subtract(t ? a1 : a0, b0), ub) / lengthB) : 0);
5138
+ consider(lengthA ? clampUnit(dot2(subtract(t ? b1 : b0, a0), ua) / lengthA) : 0, t);
5139
+ }
5140
+ const normal = cross4(ua, ub);
5141
+ const sine = Math.hypot(...normal);
5142
+ if (sine > 0) {
5143
+ const unit2 = normal.map((value) => value / sine);
5144
+ const offset = subtract(b0, a0);
5145
+ const fractionA = dot2(cross4(offset, ub), unit2) / sine / lengthA;
5146
+ const fractionB = dot2(cross4(offset, ua), unit2) / sine / lengthB;
5147
+ if (fractionA >= 0 && fractionA <= 1 && fractionB >= 0 && fractionB <= 1)
5148
+ consider(fractionA, fractionB);
5149
+ }
5150
+ return best;
5151
+ }
5152
+ function subtract(a, b) {
5153
+ return [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
5154
+ }
5155
+ function interpolatePoint(a, b, t) {
5156
+ return [0, 1, 2].map((axis) => Math.max(Math.min(a[axis], b[axis]), Math.min(Math.max(a[axis], b[axis]), (1 - t) * a[axis] + t * b[axis])));
5157
+ }
5158
+ function clampUnit(value) {
5159
+ return Math.max(0, Math.min(1, value));
5160
+ }
5161
+ function finiteDistance(a, b) {
5162
+ const distance = Math.hypot(...subtract(a, b));
5163
+ if (!Number.isFinite(distance))
5164
+ throw new RangeError("Closest-point distance overflow");
5165
+ return distance;
5166
+ }
5167
+ function dot2(a, b) {
5168
+ return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
5169
+ }
5170
+ function cross4(a, b) {
5171
+ return [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
5172
+ }
5173
+
5174
+ // dist/culling/geometric-queries.js
5175
+ var sub2 = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
5176
+ var dot3 = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
5177
+ var cross5 = (a, b) => [
5178
+ a[1] * b[2] - a[2] * b[1],
5179
+ a[2] * b[0] - a[0] * b[2],
5180
+ a[0] * b[1] - a[1] * b[0]
5181
+ ];
5182
+ var check = (...points) => {
5183
+ for (const p of points)
5184
+ validateQueryPoint(p, 3);
5185
+ };
5186
+ function output(out, values) {
5187
+ if (out.length < values.length)
5188
+ throw new RangeError("Result buffer is too short");
5189
+ const copy2 = Array.from(values);
5190
+ for (let i = 0; i < copy2.length; i++)
5191
+ out[i] = copy2[i];
5192
+ return out;
5193
+ }
5194
+ function direction(d) {
5195
+ check(d);
5196
+ if (Math.hypot(d[0], d[1], d[2]) === 0)
5197
+ throw new RangeError("Ray direction must be nonzero");
5198
+ }
5199
+ function getRayPoint(origin, dir, t, out = [0, 0, 0]) {
5200
+ check(origin);
5201
+ direction(dir);
5202
+ if (!Number.isFinite(t) || t < 0)
5203
+ throw new RangeError("Ray parameter must be finite and nonnegative");
5204
+ return output(out, [origin[0] + t * dir[0], origin[1] + t * dir[1], origin[2] + t * dir[2]]);
5205
+ }
5206
+ function getClosestPointOnRay(point2, origin, dir, out = [0, 0, 0]) {
5207
+ check(point2, origin);
5208
+ direction(dir);
5209
+ const unit2 = normalizeQueryDirection(dir, 3);
5210
+ const distance = Math.max(0, dot3(sub2(point2, origin), unit2));
5211
+ return output(out, [0, 1, 2].map((i) => origin[i] + distance * unit2[i]));
5212
+ }
5213
+ function distanceToRay(point2, origin, dir) {
5214
+ const p = getClosestPointOnRay(point2, origin, dir);
5215
+ return Math.hypot(...sub2(point2, p));
5216
+ }
5217
+ function getClosestPointsRaySegment(origin, dir, a, b) {
5218
+ check(origin, a, b);
5219
+ direction(dir);
5220
+ const unit2 = normalizeQueryDirection(dir, 3);
5221
+ const directionLength = Math.hypot(dir[0], dir[1], dir[2]);
5222
+ const edge = sub2(b, a), offset = sub2(origin, a);
5223
+ const segmentLength = Math.hypot(...edge);
5224
+ const segmentUnit = edge.map((x) => segmentLength ? x / segmentLength : 0);
5225
+ const bb = dot3(unit2, segmentUnit), dd = dot3(unit2, offset), ee = dot3(segmentUnit, offset);
5226
+ const candidates = [
5227
+ [0, Math.max(0, Math.min(segmentLength, ee))],
5228
+ [Math.max(0, -dd), 0],
5229
+ [Math.max(0, bb * segmentLength - dd), segmentLength]
5230
+ ];
5231
+ const normal = cross5(unit2, segmentUnit);
5232
+ const sine = Math.hypot(...normal);
5233
+ if (segmentLength > 0 && sine > 0) {
5234
+ const normalUnit = normal.map((value) => value / sine);
5235
+ const separation = sub2(a, origin);
5236
+ const t = dot3(cross5(separation, segmentUnit), normalUnit) / sine;
5237
+ const u = dot3(cross5(separation, unit2), normalUnit) / sine;
5238
+ if (t >= 0 && u >= 0 && u <= segmentLength)
5239
+ candidates.push([t, u]);
5240
+ }
5241
+ let best;
5242
+ for (const [t, u] of candidates) {
5243
+ const rayPoint = [
5244
+ origin[0] + t * unit2[0],
5245
+ origin[1] + t * unit2[1],
5246
+ origin[2] + t * unit2[2]
5247
+ ];
5248
+ const segmentPoint = [
5249
+ a[0] + u * segmentUnit[0],
5250
+ a[1] + u * segmentUnit[1],
5251
+ a[2] + u * segmentUnit[2]
5252
+ ];
5253
+ const distance = Math.hypot(...sub2(rayPoint, segmentPoint));
5254
+ if (!best || distance < best.distance)
5255
+ best = {
5256
+ rayPoint,
5257
+ segmentPoint,
5258
+ rayParameter: t / directionLength,
5259
+ segmentFraction: segmentLength ? u / segmentLength : 0,
5260
+ distance
5261
+ };
5262
+ }
5263
+ return best;
5264
+ }
5265
+ function transformRay(origin, dir, matrix) {
5266
+ check(origin);
5267
+ direction(dir);
5268
+ if (matrix.length !== 16 || Array.from(matrix).some((x) => !Number.isFinite(x)) || matrix[3] !== 0 || matrix[7] !== 0 || matrix[11] !== 0 || matrix[15] !== 1)
5269
+ throw new RangeError("Expected a finite affine matrix");
5270
+ const apply = (p, w) => [0, 1, 2].map((i) => matrix[i] * p[0] + matrix[i + 4] * p[1] + matrix[i + 8] * p[2] + w * matrix[i + 12]);
5271
+ const transformed = { origin: apply(origin, 1), direction: apply(dir, 0) };
5272
+ check(transformed.origin);
5273
+ direction(transformed.direction);
5274
+ return transformed;
5275
+ }
5276
+ function triangle(a, b, c) {
5277
+ check(a, b, c);
5278
+ const ab = sub2(b, a), ac = sub2(c, a);
5279
+ const scale = Math.max(Math.hypot(...ab), Math.hypot(...ac));
5280
+ const u = ab.map((x) => scale ? x / scale : 0), v = ac.map((x) => scale ? x / scale : 0);
5281
+ return { u, v, scale, normal: cross5(u, v) };
5282
+ }
5283
+ function getTriangleBarycentric(point2, a, b, c, out = [0, 0, 0]) {
5284
+ check(point2);
5285
+ const { u, v, scale, normal } = triangle(a, b, c), denominator = dot3(normal, normal);
5286
+ if (denominator === 0)
5287
+ return null;
5288
+ const p = sub2(point2, a).map((x) => x / scale);
5289
+ const second = dot3(cross5(p, v), normal) / denominator;
5290
+ const third = dot3(cross5(u, p), normal) / denominator;
5291
+ return output(out, [1 - second - third, second, third]);
5292
+ }
5293
+ function getTriangleArea(a, b, c) {
5294
+ const { normal, scale } = triangle(a, b, c);
5295
+ return Math.hypot(...normal) * scale * scale / 2;
5296
+ }
5297
+ function getTriangleNormal(a, b, c, out = [0, 0, 0]) {
5298
+ const { normal } = triangle(a, b, c), length = Math.hypot(...normal);
5299
+ return output(out, normal.map((x) => length ? x / length : 0));
5300
+ }
5301
+ function isTriangleFrontFacing(a, b, c, dir) {
5302
+ direction(dir);
5303
+ return dot3(triangle(a, b, c).normal, dir) < 0;
5304
+ }
5305
+ function triangleContainsPoint(point2, a, b, c, tolerance = 1e-10) {
5306
+ if (!Number.isFinite(tolerance) || tolerance < 0)
5307
+ throw new RangeError("Invalid tolerance");
5308
+ const weights = getTriangleBarycentric(point2, a, b, c);
5309
+ if (!weights)
5310
+ return false;
5311
+ const { normal, scale } = triangle(a, b, c);
5312
+ const distance = Math.abs(dot3(sub2(point2, a).map((x) => x / scale), normal)) / Math.hypot(...normal);
5313
+ return distance <= tolerance && Array.from(weights).every((x) => x >= -tolerance && x <= 1 + tolerance);
5314
+ }
5315
+ function interpolateTriangleAttribute(weights, a, b, c, out = new Array(a.length)) {
5316
+ check(weights);
5317
+ if (!a.length || a.length !== b.length || a.length !== c.length || [a, b, c].some((p) => Array.from(p).some((x) => !Number.isFinite(x))))
5318
+ throw new RangeError("Expected matching finite attributes");
5319
+ return output(out, Array.from(a, (x, i) => weights[0] * x + weights[1] * b[i] + weights[2] * c[i]));
5320
+ }
5321
+ function intersectPlaneSegment(normal, constant, start, end, out = [0, 0, 0]) {
5322
+ check(start, end);
5323
+ direction(normal);
5324
+ if (!Number.isFinite(constant))
5325
+ throw new RangeError("Plane constant must be finite");
5326
+ const a = dot3(normal, start) + constant, b = dot3(normal, end) + constant;
5327
+ if (a === 0)
5328
+ return output(out, start);
5329
+ if (b === 0)
5330
+ return output(out, end);
5331
+ if (a > 0 === b > 0)
5332
+ return null;
5333
+ const t = a / (a - b);
5334
+ return output(out, [0, 1, 2].map((i) => start[i] + t * (end[i] - start[i])));
5335
+ }
5336
+ function triangleIntersectsBounds(a, b, c, minimum, maximum) {
5337
+ check(a, b, c, minimum, maximum);
5338
+ if ([0, 1, 2].some((i) => minimum[i] > maximum[i]))
5339
+ return false;
5340
+ const center = [0, 1, 2].map((i) => minimum[i] / 2 + maximum[i] / 2);
5341
+ const extent = [0, 1, 2].map((i) => maximum[i] / 2 - minimum[i] / 2);
5342
+ const vertices = [a, b, c].map((p) => sub2(p, center));
5343
+ const edges = [sub2(b, a), sub2(c, b), sub2(a, c)];
5344
+ const basis = [
5345
+ [1, 0, 0],
5346
+ [0, 1, 0],
5347
+ [0, 0, 1]
5348
+ ];
5349
+ const axes = [
5350
+ ...basis,
5351
+ cross5(edges[0], edges[1]),
5352
+ ...edges.flatMap((e) => basis.map((axis) => cross5(e, axis)))
5353
+ ];
5354
+ for (const axis of axes) {
5355
+ const length = Math.hypot(...axis);
5356
+ if (!length)
5357
+ continue;
5358
+ const unit2 = axis.map((x) => x / length);
5359
+ const projections = vertices.map((v) => dot3(v, unit2));
5360
+ const radius2 = extent.reduce((sum, x, i) => sum + x * Math.abs(unit2[i]), 0);
5361
+ if (Math.min(...projections) > radius2 || Math.max(...projections) < -radius2)
5362
+ return false;
5363
+ }
5364
+ return true;
5365
+ }
5366
+
5367
+ // dist/culling/lib/ray.js
5368
+ var Ray = class {
5369
+ /**
5370
+ * Creates a new ray that extends infinitely from the provided origin in the provided direction.
5371
+ *
5372
+ * @param [origin=Vector3] The origin of the ray.
5373
+ * @param [direction=Vector3] The direction of the ray.
5374
+ */
5375
+ constructor(origin, direction2) {
5376
+ if (origin)
5377
+ origin = origin.clone();
5378
+ else
5379
+ origin = new import_core14.Vector3();
5380
+ if (direction2)
5381
+ direction2 = direction2.clone().normalize();
5382
+ else
5383
+ direction2 = new import_core14.Vector3();
5384
+ this.origin = origin;
5385
+ this.direction = direction2;
5386
+ }
5387
+ at(t, result = new import_core14.Vector3()) {
5388
+ getRayPoint(this.origin, this.direction, t, result);
5389
+ return result;
5390
+ }
5391
+ closestPointTo(point2, result = new import_core14.Vector3()) {
5392
+ getClosestPointOnRay(point2, this.origin, this.direction, result);
5393
+ return result;
5394
+ }
5395
+ distanceTo(point2) {
5396
+ return distanceToRay(point2, this.origin, this.direction);
5397
+ }
5398
+ /** Transform and renormalize: subsequent parameters are distances in the new space. */
5399
+ transform(matrix) {
5400
+ const ray = transformRay(this.origin, this.direction, matrix);
5401
+ const normalized2 = normalizeQueryDirection(ray.direction, 3);
5402
+ this.origin.copy(ray.origin);
5403
+ this.direction.copy(normalized2);
5404
+ return this;
5405
+ }
5406
+ };
5407
+
5408
+ // dist/culling/lib/shapes/implicit-shape.js
5409
+ var import_core15 = require("@math.gl/core");
5410
+ var ImplicitShapeBase = class {
5411
+ constructor(matrix) {
5412
+ this.matrix = new import_core15.Matrix4();
5413
+ if (matrix)
5414
+ this.matrix.copy(matrix);
5415
+ validateAffineMatrix(this.matrix);
5416
+ this.inverseMatrix = this.matrix.clone().invert();
5417
+ }
5418
+ equals(shape) {
5419
+ if (this.type !== shape.type)
5420
+ return false;
5421
+ for (let i = 0; i < 16; i++)
5422
+ if (this.matrix[i] !== shape.matrix[i])
5423
+ return false;
5424
+ return true;
5425
+ }
5426
+ transform(transform) {
5427
+ const next = new import_core15.Matrix4().copy(transform);
5428
+ validateAffineMatrix(next);
5429
+ this.matrix.multiplyLeft(next);
5430
+ validateAffineMatrix(this.matrix);
5431
+ this.inverseMatrix.copy(this.matrix).invert();
5432
+ return this;
5433
+ }
5434
+ containsPoint(point2) {
5435
+ return this.containsLocalPoint(this.inverseMatrix.transformAsPoint(point2));
5436
+ }
5437
+ distanceSquaredTo(point2) {
5438
+ const distance = this.distanceTo(point2);
5439
+ return distance * distance;
5440
+ }
5441
+ /** Exact for rigid/uniform transforms; conservative estimate for non-uniform scale or shear. */
5442
+ distanceTo(point2) {
5443
+ const localPoint = this.inverseMatrix.transformAsPoint(point2);
5444
+ const localDistance = this.distanceToLocalPoint(localPoint);
5445
+ const scales = this.matrix.getScale();
5446
+ return localDistance * Math.min(scales[0], scales[1], scales[2]);
5447
+ }
5448
+ intersectPlane(plane) {
5449
+ const maximum = this.getSupportPoint(plane.normal);
5450
+ const minimum = this.getSupportPoint([-plane.normal[0], -plane.normal[1], -plane.normal[2]]);
5451
+ const maxDistance = plane.getPointDistance(maximum);
5452
+ const minDistance = plane.getPointDistance(minimum);
5453
+ if (minDistance > 0)
5454
+ return "inside";
5455
+ if (maxDistance < 0)
5456
+ return "outside";
5457
+ return "intersecting";
5458
+ }
5459
+ intersectRay(ray) {
5460
+ const localOrigin = this.inverseMatrix.transformAsPoint(ray.origin);
5461
+ const localDirection = this.inverseMatrix.transformAsVector(ray.direction);
5462
+ const hit = this.intersectLocalRay(localOrigin, localDirection);
5463
+ if (!hit || hit.distance < 0)
5464
+ return void 0;
5465
+ const point2 = new import_core15.Vector3(ray.direction).scale(hit.distance).add(ray.origin);
5466
+ const inverse = this.inverseMatrix;
5467
+ const normal = new import_core15.Vector3(inverse[0] * hit.normal[0] + inverse[1] * hit.normal[1] + inverse[2] * hit.normal[2], inverse[4] * hit.normal[0] + inverse[5] * hit.normal[1] + inverse[6] * hit.normal[2], inverse[8] * hit.normal[0] + inverse[9] * hit.normal[1] + inverse[10] * hit.normal[2]).normalize();
5468
+ return { distance: hit.distance, point: point2, normal, entering: ray.direction.dot(normal) < 0 };
5469
+ }
5470
+ getAxisAlignedBoundingBox() {
5471
+ const minimum = new import_core15.Vector3();
5472
+ const maximum = new import_core15.Vector3();
5473
+ for (let axis = 0; axis < 3; axis++) {
5474
+ const direction2 = [0, 0, 0];
5475
+ direction2[axis] = 1;
5476
+ maximum[axis] = this.getSupportPoint(direction2)[axis];
5477
+ direction2[axis] = -1;
5478
+ minimum[axis] = this.getSupportPoint(direction2)[axis];
5479
+ }
5480
+ return new AxisAlignedBoundingBox(minimum, maximum);
5481
+ }
5482
+ getBoundingSphere() {
5483
+ const box = this.getAxisAlignedBoundingBox();
5484
+ if (!box)
5485
+ return void 0;
5486
+ return new BoundingSphere().fromCornerPoints(box.minimum, box.maximum);
5487
+ }
5488
+ getSupportPoint(worldDirection) {
5489
+ const matrix = this.matrix;
5490
+ const localDirection = [
5491
+ matrix[0] * worldDirection[0] + matrix[1] * worldDirection[1] + matrix[2] * worldDirection[2],
5492
+ matrix[4] * worldDirection[0] + matrix[5] * worldDirection[1] + matrix[6] * worldDirection[2],
5493
+ matrix[8] * worldDirection[0] + matrix[9] * worldDirection[1] + matrix[10] * worldDirection[2]
5494
+ ];
5495
+ return new import_core15.Vector3(this.supportLocal(localDirection)).transform(this.matrix);
5496
+ }
5497
+ };
5498
+ function validateAffineMatrix(matrix) {
5499
+ if (matrix.length !== 16 || matrix.some((value) => !Number.isFinite(value))) {
5500
+ throw new Error("Shape matrix must contain 16 finite values");
5501
+ }
5502
+ if (Math.abs(matrix[3]) > 1e-12 || Math.abs(matrix[7]) > 1e-12 || Math.abs(matrix[11]) > 1e-12 || Math.abs(matrix[15] - 1) > 1e-12) {
5503
+ throw new Error("Shape matrix must be affine");
5504
+ }
5505
+ if (Math.abs(new import_core15.Matrix4().copy(matrix).determinant()) < 1e-15)
5506
+ throw new Error("Shape matrix must be invertible");
4552
5507
  }
4553
5508
  function solveQuadratic(a, b, c) {
4554
5509
  if (Math.abs(a) < 1e-15)
@@ -4566,19 +5521,19 @@ function closestDistanceToSegment2D(px, py, ax, ay, bx, by) {
4566
5521
  const t = denominator ? Math.max(0, Math.min(1, ((px - ax) * dx + (py - ay) * dy) / denominator)) : 0;
4567
5522
  return Math.hypot(px - (ax + t * dx), py - (ay + t * dy));
4568
5523
  }
4569
- function closestDistanceToCircleArc2D(px, py, centerY, radius, minimumNormalY, maximumNormalY) {
4570
- if (radius === 0)
5524
+ function closestDistanceToCircleArc2D(px, py, centerY, radius2, minimumNormalY, maximumNormalY) {
5525
+ if (radius2 === 0)
4571
5526
  return Math.hypot(px, py - centerY);
4572
5527
  const dx = px;
4573
5528
  const dy = py - centerY;
4574
5529
  const length = Math.hypot(dx, dy);
4575
5530
  const normalY = length ? dy / length : 0;
4576
5531
  if (normalY >= minimumNormalY && normalY <= maximumNormalY) {
4577
- return Math.abs(length - radius);
5532
+ return Math.abs(length - radius2);
4578
5533
  }
4579
- const minimumRadius = radius * Math.sqrt(Math.max(0, 1 - minimumNormalY ** 2));
4580
- const maximumRadius = radius * Math.sqrt(Math.max(0, 1 - maximumNormalY ** 2));
4581
- return Math.min(Math.hypot(px - minimumRadius, py - (centerY + radius * minimumNormalY)), Math.hypot(px - maximumRadius, py - (centerY + radius * maximumNormalY)));
5534
+ const minimumRadius = radius2 * Math.sqrt(Math.max(0, 1 - minimumNormalY ** 2));
5535
+ const maximumRadius = radius2 * Math.sqrt(Math.max(0, 1 - maximumNormalY ** 2));
5536
+ return Math.min(Math.hypot(px - minimumRadius, py - (centerY + radius2 * minimumNormalY)), Math.hypot(px - maximumRadius, py - (centerY + radius2 * maximumNormalY)));
4582
5537
  }
4583
5538
 
4584
5539
  // dist/culling/lib/shapes/box-shape.js
@@ -4598,28 +5553,28 @@ var BoxShape = class _BoxShape extends ImplicitShapeBase {
4598
5553
  equals(shape) {
4599
5554
  return shape instanceof _BoxShape && super.equals(shape) && this.size.every((value, i) => value === shape.size[i]);
4600
5555
  }
4601
- containsLocalPoint(point) {
4602
- return point.every((value, i) => Math.abs(value) <= this.halfSize[i] + EPSILON);
5556
+ containsLocalPoint(point2) {
5557
+ return point2.every((value, i) => Math.abs(value) <= this.halfSize[i] + EPSILON);
4603
5558
  }
4604
- distanceToLocalPoint(point) {
4605
- return Math.hypot(...point.map((value, i) => Math.max(0, Math.abs(value) - this.halfSize[i])));
5559
+ distanceToLocalPoint(point2) {
5560
+ return Math.hypot(...point2.map((value, i) => Math.max(0, Math.abs(value) - this.halfSize[i])));
4606
5561
  }
4607
- supportLocal(direction) {
4608
- return direction.map((value, i) => value < 0 ? -this.halfSize[i] : this.halfSize[i]);
5562
+ supportLocal(direction2) {
5563
+ return direction2.map((value, i) => value < 0 ? -this.halfSize[i] : this.halfSize[i]);
4609
5564
  }
4610
- intersectLocalRay(origin, direction) {
5565
+ intersectLocalRay(origin, direction2) {
4611
5566
  let near = -Infinity;
4612
5567
  let far = Infinity;
4613
5568
  let nearAxis = 0;
4614
5569
  let farAxis = 0;
4615
5570
  for (let axis2 = 0; axis2 < 3; axis2++) {
4616
- if (Math.abs(direction[axis2]) < 1e-15) {
5571
+ if (Math.abs(direction2[axis2]) < 1e-15) {
4617
5572
  if (Math.abs(origin[axis2]) > this.halfSize[axis2])
4618
5573
  return void 0;
4619
5574
  continue;
4620
5575
  }
4621
- let t1 = (-this.halfSize[axis2] - origin[axis2]) / direction[axis2];
4622
- let t2 = (this.halfSize[axis2] - origin[axis2]) / direction[axis2];
5576
+ let t1 = (-this.halfSize[axis2] - origin[axis2]) / direction2[axis2];
5577
+ let t2 = (this.halfSize[axis2] - origin[axis2]) / direction2[axis2];
4623
5578
  if (t1 > t2)
4624
5579
  [t1, t2] = [t2, t1];
4625
5580
  if (t1 > near) {
@@ -4637,7 +5592,7 @@ var BoxShape = class _BoxShape extends ImplicitShapeBase {
4637
5592
  if (distance < 0 || !Number.isFinite(distance))
4638
5593
  return void 0;
4639
5594
  const axis = near >= 0 ? nearAxis : farAxis;
4640
- const pointCoordinate = origin[axis] + distance * direction[axis];
5595
+ const pointCoordinate = origin[axis] + distance * direction2[axis];
4641
5596
  const normal = [0, 0, 0];
4642
5597
  normal[axis] = pointCoordinate < 0 ? -1 : 1;
4643
5598
  return { distance, normal };
@@ -4671,74 +5626,74 @@ var CapsuleShape = class _CapsuleShape extends ImplicitShapeBase {
4671
5626
  equals(shape) {
4672
5627
  return shape instanceof _CapsuleShape && super.equals(shape) && this.height === shape.height && this.radiusBottom === shape.radiusBottom && this.radiusTop === shape.radiusTop;
4673
5628
  }
4674
- containsLocalPoint(point) {
5629
+ containsLocalPoint(point2) {
4675
5630
  const profile = this.getProfile();
4676
- const radial2 = Math.hypot(point[0], point[2]);
5631
+ const radial2 = Math.hypot(point2[0], point2[2]);
4677
5632
  if (profile.sphere)
4678
- return Math.hypot(radial2, point[1] - profile.sphere.center) <= profile.sphere.radius + EPSILON2;
4679
- if (point[1] < profile.bottom.y)
4680
- return Math.hypot(radial2, point[1] + this.height / 2) <= this.radiusBottom + EPSILON2;
4681
- if (point[1] > profile.top.y)
4682
- return Math.hypot(radial2, point[1] - this.height / 2) <= this.radiusTop + EPSILON2;
4683
- const t = (point[1] - profile.bottom.y) / (profile.top.y - profile.bottom.y);
5633
+ return Math.hypot(radial2, point2[1] - profile.sphere.center) <= profile.sphere.radius + EPSILON2;
5634
+ if (point2[1] < profile.bottom.y)
5635
+ return Math.hypot(radial2, point2[1] + this.height / 2) <= this.radiusBottom + EPSILON2;
5636
+ if (point2[1] > profile.top.y)
5637
+ return Math.hypot(radial2, point2[1] - this.height / 2) <= this.radiusTop + EPSILON2;
5638
+ const t = (point2[1] - profile.bottom.y) / (profile.top.y - profile.bottom.y);
4684
5639
  return radial2 <= profile.bottom.radius + (profile.top.radius - profile.bottom.radius) * t + EPSILON2;
4685
5640
  }
4686
- distanceToLocalPoint(point) {
4687
- if (this.containsLocalPoint(point))
5641
+ distanceToLocalPoint(point2) {
5642
+ if (this.containsLocalPoint(point2))
4688
5643
  return 0;
4689
5644
  const profile = this.getProfile();
4690
- const radial2 = Math.hypot(point[0], point[2]);
5645
+ const radial2 = Math.hypot(point2[0], point2[2]);
4691
5646
  if (profile.sphere)
4692
- return Math.max(0, Math.hypot(radial2, point[1] - profile.sphere.center) - profile.sphere.radius);
5647
+ return Math.max(0, Math.hypot(radial2, point2[1] - profile.sphere.center) - profile.sphere.radius);
4693
5648
  const delta = this.radiusTop - this.radiusBottom;
4694
5649
  const sideNormalY = -delta / this.height;
4695
- const bottomArc = closestDistanceToCircleArc2D(radial2, point[1], -this.height / 2, this.radiusBottom, -1, sideNormalY);
4696
- const topArc = closestDistanceToCircleArc2D(radial2, point[1], this.height / 2, this.radiusTop, sideNormalY, 1);
4697
- const side = closestDistanceToSegment2D(radial2, point[1], profile.bottom.radius, profile.bottom.y, profile.top.radius, profile.top.y);
5650
+ const bottomArc = closestDistanceToCircleArc2D(radial2, point2[1], -this.height / 2, this.radiusBottom, -1, sideNormalY);
5651
+ const topArc = closestDistanceToCircleArc2D(radial2, point2[1], this.height / 2, this.radiusTop, sideNormalY, 1);
5652
+ const side = closestDistanceToSegment2D(radial2, point2[1], profile.bottom.radius, profile.bottom.y, profile.top.radius, profile.top.y);
4698
5653
  return Math.min(bottomArc, topArc, side);
4699
5654
  }
4700
- supportLocal(direction) {
4701
- const length = Math.hypot(...direction);
4702
- const unit = length ? direction.map((value) => value / length) : [1, 0, 0];
5655
+ supportLocal(direction2) {
5656
+ const length = Math.hypot(...direction2);
5657
+ const unit2 = length ? direction2.map((value) => value / length) : [1, 0, 0];
4703
5658
  const bottom = [
4704
- unit[0] * this.radiusBottom,
4705
- -this.height / 2 + unit[1] * this.radiusBottom,
4706
- unit[2] * this.radiusBottom
5659
+ unit2[0] * this.radiusBottom,
5660
+ -this.height / 2 + unit2[1] * this.radiusBottom,
5661
+ unit2[2] * this.radiusBottom
4707
5662
  ];
4708
5663
  const top = [
4709
- unit[0] * this.radiusTop,
4710
- this.height / 2 + unit[1] * this.radiusTop,
4711
- unit[2] * this.radiusTop
5664
+ unit2[0] * this.radiusTop,
5665
+ this.height / 2 + unit2[1] * this.radiusTop,
5666
+ unit2[2] * this.radiusTop
4712
5667
  ];
4713
- return dot(top, direction) >= dot(bottom, direction) ? top : bottom;
5668
+ return dot4(top, direction2) >= dot4(bottom, direction2) ? top : bottom;
4714
5669
  }
4715
- intersectLocalRay(origin, direction) {
5670
+ intersectLocalRay(origin, direction2) {
4716
5671
  const profile = this.getProfile();
4717
5672
  if (profile.sphere)
4718
- return intersectSphere(origin, direction, profile.sphere.center, profile.sphere.radius);
5673
+ return intersectSphere(origin, direction2, profile.sphere.center, profile.sphere.radius);
4719
5674
  const candidates = [];
4720
5675
  const slope = (profile.top.radius - profile.bottom.radius) / (profile.top.y - profile.bottom.y);
4721
5676
  const intercept = profile.bottom.radius - slope * profile.bottom.y;
4722
5677
  const radialAtOrigin = intercept + slope * origin[1];
4723
- const radialAlongRay = slope * direction[1];
4724
- for (const distance of solveQuadratic(direction[0] ** 2 + direction[2] ** 2 - radialAlongRay ** 2, 2 * (origin[0] * direction[0] + origin[2] * direction[2] - radialAtOrigin * radialAlongRay), origin[0] ** 2 + origin[2] ** 2 - radialAtOrigin ** 2)) {
4725
- const y = origin[1] + distance * direction[1];
5678
+ const radialAlongRay = slope * direction2[1];
5679
+ for (const distance of solveQuadratic(direction2[0] ** 2 + direction2[2] ** 2 - radialAlongRay ** 2, 2 * (origin[0] * direction2[0] + origin[2] * direction2[2] - radialAtOrigin * radialAlongRay), origin[0] ** 2 + origin[2] ** 2 - radialAtOrigin ** 2)) {
5680
+ const y = origin[1] + distance * direction2[1];
4726
5681
  if (distance >= 0 && y >= profile.bottom.y - EPSILON2 && y <= profile.top.y + EPSILON2) {
4727
- const x = origin[0] + distance * direction[0];
4728
- const z = origin[2] + distance * direction[2];
5682
+ const x = origin[0] + distance * direction2[0];
5683
+ const z = origin[2] + distance * direction2[2];
4729
5684
  const radial2 = Math.hypot(x, z) || 1;
4730
5685
  const normal = [x / radial2, -slope, z / radial2];
4731
5686
  const length = Math.hypot(...normal);
4732
5687
  candidates.push({ distance, normal: normal.map((value) => value / length) });
4733
5688
  }
4734
5689
  }
4735
- for (const bottomHit of intersectSphereRoots(origin, direction, -this.height / 2, this.radiusBottom)) {
4736
- const y = origin[1] + bottomHit.distance * direction[1];
5690
+ for (const bottomHit of intersectSphereRoots(origin, direction2, -this.height / 2, this.radiusBottom)) {
5691
+ const y = origin[1] + bottomHit.distance * direction2[1];
4737
5692
  if (y <= profile.bottom.y + EPSILON2)
4738
5693
  candidates.push(bottomHit);
4739
5694
  }
4740
- for (const topHit of intersectSphereRoots(origin, direction, this.height / 2, this.radiusTop)) {
4741
- const y = origin[1] + topHit.distance * direction[1];
5695
+ for (const topHit of intersectSphereRoots(origin, direction2, this.height / 2, this.radiusTop)) {
5696
+ const y = origin[1] + topHit.distance * direction2[1];
4742
5697
  if (y >= profile.top.y - EPSILON2)
4743
5698
  candidates.push(topHit);
4744
5699
  }
@@ -4769,19 +5724,19 @@ var CapsuleShape = class _CapsuleShape extends ImplicitShapeBase {
4769
5724
  };
4770
5725
  }
4771
5726
  };
4772
- function intersectSphere(origin, direction, centerY, radius) {
4773
- return intersectSphereRoots(origin, direction, centerY, radius)[0];
5727
+ function intersectSphere(origin, direction2, centerY, radius2) {
5728
+ return intersectSphereRoots(origin, direction2, centerY, radius2)[0];
4774
5729
  }
4775
- function intersectSphereRoots(origin, direction, centerY, radius) {
4776
- if (radius === 0)
5730
+ function intersectSphereRoots(origin, direction2, centerY, radius2) {
5731
+ if (radius2 === 0)
4777
5732
  return [];
4778
5733
  const relative = [origin[0], origin[1] - centerY, origin[2]];
4779
- return solveQuadratic(dot(direction, direction), 2 * dot(relative, direction), dot(relative, relative) - radius * radius).filter((distance) => distance >= 0).map((distance) => ({
5734
+ return solveQuadratic(dot4(direction2, direction2), 2 * dot4(relative, direction2), dot4(relative, relative) - radius2 * radius2).filter((distance) => distance >= 0).map((distance) => ({
4780
5735
  distance,
4781
- normal: relative.map((value, i) => (value + distance * direction[i]) / radius)
5736
+ normal: relative.map((value, i) => (value + distance * direction2[i]) / radius2)
4782
5737
  }));
4783
5738
  }
4784
- function dot(a, b) {
5739
+ function dot4(a, b) {
4785
5740
  return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
4786
5741
  }
4787
5742
 
@@ -4812,61 +5767,61 @@ var CylinderShape = class _CylinderShape extends ImplicitShapeBase {
4812
5767
  equals(shape) {
4813
5768
  return shape instanceof _CylinderShape && super.equals(shape) && this.height === shape.height && this.radiusBottom === shape.radiusBottom && this.radiusTop === shape.radiusTop;
4814
5769
  }
4815
- containsLocalPoint(point) {
5770
+ containsLocalPoint(point2) {
4816
5771
  const half = this.height / 2;
4817
- if (point[1] < -half - EPSILON3 || point[1] > half + EPSILON3)
5772
+ if (point2[1] < -half - EPSILON3 || point2[1] > half + EPSILON3)
4818
5773
  return false;
4819
- const t = (point[1] + half) / this.height;
4820
- const radius = this.radiusBottom + (this.radiusTop - this.radiusBottom) * t;
4821
- return Math.hypot(point[0], point[2]) <= radius + EPSILON3;
5774
+ const t = (point2[1] + half) / this.height;
5775
+ const radius2 = this.radiusBottom + (this.radiusTop - this.radiusBottom) * t;
5776
+ return Math.hypot(point2[0], point2[2]) <= radius2 + EPSILON3;
4822
5777
  }
4823
- distanceToLocalPoint(point) {
4824
- if (this.containsLocalPoint(point))
5778
+ distanceToLocalPoint(point2) {
5779
+ if (this.containsLocalPoint(point2))
4825
5780
  return 0;
4826
- const radial2 = Math.hypot(point[0], point[2]);
5781
+ const radial2 = Math.hypot(point2[0], point2[2]);
4827
5782
  const half = this.height / 2;
4828
- const side = closestDistanceToSegment2D(radial2, point[1], this.radiusBottom, -half, this.radiusTop, half);
4829
- const bottom = closestDistanceToSegment2D(radial2, point[1], 0, -half, this.radiusBottom, -half);
4830
- const top = closestDistanceToSegment2D(radial2, point[1], 0, half, this.radiusTop, half);
5783
+ const side = closestDistanceToSegment2D(radial2, point2[1], this.radiusBottom, -half, this.radiusTop, half);
5784
+ const bottom = closestDistanceToSegment2D(radial2, point2[1], 0, -half, this.radiusBottom, -half);
5785
+ const top = closestDistanceToSegment2D(radial2, point2[1], 0, half, this.radiusTop, half);
4831
5786
  return Math.min(side, bottom, top);
4832
5787
  }
4833
- supportLocal(direction) {
4834
- const radialLength = Math.hypot(direction[0], direction[2]);
4835
- const x = radialLength ? direction[0] / radialLength : 1;
4836
- const z = radialLength ? direction[2] / radialLength : 0;
5788
+ supportLocal(direction2) {
5789
+ const radialLength = Math.hypot(direction2[0], direction2[2]);
5790
+ const x = radialLength ? direction2[0] / radialLength : 1;
5791
+ const z = radialLength ? direction2[2] / radialLength : 0;
4837
5792
  const half = this.height / 2;
4838
- const bottomValue = radialLength * this.radiusBottom - direction[1] * half;
4839
- const topValue = radialLength * this.radiusTop + direction[1] * half;
5793
+ const bottomValue = radialLength * this.radiusBottom - direction2[1] * half;
5794
+ const topValue = radialLength * this.radiusTop + direction2[1] * half;
4840
5795
  return topValue >= bottomValue ? [x * this.radiusTop, half, z * this.radiusTop] : [x * this.radiusBottom, -half, z * this.radiusBottom];
4841
5796
  }
4842
- intersectLocalRay(origin, direction) {
5797
+ intersectLocalRay(origin, direction2) {
4843
5798
  const half = this.height / 2;
4844
5799
  const slope = (this.radiusTop - this.radiusBottom) / this.height;
4845
5800
  const intercept = (this.radiusTop + this.radiusBottom) / 2;
4846
5801
  const radialAtOrigin = intercept + slope * origin[1];
4847
- const radialAlongRay = slope * direction[1];
5802
+ const radialAlongRay = slope * direction2[1];
4848
5803
  const candidates = [];
4849
- const roots = solveQuadratic(direction[0] ** 2 + direction[2] ** 2 - radialAlongRay ** 2, 2 * (origin[0] * direction[0] + origin[2] * direction[2] - radialAtOrigin * radialAlongRay), origin[0] ** 2 + origin[2] ** 2 - radialAtOrigin ** 2);
5804
+ const roots = solveQuadratic(direction2[0] ** 2 + direction2[2] ** 2 - radialAlongRay ** 2, 2 * (origin[0] * direction2[0] + origin[2] * direction2[2] - radialAtOrigin * radialAlongRay), origin[0] ** 2 + origin[2] ** 2 - radialAtOrigin ** 2);
4850
5805
  for (const distance of roots) {
4851
- const y = origin[1] + distance * direction[1];
5806
+ const y = origin[1] + distance * direction2[1];
4852
5807
  if (distance >= 0 && y >= -half - EPSILON3 && y <= half + EPSILON3) {
4853
- const x = origin[0] + distance * direction[0];
4854
- const z = origin[2] + distance * direction[2];
5808
+ const x = origin[0] + distance * direction2[0];
5809
+ const z = origin[2] + distance * direction2[2];
4855
5810
  const radial2 = Math.hypot(x, z) || 1;
4856
5811
  const normal = [x / radial2, -slope, z / radial2];
4857
5812
  const length = Math.hypot(...normal);
4858
5813
  candidates.push({ distance, normal: normal.map((value) => value / length) });
4859
5814
  }
4860
5815
  }
4861
- if (Math.abs(direction[1]) > 1e-15) {
4862
- for (const [y, radius, normalY] of [
5816
+ if (Math.abs(direction2[1]) > 1e-15) {
5817
+ for (const [y, radius2, normalY] of [
4863
5818
  [-half, this.radiusBottom, -1],
4864
5819
  [half, this.radiusTop, 1]
4865
5820
  ]) {
4866
- const distance = (y - origin[1]) / direction[1];
4867
- const x = origin[0] + distance * direction[0];
4868
- const z = origin[2] + distance * direction[2];
4869
- if (distance >= 0 && Math.hypot(x, z) <= radius + EPSILON3)
5821
+ const distance = (y - origin[1]) / direction2[1];
5822
+ const x = origin[0] + distance * direction2[0];
5823
+ const z = origin[2] + distance * direction2[2];
5824
+ if (distance >= 0 && Math.hypot(x, z) <= radius2 + EPSILON3)
4870
5825
  candidates.push({ distance, normal: [0, normalY, 0] });
4871
5826
  }
4872
5827
  }
@@ -4875,7 +5830,7 @@ var CylinderShape = class _CylinderShape extends ImplicitShapeBase {
4875
5830
  };
4876
5831
 
4877
5832
  // dist/culling/lib/shapes/plane-shape.js
4878
- var import_core15 = require("@math.gl/core");
5833
+ var import_core16 = require("@math.gl/core");
4879
5834
  var PlaneShape = class _PlaneShape extends ImplicitShapeBase {
4880
5835
  constructor(props = {}) {
4881
5836
  super(props.matrix);
@@ -4893,23 +5848,23 @@ var PlaneShape = class _PlaneShape extends ImplicitShapeBase {
4893
5848
  equals(shape) {
4894
5849
  return shape instanceof _PlaneShape && super.equals(shape) && this.sizeX === shape.sizeX && this.sizeZ === shape.sizeZ;
4895
5850
  }
4896
- containsLocalPoint(point) {
4897
- return point[1] <= 1e-12;
5851
+ containsLocalPoint(point2) {
5852
+ return point2[1] <= 1e-12;
4898
5853
  }
4899
- distanceToLocalPoint(point) {
4900
- return Math.max(0, point[1]);
5854
+ distanceToLocalPoint(point2) {
5855
+ return Math.max(0, point2[1]);
4901
5856
  }
4902
5857
  supportLocal() {
4903
5858
  throw new Error("An unbounded plane half-space has no finite support point");
4904
5859
  }
4905
- intersectLocalRay(origin, direction) {
4906
- if (Math.abs(direction[1]) < 1e-15)
5860
+ intersectLocalRay(origin, direction2) {
5861
+ if (Math.abs(direction2[1]) < 1e-15)
4907
5862
  return void 0;
4908
- const distance = -origin[1] / direction[1];
5863
+ const distance = -origin[1] / direction2[1];
4909
5864
  if (distance < 0)
4910
5865
  return void 0;
4911
- const x = origin[0] + distance * direction[0];
4912
- const z = origin[2] + distance * direction[2];
5866
+ const x = origin[0] + distance * direction2[0];
5867
+ const z = origin[2] + distance * direction2[2];
4913
5868
  if (this.sizeX !== void 0 && Math.abs(x) > this.sizeX / 2 + 1e-12)
4914
5869
  return void 0;
4915
5870
  if (this.sizeZ !== void 0 && Math.abs(z) > this.sizeZ / 2 + 1e-12)
@@ -4917,9 +5872,9 @@ var PlaneShape = class _PlaneShape extends ImplicitShapeBase {
4917
5872
  return { distance, normal: [0, 1, 0] };
4918
5873
  }
4919
5874
  intersectPlane(plane) {
4920
- const boundaryPoint = new import_core15.Vector3(0, 0, 0).transform(this.matrix);
5875
+ const boundaryPoint = new import_core16.Vector3(0, 0, 0).transform(this.matrix);
4921
5876
  const inverse = this.inverseMatrix;
4922
- const boundaryNormal = new import_core15.Vector3(inverse[1], inverse[5], inverse[9]).normalize();
5877
+ const boundaryNormal = new import_core16.Vector3(inverse[1], inverse[5], inverse[9]).normalize();
4923
5878
  const alignment = boundaryNormal.dot(plane.normal);
4924
5879
  if (Math.abs(Math.abs(alignment) - 1) > 1e-10)
4925
5880
  return "intersecting";
@@ -4954,36 +5909,36 @@ var SphereShape = class _SphereShape extends ImplicitShapeBase {
4954
5909
  equals(shape) {
4955
5910
  return shape instanceof _SphereShape && super.equals(shape) && this.radius === shape.radius;
4956
5911
  }
4957
- containsLocalPoint(point) {
4958
- return Math.hypot(...point) <= this.radius + EPSILON4;
5912
+ containsLocalPoint(point2) {
5913
+ return Math.hypot(...point2) <= this.radius + EPSILON4;
4959
5914
  }
4960
- distanceToLocalPoint(point) {
4961
- return Math.max(0, Math.hypot(...point) - this.radius);
5915
+ distanceToLocalPoint(point2) {
5916
+ return Math.max(0, Math.hypot(...point2) - this.radius);
4962
5917
  }
4963
- supportLocal(direction) {
4964
- const length = Math.hypot(...direction);
4965
- return length ? direction.map((value) => value / length * this.radius) : [this.radius, 0, 0];
5918
+ supportLocal(direction2) {
5919
+ const length = Math.hypot(...direction2);
5920
+ return length ? direction2.map((value) => value / length * this.radius) : [this.radius, 0, 0];
4966
5921
  }
4967
- intersectLocalRay(origin, direction) {
4968
- const roots = solveQuadratic(dot2(direction, direction), 2 * dot2(origin, direction), dot2(origin, origin) - this.radius * this.radius);
5922
+ intersectLocalRay(origin, direction2) {
5923
+ const roots = solveQuadratic(dot5(direction2, direction2), 2 * dot5(origin, direction2), dot5(origin, origin) - this.radius * this.radius);
4969
5924
  const distance = roots.find((value) => value >= 0);
4970
5925
  if (distance === void 0)
4971
5926
  return void 0;
4972
- const point = origin.map((value, i) => value + distance * direction[i]);
4973
- return { distance, normal: point.map((value) => value / this.radius) };
5927
+ const point2 = origin.map((value, i) => value + distance * direction2[i]);
5928
+ return { distance, normal: point2.map((value) => value / this.radius) };
4974
5929
  }
4975
5930
  };
4976
- function dot2(a, b) {
5931
+ function dot5(a, b) {
4977
5932
  return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
4978
5933
  }
4979
5934
 
4980
5935
  // dist/culling/lib/perspective-off-center-frustum.js
4981
- var import_core16 = require("@math.gl/core");
4982
- var scratchPlaneUpVector = new import_core16.Vector3();
4983
- var scratchPlaneRightVector = new import_core16.Vector3();
4984
- var scratchPlaneNearCenter = new import_core16.Vector3();
4985
- var scratchPlaneFarCenter = new import_core16.Vector3();
4986
- var scratchPlaneNormal2 = new import_core16.Vector3();
5936
+ var import_core17 = require("@math.gl/core");
5937
+ var scratchPlaneUpVector = new import_core17.Vector3();
5938
+ var scratchPlaneRightVector = new import_core17.Vector3();
5939
+ var scratchPlaneNearCenter = new import_core17.Vector3();
5940
+ var scratchPlaneFarCenter = new import_core17.Vector3();
5941
+ var scratchPlaneNormal2 = new import_core17.Vector3();
4987
5942
  var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
4988
5943
  /**
4989
5944
  * The viewing frustum is defined by 6 planes.
@@ -5014,8 +5969,8 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
5014
5969
  new Plane(),
5015
5970
  new Plane()
5016
5971
  ]);
5017
- this._perspectiveMatrix = new import_core16.Matrix4();
5018
- this._infinitePerspective = new import_core16.Matrix4();
5972
+ this._perspectiveMatrix = new import_core17.Matrix4();
5973
+ this._infinitePerspective = new import_core17.Matrix4();
5019
5974
  const { near = 1, far = 5e8 } = options;
5020
5975
  this.left = options.left;
5021
5976
  this._left = void 0;
@@ -5085,15 +6040,15 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
5085
6040
  * const intersect = cullingVolume.computeVisibility(boundingVolume);
5086
6041
  */
5087
6042
  // eslint-disable-next-line complexity, max-statements
5088
- computeCullingVolume(position, direction, up) {
5089
- (0, import_core16.assert)(position, "position is required.");
5090
- (0, import_core16.assert)(direction, "direction is required.");
5091
- (0, import_core16.assert)(up, "up is required.");
6043
+ computeCullingVolume(position, direction2, up) {
6044
+ (0, import_core17.assert)(position, "position is required.");
6045
+ (0, import_core17.assert)(direction2, "direction is required.");
6046
+ (0, import_core17.assert)(up, "up is required.");
5092
6047
  const planes = this._cullingVolume.planes;
5093
6048
  up = scratchPlaneUpVector.copy(up).normalize();
5094
- const right = scratchPlaneRightVector.copy(direction).cross(up).normalize();
5095
- const nearCenter = scratchPlaneNearCenter.copy(direction).multiplyByScalar(this.near).add(position);
5096
- const farCenter = scratchPlaneFarCenter.copy(direction).multiplyByScalar(this.far).add(position);
6049
+ const right = scratchPlaneRightVector.copy(direction2).cross(up).normalize();
6050
+ const nearCenter = scratchPlaneNearCenter.copy(direction2).multiplyByScalar(this.near).add(position);
6051
+ const farCenter = scratchPlaneFarCenter.copy(direction2).multiplyByScalar(this.far).add(position);
5097
6052
  let normal = scratchPlaneNormal2;
5098
6053
  normal.copy(right).multiplyByScalar(this.left).add(nearCenter).subtract(position).cross(up);
5099
6054
  planes[0].fromPointNormal(position, normal);
@@ -5103,7 +6058,7 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
5103
6058
  planes[2].fromPointNormal(position, normal);
5104
6059
  normal.copy(up).multiplyByScalar(this.top).add(nearCenter).subtract(position).cross(right);
5105
6060
  planes[3].fromPointNormal(position, normal);
5106
- normal = new import_core16.Vector3().copy(direction);
6061
+ normal = new import_core17.Vector3().copy(direction2);
5107
6062
  planes[4].fromPointNormal(nearCenter, normal);
5108
6063
  normal.negate();
5109
6064
  planes[5].fromPointNormal(farCenter, normal);
@@ -5135,11 +6090,11 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
5135
6090
  */
5136
6091
  getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {
5137
6092
  this._update();
5138
- (0, import_core16.assert)(Number.isFinite(drawingBufferWidth) && Number.isFinite(drawingBufferHeight));
5139
- (0, import_core16.assert)(drawingBufferWidth > 0);
5140
- (0, import_core16.assert)(drawingBufferHeight > 0);
5141
- (0, import_core16.assert)(distance > 0);
5142
- (0, import_core16.assert)(result);
6093
+ (0, import_core17.assert)(Number.isFinite(drawingBufferWidth) && Number.isFinite(drawingBufferHeight));
6094
+ (0, import_core17.assert)(drawingBufferWidth > 0);
6095
+ (0, import_core17.assert)(drawingBufferHeight > 0);
6096
+ (0, import_core17.assert)(distance > 0);
6097
+ (0, import_core17.assert)(result);
5143
6098
  const inverseNear = 1 / this.near;
5144
6099
  let tanTheta = this.top * inverseNear;
5145
6100
  const pixelHeight = 2 * distance * tanTheta / drawingBufferHeight;
@@ -5151,17 +6106,17 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
5151
6106
  }
5152
6107
  // eslint-disable-next-line complexity, max-statements
5153
6108
  _update() {
5154
- (0, import_core16.assert)(Number.isFinite(this.right) && Number.isFinite(this.left) && Number.isFinite(this.top) && Number.isFinite(this.bottom) && Number.isFinite(this.near) && Number.isFinite(this.far));
6109
+ (0, import_core17.assert)(Number.isFinite(this.right) && Number.isFinite(this.left) && Number.isFinite(this.top) && Number.isFinite(this.bottom) && Number.isFinite(this.near) && Number.isFinite(this.far));
5155
6110
  const { top, bottom, right, left, near, far } = this;
5156
6111
  if (top !== this._top || bottom !== this._bottom || left !== this._left || right !== this._right || near !== this._near || far !== this._far) {
5157
- (0, import_core16.assert)(this.near > 0 && this.near < this.far, "near must be greater than zero and less than far.");
6112
+ (0, import_core17.assert)(this.near > 0 && this.near < this.far, "near must be greater than zero and less than far.");
5158
6113
  this._left = left;
5159
6114
  this._right = right;
5160
6115
  this._top = top;
5161
6116
  this._bottom = bottom;
5162
6117
  this._near = near;
5163
6118
  this._far = far;
5164
- this._perspectiveMatrix = new import_core16.Matrix4().frustum({
6119
+ this._perspectiveMatrix = new import_core17.Matrix4().frustum({
5165
6120
  left,
5166
6121
  right,
5167
6122
  bottom,
@@ -5169,7 +6124,7 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
5169
6124
  near,
5170
6125
  far
5171
6126
  });
5172
- this._infinitePerspective = new import_core16.Matrix4().frustum({
6127
+ this._infinitePerspective = new import_core17.Matrix4().frustum({
5173
6128
  left,
5174
6129
  right,
5175
6130
  bottom,
@@ -5182,7 +6137,7 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
5182
6137
  };
5183
6138
 
5184
6139
  // dist/culling/lib/perspective-frustum.js
5185
- var import_core17 = require("@math.gl/core");
6140
+ var import_core18 = require("@math.gl/core");
5186
6141
  var defined = (val) => val !== null && typeof val !== "undefined";
5187
6142
  var PerspectiveFrustum = class _PerspectiveFrustum {
5188
6143
  constructor(options = {}) {
@@ -5255,9 +6210,9 @@ var PerspectiveFrustum = class _PerspectiveFrustum {
5255
6210
  * var cullingVolume = this.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);
5256
6211
  * var intersect = cullingVolume.computeVisibility(boundingVolume);
5257
6212
  */
5258
- computeCullingVolume(position, direction, up) {
6213
+ computeCullingVolume(position, direction2, up) {
5259
6214
  this._update();
5260
- return this._offCenterFrustum.computeCullingVolume(position, direction, up);
6215
+ return this._offCenterFrustum.computeCullingVolume(position, direction2, up);
5261
6216
  }
5262
6217
  /**
5263
6218
  * Returns the pixel's width and height in meters.
@@ -5284,16 +6239,16 @@ var PerspectiveFrustum = class _PerspectiveFrustum {
5284
6239
  */
5285
6240
  getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {
5286
6241
  this._update();
5287
- return this._offCenterFrustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result || new import_core17.Vector2());
6242
+ return this._offCenterFrustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result || new import_core18.Vector2());
5288
6243
  }
5289
6244
  // eslint-disable-next-line complexity, max-statements
5290
6245
  _update() {
5291
- (0, import_core17.assert)(Number.isFinite(this.fov) && Number.isFinite(this.aspectRatio) && Number.isFinite(this.near) && Number.isFinite(this.far));
6246
+ (0, import_core18.assert)(Number.isFinite(this.fov) && Number.isFinite(this.aspectRatio) && Number.isFinite(this.near) && Number.isFinite(this.far));
5292
6247
  const f = this._offCenterFrustum;
5293
6248
  if (this.fov !== this._fov || this.aspectRatio !== this._aspectRatio || this.near !== this._near || this.far !== this._far || this.xOffset !== this._xOffset || this.yOffset !== this._yOffset) {
5294
- (0, import_core17.assert)(this.fov >= 0 && this.fov < Math.PI);
5295
- (0, import_core17.assert)(this.aspectRatio > 0);
5296
- (0, import_core17.assert)(this.near >= 0 && this.near < this.far);
6249
+ (0, import_core18.assert)(this.fov >= 0 && this.fov < Math.PI);
6250
+ (0, import_core18.assert)(this.aspectRatio > 0);
6251
+ (0, import_core18.assert)(this.near >= 0 && this.near < this.far);
5297
6252
  this._aspectRatio = this.aspectRatio;
5298
6253
  this._fov = this.fov;
5299
6254
  this._fovy = this.aspectRatio <= 1 ? this.fov : Math.atan(Math.tan(this.fov * 0.5) / this.aspectRatio) * 2;
@@ -5317,19 +6272,19 @@ var PerspectiveFrustum = class _PerspectiveFrustum {
5317
6272
  };
5318
6273
 
5319
6274
  // dist/culling/lib/algorithms/bounding-sphere-from-points.js
5320
- var import_core18 = require("@math.gl/core");
5321
- var fromPointsXMin = new import_core18.Vector3();
5322
- var fromPointsYMin = new import_core18.Vector3();
5323
- var fromPointsZMin = new import_core18.Vector3();
5324
- var fromPointsXMax = new import_core18.Vector3();
5325
- var fromPointsYMax = new import_core18.Vector3();
5326
- var fromPointsZMax = new import_core18.Vector3();
5327
- var fromPointsCurrentPos = new import_core18.Vector3();
5328
- var fromPointsScratch = new import_core18.Vector3();
5329
- var fromPointsRitterCenter = new import_core18.Vector3();
5330
- var fromPointsMinBoxPt = new import_core18.Vector3();
5331
- var fromPointsMaxBoxPt = new import_core18.Vector3();
5332
- var fromPointsNaiveCenterScratch = new import_core18.Vector3();
6275
+ var import_core19 = require("@math.gl/core");
6276
+ var fromPointsXMin = new import_core19.Vector3();
6277
+ var fromPointsYMin = new import_core19.Vector3();
6278
+ var fromPointsZMin = new import_core19.Vector3();
6279
+ var fromPointsXMax = new import_core19.Vector3();
6280
+ var fromPointsYMax = new import_core19.Vector3();
6281
+ var fromPointsZMax = new import_core19.Vector3();
6282
+ var fromPointsCurrentPos = new import_core19.Vector3();
6283
+ var fromPointsScratch = new import_core19.Vector3();
6284
+ var fromPointsRitterCenter = new import_core19.Vector3();
6285
+ var fromPointsMinBoxPt = new import_core19.Vector3();
6286
+ var fromPointsMaxBoxPt = new import_core19.Vector3();
6287
+ var fromPointsNaiveCenterScratch = new import_core19.Vector3();
5333
6288
  function makeBoundingSphereFromPoints(positions, result = new BoundingSphere()) {
5334
6289
  if (!positions || positions.length === 0) {
5335
6290
  return result.fromCenterRadius([0, 0, 0], 0);
@@ -5425,17 +6380,17 @@ function makeBoundingSphereFromPoints(positions, result = new BoundingSphere())
5425
6380
  }
5426
6381
 
5427
6382
  // dist/culling/lib/algorithms/bounding-box-from-points.js
5428
- var import_core20 = require("@math.gl/core");
6383
+ var import_core21 = require("@math.gl/core");
5429
6384
 
5430
6385
  // dist/culling/lib/algorithms/compute-eigen-decomposition.js
5431
- var import_core19 = require("@math.gl/core");
5432
- var scratchMatrix = new import_core19.Matrix3();
5433
- var scratchUnitary = new import_core19.Matrix3();
5434
- var scratchDiagonal = new import_core19.Matrix3();
5435
- var jMatrix = new import_core19.Matrix3();
5436
- var jMatrixTranspose = new import_core19.Matrix3();
6386
+ var import_core20 = require("@math.gl/core");
6387
+ var scratchMatrix = new import_core20.Matrix3();
6388
+ var scratchUnitary = new import_core20.Matrix3();
6389
+ var scratchDiagonal = new import_core20.Matrix3();
6390
+ var jMatrix = new import_core20.Matrix3();
6391
+ var jMatrixTranspose = new import_core20.Matrix3();
5437
6392
  function computeEigenDecomposition(matrix, result = {}) {
5438
- const EIGEN_TOLERANCE = import_core19._MathUtils.EPSILON20;
6393
+ const EIGEN_TOLERANCE = import_core20._MathUtils.EPSILON20;
5439
6394
  const EIGEN_MAX_SWEEPS = 10;
5440
6395
  let count = 0;
5441
6396
  let sweep = 0;
@@ -5478,7 +6433,7 @@ function offDiagonalFrobeniusNorm(matrix) {
5478
6433
  return Math.sqrt(norm);
5479
6434
  }
5480
6435
  function shurDecomposition(matrix, result) {
5481
- const tolerance = import_core19._MathUtils.EPSILON15;
6436
+ const tolerance = import_core20._MathUtils.EPSILON15;
5482
6437
  let maxDiagonal = 0;
5483
6438
  let rotAxis = 1;
5484
6439
  for (let i = 0; i < 3; ++i) {
@@ -5506,7 +6461,7 @@ function shurDecomposition(matrix, result) {
5506
6461
  c = 1 / Math.sqrt(1 + t * t);
5507
6462
  s = t * c;
5508
6463
  }
5509
- import_core19.Matrix3.IDENTITY.to(result);
6464
+ import_core20.Matrix3.IDENTITY.to(result);
5510
6465
  result[scratchMatrix.getElementIndex(p, p)] = result[scratchMatrix.getElementIndex(q, q)] = c;
5511
6466
  result[scratchMatrix.getElementIndex(q, p)] = s;
5512
6467
  result[scratchMatrix.getElementIndex(p, q)] = -s;
@@ -5514,24 +6469,24 @@ function shurDecomposition(matrix, result) {
5514
6469
  }
5515
6470
 
5516
6471
  // dist/culling/lib/algorithms/bounding-box-from-points.js
5517
- var scratchVector23 = new import_core20.Vector3();
5518
- var scratchVector33 = new import_core20.Vector3();
5519
- var scratchVector42 = new import_core20.Vector3();
5520
- var scratchVector5 = new import_core20.Vector3();
5521
- var scratchVector6 = new import_core20.Vector3();
5522
- var scratchCovarianceResult = new import_core20.Matrix3();
6472
+ var scratchVector23 = new import_core21.Vector3();
6473
+ var scratchVector33 = new import_core21.Vector3();
6474
+ var scratchVector42 = new import_core21.Vector3();
6475
+ var scratchVector5 = new import_core21.Vector3();
6476
+ var scratchVector6 = new import_core21.Vector3();
6477
+ var scratchCovarianceResult = new import_core21.Matrix3();
5523
6478
  var scratchEigenResult = {
5524
- diagonal: new import_core20.Matrix3(),
5525
- unitary: new import_core20.Matrix3()
6479
+ diagonal: new import_core21.Matrix3(),
6480
+ unitary: new import_core21.Matrix3()
5526
6481
  };
5527
6482
  function makeOrientedBoundingBoxFromPoints(positions, result = new OrientedBoundingBox()) {
5528
6483
  if (!positions || positions.length === 0) {
5529
- result.halfAxes = new import_core20.Matrix3([0, 0, 0, 0, 0, 0, 0, 0, 0]);
5530
- result.center = new import_core20.Vector3();
6484
+ result.halfAxes = new import_core21.Matrix3([0, 0, 0, 0, 0, 0, 0, 0, 0]);
6485
+ result.center = new import_core21.Vector3();
5531
6486
  return result;
5532
6487
  }
5533
6488
  const length = positions.length;
5534
- const meanPoint = new import_core20.Vector3(0, 0, 0);
6489
+ const meanPoint = new import_core21.Vector3(0, 0, 0);
5535
6490
  for (const position of positions) {
5536
6491
  meanPoint.add(position);
5537
6492
  }
@@ -5593,7 +6548,7 @@ function makeOrientedBoundingBoxFromPoints(positions, result = new OrientedBound
5593
6548
  v3 = v3.multiplyByScalar(0.5 * (l3 + u3));
5594
6549
  result.center.copy(v1).add(v2).add(v3);
5595
6550
  const scale = scratchVector33.set(u1 - l1, u2 - l2, u3 - l3).multiplyByScalar(0.5);
5596
- const scaleMatrix = new import_core20.Matrix3([scale[0], 0, 0, 0, scale[1], 0, 0, 0, scale[2]]);
6551
+ const scaleMatrix = new import_core21.Matrix3([scale[0], 0, 0, 0, scale[1], 0, 0, 0, scale[2]]);
5597
6552
  result.halfAxes.multiplyRight(scaleMatrix);
5598
6553
  return result;
5599
6554
  }
@@ -5629,245 +6584,6 @@ function makeAxisAlignedBoundingBoxFromPoints(positions, result = new AxisAligne
5629
6584
  return result;
5630
6585
  }
5631
6586
 
5632
- // dist/culling/queries.js
5633
- function validateQueryPoint(point, dimension) {
5634
- if (point.length !== dimension)
5635
- throw new RangeError("Query dimension must match the index");
5636
- for (let i = 0; i < dimension; i++) {
5637
- if (!Number.isFinite(point[i]))
5638
- throw new RangeError("Coordinates must be finite");
5639
- }
5640
- }
5641
- function validateQueryDistance(distance) {
5642
- if (Number.isNaN(distance) || distance < 0)
5643
- throw new RangeError("Distance must be nonnegative");
5644
- }
5645
- function normalizeQueryDirection(direction, dimension) {
5646
- validateQueryPoint(direction, dimension);
5647
- const scale = Math.max(...Array.from(direction, Math.abs));
5648
- if (scale === 0)
5649
- throw new RangeError("Ray direction must be nonzero");
5650
- const scaled = Array.from(direction, (x) => x / scale);
5651
- const length = Math.hypot(...scaled);
5652
- return scaled.map((x) => x / length);
5653
- }
5654
- function intersectRayBounds(origin, direction, minimum, maximum, maxT = Infinity) {
5655
- const dimension = origin.length;
5656
- if (dimension !== 2 && dimension !== 3)
5657
- throw new RangeError("Bounds must be 2D or 3D");
5658
- validateQueryPoint(origin, dimension);
5659
- validateQueryPoint(direction, dimension);
5660
- validateQueryPoint(minimum, dimension);
5661
- validateQueryPoint(maximum, dimension);
5662
- validateQueryDistance(maxT);
5663
- let near = 0, far = maxT, nonzero = false;
5664
- for (let i = 0; i < dimension; i++) {
5665
- if (minimum[i] > maximum[i])
5666
- throw new RangeError("Bounds must be ordered");
5667
- nonzero || (nonzero = direction[i] !== 0);
5668
- }
5669
- if (!nonzero)
5670
- throw new RangeError("Ray direction must be nonzero");
5671
- for (let i = 0; i < dimension; i++) {
5672
- if (direction[i] === 0) {
5673
- if (origin[i] < minimum[i] || origin[i] > maximum[i])
5674
- return null;
5675
- continue;
5676
- }
5677
- let a = (minimum[i] - origin[i]) / direction[i];
5678
- let b = (maximum[i] - origin[i]) / direction[i];
5679
- if (a > b)
5680
- [a, b] = [b, a];
5681
- near = Math.max(near, a);
5682
- far = Math.min(far, b);
5683
- if (near > far)
5684
- return null;
5685
- }
5686
- return Number.isFinite(near) ? near : null;
5687
- }
5688
- function intersectRayTriangle(origin, direction, a, b, c, options = {}) {
5689
- for (const point of [origin, direction, a, b, c])
5690
- validateQueryPoint(point, 3);
5691
- if (direction[0] === 0 && direction[1] === 0 && direction[2] === 0) {
5692
- throw new RangeError("Ray direction must be nonzero");
5693
- }
5694
- const maxT = options.maxT ?? Infinity;
5695
- validateQueryDistance(maxT);
5696
- const e1 = [b[0] - a[0], b[1] - a[1], b[2] - a[2]];
5697
- const e2 = [c[0] - a[0], c[1] - a[1], c[2] - a[2]];
5698
- const p = cross3(direction, e2);
5699
- const determinant = dot3(e1, p);
5700
- if (determinant === 0 || options.backfaceCulling && determinant < 0)
5701
- return null;
5702
- const offset = [origin[0] - a[0], origin[1] - a[1], origin[2] - a[2]];
5703
- const u = dot3(offset, p) / determinant;
5704
- if (u < 0 || u > 1)
5705
- return null;
5706
- const q = cross3(offset, e1);
5707
- const v = dot3(direction, q) / determinant;
5708
- if (v < 0 || u + v > 1)
5709
- return null;
5710
- const t = dot3(e2, q) / determinant;
5711
- if (!Number.isFinite(t) || t < 0 || t > maxT)
5712
- return null;
5713
- return { t: Math.max(0, t), barycentric: [1 - u - v, u, v] };
5714
- }
5715
- function getClosestPointOnTriangle(point, a, b, c) {
5716
- for (const value of [point, a, b, c])
5717
- validateQueryPoint(value, 3);
5718
- const ab = [b[0] - a[0], b[1] - a[1], b[2] - a[2]];
5719
- const ac = [c[0] - a[0], c[1] - a[1], c[2] - a[2]];
5720
- const ap = [point[0] - a[0], point[1] - a[1], point[2] - a[2]];
5721
- const aa = dot3(ab, ab), bb = dot3(ac, ac), cc = dot3(ab, ac);
5722
- const denominator = aa * bb - cc * cc;
5723
- if (denominator > 0 && Number.isFinite(denominator)) {
5724
- const u = (bb * dot3(ap, ab) - cc * dot3(ap, ac)) / denominator;
5725
- const v = (aa * dot3(ap, ac) - cc * dot3(ap, ab)) / denominator;
5726
- if (u >= 0 && v >= 0 && u + v <= 1) {
5727
- return [
5728
- a[0] + u * ab[0] + v * ac[0],
5729
- a[1] + u * ab[1] + v * ac[1],
5730
- a[2] + u * ab[2] + v * ac[2]
5731
- ];
5732
- }
5733
- }
5734
- let best = [a[0], a[1], a[2]];
5735
- let distance = Infinity;
5736
- for (const [start, end] of [
5737
- [a, b],
5738
- [b, c],
5739
- [c, a]
5740
- ]) {
5741
- const edge = [end[0] - start[0], end[1] - start[1], end[2] - start[2]];
5742
- const offset = [point[0] - start[0], point[1] - start[1], point[2] - start[2]];
5743
- const squared = dot3(edge, edge);
5744
- const t = squared > 0 ? Math.max(0, Math.min(1, dot3(offset, edge) / squared)) : 0;
5745
- const candidate = [
5746
- start[0] + t * edge[0],
5747
- start[1] + t * edge[1],
5748
- start[2] + t * edge[2]
5749
- ];
5750
- const d = Math.hypot(point[0] - candidate[0], point[1] - candidate[1], point[2] - candidate[2]);
5751
- if (d < distance) {
5752
- distance = d;
5753
- best = candidate;
5754
- }
5755
- }
5756
- return best;
5757
- }
5758
- function getClosestPointsOnSegments(a0, a1, b0, b1) {
5759
- const frame = queryFrame([a0, a1, b0, b1]);
5760
- const pair = closestSegments(...frame.points);
5761
- const pointA = interpolatePoint(a0, a1, pair.fractionA);
5762
- const pointB = interpolatePoint(b0, b1, pair.fractionB);
5763
- return {
5764
- distance: finiteDistance(pointA, pointB),
5765
- pointA,
5766
- pointB,
5767
- fractionA: pair.fractionA,
5768
- fractionB: pair.fractionB
5769
- };
5770
- }
5771
- function getClosestPointsSegmentTriangle(start, end, a, b, c) {
5772
- const frame = queryFrame([start, end, a, b, c]);
5773
- const [s, e, va, vb, vc] = frame.points;
5774
- const direction = subtract(e, s);
5775
- if (direction.some((value) => value !== 0)) {
5776
- const hit = intersectRayTriangle(s, direction, va, vb, vc, { maxT: 1 });
5777
- if (hit) {
5778
- const point = interpolatePoint(start, end, hit.t);
5779
- return { distance: 0, segmentPoint: point, trianglePoint: [...point], segmentFraction: hit.t };
5780
- }
5781
- }
5782
- let best = { distance: Infinity, segmentFraction: 0, trianglePoint: va };
5783
- const consider = (point, trianglePoint2, segmentFraction) => {
5784
- const distance = Math.hypot(...subtract(point, trianglePoint2));
5785
- if (distance < best.distance || distance === best.distance && segmentFraction < best.segmentFraction)
5786
- best = { distance, segmentFraction, trianglePoint: trianglePoint2 };
5787
- };
5788
- consider(s, getClosestPointOnTriangle(s, va, vb, vc), 0);
5789
- consider(e, getClosestPointOnTriangle(e, va, vb, vc), 1);
5790
- for (const [v0, v1] of [
5791
- [va, vb],
5792
- [vb, vc],
5793
- [vc, va]
5794
- ]) {
5795
- const pair = closestSegments(s, e, v0, v1);
5796
- consider(interpolatePoint(s, e, pair.fractionA), interpolatePoint(v0, v1, pair.fractionB), pair.fractionA);
5797
- }
5798
- const trianglePoint = best.trianglePoint.map((value, axis) => Math.max(Math.min(a[axis], b[axis], c[axis]), Math.min(Math.max(a[axis], b[axis], c[axis]), start[axis] + value * frame.scale)));
5799
- if (!trianglePoint.every(Number.isFinite))
5800
- throw new RangeError("Closest-point result overflow");
5801
- const segmentPoint = interpolatePoint(start, end, best.segmentFraction);
5802
- return {
5803
- distance: finiteDistance(segmentPoint, trianglePoint),
5804
- segmentPoint,
5805
- trianglePoint,
5806
- segmentFraction: best.segmentFraction
5807
- };
5808
- }
5809
- function queryFrame(input) {
5810
- input.forEach((point) => validateQueryPoint(point, 3));
5811
- const offsets = input.map((point) => subtract(point, input[0]));
5812
- let scale = 0;
5813
- for (const offset of offsets)
5814
- for (const value of offset) {
5815
- if (!Number.isFinite(value))
5816
- throw new RangeError("Closest-point coordinate span overflow");
5817
- scale = Math.max(scale, Math.abs(value));
5818
- }
5819
- scale || (scale = 1);
5820
- return { points: offsets.map((point) => point.map((value) => value / scale)), scale };
5821
- }
5822
- function closestSegments(a0, a1, b0, b1) {
5823
- const da = subtract(a1, a0), db = subtract(b1, b0);
5824
- const lengthA = Math.hypot(...da), lengthB = Math.hypot(...db);
5825
- const ua = da.map((value) => lengthA ? value / lengthA : 0);
5826
- const ub = db.map((value) => lengthB ? value / lengthB : 0);
5827
- let best = { distance: Infinity, fractionA: 0, fractionB: 0 };
5828
- const consider = (fractionA, fractionB) => {
5829
- const distance = Math.hypot(...subtract(interpolatePoint(a0, a1, fractionA), interpolatePoint(b0, b1, fractionB)));
5830
- if (distance < best.distance || distance === best.distance && (fractionA < best.fractionA || fractionA === best.fractionA && fractionB < best.fractionB))
5831
- best = { distance, fractionA, fractionB };
5832
- };
5833
- for (const t of [0, 1]) {
5834
- consider(t, lengthB ? clampUnit(dot3(subtract(t ? a1 : a0, b0), ub) / lengthB) : 0);
5835
- consider(lengthA ? clampUnit(dot3(subtract(t ? b1 : b0, a0), ua) / lengthA) : 0, t);
5836
- }
5837
- const normal = cross3(ua, ub);
5838
- const sine = Math.hypot(...normal);
5839
- if (sine > 0) {
5840
- const unit = normal.map((value) => value / sine);
5841
- const offset = subtract(b0, a0);
5842
- const fractionA = dot3(cross3(offset, ub), unit) / sine / lengthA;
5843
- const fractionB = dot3(cross3(offset, ua), unit) / sine / lengthB;
5844
- if (fractionA >= 0 && fractionA <= 1 && fractionB >= 0 && fractionB <= 1)
5845
- consider(fractionA, fractionB);
5846
- }
5847
- return best;
5848
- }
5849
- function subtract(a, b) {
5850
- return [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
5851
- }
5852
- function interpolatePoint(a, b, t) {
5853
- return [0, 1, 2].map((axis) => Math.max(Math.min(a[axis], b[axis]), Math.min(Math.max(a[axis], b[axis]), (1 - t) * a[axis] + t * b[axis])));
5854
- }
5855
- function clampUnit(value) {
5856
- return Math.max(0, Math.min(1, value));
5857
- }
5858
- function finiteDistance(a, b) {
5859
- const distance = Math.hypot(...subtract(a, b));
5860
- if (!Number.isFinite(distance))
5861
- throw new RangeError("Closest-point distance overflow");
5862
- return distance;
5863
- }
5864
- function dot3(a, b) {
5865
- return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
5866
- }
5867
- function cross3(a, b) {
5868
- return [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
5869
- }
5870
-
5871
6587
  // dist/culling/oriented-box-2d.js
5872
6588
  function intersectOrientedBoxes2D(first, second, epsilon = 0) {
5873
6589
  validateBox(first);
@@ -5919,64 +6635,177 @@ function validateVector(vector) {
5919
6635
  }
5920
6636
 
5921
6637
  // dist/culling/lib/algorithms/oriented-bounding-box-quaternion.js
5922
- var import_core21 = require("@math.gl/core");
6638
+ var import_core22 = require("@math.gl/core");
5923
6639
  function getOrientedBoundingBoxQuaternion(box) {
5924
- const x = new import_core21.Vector3(box.halfAxes.getColumn(0)).normalize();
5925
- const y = new import_core21.Vector3(box.halfAxes.getColumn(1)).normalize();
5926
- const z = new import_core21.Vector3(box.halfAxes.getColumn(2)).normalize();
5927
- return new import_core21.Quaternion().fromMatrix3(new import_core21.Matrix3([...x, ...y, ...z]));
6640
+ const x = new import_core22.Vector3(box.halfAxes.getColumn(0)).normalize();
6641
+ const y = new import_core22.Vector3(box.halfAxes.getColumn(1)).normalize();
6642
+ const z = new import_core22.Vector3(box.halfAxes.getColumn(2)).normalize();
6643
+ return new import_core22.Quaternion().fromMatrix3(new import_core22.Matrix3([...x, ...y, ...z]));
5928
6644
  }
5929
6645
  function makeOrientedBoundingBoxFromQuaternion(center, halfSize, quaternion, result = new OrientedBoundingBox()) {
5930
- const halfAxes = new import_core21.Matrix3().fromQuaternion(quaternion);
6646
+ const halfAxes = new import_core22.Matrix3().fromQuaternion(quaternion);
5931
6647
  for (let column = 0; column < 3; column++) {
5932
6648
  for (let row = 0; row < 3; row++)
5933
6649
  halfAxes[column * 3 + row] *= halfSize[column];
5934
6650
  }
5935
- result.center = new import_core21.Vector3(center);
6651
+ result.center = new import_core22.Vector3(center);
5936
6652
  result.halfAxes = halfAxes;
5937
6653
  return result;
5938
6654
  }
5939
6655
 
6656
+ // dist/culling/bounds.js
6657
+ function dimension(bounds) {
6658
+ const n = bounds[0].length;
6659
+ if (n !== 2 && n !== 3 || bounds[1].length !== n || [...Array.from(bounds[0]), ...Array.from(bounds[1])].some(Number.isNaN)) {
6660
+ throw new RangeError("Expected 2D or 3D bounds without NaN");
6661
+ }
6662
+ const empty = Array.from({ length: n }, (_, i) => bounds[0][i] > bounds[1][i]).some(Boolean);
6663
+ if (!empty && [...Array.from(bounds[0]), ...Array.from(bounds[1])].some((x) => !Number.isFinite(x))) {
6664
+ throw new RangeError("Nonempty bounds must be finite");
6665
+ }
6666
+ return n;
6667
+ }
6668
+ function pair(a, b) {
6669
+ const n = dimension(a);
6670
+ if (dimension(b) !== n)
6671
+ throw new RangeError("Bounds dimensions must match");
6672
+ return n;
6673
+ }
6674
+ function point(p, n) {
6675
+ if (p.length !== n || Array.from(p).some((x) => !Number.isFinite(x)))
6676
+ throw new RangeError("Expected a finite point of matching dimension");
6677
+ }
6678
+ function createEmptyBounds(dimension2) {
6679
+ if (dimension2 !== 2 && dimension2 !== 3)
6680
+ throw new RangeError("Expected dimension 2 or 3");
6681
+ return [new Array(dimension2).fill(Infinity), new Array(dimension2).fill(-Infinity)];
6682
+ }
6683
+ function isEmptyBounds(bounds) {
6684
+ return Array.from({ length: dimension(bounds) }, (_, i) => bounds[0][i] > bounds[1][i]).some(Boolean);
6685
+ }
6686
+ function boundsContainsPoint(bounds, p) {
6687
+ point(p, dimension(bounds));
6688
+ return !isEmptyBounds(bounds) && Array.from(p).every((x, i) => x >= bounds[0][i] && x <= bounds[1][i]);
6689
+ }
6690
+ function boundsContainsBounds(a, b) {
6691
+ const n = pair(a, b);
6692
+ return isEmptyBounds(b) || !isEmptyBounds(a) && Array.from({ length: n }, (_, i) => a[0][i] <= b[0][i] && a[1][i] >= b[1][i]).every(Boolean);
6693
+ }
6694
+ function boundsIntersect(a, b) {
6695
+ const n = pair(a, b);
6696
+ return !isEmptyBounds(a) && !isEmptyBounds(b) && Array.from({ length: n }, (_, i) => a[0][i] <= b[1][i] && b[0][i] <= a[1][i]).every(Boolean);
6697
+ }
6698
+ function store(values, out = createEmptyBounds(values[0].length)) {
6699
+ if (out[0].length !== values[0].length || out[1].length !== values[0].length) {
6700
+ throw new RangeError("Output bounds dimensions must match");
6701
+ }
6702
+ for (let j = 0; j < 2; j++)
6703
+ for (let i = 0; i < values[j].length; i++)
6704
+ out[j][i] = values[j][i];
6705
+ return out;
6706
+ }
6707
+ function unionBounds(a, b, out) {
6708
+ const n = pair(a, b);
6709
+ const values = createEmptyBounds(n);
6710
+ const ea = isEmptyBounds(a), eb = isEmptyBounds(b);
6711
+ for (let i = 0; i < n; i++) {
6712
+ values[0][i] = Math.min(ea ? Infinity : a[0][i], eb ? Infinity : b[0][i]);
6713
+ values[1][i] = Math.max(ea ? -Infinity : a[1][i], eb ? -Infinity : b[1][i]);
6714
+ }
6715
+ return store(values, out);
6716
+ }
6717
+ function intersectBounds(a, b, out) {
6718
+ const n = pair(a, b), values = createEmptyBounds(n);
6719
+ if (boundsIntersect(a, b))
6720
+ for (let i = 0; i < n; i++) {
6721
+ values[0][i] = Math.max(a[0][i], b[0][i]);
6722
+ values[1][i] = Math.min(a[1][i], b[1][i]);
6723
+ }
6724
+ return store(values, out);
6725
+ }
6726
+ function expandBoundsByPoint(bounds, p, out) {
6727
+ point(p, dimension(bounds));
6728
+ return unionBounds(bounds, [p, p], out);
6729
+ }
6730
+ function expandBounds(bounds, padding, out) {
6731
+ if (!Number.isFinite(padding))
6732
+ throw new RangeError("Padding must be finite");
6733
+ const n = dimension(bounds), values = createEmptyBounds(n);
6734
+ if (!isEmptyBounds(bounds))
6735
+ for (let i = 0; i < n; i++) {
6736
+ values[0][i] = bounds[0][i] - padding;
6737
+ values[1][i] = bounds[1][i] + padding;
6738
+ }
6739
+ return store(isEmptyBounds(values) ? createEmptyBounds(n) : values, out);
6740
+ }
6741
+ function clampPointToBounds(bounds, p, out = new Array(p.length)) {
6742
+ point(p, dimension(bounds));
6743
+ if (out.length < p.length)
6744
+ throw new RangeError("Result buffer is too short");
6745
+ if (isEmptyBounds(bounds))
6746
+ return null;
6747
+ const result = Array.from(p, (x, i) => Math.max(bounds[0][i], Math.min(bounds[1][i], x)));
6748
+ for (let i = 0; i < result.length; i++)
6749
+ out[i] = result[i];
6750
+ return out;
6751
+ }
6752
+ function radius(r) {
6753
+ if (!Number.isFinite(r) || r < 0)
6754
+ throw new RangeError("Radius must be finite and nonnegative");
6755
+ }
6756
+ function spheresIntersect(a, ar, b, br) {
6757
+ point(a, 3);
6758
+ point(b, 3);
6759
+ radius(ar);
6760
+ radius(br);
6761
+ return Math.hypot(a[0] - b[0], a[1] - b[1], a[2] - b[2]) <= ar + br;
6762
+ }
6763
+ function boundsIntersectSphere(bounds, center, r) {
6764
+ radius(r);
6765
+ const closest = clampPointToBounds(bounds, center);
6766
+ return closest !== null && Math.hypot(...Array.from(center, (x, i) => x - closest[i])) <= r;
6767
+ }
6768
+
5940
6769
  // dist/spatial-index/box-index.js
5941
6770
  var BoxIndex = class {
5942
6771
  constructor(options) {
5943
- const { dimension, bounds, leafSize = 8 } = options;
5944
- if (dimension !== 2 && dimension !== 3)
6772
+ const { dimension: dimension2, bounds, leafSize = 8 } = options;
6773
+ if (dimension2 !== 2 && dimension2 !== 3)
5945
6774
  throw new RangeError("Index dimension must be 2 or 3");
5946
6775
  if (!Number.isSafeInteger(leafSize) || leafSize < 1)
5947
6776
  throw new RangeError("leafSize must be positive");
5948
- if (bounds.length % (dimension * 2))
6777
+ if (bounds.length % (dimension2 * 2))
5949
6778
  throw new RangeError("Incomplete bounds record");
5950
- this.dimension = dimension;
6779
+ this.dimension = dimension2;
5951
6780
  this.bounds = Float64Array.from(bounds);
5952
- this.size = bounds.length / (dimension * 2);
6781
+ this.size = bounds.length / (dimension2 * 2);
5953
6782
  if (this.size > 2147483647)
5954
6783
  throw new RangeError("Index exceeds 32-bit capacity");
5955
- const stride = dimension * 2;
6784
+ const stride = dimension2 * 2;
5956
6785
  for (let i = 0; i < this.size; i++)
5957
- this.validateBounds(this.bounds.subarray(i * stride, i * stride + dimension), this.bounds.subarray(i * stride + dimension, (i + 1) * stride));
6786
+ this.validateBounds(this.bounds.subarray(i * stride, i * stride + dimension2), this.bounds.subarray(i * stride + dimension2, (i + 1) * stride));
5958
6787
  const records = [];
5959
6788
  const ids = Array.from({ length: this.size }, (_, i) => i);
5960
6789
  const build = (start, end) => {
5961
6790
  const node = records.length;
5962
6791
  const bound = [
5963
- ...new Array(dimension).fill(Infinity),
5964
- ...new Array(dimension).fill(-Infinity)
6792
+ ...new Array(dimension2).fill(Infinity),
6793
+ ...new Array(dimension2).fill(-Infinity)
5965
6794
  ];
5966
6795
  for (let i = start; i < end; i++)
5967
- for (let axis = 0; axis < dimension; axis++) {
6796
+ for (let axis = 0; axis < dimension2; axis++) {
5968
6797
  bound[axis] = Math.min(bound[axis], this.bounds[ids[i] * stride + axis]);
5969
- bound[axis + dimension] = Math.max(bound[axis + dimension], this.bounds[ids[i] * stride + axis + dimension]);
6798
+ bound[axis + dimension2] = Math.max(bound[axis + dimension2], this.bounds[ids[i] * stride + axis + dimension2]);
5970
6799
  }
5971
6800
  const record = { bounds: bound, left: -1, right: -1, start, count: end - start };
5972
6801
  records.push(record);
5973
6802
  if (end - start > leafSize) {
5974
6803
  let axis = 0;
5975
- for (let i = 1; i < dimension; i++) {
5976
- if (bound[i + dimension] - bound[i] > bound[axis + dimension] - bound[axis])
6804
+ for (let i = 1; i < dimension2; i++) {
6805
+ if (bound[i + dimension2] - bound[i] > bound[axis + dimension2] - bound[axis])
5977
6806
  axis = i;
5978
6807
  }
5979
- const center = (i) => this.bounds[i * stride + axis] / 2 + this.bounds[i * stride + axis + dimension] / 2;
6808
+ const center = (i) => this.bounds[i * stride + axis] / 2 + this.bounds[i * stride + axis + dimension2] / 2;
5980
6809
  const sorted = ids.slice(start, end).sort((a, b) => center(a) - center(b) || a - b);
5981
6810
  for (let i = 0; i < sorted.length; i++)
5982
6811
  ids[start + i] = sorted[i];
@@ -6050,11 +6879,11 @@ var BoxIndex = class {
6050
6879
  return { result: result.sort((a, b) => a - b), complete, work: budget.work };
6051
6880
  }
6052
6881
  /** Branch-and-bound nearest box, optionally refined against actual geometry. */
6053
- nearest(point, options = {}) {
6054
- return this.nearestQuery(point, { ...options, maxWork: Infinity }).result;
6882
+ nearest(point2, options = {}) {
6883
+ return this.nearestQuery(point2, { ...options, maxWork: Infinity }).result;
6055
6884
  }
6056
- nearestQuery(point, options = {}) {
6057
- return this.nearestBoxQuery(point, point, options);
6885
+ nearestQuery(point2, options = {}) {
6886
+ return this.nearestBoxQuery(point2, point2, options);
6058
6887
  }
6059
6888
  /** Nearest indexed box to a filled query box, optionally refined to enclosed geometry. */
6060
6889
  nearestBoxQuery(minimum, maximum, options = {}) {
@@ -6118,19 +6947,19 @@ var BoxIndex = class {
6118
6947
  * Nearest accepted box/geometry hit without materializing and sorting all ray candidates.
6119
6948
  * Rejected refinements do not clip the ray. Equal distances select the lowest original row.
6120
6949
  */
6121
- intersectRay(origin, direction, options = {}) {
6122
- return this.intersectRayQuery(origin, direction, { ...options, maxWork: Infinity }).result;
6950
+ intersectRay(origin, direction2, options = {}) {
6951
+ return this.intersectRayQuery(origin, direction2, { ...options, maxWork: Infinity }).result;
6123
6952
  }
6124
- intersectRayQuery(origin, direction, options = {}) {
6953
+ intersectRayQuery(origin, direction2, options = {}) {
6125
6954
  validateQueryPoint(origin, this.dimension);
6126
6955
  const budget = new QueryBudget(options.maxWork);
6127
- const unit = normalizeQueryDirection(direction, this.dimension);
6956
+ const unit2 = normalizeQueryDirection(direction2, this.dimension);
6128
6957
  let best = options.maxDistance ?? Infinity;
6129
6958
  validateQueryDistance(best);
6130
6959
  let result = null;
6131
6960
  const getEntry = (bounds, index) => {
6132
6961
  const offset = index * this.dimension * 2;
6133
- return intersectRayBounds(origin, unit, bounds.subarray(offset, offset + this.dimension), bounds.subarray(offset + this.dimension, offset + this.dimension * 2), best + getDistanceTolerance(best, best));
6962
+ return intersectRayBounds(origin, unit2, bounds.subarray(offset, offset + this.dimension), bounds.subarray(offset + this.dimension, offset + this.dimension * 2), best + getDistanceTolerance(best, best));
6134
6963
  };
6135
6964
  const stack = this.size ? [{ index: 0, distance: 0 }] : [];
6136
6965
  let complete = true;
@@ -6183,13 +7012,13 @@ var BoxIndex = class {
6183
7012
  return { result, complete, work: budget.work };
6184
7013
  }
6185
7014
  /** Broad-phase ray candidates, sorted by entry distance then original row index. */
6186
- searchRay(origin, direction, maxDistance = Infinity) {
7015
+ searchRay(origin, direction2, maxDistance = Infinity) {
6187
7016
  validateQueryPoint(origin, this.dimension);
6188
- const unit = normalizeQueryDirection(direction, this.dimension);
7017
+ const unit2 = normalizeQueryDirection(direction2, this.dimension);
6189
7018
  validateQueryDistance(maxDistance);
6190
7019
  const entry = (bounds, index) => {
6191
7020
  const start = index * this.dimension * 2;
6192
- return intersectRayBounds(origin, unit, bounds.subarray(start, start + this.dimension), bounds.subarray(start + this.dimension, start + this.dimension * 2), maxDistance);
7021
+ return intersectRayBounds(origin, unit2, bounds.subarray(start, start + this.dimension), bounds.subarray(start + this.dimension, start + this.dimension * 2), maxDistance);
6193
7022
  };
6194
7023
  const result = [];
6195
7024
  const stack = this.size ? [0] : [];
@@ -6239,16 +7068,16 @@ var QueryBudget = class {
6239
7068
  };
6240
7069
  var PointIndex = class extends BoxIndex {
6241
7070
  constructor(options) {
6242
- const { positions, dimension, leafSize } = options;
6243
- if (dimension !== 2 && dimension !== 3 || positions.length % dimension) {
7071
+ const { positions, dimension: dimension2, leafSize } = options;
7072
+ if (dimension2 !== 2 && dimension2 !== 3 || positions.length % dimension2) {
6244
7073
  throw new RangeError("Invalid point layout");
6245
7074
  }
6246
7075
  const bounds = new Float64Array(positions.length * 2);
6247
- for (let i = 0; i < positions.length / dimension; i++)
6248
- for (let axis = 0; axis < dimension; axis++) {
6249
- bounds[i * dimension * 2 + axis] = bounds[i * dimension * 2 + axis + dimension] = positions[i * dimension + axis];
7076
+ for (let i = 0; i < positions.length / dimension2; i++)
7077
+ for (let axis = 0; axis < dimension2; axis++) {
7078
+ bounds[i * dimension2 * 2 + axis] = bounds[i * dimension2 * 2 + axis + dimension2] = positions[i * dimension2 + axis];
6250
7079
  }
6251
- super({ bounds, dimension, leafSize });
7080
+ super({ bounds, dimension: dimension2, leafSize });
6252
7081
  }
6253
7082
  };
6254
7083
 
@@ -6291,20 +7120,20 @@ var TriangleBVH = class {
6291
7120
  return this.boxes.searchQuery(minimum, maximum, options);
6292
7121
  }
6293
7122
  /** Nearest accepted exact hit; application rejection never clips away later candidates. */
6294
- intersectRay(origin, direction, options = {}) {
6295
- return this.intersectRayQuery(origin, direction, { ...options, maxWork: Infinity }).result;
7123
+ intersectRay(origin, direction2, options = {}) {
7124
+ return this.intersectRayQuery(origin, direction2, { ...options, maxWork: Infinity }).result;
6296
7125
  }
6297
- intersectRayQuery(origin, direction, options = {}) {
7126
+ intersectRayQuery(origin, direction2, options = {}) {
6298
7127
  validateQueryPoint(origin, 3);
6299
- const unit = normalizeQueryDirection(direction, 3);
7128
+ const unit2 = normalizeQueryDirection(direction2, 3);
6300
7129
  let result = null;
6301
- const query = this.boxes.intersectRayQuery(origin, direction, {
7130
+ const query = this.boxes.intersectRayQuery(origin, direction2, {
6302
7131
  maxWork: options.maxWork,
6303
7132
  maxDistance: options.maxDistance,
6304
7133
  filter: options.filter,
6305
7134
  intersectItem: (index, maximum) => {
6306
7135
  const [a, b, c] = this.triangle(index);
6307
- const hit = intersectRayTriangle(origin, unit, a, b, c, {
7136
+ const hit = intersectRayTriangle(origin, unit2, a, b, c, {
6308
7137
  backfaceCulling: options.backfaceCulling,
6309
7138
  maxT: maximum
6310
7139
  });
@@ -6313,9 +7142,9 @@ var TriangleBVH = class {
6313
7142
  index,
6314
7143
  distance: hit.t,
6315
7144
  point: [
6316
- origin[0] + hit.t * unit[0],
6317
- origin[1] + hit.t * unit[1],
6318
- origin[2] + hit.t * unit[2]
7145
+ origin[0] + hit.t * unit2[0],
7146
+ origin[1] + hit.t * unit2[1],
7147
+ origin[2] + hit.t * unit2[2]
6319
7148
  ],
6320
7149
  barycentric: hit.barycentric
6321
7150
  };
@@ -6329,16 +7158,16 @@ var TriangleBVH = class {
6329
7158
  });
6330
7159
  return { ...query, result };
6331
7160
  }
6332
- nearest(point, options = {}) {
6333
- return this.nearestQuery(point, { ...options, maxWork: Infinity }).result;
7161
+ nearest(point2, options = {}) {
7162
+ return this.nearestQuery(point2, { ...options, maxWork: Infinity }).result;
6334
7163
  }
6335
- nearestQuery(point, options = {}) {
7164
+ nearestQuery(point2, options = {}) {
6336
7165
  let candidate = null;
6337
- const query = this.boxes.nearestQuery(point, {
7166
+ const query = this.boxes.nearestQuery(point2, {
6338
7167
  ...options,
6339
7168
  distanceToItem: (index) => {
6340
- const closest = getClosestPointOnTriangle(point, ...this.triangle(index));
6341
- const distance = Math.hypot(point[0] - closest[0], point[1] - closest[1], point[2] - closest[2]);
7169
+ const closest = getClosestPointOnTriangle(point2, ...this.triangle(index));
7170
+ const distance = Math.hypot(point2[0] - closest[0], point2[1] - closest[1], point2[2] - closest[2]);
6342
7171
  if (!candidate || distance < candidate.distance || distance === candidate.distance && index < candidate.index)
6343
7172
  candidate = { index, distance, point: closest };
6344
7173
  return distance;
@@ -6349,15 +7178,15 @@ var TriangleBVH = class {
6349
7178
  /** All triangle contacts with a closed sphere, sorted by original index (not distance).
6350
7179
  * Uses closest points on faces, edges and vertices. No contact manifold reduction.
6351
7180
  */
6352
- intersectSphere(center, radius, options = {}) {
7181
+ intersectSphere(center, radius2, options = {}) {
6353
7182
  validateQueryPoint(center, 3);
6354
- if (!Number.isFinite(radius) || radius < 0)
7183
+ if (!Number.isFinite(radius2) || radius2 < 0)
6355
7184
  throw new RangeError("Sphere radius must be finite and nonnegative");
6356
7185
  const minimum = [], maximum = [];
6357
7186
  for (let axis = 0; axis < 3; axis++) {
6358
- const padding = 8 * Math.max(Number.MIN_VALUE, Number.EPSILON * Math.max(Math.abs(center[axis]), radius));
6359
- minimum.push(center[axis] - radius - padding);
6360
- maximum.push(center[axis] + radius + padding);
7187
+ const padding = 8 * Math.max(Number.MIN_VALUE, Number.EPSILON * Math.max(Math.abs(center[axis]), radius2));
7188
+ minimum.push(center[axis] - radius2 - padding);
7189
+ maximum.push(center[axis] + radius2 + padding);
6361
7190
  }
6362
7191
  const hits = /* @__PURE__ */ new Map();
6363
7192
  const query = this.boxes.searchQuery(minimum, maximum, {
@@ -6365,13 +7194,13 @@ var TriangleBVH = class {
6365
7194
  filter: (index) => {
6366
7195
  if (options.filter && !options.filter(index))
6367
7196
  return false;
6368
- const point = getClosestPointOnTriangle(center, ...this.triangle(index));
6369
- const distance = Math.hypot(center[0] - point[0], center[1] - point[1], center[2] - point[2]);
6370
- if (!point.every(Number.isFinite) || !Number.isFinite(distance))
7197
+ const point2 = getClosestPointOnTriangle(center, ...this.triangle(index));
7198
+ const distance = Math.hypot(center[0] - point2[0], center[1] - point2[1], center[2] - point2[2]);
7199
+ if (!point2.every(Number.isFinite) || !Number.isFinite(distance))
6371
7200
  throw new RangeError("Sphere query arithmetic overflow");
6372
- if (distance > radius)
7201
+ if (distance > radius2)
6373
7202
  return false;
6374
- hits.set(index, { index, distance, point });
7203
+ hits.set(index, { index, distance, point: point2 });
6375
7204
  return true;
6376
7205
  }
6377
7206
  });
@@ -6398,10 +7227,10 @@ var TriangleBVH = class {
6398
7227
  /** Closed capsule overlap, with one closest pair per accepted triangle.
6399
7228
  * A straight translating sphere covers this volume, but segmentFraction is not first-impact time.
6400
7229
  */
6401
- intersectCapsule(start, end, radius, options = {}) {
6402
- if (!Number.isFinite(radius) || radius < 0)
7230
+ intersectCapsule(start, end, radius2, options = {}) {
7231
+ if (!Number.isFinite(radius2) || radius2 < 0)
6403
7232
  throw new RangeError("Capsule radius must be finite and nonnegative");
6404
- const { minimum, maximum } = segmentBounds(start, end, radius);
7233
+ const { minimum, maximum } = segmentBounds(start, end, radius2);
6405
7234
  const hits = /* @__PURE__ */ new Map();
6406
7235
  const query = this.boxes.searchQuery(minimum, maximum, {
6407
7236
  ...options,
@@ -6409,7 +7238,7 @@ var TriangleBVH = class {
6409
7238
  if (options.filter && !options.filter(index))
6410
7239
  return false;
6411
7240
  const closest = this.segmentClosest(index, start, end);
6412
- if (closest.distance > radius)
7241
+ if (closest.distance > radius2)
6413
7242
  return false;
6414
7243
  hits.set(index, closest);
6415
7244
  return true;
@@ -6435,7 +7264,7 @@ var TriangleBVH = class {
6435
7264
  return [vertex2(0), vertex2(1), vertex2(2)];
6436
7265
  }
6437
7266
  };
6438
- function segmentBounds(start, end, radius) {
7267
+ function segmentBounds(start, end, radius2) {
6439
7268
  validateQueryPoint(start, 3);
6440
7269
  validateQueryPoint(end, 3);
6441
7270
  for (let axis = 0; axis < 3; axis++)
@@ -6443,10 +7272,286 @@ function segmentBounds(start, end, radius) {
6443
7272
  throw new RangeError("Segment coordinate span overflow");
6444
7273
  const minimum = [], maximum = [];
6445
7274
  for (let axis = 0; axis < 3; axis++) {
6446
- const padding = radius === void 0 ? 0 : radius + 8 * Math.max(Number.MIN_VALUE, Number.EPSILON * Math.max(Math.abs(start[axis]), Math.abs(end[axis]), radius));
7275
+ const padding = radius2 === void 0 ? 0 : radius2 + 8 * Math.max(Number.MIN_VALUE, Number.EPSILON * Math.max(Math.abs(start[axis]), Math.abs(end[axis]), radius2));
6447
7276
  minimum.push(Math.min(start[axis], end[axis]) - padding);
6448
7277
  maximum.push(Math.max(start[axis], end[axis]) + padding);
6449
7278
  }
6450
7279
  return { minimum, maximum };
6451
7280
  }
7281
+
7282
+ // dist/utils/compose-attribute-provenance.js
7283
+ function composeAttributeProvenance(parent, child, options = {}) {
7284
+ const limit = options.maxVertices ?? 65536;
7285
+ if (!Number.isSafeInteger(limit) || limit < 0 || limit > 4294967295)
7286
+ throw new RangeError("Invalid provenance vertex limit");
7287
+ validate(parent);
7288
+ validate(child, parent.sourceVertexIndices.length / 3);
7289
+ if (child.sourceVertexIndices.length / 3 > limit)
7290
+ throw new RangeError("Provenance composition exceeded maxVertices");
7291
+ const indices = new Uint32Array(child.sourceVertexIndices.length);
7292
+ const weights = new Float64Array(indices.length);
7293
+ for (let vertex2 = 0; vertex2 < indices.length / 3; vertex2++) {
7294
+ const contributors = /* @__PURE__ */ new Map();
7295
+ for (let j = 0; j < 3; j++) {
7296
+ const weight = child.sourceVertexWeights[3 * vertex2 + j];
7297
+ if (!weight)
7298
+ continue;
7299
+ const intermediate = child.sourceVertexIndices[3 * vertex2 + j];
7300
+ for (let k = 0; k < 3; k++) {
7301
+ const w = weight * parent.sourceVertexWeights[3 * intermediate + k];
7302
+ if (!w)
7303
+ continue;
7304
+ const index = parent.sourceVertexIndices[3 * intermediate + k];
7305
+ contributors.set(index, (contributors.get(index) ?? 0) + w);
7306
+ }
7307
+ }
7308
+ if (contributors.size > 3)
7309
+ throw new RangeError("Composed vertex spans multiple source triangles");
7310
+ const sum = Array.from(contributors.values()).reduce((a, b) => a + b, 0);
7311
+ let slot = 3 * vertex2;
7312
+ for (const [index, weight] of contributors) {
7313
+ indices[slot] = index;
7314
+ weights[slot++] = weight / sum;
7315
+ }
7316
+ }
7317
+ return { sourceVertexIndices: indices, sourceVertexWeights: weights };
7318
+ }
7319
+ function validate(p, count = 4294967296) {
7320
+ if (!Number.isSafeInteger(p.sourceVertexIndices.length) || p.sourceVertexIndices.length < 0 || p.sourceVertexIndices.length % 3 || p.sourceVertexIndices.length !== p.sourceVertexWeights.length)
7321
+ throw new RangeError("Invalid provenance lengths");
7322
+ for (let i = 0; i < p.sourceVertexIndices.length; i += 3) {
7323
+ let sum = 0;
7324
+ for (let j = 0; j < 3; j++) {
7325
+ const w = p.sourceVertexWeights[i + j], index = p.sourceVertexIndices[i + j];
7326
+ if (!Number.isFinite(w) || w < 0 || w > 1 || w > 0 && (!Number.isSafeInteger(index) || index < 0 || index >= count))
7327
+ throw new RangeError("Invalid provenance contributor");
7328
+ sum += w;
7329
+ }
7330
+ if (Math.abs(sum - 1) > 1e-10)
7331
+ throw new RangeError("Provenance weights must sum to one");
7332
+ }
7333
+ }
7334
+
7335
+ // dist/utils/qualify-surface-transition.js
7336
+ function qualifySurfaceTransition(mesh, targetPositions, options = {}) {
7337
+ const from = Array.from(mesh.positions), to = Array.from(targetPositions), indices = Array.from(mesh.indices), count = from.length / 3, maxChecks = options.maxChecks ?? 1e6;
7338
+ 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)
7339
+ throw new RangeError("Invalid surface transition mesh or budget");
7340
+ let scale = 0;
7341
+ for (const positions of [from, to])
7342
+ for (let i = 0; i < indices.length; i += 3)
7343
+ for (let j = 0; j < 3; j++) {
7344
+ const a = indices[i + j] * 3, b = indices[i + (j + 1) % 3] * 3;
7345
+ scale = Math.max(scale, Math.hypot(positions[b] - positions[a], positions[b + 1] - positions[a + 1]));
7346
+ }
7347
+ const margin = options.minimumDoubleArea ?? scale * scale * 1e-12;
7348
+ if (!Number.isFinite(margin) || margin <= 0)
7349
+ throw new RangeError("Expected positive finite area margin");
7350
+ let checks = 0;
7351
+ const tick = () => {
7352
+ if (++checks > maxChecks)
7353
+ throw new RangeError("Surface qualification exceeded maxChecks");
7354
+ };
7355
+ const edges = /* @__PURE__ */ new Map(), used = new Set(indices);
7356
+ let minimum = Infinity;
7357
+ const orientation = (a, b, c, t) => {
7358
+ const edge = (v2, k) => (from[3 * v2 + k] - from[3 * a + k]) * (1 - t) + (to[3 * v2 + k] - to[3 * a + k]) * t;
7359
+ return edge(b, 0) * edge(c, 1) - edge(b, 1) * edge(c, 0);
7360
+ };
7361
+ const minimumOrientation = (a, b, c) => {
7362
+ tick();
7363
+ return quadraticMinimum((t) => orientation(a, b, c, t));
7364
+ };
7365
+ for (let i = 0; i < indices.length; i += 3) {
7366
+ const tri = indices.slice(i, i + 3);
7367
+ const area2 = minimumOrientation(tri[0], tri[1], tri[2]);
7368
+ if (area2 < margin)
7369
+ throw new RangeError("Triangle collapses or reverses during transition");
7370
+ minimum = Math.min(minimum, area2);
7371
+ for (let j = 0; j < 3; j++) {
7372
+ const a = tri[j], b = tri[(j + 1) % 3], key = a < b ? `${a}:${b}` : `${b}:${a}`, edge = edges.get(key);
7373
+ if (edge) {
7374
+ if (edge.faces !== 1 || edge.a !== b || edge.b !== a)
7375
+ throw new RangeError("Expected oriented manifold edges");
7376
+ edge.faces++;
7377
+ } else
7378
+ edges.set(key, { a, b, faces: 1 });
7379
+ }
7380
+ }
7381
+ const next = /* @__PURE__ */ new Map();
7382
+ for (const edge of edges.values())
7383
+ if (edge.faces === 1) {
7384
+ if (next.has(edge.a))
7385
+ throw new RangeError("Nonmanifold boundary");
7386
+ next.set(edge.a, edge.b);
7387
+ }
7388
+ if (!next.size || used.size !== count || used.size - edges.size + indices.length / 3 !== 1)
7389
+ throw new RangeError("Expected a triangulated disk without unused vertices");
7390
+ const start = next.keys().next().value, boundary = [];
7391
+ const visitedBoundary = /* @__PURE__ */ new Set();
7392
+ let v = start;
7393
+ do {
7394
+ if (visitedBoundary.has(v) || !next.has(v))
7395
+ throw new RangeError("Expected one boundary cycle");
7396
+ visitedBoundary.add(v);
7397
+ boundary.push(v);
7398
+ v = next.get(v);
7399
+ } while (v !== start);
7400
+ if (boundary.length !== next.size)
7401
+ throw new RangeError("Multiple boundary cycles");
7402
+ for (let i = 0; i < boundary.length; i++) {
7403
+ const a = boundary[i], b = boundary[(i + 1) % boundary.length];
7404
+ for (let j = i + 1; j < boundary.length; j++) {
7405
+ tick();
7406
+ const c = boundary[j];
7407
+ const separation = quadraticMinimum((t) => {
7408
+ 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;
7409
+ return dx * dx + dy * dy;
7410
+ });
7411
+ if (separation < margin)
7412
+ throw new RangeError("Boundary vertices meet during transition");
7413
+ }
7414
+ for (const c of boundary)
7415
+ if (c !== a && c !== b && minimumOrientation(a, b, c) < -margin * 1e-3)
7416
+ throw new RangeError("Boundary is not convex throughout transition");
7417
+ }
7418
+ const neighbors = Array.from({ length: count }, () => []);
7419
+ for (const { a, b } of edges.values()) {
7420
+ neighbors[a].push(b);
7421
+ neighbors[b].push(a);
7422
+ }
7423
+ const seen = /* @__PURE__ */ new Set([start]), queue = [start];
7424
+ for (let i = 0; i < queue.length; i++)
7425
+ for (const n of neighbors[queue[i]])
7426
+ if (!seen.has(n)) {
7427
+ seen.add(n);
7428
+ queue.push(n);
7429
+ }
7430
+ if (seen.size !== count)
7431
+ throw new RangeError("Disconnected surface mesh");
7432
+ return {
7433
+ scope: "convex-xy-disk-linear",
7434
+ minimumProjectedDoubleArea: minimum,
7435
+ boundary: new Uint32Array(boundary)
7436
+ };
7437
+ }
7438
+ function quadraticMinimum(value) {
7439
+ const f = value(0), g = value(1), h = value(0.5), a = 2 * (f + g - 2 * h), b = g - f - a;
7440
+ if (![f, g, h, a, b].every(Number.isFinite))
7441
+ throw new RangeError("Nonfinite surface orientation polynomial");
7442
+ const t = a > 0 ? -b / (2 * a) : -1;
7443
+ const result = Math.min(f, g, t > 0 && t < 1 ? value(t) : Infinity);
7444
+ if (!Number.isFinite(result))
7445
+ throw new RangeError("Nonfinite surface orientation");
7446
+ return result;
7447
+ }
7448
+
7449
+ // dist/utils/project-bounds.js
7450
+ function projectBounds(sourceBounds, options) {
7451
+ const [minimum, maximum] = sourceBounds;
7452
+ const size = minimum.length;
7453
+ const { transform, targetSize = size, subdivisions = 8, maxSamples = 262144, lipschitz } = options;
7454
+ if (size !== 2 && size !== 3 || maximum.length !== size || targetSize !== 2 && targetSize !== 3) {
7455
+ throw new RangeError("Bounds and target dimension must be 2 or 3");
7456
+ }
7457
+ if (!Number.isSafeInteger(subdivisions) || subdivisions < 1 || !Number.isSafeInteger(maxSamples) || maxSamples < 1) {
7458
+ throw new RangeError("Subdivision and sample budgets must be positive safe integers");
7459
+ }
7460
+ if (lipschitz && (lipschitz.length !== targetSize || !Array.from(lipschitz).every((value) => Number.isFinite(value) && value >= 0))) {
7461
+ throw new RangeError("Lipschitz constants must be finite, nonnegative and match target size");
7462
+ }
7463
+ const widths = [];
7464
+ const counts = [];
7465
+ let count = 1;
7466
+ for (let axis = 0; axis < size; axis++) {
7467
+ const width = maximum[axis] - minimum[axis];
7468
+ if (!Number.isFinite(minimum[axis]) || !Number.isFinite(maximum[axis]) || !Number.isFinite(width) || width < 0) {
7469
+ throw new RangeError("Source bounds must have finite ordered coordinates and extents");
7470
+ }
7471
+ widths.push(width);
7472
+ counts.push(width === 0 ? 1 : subdivisions + 1);
7473
+ count *= counts[axis];
7474
+ if (!Number.isSafeInteger(count) || count > maxSamples) {
7475
+ throw new RangeError("Projected bounds exceed the sample budget");
7476
+ }
7477
+ }
7478
+ const lower = new Array(targetSize).fill(Infinity);
7479
+ const upper = new Array(targetSize).fill(-Infinity);
7480
+ for (let index = 0; index < count; index++) {
7481
+ let remaining = index;
7482
+ const source = [];
7483
+ for (let axis = 0; axis < size; axis++) {
7484
+ const step = remaining % counts[axis];
7485
+ remaining = Math.floor(remaining / counts[axis]);
7486
+ source.push(step === 0 ? minimum[axis] : step === subdivisions ? maximum[axis] : minimum[axis] + widths[axis] * (step / subdivisions));
7487
+ }
7488
+ const projected = transform(source);
7489
+ if (!projected || projected.length < targetSize) {
7490
+ return { status: "invalid", bounds: null, sampleCount: index + 1 };
7491
+ }
7492
+ for (let axis = 0; axis < targetSize; axis++) {
7493
+ if (!Number.isFinite(projected[axis]))
7494
+ return { status: "invalid", bounds: null, sampleCount: index + 1 };
7495
+ lower[axis] = Math.min(lower[axis], projected[axis]);
7496
+ upper[axis] = Math.max(upper[axis], projected[axis]);
7497
+ }
7498
+ }
7499
+ if (lipschitz) {
7500
+ const radius2 = Math.hypot(...widths.map((width, axis) => width / subdivisions / 2 + 4 * Number.EPSILON * Math.max(Math.abs(minimum[axis]), Math.abs(maximum[axis]))));
7501
+ for (let axis = 0; axis < targetSize; axis++) {
7502
+ const displacement = lipschitz[axis] * radius2;
7503
+ const roundoff = 8 * Number.EPSILON * Math.max(1, Math.abs(lower[axis]), Math.abs(upper[axis]), displacement);
7504
+ lower[axis] -= displacement + roundoff;
7505
+ upper[axis] += displacement + roundoff;
7506
+ if (!Number.isFinite(lower[axis]) || !Number.isFinite(upper[axis])) {
7507
+ return { status: "invalid", bounds: null, sampleCount: count };
7508
+ }
7509
+ }
7510
+ }
7511
+ return {
7512
+ status: lipschitz ? "conservative" : "sampled",
7513
+ bounds: [lower, upper],
7514
+ sampleCount: count
7515
+ };
7516
+ }
7517
+
7518
+ // dist/utils/project-texture-coordinates.js
7519
+ function projectTextureCoordinates(positions, options) {
7520
+ const { transform, bounds, size = 3, origin = "top-left" } = options;
7521
+ if (size !== 2 && size !== 3)
7522
+ throw new RangeError("Source size must be 2 or 3");
7523
+ if (!Number.isSafeInteger(positions.length) || positions.length < 0 || positions.length % size) {
7524
+ throw new RangeError("Positions must contain complete packed vertices");
7525
+ }
7526
+ if (origin !== "top-left" && origin !== "bottom-left") {
7527
+ throw new RangeError("Invalid texture origin");
7528
+ }
7529
+ if (bounds.length !== 4 || !bounds.every(Number.isFinite)) {
7530
+ throw new RangeError("Image bounds must contain four finite values");
7531
+ }
7532
+ const [left, bottom, right, top] = bounds;
7533
+ const width = right - left;
7534
+ const height = top - bottom;
7535
+ if (!(width > 0) || !(height > 0) || !Number.isFinite(width) || !Number.isFinite(height)) {
7536
+ throw new RangeError("Image bounds must have finite positive extents");
7537
+ }
7538
+ const count = positions.length / size;
7539
+ const result = new Float64Array(count * 2);
7540
+ for (let index = 0; index < count; index++) {
7541
+ const source = Array.from({ length: size }, (_, axis) => positions[index * size + axis]);
7542
+ if (!source.every(Number.isFinite))
7543
+ throw new RangeError(`Invalid source vertex ${index}`);
7544
+ const projected = transform(source);
7545
+ if (!projected || projected.length < 2 || !Number.isFinite(projected[0]) || !Number.isFinite(projected[1])) {
7546
+ throw new RangeError(`Invalid projected vertex ${index}`);
7547
+ }
7548
+ const u = (projected[0] - left) / width;
7549
+ const v = origin === "top-left" ? (top - projected[1]) / height : (projected[1] - bottom) / height;
7550
+ if (!Number.isFinite(u) || !Number.isFinite(v))
7551
+ throw new RangeError(`Invalid UV at vertex ${index}`);
7552
+ result[index * 2] = u;
7553
+ result[index * 2 + 1] = v;
7554
+ }
7555
+ return result;
7556
+ }
6452
7557
  //# sourceMappingURL=index.cjs.map