@math.gl/geometry 5.0.0-beta.4 → 5.0.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/README.md +58 -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 +917 -514
  30. package/dist/culling/index.cjs.map +3 -3
  31. package/dist/culling/index.d.ts +5 -1
  32. package/dist/culling/index.d.ts.map +1 -1
  33. package/dist/culling/index.js +3 -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/curves/adaptive-sampling.d.ts +16 -0
  48. package/dist/curves/adaptive-sampling.d.ts.map +1 -0
  49. package/dist/curves/adaptive-sampling.js +59 -0
  50. package/dist/curves/adaptive-sampling.js.map +1 -0
  51. package/dist/curves/index.d.ts +4 -0
  52. package/dist/curves/index.d.ts.map +1 -1
  53. package/dist/curves/index.js +2 -0
  54. package/dist/curves/index.js.map +1 -1
  55. package/dist/curves/parallel-transport.d.ts +12 -0
  56. package/dist/curves/parallel-transport.d.ts.map +1 -0
  57. package/dist/curves/parallel-transport.js +83 -0
  58. package/dist/curves/parallel-transport.js.map +1 -0
  59. package/dist/index.cjs +1225 -699
  60. package/dist/index.cjs.map +3 -3
  61. package/dist/index.d.ts +6 -1
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.js +3 -0
  64. package/dist/index.js.map +1 -1
  65. package/dist/lighting/index.cjs +175 -0
  66. package/dist/lighting/index.cjs.map +6 -0
  67. package/dist/lighting/index.d.ts +4 -0
  68. package/dist/lighting/index.d.ts.map +1 -0
  69. package/dist/lighting/index.js +5 -0
  70. package/dist/lighting/index.js.map +1 -0
  71. package/dist/lighting/lighting-types.d.ts +16 -0
  72. package/dist/lighting/lighting-types.d.ts.map +1 -0
  73. package/dist/lighting/lighting-types.js +5 -0
  74. package/dist/lighting/lighting-types.js.map +1 -0
  75. package/dist/lighting/photometry.d.ts +36 -0
  76. package/dist/lighting/photometry.d.ts.map +1 -0
  77. package/dist/lighting/photometry.js +181 -0
  78. package/dist/lighting/photometry.js.map +1 -0
  79. package/package.json +15 -3
  80. package/src/color/color-lut-types.ts +19 -0
  81. package/src/color/index.ts +6 -0
  82. package/src/color/sample-lut.ts +175 -0
  83. package/src/culling/bounds.ts +152 -0
  84. package/src/culling/frustum-planes.ts +41 -0
  85. package/src/culling/geometric-queries.ts +299 -0
  86. package/src/culling/index.ts +37 -1
  87. package/src/culling/lib/bounding-volumes/axis-aligned-bounding-box.ts +26 -8
  88. package/src/culling/lib/culling-volume.ts +9 -1
  89. package/src/culling/lib/ray.ts +21 -0
  90. package/src/curves/adaptive-sampling.ts +85 -0
  91. package/src/curves/index.ts +4 -0
  92. package/src/curves/parallel-transport.ts +104 -0
  93. package/src/index.ts +35 -0
  94. package/src/lighting/index.ts +10 -0
  95. package/src/lighting/lighting-types.ts +20 -0
  96. package/src/lighting/photometry.ts +264 -0
package/dist/index.cjs CHANGED
@@ -64,36 +64,58 @@ __export(index_exports, {
64
64
  TruncatedConeGeometry: () => TruncatedConeGeometry,
65
65
  _PerspectiveFrustum: () => PerspectiveFrustum,
66
66
  _PerspectiveOffCenterFrustum: () => PerspectiveOffCenterFrustum,
67
+ boundsContainsBounds: () => boundsContainsBounds,
68
+ boundsContainsPoint: () => boundsContainsPoint,
69
+ boundsIntersect: () => boundsIntersect,
70
+ boundsIntersectSphere: () => boundsIntersectSphere,
71
+ clampPointToBounds: () => clampPointToBounds,
67
72
  clipPolygon: () => clipPolygon,
68
73
  clipPolyline: () => clipPolyline,
69
74
  clipTriangleMesh: () => clipTriangleMesh,
70
75
  composeAttributeProvenance: () => composeAttributeProvenance,
71
76
  compressTextureCoordinates: () => compressTextureCoordinates,
72
77
  computeEigenDecomposition: () => computeEigenDecomposition,
78
+ computeParallelTransportFrames: () => computeParallelTransportFrames,
73
79
  computeVertexNormals: () => computeVertexNormals,
74
80
  concatTypedArrays: () => concatTypedArrays,
81
+ createEmptyBounds: () => createEmptyBounds,
75
82
  cutPolygonByGrid: () => cutPolygonByGrid,
76
83
  cutPolygonByMercatorBounds: () => cutPolygonByMercatorBounds,
77
84
  cutPolylineByGrid: () => cutPolylineByGrid,
78
85
  cutPolylineByMercatorBounds: () => cutPolylineByMercatorBounds,
79
86
  decodeRGB565: () => decodeRGB565,
80
87
  decompressTextureCoordinates: () => decompressTextureCoordinates,
88
+ distanceToRay: () => distanceToRay,
81
89
  earcut: () => earcut,
82
90
  emod: () => emod,
83
91
  encodeRGB565: () => encodeRGB565,
92
+ expandBounds: () => expandBounds,
93
+ expandBoundsByPoint: () => expandBoundsByPoint,
94
+ extractFrustumPlanes: () => extractFrustumPlanes,
84
95
  forEachSegmentInPolygon: () => forEachSegmentInPolygon,
96
+ getClosestPointOnRay: () => getClosestPointOnRay,
85
97
  getClosestPointOnTriangle: () => getClosestPointOnTriangle,
86
98
  getClosestPointsOnSegments: () => getClosestPointsOnSegments,
99
+ getClosestPointsRaySegment: () => getClosestPointsRaySegment,
87
100
  getClosestPointsSegmentTriangle: () => getClosestPointsSegmentTriangle,
88
101
  getDegenerateTriangles: () => getDegenerateTriangles,
89
102
  getOrientedBoundingBoxQuaternion: () => getOrientedBoundingBoxQuaternion,
90
103
  getPolygonSignedArea: () => getPolygonSignedArea,
91
104
  getPolygonWindingDirection: () => getPolygonWindingDirection,
105
+ getRayPoint: () => getRayPoint,
106
+ getTriangleArea: () => getTriangleArea,
107
+ getTriangleBarycentric: () => getTriangleBarycentric,
108
+ getTriangleNormal: () => getTriangleNormal,
92
109
  interpolatePackedAttributes: () => interpolatePackedAttributes,
110
+ interpolateTriangleAttribute: () => interpolateTriangleAttribute,
111
+ intersectBounds: () => intersectBounds,
93
112
  intersectOrientedBoxes2D: () => intersectOrientedBoxes2D,
113
+ intersectPlaneSegment: () => intersectPlaneSegment,
94
114
  intersectRayBounds: () => intersectRayBounds,
95
115
  intersectRayTriangle: () => intersectRayTriangle,
116
+ isEmptyBounds: () => isEmptyBounds,
96
117
  isGeometry: () => isGeometry,
118
+ isTriangleFrontFacing: () => isTriangleFrontFacing,
97
119
  makeAttributeIterator: () => makeAttributeIterator,
98
120
  makeAxisAlignedBoundingBoxFromPoints: () => makeAxisAlignedBoundingBoxFromPoints,
99
121
  makeBoundingSphereFromPoints: () => makeBoundingSphereFromPoints,
@@ -115,9 +137,15 @@ __export(index_exports, {
115
137
  octPackFloat: () => octPackFloat,
116
138
  octUnpack: () => octUnpack,
117
139
  qualifySurfaceTransition: () => qualifySurfaceTransition,
140
+ sampleCurveAdaptive: () => sampleCurveAdaptive,
141
+ spheresIntersect: () => spheresIntersect,
118
142
  subdividePolyline: () => subdividePolyline,
119
143
  subdivideTriangleMesh: () => subdivideTriangleMesh,
120
144
  transformGeometry: () => transformGeometry,
145
+ transformRay: () => transformRay,
146
+ triangleContainsPoint: () => triangleContainsPoint,
147
+ triangleIntersectsBounds: () => triangleIntersectsBounds,
148
+ unionBounds: () => unionBounds,
121
149
  unpackIndexedGeometry: () => unpackIndexedGeometry,
122
150
  validateQueryDistance: () => validateQueryDistance,
123
151
  validateQueryPoint: () => validateQueryPoint,
@@ -265,10 +293,10 @@ var HingeTree = class {
265
293
  * Output may alias the inputs: angles and root transform are snapshotted first.
266
294
  * Finite inputs that overflow during composition throw; output may then be partial.
267
295
  */
268
- evaluate(angles, output = new Float64Array(this.panelCount * 16), rootTransform) {
296
+ evaluate(angles, output2 = new Float64Array(this.panelCount * 16), rootTransform) {
269
297
  if (angles.length !== this.panelCount)
270
298
  throw new RangeError("Expected one angle per panel");
271
- if (!(output instanceof Float64Array) || output.length !== this.panelCount * 16) {
299
+ if (!(output2 instanceof Float64Array) || output2.length !== this.panelCount * 16) {
272
300
  throw new RangeError("Expected 16 Float64 values per panel");
273
301
  }
274
302
  for (let i = 0; i < angles.length; i++) {
@@ -293,16 +321,16 @@ var HingeTree = class {
293
321
  this.world.copy(this.root);
294
322
  else {
295
323
  for (let i = 0; i < 16; i++)
296
- this.world[i] = output[joint.parent * 16 + i];
324
+ this.world[i] = output2[joint.parent * 16 + i];
297
325
  }
298
326
  this.world.multiplyRight(this.local);
299
327
  for (let i = 0; i < 16; i++) {
300
328
  if (!Number.isFinite(this.world[i]))
301
329
  throw new RangeError("Hinge transform overflow");
302
- output[index * 16 + i] = this.world[i];
330
+ output2[index * 16 + i] = this.world[i];
303
331
  }
304
332
  }
305
- return output;
333
+ return output2;
306
334
  }
307
335
  };
308
336
  function copyVector(vector) {
@@ -323,10 +351,10 @@ function validateRigidTransform(matrix) {
323
351
  throw new RangeError("Expected an affine rigid transform");
324
352
  for (let a = 0; a < 3; a++) {
325
353
  for (let b = a; b < 3; b++) {
326
- let dot4 = 0;
354
+ let dot6 = 0;
327
355
  for (let row = 0; row < 3; row++)
328
- dot4 += matrix[a * 4 + row] * matrix[b * 4 + row];
329
- if (Math.abs(dot4 - (a === b ? 1 : 0)) > tolerance) {
356
+ dot6 += matrix[a * 4 + row] * matrix[b * 4 + row];
357
+ if (Math.abs(dot6 - (a === b ? 1 : 0)) > tolerance) {
330
358
  throw new RangeError("Rigid transforms cannot scale or shear");
331
359
  }
332
360
  }
@@ -482,9 +510,9 @@ var CapsuleGeometry = class extends Geometry {
482
510
  const deltaRadius = radiusTop - radiusBottom;
483
511
  if (Math.abs(deltaRadius) >= height) {
484
512
  const topWins = radiusTop >= radiusBottom;
485
- const radius = topWins ? radiusTop : radiusBottom;
513
+ const radius2 = topWins ? radiusTop : radiusBottom;
486
514
  const center = topWins ? height / 2 : -height / 2;
487
- addSphereRings(rings, center, radius, ncap * 2);
515
+ addSphereRings(rings, center, radius2, ncap * 2);
488
516
  } else {
489
517
  const sinSlope = deltaRadius / height;
490
518
  const radialNormal = Math.sqrt(1 - sinSlope * sinSlope);
@@ -503,11 +531,11 @@ var CapsuleGeometry = class extends Geometry {
503
531
  }
504
532
  for (let i = 1; i <= nvertical; i++) {
505
533
  const t = i / nvertical;
506
- const radius = radiusBottom + deltaRadius * t;
534
+ const radius2 = radiusBottom + deltaRadius * t;
507
535
  const center = bottomCenter + height * t;
508
536
  rings.push({
509
- radius: radius * radialNormal,
510
- y: center + radius * sideNormalY,
537
+ radius: radius2 * radialNormal,
538
+ y: center + radius2 * sideNormalY,
511
539
  normalRadius: radialNormal,
512
540
  normalY: sideNormalY
513
541
  });
@@ -537,14 +565,14 @@ var CapsuleGeometry = class extends Geometry {
537
565
  });
538
566
  }
539
567
  };
540
- function addSphereRings(rings, center, radius, segments) {
568
+ function addSphereRings(rings, center, radius2, segments) {
541
569
  for (let i = 0; i <= segments; i++) {
542
570
  const angle = -Math.PI / 2 + i / segments * Math.PI;
543
571
  const normalRadius = Math.cos(angle);
544
572
  const normalY = Math.sin(angle);
545
573
  rings.push({
546
- radius: radius * normalRadius,
547
- y: center + radius * normalY,
574
+ radius: radius2 * normalRadius,
575
+ y: center + radius2 * normalY,
548
576
  normalRadius,
549
577
  normalY
550
578
  });
@@ -569,16 +597,16 @@ var TruncatedConeGeometry = class extends Geometry {
569
597
  const stride = nradial + 1;
570
598
  const slope = (bottomRadius - topRadius) / height;
571
599
  const normalScale = 1 / Math.hypot(1, slope);
572
- const addRing = (radius, y, normalRadius, normalY, v) => {
600
+ const addRing = (radius2, y, normalRadius, normalY, v) => {
573
601
  const ring = positions.length / 3 / stride;
574
602
  for (let radial2 = 0; radial2 <= nradial; radial2++) {
575
603
  const u = radial2 / nradial;
576
604
  const angle = u * Math.PI * 2;
577
605
  const sin = Math.sin(angle);
578
606
  const cos = Math.cos(angle);
579
- const point = orient([sin * radius, y, cos * radius], verticalAxis);
607
+ const point2 = orient([sin * radius2, y, cos * radius2], verticalAxis);
580
608
  const normal = orient([sin * normalRadius, normalY, cos * normalRadius], verticalAxis);
581
- positions.push(...point);
609
+ positions.push(...point2);
582
610
  normals.push(...normal);
583
611
  texCoords.push(u, v);
584
612
  }
@@ -602,8 +630,8 @@ var TruncatedConeGeometry = class extends Geometry {
602
630
  }
603
631
  for (let vertical = 0; vertical <= nvertical; vertical++) {
604
632
  const v = vertical / nvertical;
605
- const radius = bottomRadius + (topRadius - bottomRadius) * v;
606
- const ring = addRing(radius, (v - 0.5) * height, normalScale, slope * normalScale, v);
633
+ const radius2 = bottomRadius + (topRadius - bottomRadius) * v;
634
+ const ring = addRing(radius2, (v - 0.5) * height, normalScale, slope * normalScale, v);
607
635
  if (previous !== void 0 && !(bottomCap && vertical === 0))
608
636
  connect(previous, ring);
609
637
  previous = ring;
@@ -655,8 +683,8 @@ var CylinderGeometry = class extends TruncatedConeGeometry {
655
683
  };
656
684
  var ConeGeometry = class extends TruncatedConeGeometry {
657
685
  constructor(props = {}) {
658
- const { radius = 0.5, topCap = false, bottomCap = true } = props;
659
- super({ ...props, topRadius: 0, bottomRadius: radius, topCap, bottomCap });
686
+ const { radius: radius2 = 0.5, topCap = false, bottomCap = true } = props;
687
+ super({ ...props, topRadius: 0, bottomRadius: radius2, topCap, bottomCap });
660
688
  }
661
689
  };
662
690
 
@@ -709,8 +737,8 @@ var PlaneGeometry = class extends Geometry {
709
737
  // dist/geometries/sphere-geometry.js
710
738
  var SphereGeometry = class extends Geometry {
711
739
  constructor(props = {}) {
712
- const { radius = 0.5, nlat = 10, nlong = 10 } = props;
713
- assertPositive(radius, "radius");
740
+ const { radius: radius2 = 0.5, nlat = 10, nlong = 10 } = props;
741
+ assertPositive(radius2, "radius");
714
742
  assertSegments(nlat, "nlat", 2);
715
743
  assertSegments(nlong, "nlong", 3);
716
744
  const rings = [];
@@ -718,7 +746,7 @@ var SphereGeometry = class extends Geometry {
718
746
  const angle = -Math.PI / 2 + latitude / nlat * Math.PI;
719
747
  const normalRadius = Math.cos(angle);
720
748
  const normalY = Math.sin(angle);
721
- rings.push({ radius: radius * normalRadius, y: radius * normalY, normalRadius, normalY });
749
+ rings.push({ radius: radius2 * normalRadius, y: radius2 * normalY, normalRadius, normalY });
722
750
  }
723
751
  const mesh = makeSurfaceOfRevolution(rings, nlong);
724
752
  super({
@@ -738,8 +766,8 @@ var SphereGeometry = class extends Geometry {
738
766
  // dist/geometries/ico-sphere-geometry.js
739
767
  var IcoSphereGeometry = class extends Geometry {
740
768
  constructor(props = {}) {
741
- const { radius = 0.5, iterations = 0 } = props;
742
- assertPositive(radius, "radius");
769
+ const { radius: radius2 = 0.5, iterations = 0 } = props;
770
+ assertPositive(radius2, "radius");
743
771
  assertSegments(iterations, "iterations", 0);
744
772
  if (iterations > 8)
745
773
  throw new Error("iterations must be <= 8");
@@ -795,7 +823,7 @@ var IcoSphereGeometry = class extends Geometry {
795
823
  const texCoords = [];
796
824
  for (const face of faces2) {
797
825
  for (const normal of face) {
798
- positions.push(normal[0] * radius, normal[1] * radius, normal[2] * radius);
826
+ positions.push(normal[0] * radius2, normal[1] * radius2, normal[2] * radius2);
799
827
  normals.push(...normal);
800
828
  texCoords.push(0.5 + Math.atan2(normal[0], normal[2]) / (2 * Math.PI), 0.5 - Math.asin(normal[1]) / Math.PI);
801
829
  }
@@ -819,12 +847,12 @@ function normalize(vector) {
819
847
 
820
848
  // dist/geometries/primitive-mesh-builder.js
821
849
  var FULL_CIRCLE = Math.PI * 2;
822
- function radial(angle, direction = 1) {
823
- return [Math.cos(angle) * direction, 0, -Math.sin(angle) * direction];
850
+ function radial(angle, direction2 = 1) {
851
+ return [Math.cos(angle) * direction2, 0, -Math.sin(angle) * direction2];
824
852
  }
825
- function vertex(radius, height, angle, normal, textureCoordinates) {
853
+ function vertex(radius2, height, angle, normal, textureCoordinates) {
826
854
  return {
827
- position: [radius * Math.cos(angle), height, -radius * Math.sin(angle)],
855
+ position: [radius2 * Math.cos(angle), height, -radius2 * Math.sin(angle)],
828
856
  normal,
829
857
  textureCoordinates: textureCoordinates ?? [(Math.cos(angle) + 1) / 2, (Math.sin(angle) + 1) / 2]
830
858
  };
@@ -853,12 +881,12 @@ var PrimitiveMeshBuilder = class {
853
881
  addTriangle(first, second, third, indices) {
854
882
  const firstEdge = second.position.map((value, index) => value - first.position[index]);
855
883
  const secondEdge = third.position.map((value, index) => value - first.position[index]);
856
- const cross4 = [
884
+ const cross6 = [
857
885
  firstEdge[1] * secondEdge[2] - firstEdge[2] * secondEdge[1],
858
886
  firstEdge[2] * secondEdge[0] - firstEdge[0] * secondEdge[2],
859
887
  firstEdge[0] * secondEdge[1] - firstEdge[1] * secondEdge[0]
860
888
  ];
861
- const orientation = cross4.reduce((sum, value, index) => sum + value * (first.normal[index] + second.normal[index] + third.normal[index]), 0);
889
+ const orientation = cross6.reduce((sum, value, index) => sum + value * (first.normal[index] + second.normal[index] + third.normal[index]), 0);
862
890
  this.indices.push(...orientation < 0 ? [indices[0], indices[2], indices[1]] : indices);
863
891
  }
864
892
  triangle(first, second, third) {
@@ -891,8 +919,8 @@ var PrimitiveMeshBuilder = class {
891
919
  // dist/geometries/prism-geometry.js
892
920
  var PrismGeometry = class extends Geometry {
893
921
  constructor(props = {}) {
894
- const { radius = 1, height = 1, sides = 6, startAngle = 0 } = props;
895
- assertPositive(radius, "radius");
922
+ const { radius: radius2 = 1, height = 1, sides = 6, startAngle = 0 } = props;
923
+ assertPositive(radius2, "radius");
896
924
  assertPositive(height, "height");
897
925
  validateArc(sides, startAngle, FULL_CIRCLE);
898
926
  const mesh = new PrimitiveMeshBuilder();
@@ -901,15 +929,15 @@ var PrismGeometry = class extends Geometry {
901
929
  const secondAngle = startAngle + (segment + 1) * FULL_CIRCLE / sides;
902
930
  const normal = radial((firstAngle + secondAngle) / 2);
903
931
  const secondCornerAngle = segment === sides - 1 ? startAngle : secondAngle;
904
- 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]));
905
- for (const direction of [-1, 1]) {
906
- const capNormal = [0, direction, 0];
932
+ 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]));
933
+ for (const direction2 of [-1, 1]) {
934
+ const capNormal = [0, direction2, 0];
907
935
  const center = {
908
- position: [0, direction * height / 2, 0],
936
+ position: [0, direction2 * height / 2, 0],
909
937
  normal: capNormal,
910
938
  textureCoordinates: [0.5, 0.5]
911
939
  };
912
- mesh.triangle(center, vertex(radius, direction * height / 2, firstAngle, capNormal), vertex(radius, direction * height / 2, secondCornerAngle, capNormal));
940
+ mesh.triangle(center, vertex(radius2, direction2 * height / 2, firstAngle, capNormal), vertex(radius2, direction2 * height / 2, secondCornerAngle, capNormal));
913
941
  }
914
942
  }
915
943
  super(mesh.getProps(props));
@@ -930,39 +958,39 @@ var RingGeometry = class extends Geometry {
930
958
  for (let segment = 0; segment < segments; segment++) {
931
959
  const firstAngle = startAngle + segment * sweepAngle / segments;
932
960
  const secondAngle = segment === segments - 1 ? sweepAngle === FULL_CIRCLE ? startAngle : startAngle + sweepAngle : startAngle + (segment + 1) * sweepAngle / segments;
933
- const makeCapVertex = (radius, height2, angle, normal) => vertex(radius, height2, angle, normal, [
934
- (radius * Math.cos(angle) / outerRadius + 1) / 2,
935
- (radius * Math.sin(angle) / outerRadius + 1) / 2
961
+ const makeCapVertex = (radius2, height2, angle, normal) => vertex(radius2, height2, angle, normal, [
962
+ (radius2 * Math.cos(angle) / outerRadius + 1) / 2,
963
+ (radius2 * Math.sin(angle) / outerRadius + 1) / 2
936
964
  ]);
937
- for (const direction of [-1, 1]) {
938
- const normal = [0, direction, 0];
939
- 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));
965
+ for (const direction2 of [-1, 1]) {
966
+ const normal = [0, direction2, 0];
967
+ 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));
940
968
  }
941
- for (const [radius, direction] of [
969
+ for (const [radius2, direction2] of [
942
970
  [innerRadius, -1],
943
971
  [outerRadius, 1]
944
972
  ]) {
945
- mesh.quad(vertex(radius, -height / 2, firstAngle, radial(firstAngle, direction), [
973
+ mesh.quad(vertex(radius2, -height / 2, firstAngle, radial(firstAngle, direction2), [
946
974
  segment / segments,
947
975
  0
948
- ]), vertex(radius, height / 2, firstAngle, radial(firstAngle, direction), [
976
+ ]), vertex(radius2, height / 2, firstAngle, radial(firstAngle, direction2), [
949
977
  segment / segments,
950
978
  1
951
- ]), vertex(radius, height / 2, secondAngle, radial(secondAngle, direction), [
979
+ ]), vertex(radius2, height / 2, secondAngle, radial(secondAngle, direction2), [
952
980
  (segment + 1) / segments,
953
981
  1
954
- ]), vertex(radius, -height / 2, secondAngle, radial(secondAngle, direction), [
982
+ ]), vertex(radius2, -height / 2, secondAngle, radial(secondAngle, direction2), [
955
983
  (segment + 1) / segments,
956
984
  0
957
985
  ]));
958
986
  }
959
987
  }
960
988
  if (sweepAngle < FULL_CIRCLE) {
961
- for (const [angle, direction] of [
989
+ for (const [angle, direction2] of [
962
990
  [startAngle, -1],
963
991
  [startAngle + sweepAngle, 1]
964
992
  ]) {
965
- const normal = [-Math.sin(angle) * direction, 0, -Math.cos(angle) * direction];
993
+ const normal = [-Math.sin(angle) * direction2, 0, -Math.cos(angle) * direction2];
966
994
  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]));
967
995
  }
968
996
  }
@@ -1074,8 +1102,8 @@ var TorusGeometry = class extends ParametricGeometry {
1074
1102
  periodicU: arc === Math.PI * 2,
1075
1103
  periodicV: true,
1076
1104
  sample: (u, v) => {
1077
- const theta = startAngle + u * arc, phi = v * Math.PI * 2, radius = majorRadius + minorRadius * Math.cos(phi);
1078
- return [radius * Math.cos(theta), minorRadius * Math.sin(phi), -radius * Math.sin(theta)];
1105
+ const theta = startAngle + u * arc, phi = v * Math.PI * 2, radius2 = majorRadius + minorRadius * Math.cos(phi);
1106
+ return [radius2 * Math.cos(theta), minorRadius * Math.sin(phi), -radius2 * Math.sin(theta)];
1079
1107
  },
1080
1108
  normal: (u, v) => [
1081
1109
  Math.cos(v * Math.PI * 2) * Math.cos(startAngle + u * arc),
@@ -1089,25 +1117,25 @@ var TorusGeometry = class extends ParametricGeometry {
1089
1117
  const normals = Array.from(this.attributes["NORMAL"].value);
1090
1118
  const textureCoordinates = Array.from(this.attributes["TEXCOORD_0"].value);
1091
1119
  const indices = Array.from(this.indices.value);
1092
- for (const [angle, direction] of [
1120
+ for (const [angle, direction2] of [
1093
1121
  [startAngle, -1],
1094
1122
  [startAngle + arc, 1]
1095
1123
  ]) {
1096
- const normal = [-Math.sin(angle) * direction, 0, -Math.cos(angle) * direction];
1124
+ const normal = [-Math.sin(angle) * direction2, 0, -Math.cos(angle) * direction2];
1097
1125
  const centerIndex = positions.length / 3;
1098
1126
  positions.push(majorRadius * Math.cos(angle), 0, -majorRadius * Math.sin(angle));
1099
1127
  normals.push(...normal);
1100
1128
  textureCoordinates.push(0.5, 0.5);
1101
1129
  for (let minorSegment = 0; minorSegment <= minorSegments; minorSegment++) {
1102
1130
  const tubeAngle = minorSegment % minorSegments * Math.PI * 2 / minorSegments;
1103
- const boundaryOffset = (minorSegment * (majorSegments + 1) + (direction < 0 ? 0 : majorSegments)) * 3;
1131
+ const boundaryOffset = (minorSegment * (majorSegments + 1) + (direction2 < 0 ? 0 : majorSegments)) * 3;
1104
1132
  positions.push(...surfacePositions.slice(boundaryOffset, boundaryOffset + 3));
1105
1133
  normals.push(...normal);
1106
1134
  textureCoordinates.push((Math.cos(tubeAngle) + 1) / 2, (Math.sin(tubeAngle) + 1) / 2);
1107
1135
  if (minorSegment < minorSegments) {
1108
1136
  const firstIndex = centerIndex + minorSegment + 1;
1109
1137
  const secondIndex = firstIndex + 1;
1110
- indices.push(centerIndex, ...direction > 0 ? [secondIndex, firstIndex] : [firstIndex, secondIndex]);
1138
+ indices.push(centerIndex, ...direction2 > 0 ? [secondIndex, firstIndex] : [firstIndex, secondIndex]);
1111
1139
  }
1112
1140
  }
1113
1141
  }
@@ -1162,8 +1190,8 @@ var LatheGeometry = class extends ParametricGeometry {
1162
1190
  vSegments: profile.length - 1,
1163
1191
  periodicU: phiLength === Math.PI * 2,
1164
1192
  sample: (u, v) => {
1165
- 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;
1166
- return [radius * Math.cos(theta), height, -radius * Math.sin(theta)];
1193
+ 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;
1194
+ return [radius2 * Math.cos(theta), height, -radius2 * Math.sin(theta)];
1167
1195
  },
1168
1196
  normal: (u, v) => {
1169
1197
  const { i, t } = section(v), n = profileNormals[i].map((value, axis) => value * (1 - t) + profileNormals[i + 1][axis] * t), theta = phiStart + u * phiLength;
@@ -1682,26 +1710,26 @@ function transformGeometry(geometry, matrix) {
1682
1710
  const positions = new Float64Array(mesh.count * 3);
1683
1711
  const source = mesh.attributes[mesh.position].value;
1684
1712
  for (let i = 0; i < mesh.count; i++) {
1685
- const point = transform.transformAsPoint([source[i * 3], source[i * 3 + 1], source[i * 3 + 2]]);
1686
- positions.set(point, i * 3);
1713
+ const point2 = transform.transformAsPoint([source[i * 3], source[i * 3 + 1], source[i * 3 + 2]]);
1714
+ positions.set(point2, i * 3);
1687
1715
  }
1688
1716
  attributes[mesh.position] = { size: 3, value: positions };
1689
1717
  if (normalName) {
1690
1718
  const input = mesh.attributes[normalName];
1691
1719
  if (input.size !== 3)
1692
1720
  throw new RangeError("Normals must have size 3");
1693
- const output = new Float64Array(mesh.count * 3);
1721
+ const output2 = new Float64Array(mesh.count * 3);
1694
1722
  for (let i = 0; i < mesh.count; i++) {
1695
1723
  const value = normalizedLinearCombination(cofactors, Array.from(input.value.slice(i * 3, i * 3 + 3)), scales.map((v) => -Math.log(v)));
1696
- output.set(value.map((v) => determinant < 0 ? -v : v), i * 3);
1724
+ output2.set(value.map((v) => determinant < 0 ? -v : v), i * 3);
1697
1725
  }
1698
- attributes[normalName] = { size: 3, value: output };
1726
+ attributes[normalName] = { size: 3, value: output2 };
1699
1727
  }
1700
1728
  if (tangentName) {
1701
1729
  const input = mesh.attributes[tangentName];
1702
1730
  if (input.size !== 4)
1703
1731
  throw new RangeError("Tangents must have size 4");
1704
- const output = new Float64Array(mesh.count * 4);
1732
+ const output2 = new Float64Array(mesh.count * 4);
1705
1733
  for (let i = 0; i < mesh.count; i++) {
1706
1734
  const value = normalizedLinearCombination(basis, Array.from(input.value.slice(i * 4, i * 4 + 3)), scales.map(Math.log));
1707
1735
  if (normalName) {
@@ -1711,10 +1739,10 @@ function transformGeometry(geometry, matrix) {
1711
1739
  value[axis] -= projection * n[axis];
1712
1740
  }
1713
1741
  const length = Math.hypot(...value);
1714
- output.set(value.map((v) => length ? v / length : 0), i * 4);
1715
- output[i * 4 + 3] = input.value[i * 4 + 3] * (determinant < 0 ? -1 : 1);
1742
+ output2.set(value.map((v) => length ? v / length : 0), i * 4);
1743
+ output2[i * 4 + 3] = input.value[i * 4 + 3] * (determinant < 0 ? -1 : 1);
1716
1744
  }
1717
- attributes[tangentName] = { size: 4, value: output };
1745
+ attributes[tangentName] = { size: 4, value: output2 };
1718
1746
  }
1719
1747
  const indices = mesh.indices.slice();
1720
1748
  if (determinant < 0)
@@ -1974,8 +2002,8 @@ function interpolatePackedAttributes(source, provenance, options) {
1974
2002
  }
1975
2003
  const sourceCount = source.byteLength / byteStride;
1976
2004
  const input = new DataView(source.buffer, source.byteOffset, source.byteLength);
1977
- const output = new Uint8Array(outputBytes);
1978
- const result = new DataView(output.buffer);
2005
+ const output2 = new Uint8Array(outputBytes);
2006
+ const result = new DataView(output2.buffer);
1979
2007
  for (let vertex2 = 0; vertex2 < outputCount; vertex2++) {
1980
2008
  let sum = 0;
1981
2009
  let firstSource = -1;
@@ -1996,7 +2024,7 @@ function interpolatePackedAttributes(source, provenance, options) {
1996
2024
  if (firstSource < 0 || Math.abs(sum - 1) > 1e-10) {
1997
2025
  throw new RangeError("Interpolation weights must sum to one");
1998
2026
  }
1999
- output.set(source.subarray(firstSource * byteStride, (firstSource + 1) * byteStride), vertex2 * byteStride);
2027
+ output2.set(source.subarray(firstSource * byteStride, (firstSource + 1) * byteStride), vertex2 * byteStride);
2000
2028
  for (const attribute of attributes) {
2001
2029
  for (let component = 0; component < attribute.size; component++) {
2002
2030
  const offset = attribute.byteOffset + component * BYTE_SIZES[attribute.type];
@@ -2025,7 +2053,7 @@ function interpolatePackedAttributes(source, provenance, options) {
2025
2053
  }
2026
2054
  }
2027
2055
  }
2028
- return output;
2056
+ return output2;
2029
2057
  }
2030
2058
  function validateInterpolation(interpolation) {
2031
2059
  if (interpolation !== "linear" && interpolation !== "flat") {
@@ -2084,11 +2112,11 @@ function writeComponent(view, offset, type, value, littleEndian) {
2084
2112
 
2085
2113
  // dist/curves/curve.js
2086
2114
  var Curve = class {
2087
- constructor(dimension) {
2088
- if (dimension !== 2 && dimension !== 3) {
2115
+ constructor(dimension2) {
2116
+ if (dimension2 !== 2 && dimension2 !== 3) {
2089
2117
  throw new RangeError("Curve points must have two or three coordinates");
2090
2118
  }
2091
- this.dimension = dimension;
2119
+ this.dimension = dimension2;
2092
2120
  }
2093
2121
  getPoint(t, result = new Array(this.dimension)) {
2094
2122
  validateParameter(t);
@@ -2115,10 +2143,10 @@ var Curve = class {
2115
2143
  getPoints(divisions = 64) {
2116
2144
  validateDivisions(divisions);
2117
2145
  const points = new Float64Array((divisions + 1) * this.dimension);
2118
- const point = new Array(this.dimension);
2146
+ const point2 = new Array(this.dimension);
2119
2147
  for (let i = 0; i <= divisions; i++) {
2120
- this.getPoint(i / divisions, point);
2121
- points.set(point, i * this.dimension);
2148
+ this.getPoint(i / divisions, point2);
2149
+ points.set(point2, i * this.dimension);
2122
2150
  }
2123
2151
  return points;
2124
2152
  }
@@ -2126,14 +2154,14 @@ var Curve = class {
2126
2154
  function copyPoints(points) {
2127
2155
  if (!points.length)
2128
2156
  throw new RangeError("Invalid number of curve control points");
2129
- const dimension = points[0].length;
2130
- if (dimension !== 2 && dimension !== 3) {
2157
+ const dimension2 = points[0].length;
2158
+ if (dimension2 !== 2 && dimension2 !== 3) {
2131
2159
  throw new RangeError("Curve points must have two or three coordinates");
2132
2160
  }
2133
- return points.map((point) => {
2134
- if (point.length !== dimension)
2161
+ return points.map((point2) => {
2162
+ if (point2.length !== dimension2)
2135
2163
  throw new RangeError("Control point dimensions must match");
2136
- return Array.from(point, (value) => {
2164
+ return Array.from(point2, (value) => {
2137
2165
  if (!Number.isFinite(value))
2138
2166
  throw new RangeError("Control coordinates must be finite");
2139
2167
  return value;
@@ -2150,8 +2178,8 @@ function validateDivisions(divisions) {
2150
2178
  throw new RangeError("divisions must be a positive safe integer");
2151
2179
  }
2152
2180
  }
2153
- function validateResult(result, dimension) {
2154
- if (result.length < dimension)
2181
+ function validateResult(result, dimension2) {
2182
+ if (result.length < dimension2)
2155
2183
  throw new RangeError("Result buffer is too short");
2156
2184
  }
2157
2185
 
@@ -2243,7 +2271,7 @@ var CatmullRomCurve = class extends Curve {
2243
2271
  if (options.tension !== void 0 && mode !== "uniform") {
2244
2272
  throw new RangeError("tension is only supported for uniform splines");
2245
2273
  }
2246
- const point = (index) => {
2274
+ const point2 = (index) => {
2247
2275
  if (this.closed)
2248
2276
  return data[(index + data.length) % data.length];
2249
2277
  if (index < 0)
@@ -2255,10 +2283,10 @@ var CatmullRomCurve = class extends Curve {
2255
2283
  };
2256
2284
  this.segments = [];
2257
2285
  for (let s = 0; s < data.length - (this.closed ? 0 : 1); s++) {
2258
- const p0 = point(s - 1);
2259
- const p1 = point(s);
2260
- const p2 = point(s + 1);
2261
- const p3 = point(s + 2);
2286
+ const p0 = point2(s - 1);
2287
+ const p1 = point2(s);
2288
+ const p2 = point2(s + 1);
2289
+ const p3 = point2(s + 2);
2262
2290
  const interval = (a, b) => {
2263
2291
  const distance = Math.hypot(...a.map((x, i) => b[i] - x));
2264
2292
  return distance ** (mode === "chordal" ? 1 : 0.5);
@@ -2335,23 +2363,144 @@ var CurveArcLength = class {
2335
2363
  getSpacedPoints(divisions = 64) {
2336
2364
  validateDivisions(divisions);
2337
2365
  const points = new Float64Array((divisions + 1) * this.curve.dimension);
2338
- const point = new Array(this.curve.dimension);
2366
+ const point2 = new Array(this.curve.dimension);
2339
2367
  for (let i = 0; i <= divisions; i++) {
2340
- this.getPointAt(i / divisions, point);
2341
- points.set(point, i * this.curve.dimension);
2368
+ this.getPointAt(i / divisions, point2);
2369
+ points.set(point2, i * this.curve.dimension);
2342
2370
  }
2343
2371
  return points;
2344
2372
  }
2345
2373
  };
2346
2374
 
2375
+ // dist/curves/adaptive-sampling.js
2376
+ function sampleCurveAdaptive(curve, options) {
2377
+ const { tolerance, maxDepth = 16, maxPoints = 65536 } = options;
2378
+ if (!Number.isFinite(tolerance) || tolerance <= 0 || !Number.isInteger(maxDepth) || maxDepth < 0 || maxDepth > 30 || !Number.isSafeInteger(maxPoints) || maxPoints < 2)
2379
+ throw new RangeError("Invalid adaptive sampling budget");
2380
+ const parameters = [0], positions = [...curve.getPoint(0)];
2381
+ let converged = true, maxSampledError = 0;
2382
+ const stack = [{ t0: 0, t1: 1, a: curve.getPoint(0), b: curve.getPoint(1), depth: 0 }];
2383
+ while (stack.length) {
2384
+ const segment = stack.pop();
2385
+ const { t0, t1, a, b, depth } = segment;
2386
+ const localEdge = b.map((x, i) => x - a[i]);
2387
+ const samples = [0.25, 0.5, 0.75].map((f) => curve.getPoint(t0 + (t1 - t0) * f));
2388
+ const localSamples = samples.map((point2) => point2.map((x, i) => x - a[i]));
2389
+ const local = [...localEdge, ...localSamples.flat()].every(Number.isFinite);
2390
+ 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));
2391
+ const edge = local ? localEdge.map((x) => x / scale) : b.map((x, i) => x / scale - a[i] / scale);
2392
+ const squared = edge.reduce((sum, x) => sum + x * x, 0);
2393
+ const measuredError = Math.max(...samples.map((p, sampleIndex) => {
2394
+ const offset = local ? localSamples[sampleIndex].map((x) => x / scale) : p.map((x, i) => x / scale - a[i] / scale);
2395
+ const t = squared ? Math.max(0, Math.min(1, edge.reduce((sum, x, i) => sum + x * offset[i], 0) / squared)) : 0;
2396
+ return Math.hypot(...offset.map((x, i) => x - t * edge[i])) * scale;
2397
+ }));
2398
+ const error = Number.isFinite(measuredError) ? measuredError : Infinity;
2399
+ if (error > tolerance && depth < maxDepth && parameters.length + stack.length + 2 <= maxPoints) {
2400
+ const mid = (t0 + t1) / 2;
2401
+ stack.push({ t0: mid, t1, a: samples[1], b, depth: depth + 1 });
2402
+ stack.push({ t0, t1: mid, a, b: samples[1], depth: depth + 1 });
2403
+ } else {
2404
+ if (error > tolerance)
2405
+ converged = false;
2406
+ maxSampledError = Math.max(maxSampledError, error);
2407
+ parameters.push(t1);
2408
+ positions.push(...b);
2409
+ }
2410
+ }
2411
+ return {
2412
+ parameters: new Float64Array(parameters),
2413
+ positions: new Float64Array(positions),
2414
+ converged,
2415
+ maxSampledError
2416
+ };
2417
+ }
2418
+
2419
+ // dist/curves/parallel-transport.js
2420
+ var sub = (a, b) => a.map((x, i) => x - b[i]);
2421
+ var dot = (a, b) => a.reduce((sum, x, i) => sum + x * b[i], 0);
2422
+ var cross2 = (a, b) => [
2423
+ a[1] * b[2] - a[2] * b[1],
2424
+ a[2] * b[0] - a[0] * b[2],
2425
+ a[0] * b[1] - a[1] * b[0]
2426
+ ];
2427
+ var unit = (a) => {
2428
+ const length = Math.hypot(...a);
2429
+ if (!length)
2430
+ throw new RangeError("Cannot construct a frame for a stationary path");
2431
+ return a.map((x) => x / length);
2432
+ };
2433
+ function rotate(v, axis, angle) {
2434
+ const c = Math.cos(angle), s = Math.sin(angle), d = dot(axis, v), k = cross2(axis, v);
2435
+ return v.map((x, i) => x * c + k[i] * s + axis[i] * d * (1 - c));
2436
+ }
2437
+ function computeParallelTransportFrames(points, options = {}) {
2438
+ if (points.length < 2 || points.some((p) => p.length !== 3 || Array.from(p).some((x) => !Number.isFinite(x))))
2439
+ throw new RangeError("Expected at least two finite 3D points");
2440
+ const data = points.map((p) => Array.from(p)), n = data.length, closed = options.closed ?? false;
2441
+ if (closed && (n < 4 || Math.hypot(...sub(data[0], data[n - 1])) !== 0))
2442
+ throw new RangeError("A closed path must repeat its first point");
2443
+ const tangent = new Array(n);
2444
+ const edges = new Array(n - 1);
2445
+ let last;
2446
+ for (let i = 0; i < n - 1; i++) {
2447
+ const edge = sub(data[i + 1], data[i]);
2448
+ if (Math.hypot(...edge) > 0)
2449
+ last = edges[i] = unit(edge);
2450
+ }
2451
+ if (!last)
2452
+ throw new RangeError("Cannot construct a frame for a stationary path");
2453
+ tangent[n - 1] = last;
2454
+ for (let i = n - 2; i >= 0; i--) {
2455
+ last = edges[i] ?? last;
2456
+ tangent[i] = last;
2457
+ }
2458
+ if (closed)
2459
+ tangent[n - 1] = [...tangent[0]];
2460
+ const t = tangent[0];
2461
+ let initial = options.initialNormal ? Array.from(options.initialNormal) : [0, 0, 0];
2462
+ if (options.initialNormal && (initial.length !== 3 || initial.some((x) => !Number.isFinite(x))))
2463
+ throw new RangeError("Invalid initial normal");
2464
+ if (!options.initialNormal) {
2465
+ initial = [0, 0, 0];
2466
+ initial[t.map(Math.abs).indexOf(Math.min(...t.map(Math.abs)))] = 1;
2467
+ }
2468
+ initial = unit(initial);
2469
+ const perpendicular = cross2(t, initial);
2470
+ if (Math.hypot(...perpendicular) <= 1e-12) {
2471
+ throw new RangeError("Initial normal must not be parallel to the tangent");
2472
+ }
2473
+ const normals = [unit(cross2(perpendicular, t))];
2474
+ for (let i = 1; i < n; i++) {
2475
+ 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])));
2476
+ let normal = normals[i - 1];
2477
+ if (length > 1e-12)
2478
+ normal = rotate(normal, axis.map((x) => x / length), Math.atan2(length, cosine));
2479
+ normals.push(unit(normal.map((x, j) => x - dot(normal, tangent[i]) * tangent[i][j])));
2480
+ }
2481
+ if (closed) {
2482
+ const mismatch = Math.atan2(dot(tangent[0], cross2(normals[n - 1], normals[0])), dot(normals[n - 1], normals[0]));
2483
+ const lengths = [0];
2484
+ for (let i = 1; i < n; i++)
2485
+ lengths.push(lengths[i - 1] + Math.hypot(...sub(data[i], data[i - 1])));
2486
+ for (let i = 1; i < n; i++)
2487
+ normals[i] = rotate(normals[i], tangent[i], mismatch * lengths[i] / lengths[n - 1]);
2488
+ }
2489
+ return {
2490
+ tangents: new Float64Array(tangent.flat()),
2491
+ normals: new Float64Array(normals.flat()),
2492
+ binormals: new Float64Array(normals.flatMap((normal, i) => cross2(tangent[i], normal)))
2493
+ };
2494
+ }
2495
+
2347
2496
  // dist/polygon/polygon.js
2348
2497
  var import_core6 = require("@math.gl/core");
2349
2498
 
2350
2499
  // dist/polygon/polygon-utils.js
2351
2500
  var import_core5 = require("@math.gl/core");
2352
- function modifyPolygonWindingDirection(points, direction, options = {}) {
2501
+ function modifyPolygonWindingDirection(points, direction2, options = {}) {
2353
2502
  const windingDirection = getPolygonWindingDirection(points, options);
2354
- if (windingDirection !== direction) {
2503
+ if (windingDirection !== direction2) {
2355
2504
  reversePolygon(points, options);
2356
2505
  return true;
2357
2506
  }
@@ -2403,9 +2552,9 @@ function reversePolygon(points, options) {
2403
2552
  }
2404
2553
  }
2405
2554
  }
2406
- function modifyPolygonWindingDirectionPoints(points, direction, options = {}) {
2555
+ function modifyPolygonWindingDirectionPoints(points, direction2, options = {}) {
2407
2556
  const currentDirection = getPolygonWindingDirectionPoints(points, options);
2408
- if (currentDirection !== direction) {
2557
+ if (currentDirection !== direction2) {
2409
2558
  points.reverse();
2410
2559
  return true;
2411
2560
  }
@@ -2507,11 +2656,11 @@ var Polygon = class {
2507
2656
  * @param direction Requested winding direction.
2508
2657
  * @return Returns true if the winding direction was changed.
2509
2658
  */
2510
- modifyWindingDirection(direction) {
2659
+ modifyWindingDirection(direction2) {
2511
2660
  if (this.isFlatArray) {
2512
- return modifyPolygonWindingDirection(this.points, direction, this.options);
2661
+ return modifyPolygonWindingDirection(this.points, direction2, this.options);
2513
2662
  }
2514
- return modifyPolygonWindingDirectionPoints(this.points, direction, this.options);
2663
+ return modifyPolygonWindingDirectionPoints(this.points, direction2, this.options);
2515
2664
  }
2516
2665
  };
2517
2666
 
@@ -3540,16 +3689,16 @@ function subdividePolyline(input, options) {
3540
3689
  throw new RangeError("Transform returned nonfinite coordinates");
3541
3690
  return { source, target, fraction };
3542
3691
  }
3543
- function append(point, segment) {
3692
+ function append(point2, segment) {
3544
3693
  if (segmentIndices.length >= maxVertices) {
3545
3694
  throw new RangeError("Polyline subdivision exceeded maxVertices");
3546
3695
  }
3547
- for (const value of point.source)
3696
+ for (const value of point2.source)
3548
3697
  sourcePositions.push(value);
3549
- for (const value of point.target)
3698
+ for (const value of point2.target)
3550
3699
  positions.push(value);
3551
3700
  segmentIndices.push(segment);
3552
- segmentFractions.push(point.fraction);
3701
+ segmentFractions.push(point2.fraction);
3553
3702
  }
3554
3703
  function sampledSource(sampler, fraction) {
3555
3704
  const value = sampler.sample(fraction);
@@ -3569,10 +3718,10 @@ function subdividePolyline(input, options) {
3569
3718
  let error = 0;
3570
3719
  let midpoint;
3571
3720
  for (const fraction of [0.25, 0.5, 0.75]) {
3572
- const point = interpolate(a, b, fraction, sampler);
3721
+ const point2 = interpolate(a, b, fraction, sampler);
3573
3722
  if (fraction === 0.5)
3574
- midpoint = point;
3575
- const delta = point.target.map((value, i) => value - (a.target[i] * (1 - fraction) + b.target[i] * fraction));
3723
+ midpoint = point2;
3724
+ const delta = point2.target.map((value, i) => value - (a.target[i] * (1 - fraction) + b.target[i] * fraction));
3576
3725
  error = Math.max(error, Math.hypot(...delta));
3577
3726
  }
3578
3727
  const sourceLength = sampler ? sampler.length * (b.fraction - a.fraction) : Math.hypot(...a.source.map((value, i) => value - b.source[i]));
@@ -3741,7 +3890,7 @@ function subdivideTriangleMesh(mesh, options) {
3741
3890
  midpoints.set(key, index);
3742
3891
  return index;
3743
3892
  }
3744
- function splitFace(face, output, splitEdges, midpoints) {
3893
+ function splitFace(face, output2, splitEdges, midpoints) {
3745
3894
  const [a, b, c] = face.vertices;
3746
3895
  const ab = splitEdges.has(edgeKey(a, b)) ? midpoint(a, b, midpoints) : -1;
3747
3896
  const bc = splitEdges.has(edgeKey(b, c)) ? midpoint(b, c, midpoints) : -1;
@@ -3774,9 +3923,9 @@ function subdivideTriangleMesh(mesh, options) {
3774
3923
  }
3775
3924
  }
3776
3925
  function emit(x, y, z) {
3777
- if (output.length >= maxTriangles)
3926
+ if (output2.length >= maxTriangles)
3778
3927
  throw new RangeError("Triangle mesh subdivision exceeded maxTriangles");
3779
- output.push({ vertices: [x, y, z], sourceTriangle: face.sourceTriangle });
3928
+ output2.push({ vertices: [x, y, z], sourceTriangle: face.sourceTriangle });
3780
3929
  }
3781
3930
  }
3782
3931
  function buildResult() {
@@ -3839,8 +3988,8 @@ function clipTriangleMesh(mesh, options) {
3839
3988
  const positions = [], indices = [], sourceVertexIndices = [], sourceVertexWeights = [];
3840
3989
  const sourceTriangleIndices = [], periodicCopies = [];
3841
3990
  let intersections = 0;
3842
- for (let triangle = 0; triangle < inputIndices.length / 3; triangle++) {
3843
- const originalIndices = inputIndices.slice(triangle * 3, triangle * 3 + 3);
3991
+ for (let triangle2 = 0; triangle2 < inputIndices.length / 3; triangle2++) {
3992
+ const originalIndices = inputIndices.slice(triangle2 * 3, triangle2 * 3 + 3);
3844
3993
  const vertices = originalIndices.map((index, j) => ({
3845
3994
  position: source.slice(index * size, index * size + size),
3846
3995
  weights: [0, 1, 2].map((k) => Number(k === j))
@@ -3872,7 +4021,7 @@ function clipTriangleMesh(mesh, options) {
3872
4021
  const clipped = [];
3873
4022
  for (let i = 0; i < polygon.length; i++) {
3874
4023
  const p = polygon[i], q = polygon[(i + 1) % polygon.length];
3875
- const dp = cross2(a, b, p.position), dq = cross2(a, b, q.position);
4024
+ const dp = cross3(a, b, p.position), dq = cross3(a, b, q.position);
3876
4025
  if (dp >= 0)
3877
4026
  clipped.push(p);
3878
4027
  if (dp < 0 !== dq < 0) {
@@ -3888,7 +4037,7 @@ function clipTriangleMesh(mesh, options) {
3888
4037
  }
3889
4038
  for (let j = 1; j + 1 < polygon.length; j++) {
3890
4039
  const face = [polygon[0], polygon[j], polygon[j + 1]];
3891
- if (cross2(face[0].position, face[1].position, face[2].position) === 0)
4040
+ if (cross3(face[0].position, face[1].position, face[2].position) === 0)
3892
4041
  continue;
3893
4042
  if (positions.length / size + 3 > maxVertices || indices.length / 3 + 1 > maxTriangles)
3894
4043
  throw new RangeError("Mesh clipping exceeded output limits");
@@ -3898,7 +4047,7 @@ function clipTriangleMesh(mesh, options) {
3898
4047
  sourceVertexIndices.push(...originalIndices);
3899
4048
  sourceVertexWeights.push(...vertex2.weights);
3900
4049
  }
3901
- sourceTriangleIndices.push(triangle);
4050
+ sourceTriangleIndices.push(triangle2);
3902
4051
  periodicCopies.push(copy2);
3903
4052
  }
3904
4053
  }
@@ -3913,7 +4062,7 @@ function clipTriangleMesh(mesh, options) {
3913
4062
  periodicCopies: new Int32Array(periodicCopies)
3914
4063
  };
3915
4064
  }
3916
- function cross2(a, b, p) {
4065
+ function cross3(a, b, p) {
3917
4066
  const result = (b[0] - a[0]) * (p[1] - a[1]) - (b[1] - a[1]) * (p[0] - a[0]);
3918
4067
  if (!Number.isFinite(result))
3919
4068
  throw new RangeError("Unrepresentable clipping arithmetic");
@@ -3924,13 +4073,13 @@ function validateRegion(region) {
3924
4073
  throw new RangeError("Invalid convex clipping region");
3925
4074
  let area2 = 0;
3926
4075
  for (let i = 1; i + 1 < region.length; i++)
3927
- area2 += cross2(region[0], region[i], region[i + 1]);
4076
+ area2 += cross3(region[0], region[i], region[i + 1]);
3928
4077
  if (!Number.isFinite(area2) || area2 === 0)
3929
4078
  throw new RangeError("Degenerate clipping region");
3930
4079
  const result = area2 > 0 ? Array.from(region) : Array.from(region).reverse();
3931
4080
  for (let i = 0; i < result.length; i++) {
3932
4081
  const a = result[i], b = result[(i + 1) % result.length];
3933
- if (a[0] === b[0] && a[1] === b[1] || result.some((p) => cross2(a, b, p) < 0))
4082
+ if (a[0] === b[0] && a[1] === b[1] || result.some((p) => cross3(a, b, p) < 0))
3934
4083
  throw new RangeError("Clip region must be convex");
3935
4084
  }
3936
4085
  return result;
@@ -3973,15 +4122,25 @@ var AxisAlignedBoundingBox = class _AxisAlignedBoundingBox {
3973
4122
  return this === right || Boolean(right) && this.minimum.equals(right.minimum) && this.maximum.equals(right.maximum);
3974
4123
  }
3975
4124
  /**
3976
- * Applies a 4x4 affine transformation matrix to a bounding sphere.
3977
- * @param transform The transformation matrix to apply to the bounding sphere.
3978
- * @returns itself, i.e. the modified BoundingVolume.
4125
+ * Transforms an AABB by a finite affine matrix, rebuilding all bounds and extents.
4126
+ * @param transform The affine transformation matrix.
4127
+ * @returns itself, i.e. the modified bounding box.
3979
4128
  */
3980
4129
  transform(transform) {
3981
- this.center.transformAsPoint(transform);
3982
- this.halfDiagonal.transform(transform);
3983
- this.minimum.transform(transform);
3984
- this.maximum.transform(transform);
4130
+ if (transform.length !== 16 || transform.some((x) => !Number.isFinite(x)) || transform[3] !== 0 || transform[7] !== 0 || transform[11] !== 0 || transform[15] !== 1) {
4131
+ throw new RangeError("Expected a finite affine matrix");
4132
+ }
4133
+ const center = this.minimum.clone().add(this.maximum).scale(0.5);
4134
+ const extent = this.maximum.clone().subtract(this.minimum).scale(0.5);
4135
+ if (extent.some((x) => x < 0))
4136
+ throw new RangeError("Bounds must be ordered");
4137
+ center.transformAsPoint(transform);
4138
+ for (let row = 0; row < 3; row++) {
4139
+ this.halfDiagonal[row] = Math.abs(transform[row]) * extent[0] + Math.abs(transform[row + 4]) * extent[1] + Math.abs(transform[row + 8]) * extent[2];
4140
+ }
4141
+ this.center.copy(center);
4142
+ this.minimum.copy(center).subtract(this.halfDiagonal);
4143
+ this.maximum.copy(center).add(this.halfDiagonal);
3985
4144
  return this;
3986
4145
  }
3987
4146
  /**
@@ -4001,12 +4160,12 @@ var AxisAlignedBoundingBox = class _AxisAlignedBoundingBox {
4001
4160
  return "intersecting";
4002
4161
  }
4003
4162
  /** Computes the estimated distance from the closest point on a bounding box to a point. */
4004
- distanceTo(point) {
4005
- return Math.sqrt(this.distanceSquaredTo(point));
4163
+ distanceTo(point2) {
4164
+ return Math.sqrt(this.distanceSquaredTo(point2));
4006
4165
  }
4007
4166
  /** Computes the estimated distance squared from the closest point on a bounding box to a point. */
4008
- distanceSquaredTo(point) {
4009
- const offset = scratchVector.from(point).subtract(this.center);
4167
+ distanceSquaredTo(point2) {
4168
+ const offset = scratchVector.from(point2).subtract(this.center);
4010
4169
  const { halfDiagonal } = this;
4011
4170
  let distanceSquared = 0;
4012
4171
  let d;
@@ -4033,15 +4192,15 @@ var scratchVector4 = new import_core8.Vector3();
4033
4192
  var scratchVector22 = new import_core8.Vector3();
4034
4193
  var BoundingSphere = class _BoundingSphere {
4035
4194
  /** Creates a bounding sphere */
4036
- constructor(center = [0, 0, 0], radius = 0) {
4195
+ constructor(center = [0, 0, 0], radius2 = 0) {
4037
4196
  this.radius = -0;
4038
4197
  this.center = new import_core8.Vector3();
4039
- this.fromCenterRadius(center, radius);
4198
+ this.fromCenterRadius(center, radius2);
4040
4199
  }
4041
4200
  /** Sets the bounding sphere from `center` and `radius`. */
4042
- fromCenterRadius(center, radius) {
4201
+ fromCenterRadius(center, radius2) {
4043
4202
  this.center.from(center);
4044
- this.radius = radius;
4203
+ this.radius = radius2;
4045
4204
  return this;
4046
4205
  }
4047
4206
  /**
@@ -4083,11 +4242,11 @@ var BoundingSphere = class _BoundingSphere {
4083
4242
  return this;
4084
4243
  }
4085
4244
  /** Computes a bounding sphere by enlarging the provided sphere to contain the provided point. */
4086
- expand(point) {
4087
- const scratchPoint = scratchVector4.from(point);
4088
- const radius = scratchPoint.subtract(this.center).magnitude();
4089
- if (radius > this.radius) {
4090
- this.radius = radius;
4245
+ expand(point2) {
4246
+ const scratchPoint = scratchVector4.from(point2);
4247
+ const radius2 = scratchPoint.subtract(this.center).magnitude();
4248
+ if (radius2 > this.radius) {
4249
+ this.radius = radius2;
4091
4250
  }
4092
4251
  return this;
4093
4252
  }
@@ -4105,26 +4264,26 @@ var BoundingSphere = class _BoundingSphere {
4105
4264
  return this;
4106
4265
  }
4107
4266
  /** Computes the estimated distance squared from the closest point on a bounding sphere to a point. */
4108
- distanceSquaredTo(point) {
4109
- const d = this.distanceTo(point);
4267
+ distanceSquaredTo(point2) {
4268
+ const d = this.distanceTo(point2);
4110
4269
  return d * d;
4111
4270
  }
4112
4271
  /** Computes the estimated distance from the closest point on a bounding sphere to a point. */
4113
- distanceTo(point) {
4114
- const scratchPoint = scratchVector4.from(point);
4272
+ distanceTo(point2) {
4273
+ const scratchPoint = scratchVector4.from(point2);
4115
4274
  const delta = scratchPoint.subtract(this.center);
4116
4275
  return Math.max(0, delta.len() - this.radius);
4117
4276
  }
4118
4277
  /** Determines which side of a plane a sphere is located. */
4119
4278
  intersectPlane(plane) {
4120
4279
  const center = this.center;
4121
- const radius = this.radius;
4280
+ const radius2 = this.radius;
4122
4281
  const normal = plane.normal;
4123
4282
  const distanceToPlane = normal.dot(center) + plane.distance;
4124
- if (distanceToPlane < -radius) {
4283
+ if (distanceToPlane < -radius2) {
4125
4284
  return "outside";
4126
4285
  }
4127
- if (distanceToPlane < radius) {
4286
+ if (distanceToPlane < radius2) {
4128
4287
  return "intersecting";
4129
4288
  }
4130
4289
  return "inside";
@@ -4200,16 +4359,16 @@ var OrientedBoundingBox = class _OrientedBoundingBox {
4200
4359
  return "intersecting";
4201
4360
  }
4202
4361
  /** Computes the estimated distance from the closest point on a bounding box to a point. */
4203
- distanceTo(point) {
4204
- return Math.sqrt(this.distanceSquaredTo(point));
4362
+ distanceTo(point2) {
4363
+ return Math.sqrt(this.distanceSquaredTo(point2));
4205
4364
  }
4206
4365
  /**
4207
4366
  * Computes the estimated distance squared from the closest point
4208
4367
  * on a bounding box to a point.
4209
4368
  * See Geometric Tools for Computer Graphics 10.4.2
4210
4369
  */
4211
- distanceSquaredTo(point) {
4212
- const offset = scratchOffset.from(point).subtract(this.center);
4370
+ distanceSquaredTo(point2) {
4371
+ const offset = scratchOffset.from(point2).subtract(this.center);
4213
4372
  const halfAxes = this.halfAxes;
4214
4373
  const u = halfAxes.getColumn(0, scratchVectorU);
4215
4374
  const v = halfAxes.getColumn(1, scratchVectorV);
@@ -4251,7 +4410,7 @@ var OrientedBoundingBox = class _OrientedBoundingBox {
4251
4410
  * on the bounding box from position in direction.
4252
4411
  */
4253
4412
  // eslint-disable-next-line max-statements
4254
- computePlaneDistances(position, direction, result = [-0, -0]) {
4413
+ computePlaneDistances(position, direction2, result = [-0, -0]) {
4255
4414
  let minDist = Number.POSITIVE_INFINITY;
4256
4415
  let maxDist = Number.NEGATIVE_INFINITY;
4257
4416
  const center = this.center;
@@ -4261,42 +4420,42 @@ var OrientedBoundingBox = class _OrientedBoundingBox {
4261
4420
  const w = halfAxes.getColumn(2, scratchVectorW);
4262
4421
  const corner = scratchCorner.copy(u).add(v).add(w).add(center);
4263
4422
  const toCenter = scratchToCenter.copy(corner).subtract(position);
4264
- let mag = direction.dot(toCenter);
4423
+ let mag = direction2.dot(toCenter);
4265
4424
  minDist = Math.min(mag, minDist);
4266
4425
  maxDist = Math.max(mag, maxDist);
4267
4426
  corner.copy(center).add(u).add(v).subtract(w);
4268
4427
  toCenter.copy(corner).subtract(position);
4269
- mag = direction.dot(toCenter);
4428
+ mag = direction2.dot(toCenter);
4270
4429
  minDist = Math.min(mag, minDist);
4271
4430
  maxDist = Math.max(mag, maxDist);
4272
4431
  corner.copy(center).add(u).subtract(v).add(w);
4273
4432
  toCenter.copy(corner).subtract(position);
4274
- mag = direction.dot(toCenter);
4433
+ mag = direction2.dot(toCenter);
4275
4434
  minDist = Math.min(mag, minDist);
4276
4435
  maxDist = Math.max(mag, maxDist);
4277
4436
  corner.copy(center).add(u).subtract(v).subtract(w);
4278
4437
  toCenter.copy(corner).subtract(position);
4279
- mag = direction.dot(toCenter);
4438
+ mag = direction2.dot(toCenter);
4280
4439
  minDist = Math.min(mag, minDist);
4281
4440
  maxDist = Math.max(mag, maxDist);
4282
4441
  center.copy(corner).subtract(u).add(v).add(w);
4283
4442
  toCenter.copy(corner).subtract(position);
4284
- mag = direction.dot(toCenter);
4443
+ mag = direction2.dot(toCenter);
4285
4444
  minDist = Math.min(mag, minDist);
4286
4445
  maxDist = Math.max(mag, maxDist);
4287
4446
  center.copy(corner).subtract(u).add(v).subtract(w);
4288
4447
  toCenter.copy(corner).subtract(position);
4289
- mag = direction.dot(toCenter);
4448
+ mag = direction2.dot(toCenter);
4290
4449
  minDist = Math.min(mag, minDist);
4291
4450
  maxDist = Math.max(mag, maxDist);
4292
4451
  center.copy(corner).subtract(u).subtract(v).add(w);
4293
4452
  toCenter.copy(corner).subtract(position);
4294
- mag = direction.dot(toCenter);
4453
+ mag = direction2.dot(toCenter);
4295
4454
  minDist = Math.min(mag, minDist);
4296
4455
  maxDist = Math.max(mag, maxDist);
4297
4456
  center.copy(corner).subtract(u).subtract(v).subtract(w);
4298
4457
  toCenter.copy(corner).subtract(position);
4299
- mag = direction.dot(toCenter);
4458
+ mag = direction2.dot(toCenter);
4300
4459
  minDist = Math.min(mag, minDist);
4301
4460
  maxDist = Math.max(mag, maxDist);
4302
4461
  result[0] = minDist;
@@ -4325,6 +4484,9 @@ var OrientedBoundingBox = class _OrientedBoundingBox {
4325
4484
  };
4326
4485
 
4327
4486
  // dist/culling/lib/culling-volume.js
4487
+ var import_core13 = require("@math.gl/core");
4488
+
4489
+ // dist/culling/frustum-planes.js
4328
4490
  var import_core12 = require("@math.gl/core");
4329
4491
 
4330
4492
  // dist/culling/lib/plane.js
@@ -4345,10 +4507,10 @@ var Plane = class _Plane {
4345
4507
  return this;
4346
4508
  }
4347
4509
  /** Creates a plane from a normal and a point on the plane. */
4348
- fromPointNormal(point, normal) {
4349
- point = scratchPosition.from(point);
4510
+ fromPointNormal(point2, normal) {
4511
+ point2 = scratchPosition.from(point2);
4350
4512
  this.normal.from(normal).normalize();
4351
- const distance = -this.normal.dot(point);
4513
+ const distance = -this.normal.dot(point2);
4352
4514
  this.distance = distance;
4353
4515
  return this;
4354
4516
  }
@@ -4370,17 +4532,17 @@ var Plane = class _Plane {
4370
4532
  /** Computes the signed shortest distance of a point to a plane.
4371
4533
  * The sign of the distance determines which side of the plane the point is on.
4372
4534
  */
4373
- getPointDistance(point) {
4374
- return this.normal.dot(point) + this.distance;
4535
+ getPointDistance(point2) {
4536
+ return this.normal.dot(point2) + this.distance;
4375
4537
  }
4376
4538
  /** Transforms the plane by the given transformation matrix. */
4377
4539
  transform(matrix4) {
4378
4540
  const normal = scratchNormal2.copy(this.normal).transformAsVector(matrix4).normalize();
4379
- const point = this.normal.scale(-this.distance).transform(matrix4);
4380
- return this.fromPointNormal(point, normal);
4541
+ const point2 = this.normal.scale(-this.distance).transform(matrix4);
4542
+ return this.fromPointNormal(point2, normal);
4381
4543
  }
4382
- projectPointOntoPlane(point, result = [0, 0, 0]) {
4383
- const scratchPoint = scratchPosition.from(point);
4544
+ projectPointOntoPlane(point2, result = [0, 0, 0]) {
4545
+ const scratchPoint = scratchPosition.from(point2);
4384
4546
  const pointDistance = this.getPointDistance(scratchPoint);
4385
4547
  const scaledNormal = scratchNormal2.copy(this.normal).scale(pointDistance);
4386
4548
  return scratchPoint.subtract(scaledNormal).to(result);
@@ -4394,9 +4556,9 @@ var Plane = class _Plane {
4394
4556
  */
4395
4557
  intersectWithRay(ray, result = new import_core11.Vector3()) {
4396
4558
  const origin = ray.origin;
4397
- const direction = ray.direction;
4559
+ const direction2 = ray.direction;
4398
4560
  const normal = this.normal;
4399
- const denominator = normal.dot(direction);
4561
+ const denominator = normal.dot(direction2);
4400
4562
  if (Math.abs(denominator) < import_core11._MathUtils.EPSILON15) {
4401
4563
  return void 0;
4402
4564
  }
@@ -4404,14 +4566,45 @@ var Plane = class _Plane {
4404
4566
  if (t < 0) {
4405
4567
  return void 0;
4406
4568
  }
4407
- return result.copy(direction).multiplyByScalar(t).add(origin);
4569
+ return result.copy(direction2).multiplyByScalar(t).add(origin);
4408
4570
  }
4409
4571
  };
4410
4572
 
4573
+ // dist/culling/frustum-planes.js
4574
+ function extractFrustumPlanes(matrix, options = {}) {
4575
+ if (matrix.length !== 16 || Array.from(matrix).some((x2) => !Number.isFinite(x2)))
4576
+ throw new RangeError("Expected a finite view-projection matrix");
4577
+ const [near, far] = (0, import_core12.getProjectionDepthRange)(options);
4578
+ const low = Math.min(near, far), high = Math.max(near, far);
4579
+ const row = (i) => [matrix[i], matrix[i + 4], matrix[i + 8], matrix[i + 12]];
4580
+ const x = row(0), y = row(1), z = row(2), w = row(3);
4581
+ const combine = (a, b, factor) => a.map((v, i) => v + factor * b[i]);
4582
+ const lo = combine(z, w, -low), hi = w.map((v, i) => high * v - z[i]);
4583
+ const coefficients = [
4584
+ combine(w, x, 1),
4585
+ combine(w, x, -1),
4586
+ combine(w, y, 1),
4587
+ combine(w, y, -1),
4588
+ ...options.reversedDepth ? [hi, lo] : [lo, hi]
4589
+ ];
4590
+ const planes = [];
4591
+ for (const [a, b, c, d] of coefficients) {
4592
+ const length = Math.hypot(a, b, c);
4593
+ if (length === 0) {
4594
+ if (d < 0)
4595
+ throw new RangeError("Empty clipping volume");
4596
+ } else
4597
+ planes.push(new Plane([a / length, b / length, c / length], d / length));
4598
+ }
4599
+ if (planes.length < 4)
4600
+ throw new RangeError("Degenerate clipping volume");
4601
+ return planes;
4602
+ }
4603
+
4411
4604
  // dist/culling/lib/culling-volume.js
4412
- var faces = [new import_core12.Vector3([1, 0, 0]), new import_core12.Vector3([0, 1, 0]), new import_core12.Vector3([0, 0, 1])];
4413
- var scratchPlaneCenter = new import_core12.Vector3();
4414
- var scratchPlaneNormal = new import_core12.Vector3();
4605
+ var faces = [new import_core13.Vector3([1, 0, 0]), new import_core13.Vector3([0, 1, 0]), new import_core13.Vector3([0, 0, 1])];
4606
+ var scratchPlaneCenter = new import_core13.Vector3();
4607
+ var scratchPlaneNormal = new import_core13.Vector3();
4415
4608
  var CullingVolume = class _CullingVolume {
4416
4609
  /**
4417
4610
  * Create a new `CullingVolume` bounded by an array of clipping planed
@@ -4427,7 +4620,7 @@ var CullingVolume = class _CullingVolume {
4427
4620
  fromBoundingSphere(boundingSphere) {
4428
4621
  this.planes.length = 2 * faces.length;
4429
4622
  const center = boundingSphere.center;
4430
- const radius = boundingSphere.radius;
4623
+ const radius2 = boundingSphere.radius;
4431
4624
  let planeIndex = 0;
4432
4625
  for (const faceNormal of faces) {
4433
4626
  let plane0 = this.planes[planeIndex];
@@ -4438,15 +4631,21 @@ var CullingVolume = class _CullingVolume {
4438
4631
  if (!plane1) {
4439
4632
  plane1 = this.planes[planeIndex + 1] = new Plane();
4440
4633
  }
4441
- const plane0Center = scratchPlaneCenter.copy(faceNormal).scale(-radius).add(center);
4634
+ const plane0Center = scratchPlaneCenter.copy(faceNormal).scale(-radius2).add(center);
4442
4635
  plane0.fromPointNormal(plane0Center, faceNormal);
4443
- const plane1Center = scratchPlaneCenter.copy(faceNormal).scale(radius).add(center);
4636
+ const plane1Center = scratchPlaneCenter.copy(faceNormal).scale(radius2).add(center);
4444
4637
  const negatedFaceNormal = scratchPlaneNormal.copy(faceNormal).negate();
4445
4638
  plane1.fromPointNormal(plane1Center, negatedFaceNormal);
4446
4639
  planeIndex += 2;
4447
4640
  }
4448
4641
  return this;
4449
4642
  }
4643
+ /** Replace planes from a view-projection matrix; validates before mutating. */
4644
+ fromViewProjection(matrix, options = {}) {
4645
+ const planes = extractFrustumPlanes(matrix, options);
4646
+ this.planes.splice(0, this.planes.length, ...planes);
4647
+ return this;
4648
+ }
4450
4649
  /** Determines whether a bounding volume intersects the culling volume. */
4451
4650
  computeVisibility(boundingVolume) {
4452
4651
  let intersect2 = "inside";
@@ -4472,7 +4671,7 @@ var CullingVolume = class _CullingVolume {
4472
4671
  * and that plane check can be skipped.
4473
4672
  */
4474
4673
  computeVisibilityWithPlaneMask(boundingVolume, parentPlaneMask) {
4475
- (0, import_core12.assert)(Number.isFinite(parentPlaneMask), "parentPlaneMask is required.");
4674
+ (0, import_core13.assert)(Number.isFinite(parentPlaneMask), "parentPlaneMask is required.");
4476
4675
  if (parentPlaneMask === _CullingVolume.MASK_OUTSIDE || parentPlaneMask === _CullingVolume.MASK_INSIDE) {
4477
4676
  return parentPlaneMask;
4478
4677
  }
@@ -4499,7 +4698,441 @@ CullingVolume.MASK_INSIDE = 0;
4499
4698
  CullingVolume.MASK_INDETERMINATE = 2147483647;
4500
4699
 
4501
4700
  // dist/culling/lib/ray.js
4502
- var import_core13 = require("@math.gl/core");
4701
+ var import_core14 = require("@math.gl/core");
4702
+
4703
+ // dist/culling/queries.js
4704
+ function validateQueryPoint(point2, dimension2) {
4705
+ if (point2.length !== dimension2)
4706
+ throw new RangeError("Query dimension must match the index");
4707
+ for (let i = 0; i < dimension2; i++) {
4708
+ if (!Number.isFinite(point2[i]))
4709
+ throw new RangeError("Coordinates must be finite");
4710
+ }
4711
+ }
4712
+ function validateQueryDistance(distance) {
4713
+ if (Number.isNaN(distance) || distance < 0)
4714
+ throw new RangeError("Distance must be nonnegative");
4715
+ }
4716
+ function normalizeQueryDirection(direction2, dimension2) {
4717
+ validateQueryPoint(direction2, dimension2);
4718
+ const scale = Math.max(...Array.from(direction2, Math.abs));
4719
+ if (scale === 0)
4720
+ throw new RangeError("Ray direction must be nonzero");
4721
+ const scaled = Array.from(direction2, (x) => x / scale);
4722
+ const length = Math.hypot(...scaled);
4723
+ return scaled.map((x) => x / length);
4724
+ }
4725
+ function intersectRayBounds(origin, direction2, minimum, maximum, maxT = Infinity) {
4726
+ const dimension2 = origin.length;
4727
+ if (dimension2 !== 2 && dimension2 !== 3)
4728
+ throw new RangeError("Bounds must be 2D or 3D");
4729
+ validateQueryPoint(origin, dimension2);
4730
+ validateQueryPoint(direction2, dimension2);
4731
+ validateQueryPoint(minimum, dimension2);
4732
+ validateQueryPoint(maximum, dimension2);
4733
+ validateQueryDistance(maxT);
4734
+ let near = 0, far = maxT, nonzero = false;
4735
+ for (let i = 0; i < dimension2; i++) {
4736
+ if (minimum[i] > maximum[i])
4737
+ throw new RangeError("Bounds must be ordered");
4738
+ nonzero || (nonzero = direction2[i] !== 0);
4739
+ }
4740
+ if (!nonzero)
4741
+ throw new RangeError("Ray direction must be nonzero");
4742
+ for (let i = 0; i < dimension2; i++) {
4743
+ if (direction2[i] === 0) {
4744
+ if (origin[i] < minimum[i] || origin[i] > maximum[i])
4745
+ return null;
4746
+ continue;
4747
+ }
4748
+ let a = (minimum[i] - origin[i]) / direction2[i];
4749
+ let b = (maximum[i] - origin[i]) / direction2[i];
4750
+ if (a > b)
4751
+ [a, b] = [b, a];
4752
+ near = Math.max(near, a);
4753
+ far = Math.min(far, b);
4754
+ if (near > far)
4755
+ return null;
4756
+ }
4757
+ return Number.isFinite(near) ? near : null;
4758
+ }
4759
+ function intersectRayTriangle(origin, direction2, a, b, c, options = {}) {
4760
+ for (const point2 of [origin, direction2, a, b, c])
4761
+ validateQueryPoint(point2, 3);
4762
+ if (direction2[0] === 0 && direction2[1] === 0 && direction2[2] === 0) {
4763
+ throw new RangeError("Ray direction must be nonzero");
4764
+ }
4765
+ const maxT = options.maxT ?? Infinity;
4766
+ validateQueryDistance(maxT);
4767
+ const e1 = [b[0] - a[0], b[1] - a[1], b[2] - a[2]];
4768
+ const e2 = [c[0] - a[0], c[1] - a[1], c[2] - a[2]];
4769
+ const p = cross4(direction2, e2);
4770
+ const determinant = dot2(e1, p);
4771
+ if (determinant === 0 || options.backfaceCulling && determinant < 0)
4772
+ return null;
4773
+ const offset = [origin[0] - a[0], origin[1] - a[1], origin[2] - a[2]];
4774
+ const u = dot2(offset, p) / determinant;
4775
+ if (u < 0 || u > 1)
4776
+ return null;
4777
+ const q = cross4(offset, e1);
4778
+ const v = dot2(direction2, q) / determinant;
4779
+ if (v < 0 || u + v > 1)
4780
+ return null;
4781
+ const t = dot2(e2, q) / determinant;
4782
+ if (!Number.isFinite(t) || t < 0 || t > maxT)
4783
+ return null;
4784
+ return { t: Math.max(0, t), barycentric: [1 - u - v, u, v] };
4785
+ }
4786
+ function getClosestPointOnTriangle(point2, a, b, c) {
4787
+ for (const value of [point2, a, b, c])
4788
+ validateQueryPoint(value, 3);
4789
+ const ab = [b[0] - a[0], b[1] - a[1], b[2] - a[2]];
4790
+ const ac = [c[0] - a[0], c[1] - a[1], c[2] - a[2]];
4791
+ const ap = [point2[0] - a[0], point2[1] - a[1], point2[2] - a[2]];
4792
+ const aa = dot2(ab, ab), bb = dot2(ac, ac), cc = dot2(ab, ac);
4793
+ const denominator = aa * bb - cc * cc;
4794
+ if (denominator > 0 && Number.isFinite(denominator)) {
4795
+ const u = (bb * dot2(ap, ab) - cc * dot2(ap, ac)) / denominator;
4796
+ const v = (aa * dot2(ap, ac) - cc * dot2(ap, ab)) / denominator;
4797
+ if (u >= 0 && v >= 0 && u + v <= 1) {
4798
+ return [
4799
+ a[0] + u * ab[0] + v * ac[0],
4800
+ a[1] + u * ab[1] + v * ac[1],
4801
+ a[2] + u * ab[2] + v * ac[2]
4802
+ ];
4803
+ }
4804
+ }
4805
+ let best = [a[0], a[1], a[2]];
4806
+ let distance = Infinity;
4807
+ for (const [start, end] of [
4808
+ [a, b],
4809
+ [b, c],
4810
+ [c, a]
4811
+ ]) {
4812
+ const edge = [end[0] - start[0], end[1] - start[1], end[2] - start[2]];
4813
+ const offset = [point2[0] - start[0], point2[1] - start[1], point2[2] - start[2]];
4814
+ const squared = dot2(edge, edge);
4815
+ const t = squared > 0 ? Math.max(0, Math.min(1, dot2(offset, edge) / squared)) : 0;
4816
+ const candidate = [
4817
+ start[0] + t * edge[0],
4818
+ start[1] + t * edge[1],
4819
+ start[2] + t * edge[2]
4820
+ ];
4821
+ const d = Math.hypot(point2[0] - candidate[0], point2[1] - candidate[1], point2[2] - candidate[2]);
4822
+ if (d < distance) {
4823
+ distance = d;
4824
+ best = candidate;
4825
+ }
4826
+ }
4827
+ return best;
4828
+ }
4829
+ function getClosestPointsOnSegments(a0, a1, b0, b1) {
4830
+ const frame = queryFrame([a0, a1, b0, b1]);
4831
+ const pair2 = closestSegments(...frame.points);
4832
+ const pointA = interpolatePoint(a0, a1, pair2.fractionA);
4833
+ const pointB = interpolatePoint(b0, b1, pair2.fractionB);
4834
+ return {
4835
+ distance: finiteDistance(pointA, pointB),
4836
+ pointA,
4837
+ pointB,
4838
+ fractionA: pair2.fractionA,
4839
+ fractionB: pair2.fractionB
4840
+ };
4841
+ }
4842
+ function getClosestPointsSegmentTriangle(start, end, a, b, c) {
4843
+ const frame = queryFrame([start, end, a, b, c]);
4844
+ const [s, e, va, vb, vc] = frame.points;
4845
+ const direction2 = subtract(e, s);
4846
+ if (direction2.some((value) => value !== 0)) {
4847
+ const hit = intersectRayTriangle(s, direction2, va, vb, vc, { maxT: 1 });
4848
+ if (hit) {
4849
+ const point2 = interpolatePoint(start, end, hit.t);
4850
+ return { distance: 0, segmentPoint: point2, trianglePoint: [...point2], segmentFraction: hit.t };
4851
+ }
4852
+ }
4853
+ let best = { distance: Infinity, segmentFraction: 0, trianglePoint: va };
4854
+ const consider = (point2, trianglePoint2, segmentFraction) => {
4855
+ const distance = Math.hypot(...subtract(point2, trianglePoint2));
4856
+ if (distance < best.distance || distance === best.distance && segmentFraction < best.segmentFraction)
4857
+ best = { distance, segmentFraction, trianglePoint: trianglePoint2 };
4858
+ };
4859
+ consider(s, getClosestPointOnTriangle(s, va, vb, vc), 0);
4860
+ consider(e, getClosestPointOnTriangle(e, va, vb, vc), 1);
4861
+ for (const [v0, v1] of [
4862
+ [va, vb],
4863
+ [vb, vc],
4864
+ [vc, va]
4865
+ ]) {
4866
+ const pair2 = closestSegments(s, e, v0, v1);
4867
+ consider(interpolatePoint(s, e, pair2.fractionA), interpolatePoint(v0, v1, pair2.fractionB), pair2.fractionA);
4868
+ }
4869
+ 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)));
4870
+ if (!trianglePoint.every(Number.isFinite))
4871
+ throw new RangeError("Closest-point result overflow");
4872
+ const segmentPoint = interpolatePoint(start, end, best.segmentFraction);
4873
+ return {
4874
+ distance: finiteDistance(segmentPoint, trianglePoint),
4875
+ segmentPoint,
4876
+ trianglePoint,
4877
+ segmentFraction: best.segmentFraction
4878
+ };
4879
+ }
4880
+ function queryFrame(input) {
4881
+ input.forEach((point2) => validateQueryPoint(point2, 3));
4882
+ const offsets = input.map((point2) => subtract(point2, input[0]));
4883
+ let scale = 0;
4884
+ for (const offset of offsets)
4885
+ for (const value of offset) {
4886
+ if (!Number.isFinite(value))
4887
+ throw new RangeError("Closest-point coordinate span overflow");
4888
+ scale = Math.max(scale, Math.abs(value));
4889
+ }
4890
+ scale || (scale = 1);
4891
+ return { points: offsets.map((point2) => point2.map((value) => value / scale)), scale };
4892
+ }
4893
+ function closestSegments(a0, a1, b0, b1) {
4894
+ const da = subtract(a1, a0), db = subtract(b1, b0);
4895
+ const lengthA = Math.hypot(...da), lengthB = Math.hypot(...db);
4896
+ const ua = da.map((value) => lengthA ? value / lengthA : 0);
4897
+ const ub = db.map((value) => lengthB ? value / lengthB : 0);
4898
+ let best = { distance: Infinity, fractionA: 0, fractionB: 0 };
4899
+ const consider = (fractionA, fractionB) => {
4900
+ const distance = Math.hypot(...subtract(interpolatePoint(a0, a1, fractionA), interpolatePoint(b0, b1, fractionB)));
4901
+ if (distance < best.distance || distance === best.distance && (fractionA < best.fractionA || fractionA === best.fractionA && fractionB < best.fractionB))
4902
+ best = { distance, fractionA, fractionB };
4903
+ };
4904
+ for (const t of [0, 1]) {
4905
+ consider(t, lengthB ? clampUnit(dot2(subtract(t ? a1 : a0, b0), ub) / lengthB) : 0);
4906
+ consider(lengthA ? clampUnit(dot2(subtract(t ? b1 : b0, a0), ua) / lengthA) : 0, t);
4907
+ }
4908
+ const normal = cross4(ua, ub);
4909
+ const sine = Math.hypot(...normal);
4910
+ if (sine > 0) {
4911
+ const unit2 = normal.map((value) => value / sine);
4912
+ const offset = subtract(b0, a0);
4913
+ const fractionA = dot2(cross4(offset, ub), unit2) / sine / lengthA;
4914
+ const fractionB = dot2(cross4(offset, ua), unit2) / sine / lengthB;
4915
+ if (fractionA >= 0 && fractionA <= 1 && fractionB >= 0 && fractionB <= 1)
4916
+ consider(fractionA, fractionB);
4917
+ }
4918
+ return best;
4919
+ }
4920
+ function subtract(a, b) {
4921
+ return [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
4922
+ }
4923
+ function interpolatePoint(a, b, t) {
4924
+ 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])));
4925
+ }
4926
+ function clampUnit(value) {
4927
+ return Math.max(0, Math.min(1, value));
4928
+ }
4929
+ function finiteDistance(a, b) {
4930
+ const distance = Math.hypot(...subtract(a, b));
4931
+ if (!Number.isFinite(distance))
4932
+ throw new RangeError("Closest-point distance overflow");
4933
+ return distance;
4934
+ }
4935
+ function dot2(a, b) {
4936
+ return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
4937
+ }
4938
+ function cross4(a, b) {
4939
+ 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]];
4940
+ }
4941
+
4942
+ // dist/culling/geometric-queries.js
4943
+ var sub2 = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
4944
+ var dot3 = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
4945
+ var cross5 = (a, b) => [
4946
+ a[1] * b[2] - a[2] * b[1],
4947
+ a[2] * b[0] - a[0] * b[2],
4948
+ a[0] * b[1] - a[1] * b[0]
4949
+ ];
4950
+ var check = (...points) => {
4951
+ for (const p of points)
4952
+ validateQueryPoint(p, 3);
4953
+ };
4954
+ function output(out, values) {
4955
+ if (out.length < values.length)
4956
+ throw new RangeError("Result buffer is too short");
4957
+ const copy2 = Array.from(values);
4958
+ for (let i = 0; i < copy2.length; i++)
4959
+ out[i] = copy2[i];
4960
+ return out;
4961
+ }
4962
+ function direction(d) {
4963
+ check(d);
4964
+ if (Math.hypot(d[0], d[1], d[2]) === 0)
4965
+ throw new RangeError("Ray direction must be nonzero");
4966
+ }
4967
+ function getRayPoint(origin, dir, t, out = [0, 0, 0]) {
4968
+ check(origin);
4969
+ direction(dir);
4970
+ if (!Number.isFinite(t) || t < 0)
4971
+ throw new RangeError("Ray parameter must be finite and nonnegative");
4972
+ return output(out, [origin[0] + t * dir[0], origin[1] + t * dir[1], origin[2] + t * dir[2]]);
4973
+ }
4974
+ function getClosestPointOnRay(point2, origin, dir, out = [0, 0, 0]) {
4975
+ check(point2, origin);
4976
+ direction(dir);
4977
+ const unit2 = normalizeQueryDirection(dir, 3);
4978
+ const distance = Math.max(0, dot3(sub2(point2, origin), unit2));
4979
+ return output(out, [0, 1, 2].map((i) => origin[i] + distance * unit2[i]));
4980
+ }
4981
+ function distanceToRay(point2, origin, dir) {
4982
+ const p = getClosestPointOnRay(point2, origin, dir);
4983
+ return Math.hypot(...sub2(point2, p));
4984
+ }
4985
+ function getClosestPointsRaySegment(origin, dir, a, b) {
4986
+ check(origin, a, b);
4987
+ direction(dir);
4988
+ const unit2 = normalizeQueryDirection(dir, 3);
4989
+ const directionLength = Math.hypot(dir[0], dir[1], dir[2]);
4990
+ const edge = sub2(b, a), offset = sub2(origin, a);
4991
+ const segmentLength = Math.hypot(...edge);
4992
+ const segmentUnit = edge.map((x) => segmentLength ? x / segmentLength : 0);
4993
+ const bb = dot3(unit2, segmentUnit), dd = dot3(unit2, offset), ee = dot3(segmentUnit, offset);
4994
+ const candidates = [
4995
+ [0, Math.max(0, Math.min(segmentLength, ee))],
4996
+ [Math.max(0, -dd), 0],
4997
+ [Math.max(0, bb * segmentLength - dd), segmentLength]
4998
+ ];
4999
+ const normal = cross5(unit2, segmentUnit);
5000
+ const sine = Math.hypot(...normal);
5001
+ if (segmentLength > 0 && sine > 0) {
5002
+ const normalUnit = normal.map((value) => value / sine);
5003
+ const separation = sub2(a, origin);
5004
+ const t = dot3(cross5(separation, segmentUnit), normalUnit) / sine;
5005
+ const u = dot3(cross5(separation, unit2), normalUnit) / sine;
5006
+ if (t >= 0 && u >= 0 && u <= segmentLength)
5007
+ candidates.push([t, u]);
5008
+ }
5009
+ let best;
5010
+ for (const [t, u] of candidates) {
5011
+ const rayPoint = [
5012
+ origin[0] + t * unit2[0],
5013
+ origin[1] + t * unit2[1],
5014
+ origin[2] + t * unit2[2]
5015
+ ];
5016
+ const segmentPoint = [
5017
+ a[0] + u * segmentUnit[0],
5018
+ a[1] + u * segmentUnit[1],
5019
+ a[2] + u * segmentUnit[2]
5020
+ ];
5021
+ const distance = Math.hypot(...sub2(rayPoint, segmentPoint));
5022
+ if (!best || distance < best.distance)
5023
+ best = {
5024
+ rayPoint,
5025
+ segmentPoint,
5026
+ rayParameter: t / directionLength,
5027
+ segmentFraction: segmentLength ? u / segmentLength : 0,
5028
+ distance
5029
+ };
5030
+ }
5031
+ return best;
5032
+ }
5033
+ function transformRay(origin, dir, matrix) {
5034
+ check(origin);
5035
+ direction(dir);
5036
+ if (matrix.length !== 16 || Array.from(matrix).some((x) => !Number.isFinite(x)) || matrix[3] !== 0 || matrix[7] !== 0 || matrix[11] !== 0 || matrix[15] !== 1)
5037
+ throw new RangeError("Expected a finite affine matrix");
5038
+ 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]);
5039
+ const transformed = { origin: apply(origin, 1), direction: apply(dir, 0) };
5040
+ check(transformed.origin);
5041
+ direction(transformed.direction);
5042
+ return transformed;
5043
+ }
5044
+ function triangle(a, b, c) {
5045
+ check(a, b, c);
5046
+ const ab = sub2(b, a), ac = sub2(c, a);
5047
+ const scale = Math.max(Math.hypot(...ab), Math.hypot(...ac));
5048
+ const u = ab.map((x) => scale ? x / scale : 0), v = ac.map((x) => scale ? x / scale : 0);
5049
+ return { u, v, scale, normal: cross5(u, v) };
5050
+ }
5051
+ function getTriangleBarycentric(point2, a, b, c, out = [0, 0, 0]) {
5052
+ check(point2);
5053
+ const { u, v, scale, normal } = triangle(a, b, c), denominator = dot3(normal, normal);
5054
+ if (denominator === 0)
5055
+ return null;
5056
+ const p = sub2(point2, a).map((x) => x / scale);
5057
+ const second = dot3(cross5(p, v), normal) / denominator;
5058
+ const third = dot3(cross5(u, p), normal) / denominator;
5059
+ return output(out, [1 - second - third, second, third]);
5060
+ }
5061
+ function getTriangleArea(a, b, c) {
5062
+ const { normal, scale } = triangle(a, b, c);
5063
+ return Math.hypot(...normal) * scale * scale / 2;
5064
+ }
5065
+ function getTriangleNormal(a, b, c, out = [0, 0, 0]) {
5066
+ const { normal } = triangle(a, b, c), length = Math.hypot(...normal);
5067
+ return output(out, normal.map((x) => length ? x / length : 0));
5068
+ }
5069
+ function isTriangleFrontFacing(a, b, c, dir) {
5070
+ direction(dir);
5071
+ return dot3(triangle(a, b, c).normal, dir) < 0;
5072
+ }
5073
+ function triangleContainsPoint(point2, a, b, c, tolerance = 1e-10) {
5074
+ if (!Number.isFinite(tolerance) || tolerance < 0)
5075
+ throw new RangeError("Invalid tolerance");
5076
+ const weights = getTriangleBarycentric(point2, a, b, c);
5077
+ if (!weights)
5078
+ return false;
5079
+ const { normal, scale } = triangle(a, b, c);
5080
+ const distance = Math.abs(dot3(sub2(point2, a).map((x) => x / scale), normal)) / Math.hypot(...normal);
5081
+ return distance <= tolerance && Array.from(weights).every((x) => x >= -tolerance && x <= 1 + tolerance);
5082
+ }
5083
+ function interpolateTriangleAttribute(weights, a, b, c, out = new Array(a.length)) {
5084
+ check(weights);
5085
+ if (!a.length || a.length !== b.length || a.length !== c.length || [a, b, c].some((p) => Array.from(p).some((x) => !Number.isFinite(x))))
5086
+ throw new RangeError("Expected matching finite attributes");
5087
+ return output(out, Array.from(a, (x, i) => weights[0] * x + weights[1] * b[i] + weights[2] * c[i]));
5088
+ }
5089
+ function intersectPlaneSegment(normal, constant, start, end, out = [0, 0, 0]) {
5090
+ check(start, end);
5091
+ direction(normal);
5092
+ if (!Number.isFinite(constant))
5093
+ throw new RangeError("Plane constant must be finite");
5094
+ const a = dot3(normal, start) + constant, b = dot3(normal, end) + constant;
5095
+ if (a === 0)
5096
+ return output(out, start);
5097
+ if (b === 0)
5098
+ return output(out, end);
5099
+ if (a > 0 === b > 0)
5100
+ return null;
5101
+ const t = a / (a - b);
5102
+ return output(out, [0, 1, 2].map((i) => start[i] + t * (end[i] - start[i])));
5103
+ }
5104
+ function triangleIntersectsBounds(a, b, c, minimum, maximum) {
5105
+ check(a, b, c, minimum, maximum);
5106
+ if ([0, 1, 2].some((i) => minimum[i] > maximum[i]))
5107
+ return false;
5108
+ const center = [0, 1, 2].map((i) => minimum[i] / 2 + maximum[i] / 2);
5109
+ const extent = [0, 1, 2].map((i) => maximum[i] / 2 - minimum[i] / 2);
5110
+ const vertices = [a, b, c].map((p) => sub2(p, center));
5111
+ const edges = [sub2(b, a), sub2(c, b), sub2(a, c)];
5112
+ const basis = [
5113
+ [1, 0, 0],
5114
+ [0, 1, 0],
5115
+ [0, 0, 1]
5116
+ ];
5117
+ const axes = [
5118
+ ...basis,
5119
+ cross5(edges[0], edges[1]),
5120
+ ...edges.flatMap((e) => basis.map((axis) => cross5(e, axis)))
5121
+ ];
5122
+ for (const axis of axes) {
5123
+ const length = Math.hypot(...axis);
5124
+ if (!length)
5125
+ continue;
5126
+ const unit2 = axis.map((x) => x / length);
5127
+ const projections = vertices.map((v) => dot3(v, unit2));
5128
+ const radius2 = extent.reduce((sum, x, i) => sum + x * Math.abs(unit2[i]), 0);
5129
+ if (Math.min(...projections) > radius2 || Math.max(...projections) < -radius2)
5130
+ return false;
5131
+ }
5132
+ return true;
5133
+ }
5134
+
5135
+ // dist/culling/lib/ray.js
4503
5136
  var Ray = class {
4504
5137
  /**
4505
5138
  * Creates a new ray that extends infinitely from the provided origin in the provided direction.
@@ -4507,25 +5140,44 @@ var Ray = class {
4507
5140
  * @param [origin=Vector3] The origin of the ray.
4508
5141
  * @param [direction=Vector3] The direction of the ray.
4509
5142
  */
4510
- constructor(origin, direction) {
5143
+ constructor(origin, direction2) {
4511
5144
  if (origin)
4512
5145
  origin = origin.clone();
4513
5146
  else
4514
- origin = new import_core13.Vector3();
4515
- if (direction)
4516
- direction = direction.clone().normalize();
5147
+ origin = new import_core14.Vector3();
5148
+ if (direction2)
5149
+ direction2 = direction2.clone().normalize();
4517
5150
  else
4518
- direction = new import_core13.Vector3();
5151
+ direction2 = new import_core14.Vector3();
4519
5152
  this.origin = origin;
4520
- this.direction = direction;
5153
+ this.direction = direction2;
5154
+ }
5155
+ at(t, result = new import_core14.Vector3()) {
5156
+ getRayPoint(this.origin, this.direction, t, result);
5157
+ return result;
5158
+ }
5159
+ closestPointTo(point2, result = new import_core14.Vector3()) {
5160
+ getClosestPointOnRay(point2, this.origin, this.direction, result);
5161
+ return result;
5162
+ }
5163
+ distanceTo(point2) {
5164
+ return distanceToRay(point2, this.origin, this.direction);
5165
+ }
5166
+ /** Transform and renormalize: subsequent parameters are distances in the new space. */
5167
+ transform(matrix) {
5168
+ const ray = transformRay(this.origin, this.direction, matrix);
5169
+ const normalized2 = normalizeQueryDirection(ray.direction, 3);
5170
+ this.origin.copy(ray.origin);
5171
+ this.direction.copy(normalized2);
5172
+ return this;
4521
5173
  }
4522
5174
  };
4523
5175
 
4524
5176
  // dist/culling/lib/shapes/implicit-shape.js
4525
- var import_core14 = require("@math.gl/core");
5177
+ var import_core15 = require("@math.gl/core");
4526
5178
  var ImplicitShapeBase = class {
4527
5179
  constructor(matrix) {
4528
- this.matrix = new import_core14.Matrix4();
5180
+ this.matrix = new import_core15.Matrix4();
4529
5181
  if (matrix)
4530
5182
  this.matrix.copy(matrix);
4531
5183
  validateAffineMatrix(this.matrix);
@@ -4540,23 +5192,23 @@ var ImplicitShapeBase = class {
4540
5192
  return true;
4541
5193
  }
4542
5194
  transform(transform) {
4543
- const next = new import_core14.Matrix4().copy(transform);
5195
+ const next = new import_core15.Matrix4().copy(transform);
4544
5196
  validateAffineMatrix(next);
4545
5197
  this.matrix.multiplyLeft(next);
4546
5198
  validateAffineMatrix(this.matrix);
4547
5199
  this.inverseMatrix.copy(this.matrix).invert();
4548
5200
  return this;
4549
5201
  }
4550
- containsPoint(point) {
4551
- return this.containsLocalPoint(this.inverseMatrix.transformAsPoint(point));
5202
+ containsPoint(point2) {
5203
+ return this.containsLocalPoint(this.inverseMatrix.transformAsPoint(point2));
4552
5204
  }
4553
- distanceSquaredTo(point) {
4554
- const distance = this.distanceTo(point);
5205
+ distanceSquaredTo(point2) {
5206
+ const distance = this.distanceTo(point2);
4555
5207
  return distance * distance;
4556
5208
  }
4557
5209
  /** Exact for rigid/uniform transforms; conservative estimate for non-uniform scale or shear. */
4558
- distanceTo(point) {
4559
- const localPoint = this.inverseMatrix.transformAsPoint(point);
5210
+ distanceTo(point2) {
5211
+ const localPoint = this.inverseMatrix.transformAsPoint(point2);
4560
5212
  const localDistance = this.distanceToLocalPoint(localPoint);
4561
5213
  const scales = this.matrix.getScale();
4562
5214
  return localDistance * Math.min(scales[0], scales[1], scales[2]);
@@ -4578,20 +5230,20 @@ var ImplicitShapeBase = class {
4578
5230
  const hit = this.intersectLocalRay(localOrigin, localDirection);
4579
5231
  if (!hit || hit.distance < 0)
4580
5232
  return void 0;
4581
- const point = new import_core14.Vector3(ray.direction).scale(hit.distance).add(ray.origin);
5233
+ const point2 = new import_core15.Vector3(ray.direction).scale(hit.distance).add(ray.origin);
4582
5234
  const inverse = this.inverseMatrix;
4583
- 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();
4584
- return { distance: hit.distance, point, normal, entering: ray.direction.dot(normal) < 0 };
5235
+ 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();
5236
+ return { distance: hit.distance, point: point2, normal, entering: ray.direction.dot(normal) < 0 };
4585
5237
  }
4586
5238
  getAxisAlignedBoundingBox() {
4587
- const minimum = new import_core14.Vector3();
4588
- const maximum = new import_core14.Vector3();
5239
+ const minimum = new import_core15.Vector3();
5240
+ const maximum = new import_core15.Vector3();
4589
5241
  for (let axis = 0; axis < 3; axis++) {
4590
- const direction = [0, 0, 0];
4591
- direction[axis] = 1;
4592
- maximum[axis] = this.getSupportPoint(direction)[axis];
4593
- direction[axis] = -1;
4594
- minimum[axis] = this.getSupportPoint(direction)[axis];
5242
+ const direction2 = [0, 0, 0];
5243
+ direction2[axis] = 1;
5244
+ maximum[axis] = this.getSupportPoint(direction2)[axis];
5245
+ direction2[axis] = -1;
5246
+ minimum[axis] = this.getSupportPoint(direction2)[axis];
4595
5247
  }
4596
5248
  return new AxisAlignedBoundingBox(minimum, maximum);
4597
5249
  }
@@ -4608,7 +5260,7 @@ var ImplicitShapeBase = class {
4608
5260
  matrix[4] * worldDirection[0] + matrix[5] * worldDirection[1] + matrix[6] * worldDirection[2],
4609
5261
  matrix[8] * worldDirection[0] + matrix[9] * worldDirection[1] + matrix[10] * worldDirection[2]
4610
5262
  ];
4611
- return new import_core14.Vector3(this.supportLocal(localDirection)).transform(this.matrix);
5263
+ return new import_core15.Vector3(this.supportLocal(localDirection)).transform(this.matrix);
4612
5264
  }
4613
5265
  };
4614
5266
  function validateAffineMatrix(matrix) {
@@ -4618,7 +5270,7 @@ function validateAffineMatrix(matrix) {
4618
5270
  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) {
4619
5271
  throw new Error("Shape matrix must be affine");
4620
5272
  }
4621
- if (Math.abs(new import_core14.Matrix4().copy(matrix).determinant()) < 1e-15)
5273
+ if (Math.abs(new import_core15.Matrix4().copy(matrix).determinant()) < 1e-15)
4622
5274
  throw new Error("Shape matrix must be invertible");
4623
5275
  }
4624
5276
  function solveQuadratic(a, b, c) {
@@ -4637,19 +5289,19 @@ function closestDistanceToSegment2D(px, py, ax, ay, bx, by) {
4637
5289
  const t = denominator ? Math.max(0, Math.min(1, ((px - ax) * dx + (py - ay) * dy) / denominator)) : 0;
4638
5290
  return Math.hypot(px - (ax + t * dx), py - (ay + t * dy));
4639
5291
  }
4640
- function closestDistanceToCircleArc2D(px, py, centerY, radius, minimumNormalY, maximumNormalY) {
4641
- if (radius === 0)
5292
+ function closestDistanceToCircleArc2D(px, py, centerY, radius2, minimumNormalY, maximumNormalY) {
5293
+ if (radius2 === 0)
4642
5294
  return Math.hypot(px, py - centerY);
4643
5295
  const dx = px;
4644
5296
  const dy = py - centerY;
4645
5297
  const length = Math.hypot(dx, dy);
4646
5298
  const normalY = length ? dy / length : 0;
4647
5299
  if (normalY >= minimumNormalY && normalY <= maximumNormalY) {
4648
- return Math.abs(length - radius);
5300
+ return Math.abs(length - radius2);
4649
5301
  }
4650
- const minimumRadius = radius * Math.sqrt(Math.max(0, 1 - minimumNormalY ** 2));
4651
- const maximumRadius = radius * Math.sqrt(Math.max(0, 1 - maximumNormalY ** 2));
4652
- return Math.min(Math.hypot(px - minimumRadius, py - (centerY + radius * minimumNormalY)), Math.hypot(px - maximumRadius, py - (centerY + radius * maximumNormalY)));
5302
+ const minimumRadius = radius2 * Math.sqrt(Math.max(0, 1 - minimumNormalY ** 2));
5303
+ const maximumRadius = radius2 * Math.sqrt(Math.max(0, 1 - maximumNormalY ** 2));
5304
+ return Math.min(Math.hypot(px - minimumRadius, py - (centerY + radius2 * minimumNormalY)), Math.hypot(px - maximumRadius, py - (centerY + radius2 * maximumNormalY)));
4653
5305
  }
4654
5306
 
4655
5307
  // dist/culling/lib/shapes/box-shape.js
@@ -4669,28 +5321,28 @@ var BoxShape = class _BoxShape extends ImplicitShapeBase {
4669
5321
  equals(shape) {
4670
5322
  return shape instanceof _BoxShape && super.equals(shape) && this.size.every((value, i) => value === shape.size[i]);
4671
5323
  }
4672
- containsLocalPoint(point) {
4673
- return point.every((value, i) => Math.abs(value) <= this.halfSize[i] + EPSILON);
5324
+ containsLocalPoint(point2) {
5325
+ return point2.every((value, i) => Math.abs(value) <= this.halfSize[i] + EPSILON);
4674
5326
  }
4675
- distanceToLocalPoint(point) {
4676
- return Math.hypot(...point.map((value, i) => Math.max(0, Math.abs(value) - this.halfSize[i])));
5327
+ distanceToLocalPoint(point2) {
5328
+ return Math.hypot(...point2.map((value, i) => Math.max(0, Math.abs(value) - this.halfSize[i])));
4677
5329
  }
4678
- supportLocal(direction) {
4679
- return direction.map((value, i) => value < 0 ? -this.halfSize[i] : this.halfSize[i]);
5330
+ supportLocal(direction2) {
5331
+ return direction2.map((value, i) => value < 0 ? -this.halfSize[i] : this.halfSize[i]);
4680
5332
  }
4681
- intersectLocalRay(origin, direction) {
5333
+ intersectLocalRay(origin, direction2) {
4682
5334
  let near = -Infinity;
4683
5335
  let far = Infinity;
4684
5336
  let nearAxis = 0;
4685
5337
  let farAxis = 0;
4686
5338
  for (let axis2 = 0; axis2 < 3; axis2++) {
4687
- if (Math.abs(direction[axis2]) < 1e-15) {
5339
+ if (Math.abs(direction2[axis2]) < 1e-15) {
4688
5340
  if (Math.abs(origin[axis2]) > this.halfSize[axis2])
4689
5341
  return void 0;
4690
5342
  continue;
4691
5343
  }
4692
- let t1 = (-this.halfSize[axis2] - origin[axis2]) / direction[axis2];
4693
- let t2 = (this.halfSize[axis2] - origin[axis2]) / direction[axis2];
5344
+ let t1 = (-this.halfSize[axis2] - origin[axis2]) / direction2[axis2];
5345
+ let t2 = (this.halfSize[axis2] - origin[axis2]) / direction2[axis2];
4694
5346
  if (t1 > t2)
4695
5347
  [t1, t2] = [t2, t1];
4696
5348
  if (t1 > near) {
@@ -4708,7 +5360,7 @@ var BoxShape = class _BoxShape extends ImplicitShapeBase {
4708
5360
  if (distance < 0 || !Number.isFinite(distance))
4709
5361
  return void 0;
4710
5362
  const axis = near >= 0 ? nearAxis : farAxis;
4711
- const pointCoordinate = origin[axis] + distance * direction[axis];
5363
+ const pointCoordinate = origin[axis] + distance * direction2[axis];
4712
5364
  const normal = [0, 0, 0];
4713
5365
  normal[axis] = pointCoordinate < 0 ? -1 : 1;
4714
5366
  return { distance, normal };
@@ -4742,74 +5394,74 @@ var CapsuleShape = class _CapsuleShape extends ImplicitShapeBase {
4742
5394
  equals(shape) {
4743
5395
  return shape instanceof _CapsuleShape && super.equals(shape) && this.height === shape.height && this.radiusBottom === shape.radiusBottom && this.radiusTop === shape.radiusTop;
4744
5396
  }
4745
- containsLocalPoint(point) {
5397
+ containsLocalPoint(point2) {
4746
5398
  const profile = this.getProfile();
4747
- const radial2 = Math.hypot(point[0], point[2]);
5399
+ const radial2 = Math.hypot(point2[0], point2[2]);
4748
5400
  if (profile.sphere)
4749
- return Math.hypot(radial2, point[1] - profile.sphere.center) <= profile.sphere.radius + EPSILON2;
4750
- if (point[1] < profile.bottom.y)
4751
- return Math.hypot(radial2, point[1] + this.height / 2) <= this.radiusBottom + EPSILON2;
4752
- if (point[1] > profile.top.y)
4753
- return Math.hypot(radial2, point[1] - this.height / 2) <= this.radiusTop + EPSILON2;
4754
- const t = (point[1] - profile.bottom.y) / (profile.top.y - profile.bottom.y);
5401
+ return Math.hypot(radial2, point2[1] - profile.sphere.center) <= profile.sphere.radius + EPSILON2;
5402
+ if (point2[1] < profile.bottom.y)
5403
+ return Math.hypot(radial2, point2[1] + this.height / 2) <= this.radiusBottom + EPSILON2;
5404
+ if (point2[1] > profile.top.y)
5405
+ return Math.hypot(radial2, point2[1] - this.height / 2) <= this.radiusTop + EPSILON2;
5406
+ const t = (point2[1] - profile.bottom.y) / (profile.top.y - profile.bottom.y);
4755
5407
  return radial2 <= profile.bottom.radius + (profile.top.radius - profile.bottom.radius) * t + EPSILON2;
4756
5408
  }
4757
- distanceToLocalPoint(point) {
4758
- if (this.containsLocalPoint(point))
5409
+ distanceToLocalPoint(point2) {
5410
+ if (this.containsLocalPoint(point2))
4759
5411
  return 0;
4760
5412
  const profile = this.getProfile();
4761
- const radial2 = Math.hypot(point[0], point[2]);
5413
+ const radial2 = Math.hypot(point2[0], point2[2]);
4762
5414
  if (profile.sphere)
4763
- return Math.max(0, Math.hypot(radial2, point[1] - profile.sphere.center) - profile.sphere.radius);
5415
+ return Math.max(0, Math.hypot(radial2, point2[1] - profile.sphere.center) - profile.sphere.radius);
4764
5416
  const delta = this.radiusTop - this.radiusBottom;
4765
5417
  const sideNormalY = -delta / this.height;
4766
- const bottomArc = closestDistanceToCircleArc2D(radial2, point[1], -this.height / 2, this.radiusBottom, -1, sideNormalY);
4767
- const topArc = closestDistanceToCircleArc2D(radial2, point[1], this.height / 2, this.radiusTop, sideNormalY, 1);
4768
- const side = closestDistanceToSegment2D(radial2, point[1], profile.bottom.radius, profile.bottom.y, profile.top.radius, profile.top.y);
5418
+ const bottomArc = closestDistanceToCircleArc2D(radial2, point2[1], -this.height / 2, this.radiusBottom, -1, sideNormalY);
5419
+ const topArc = closestDistanceToCircleArc2D(radial2, point2[1], this.height / 2, this.radiusTop, sideNormalY, 1);
5420
+ const side = closestDistanceToSegment2D(radial2, point2[1], profile.bottom.radius, profile.bottom.y, profile.top.radius, profile.top.y);
4769
5421
  return Math.min(bottomArc, topArc, side);
4770
5422
  }
4771
- supportLocal(direction) {
4772
- const length = Math.hypot(...direction);
4773
- const unit = length ? direction.map((value) => value / length) : [1, 0, 0];
5423
+ supportLocal(direction2) {
5424
+ const length = Math.hypot(...direction2);
5425
+ const unit2 = length ? direction2.map((value) => value / length) : [1, 0, 0];
4774
5426
  const bottom = [
4775
- unit[0] * this.radiusBottom,
4776
- -this.height / 2 + unit[1] * this.radiusBottom,
4777
- unit[2] * this.radiusBottom
5427
+ unit2[0] * this.radiusBottom,
5428
+ -this.height / 2 + unit2[1] * this.radiusBottom,
5429
+ unit2[2] * this.radiusBottom
4778
5430
  ];
4779
5431
  const top = [
4780
- unit[0] * this.radiusTop,
4781
- this.height / 2 + unit[1] * this.radiusTop,
4782
- unit[2] * this.radiusTop
5432
+ unit2[0] * this.radiusTop,
5433
+ this.height / 2 + unit2[1] * this.radiusTop,
5434
+ unit2[2] * this.radiusTop
4783
5435
  ];
4784
- return dot(top, direction) >= dot(bottom, direction) ? top : bottom;
5436
+ return dot4(top, direction2) >= dot4(bottom, direction2) ? top : bottom;
4785
5437
  }
4786
- intersectLocalRay(origin, direction) {
5438
+ intersectLocalRay(origin, direction2) {
4787
5439
  const profile = this.getProfile();
4788
5440
  if (profile.sphere)
4789
- return intersectSphere(origin, direction, profile.sphere.center, profile.sphere.radius);
5441
+ return intersectSphere(origin, direction2, profile.sphere.center, profile.sphere.radius);
4790
5442
  const candidates = [];
4791
5443
  const slope = (profile.top.radius - profile.bottom.radius) / (profile.top.y - profile.bottom.y);
4792
5444
  const intercept = profile.bottom.radius - slope * profile.bottom.y;
4793
5445
  const radialAtOrigin = intercept + slope * origin[1];
4794
- const radialAlongRay = slope * direction[1];
4795
- 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)) {
4796
- const y = origin[1] + distance * direction[1];
5446
+ const radialAlongRay = slope * direction2[1];
5447
+ 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)) {
5448
+ const y = origin[1] + distance * direction2[1];
4797
5449
  if (distance >= 0 && y >= profile.bottom.y - EPSILON2 && y <= profile.top.y + EPSILON2) {
4798
- const x = origin[0] + distance * direction[0];
4799
- const z = origin[2] + distance * direction[2];
5450
+ const x = origin[0] + distance * direction2[0];
5451
+ const z = origin[2] + distance * direction2[2];
4800
5452
  const radial2 = Math.hypot(x, z) || 1;
4801
5453
  const normal = [x / radial2, -slope, z / radial2];
4802
5454
  const length = Math.hypot(...normal);
4803
5455
  candidates.push({ distance, normal: normal.map((value) => value / length) });
4804
5456
  }
4805
5457
  }
4806
- for (const bottomHit of intersectSphereRoots(origin, direction, -this.height / 2, this.radiusBottom)) {
4807
- const y = origin[1] + bottomHit.distance * direction[1];
5458
+ for (const bottomHit of intersectSphereRoots(origin, direction2, -this.height / 2, this.radiusBottom)) {
5459
+ const y = origin[1] + bottomHit.distance * direction2[1];
4808
5460
  if (y <= profile.bottom.y + EPSILON2)
4809
5461
  candidates.push(bottomHit);
4810
5462
  }
4811
- for (const topHit of intersectSphereRoots(origin, direction, this.height / 2, this.radiusTop)) {
4812
- const y = origin[1] + topHit.distance * direction[1];
5463
+ for (const topHit of intersectSphereRoots(origin, direction2, this.height / 2, this.radiusTop)) {
5464
+ const y = origin[1] + topHit.distance * direction2[1];
4813
5465
  if (y >= profile.top.y - EPSILON2)
4814
5466
  candidates.push(topHit);
4815
5467
  }
@@ -4840,19 +5492,19 @@ var CapsuleShape = class _CapsuleShape extends ImplicitShapeBase {
4840
5492
  };
4841
5493
  }
4842
5494
  };
4843
- function intersectSphere(origin, direction, centerY, radius) {
4844
- return intersectSphereRoots(origin, direction, centerY, radius)[0];
5495
+ function intersectSphere(origin, direction2, centerY, radius2) {
5496
+ return intersectSphereRoots(origin, direction2, centerY, radius2)[0];
4845
5497
  }
4846
- function intersectSphereRoots(origin, direction, centerY, radius) {
4847
- if (radius === 0)
5498
+ function intersectSphereRoots(origin, direction2, centerY, radius2) {
5499
+ if (radius2 === 0)
4848
5500
  return [];
4849
5501
  const relative = [origin[0], origin[1] - centerY, origin[2]];
4850
- return solveQuadratic(dot(direction, direction), 2 * dot(relative, direction), dot(relative, relative) - radius * radius).filter((distance) => distance >= 0).map((distance) => ({
5502
+ return solveQuadratic(dot4(direction2, direction2), 2 * dot4(relative, direction2), dot4(relative, relative) - radius2 * radius2).filter((distance) => distance >= 0).map((distance) => ({
4851
5503
  distance,
4852
- normal: relative.map((value, i) => (value + distance * direction[i]) / radius)
5504
+ normal: relative.map((value, i) => (value + distance * direction2[i]) / radius2)
4853
5505
  }));
4854
5506
  }
4855
- function dot(a, b) {
5507
+ function dot4(a, b) {
4856
5508
  return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
4857
5509
  }
4858
5510
 
@@ -4883,61 +5535,61 @@ var CylinderShape = class _CylinderShape extends ImplicitShapeBase {
4883
5535
  equals(shape) {
4884
5536
  return shape instanceof _CylinderShape && super.equals(shape) && this.height === shape.height && this.radiusBottom === shape.radiusBottom && this.radiusTop === shape.radiusTop;
4885
5537
  }
4886
- containsLocalPoint(point) {
5538
+ containsLocalPoint(point2) {
4887
5539
  const half = this.height / 2;
4888
- if (point[1] < -half - EPSILON3 || point[1] > half + EPSILON3)
5540
+ if (point2[1] < -half - EPSILON3 || point2[1] > half + EPSILON3)
4889
5541
  return false;
4890
- const t = (point[1] + half) / this.height;
4891
- const radius = this.radiusBottom + (this.radiusTop - this.radiusBottom) * t;
4892
- return Math.hypot(point[0], point[2]) <= radius + EPSILON3;
5542
+ const t = (point2[1] + half) / this.height;
5543
+ const radius2 = this.radiusBottom + (this.radiusTop - this.radiusBottom) * t;
5544
+ return Math.hypot(point2[0], point2[2]) <= radius2 + EPSILON3;
4893
5545
  }
4894
- distanceToLocalPoint(point) {
4895
- if (this.containsLocalPoint(point))
5546
+ distanceToLocalPoint(point2) {
5547
+ if (this.containsLocalPoint(point2))
4896
5548
  return 0;
4897
- const radial2 = Math.hypot(point[0], point[2]);
5549
+ const radial2 = Math.hypot(point2[0], point2[2]);
4898
5550
  const half = this.height / 2;
4899
- const side = closestDistanceToSegment2D(radial2, point[1], this.radiusBottom, -half, this.radiusTop, half);
4900
- const bottom = closestDistanceToSegment2D(radial2, point[1], 0, -half, this.radiusBottom, -half);
4901
- const top = closestDistanceToSegment2D(radial2, point[1], 0, half, this.radiusTop, half);
5551
+ const side = closestDistanceToSegment2D(radial2, point2[1], this.radiusBottom, -half, this.radiusTop, half);
5552
+ const bottom = closestDistanceToSegment2D(radial2, point2[1], 0, -half, this.radiusBottom, -half);
5553
+ const top = closestDistanceToSegment2D(radial2, point2[1], 0, half, this.radiusTop, half);
4902
5554
  return Math.min(side, bottom, top);
4903
5555
  }
4904
- supportLocal(direction) {
4905
- const radialLength = Math.hypot(direction[0], direction[2]);
4906
- const x = radialLength ? direction[0] / radialLength : 1;
4907
- const z = radialLength ? direction[2] / radialLength : 0;
5556
+ supportLocal(direction2) {
5557
+ const radialLength = Math.hypot(direction2[0], direction2[2]);
5558
+ const x = radialLength ? direction2[0] / radialLength : 1;
5559
+ const z = radialLength ? direction2[2] / radialLength : 0;
4908
5560
  const half = this.height / 2;
4909
- const bottomValue = radialLength * this.radiusBottom - direction[1] * half;
4910
- const topValue = radialLength * this.radiusTop + direction[1] * half;
5561
+ const bottomValue = radialLength * this.radiusBottom - direction2[1] * half;
5562
+ const topValue = radialLength * this.radiusTop + direction2[1] * half;
4911
5563
  return topValue >= bottomValue ? [x * this.radiusTop, half, z * this.radiusTop] : [x * this.radiusBottom, -half, z * this.radiusBottom];
4912
5564
  }
4913
- intersectLocalRay(origin, direction) {
5565
+ intersectLocalRay(origin, direction2) {
4914
5566
  const half = this.height / 2;
4915
5567
  const slope = (this.radiusTop - this.radiusBottom) / this.height;
4916
5568
  const intercept = (this.radiusTop + this.radiusBottom) / 2;
4917
5569
  const radialAtOrigin = intercept + slope * origin[1];
4918
- const radialAlongRay = slope * direction[1];
5570
+ const radialAlongRay = slope * direction2[1];
4919
5571
  const candidates = [];
4920
- 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);
5572
+ 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);
4921
5573
  for (const distance of roots) {
4922
- const y = origin[1] + distance * direction[1];
5574
+ const y = origin[1] + distance * direction2[1];
4923
5575
  if (distance >= 0 && y >= -half - EPSILON3 && y <= half + EPSILON3) {
4924
- const x = origin[0] + distance * direction[0];
4925
- const z = origin[2] + distance * direction[2];
5576
+ const x = origin[0] + distance * direction2[0];
5577
+ const z = origin[2] + distance * direction2[2];
4926
5578
  const radial2 = Math.hypot(x, z) || 1;
4927
5579
  const normal = [x / radial2, -slope, z / radial2];
4928
5580
  const length = Math.hypot(...normal);
4929
5581
  candidates.push({ distance, normal: normal.map((value) => value / length) });
4930
5582
  }
4931
5583
  }
4932
- if (Math.abs(direction[1]) > 1e-15) {
4933
- for (const [y, radius, normalY] of [
5584
+ if (Math.abs(direction2[1]) > 1e-15) {
5585
+ for (const [y, radius2, normalY] of [
4934
5586
  [-half, this.radiusBottom, -1],
4935
5587
  [half, this.radiusTop, 1]
4936
5588
  ]) {
4937
- const distance = (y - origin[1]) / direction[1];
4938
- const x = origin[0] + distance * direction[0];
4939
- const z = origin[2] + distance * direction[2];
4940
- if (distance >= 0 && Math.hypot(x, z) <= radius + EPSILON3)
5589
+ const distance = (y - origin[1]) / direction2[1];
5590
+ const x = origin[0] + distance * direction2[0];
5591
+ const z = origin[2] + distance * direction2[2];
5592
+ if (distance >= 0 && Math.hypot(x, z) <= radius2 + EPSILON3)
4941
5593
  candidates.push({ distance, normal: [0, normalY, 0] });
4942
5594
  }
4943
5595
  }
@@ -4946,7 +5598,7 @@ var CylinderShape = class _CylinderShape extends ImplicitShapeBase {
4946
5598
  };
4947
5599
 
4948
5600
  // dist/culling/lib/shapes/plane-shape.js
4949
- var import_core15 = require("@math.gl/core");
5601
+ var import_core16 = require("@math.gl/core");
4950
5602
  var PlaneShape = class _PlaneShape extends ImplicitShapeBase {
4951
5603
  constructor(props = {}) {
4952
5604
  super(props.matrix);
@@ -4964,23 +5616,23 @@ var PlaneShape = class _PlaneShape extends ImplicitShapeBase {
4964
5616
  equals(shape) {
4965
5617
  return shape instanceof _PlaneShape && super.equals(shape) && this.sizeX === shape.sizeX && this.sizeZ === shape.sizeZ;
4966
5618
  }
4967
- containsLocalPoint(point) {
4968
- return point[1] <= 1e-12;
5619
+ containsLocalPoint(point2) {
5620
+ return point2[1] <= 1e-12;
4969
5621
  }
4970
- distanceToLocalPoint(point) {
4971
- return Math.max(0, point[1]);
5622
+ distanceToLocalPoint(point2) {
5623
+ return Math.max(0, point2[1]);
4972
5624
  }
4973
5625
  supportLocal() {
4974
5626
  throw new Error("An unbounded plane half-space has no finite support point");
4975
5627
  }
4976
- intersectLocalRay(origin, direction) {
4977
- if (Math.abs(direction[1]) < 1e-15)
5628
+ intersectLocalRay(origin, direction2) {
5629
+ if (Math.abs(direction2[1]) < 1e-15)
4978
5630
  return void 0;
4979
- const distance = -origin[1] / direction[1];
5631
+ const distance = -origin[1] / direction2[1];
4980
5632
  if (distance < 0)
4981
5633
  return void 0;
4982
- const x = origin[0] + distance * direction[0];
4983
- const z = origin[2] + distance * direction[2];
5634
+ const x = origin[0] + distance * direction2[0];
5635
+ const z = origin[2] + distance * direction2[2];
4984
5636
  if (this.sizeX !== void 0 && Math.abs(x) > this.sizeX / 2 + 1e-12)
4985
5637
  return void 0;
4986
5638
  if (this.sizeZ !== void 0 && Math.abs(z) > this.sizeZ / 2 + 1e-12)
@@ -4988,9 +5640,9 @@ var PlaneShape = class _PlaneShape extends ImplicitShapeBase {
4988
5640
  return { distance, normal: [0, 1, 0] };
4989
5641
  }
4990
5642
  intersectPlane(plane) {
4991
- const boundaryPoint = new import_core15.Vector3(0, 0, 0).transform(this.matrix);
5643
+ const boundaryPoint = new import_core16.Vector3(0, 0, 0).transform(this.matrix);
4992
5644
  const inverse = this.inverseMatrix;
4993
- const boundaryNormal = new import_core15.Vector3(inverse[1], inverse[5], inverse[9]).normalize();
5645
+ const boundaryNormal = new import_core16.Vector3(inverse[1], inverse[5], inverse[9]).normalize();
4994
5646
  const alignment = boundaryNormal.dot(plane.normal);
4995
5647
  if (Math.abs(Math.abs(alignment) - 1) > 1e-10)
4996
5648
  return "intersecting";
@@ -5025,36 +5677,36 @@ var SphereShape = class _SphereShape extends ImplicitShapeBase {
5025
5677
  equals(shape) {
5026
5678
  return shape instanceof _SphereShape && super.equals(shape) && this.radius === shape.radius;
5027
5679
  }
5028
- containsLocalPoint(point) {
5029
- return Math.hypot(...point) <= this.radius + EPSILON4;
5680
+ containsLocalPoint(point2) {
5681
+ return Math.hypot(...point2) <= this.radius + EPSILON4;
5030
5682
  }
5031
- distanceToLocalPoint(point) {
5032
- return Math.max(0, Math.hypot(...point) - this.radius);
5683
+ distanceToLocalPoint(point2) {
5684
+ return Math.max(0, Math.hypot(...point2) - this.radius);
5033
5685
  }
5034
- supportLocal(direction) {
5035
- const length = Math.hypot(...direction);
5036
- return length ? direction.map((value) => value / length * this.radius) : [this.radius, 0, 0];
5686
+ supportLocal(direction2) {
5687
+ const length = Math.hypot(...direction2);
5688
+ return length ? direction2.map((value) => value / length * this.radius) : [this.radius, 0, 0];
5037
5689
  }
5038
- intersectLocalRay(origin, direction) {
5039
- const roots = solveQuadratic(dot2(direction, direction), 2 * dot2(origin, direction), dot2(origin, origin) - this.radius * this.radius);
5690
+ intersectLocalRay(origin, direction2) {
5691
+ const roots = solveQuadratic(dot5(direction2, direction2), 2 * dot5(origin, direction2), dot5(origin, origin) - this.radius * this.radius);
5040
5692
  const distance = roots.find((value) => value >= 0);
5041
5693
  if (distance === void 0)
5042
5694
  return void 0;
5043
- const point = origin.map((value, i) => value + distance * direction[i]);
5044
- return { distance, normal: point.map((value) => value / this.radius) };
5695
+ const point2 = origin.map((value, i) => value + distance * direction2[i]);
5696
+ return { distance, normal: point2.map((value) => value / this.radius) };
5045
5697
  }
5046
5698
  };
5047
- function dot2(a, b) {
5699
+ function dot5(a, b) {
5048
5700
  return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
5049
5701
  }
5050
5702
 
5051
5703
  // dist/culling/lib/perspective-off-center-frustum.js
5052
- var import_core16 = require("@math.gl/core");
5053
- var scratchPlaneUpVector = new import_core16.Vector3();
5054
- var scratchPlaneRightVector = new import_core16.Vector3();
5055
- var scratchPlaneNearCenter = new import_core16.Vector3();
5056
- var scratchPlaneFarCenter = new import_core16.Vector3();
5057
- var scratchPlaneNormal2 = new import_core16.Vector3();
5704
+ var import_core17 = require("@math.gl/core");
5705
+ var scratchPlaneUpVector = new import_core17.Vector3();
5706
+ var scratchPlaneRightVector = new import_core17.Vector3();
5707
+ var scratchPlaneNearCenter = new import_core17.Vector3();
5708
+ var scratchPlaneFarCenter = new import_core17.Vector3();
5709
+ var scratchPlaneNormal2 = new import_core17.Vector3();
5058
5710
  var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
5059
5711
  /**
5060
5712
  * The viewing frustum is defined by 6 planes.
@@ -5085,8 +5737,8 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
5085
5737
  new Plane(),
5086
5738
  new Plane()
5087
5739
  ]);
5088
- this._perspectiveMatrix = new import_core16.Matrix4();
5089
- this._infinitePerspective = new import_core16.Matrix4();
5740
+ this._perspectiveMatrix = new import_core17.Matrix4();
5741
+ this._infinitePerspective = new import_core17.Matrix4();
5090
5742
  const { near = 1, far = 5e8 } = options;
5091
5743
  this.left = options.left;
5092
5744
  this._left = void 0;
@@ -5156,15 +5808,15 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
5156
5808
  * const intersect = cullingVolume.computeVisibility(boundingVolume);
5157
5809
  */
5158
5810
  // eslint-disable-next-line complexity, max-statements
5159
- computeCullingVolume(position, direction, up) {
5160
- (0, import_core16.assert)(position, "position is required.");
5161
- (0, import_core16.assert)(direction, "direction is required.");
5162
- (0, import_core16.assert)(up, "up is required.");
5811
+ computeCullingVolume(position, direction2, up) {
5812
+ (0, import_core17.assert)(position, "position is required.");
5813
+ (0, import_core17.assert)(direction2, "direction is required.");
5814
+ (0, import_core17.assert)(up, "up is required.");
5163
5815
  const planes = this._cullingVolume.planes;
5164
5816
  up = scratchPlaneUpVector.copy(up).normalize();
5165
- const right = scratchPlaneRightVector.copy(direction).cross(up).normalize();
5166
- const nearCenter = scratchPlaneNearCenter.copy(direction).multiplyByScalar(this.near).add(position);
5167
- const farCenter = scratchPlaneFarCenter.copy(direction).multiplyByScalar(this.far).add(position);
5817
+ const right = scratchPlaneRightVector.copy(direction2).cross(up).normalize();
5818
+ const nearCenter = scratchPlaneNearCenter.copy(direction2).multiplyByScalar(this.near).add(position);
5819
+ const farCenter = scratchPlaneFarCenter.copy(direction2).multiplyByScalar(this.far).add(position);
5168
5820
  let normal = scratchPlaneNormal2;
5169
5821
  normal.copy(right).multiplyByScalar(this.left).add(nearCenter).subtract(position).cross(up);
5170
5822
  planes[0].fromPointNormal(position, normal);
@@ -5174,7 +5826,7 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
5174
5826
  planes[2].fromPointNormal(position, normal);
5175
5827
  normal.copy(up).multiplyByScalar(this.top).add(nearCenter).subtract(position).cross(right);
5176
5828
  planes[3].fromPointNormal(position, normal);
5177
- normal = new import_core16.Vector3().copy(direction);
5829
+ normal = new import_core17.Vector3().copy(direction2);
5178
5830
  planes[4].fromPointNormal(nearCenter, normal);
5179
5831
  normal.negate();
5180
5832
  planes[5].fromPointNormal(farCenter, normal);
@@ -5206,11 +5858,11 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
5206
5858
  */
5207
5859
  getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {
5208
5860
  this._update();
5209
- (0, import_core16.assert)(Number.isFinite(drawingBufferWidth) && Number.isFinite(drawingBufferHeight));
5210
- (0, import_core16.assert)(drawingBufferWidth > 0);
5211
- (0, import_core16.assert)(drawingBufferHeight > 0);
5212
- (0, import_core16.assert)(distance > 0);
5213
- (0, import_core16.assert)(result);
5861
+ (0, import_core17.assert)(Number.isFinite(drawingBufferWidth) && Number.isFinite(drawingBufferHeight));
5862
+ (0, import_core17.assert)(drawingBufferWidth > 0);
5863
+ (0, import_core17.assert)(drawingBufferHeight > 0);
5864
+ (0, import_core17.assert)(distance > 0);
5865
+ (0, import_core17.assert)(result);
5214
5866
  const inverseNear = 1 / this.near;
5215
5867
  let tanTheta = this.top * inverseNear;
5216
5868
  const pixelHeight = 2 * distance * tanTheta / drawingBufferHeight;
@@ -5222,17 +5874,17 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
5222
5874
  }
5223
5875
  // eslint-disable-next-line complexity, max-statements
5224
5876
  _update() {
5225
- (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));
5877
+ (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));
5226
5878
  const { top, bottom, right, left, near, far } = this;
5227
5879
  if (top !== this._top || bottom !== this._bottom || left !== this._left || right !== this._right || near !== this._near || far !== this._far) {
5228
- (0, import_core16.assert)(this.near > 0 && this.near < this.far, "near must be greater than zero and less than far.");
5880
+ (0, import_core17.assert)(this.near > 0 && this.near < this.far, "near must be greater than zero and less than far.");
5229
5881
  this._left = left;
5230
5882
  this._right = right;
5231
5883
  this._top = top;
5232
5884
  this._bottom = bottom;
5233
5885
  this._near = near;
5234
5886
  this._far = far;
5235
- this._perspectiveMatrix = new import_core16.Matrix4().frustum({
5887
+ this._perspectiveMatrix = new import_core17.Matrix4().frustum({
5236
5888
  left,
5237
5889
  right,
5238
5890
  bottom,
@@ -5240,7 +5892,7 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
5240
5892
  near,
5241
5893
  far
5242
5894
  });
5243
- this._infinitePerspective = new import_core16.Matrix4().frustum({
5895
+ this._infinitePerspective = new import_core17.Matrix4().frustum({
5244
5896
  left,
5245
5897
  right,
5246
5898
  bottom,
@@ -5253,7 +5905,7 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
5253
5905
  };
5254
5906
 
5255
5907
  // dist/culling/lib/perspective-frustum.js
5256
- var import_core17 = require("@math.gl/core");
5908
+ var import_core18 = require("@math.gl/core");
5257
5909
  var defined = (val) => val !== null && typeof val !== "undefined";
5258
5910
  var PerspectiveFrustum = class _PerspectiveFrustum {
5259
5911
  constructor(options = {}) {
@@ -5326,9 +5978,9 @@ var PerspectiveFrustum = class _PerspectiveFrustum {
5326
5978
  * var cullingVolume = this.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);
5327
5979
  * var intersect = cullingVolume.computeVisibility(boundingVolume);
5328
5980
  */
5329
- computeCullingVolume(position, direction, up) {
5981
+ computeCullingVolume(position, direction2, up) {
5330
5982
  this._update();
5331
- return this._offCenterFrustum.computeCullingVolume(position, direction, up);
5983
+ return this._offCenterFrustum.computeCullingVolume(position, direction2, up);
5332
5984
  }
5333
5985
  /**
5334
5986
  * Returns the pixel's width and height in meters.
@@ -5355,16 +6007,16 @@ var PerspectiveFrustum = class _PerspectiveFrustum {
5355
6007
  */
5356
6008
  getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {
5357
6009
  this._update();
5358
- return this._offCenterFrustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result || new import_core17.Vector2());
6010
+ return this._offCenterFrustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result || new import_core18.Vector2());
5359
6011
  }
5360
6012
  // eslint-disable-next-line complexity, max-statements
5361
6013
  _update() {
5362
- (0, import_core17.assert)(Number.isFinite(this.fov) && Number.isFinite(this.aspectRatio) && Number.isFinite(this.near) && Number.isFinite(this.far));
6014
+ (0, import_core18.assert)(Number.isFinite(this.fov) && Number.isFinite(this.aspectRatio) && Number.isFinite(this.near) && Number.isFinite(this.far));
5363
6015
  const f = this._offCenterFrustum;
5364
6016
  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) {
5365
- (0, import_core17.assert)(this.fov >= 0 && this.fov < Math.PI);
5366
- (0, import_core17.assert)(this.aspectRatio > 0);
5367
- (0, import_core17.assert)(this.near >= 0 && this.near < this.far);
6017
+ (0, import_core18.assert)(this.fov >= 0 && this.fov < Math.PI);
6018
+ (0, import_core18.assert)(this.aspectRatio > 0);
6019
+ (0, import_core18.assert)(this.near >= 0 && this.near < this.far);
5368
6020
  this._aspectRatio = this.aspectRatio;
5369
6021
  this._fov = this.fov;
5370
6022
  this._fovy = this.aspectRatio <= 1 ? this.fov : Math.atan(Math.tan(this.fov * 0.5) / this.aspectRatio) * 2;
@@ -5388,19 +6040,19 @@ var PerspectiveFrustum = class _PerspectiveFrustum {
5388
6040
  };
5389
6041
 
5390
6042
  // dist/culling/lib/algorithms/bounding-sphere-from-points.js
5391
- var import_core18 = require("@math.gl/core");
5392
- var fromPointsXMin = new import_core18.Vector3();
5393
- var fromPointsYMin = new import_core18.Vector3();
5394
- var fromPointsZMin = new import_core18.Vector3();
5395
- var fromPointsXMax = new import_core18.Vector3();
5396
- var fromPointsYMax = new import_core18.Vector3();
5397
- var fromPointsZMax = new import_core18.Vector3();
5398
- var fromPointsCurrentPos = new import_core18.Vector3();
5399
- var fromPointsScratch = new import_core18.Vector3();
5400
- var fromPointsRitterCenter = new import_core18.Vector3();
5401
- var fromPointsMinBoxPt = new import_core18.Vector3();
5402
- var fromPointsMaxBoxPt = new import_core18.Vector3();
5403
- var fromPointsNaiveCenterScratch = new import_core18.Vector3();
6043
+ var import_core19 = require("@math.gl/core");
6044
+ var fromPointsXMin = new import_core19.Vector3();
6045
+ var fromPointsYMin = new import_core19.Vector3();
6046
+ var fromPointsZMin = new import_core19.Vector3();
6047
+ var fromPointsXMax = new import_core19.Vector3();
6048
+ var fromPointsYMax = new import_core19.Vector3();
6049
+ var fromPointsZMax = new import_core19.Vector3();
6050
+ var fromPointsCurrentPos = new import_core19.Vector3();
6051
+ var fromPointsScratch = new import_core19.Vector3();
6052
+ var fromPointsRitterCenter = new import_core19.Vector3();
6053
+ var fromPointsMinBoxPt = new import_core19.Vector3();
6054
+ var fromPointsMaxBoxPt = new import_core19.Vector3();
6055
+ var fromPointsNaiveCenterScratch = new import_core19.Vector3();
5404
6056
  function makeBoundingSphereFromPoints(positions, result = new BoundingSphere()) {
5405
6057
  if (!positions || positions.length === 0) {
5406
6058
  return result.fromCenterRadius([0, 0, 0], 0);
@@ -5496,17 +6148,17 @@ function makeBoundingSphereFromPoints(positions, result = new BoundingSphere())
5496
6148
  }
5497
6149
 
5498
6150
  // dist/culling/lib/algorithms/bounding-box-from-points.js
5499
- var import_core20 = require("@math.gl/core");
6151
+ var import_core21 = require("@math.gl/core");
5500
6152
 
5501
6153
  // dist/culling/lib/algorithms/compute-eigen-decomposition.js
5502
- var import_core19 = require("@math.gl/core");
5503
- var scratchMatrix = new import_core19.Matrix3();
5504
- var scratchUnitary = new import_core19.Matrix3();
5505
- var scratchDiagonal = new import_core19.Matrix3();
5506
- var jMatrix = new import_core19.Matrix3();
5507
- var jMatrixTranspose = new import_core19.Matrix3();
6154
+ var import_core20 = require("@math.gl/core");
6155
+ var scratchMatrix = new import_core20.Matrix3();
6156
+ var scratchUnitary = new import_core20.Matrix3();
6157
+ var scratchDiagonal = new import_core20.Matrix3();
6158
+ var jMatrix = new import_core20.Matrix3();
6159
+ var jMatrixTranspose = new import_core20.Matrix3();
5508
6160
  function computeEigenDecomposition(matrix, result = {}) {
5509
- const EIGEN_TOLERANCE = import_core19._MathUtils.EPSILON20;
6161
+ const EIGEN_TOLERANCE = import_core20._MathUtils.EPSILON20;
5510
6162
  const EIGEN_MAX_SWEEPS = 10;
5511
6163
  let count = 0;
5512
6164
  let sweep = 0;
@@ -5549,7 +6201,7 @@ function offDiagonalFrobeniusNorm(matrix) {
5549
6201
  return Math.sqrt(norm);
5550
6202
  }
5551
6203
  function shurDecomposition(matrix, result) {
5552
- const tolerance = import_core19._MathUtils.EPSILON15;
6204
+ const tolerance = import_core20._MathUtils.EPSILON15;
5553
6205
  let maxDiagonal = 0;
5554
6206
  let rotAxis = 1;
5555
6207
  for (let i = 0; i < 3; ++i) {
@@ -5577,7 +6229,7 @@ function shurDecomposition(matrix, result) {
5577
6229
  c = 1 / Math.sqrt(1 + t * t);
5578
6230
  s = t * c;
5579
6231
  }
5580
- import_core19.Matrix3.IDENTITY.to(result);
6232
+ import_core20.Matrix3.IDENTITY.to(result);
5581
6233
  result[scratchMatrix.getElementIndex(p, p)] = result[scratchMatrix.getElementIndex(q, q)] = c;
5582
6234
  result[scratchMatrix.getElementIndex(q, p)] = s;
5583
6235
  result[scratchMatrix.getElementIndex(p, q)] = -s;
@@ -5585,24 +6237,24 @@ function shurDecomposition(matrix, result) {
5585
6237
  }
5586
6238
 
5587
6239
  // dist/culling/lib/algorithms/bounding-box-from-points.js
5588
- var scratchVector23 = new import_core20.Vector3();
5589
- var scratchVector33 = new import_core20.Vector3();
5590
- var scratchVector42 = new import_core20.Vector3();
5591
- var scratchVector5 = new import_core20.Vector3();
5592
- var scratchVector6 = new import_core20.Vector3();
5593
- var scratchCovarianceResult = new import_core20.Matrix3();
6240
+ var scratchVector23 = new import_core21.Vector3();
6241
+ var scratchVector33 = new import_core21.Vector3();
6242
+ var scratchVector42 = new import_core21.Vector3();
6243
+ var scratchVector5 = new import_core21.Vector3();
6244
+ var scratchVector6 = new import_core21.Vector3();
6245
+ var scratchCovarianceResult = new import_core21.Matrix3();
5594
6246
  var scratchEigenResult = {
5595
- diagonal: new import_core20.Matrix3(),
5596
- unitary: new import_core20.Matrix3()
6247
+ diagonal: new import_core21.Matrix3(),
6248
+ unitary: new import_core21.Matrix3()
5597
6249
  };
5598
6250
  function makeOrientedBoundingBoxFromPoints(positions, result = new OrientedBoundingBox()) {
5599
6251
  if (!positions || positions.length === 0) {
5600
- result.halfAxes = new import_core20.Matrix3([0, 0, 0, 0, 0, 0, 0, 0, 0]);
5601
- result.center = new import_core20.Vector3();
6252
+ result.halfAxes = new import_core21.Matrix3([0, 0, 0, 0, 0, 0, 0, 0, 0]);
6253
+ result.center = new import_core21.Vector3();
5602
6254
  return result;
5603
6255
  }
5604
6256
  const length = positions.length;
5605
- const meanPoint = new import_core20.Vector3(0, 0, 0);
6257
+ const meanPoint = new import_core21.Vector3(0, 0, 0);
5606
6258
  for (const position of positions) {
5607
6259
  meanPoint.add(position);
5608
6260
  }
@@ -5664,7 +6316,7 @@ function makeOrientedBoundingBoxFromPoints(positions, result = new OrientedBound
5664
6316
  v3 = v3.multiplyByScalar(0.5 * (l3 + u3));
5665
6317
  result.center.copy(v1).add(v2).add(v3);
5666
6318
  const scale = scratchVector33.set(u1 - l1, u2 - l2, u3 - l3).multiplyByScalar(0.5);
5667
- const scaleMatrix = new import_core20.Matrix3([scale[0], 0, 0, 0, scale[1], 0, 0, 0, scale[2]]);
6319
+ const scaleMatrix = new import_core21.Matrix3([scale[0], 0, 0, 0, scale[1], 0, 0, 0, scale[2]]);
5668
6320
  result.halfAxes.multiplyRight(scaleMatrix);
5669
6321
  return result;
5670
6322
  }
@@ -5700,245 +6352,6 @@ function makeAxisAlignedBoundingBoxFromPoints(positions, result = new AxisAligne
5700
6352
  return result;
5701
6353
  }
5702
6354
 
5703
- // dist/culling/queries.js
5704
- function validateQueryPoint(point, dimension) {
5705
- if (point.length !== dimension)
5706
- throw new RangeError("Query dimension must match the index");
5707
- for (let i = 0; i < dimension; i++) {
5708
- if (!Number.isFinite(point[i]))
5709
- throw new RangeError("Coordinates must be finite");
5710
- }
5711
- }
5712
- function validateQueryDistance(distance) {
5713
- if (Number.isNaN(distance) || distance < 0)
5714
- throw new RangeError("Distance must be nonnegative");
5715
- }
5716
- function normalizeQueryDirection(direction, dimension) {
5717
- validateQueryPoint(direction, dimension);
5718
- const scale = Math.max(...Array.from(direction, Math.abs));
5719
- if (scale === 0)
5720
- throw new RangeError("Ray direction must be nonzero");
5721
- const scaled = Array.from(direction, (x) => x / scale);
5722
- const length = Math.hypot(...scaled);
5723
- return scaled.map((x) => x / length);
5724
- }
5725
- function intersectRayBounds(origin, direction, minimum, maximum, maxT = Infinity) {
5726
- const dimension = origin.length;
5727
- if (dimension !== 2 && dimension !== 3)
5728
- throw new RangeError("Bounds must be 2D or 3D");
5729
- validateQueryPoint(origin, dimension);
5730
- validateQueryPoint(direction, dimension);
5731
- validateQueryPoint(minimum, dimension);
5732
- validateQueryPoint(maximum, dimension);
5733
- validateQueryDistance(maxT);
5734
- let near = 0, far = maxT, nonzero = false;
5735
- for (let i = 0; i < dimension; i++) {
5736
- if (minimum[i] > maximum[i])
5737
- throw new RangeError("Bounds must be ordered");
5738
- nonzero || (nonzero = direction[i] !== 0);
5739
- }
5740
- if (!nonzero)
5741
- throw new RangeError("Ray direction must be nonzero");
5742
- for (let i = 0; i < dimension; i++) {
5743
- if (direction[i] === 0) {
5744
- if (origin[i] < minimum[i] || origin[i] > maximum[i])
5745
- return null;
5746
- continue;
5747
- }
5748
- let a = (minimum[i] - origin[i]) / direction[i];
5749
- let b = (maximum[i] - origin[i]) / direction[i];
5750
- if (a > b)
5751
- [a, b] = [b, a];
5752
- near = Math.max(near, a);
5753
- far = Math.min(far, b);
5754
- if (near > far)
5755
- return null;
5756
- }
5757
- return Number.isFinite(near) ? near : null;
5758
- }
5759
- function intersectRayTriangle(origin, direction, a, b, c, options = {}) {
5760
- for (const point of [origin, direction, a, b, c])
5761
- validateQueryPoint(point, 3);
5762
- if (direction[0] === 0 && direction[1] === 0 && direction[2] === 0) {
5763
- throw new RangeError("Ray direction must be nonzero");
5764
- }
5765
- const maxT = options.maxT ?? Infinity;
5766
- validateQueryDistance(maxT);
5767
- const e1 = [b[0] - a[0], b[1] - a[1], b[2] - a[2]];
5768
- const e2 = [c[0] - a[0], c[1] - a[1], c[2] - a[2]];
5769
- const p = cross3(direction, e2);
5770
- const determinant = dot3(e1, p);
5771
- if (determinant === 0 || options.backfaceCulling && determinant < 0)
5772
- return null;
5773
- const offset = [origin[0] - a[0], origin[1] - a[1], origin[2] - a[2]];
5774
- const u = dot3(offset, p) / determinant;
5775
- if (u < 0 || u > 1)
5776
- return null;
5777
- const q = cross3(offset, e1);
5778
- const v = dot3(direction, q) / determinant;
5779
- if (v < 0 || u + v > 1)
5780
- return null;
5781
- const t = dot3(e2, q) / determinant;
5782
- if (!Number.isFinite(t) || t < 0 || t > maxT)
5783
- return null;
5784
- return { t: Math.max(0, t), barycentric: [1 - u - v, u, v] };
5785
- }
5786
- function getClosestPointOnTriangle(point, a, b, c) {
5787
- for (const value of [point, a, b, c])
5788
- validateQueryPoint(value, 3);
5789
- const ab = [b[0] - a[0], b[1] - a[1], b[2] - a[2]];
5790
- const ac = [c[0] - a[0], c[1] - a[1], c[2] - a[2]];
5791
- const ap = [point[0] - a[0], point[1] - a[1], point[2] - a[2]];
5792
- const aa = dot3(ab, ab), bb = dot3(ac, ac), cc = dot3(ab, ac);
5793
- const denominator = aa * bb - cc * cc;
5794
- if (denominator > 0 && Number.isFinite(denominator)) {
5795
- const u = (bb * dot3(ap, ab) - cc * dot3(ap, ac)) / denominator;
5796
- const v = (aa * dot3(ap, ac) - cc * dot3(ap, ab)) / denominator;
5797
- if (u >= 0 && v >= 0 && u + v <= 1) {
5798
- return [
5799
- a[0] + u * ab[0] + v * ac[0],
5800
- a[1] + u * ab[1] + v * ac[1],
5801
- a[2] + u * ab[2] + v * ac[2]
5802
- ];
5803
- }
5804
- }
5805
- let best = [a[0], a[1], a[2]];
5806
- let distance = Infinity;
5807
- for (const [start, end] of [
5808
- [a, b],
5809
- [b, c],
5810
- [c, a]
5811
- ]) {
5812
- const edge = [end[0] - start[0], end[1] - start[1], end[2] - start[2]];
5813
- const offset = [point[0] - start[0], point[1] - start[1], point[2] - start[2]];
5814
- const squared = dot3(edge, edge);
5815
- const t = squared > 0 ? Math.max(0, Math.min(1, dot3(offset, edge) / squared)) : 0;
5816
- const candidate = [
5817
- start[0] + t * edge[0],
5818
- start[1] + t * edge[1],
5819
- start[2] + t * edge[2]
5820
- ];
5821
- const d = Math.hypot(point[0] - candidate[0], point[1] - candidate[1], point[2] - candidate[2]);
5822
- if (d < distance) {
5823
- distance = d;
5824
- best = candidate;
5825
- }
5826
- }
5827
- return best;
5828
- }
5829
- function getClosestPointsOnSegments(a0, a1, b0, b1) {
5830
- const frame = queryFrame([a0, a1, b0, b1]);
5831
- const pair = closestSegments(...frame.points);
5832
- const pointA = interpolatePoint(a0, a1, pair.fractionA);
5833
- const pointB = interpolatePoint(b0, b1, pair.fractionB);
5834
- return {
5835
- distance: finiteDistance(pointA, pointB),
5836
- pointA,
5837
- pointB,
5838
- fractionA: pair.fractionA,
5839
- fractionB: pair.fractionB
5840
- };
5841
- }
5842
- function getClosestPointsSegmentTriangle(start, end, a, b, c) {
5843
- const frame = queryFrame([start, end, a, b, c]);
5844
- const [s, e, va, vb, vc] = frame.points;
5845
- const direction = subtract(e, s);
5846
- if (direction.some((value) => value !== 0)) {
5847
- const hit = intersectRayTriangle(s, direction, va, vb, vc, { maxT: 1 });
5848
- if (hit) {
5849
- const point = interpolatePoint(start, end, hit.t);
5850
- return { distance: 0, segmentPoint: point, trianglePoint: [...point], segmentFraction: hit.t };
5851
- }
5852
- }
5853
- let best = { distance: Infinity, segmentFraction: 0, trianglePoint: va };
5854
- const consider = (point, trianglePoint2, segmentFraction) => {
5855
- const distance = Math.hypot(...subtract(point, trianglePoint2));
5856
- if (distance < best.distance || distance === best.distance && segmentFraction < best.segmentFraction)
5857
- best = { distance, segmentFraction, trianglePoint: trianglePoint2 };
5858
- };
5859
- consider(s, getClosestPointOnTriangle(s, va, vb, vc), 0);
5860
- consider(e, getClosestPointOnTriangle(e, va, vb, vc), 1);
5861
- for (const [v0, v1] of [
5862
- [va, vb],
5863
- [vb, vc],
5864
- [vc, va]
5865
- ]) {
5866
- const pair = closestSegments(s, e, v0, v1);
5867
- consider(interpolatePoint(s, e, pair.fractionA), interpolatePoint(v0, v1, pair.fractionB), pair.fractionA);
5868
- }
5869
- 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)));
5870
- if (!trianglePoint.every(Number.isFinite))
5871
- throw new RangeError("Closest-point result overflow");
5872
- const segmentPoint = interpolatePoint(start, end, best.segmentFraction);
5873
- return {
5874
- distance: finiteDistance(segmentPoint, trianglePoint),
5875
- segmentPoint,
5876
- trianglePoint,
5877
- segmentFraction: best.segmentFraction
5878
- };
5879
- }
5880
- function queryFrame(input) {
5881
- input.forEach((point) => validateQueryPoint(point, 3));
5882
- const offsets = input.map((point) => subtract(point, input[0]));
5883
- let scale = 0;
5884
- for (const offset of offsets)
5885
- for (const value of offset) {
5886
- if (!Number.isFinite(value))
5887
- throw new RangeError("Closest-point coordinate span overflow");
5888
- scale = Math.max(scale, Math.abs(value));
5889
- }
5890
- scale || (scale = 1);
5891
- return { points: offsets.map((point) => point.map((value) => value / scale)), scale };
5892
- }
5893
- function closestSegments(a0, a1, b0, b1) {
5894
- const da = subtract(a1, a0), db = subtract(b1, b0);
5895
- const lengthA = Math.hypot(...da), lengthB = Math.hypot(...db);
5896
- const ua = da.map((value) => lengthA ? value / lengthA : 0);
5897
- const ub = db.map((value) => lengthB ? value / lengthB : 0);
5898
- let best = { distance: Infinity, fractionA: 0, fractionB: 0 };
5899
- const consider = (fractionA, fractionB) => {
5900
- const distance = Math.hypot(...subtract(interpolatePoint(a0, a1, fractionA), interpolatePoint(b0, b1, fractionB)));
5901
- if (distance < best.distance || distance === best.distance && (fractionA < best.fractionA || fractionA === best.fractionA && fractionB < best.fractionB))
5902
- best = { distance, fractionA, fractionB };
5903
- };
5904
- for (const t of [0, 1]) {
5905
- consider(t, lengthB ? clampUnit(dot3(subtract(t ? a1 : a0, b0), ub) / lengthB) : 0);
5906
- consider(lengthA ? clampUnit(dot3(subtract(t ? b1 : b0, a0), ua) / lengthA) : 0, t);
5907
- }
5908
- const normal = cross3(ua, ub);
5909
- const sine = Math.hypot(...normal);
5910
- if (sine > 0) {
5911
- const unit = normal.map((value) => value / sine);
5912
- const offset = subtract(b0, a0);
5913
- const fractionA = dot3(cross3(offset, ub), unit) / sine / lengthA;
5914
- const fractionB = dot3(cross3(offset, ua), unit) / sine / lengthB;
5915
- if (fractionA >= 0 && fractionA <= 1 && fractionB >= 0 && fractionB <= 1)
5916
- consider(fractionA, fractionB);
5917
- }
5918
- return best;
5919
- }
5920
- function subtract(a, b) {
5921
- return [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
5922
- }
5923
- function interpolatePoint(a, b, t) {
5924
- 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])));
5925
- }
5926
- function clampUnit(value) {
5927
- return Math.max(0, Math.min(1, value));
5928
- }
5929
- function finiteDistance(a, b) {
5930
- const distance = Math.hypot(...subtract(a, b));
5931
- if (!Number.isFinite(distance))
5932
- throw new RangeError("Closest-point distance overflow");
5933
- return distance;
5934
- }
5935
- function dot3(a, b) {
5936
- return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
5937
- }
5938
- function cross3(a, b) {
5939
- 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]];
5940
- }
5941
-
5942
6355
  // dist/culling/oriented-box-2d.js
5943
6356
  function intersectOrientedBoxes2D(first, second, epsilon = 0) {
5944
6357
  validateBox(first);
@@ -5990,64 +6403,177 @@ function validateVector(vector) {
5990
6403
  }
5991
6404
 
5992
6405
  // dist/culling/lib/algorithms/oriented-bounding-box-quaternion.js
5993
- var import_core21 = require("@math.gl/core");
6406
+ var import_core22 = require("@math.gl/core");
5994
6407
  function getOrientedBoundingBoxQuaternion(box) {
5995
- const x = new import_core21.Vector3(box.halfAxes.getColumn(0)).normalize();
5996
- const y = new import_core21.Vector3(box.halfAxes.getColumn(1)).normalize();
5997
- const z = new import_core21.Vector3(box.halfAxes.getColumn(2)).normalize();
5998
- return new import_core21.Quaternion().fromMatrix3(new import_core21.Matrix3([...x, ...y, ...z]));
6408
+ const x = new import_core22.Vector3(box.halfAxes.getColumn(0)).normalize();
6409
+ const y = new import_core22.Vector3(box.halfAxes.getColumn(1)).normalize();
6410
+ const z = new import_core22.Vector3(box.halfAxes.getColumn(2)).normalize();
6411
+ return new import_core22.Quaternion().fromMatrix3(new import_core22.Matrix3([...x, ...y, ...z]));
5999
6412
  }
6000
6413
  function makeOrientedBoundingBoxFromQuaternion(center, halfSize, quaternion, result = new OrientedBoundingBox()) {
6001
- const halfAxes = new import_core21.Matrix3().fromQuaternion(quaternion);
6414
+ const halfAxes = new import_core22.Matrix3().fromQuaternion(quaternion);
6002
6415
  for (let column = 0; column < 3; column++) {
6003
6416
  for (let row = 0; row < 3; row++)
6004
6417
  halfAxes[column * 3 + row] *= halfSize[column];
6005
6418
  }
6006
- result.center = new import_core21.Vector3(center);
6419
+ result.center = new import_core22.Vector3(center);
6007
6420
  result.halfAxes = halfAxes;
6008
6421
  return result;
6009
6422
  }
6010
6423
 
6424
+ // dist/culling/bounds.js
6425
+ function dimension(bounds) {
6426
+ const n = bounds[0].length;
6427
+ if (n !== 2 && n !== 3 || bounds[1].length !== n || [...Array.from(bounds[0]), ...Array.from(bounds[1])].some(Number.isNaN)) {
6428
+ throw new RangeError("Expected 2D or 3D bounds without NaN");
6429
+ }
6430
+ const empty = Array.from({ length: n }, (_, i) => bounds[0][i] > bounds[1][i]).some(Boolean);
6431
+ if (!empty && [...Array.from(bounds[0]), ...Array.from(bounds[1])].some((x) => !Number.isFinite(x))) {
6432
+ throw new RangeError("Nonempty bounds must be finite");
6433
+ }
6434
+ return n;
6435
+ }
6436
+ function pair(a, b) {
6437
+ const n = dimension(a);
6438
+ if (dimension(b) !== n)
6439
+ throw new RangeError("Bounds dimensions must match");
6440
+ return n;
6441
+ }
6442
+ function point(p, n) {
6443
+ if (p.length !== n || Array.from(p).some((x) => !Number.isFinite(x)))
6444
+ throw new RangeError("Expected a finite point of matching dimension");
6445
+ }
6446
+ function createEmptyBounds(dimension2) {
6447
+ if (dimension2 !== 2 && dimension2 !== 3)
6448
+ throw new RangeError("Expected dimension 2 or 3");
6449
+ return [new Array(dimension2).fill(Infinity), new Array(dimension2).fill(-Infinity)];
6450
+ }
6451
+ function isEmptyBounds(bounds) {
6452
+ return Array.from({ length: dimension(bounds) }, (_, i) => bounds[0][i] > bounds[1][i]).some(Boolean);
6453
+ }
6454
+ function boundsContainsPoint(bounds, p) {
6455
+ point(p, dimension(bounds));
6456
+ return !isEmptyBounds(bounds) && Array.from(p).every((x, i) => x >= bounds[0][i] && x <= bounds[1][i]);
6457
+ }
6458
+ function boundsContainsBounds(a, b) {
6459
+ const n = pair(a, b);
6460
+ return isEmptyBounds(b) || !isEmptyBounds(a) && Array.from({ length: n }, (_, i) => a[0][i] <= b[0][i] && a[1][i] >= b[1][i]).every(Boolean);
6461
+ }
6462
+ function boundsIntersect(a, b) {
6463
+ const n = pair(a, b);
6464
+ return !isEmptyBounds(a) && !isEmptyBounds(b) && Array.from({ length: n }, (_, i) => a[0][i] <= b[1][i] && b[0][i] <= a[1][i]).every(Boolean);
6465
+ }
6466
+ function store(values, out = createEmptyBounds(values[0].length)) {
6467
+ if (out[0].length !== values[0].length || out[1].length !== values[0].length) {
6468
+ throw new RangeError("Output bounds dimensions must match");
6469
+ }
6470
+ for (let j = 0; j < 2; j++)
6471
+ for (let i = 0; i < values[j].length; i++)
6472
+ out[j][i] = values[j][i];
6473
+ return out;
6474
+ }
6475
+ function unionBounds(a, b, out) {
6476
+ const n = pair(a, b);
6477
+ const values = createEmptyBounds(n);
6478
+ const ea = isEmptyBounds(a), eb = isEmptyBounds(b);
6479
+ for (let i = 0; i < n; i++) {
6480
+ values[0][i] = Math.min(ea ? Infinity : a[0][i], eb ? Infinity : b[0][i]);
6481
+ values[1][i] = Math.max(ea ? -Infinity : a[1][i], eb ? -Infinity : b[1][i]);
6482
+ }
6483
+ return store(values, out);
6484
+ }
6485
+ function intersectBounds(a, b, out) {
6486
+ const n = pair(a, b), values = createEmptyBounds(n);
6487
+ if (boundsIntersect(a, b))
6488
+ for (let i = 0; i < n; i++) {
6489
+ values[0][i] = Math.max(a[0][i], b[0][i]);
6490
+ values[1][i] = Math.min(a[1][i], b[1][i]);
6491
+ }
6492
+ return store(values, out);
6493
+ }
6494
+ function expandBoundsByPoint(bounds, p, out) {
6495
+ point(p, dimension(bounds));
6496
+ return unionBounds(bounds, [p, p], out);
6497
+ }
6498
+ function expandBounds(bounds, padding, out) {
6499
+ if (!Number.isFinite(padding))
6500
+ throw new RangeError("Padding must be finite");
6501
+ const n = dimension(bounds), values = createEmptyBounds(n);
6502
+ if (!isEmptyBounds(bounds))
6503
+ for (let i = 0; i < n; i++) {
6504
+ values[0][i] = bounds[0][i] - padding;
6505
+ values[1][i] = bounds[1][i] + padding;
6506
+ }
6507
+ return store(isEmptyBounds(values) ? createEmptyBounds(n) : values, out);
6508
+ }
6509
+ function clampPointToBounds(bounds, p, out = new Array(p.length)) {
6510
+ point(p, dimension(bounds));
6511
+ if (out.length < p.length)
6512
+ throw new RangeError("Result buffer is too short");
6513
+ if (isEmptyBounds(bounds))
6514
+ return null;
6515
+ const result = Array.from(p, (x, i) => Math.max(bounds[0][i], Math.min(bounds[1][i], x)));
6516
+ for (let i = 0; i < result.length; i++)
6517
+ out[i] = result[i];
6518
+ return out;
6519
+ }
6520
+ function radius(r) {
6521
+ if (!Number.isFinite(r) || r < 0)
6522
+ throw new RangeError("Radius must be finite and nonnegative");
6523
+ }
6524
+ function spheresIntersect(a, ar, b, br) {
6525
+ point(a, 3);
6526
+ point(b, 3);
6527
+ radius(ar);
6528
+ radius(br);
6529
+ return Math.hypot(a[0] - b[0], a[1] - b[1], a[2] - b[2]) <= ar + br;
6530
+ }
6531
+ function boundsIntersectSphere(bounds, center, r) {
6532
+ radius(r);
6533
+ const closest = clampPointToBounds(bounds, center);
6534
+ return closest !== null && Math.hypot(...Array.from(center, (x, i) => x - closest[i])) <= r;
6535
+ }
6536
+
6011
6537
  // dist/spatial-index/box-index.js
6012
6538
  var BoxIndex = class {
6013
6539
  constructor(options) {
6014
- const { dimension, bounds, leafSize = 8 } = options;
6015
- if (dimension !== 2 && dimension !== 3)
6540
+ const { dimension: dimension2, bounds, leafSize = 8 } = options;
6541
+ if (dimension2 !== 2 && dimension2 !== 3)
6016
6542
  throw new RangeError("Index dimension must be 2 or 3");
6017
6543
  if (!Number.isSafeInteger(leafSize) || leafSize < 1)
6018
6544
  throw new RangeError("leafSize must be positive");
6019
- if (bounds.length % (dimension * 2))
6545
+ if (bounds.length % (dimension2 * 2))
6020
6546
  throw new RangeError("Incomplete bounds record");
6021
- this.dimension = dimension;
6547
+ this.dimension = dimension2;
6022
6548
  this.bounds = Float64Array.from(bounds);
6023
- this.size = bounds.length / (dimension * 2);
6549
+ this.size = bounds.length / (dimension2 * 2);
6024
6550
  if (this.size > 2147483647)
6025
6551
  throw new RangeError("Index exceeds 32-bit capacity");
6026
- const stride = dimension * 2;
6552
+ const stride = dimension2 * 2;
6027
6553
  for (let i = 0; i < this.size; i++)
6028
- this.validateBounds(this.bounds.subarray(i * stride, i * stride + dimension), this.bounds.subarray(i * stride + dimension, (i + 1) * stride));
6554
+ this.validateBounds(this.bounds.subarray(i * stride, i * stride + dimension2), this.bounds.subarray(i * stride + dimension2, (i + 1) * stride));
6029
6555
  const records = [];
6030
6556
  const ids = Array.from({ length: this.size }, (_, i) => i);
6031
6557
  const build = (start, end) => {
6032
6558
  const node = records.length;
6033
6559
  const bound = [
6034
- ...new Array(dimension).fill(Infinity),
6035
- ...new Array(dimension).fill(-Infinity)
6560
+ ...new Array(dimension2).fill(Infinity),
6561
+ ...new Array(dimension2).fill(-Infinity)
6036
6562
  ];
6037
6563
  for (let i = start; i < end; i++)
6038
- for (let axis = 0; axis < dimension; axis++) {
6564
+ for (let axis = 0; axis < dimension2; axis++) {
6039
6565
  bound[axis] = Math.min(bound[axis], this.bounds[ids[i] * stride + axis]);
6040
- bound[axis + dimension] = Math.max(bound[axis + dimension], this.bounds[ids[i] * stride + axis + dimension]);
6566
+ bound[axis + dimension2] = Math.max(bound[axis + dimension2], this.bounds[ids[i] * stride + axis + dimension2]);
6041
6567
  }
6042
6568
  const record = { bounds: bound, left: -1, right: -1, start, count: end - start };
6043
6569
  records.push(record);
6044
6570
  if (end - start > leafSize) {
6045
6571
  let axis = 0;
6046
- for (let i = 1; i < dimension; i++) {
6047
- if (bound[i + dimension] - bound[i] > bound[axis + dimension] - bound[axis])
6572
+ for (let i = 1; i < dimension2; i++) {
6573
+ if (bound[i + dimension2] - bound[i] > bound[axis + dimension2] - bound[axis])
6048
6574
  axis = i;
6049
6575
  }
6050
- const center = (i) => this.bounds[i * stride + axis] / 2 + this.bounds[i * stride + axis + dimension] / 2;
6576
+ const center = (i) => this.bounds[i * stride + axis] / 2 + this.bounds[i * stride + axis + dimension2] / 2;
6051
6577
  const sorted = ids.slice(start, end).sort((a, b) => center(a) - center(b) || a - b);
6052
6578
  for (let i = 0; i < sorted.length; i++)
6053
6579
  ids[start + i] = sorted[i];
@@ -6121,11 +6647,11 @@ var BoxIndex = class {
6121
6647
  return { result: result.sort((a, b) => a - b), complete, work: budget.work };
6122
6648
  }
6123
6649
  /** Branch-and-bound nearest box, optionally refined against actual geometry. */
6124
- nearest(point, options = {}) {
6125
- return this.nearestQuery(point, { ...options, maxWork: Infinity }).result;
6650
+ nearest(point2, options = {}) {
6651
+ return this.nearestQuery(point2, { ...options, maxWork: Infinity }).result;
6126
6652
  }
6127
- nearestQuery(point, options = {}) {
6128
- return this.nearestBoxQuery(point, point, options);
6653
+ nearestQuery(point2, options = {}) {
6654
+ return this.nearestBoxQuery(point2, point2, options);
6129
6655
  }
6130
6656
  /** Nearest indexed box to a filled query box, optionally refined to enclosed geometry. */
6131
6657
  nearestBoxQuery(minimum, maximum, options = {}) {
@@ -6189,19 +6715,19 @@ var BoxIndex = class {
6189
6715
  * Nearest accepted box/geometry hit without materializing and sorting all ray candidates.
6190
6716
  * Rejected refinements do not clip the ray. Equal distances select the lowest original row.
6191
6717
  */
6192
- intersectRay(origin, direction, options = {}) {
6193
- return this.intersectRayQuery(origin, direction, { ...options, maxWork: Infinity }).result;
6718
+ intersectRay(origin, direction2, options = {}) {
6719
+ return this.intersectRayQuery(origin, direction2, { ...options, maxWork: Infinity }).result;
6194
6720
  }
6195
- intersectRayQuery(origin, direction, options = {}) {
6721
+ intersectRayQuery(origin, direction2, options = {}) {
6196
6722
  validateQueryPoint(origin, this.dimension);
6197
6723
  const budget = new QueryBudget(options.maxWork);
6198
- const unit = normalizeQueryDirection(direction, this.dimension);
6724
+ const unit2 = normalizeQueryDirection(direction2, this.dimension);
6199
6725
  let best = options.maxDistance ?? Infinity;
6200
6726
  validateQueryDistance(best);
6201
6727
  let result = null;
6202
6728
  const getEntry = (bounds, index) => {
6203
6729
  const offset = index * this.dimension * 2;
6204
- return intersectRayBounds(origin, unit, bounds.subarray(offset, offset + this.dimension), bounds.subarray(offset + this.dimension, offset + this.dimension * 2), best + getDistanceTolerance(best, best));
6730
+ return intersectRayBounds(origin, unit2, bounds.subarray(offset, offset + this.dimension), bounds.subarray(offset + this.dimension, offset + this.dimension * 2), best + getDistanceTolerance(best, best));
6205
6731
  };
6206
6732
  const stack = this.size ? [{ index: 0, distance: 0 }] : [];
6207
6733
  let complete = true;
@@ -6254,13 +6780,13 @@ var BoxIndex = class {
6254
6780
  return { result, complete, work: budget.work };
6255
6781
  }
6256
6782
  /** Broad-phase ray candidates, sorted by entry distance then original row index. */
6257
- searchRay(origin, direction, maxDistance = Infinity) {
6783
+ searchRay(origin, direction2, maxDistance = Infinity) {
6258
6784
  validateQueryPoint(origin, this.dimension);
6259
- const unit = normalizeQueryDirection(direction, this.dimension);
6785
+ const unit2 = normalizeQueryDirection(direction2, this.dimension);
6260
6786
  validateQueryDistance(maxDistance);
6261
6787
  const entry = (bounds, index) => {
6262
6788
  const start = index * this.dimension * 2;
6263
- return intersectRayBounds(origin, unit, bounds.subarray(start, start + this.dimension), bounds.subarray(start + this.dimension, start + this.dimension * 2), maxDistance);
6789
+ return intersectRayBounds(origin, unit2, bounds.subarray(start, start + this.dimension), bounds.subarray(start + this.dimension, start + this.dimension * 2), maxDistance);
6264
6790
  };
6265
6791
  const result = [];
6266
6792
  const stack = this.size ? [0] : [];
@@ -6310,16 +6836,16 @@ var QueryBudget = class {
6310
6836
  };
6311
6837
  var PointIndex = class extends BoxIndex {
6312
6838
  constructor(options) {
6313
- const { positions, dimension, leafSize } = options;
6314
- if (dimension !== 2 && dimension !== 3 || positions.length % dimension) {
6839
+ const { positions, dimension: dimension2, leafSize } = options;
6840
+ if (dimension2 !== 2 && dimension2 !== 3 || positions.length % dimension2) {
6315
6841
  throw new RangeError("Invalid point layout");
6316
6842
  }
6317
6843
  const bounds = new Float64Array(positions.length * 2);
6318
- for (let i = 0; i < positions.length / dimension; i++)
6319
- for (let axis = 0; axis < dimension; axis++) {
6320
- bounds[i * dimension * 2 + axis] = bounds[i * dimension * 2 + axis + dimension] = positions[i * dimension + axis];
6844
+ for (let i = 0; i < positions.length / dimension2; i++)
6845
+ for (let axis = 0; axis < dimension2; axis++) {
6846
+ bounds[i * dimension2 * 2 + axis] = bounds[i * dimension2 * 2 + axis + dimension2] = positions[i * dimension2 + axis];
6321
6847
  }
6322
- super({ bounds, dimension, leafSize });
6848
+ super({ bounds, dimension: dimension2, leafSize });
6323
6849
  }
6324
6850
  };
6325
6851
 
@@ -6362,20 +6888,20 @@ var TriangleBVH = class {
6362
6888
  return this.boxes.searchQuery(minimum, maximum, options);
6363
6889
  }
6364
6890
  /** Nearest accepted exact hit; application rejection never clips away later candidates. */
6365
- intersectRay(origin, direction, options = {}) {
6366
- return this.intersectRayQuery(origin, direction, { ...options, maxWork: Infinity }).result;
6891
+ intersectRay(origin, direction2, options = {}) {
6892
+ return this.intersectRayQuery(origin, direction2, { ...options, maxWork: Infinity }).result;
6367
6893
  }
6368
- intersectRayQuery(origin, direction, options = {}) {
6894
+ intersectRayQuery(origin, direction2, options = {}) {
6369
6895
  validateQueryPoint(origin, 3);
6370
- const unit = normalizeQueryDirection(direction, 3);
6896
+ const unit2 = normalizeQueryDirection(direction2, 3);
6371
6897
  let result = null;
6372
- const query = this.boxes.intersectRayQuery(origin, direction, {
6898
+ const query = this.boxes.intersectRayQuery(origin, direction2, {
6373
6899
  maxWork: options.maxWork,
6374
6900
  maxDistance: options.maxDistance,
6375
6901
  filter: options.filter,
6376
6902
  intersectItem: (index, maximum) => {
6377
6903
  const [a, b, c] = this.triangle(index);
6378
- const hit = intersectRayTriangle(origin, unit, a, b, c, {
6904
+ const hit = intersectRayTriangle(origin, unit2, a, b, c, {
6379
6905
  backfaceCulling: options.backfaceCulling,
6380
6906
  maxT: maximum
6381
6907
  });
@@ -6384,9 +6910,9 @@ var TriangleBVH = class {
6384
6910
  index,
6385
6911
  distance: hit.t,
6386
6912
  point: [
6387
- origin[0] + hit.t * unit[0],
6388
- origin[1] + hit.t * unit[1],
6389
- origin[2] + hit.t * unit[2]
6913
+ origin[0] + hit.t * unit2[0],
6914
+ origin[1] + hit.t * unit2[1],
6915
+ origin[2] + hit.t * unit2[2]
6390
6916
  ],
6391
6917
  barycentric: hit.barycentric
6392
6918
  };
@@ -6400,16 +6926,16 @@ var TriangleBVH = class {
6400
6926
  });
6401
6927
  return { ...query, result };
6402
6928
  }
6403
- nearest(point, options = {}) {
6404
- return this.nearestQuery(point, { ...options, maxWork: Infinity }).result;
6929
+ nearest(point2, options = {}) {
6930
+ return this.nearestQuery(point2, { ...options, maxWork: Infinity }).result;
6405
6931
  }
6406
- nearestQuery(point, options = {}) {
6932
+ nearestQuery(point2, options = {}) {
6407
6933
  let candidate = null;
6408
- const query = this.boxes.nearestQuery(point, {
6934
+ const query = this.boxes.nearestQuery(point2, {
6409
6935
  ...options,
6410
6936
  distanceToItem: (index) => {
6411
- const closest = getClosestPointOnTriangle(point, ...this.triangle(index));
6412
- const distance = Math.hypot(point[0] - closest[0], point[1] - closest[1], point[2] - closest[2]);
6937
+ const closest = getClosestPointOnTriangle(point2, ...this.triangle(index));
6938
+ const distance = Math.hypot(point2[0] - closest[0], point2[1] - closest[1], point2[2] - closest[2]);
6413
6939
  if (!candidate || distance < candidate.distance || distance === candidate.distance && index < candidate.index)
6414
6940
  candidate = { index, distance, point: closest };
6415
6941
  return distance;
@@ -6420,15 +6946,15 @@ var TriangleBVH = class {
6420
6946
  /** All triangle contacts with a closed sphere, sorted by original index (not distance).
6421
6947
  * Uses closest points on faces, edges and vertices. No contact manifold reduction.
6422
6948
  */
6423
- intersectSphere(center, radius, options = {}) {
6949
+ intersectSphere(center, radius2, options = {}) {
6424
6950
  validateQueryPoint(center, 3);
6425
- if (!Number.isFinite(radius) || radius < 0)
6951
+ if (!Number.isFinite(radius2) || radius2 < 0)
6426
6952
  throw new RangeError("Sphere radius must be finite and nonnegative");
6427
6953
  const minimum = [], maximum = [];
6428
6954
  for (let axis = 0; axis < 3; axis++) {
6429
- const padding = 8 * Math.max(Number.MIN_VALUE, Number.EPSILON * Math.max(Math.abs(center[axis]), radius));
6430
- minimum.push(center[axis] - radius - padding);
6431
- maximum.push(center[axis] + radius + padding);
6955
+ const padding = 8 * Math.max(Number.MIN_VALUE, Number.EPSILON * Math.max(Math.abs(center[axis]), radius2));
6956
+ minimum.push(center[axis] - radius2 - padding);
6957
+ maximum.push(center[axis] + radius2 + padding);
6432
6958
  }
6433
6959
  const hits = /* @__PURE__ */ new Map();
6434
6960
  const query = this.boxes.searchQuery(minimum, maximum, {
@@ -6436,13 +6962,13 @@ var TriangleBVH = class {
6436
6962
  filter: (index) => {
6437
6963
  if (options.filter && !options.filter(index))
6438
6964
  return false;
6439
- const point = getClosestPointOnTriangle(center, ...this.triangle(index));
6440
- const distance = Math.hypot(center[0] - point[0], center[1] - point[1], center[2] - point[2]);
6441
- if (!point.every(Number.isFinite) || !Number.isFinite(distance))
6965
+ const point2 = getClosestPointOnTriangle(center, ...this.triangle(index));
6966
+ const distance = Math.hypot(center[0] - point2[0], center[1] - point2[1], center[2] - point2[2]);
6967
+ if (!point2.every(Number.isFinite) || !Number.isFinite(distance))
6442
6968
  throw new RangeError("Sphere query arithmetic overflow");
6443
- if (distance > radius)
6969
+ if (distance > radius2)
6444
6970
  return false;
6445
- hits.set(index, { index, distance, point });
6971
+ hits.set(index, { index, distance, point: point2 });
6446
6972
  return true;
6447
6973
  }
6448
6974
  });
@@ -6469,10 +6995,10 @@ var TriangleBVH = class {
6469
6995
  /** Closed capsule overlap, with one closest pair per accepted triangle.
6470
6996
  * A straight translating sphere covers this volume, but segmentFraction is not first-impact time.
6471
6997
  */
6472
- intersectCapsule(start, end, radius, options = {}) {
6473
- if (!Number.isFinite(radius) || radius < 0)
6998
+ intersectCapsule(start, end, radius2, options = {}) {
6999
+ if (!Number.isFinite(radius2) || radius2 < 0)
6474
7000
  throw new RangeError("Capsule radius must be finite and nonnegative");
6475
- const { minimum, maximum } = segmentBounds(start, end, radius);
7001
+ const { minimum, maximum } = segmentBounds(start, end, radius2);
6476
7002
  const hits = /* @__PURE__ */ new Map();
6477
7003
  const query = this.boxes.searchQuery(minimum, maximum, {
6478
7004
  ...options,
@@ -6480,7 +7006,7 @@ var TriangleBVH = class {
6480
7006
  if (options.filter && !options.filter(index))
6481
7007
  return false;
6482
7008
  const closest = this.segmentClosest(index, start, end);
6483
- if (closest.distance > radius)
7009
+ if (closest.distance > radius2)
6484
7010
  return false;
6485
7011
  hits.set(index, closest);
6486
7012
  return true;
@@ -6506,7 +7032,7 @@ var TriangleBVH = class {
6506
7032
  return [vertex2(0), vertex2(1), vertex2(2)];
6507
7033
  }
6508
7034
  };
6509
- function segmentBounds(start, end, radius) {
7035
+ function segmentBounds(start, end, radius2) {
6510
7036
  validateQueryPoint(start, 3);
6511
7037
  validateQueryPoint(end, 3);
6512
7038
  for (let axis = 0; axis < 3; axis++)
@@ -6514,7 +7040,7 @@ function segmentBounds(start, end, radius) {
6514
7040
  throw new RangeError("Segment coordinate span overflow");
6515
7041
  const minimum = [], maximum = [];
6516
7042
  for (let axis = 0; axis < 3; axis++) {
6517
- 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));
7043
+ 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));
6518
7044
  minimum.push(Math.min(start[axis], end[axis]) - padding);
6519
7045
  maximum.push(Math.max(start[axis], end[axis]) + padding);
6520
7046
  }