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

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 (179) hide show
  1. package/README.md +61 -0
  2. package/THIRD-PARTY-NOTICES.md +1 -1
  3. package/dist/color/color-lut-types.d.ts +16 -0
  4. package/dist/color/color-lut-types.d.ts.map +1 -0
  5. package/dist/color/color-lut-types.js +5 -0
  6. package/dist/color/color-lut-types.js.map +1 -0
  7. package/dist/color/index.cjs +132 -0
  8. package/dist/color/index.cjs.map +6 -0
  9. package/dist/color/index.d.ts +4 -0
  10. package/dist/color/index.d.ts.map +1 -0
  11. package/dist/color/index.js +5 -0
  12. package/dist/color/index.js.map +1 -0
  13. package/dist/color/sample-lut.d.ts +13 -0
  14. package/dist/color/sample-lut.d.ts.map +1 -0
  15. package/dist/color/sample-lut.js +132 -0
  16. package/dist/color/sample-lut.js.map +1 -0
  17. package/dist/culling/bounds.d.ts +20 -0
  18. package/dist/culling/bounds.d.ts.map +1 -0
  19. package/dist/culling/bounds.js +121 -0
  20. package/dist/culling/bounds.js.map +1 -0
  21. package/dist/culling/frustum-planes.d.ts +5 -0
  22. package/dist/culling/frustum-planes.d.ts.map +1 -0
  23. package/dist/culling/frustum-planes.js +37 -0
  24. package/dist/culling/frustum-planes.js.map +1 -0
  25. package/dist/culling/geometric-queries.d.ts +34 -0
  26. package/dist/culling/geometric-queries.d.ts.map +1 -0
  27. package/dist/culling/geometric-queries.js +208 -0
  28. package/dist/culling/geometric-queries.js.map +1 -0
  29. package/dist/culling/index.cjs +944 -508
  30. package/dist/culling/index.cjs.map +3 -3
  31. package/dist/culling/index.d.ts +7 -1
  32. package/dist/culling/index.d.ts.map +1 -1
  33. package/dist/culling/index.js +4 -0
  34. package/dist/culling/index.js.map +1 -1
  35. package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +3 -3
  36. package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.d.ts.map +1 -1
  37. package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.js +25 -8
  38. package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -1
  39. package/dist/culling/lib/culling-volume.d.ts +3 -0
  40. package/dist/culling/lib/culling-volume.d.ts.map +1 -1
  41. package/dist/culling/lib/culling-volume.js +7 -0
  42. package/dist/culling/lib/culling-volume.js.map +1 -1
  43. package/dist/culling/lib/ray.d.ts +5 -0
  44. package/dist/culling/lib/ray.d.ts.map +1 -1
  45. package/dist/culling/lib/ray.js +21 -0
  46. package/dist/culling/lib/ray.js.map +1 -1
  47. package/dist/culling/screen-ray.d.ts +22 -0
  48. package/dist/culling/screen-ray.d.ts.map +1 -0
  49. package/dist/culling/screen-ray.js +55 -0
  50. package/dist/culling/screen-ray.js.map +1 -0
  51. package/dist/curves/adaptive-sampling.d.ts +16 -0
  52. package/dist/curves/adaptive-sampling.d.ts.map +1 -0
  53. package/dist/curves/adaptive-sampling.js +59 -0
  54. package/dist/curves/adaptive-sampling.js.map +1 -0
  55. package/dist/curves/index.d.ts +4 -0
  56. package/dist/curves/index.d.ts.map +1 -1
  57. package/dist/curves/index.js +2 -0
  58. package/dist/curves/index.js.map +1 -1
  59. package/dist/curves/parallel-transport.d.ts +12 -0
  60. package/dist/curves/parallel-transport.d.ts.map +1 -0
  61. package/dist/curves/parallel-transport.js +83 -0
  62. package/dist/curves/parallel-transport.js.map +1 -0
  63. package/dist/index.cjs +1988 -934
  64. package/dist/index.cjs.map +3 -3
  65. package/dist/index.d.ts +17 -5
  66. package/dist/index.d.ts.map +1 -1
  67. package/dist/index.js +9 -2
  68. package/dist/index.js.map +1 -1
  69. package/dist/lighting/index.cjs +175 -0
  70. package/dist/lighting/index.cjs.map +6 -0
  71. package/dist/lighting/index.d.ts +4 -0
  72. package/dist/lighting/index.d.ts.map +1 -0
  73. package/dist/lighting/index.js +5 -0
  74. package/dist/lighting/index.js.map +1 -0
  75. package/dist/lighting/lighting-types.d.ts +16 -0
  76. package/dist/lighting/lighting-types.d.ts.map +1 -0
  77. package/dist/lighting/lighting-types.js +5 -0
  78. package/dist/lighting/lighting-types.js.map +1 -0
  79. package/dist/lighting/photometry.d.ts +36 -0
  80. package/dist/lighting/photometry.d.ts.map +1 -0
  81. package/dist/lighting/photometry.js +181 -0
  82. package/dist/lighting/photometry.js.map +1 -0
  83. package/dist/polygon/cut-by-grid.d.ts.map +1 -1
  84. package/dist/polygon/cut-by-grid.js +18 -0
  85. package/dist/polygon/cut-by-grid.js.map +1 -1
  86. package/dist/polygon/earcut.d.ts.map +1 -1
  87. package/dist/polygon/earcut.js +100 -34
  88. package/dist/polygon/earcut.js.map +1 -1
  89. package/dist/polygon/index.d.ts +2 -0
  90. package/dist/polygon/index.d.ts.map +1 -1
  91. package/dist/polygon/index.js +1 -0
  92. package/dist/polygon/index.js.map +1 -1
  93. package/dist/polygon/pole-of-inaccessibility.d.ts +21 -0
  94. package/dist/polygon/pole-of-inaccessibility.d.ts.map +1 -0
  95. package/dist/polygon/pole-of-inaccessibility.js +285 -0
  96. package/dist/polygon/pole-of-inaccessibility.js.map +1 -0
  97. package/dist/polygon/subdivide-triangle-mesh.d.ts +10 -0
  98. package/dist/polygon/subdivide-triangle-mesh.d.ts.map +1 -1
  99. package/dist/polygon/subdivide-triangle-mesh.js +67 -19
  100. package/dist/polygon/subdivide-triangle-mesh.js.map +1 -1
  101. package/dist/utils/compose-attribute-provenance.d.ts +13 -0
  102. package/dist/utils/compose-attribute-provenance.d.ts.map +1 -0
  103. package/dist/utils/compose-attribute-provenance.js +63 -0
  104. package/dist/utils/compose-attribute-provenance.js.map +1 -0
  105. package/dist/utils/compute-vertex-normals.d.ts +2 -2
  106. package/dist/utils/compute-vertex-normals.d.ts.map +1 -1
  107. package/dist/utils/compute-vertex-normals.js +3 -4
  108. package/dist/utils/compute-vertex-normals.js.map +1 -1
  109. package/dist/utils/geometry.d.ts +11 -4
  110. package/dist/utils/geometry.d.ts.map +1 -1
  111. package/dist/utils/geometry.js +19 -2
  112. package/dist/utils/geometry.js.map +1 -1
  113. package/dist/utils/index.d.ts +1 -3
  114. package/dist/utils/index.d.ts.map +1 -1
  115. package/dist/utils/index.js +0 -2
  116. package/dist/utils/index.js.map +1 -1
  117. package/dist/utils/mesh-processing.d.ts +16 -6
  118. package/dist/utils/mesh-processing.d.ts.map +1 -1
  119. package/dist/utils/mesh-processing.js +9 -6
  120. package/dist/utils/mesh-processing.js.map +1 -1
  121. package/dist/utils/primitive-iterator.d.ts +16 -8
  122. package/dist/utils/primitive-iterator.d.ts.map +1 -1
  123. package/dist/utils/primitive-iterator.js +32 -35
  124. package/dist/utils/primitive-iterator.js.map +1 -1
  125. package/dist/utils/project-bounds.d.ts +44 -0
  126. package/dist/utils/project-bounds.d.ts.map +1 -0
  127. package/dist/utils/project-bounds.js +93 -0
  128. package/dist/utils/project-bounds.js.map +1 -0
  129. package/dist/utils/project-texture-coordinates.d.ts +19 -0
  130. package/dist/utils/project-texture-coordinates.d.ts.map +1 -0
  131. package/dist/utils/project-texture-coordinates.js +49 -0
  132. package/dist/utils/project-texture-coordinates.js.map +1 -0
  133. package/dist/utils/qualify-surface-transition.d.ts +21 -0
  134. package/dist/utils/qualify-surface-transition.d.ts.map +1 -0
  135. package/dist/utils/qualify-surface-transition.js +140 -0
  136. package/dist/utils/qualify-surface-transition.js.map +1 -0
  137. package/package.json +15 -3
  138. package/src/color/color-lut-types.ts +19 -0
  139. package/src/color/index.ts +6 -0
  140. package/src/color/sample-lut.ts +175 -0
  141. package/src/culling/bounds.ts +152 -0
  142. package/src/culling/frustum-planes.ts +41 -0
  143. package/src/culling/geometric-queries.ts +299 -0
  144. package/src/culling/index.ts +39 -1
  145. package/src/culling/lib/bounding-volumes/axis-aligned-bounding-box.ts +26 -8
  146. package/src/culling/lib/culling-volume.ts +9 -1
  147. package/src/culling/lib/ray.ts +21 -0
  148. package/src/culling/screen-ray.ts +75 -0
  149. package/src/curves/adaptive-sampling.ts +85 -0
  150. package/src/curves/index.ts +4 -0
  151. package/src/curves/parallel-transport.ts +104 -0
  152. package/src/index.ts +71 -9
  153. package/src/lighting/index.ts +10 -0
  154. package/src/lighting/lighting-types.ts +20 -0
  155. package/src/lighting/photometry.ts +264 -0
  156. package/src/polygon/cut-by-grid.ts +18 -0
  157. package/src/polygon/earcut.ts +98 -37
  158. package/src/polygon/index.ts +6 -0
  159. package/src/polygon/pole-of-inaccessibility.ts +330 -0
  160. package/src/polygon/subdivide-triangle-mesh.ts +77 -17
  161. package/src/utils/compose-attribute-provenance.ts +74 -0
  162. package/src/utils/compute-vertex-normals.ts +5 -6
  163. package/src/utils/geometry.ts +32 -6
  164. package/src/utils/index.ts +5 -5
  165. package/src/utils/mesh-processing.ts +30 -14
  166. package/src/utils/primitive-iterator.ts +45 -43
  167. package/src/utils/project-bounds.ts +154 -0
  168. package/src/utils/project-texture-coordinates.ts +67 -0
  169. package/src/utils/qualify-surface-transition.ts +169 -0
  170. package/dist/utils/constants.d.ts +0 -52
  171. package/dist/utils/constants.d.ts.map +0 -1
  172. package/dist/utils/constants.js +0 -39
  173. package/dist/utils/constants.js.map +0 -1
  174. package/dist/utils/gl-type.d.ts +0 -17
  175. package/dist/utils/gl-type.d.ts.map +0 -1
  176. package/dist/utils/gl-type.js +0 -69
  177. package/dist/utils/gl-type.js.map +0 -1
  178. package/src/utils/constants.ts +0 -42
  179. package/src/utils/gl-type.ts +0 -87
@@ -32,19 +32,46 @@ __export(index_exports, {
32
32
  SphereShape: () => SphereShape,
33
33
  _PerspectiveFrustum: () => PerspectiveFrustum,
34
34
  _PerspectiveOffCenterFrustum: () => PerspectiveOffCenterFrustum,
35
+ boundsContainsBounds: () => boundsContainsBounds,
36
+ boundsContainsPoint: () => boundsContainsPoint,
37
+ boundsIntersect: () => boundsIntersect,
38
+ boundsIntersectSphere: () => boundsIntersectSphere,
39
+ clampPointToBounds: () => clampPointToBounds,
35
40
  computeEigenDecomposition: () => computeEigenDecomposition,
41
+ createEmptyBounds: () => createEmptyBounds,
42
+ distanceToRay: () => distanceToRay,
43
+ expandBounds: () => expandBounds,
44
+ expandBoundsByPoint: () => expandBoundsByPoint,
45
+ extractFrustumPlanes: () => extractFrustumPlanes,
46
+ getClosestPointOnRay: () => getClosestPointOnRay,
36
47
  getClosestPointOnTriangle: () => getClosestPointOnTriangle,
37
48
  getClosestPointsOnSegments: () => getClosestPointsOnSegments,
49
+ getClosestPointsRaySegment: () => getClosestPointsRaySegment,
38
50
  getClosestPointsSegmentTriangle: () => getClosestPointsSegmentTriangle,
39
51
  getOrientedBoundingBoxQuaternion: () => getOrientedBoundingBoxQuaternion,
52
+ getRayPoint: () => getRayPoint,
53
+ getTriangleArea: () => getTriangleArea,
54
+ getTriangleBarycentric: () => getTriangleBarycentric,
55
+ getTriangleNormal: () => getTriangleNormal,
56
+ interpolateTriangleAttribute: () => interpolateTriangleAttribute,
57
+ intersectBounds: () => intersectBounds,
40
58
  intersectOrientedBoxes2D: () => intersectOrientedBoxes2D,
59
+ intersectPlaneSegment: () => intersectPlaneSegment,
41
60
  intersectRayBounds: () => intersectRayBounds,
42
61
  intersectRayTriangle: () => intersectRayTriangle,
62
+ isEmptyBounds: () => isEmptyBounds,
63
+ isTriangleFrontFacing: () => isTriangleFrontFacing,
43
64
  makeAxisAlignedBoundingBoxFromPoints: () => makeAxisAlignedBoundingBoxFromPoints,
44
65
  makeBoundingSphereFromPoints: () => makeBoundingSphereFromPoints,
45
66
  makeOrientedBoundingBoxFromPoints: () => makeOrientedBoundingBoxFromPoints,
46
67
  makeOrientedBoundingBoxFromQuaternion: () => makeOrientedBoundingBoxFromQuaternion,
47
68
  normalizeQueryDirection: () => normalizeQueryDirection,
69
+ spheresIntersect: () => spheresIntersect,
70
+ transformRay: () => transformRay,
71
+ triangleContainsPoint: () => triangleContainsPoint,
72
+ triangleIntersectsBounds: () => triangleIntersectsBounds,
73
+ unionBounds: () => unionBounds,
74
+ unprojectScreenRay: () => unprojectScreenRay,
48
75
  validateQueryDistance: () => validateQueryDistance,
49
76
  validateQueryPoint: () => validateQueryPoint
50
77
  });
@@ -87,15 +114,25 @@ var AxisAlignedBoundingBox = class _AxisAlignedBoundingBox {
87
114
  return this === right || Boolean(right) && this.minimum.equals(right.minimum) && this.maximum.equals(right.maximum);
88
115
  }
89
116
  /**
90
- * Applies a 4x4 affine transformation matrix to a bounding sphere.
91
- * @param transform The transformation matrix to apply to the bounding sphere.
92
- * @returns itself, i.e. the modified BoundingVolume.
117
+ * Transforms an AABB by a finite affine matrix, rebuilding all bounds and extents.
118
+ * @param transform The affine transformation matrix.
119
+ * @returns itself, i.e. the modified bounding box.
93
120
  */
94
121
  transform(transform) {
95
- this.center.transformAsPoint(transform);
96
- this.halfDiagonal.transform(transform);
97
- this.minimum.transform(transform);
98
- this.maximum.transform(transform);
122
+ if (transform.length !== 16 || transform.some((x) => !Number.isFinite(x)) || transform[3] !== 0 || transform[7] !== 0 || transform[11] !== 0 || transform[15] !== 1) {
123
+ throw new RangeError("Expected a finite affine matrix");
124
+ }
125
+ const center = this.minimum.clone().add(this.maximum).scale(0.5);
126
+ const extent = this.maximum.clone().subtract(this.minimum).scale(0.5);
127
+ if (extent.some((x) => x < 0))
128
+ throw new RangeError("Bounds must be ordered");
129
+ center.transformAsPoint(transform);
130
+ for (let row = 0; row < 3; row++) {
131
+ this.halfDiagonal[row] = Math.abs(transform[row]) * extent[0] + Math.abs(transform[row + 4]) * extent[1] + Math.abs(transform[row + 8]) * extent[2];
132
+ }
133
+ this.center.copy(center);
134
+ this.minimum.copy(center).subtract(this.halfDiagonal);
135
+ this.maximum.copy(center).add(this.halfDiagonal);
99
136
  return this;
100
137
  }
101
138
  /**
@@ -115,12 +152,12 @@ var AxisAlignedBoundingBox = class _AxisAlignedBoundingBox {
115
152
  return "intersecting";
116
153
  }
117
154
  /** Computes the estimated distance from the closest point on a bounding box to a point. */
118
- distanceTo(point) {
119
- return Math.sqrt(this.distanceSquaredTo(point));
155
+ distanceTo(point2) {
156
+ return Math.sqrt(this.distanceSquaredTo(point2));
120
157
  }
121
158
  /** Computes the estimated distance squared from the closest point on a bounding box to a point. */
122
- distanceSquaredTo(point) {
123
- const offset = scratchVector.from(point).subtract(this.center);
159
+ distanceSquaredTo(point2) {
160
+ const offset = scratchVector.from(point2).subtract(this.center);
124
161
  const { halfDiagonal } = this;
125
162
  let distanceSquared = 0;
126
163
  let d;
@@ -147,15 +184,15 @@ var scratchVector2 = new import_core2.Vector3();
147
184
  var scratchVector22 = new import_core2.Vector3();
148
185
  var BoundingSphere = class _BoundingSphere {
149
186
  /** Creates a bounding sphere */
150
- constructor(center = [0, 0, 0], radius = 0) {
187
+ constructor(center = [0, 0, 0], radius2 = 0) {
151
188
  this.radius = -0;
152
189
  this.center = new import_core2.Vector3();
153
- this.fromCenterRadius(center, radius);
190
+ this.fromCenterRadius(center, radius2);
154
191
  }
155
192
  /** Sets the bounding sphere from `center` and `radius`. */
156
- fromCenterRadius(center, radius) {
193
+ fromCenterRadius(center, radius2) {
157
194
  this.center.from(center);
158
- this.radius = radius;
195
+ this.radius = radius2;
159
196
  return this;
160
197
  }
161
198
  /**
@@ -197,11 +234,11 @@ var BoundingSphere = class _BoundingSphere {
197
234
  return this;
198
235
  }
199
236
  /** Computes a bounding sphere by enlarging the provided sphere to contain the provided point. */
200
- expand(point) {
201
- const scratchPoint = scratchVector2.from(point);
202
- const radius = scratchPoint.subtract(this.center).magnitude();
203
- if (radius > this.radius) {
204
- this.radius = radius;
237
+ expand(point2) {
238
+ const scratchPoint = scratchVector2.from(point2);
239
+ const radius2 = scratchPoint.subtract(this.center).magnitude();
240
+ if (radius2 > this.radius) {
241
+ this.radius = radius2;
205
242
  }
206
243
  return this;
207
244
  }
@@ -219,26 +256,26 @@ var BoundingSphere = class _BoundingSphere {
219
256
  return this;
220
257
  }
221
258
  /** Computes the estimated distance squared from the closest point on a bounding sphere to a point. */
222
- distanceSquaredTo(point) {
223
- const d = this.distanceTo(point);
259
+ distanceSquaredTo(point2) {
260
+ const d = this.distanceTo(point2);
224
261
  return d * d;
225
262
  }
226
263
  /** Computes the estimated distance from the closest point on a bounding sphere to a point. */
227
- distanceTo(point) {
228
- const scratchPoint = scratchVector2.from(point);
264
+ distanceTo(point2) {
265
+ const scratchPoint = scratchVector2.from(point2);
229
266
  const delta = scratchPoint.subtract(this.center);
230
267
  return Math.max(0, delta.len() - this.radius);
231
268
  }
232
269
  /** Determines which side of a plane a sphere is located. */
233
270
  intersectPlane(plane) {
234
271
  const center = this.center;
235
- const radius = this.radius;
272
+ const radius2 = this.radius;
236
273
  const normal = plane.normal;
237
274
  const distanceToPlane = normal.dot(center) + plane.distance;
238
- if (distanceToPlane < -radius) {
275
+ if (distanceToPlane < -radius2) {
239
276
  return "outside";
240
277
  }
241
- if (distanceToPlane < radius) {
278
+ if (distanceToPlane < radius2) {
242
279
  return "intersecting";
243
280
  }
244
281
  return "inside";
@@ -314,16 +351,16 @@ var OrientedBoundingBox = class _OrientedBoundingBox {
314
351
  return "intersecting";
315
352
  }
316
353
  /** Computes the estimated distance from the closest point on a bounding box to a point. */
317
- distanceTo(point) {
318
- return Math.sqrt(this.distanceSquaredTo(point));
354
+ distanceTo(point2) {
355
+ return Math.sqrt(this.distanceSquaredTo(point2));
319
356
  }
320
357
  /**
321
358
  * Computes the estimated distance squared from the closest point
322
359
  * on a bounding box to a point.
323
360
  * See Geometric Tools for Computer Graphics 10.4.2
324
361
  */
325
- distanceSquaredTo(point) {
326
- const offset = scratchOffset.from(point).subtract(this.center);
362
+ distanceSquaredTo(point2) {
363
+ const offset = scratchOffset.from(point2).subtract(this.center);
327
364
  const halfAxes = this.halfAxes;
328
365
  const u = halfAxes.getColumn(0, scratchVectorU);
329
366
  const v = halfAxes.getColumn(1, scratchVectorV);
@@ -365,7 +402,7 @@ var OrientedBoundingBox = class _OrientedBoundingBox {
365
402
  * on the bounding box from position in direction.
366
403
  */
367
404
  // eslint-disable-next-line max-statements
368
- computePlaneDistances(position, direction, result = [-0, -0]) {
405
+ computePlaneDistances(position, direction2, result = [-0, -0]) {
369
406
  let minDist = Number.POSITIVE_INFINITY;
370
407
  let maxDist = Number.NEGATIVE_INFINITY;
371
408
  const center = this.center;
@@ -375,42 +412,42 @@ var OrientedBoundingBox = class _OrientedBoundingBox {
375
412
  const w = halfAxes.getColumn(2, scratchVectorW);
376
413
  const corner = scratchCorner.copy(u).add(v).add(w).add(center);
377
414
  const toCenter = scratchToCenter.copy(corner).subtract(position);
378
- let mag = direction.dot(toCenter);
415
+ let mag = direction2.dot(toCenter);
379
416
  minDist = Math.min(mag, minDist);
380
417
  maxDist = Math.max(mag, maxDist);
381
418
  corner.copy(center).add(u).add(v).subtract(w);
382
419
  toCenter.copy(corner).subtract(position);
383
- mag = direction.dot(toCenter);
420
+ mag = direction2.dot(toCenter);
384
421
  minDist = Math.min(mag, minDist);
385
422
  maxDist = Math.max(mag, maxDist);
386
423
  corner.copy(center).add(u).subtract(v).add(w);
387
424
  toCenter.copy(corner).subtract(position);
388
- mag = direction.dot(toCenter);
425
+ mag = direction2.dot(toCenter);
389
426
  minDist = Math.min(mag, minDist);
390
427
  maxDist = Math.max(mag, maxDist);
391
428
  corner.copy(center).add(u).subtract(v).subtract(w);
392
429
  toCenter.copy(corner).subtract(position);
393
- mag = direction.dot(toCenter);
430
+ mag = direction2.dot(toCenter);
394
431
  minDist = Math.min(mag, minDist);
395
432
  maxDist = Math.max(mag, maxDist);
396
433
  center.copy(corner).subtract(u).add(v).add(w);
397
434
  toCenter.copy(corner).subtract(position);
398
- mag = direction.dot(toCenter);
435
+ mag = direction2.dot(toCenter);
399
436
  minDist = Math.min(mag, minDist);
400
437
  maxDist = Math.max(mag, maxDist);
401
438
  center.copy(corner).subtract(u).add(v).subtract(w);
402
439
  toCenter.copy(corner).subtract(position);
403
- mag = direction.dot(toCenter);
440
+ mag = direction2.dot(toCenter);
404
441
  minDist = Math.min(mag, minDist);
405
442
  maxDist = Math.max(mag, maxDist);
406
443
  center.copy(corner).subtract(u).subtract(v).add(w);
407
444
  toCenter.copy(corner).subtract(position);
408
- mag = direction.dot(toCenter);
445
+ mag = direction2.dot(toCenter);
409
446
  minDist = Math.min(mag, minDist);
410
447
  maxDist = Math.max(mag, maxDist);
411
448
  center.copy(corner).subtract(u).subtract(v).subtract(w);
412
449
  toCenter.copy(corner).subtract(position);
413
- mag = direction.dot(toCenter);
450
+ mag = direction2.dot(toCenter);
414
451
  minDist = Math.min(mag, minDist);
415
452
  maxDist = Math.max(mag, maxDist);
416
453
  result[0] = minDist;
@@ -439,6 +476,9 @@ var OrientedBoundingBox = class _OrientedBoundingBox {
439
476
  };
440
477
 
441
478
  // dist/culling/lib/culling-volume.js
479
+ var import_core7 = require("@math.gl/core");
480
+
481
+ // dist/culling/frustum-planes.js
442
482
  var import_core6 = require("@math.gl/core");
443
483
 
444
484
  // dist/culling/lib/plane.js
@@ -459,10 +499,10 @@ var Plane = class _Plane {
459
499
  return this;
460
500
  }
461
501
  /** Creates a plane from a normal and a point on the plane. */
462
- fromPointNormal(point, normal) {
463
- point = scratchPosition.from(point);
502
+ fromPointNormal(point2, normal) {
503
+ point2 = scratchPosition.from(point2);
464
504
  this.normal.from(normal).normalize();
465
- const distance = -this.normal.dot(point);
505
+ const distance = -this.normal.dot(point2);
466
506
  this.distance = distance;
467
507
  return this;
468
508
  }
@@ -484,17 +524,17 @@ var Plane = class _Plane {
484
524
  /** Computes the signed shortest distance of a point to a plane.
485
525
  * The sign of the distance determines which side of the plane the point is on.
486
526
  */
487
- getPointDistance(point) {
488
- return this.normal.dot(point) + this.distance;
527
+ getPointDistance(point2) {
528
+ return this.normal.dot(point2) + this.distance;
489
529
  }
490
530
  /** Transforms the plane by the given transformation matrix. */
491
531
  transform(matrix4) {
492
532
  const normal = scratchNormal2.copy(this.normal).transformAsVector(matrix4).normalize();
493
- const point = this.normal.scale(-this.distance).transform(matrix4);
494
- return this.fromPointNormal(point, normal);
533
+ const point2 = this.normal.scale(-this.distance).transform(matrix4);
534
+ return this.fromPointNormal(point2, normal);
495
535
  }
496
- projectPointOntoPlane(point, result = [0, 0, 0]) {
497
- const scratchPoint = scratchPosition.from(point);
536
+ projectPointOntoPlane(point2, result = [0, 0, 0]) {
537
+ const scratchPoint = scratchPosition.from(point2);
498
538
  const pointDistance = this.getPointDistance(scratchPoint);
499
539
  const scaledNormal = scratchNormal2.copy(this.normal).scale(pointDistance);
500
540
  return scratchPoint.subtract(scaledNormal).to(result);
@@ -508,9 +548,9 @@ var Plane = class _Plane {
508
548
  */
509
549
  intersectWithRay(ray, result = new import_core5.Vector3()) {
510
550
  const origin = ray.origin;
511
- const direction = ray.direction;
551
+ const direction2 = ray.direction;
512
552
  const normal = this.normal;
513
- const denominator = normal.dot(direction);
553
+ const denominator = normal.dot(direction2);
514
554
  if (Math.abs(denominator) < import_core5._MathUtils.EPSILON15) {
515
555
  return void 0;
516
556
  }
@@ -518,14 +558,45 @@ var Plane = class _Plane {
518
558
  if (t < 0) {
519
559
  return void 0;
520
560
  }
521
- return result.copy(direction).multiplyByScalar(t).add(origin);
561
+ return result.copy(direction2).multiplyByScalar(t).add(origin);
522
562
  }
523
563
  };
524
564
 
565
+ // dist/culling/frustum-planes.js
566
+ function extractFrustumPlanes(matrix, options = {}) {
567
+ if (matrix.length !== 16 || Array.from(matrix).some((x2) => !Number.isFinite(x2)))
568
+ throw new RangeError("Expected a finite view-projection matrix");
569
+ const [near, far] = (0, import_core6.getProjectionDepthRange)(options);
570
+ const low = Math.min(near, far), high = Math.max(near, far);
571
+ const row = (i) => [matrix[i], matrix[i + 4], matrix[i + 8], matrix[i + 12]];
572
+ const x = row(0), y = row(1), z = row(2), w = row(3);
573
+ const combine = (a, b, factor) => a.map((v, i) => v + factor * b[i]);
574
+ const lo = combine(z, w, -low), hi = w.map((v, i) => high * v - z[i]);
575
+ const coefficients = [
576
+ combine(w, x, 1),
577
+ combine(w, x, -1),
578
+ combine(w, y, 1),
579
+ combine(w, y, -1),
580
+ ...options.reversedDepth ? [hi, lo] : [lo, hi]
581
+ ];
582
+ const planes = [];
583
+ for (const [a, b, c, d] of coefficients) {
584
+ const length = Math.hypot(a, b, c);
585
+ if (length === 0) {
586
+ if (d < 0)
587
+ throw new RangeError("Empty clipping volume");
588
+ } else
589
+ planes.push(new Plane([a / length, b / length, c / length], d / length));
590
+ }
591
+ if (planes.length < 4)
592
+ throw new RangeError("Degenerate clipping volume");
593
+ return planes;
594
+ }
595
+
525
596
  // dist/culling/lib/culling-volume.js
526
- var faces = [new import_core6.Vector3([1, 0, 0]), new import_core6.Vector3([0, 1, 0]), new import_core6.Vector3([0, 0, 1])];
527
- var scratchPlaneCenter = new import_core6.Vector3();
528
- var scratchPlaneNormal = new import_core6.Vector3();
597
+ var faces = [new import_core7.Vector3([1, 0, 0]), new import_core7.Vector3([0, 1, 0]), new import_core7.Vector3([0, 0, 1])];
598
+ var scratchPlaneCenter = new import_core7.Vector3();
599
+ var scratchPlaneNormal = new import_core7.Vector3();
529
600
  var CullingVolume = class _CullingVolume {
530
601
  /**
531
602
  * Create a new `CullingVolume` bounded by an array of clipping planed
@@ -541,7 +612,7 @@ var CullingVolume = class _CullingVolume {
541
612
  fromBoundingSphere(boundingSphere) {
542
613
  this.planes.length = 2 * faces.length;
543
614
  const center = boundingSphere.center;
544
- const radius = boundingSphere.radius;
615
+ const radius2 = boundingSphere.radius;
545
616
  let planeIndex = 0;
546
617
  for (const faceNormal of faces) {
547
618
  let plane0 = this.planes[planeIndex];
@@ -552,15 +623,21 @@ var CullingVolume = class _CullingVolume {
552
623
  if (!plane1) {
553
624
  plane1 = this.planes[planeIndex + 1] = new Plane();
554
625
  }
555
- const plane0Center = scratchPlaneCenter.copy(faceNormal).scale(-radius).add(center);
626
+ const plane0Center = scratchPlaneCenter.copy(faceNormal).scale(-radius2).add(center);
556
627
  plane0.fromPointNormal(plane0Center, faceNormal);
557
- const plane1Center = scratchPlaneCenter.copy(faceNormal).scale(radius).add(center);
628
+ const plane1Center = scratchPlaneCenter.copy(faceNormal).scale(radius2).add(center);
558
629
  const negatedFaceNormal = scratchPlaneNormal.copy(faceNormal).negate();
559
630
  plane1.fromPointNormal(plane1Center, negatedFaceNormal);
560
631
  planeIndex += 2;
561
632
  }
562
633
  return this;
563
634
  }
635
+ /** Replace planes from a view-projection matrix; validates before mutating. */
636
+ fromViewProjection(matrix, options = {}) {
637
+ const planes = extractFrustumPlanes(matrix, options);
638
+ this.planes.splice(0, this.planes.length, ...planes);
639
+ return this;
640
+ }
564
641
  /** Determines whether a bounding volume intersects the culling volume. */
565
642
  computeVisibility(boundingVolume) {
566
643
  let intersect = "inside";
@@ -586,7 +663,7 @@ var CullingVolume = class _CullingVolume {
586
663
  * and that plane check can be skipped.
587
664
  */
588
665
  computeVisibilityWithPlaneMask(boundingVolume, parentPlaneMask) {
589
- (0, import_core6.assert)(Number.isFinite(parentPlaneMask), "parentPlaneMask is required.");
666
+ (0, import_core7.assert)(Number.isFinite(parentPlaneMask), "parentPlaneMask is required.");
590
667
  if (parentPlaneMask === _CullingVolume.MASK_OUTSIDE || parentPlaneMask === _CullingVolume.MASK_INSIDE) {
591
668
  return parentPlaneMask;
592
669
  }
@@ -613,7 +690,441 @@ CullingVolume.MASK_INSIDE = 0;
613
690
  CullingVolume.MASK_INDETERMINATE = 2147483647;
614
691
 
615
692
  // dist/culling/lib/ray.js
616
- var import_core7 = require("@math.gl/core");
693
+ var import_core8 = require("@math.gl/core");
694
+
695
+ // dist/culling/queries.js
696
+ function validateQueryPoint(point2, dimension2) {
697
+ if (point2.length !== dimension2)
698
+ throw new RangeError("Query dimension must match the index");
699
+ for (let i = 0; i < dimension2; i++) {
700
+ if (!Number.isFinite(point2[i]))
701
+ throw new RangeError("Coordinates must be finite");
702
+ }
703
+ }
704
+ function validateQueryDistance(distance) {
705
+ if (Number.isNaN(distance) || distance < 0)
706
+ throw new RangeError("Distance must be nonnegative");
707
+ }
708
+ function normalizeQueryDirection(direction2, dimension2) {
709
+ validateQueryPoint(direction2, dimension2);
710
+ const scale = Math.max(...Array.from(direction2, Math.abs));
711
+ if (scale === 0)
712
+ throw new RangeError("Ray direction must be nonzero");
713
+ const scaled = Array.from(direction2, (x) => x / scale);
714
+ const length = Math.hypot(...scaled);
715
+ return scaled.map((x) => x / length);
716
+ }
717
+ function intersectRayBounds(origin, direction2, minimum, maximum, maxT = Infinity) {
718
+ const dimension2 = origin.length;
719
+ if (dimension2 !== 2 && dimension2 !== 3)
720
+ throw new RangeError("Bounds must be 2D or 3D");
721
+ validateQueryPoint(origin, dimension2);
722
+ validateQueryPoint(direction2, dimension2);
723
+ validateQueryPoint(minimum, dimension2);
724
+ validateQueryPoint(maximum, dimension2);
725
+ validateQueryDistance(maxT);
726
+ let near = 0, far = maxT, nonzero = false;
727
+ for (let i = 0; i < dimension2; i++) {
728
+ if (minimum[i] > maximum[i])
729
+ throw new RangeError("Bounds must be ordered");
730
+ nonzero || (nonzero = direction2[i] !== 0);
731
+ }
732
+ if (!nonzero)
733
+ throw new RangeError("Ray direction must be nonzero");
734
+ for (let i = 0; i < dimension2; i++) {
735
+ if (direction2[i] === 0) {
736
+ if (origin[i] < minimum[i] || origin[i] > maximum[i])
737
+ return null;
738
+ continue;
739
+ }
740
+ let a = (minimum[i] - origin[i]) / direction2[i];
741
+ let b = (maximum[i] - origin[i]) / direction2[i];
742
+ if (a > b)
743
+ [a, b] = [b, a];
744
+ near = Math.max(near, a);
745
+ far = Math.min(far, b);
746
+ if (near > far)
747
+ return null;
748
+ }
749
+ return Number.isFinite(near) ? near : null;
750
+ }
751
+ function intersectRayTriangle(origin, direction2, a, b, c, options = {}) {
752
+ for (const point2 of [origin, direction2, a, b, c])
753
+ validateQueryPoint(point2, 3);
754
+ if (direction2[0] === 0 && direction2[1] === 0 && direction2[2] === 0) {
755
+ throw new RangeError("Ray direction must be nonzero");
756
+ }
757
+ const maxT = options.maxT ?? Infinity;
758
+ validateQueryDistance(maxT);
759
+ const e1 = [b[0] - a[0], b[1] - a[1], b[2] - a[2]];
760
+ const e2 = [c[0] - a[0], c[1] - a[1], c[2] - a[2]];
761
+ const p = cross(direction2, e2);
762
+ const determinant = dot(e1, p);
763
+ if (determinant === 0 || options.backfaceCulling && determinant < 0)
764
+ return null;
765
+ const offset = [origin[0] - a[0], origin[1] - a[1], origin[2] - a[2]];
766
+ const u = dot(offset, p) / determinant;
767
+ if (u < 0 || u > 1)
768
+ return null;
769
+ const q = cross(offset, e1);
770
+ const v = dot(direction2, q) / determinant;
771
+ if (v < 0 || u + v > 1)
772
+ return null;
773
+ const t = dot(e2, q) / determinant;
774
+ if (!Number.isFinite(t) || t < 0 || t > maxT)
775
+ return null;
776
+ return { t: Math.max(0, t), barycentric: [1 - u - v, u, v] };
777
+ }
778
+ function getClosestPointOnTriangle(point2, a, b, c) {
779
+ for (const value of [point2, a, b, c])
780
+ validateQueryPoint(value, 3);
781
+ const ab = [b[0] - a[0], b[1] - a[1], b[2] - a[2]];
782
+ const ac = [c[0] - a[0], c[1] - a[1], c[2] - a[2]];
783
+ const ap = [point2[0] - a[0], point2[1] - a[1], point2[2] - a[2]];
784
+ const aa = dot(ab, ab), bb = dot(ac, ac), cc = dot(ab, ac);
785
+ const denominator = aa * bb - cc * cc;
786
+ if (denominator > 0 && Number.isFinite(denominator)) {
787
+ const u = (bb * dot(ap, ab) - cc * dot(ap, ac)) / denominator;
788
+ const v = (aa * dot(ap, ac) - cc * dot(ap, ab)) / denominator;
789
+ if (u >= 0 && v >= 0 && u + v <= 1) {
790
+ return [
791
+ a[0] + u * ab[0] + v * ac[0],
792
+ a[1] + u * ab[1] + v * ac[1],
793
+ a[2] + u * ab[2] + v * ac[2]
794
+ ];
795
+ }
796
+ }
797
+ let best = [a[0], a[1], a[2]];
798
+ let distance = Infinity;
799
+ for (const [start, end] of [
800
+ [a, b],
801
+ [b, c],
802
+ [c, a]
803
+ ]) {
804
+ const edge = [end[0] - start[0], end[1] - start[1], end[2] - start[2]];
805
+ const offset = [point2[0] - start[0], point2[1] - start[1], point2[2] - start[2]];
806
+ const squared = dot(edge, edge);
807
+ const t = squared > 0 ? Math.max(0, Math.min(1, dot(offset, edge) / squared)) : 0;
808
+ const candidate = [
809
+ start[0] + t * edge[0],
810
+ start[1] + t * edge[1],
811
+ start[2] + t * edge[2]
812
+ ];
813
+ const d = Math.hypot(point2[0] - candidate[0], point2[1] - candidate[1], point2[2] - candidate[2]);
814
+ if (d < distance) {
815
+ distance = d;
816
+ best = candidate;
817
+ }
818
+ }
819
+ return best;
820
+ }
821
+ function getClosestPointsOnSegments(a0, a1, b0, b1) {
822
+ const frame = queryFrame([a0, a1, b0, b1]);
823
+ const pair2 = closestSegments(...frame.points);
824
+ const pointA = interpolatePoint(a0, a1, pair2.fractionA);
825
+ const pointB = interpolatePoint(b0, b1, pair2.fractionB);
826
+ return {
827
+ distance: finiteDistance(pointA, pointB),
828
+ pointA,
829
+ pointB,
830
+ fractionA: pair2.fractionA,
831
+ fractionB: pair2.fractionB
832
+ };
833
+ }
834
+ function getClosestPointsSegmentTriangle(start, end, a, b, c) {
835
+ const frame = queryFrame([start, end, a, b, c]);
836
+ const [s, e, va, vb, vc] = frame.points;
837
+ const direction2 = subtract(e, s);
838
+ if (direction2.some((value) => value !== 0)) {
839
+ const hit = intersectRayTriangle(s, direction2, va, vb, vc, { maxT: 1 });
840
+ if (hit) {
841
+ const point2 = interpolatePoint(start, end, hit.t);
842
+ return { distance: 0, segmentPoint: point2, trianglePoint: [...point2], segmentFraction: hit.t };
843
+ }
844
+ }
845
+ let best = { distance: Infinity, segmentFraction: 0, trianglePoint: va };
846
+ const consider = (point2, trianglePoint2, segmentFraction) => {
847
+ const distance = Math.hypot(...subtract(point2, trianglePoint2));
848
+ if (distance < best.distance || distance === best.distance && segmentFraction < best.segmentFraction)
849
+ best = { distance, segmentFraction, trianglePoint: trianglePoint2 };
850
+ };
851
+ consider(s, getClosestPointOnTriangle(s, va, vb, vc), 0);
852
+ consider(e, getClosestPointOnTriangle(e, va, vb, vc), 1);
853
+ for (const [v0, v1] of [
854
+ [va, vb],
855
+ [vb, vc],
856
+ [vc, va]
857
+ ]) {
858
+ const pair2 = closestSegments(s, e, v0, v1);
859
+ consider(interpolatePoint(s, e, pair2.fractionA), interpolatePoint(v0, v1, pair2.fractionB), pair2.fractionA);
860
+ }
861
+ 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)));
862
+ if (!trianglePoint.every(Number.isFinite))
863
+ throw new RangeError("Closest-point result overflow");
864
+ const segmentPoint = interpolatePoint(start, end, best.segmentFraction);
865
+ return {
866
+ distance: finiteDistance(segmentPoint, trianglePoint),
867
+ segmentPoint,
868
+ trianglePoint,
869
+ segmentFraction: best.segmentFraction
870
+ };
871
+ }
872
+ function queryFrame(input) {
873
+ input.forEach((point2) => validateQueryPoint(point2, 3));
874
+ const offsets = input.map((point2) => subtract(point2, input[0]));
875
+ let scale = 0;
876
+ for (const offset of offsets)
877
+ for (const value of offset) {
878
+ if (!Number.isFinite(value))
879
+ throw new RangeError("Closest-point coordinate span overflow");
880
+ scale = Math.max(scale, Math.abs(value));
881
+ }
882
+ scale || (scale = 1);
883
+ return { points: offsets.map((point2) => point2.map((value) => value / scale)), scale };
884
+ }
885
+ function closestSegments(a0, a1, b0, b1) {
886
+ const da = subtract(a1, a0), db = subtract(b1, b0);
887
+ const lengthA = Math.hypot(...da), lengthB = Math.hypot(...db);
888
+ const ua = da.map((value) => lengthA ? value / lengthA : 0);
889
+ const ub = db.map((value) => lengthB ? value / lengthB : 0);
890
+ let best = { distance: Infinity, fractionA: 0, fractionB: 0 };
891
+ const consider = (fractionA, fractionB) => {
892
+ const distance = Math.hypot(...subtract(interpolatePoint(a0, a1, fractionA), interpolatePoint(b0, b1, fractionB)));
893
+ if (distance < best.distance || distance === best.distance && (fractionA < best.fractionA || fractionA === best.fractionA && fractionB < best.fractionB))
894
+ best = { distance, fractionA, fractionB };
895
+ };
896
+ for (const t of [0, 1]) {
897
+ consider(t, lengthB ? clampUnit(dot(subtract(t ? a1 : a0, b0), ub) / lengthB) : 0);
898
+ consider(lengthA ? clampUnit(dot(subtract(t ? b1 : b0, a0), ua) / lengthA) : 0, t);
899
+ }
900
+ const normal = cross(ua, ub);
901
+ const sine = Math.hypot(...normal);
902
+ if (sine > 0) {
903
+ const unit = normal.map((value) => value / sine);
904
+ const offset = subtract(b0, a0);
905
+ const fractionA = dot(cross(offset, ub), unit) / sine / lengthA;
906
+ const fractionB = dot(cross(offset, ua), unit) / sine / lengthB;
907
+ if (fractionA >= 0 && fractionA <= 1 && fractionB >= 0 && fractionB <= 1)
908
+ consider(fractionA, fractionB);
909
+ }
910
+ return best;
911
+ }
912
+ function subtract(a, b) {
913
+ return [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
914
+ }
915
+ function interpolatePoint(a, b, t) {
916
+ 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])));
917
+ }
918
+ function clampUnit(value) {
919
+ return Math.max(0, Math.min(1, value));
920
+ }
921
+ function finiteDistance(a, b) {
922
+ const distance = Math.hypot(...subtract(a, b));
923
+ if (!Number.isFinite(distance))
924
+ throw new RangeError("Closest-point distance overflow");
925
+ return distance;
926
+ }
927
+ function dot(a, b) {
928
+ return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
929
+ }
930
+ function cross(a, b) {
931
+ 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]];
932
+ }
933
+
934
+ // dist/culling/geometric-queries.js
935
+ var sub = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
936
+ var dot2 = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
937
+ var cross2 = (a, b) => [
938
+ a[1] * b[2] - a[2] * b[1],
939
+ a[2] * b[0] - a[0] * b[2],
940
+ a[0] * b[1] - a[1] * b[0]
941
+ ];
942
+ var check = (...points) => {
943
+ for (const p of points)
944
+ validateQueryPoint(p, 3);
945
+ };
946
+ function output(out, values) {
947
+ if (out.length < values.length)
948
+ throw new RangeError("Result buffer is too short");
949
+ const copy = Array.from(values);
950
+ for (let i = 0; i < copy.length; i++)
951
+ out[i] = copy[i];
952
+ return out;
953
+ }
954
+ function direction(d) {
955
+ check(d);
956
+ if (Math.hypot(d[0], d[1], d[2]) === 0)
957
+ throw new RangeError("Ray direction must be nonzero");
958
+ }
959
+ function getRayPoint(origin, dir, t, out = [0, 0, 0]) {
960
+ check(origin);
961
+ direction(dir);
962
+ if (!Number.isFinite(t) || t < 0)
963
+ throw new RangeError("Ray parameter must be finite and nonnegative");
964
+ return output(out, [origin[0] + t * dir[0], origin[1] + t * dir[1], origin[2] + t * dir[2]]);
965
+ }
966
+ function getClosestPointOnRay(point2, origin, dir, out = [0, 0, 0]) {
967
+ check(point2, origin);
968
+ direction(dir);
969
+ const unit = normalizeQueryDirection(dir, 3);
970
+ const distance = Math.max(0, dot2(sub(point2, origin), unit));
971
+ return output(out, [0, 1, 2].map((i) => origin[i] + distance * unit[i]));
972
+ }
973
+ function distanceToRay(point2, origin, dir) {
974
+ const p = getClosestPointOnRay(point2, origin, dir);
975
+ return Math.hypot(...sub(point2, p));
976
+ }
977
+ function getClosestPointsRaySegment(origin, dir, a, b) {
978
+ check(origin, a, b);
979
+ direction(dir);
980
+ const unit = normalizeQueryDirection(dir, 3);
981
+ const directionLength = Math.hypot(dir[0], dir[1], dir[2]);
982
+ const edge = sub(b, a), offset = sub(origin, a);
983
+ const segmentLength = Math.hypot(...edge);
984
+ const segmentUnit = edge.map((x) => segmentLength ? x / segmentLength : 0);
985
+ const bb = dot2(unit, segmentUnit), dd = dot2(unit, offset), ee = dot2(segmentUnit, offset);
986
+ const candidates = [
987
+ [0, Math.max(0, Math.min(segmentLength, ee))],
988
+ [Math.max(0, -dd), 0],
989
+ [Math.max(0, bb * segmentLength - dd), segmentLength]
990
+ ];
991
+ const normal = cross2(unit, segmentUnit);
992
+ const sine = Math.hypot(...normal);
993
+ if (segmentLength > 0 && sine > 0) {
994
+ const normalUnit = normal.map((value) => value / sine);
995
+ const separation = sub(a, origin);
996
+ const t = dot2(cross2(separation, segmentUnit), normalUnit) / sine;
997
+ const u = dot2(cross2(separation, unit), normalUnit) / sine;
998
+ if (t >= 0 && u >= 0 && u <= segmentLength)
999
+ candidates.push([t, u]);
1000
+ }
1001
+ let best;
1002
+ for (const [t, u] of candidates) {
1003
+ const rayPoint = [
1004
+ origin[0] + t * unit[0],
1005
+ origin[1] + t * unit[1],
1006
+ origin[2] + t * unit[2]
1007
+ ];
1008
+ const segmentPoint = [
1009
+ a[0] + u * segmentUnit[0],
1010
+ a[1] + u * segmentUnit[1],
1011
+ a[2] + u * segmentUnit[2]
1012
+ ];
1013
+ const distance = Math.hypot(...sub(rayPoint, segmentPoint));
1014
+ if (!best || distance < best.distance)
1015
+ best = {
1016
+ rayPoint,
1017
+ segmentPoint,
1018
+ rayParameter: t / directionLength,
1019
+ segmentFraction: segmentLength ? u / segmentLength : 0,
1020
+ distance
1021
+ };
1022
+ }
1023
+ return best;
1024
+ }
1025
+ function transformRay(origin, dir, matrix) {
1026
+ check(origin);
1027
+ direction(dir);
1028
+ if (matrix.length !== 16 || Array.from(matrix).some((x) => !Number.isFinite(x)) || matrix[3] !== 0 || matrix[7] !== 0 || matrix[11] !== 0 || matrix[15] !== 1)
1029
+ throw new RangeError("Expected a finite affine matrix");
1030
+ 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]);
1031
+ const transformed = { origin: apply(origin, 1), direction: apply(dir, 0) };
1032
+ check(transformed.origin);
1033
+ direction(transformed.direction);
1034
+ return transformed;
1035
+ }
1036
+ function triangle(a, b, c) {
1037
+ check(a, b, c);
1038
+ const ab = sub(b, a), ac = sub(c, a);
1039
+ const scale = Math.max(Math.hypot(...ab), Math.hypot(...ac));
1040
+ const u = ab.map((x) => scale ? x / scale : 0), v = ac.map((x) => scale ? x / scale : 0);
1041
+ return { u, v, scale, normal: cross2(u, v) };
1042
+ }
1043
+ function getTriangleBarycentric(point2, a, b, c, out = [0, 0, 0]) {
1044
+ check(point2);
1045
+ const { u, v, scale, normal } = triangle(a, b, c), denominator = dot2(normal, normal);
1046
+ if (denominator === 0)
1047
+ return null;
1048
+ const p = sub(point2, a).map((x) => x / scale);
1049
+ const second = dot2(cross2(p, v), normal) / denominator;
1050
+ const third = dot2(cross2(u, p), normal) / denominator;
1051
+ return output(out, [1 - second - third, second, third]);
1052
+ }
1053
+ function getTriangleArea(a, b, c) {
1054
+ const { normal, scale } = triangle(a, b, c);
1055
+ return Math.hypot(...normal) * scale * scale / 2;
1056
+ }
1057
+ function getTriangleNormal(a, b, c, out = [0, 0, 0]) {
1058
+ const { normal } = triangle(a, b, c), length = Math.hypot(...normal);
1059
+ return output(out, normal.map((x) => length ? x / length : 0));
1060
+ }
1061
+ function isTriangleFrontFacing(a, b, c, dir) {
1062
+ direction(dir);
1063
+ return dot2(triangle(a, b, c).normal, dir) < 0;
1064
+ }
1065
+ function triangleContainsPoint(point2, a, b, c, tolerance = 1e-10) {
1066
+ if (!Number.isFinite(tolerance) || tolerance < 0)
1067
+ throw new RangeError("Invalid tolerance");
1068
+ const weights = getTriangleBarycentric(point2, a, b, c);
1069
+ if (!weights)
1070
+ return false;
1071
+ const { normal, scale } = triangle(a, b, c);
1072
+ const distance = Math.abs(dot2(sub(point2, a).map((x) => x / scale), normal)) / Math.hypot(...normal);
1073
+ return distance <= tolerance && Array.from(weights).every((x) => x >= -tolerance && x <= 1 + tolerance);
1074
+ }
1075
+ function interpolateTriangleAttribute(weights, a, b, c, out = new Array(a.length)) {
1076
+ check(weights);
1077
+ if (!a.length || a.length !== b.length || a.length !== c.length || [a, b, c].some((p) => Array.from(p).some((x) => !Number.isFinite(x))))
1078
+ throw new RangeError("Expected matching finite attributes");
1079
+ return output(out, Array.from(a, (x, i) => weights[0] * x + weights[1] * b[i] + weights[2] * c[i]));
1080
+ }
1081
+ function intersectPlaneSegment(normal, constant, start, end, out = [0, 0, 0]) {
1082
+ check(start, end);
1083
+ direction(normal);
1084
+ if (!Number.isFinite(constant))
1085
+ throw new RangeError("Plane constant must be finite");
1086
+ const a = dot2(normal, start) + constant, b = dot2(normal, end) + constant;
1087
+ if (a === 0)
1088
+ return output(out, start);
1089
+ if (b === 0)
1090
+ return output(out, end);
1091
+ if (a > 0 === b > 0)
1092
+ return null;
1093
+ const t = a / (a - b);
1094
+ return output(out, [0, 1, 2].map((i) => start[i] + t * (end[i] - start[i])));
1095
+ }
1096
+ function triangleIntersectsBounds(a, b, c, minimum, maximum) {
1097
+ check(a, b, c, minimum, maximum);
1098
+ if ([0, 1, 2].some((i) => minimum[i] > maximum[i]))
1099
+ return false;
1100
+ const center = [0, 1, 2].map((i) => minimum[i] / 2 + maximum[i] / 2);
1101
+ const extent = [0, 1, 2].map((i) => maximum[i] / 2 - minimum[i] / 2);
1102
+ const vertices = [a, b, c].map((p) => sub(p, center));
1103
+ const edges = [sub(b, a), sub(c, b), sub(a, c)];
1104
+ const basis = [
1105
+ [1, 0, 0],
1106
+ [0, 1, 0],
1107
+ [0, 0, 1]
1108
+ ];
1109
+ const axes = [
1110
+ ...basis,
1111
+ cross2(edges[0], edges[1]),
1112
+ ...edges.flatMap((e) => basis.map((axis) => cross2(e, axis)))
1113
+ ];
1114
+ for (const axis of axes) {
1115
+ const length = Math.hypot(...axis);
1116
+ if (!length)
1117
+ continue;
1118
+ const unit = axis.map((x) => x / length);
1119
+ const projections = vertices.map((v) => dot2(v, unit));
1120
+ const radius2 = extent.reduce((sum, x, i) => sum + x * Math.abs(unit[i]), 0);
1121
+ if (Math.min(...projections) > radius2 || Math.max(...projections) < -radius2)
1122
+ return false;
1123
+ }
1124
+ return true;
1125
+ }
1126
+
1127
+ // dist/culling/lib/ray.js
617
1128
  var Ray = class {
618
1129
  /**
619
1130
  * Creates a new ray that extends infinitely from the provided origin in the provided direction.
@@ -621,25 +1132,44 @@ var Ray = class {
621
1132
  * @param [origin=Vector3] The origin of the ray.
622
1133
  * @param [direction=Vector3] The direction of the ray.
623
1134
  */
624
- constructor(origin, direction) {
1135
+ constructor(origin, direction2) {
625
1136
  if (origin)
626
1137
  origin = origin.clone();
627
1138
  else
628
- origin = new import_core7.Vector3();
629
- if (direction)
630
- direction = direction.clone().normalize();
1139
+ origin = new import_core8.Vector3();
1140
+ if (direction2)
1141
+ direction2 = direction2.clone().normalize();
631
1142
  else
632
- direction = new import_core7.Vector3();
1143
+ direction2 = new import_core8.Vector3();
633
1144
  this.origin = origin;
634
- this.direction = direction;
1145
+ this.direction = direction2;
1146
+ }
1147
+ at(t, result = new import_core8.Vector3()) {
1148
+ getRayPoint(this.origin, this.direction, t, result);
1149
+ return result;
1150
+ }
1151
+ closestPointTo(point2, result = new import_core8.Vector3()) {
1152
+ getClosestPointOnRay(point2, this.origin, this.direction, result);
1153
+ return result;
1154
+ }
1155
+ distanceTo(point2) {
1156
+ return distanceToRay(point2, this.origin, this.direction);
1157
+ }
1158
+ /** Transform and renormalize: subsequent parameters are distances in the new space. */
1159
+ transform(matrix) {
1160
+ const ray = transformRay(this.origin, this.direction, matrix);
1161
+ const normalized = normalizeQueryDirection(ray.direction, 3);
1162
+ this.origin.copy(ray.origin);
1163
+ this.direction.copy(normalized);
1164
+ return this;
635
1165
  }
636
1166
  };
637
1167
 
638
1168
  // dist/culling/lib/shapes/implicit-shape.js
639
- var import_core8 = require("@math.gl/core");
1169
+ var import_core9 = require("@math.gl/core");
640
1170
  var ImplicitShapeBase = class {
641
1171
  constructor(matrix) {
642
- this.matrix = new import_core8.Matrix4();
1172
+ this.matrix = new import_core9.Matrix4();
643
1173
  if (matrix)
644
1174
  this.matrix.copy(matrix);
645
1175
  validateAffineMatrix(this.matrix);
@@ -654,23 +1184,23 @@ var ImplicitShapeBase = class {
654
1184
  return true;
655
1185
  }
656
1186
  transform(transform) {
657
- const next = new import_core8.Matrix4().copy(transform);
1187
+ const next = new import_core9.Matrix4().copy(transform);
658
1188
  validateAffineMatrix(next);
659
1189
  this.matrix.multiplyLeft(next);
660
1190
  validateAffineMatrix(this.matrix);
661
1191
  this.inverseMatrix.copy(this.matrix).invert();
662
1192
  return this;
663
1193
  }
664
- containsPoint(point) {
665
- return this.containsLocalPoint(this.inverseMatrix.transformAsPoint(point));
1194
+ containsPoint(point2) {
1195
+ return this.containsLocalPoint(this.inverseMatrix.transformAsPoint(point2));
666
1196
  }
667
- distanceSquaredTo(point) {
668
- const distance = this.distanceTo(point);
1197
+ distanceSquaredTo(point2) {
1198
+ const distance = this.distanceTo(point2);
669
1199
  return distance * distance;
670
1200
  }
671
1201
  /** Exact for rigid/uniform transforms; conservative estimate for non-uniform scale or shear. */
672
- distanceTo(point) {
673
- const localPoint = this.inverseMatrix.transformAsPoint(point);
1202
+ distanceTo(point2) {
1203
+ const localPoint = this.inverseMatrix.transformAsPoint(point2);
674
1204
  const localDistance = this.distanceToLocalPoint(localPoint);
675
1205
  const scales = this.matrix.getScale();
676
1206
  return localDistance * Math.min(scales[0], scales[1], scales[2]);
@@ -692,20 +1222,20 @@ var ImplicitShapeBase = class {
692
1222
  const hit = this.intersectLocalRay(localOrigin, localDirection);
693
1223
  if (!hit || hit.distance < 0)
694
1224
  return void 0;
695
- const point = new import_core8.Vector3(ray.direction).scale(hit.distance).add(ray.origin);
1225
+ const point2 = new import_core9.Vector3(ray.direction).scale(hit.distance).add(ray.origin);
696
1226
  const inverse = this.inverseMatrix;
697
- const normal = new import_core8.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();
698
- return { distance: hit.distance, point, normal, entering: ray.direction.dot(normal) < 0 };
1227
+ const normal = new import_core9.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();
1228
+ return { distance: hit.distance, point: point2, normal, entering: ray.direction.dot(normal) < 0 };
699
1229
  }
700
1230
  getAxisAlignedBoundingBox() {
701
- const minimum = new import_core8.Vector3();
702
- const maximum = new import_core8.Vector3();
1231
+ const minimum = new import_core9.Vector3();
1232
+ const maximum = new import_core9.Vector3();
703
1233
  for (let axis = 0; axis < 3; axis++) {
704
- const direction = [0, 0, 0];
705
- direction[axis] = 1;
706
- maximum[axis] = this.getSupportPoint(direction)[axis];
707
- direction[axis] = -1;
708
- minimum[axis] = this.getSupportPoint(direction)[axis];
1234
+ const direction2 = [0, 0, 0];
1235
+ direction2[axis] = 1;
1236
+ maximum[axis] = this.getSupportPoint(direction2)[axis];
1237
+ direction2[axis] = -1;
1238
+ minimum[axis] = this.getSupportPoint(direction2)[axis];
709
1239
  }
710
1240
  return new AxisAlignedBoundingBox(minimum, maximum);
711
1241
  }
@@ -722,7 +1252,7 @@ var ImplicitShapeBase = class {
722
1252
  matrix[4] * worldDirection[0] + matrix[5] * worldDirection[1] + matrix[6] * worldDirection[2],
723
1253
  matrix[8] * worldDirection[0] + matrix[9] * worldDirection[1] + matrix[10] * worldDirection[2]
724
1254
  ];
725
- return new import_core8.Vector3(this.supportLocal(localDirection)).transform(this.matrix);
1255
+ return new import_core9.Vector3(this.supportLocal(localDirection)).transform(this.matrix);
726
1256
  }
727
1257
  };
728
1258
  function validateAffineMatrix(matrix) {
@@ -732,7 +1262,7 @@ function validateAffineMatrix(matrix) {
732
1262
  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) {
733
1263
  throw new Error("Shape matrix must be affine");
734
1264
  }
735
- if (Math.abs(new import_core8.Matrix4().copy(matrix).determinant()) < 1e-15)
1265
+ if (Math.abs(new import_core9.Matrix4().copy(matrix).determinant()) < 1e-15)
736
1266
  throw new Error("Shape matrix must be invertible");
737
1267
  }
738
1268
  function solveQuadratic(a, b, c) {
@@ -751,19 +1281,19 @@ function closestDistanceToSegment2D(px, py, ax, ay, bx, by) {
751
1281
  const t = denominator ? Math.max(0, Math.min(1, ((px - ax) * dx + (py - ay) * dy) / denominator)) : 0;
752
1282
  return Math.hypot(px - (ax + t * dx), py - (ay + t * dy));
753
1283
  }
754
- function closestDistanceToCircleArc2D(px, py, centerY, radius, minimumNormalY, maximumNormalY) {
755
- if (radius === 0)
1284
+ function closestDistanceToCircleArc2D(px, py, centerY, radius2, minimumNormalY, maximumNormalY) {
1285
+ if (radius2 === 0)
756
1286
  return Math.hypot(px, py - centerY);
757
1287
  const dx = px;
758
1288
  const dy = py - centerY;
759
1289
  const length = Math.hypot(dx, dy);
760
1290
  const normalY = length ? dy / length : 0;
761
1291
  if (normalY >= minimumNormalY && normalY <= maximumNormalY) {
762
- return Math.abs(length - radius);
1292
+ return Math.abs(length - radius2);
763
1293
  }
764
- const minimumRadius = radius * Math.sqrt(Math.max(0, 1 - minimumNormalY ** 2));
765
- const maximumRadius = radius * Math.sqrt(Math.max(0, 1 - maximumNormalY ** 2));
766
- return Math.min(Math.hypot(px - minimumRadius, py - (centerY + radius * minimumNormalY)), Math.hypot(px - maximumRadius, py - (centerY + radius * maximumNormalY)));
1294
+ const minimumRadius = radius2 * Math.sqrt(Math.max(0, 1 - minimumNormalY ** 2));
1295
+ const maximumRadius = radius2 * Math.sqrt(Math.max(0, 1 - maximumNormalY ** 2));
1296
+ return Math.min(Math.hypot(px - minimumRadius, py - (centerY + radius2 * minimumNormalY)), Math.hypot(px - maximumRadius, py - (centerY + radius2 * maximumNormalY)));
767
1297
  }
768
1298
 
769
1299
  // dist/culling/lib/shapes/box-shape.js
@@ -783,28 +1313,28 @@ var BoxShape = class _BoxShape extends ImplicitShapeBase {
783
1313
  equals(shape) {
784
1314
  return shape instanceof _BoxShape && super.equals(shape) && this.size.every((value, i) => value === shape.size[i]);
785
1315
  }
786
- containsLocalPoint(point) {
787
- return point.every((value, i) => Math.abs(value) <= this.halfSize[i] + EPSILON);
1316
+ containsLocalPoint(point2) {
1317
+ return point2.every((value, i) => Math.abs(value) <= this.halfSize[i] + EPSILON);
788
1318
  }
789
- distanceToLocalPoint(point) {
790
- return Math.hypot(...point.map((value, i) => Math.max(0, Math.abs(value) - this.halfSize[i])));
1319
+ distanceToLocalPoint(point2) {
1320
+ return Math.hypot(...point2.map((value, i) => Math.max(0, Math.abs(value) - this.halfSize[i])));
791
1321
  }
792
- supportLocal(direction) {
793
- return direction.map((value, i) => value < 0 ? -this.halfSize[i] : this.halfSize[i]);
1322
+ supportLocal(direction2) {
1323
+ return direction2.map((value, i) => value < 0 ? -this.halfSize[i] : this.halfSize[i]);
794
1324
  }
795
- intersectLocalRay(origin, direction) {
1325
+ intersectLocalRay(origin, direction2) {
796
1326
  let near = -Infinity;
797
1327
  let far = Infinity;
798
1328
  let nearAxis = 0;
799
1329
  let farAxis = 0;
800
1330
  for (let axis2 = 0; axis2 < 3; axis2++) {
801
- if (Math.abs(direction[axis2]) < 1e-15) {
1331
+ if (Math.abs(direction2[axis2]) < 1e-15) {
802
1332
  if (Math.abs(origin[axis2]) > this.halfSize[axis2])
803
1333
  return void 0;
804
1334
  continue;
805
1335
  }
806
- let t1 = (-this.halfSize[axis2] - origin[axis2]) / direction[axis2];
807
- let t2 = (this.halfSize[axis2] - origin[axis2]) / direction[axis2];
1336
+ let t1 = (-this.halfSize[axis2] - origin[axis2]) / direction2[axis2];
1337
+ let t2 = (this.halfSize[axis2] - origin[axis2]) / direction2[axis2];
808
1338
  if (t1 > t2)
809
1339
  [t1, t2] = [t2, t1];
810
1340
  if (t1 > near) {
@@ -822,7 +1352,7 @@ var BoxShape = class _BoxShape extends ImplicitShapeBase {
822
1352
  if (distance < 0 || !Number.isFinite(distance))
823
1353
  return void 0;
824
1354
  const axis = near >= 0 ? nearAxis : farAxis;
825
- const pointCoordinate = origin[axis] + distance * direction[axis];
1355
+ const pointCoordinate = origin[axis] + distance * direction2[axis];
826
1356
  const normal = [0, 0, 0];
827
1357
  normal[axis] = pointCoordinate < 0 ? -1 : 1;
828
1358
  return { distance, normal };
@@ -856,35 +1386,35 @@ var CapsuleShape = class _CapsuleShape extends ImplicitShapeBase {
856
1386
  equals(shape) {
857
1387
  return shape instanceof _CapsuleShape && super.equals(shape) && this.height === shape.height && this.radiusBottom === shape.radiusBottom && this.radiusTop === shape.radiusTop;
858
1388
  }
859
- containsLocalPoint(point) {
1389
+ containsLocalPoint(point2) {
860
1390
  const profile = this.getProfile();
861
- const radial = Math.hypot(point[0], point[2]);
1391
+ const radial = Math.hypot(point2[0], point2[2]);
862
1392
  if (profile.sphere)
863
- return Math.hypot(radial, point[1] - profile.sphere.center) <= profile.sphere.radius + EPSILON2;
864
- if (point[1] < profile.bottom.y)
865
- return Math.hypot(radial, point[1] + this.height / 2) <= this.radiusBottom + EPSILON2;
866
- if (point[1] > profile.top.y)
867
- return Math.hypot(radial, point[1] - this.height / 2) <= this.radiusTop + EPSILON2;
868
- const t = (point[1] - profile.bottom.y) / (profile.top.y - profile.bottom.y);
1393
+ return Math.hypot(radial, point2[1] - profile.sphere.center) <= profile.sphere.radius + EPSILON2;
1394
+ if (point2[1] < profile.bottom.y)
1395
+ return Math.hypot(radial, point2[1] + this.height / 2) <= this.radiusBottom + EPSILON2;
1396
+ if (point2[1] > profile.top.y)
1397
+ return Math.hypot(radial, point2[1] - this.height / 2) <= this.radiusTop + EPSILON2;
1398
+ const t = (point2[1] - profile.bottom.y) / (profile.top.y - profile.bottom.y);
869
1399
  return radial <= profile.bottom.radius + (profile.top.radius - profile.bottom.radius) * t + EPSILON2;
870
1400
  }
871
- distanceToLocalPoint(point) {
872
- if (this.containsLocalPoint(point))
1401
+ distanceToLocalPoint(point2) {
1402
+ if (this.containsLocalPoint(point2))
873
1403
  return 0;
874
1404
  const profile = this.getProfile();
875
- const radial = Math.hypot(point[0], point[2]);
1405
+ const radial = Math.hypot(point2[0], point2[2]);
876
1406
  if (profile.sphere)
877
- return Math.max(0, Math.hypot(radial, point[1] - profile.sphere.center) - profile.sphere.radius);
1407
+ return Math.max(0, Math.hypot(radial, point2[1] - profile.sphere.center) - profile.sphere.radius);
878
1408
  const delta = this.radiusTop - this.radiusBottom;
879
1409
  const sideNormalY = -delta / this.height;
880
- const bottomArc = closestDistanceToCircleArc2D(radial, point[1], -this.height / 2, this.radiusBottom, -1, sideNormalY);
881
- const topArc = closestDistanceToCircleArc2D(radial, point[1], this.height / 2, this.radiusTop, sideNormalY, 1);
882
- const side = closestDistanceToSegment2D(radial, point[1], profile.bottom.radius, profile.bottom.y, profile.top.radius, profile.top.y);
1410
+ const bottomArc = closestDistanceToCircleArc2D(radial, point2[1], -this.height / 2, this.radiusBottom, -1, sideNormalY);
1411
+ const topArc = closestDistanceToCircleArc2D(radial, point2[1], this.height / 2, this.radiusTop, sideNormalY, 1);
1412
+ const side = closestDistanceToSegment2D(radial, point2[1], profile.bottom.radius, profile.bottom.y, profile.top.radius, profile.top.y);
883
1413
  return Math.min(bottomArc, topArc, side);
884
1414
  }
885
- supportLocal(direction) {
886
- const length = Math.hypot(...direction);
887
- const unit = length ? direction.map((value) => value / length) : [1, 0, 0];
1415
+ supportLocal(direction2) {
1416
+ const length = Math.hypot(...direction2);
1417
+ const unit = length ? direction2.map((value) => value / length) : [1, 0, 0];
888
1418
  const bottom = [
889
1419
  unit[0] * this.radiusBottom,
890
1420
  -this.height / 2 + unit[1] * this.radiusBottom,
@@ -895,35 +1425,35 @@ var CapsuleShape = class _CapsuleShape extends ImplicitShapeBase {
895
1425
  this.height / 2 + unit[1] * this.radiusTop,
896
1426
  unit[2] * this.radiusTop
897
1427
  ];
898
- return dot(top, direction) >= dot(bottom, direction) ? top : bottom;
1428
+ return dot3(top, direction2) >= dot3(bottom, direction2) ? top : bottom;
899
1429
  }
900
- intersectLocalRay(origin, direction) {
1430
+ intersectLocalRay(origin, direction2) {
901
1431
  const profile = this.getProfile();
902
1432
  if (profile.sphere)
903
- return intersectSphere(origin, direction, profile.sphere.center, profile.sphere.radius);
1433
+ return intersectSphere(origin, direction2, profile.sphere.center, profile.sphere.radius);
904
1434
  const candidates = [];
905
1435
  const slope = (profile.top.radius - profile.bottom.radius) / (profile.top.y - profile.bottom.y);
906
1436
  const intercept = profile.bottom.radius - slope * profile.bottom.y;
907
1437
  const radialAtOrigin = intercept + slope * origin[1];
908
- const radialAlongRay = slope * direction[1];
909
- 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)) {
910
- const y = origin[1] + distance * direction[1];
1438
+ const radialAlongRay = slope * direction2[1];
1439
+ 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)) {
1440
+ const y = origin[1] + distance * direction2[1];
911
1441
  if (distance >= 0 && y >= profile.bottom.y - EPSILON2 && y <= profile.top.y + EPSILON2) {
912
- const x = origin[0] + distance * direction[0];
913
- const z = origin[2] + distance * direction[2];
1442
+ const x = origin[0] + distance * direction2[0];
1443
+ const z = origin[2] + distance * direction2[2];
914
1444
  const radial = Math.hypot(x, z) || 1;
915
1445
  const normal = [x / radial, -slope, z / radial];
916
1446
  const length = Math.hypot(...normal);
917
1447
  candidates.push({ distance, normal: normal.map((value) => value / length) });
918
1448
  }
919
1449
  }
920
- for (const bottomHit of intersectSphereRoots(origin, direction, -this.height / 2, this.radiusBottom)) {
921
- const y = origin[1] + bottomHit.distance * direction[1];
1450
+ for (const bottomHit of intersectSphereRoots(origin, direction2, -this.height / 2, this.radiusBottom)) {
1451
+ const y = origin[1] + bottomHit.distance * direction2[1];
922
1452
  if (y <= profile.bottom.y + EPSILON2)
923
1453
  candidates.push(bottomHit);
924
1454
  }
925
- for (const topHit of intersectSphereRoots(origin, direction, this.height / 2, this.radiusTop)) {
926
- const y = origin[1] + topHit.distance * direction[1];
1455
+ for (const topHit of intersectSphereRoots(origin, direction2, this.height / 2, this.radiusTop)) {
1456
+ const y = origin[1] + topHit.distance * direction2[1];
927
1457
  if (y >= profile.top.y - EPSILON2)
928
1458
  candidates.push(topHit);
929
1459
  }
@@ -954,19 +1484,19 @@ var CapsuleShape = class _CapsuleShape extends ImplicitShapeBase {
954
1484
  };
955
1485
  }
956
1486
  };
957
- function intersectSphere(origin, direction, centerY, radius) {
958
- return intersectSphereRoots(origin, direction, centerY, radius)[0];
1487
+ function intersectSphere(origin, direction2, centerY, radius2) {
1488
+ return intersectSphereRoots(origin, direction2, centerY, radius2)[0];
959
1489
  }
960
- function intersectSphereRoots(origin, direction, centerY, radius) {
961
- if (radius === 0)
1490
+ function intersectSphereRoots(origin, direction2, centerY, radius2) {
1491
+ if (radius2 === 0)
962
1492
  return [];
963
1493
  const relative = [origin[0], origin[1] - centerY, origin[2]];
964
- return solveQuadratic(dot(direction, direction), 2 * dot(relative, direction), dot(relative, relative) - radius * radius).filter((distance) => distance >= 0).map((distance) => ({
1494
+ return solveQuadratic(dot3(direction2, direction2), 2 * dot3(relative, direction2), dot3(relative, relative) - radius2 * radius2).filter((distance) => distance >= 0).map((distance) => ({
965
1495
  distance,
966
- normal: relative.map((value, i) => (value + distance * direction[i]) / radius)
1496
+ normal: relative.map((value, i) => (value + distance * direction2[i]) / radius2)
967
1497
  }));
968
1498
  }
969
- function dot(a, b) {
1499
+ function dot3(a, b) {
970
1500
  return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
971
1501
  }
972
1502
 
@@ -997,61 +1527,61 @@ var CylinderShape = class _CylinderShape extends ImplicitShapeBase {
997
1527
  equals(shape) {
998
1528
  return shape instanceof _CylinderShape && super.equals(shape) && this.height === shape.height && this.radiusBottom === shape.radiusBottom && this.radiusTop === shape.radiusTop;
999
1529
  }
1000
- containsLocalPoint(point) {
1530
+ containsLocalPoint(point2) {
1001
1531
  const half = this.height / 2;
1002
- if (point[1] < -half - EPSILON3 || point[1] > half + EPSILON3)
1532
+ if (point2[1] < -half - EPSILON3 || point2[1] > half + EPSILON3)
1003
1533
  return false;
1004
- const t = (point[1] + half) / this.height;
1005
- const radius = this.radiusBottom + (this.radiusTop - this.radiusBottom) * t;
1006
- return Math.hypot(point[0], point[2]) <= radius + EPSILON3;
1534
+ const t = (point2[1] + half) / this.height;
1535
+ const radius2 = this.radiusBottom + (this.radiusTop - this.radiusBottom) * t;
1536
+ return Math.hypot(point2[0], point2[2]) <= radius2 + EPSILON3;
1007
1537
  }
1008
- distanceToLocalPoint(point) {
1009
- if (this.containsLocalPoint(point))
1538
+ distanceToLocalPoint(point2) {
1539
+ if (this.containsLocalPoint(point2))
1010
1540
  return 0;
1011
- const radial = Math.hypot(point[0], point[2]);
1541
+ const radial = Math.hypot(point2[0], point2[2]);
1012
1542
  const half = this.height / 2;
1013
- const side = closestDistanceToSegment2D(radial, point[1], this.radiusBottom, -half, this.radiusTop, half);
1014
- const bottom = closestDistanceToSegment2D(radial, point[1], 0, -half, this.radiusBottom, -half);
1015
- const top = closestDistanceToSegment2D(radial, point[1], 0, half, this.radiusTop, half);
1543
+ const side = closestDistanceToSegment2D(radial, point2[1], this.radiusBottom, -half, this.radiusTop, half);
1544
+ const bottom = closestDistanceToSegment2D(radial, point2[1], 0, -half, this.radiusBottom, -half);
1545
+ const top = closestDistanceToSegment2D(radial, point2[1], 0, half, this.radiusTop, half);
1016
1546
  return Math.min(side, bottom, top);
1017
1547
  }
1018
- supportLocal(direction) {
1019
- const radialLength = Math.hypot(direction[0], direction[2]);
1020
- const x = radialLength ? direction[0] / radialLength : 1;
1021
- const z = radialLength ? direction[2] / radialLength : 0;
1548
+ supportLocal(direction2) {
1549
+ const radialLength = Math.hypot(direction2[0], direction2[2]);
1550
+ const x = radialLength ? direction2[0] / radialLength : 1;
1551
+ const z = radialLength ? direction2[2] / radialLength : 0;
1022
1552
  const half = this.height / 2;
1023
- const bottomValue = radialLength * this.radiusBottom - direction[1] * half;
1024
- const topValue = radialLength * this.radiusTop + direction[1] * half;
1553
+ const bottomValue = radialLength * this.radiusBottom - direction2[1] * half;
1554
+ const topValue = radialLength * this.radiusTop + direction2[1] * half;
1025
1555
  return topValue >= bottomValue ? [x * this.radiusTop, half, z * this.radiusTop] : [x * this.radiusBottom, -half, z * this.radiusBottom];
1026
1556
  }
1027
- intersectLocalRay(origin, direction) {
1557
+ intersectLocalRay(origin, direction2) {
1028
1558
  const half = this.height / 2;
1029
1559
  const slope = (this.radiusTop - this.radiusBottom) / this.height;
1030
1560
  const intercept = (this.radiusTop + this.radiusBottom) / 2;
1031
1561
  const radialAtOrigin = intercept + slope * origin[1];
1032
- const radialAlongRay = slope * direction[1];
1562
+ const radialAlongRay = slope * direction2[1];
1033
1563
  const candidates = [];
1034
- 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);
1564
+ 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);
1035
1565
  for (const distance of roots) {
1036
- const y = origin[1] + distance * direction[1];
1566
+ const y = origin[1] + distance * direction2[1];
1037
1567
  if (distance >= 0 && y >= -half - EPSILON3 && y <= half + EPSILON3) {
1038
- const x = origin[0] + distance * direction[0];
1039
- const z = origin[2] + distance * direction[2];
1568
+ const x = origin[0] + distance * direction2[0];
1569
+ const z = origin[2] + distance * direction2[2];
1040
1570
  const radial = Math.hypot(x, z) || 1;
1041
1571
  const normal = [x / radial, -slope, z / radial];
1042
1572
  const length = Math.hypot(...normal);
1043
1573
  candidates.push({ distance, normal: normal.map((value) => value / length) });
1044
1574
  }
1045
1575
  }
1046
- if (Math.abs(direction[1]) > 1e-15) {
1047
- for (const [y, radius, normalY] of [
1576
+ if (Math.abs(direction2[1]) > 1e-15) {
1577
+ for (const [y, radius2, normalY] of [
1048
1578
  [-half, this.radiusBottom, -1],
1049
1579
  [half, this.radiusTop, 1]
1050
1580
  ]) {
1051
- const distance = (y - origin[1]) / direction[1];
1052
- const x = origin[0] + distance * direction[0];
1053
- const z = origin[2] + distance * direction[2];
1054
- if (distance >= 0 && Math.hypot(x, z) <= radius + EPSILON3)
1581
+ const distance = (y - origin[1]) / direction2[1];
1582
+ const x = origin[0] + distance * direction2[0];
1583
+ const z = origin[2] + distance * direction2[2];
1584
+ if (distance >= 0 && Math.hypot(x, z) <= radius2 + EPSILON3)
1055
1585
  candidates.push({ distance, normal: [0, normalY, 0] });
1056
1586
  }
1057
1587
  }
@@ -1060,7 +1590,7 @@ var CylinderShape = class _CylinderShape extends ImplicitShapeBase {
1060
1590
  };
1061
1591
 
1062
1592
  // dist/culling/lib/shapes/plane-shape.js
1063
- var import_core9 = require("@math.gl/core");
1593
+ var import_core10 = require("@math.gl/core");
1064
1594
  var PlaneShape = class _PlaneShape extends ImplicitShapeBase {
1065
1595
  constructor(props = {}) {
1066
1596
  super(props.matrix);
@@ -1078,23 +1608,23 @@ var PlaneShape = class _PlaneShape extends ImplicitShapeBase {
1078
1608
  equals(shape) {
1079
1609
  return shape instanceof _PlaneShape && super.equals(shape) && this.sizeX === shape.sizeX && this.sizeZ === shape.sizeZ;
1080
1610
  }
1081
- containsLocalPoint(point) {
1082
- return point[1] <= 1e-12;
1611
+ containsLocalPoint(point2) {
1612
+ return point2[1] <= 1e-12;
1083
1613
  }
1084
- distanceToLocalPoint(point) {
1085
- return Math.max(0, point[1]);
1614
+ distanceToLocalPoint(point2) {
1615
+ return Math.max(0, point2[1]);
1086
1616
  }
1087
1617
  supportLocal() {
1088
1618
  throw new Error("An unbounded plane half-space has no finite support point");
1089
1619
  }
1090
- intersectLocalRay(origin, direction) {
1091
- if (Math.abs(direction[1]) < 1e-15)
1620
+ intersectLocalRay(origin, direction2) {
1621
+ if (Math.abs(direction2[1]) < 1e-15)
1092
1622
  return void 0;
1093
- const distance = -origin[1] / direction[1];
1623
+ const distance = -origin[1] / direction2[1];
1094
1624
  if (distance < 0)
1095
1625
  return void 0;
1096
- const x = origin[0] + distance * direction[0];
1097
- const z = origin[2] + distance * direction[2];
1626
+ const x = origin[0] + distance * direction2[0];
1627
+ const z = origin[2] + distance * direction2[2];
1098
1628
  if (this.sizeX !== void 0 && Math.abs(x) > this.sizeX / 2 + 1e-12)
1099
1629
  return void 0;
1100
1630
  if (this.sizeZ !== void 0 && Math.abs(z) > this.sizeZ / 2 + 1e-12)
@@ -1102,9 +1632,9 @@ var PlaneShape = class _PlaneShape extends ImplicitShapeBase {
1102
1632
  return { distance, normal: [0, 1, 0] };
1103
1633
  }
1104
1634
  intersectPlane(plane) {
1105
- const boundaryPoint = new import_core9.Vector3(0, 0, 0).transform(this.matrix);
1635
+ const boundaryPoint = new import_core10.Vector3(0, 0, 0).transform(this.matrix);
1106
1636
  const inverse = this.inverseMatrix;
1107
- const boundaryNormal = new import_core9.Vector3(inverse[1], inverse[5], inverse[9]).normalize();
1637
+ const boundaryNormal = new import_core10.Vector3(inverse[1], inverse[5], inverse[9]).normalize();
1108
1638
  const alignment = boundaryNormal.dot(plane.normal);
1109
1639
  if (Math.abs(Math.abs(alignment) - 1) > 1e-10)
1110
1640
  return "intersecting";
@@ -1139,36 +1669,36 @@ var SphereShape = class _SphereShape extends ImplicitShapeBase {
1139
1669
  equals(shape) {
1140
1670
  return shape instanceof _SphereShape && super.equals(shape) && this.radius === shape.radius;
1141
1671
  }
1142
- containsLocalPoint(point) {
1143
- return Math.hypot(...point) <= this.radius + EPSILON4;
1672
+ containsLocalPoint(point2) {
1673
+ return Math.hypot(...point2) <= this.radius + EPSILON4;
1144
1674
  }
1145
- distanceToLocalPoint(point) {
1146
- return Math.max(0, Math.hypot(...point) - this.radius);
1675
+ distanceToLocalPoint(point2) {
1676
+ return Math.max(0, Math.hypot(...point2) - this.radius);
1147
1677
  }
1148
- supportLocal(direction) {
1149
- const length = Math.hypot(...direction);
1150
- return length ? direction.map((value) => value / length * this.radius) : [this.radius, 0, 0];
1678
+ supportLocal(direction2) {
1679
+ const length = Math.hypot(...direction2);
1680
+ return length ? direction2.map((value) => value / length * this.radius) : [this.radius, 0, 0];
1151
1681
  }
1152
- intersectLocalRay(origin, direction) {
1153
- const roots = solveQuadratic(dot2(direction, direction), 2 * dot2(origin, direction), dot2(origin, origin) - this.radius * this.radius);
1682
+ intersectLocalRay(origin, direction2) {
1683
+ const roots = solveQuadratic(dot4(direction2, direction2), 2 * dot4(origin, direction2), dot4(origin, origin) - this.radius * this.radius);
1154
1684
  const distance = roots.find((value) => value >= 0);
1155
1685
  if (distance === void 0)
1156
1686
  return void 0;
1157
- const point = origin.map((value, i) => value + distance * direction[i]);
1158
- return { distance, normal: point.map((value) => value / this.radius) };
1687
+ const point2 = origin.map((value, i) => value + distance * direction2[i]);
1688
+ return { distance, normal: point2.map((value) => value / this.radius) };
1159
1689
  }
1160
1690
  };
1161
- function dot2(a, b) {
1691
+ function dot4(a, b) {
1162
1692
  return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
1163
1693
  }
1164
1694
 
1165
1695
  // dist/culling/lib/perspective-off-center-frustum.js
1166
- var import_core10 = require("@math.gl/core");
1167
- var scratchPlaneUpVector = new import_core10.Vector3();
1168
- var scratchPlaneRightVector = new import_core10.Vector3();
1169
- var scratchPlaneNearCenter = new import_core10.Vector3();
1170
- var scratchPlaneFarCenter = new import_core10.Vector3();
1171
- var scratchPlaneNormal2 = new import_core10.Vector3();
1696
+ var import_core11 = require("@math.gl/core");
1697
+ var scratchPlaneUpVector = new import_core11.Vector3();
1698
+ var scratchPlaneRightVector = new import_core11.Vector3();
1699
+ var scratchPlaneNearCenter = new import_core11.Vector3();
1700
+ var scratchPlaneFarCenter = new import_core11.Vector3();
1701
+ var scratchPlaneNormal2 = new import_core11.Vector3();
1172
1702
  var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
1173
1703
  /**
1174
1704
  * The viewing frustum is defined by 6 planes.
@@ -1199,8 +1729,8 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
1199
1729
  new Plane(),
1200
1730
  new Plane()
1201
1731
  ]);
1202
- this._perspectiveMatrix = new import_core10.Matrix4();
1203
- this._infinitePerspective = new import_core10.Matrix4();
1732
+ this._perspectiveMatrix = new import_core11.Matrix4();
1733
+ this._infinitePerspective = new import_core11.Matrix4();
1204
1734
  const { near = 1, far = 5e8 } = options;
1205
1735
  this.left = options.left;
1206
1736
  this._left = void 0;
@@ -1270,15 +1800,15 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
1270
1800
  * const intersect = cullingVolume.computeVisibility(boundingVolume);
1271
1801
  */
1272
1802
  // eslint-disable-next-line complexity, max-statements
1273
- computeCullingVolume(position, direction, up) {
1274
- (0, import_core10.assert)(position, "position is required.");
1275
- (0, import_core10.assert)(direction, "direction is required.");
1276
- (0, import_core10.assert)(up, "up is required.");
1803
+ computeCullingVolume(position, direction2, up) {
1804
+ (0, import_core11.assert)(position, "position is required.");
1805
+ (0, import_core11.assert)(direction2, "direction is required.");
1806
+ (0, import_core11.assert)(up, "up is required.");
1277
1807
  const planes = this._cullingVolume.planes;
1278
1808
  up = scratchPlaneUpVector.copy(up).normalize();
1279
- const right = scratchPlaneRightVector.copy(direction).cross(up).normalize();
1280
- const nearCenter = scratchPlaneNearCenter.copy(direction).multiplyByScalar(this.near).add(position);
1281
- const farCenter = scratchPlaneFarCenter.copy(direction).multiplyByScalar(this.far).add(position);
1809
+ const right = scratchPlaneRightVector.copy(direction2).cross(up).normalize();
1810
+ const nearCenter = scratchPlaneNearCenter.copy(direction2).multiplyByScalar(this.near).add(position);
1811
+ const farCenter = scratchPlaneFarCenter.copy(direction2).multiplyByScalar(this.far).add(position);
1282
1812
  let normal = scratchPlaneNormal2;
1283
1813
  normal.copy(right).multiplyByScalar(this.left).add(nearCenter).subtract(position).cross(up);
1284
1814
  planes[0].fromPointNormal(position, normal);
@@ -1288,7 +1818,7 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
1288
1818
  planes[2].fromPointNormal(position, normal);
1289
1819
  normal.copy(up).multiplyByScalar(this.top).add(nearCenter).subtract(position).cross(right);
1290
1820
  planes[3].fromPointNormal(position, normal);
1291
- normal = new import_core10.Vector3().copy(direction);
1821
+ normal = new import_core11.Vector3().copy(direction2);
1292
1822
  planes[4].fromPointNormal(nearCenter, normal);
1293
1823
  normal.negate();
1294
1824
  planes[5].fromPointNormal(farCenter, normal);
@@ -1320,11 +1850,11 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
1320
1850
  */
1321
1851
  getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {
1322
1852
  this._update();
1323
- (0, import_core10.assert)(Number.isFinite(drawingBufferWidth) && Number.isFinite(drawingBufferHeight));
1324
- (0, import_core10.assert)(drawingBufferWidth > 0);
1325
- (0, import_core10.assert)(drawingBufferHeight > 0);
1326
- (0, import_core10.assert)(distance > 0);
1327
- (0, import_core10.assert)(result);
1853
+ (0, import_core11.assert)(Number.isFinite(drawingBufferWidth) && Number.isFinite(drawingBufferHeight));
1854
+ (0, import_core11.assert)(drawingBufferWidth > 0);
1855
+ (0, import_core11.assert)(drawingBufferHeight > 0);
1856
+ (0, import_core11.assert)(distance > 0);
1857
+ (0, import_core11.assert)(result);
1328
1858
  const inverseNear = 1 / this.near;
1329
1859
  let tanTheta = this.top * inverseNear;
1330
1860
  const pixelHeight = 2 * distance * tanTheta / drawingBufferHeight;
@@ -1336,17 +1866,17 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
1336
1866
  }
1337
1867
  // eslint-disable-next-line complexity, max-statements
1338
1868
  _update() {
1339
- (0, import_core10.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));
1869
+ (0, import_core11.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));
1340
1870
  const { top, bottom, right, left, near, far } = this;
1341
1871
  if (top !== this._top || bottom !== this._bottom || left !== this._left || right !== this._right || near !== this._near || far !== this._far) {
1342
- (0, import_core10.assert)(this.near > 0 && this.near < this.far, "near must be greater than zero and less than far.");
1872
+ (0, import_core11.assert)(this.near > 0 && this.near < this.far, "near must be greater than zero and less than far.");
1343
1873
  this._left = left;
1344
1874
  this._right = right;
1345
1875
  this._top = top;
1346
1876
  this._bottom = bottom;
1347
1877
  this._near = near;
1348
1878
  this._far = far;
1349
- this._perspectiveMatrix = new import_core10.Matrix4().frustum({
1879
+ this._perspectiveMatrix = new import_core11.Matrix4().frustum({
1350
1880
  left,
1351
1881
  right,
1352
1882
  bottom,
@@ -1354,7 +1884,7 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
1354
1884
  near,
1355
1885
  far
1356
1886
  });
1357
- this._infinitePerspective = new import_core10.Matrix4().frustum({
1887
+ this._infinitePerspective = new import_core11.Matrix4().frustum({
1358
1888
  left,
1359
1889
  right,
1360
1890
  bottom,
@@ -1367,7 +1897,7 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
1367
1897
  };
1368
1898
 
1369
1899
  // dist/culling/lib/perspective-frustum.js
1370
- var import_core11 = require("@math.gl/core");
1900
+ var import_core12 = require("@math.gl/core");
1371
1901
  var defined = (val) => val !== null && typeof val !== "undefined";
1372
1902
  var PerspectiveFrustum = class _PerspectiveFrustum {
1373
1903
  constructor(options = {}) {
@@ -1440,9 +1970,9 @@ var PerspectiveFrustum = class _PerspectiveFrustum {
1440
1970
  * var cullingVolume = this.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);
1441
1971
  * var intersect = cullingVolume.computeVisibility(boundingVolume);
1442
1972
  */
1443
- computeCullingVolume(position, direction, up) {
1973
+ computeCullingVolume(position, direction2, up) {
1444
1974
  this._update();
1445
- return this._offCenterFrustum.computeCullingVolume(position, direction, up);
1975
+ return this._offCenterFrustum.computeCullingVolume(position, direction2, up);
1446
1976
  }
1447
1977
  /**
1448
1978
  * Returns the pixel's width and height in meters.
@@ -1469,16 +1999,16 @@ var PerspectiveFrustum = class _PerspectiveFrustum {
1469
1999
  */
1470
2000
  getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {
1471
2001
  this._update();
1472
- return this._offCenterFrustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result || new import_core11.Vector2());
2002
+ return this._offCenterFrustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result || new import_core12.Vector2());
1473
2003
  }
1474
2004
  // eslint-disable-next-line complexity, max-statements
1475
2005
  _update() {
1476
- (0, import_core11.assert)(Number.isFinite(this.fov) && Number.isFinite(this.aspectRatio) && Number.isFinite(this.near) && Number.isFinite(this.far));
2006
+ (0, import_core12.assert)(Number.isFinite(this.fov) && Number.isFinite(this.aspectRatio) && Number.isFinite(this.near) && Number.isFinite(this.far));
1477
2007
  const f = this._offCenterFrustum;
1478
2008
  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) {
1479
- (0, import_core11.assert)(this.fov >= 0 && this.fov < Math.PI);
1480
- (0, import_core11.assert)(this.aspectRatio > 0);
1481
- (0, import_core11.assert)(this.near >= 0 && this.near < this.far);
2009
+ (0, import_core12.assert)(this.fov >= 0 && this.fov < Math.PI);
2010
+ (0, import_core12.assert)(this.aspectRatio > 0);
2011
+ (0, import_core12.assert)(this.near >= 0 && this.near < this.far);
1482
2012
  this._aspectRatio = this.aspectRatio;
1483
2013
  this._fov = this.fov;
1484
2014
  this._fovy = this.aspectRatio <= 1 ? this.fov : Math.atan(Math.tan(this.fov * 0.5) / this.aspectRatio) * 2;
@@ -1502,19 +2032,19 @@ var PerspectiveFrustum = class _PerspectiveFrustum {
1502
2032
  };
1503
2033
 
1504
2034
  // dist/culling/lib/algorithms/bounding-sphere-from-points.js
1505
- var import_core12 = require("@math.gl/core");
1506
- var fromPointsXMin = new import_core12.Vector3();
1507
- var fromPointsYMin = new import_core12.Vector3();
1508
- var fromPointsZMin = new import_core12.Vector3();
1509
- var fromPointsXMax = new import_core12.Vector3();
1510
- var fromPointsYMax = new import_core12.Vector3();
1511
- var fromPointsZMax = new import_core12.Vector3();
1512
- var fromPointsCurrentPos = new import_core12.Vector3();
1513
- var fromPointsScratch = new import_core12.Vector3();
1514
- var fromPointsRitterCenter = new import_core12.Vector3();
1515
- var fromPointsMinBoxPt = new import_core12.Vector3();
1516
- var fromPointsMaxBoxPt = new import_core12.Vector3();
1517
- var fromPointsNaiveCenterScratch = new import_core12.Vector3();
2035
+ var import_core13 = require("@math.gl/core");
2036
+ var fromPointsXMin = new import_core13.Vector3();
2037
+ var fromPointsYMin = new import_core13.Vector3();
2038
+ var fromPointsZMin = new import_core13.Vector3();
2039
+ var fromPointsXMax = new import_core13.Vector3();
2040
+ var fromPointsYMax = new import_core13.Vector3();
2041
+ var fromPointsZMax = new import_core13.Vector3();
2042
+ var fromPointsCurrentPos = new import_core13.Vector3();
2043
+ var fromPointsScratch = new import_core13.Vector3();
2044
+ var fromPointsRitterCenter = new import_core13.Vector3();
2045
+ var fromPointsMinBoxPt = new import_core13.Vector3();
2046
+ var fromPointsMaxBoxPt = new import_core13.Vector3();
2047
+ var fromPointsNaiveCenterScratch = new import_core13.Vector3();
1518
2048
  function makeBoundingSphereFromPoints(positions, result = new BoundingSphere()) {
1519
2049
  if (!positions || positions.length === 0) {
1520
2050
  return result.fromCenterRadius([0, 0, 0], 0);
@@ -1610,17 +2140,17 @@ function makeBoundingSphereFromPoints(positions, result = new BoundingSphere())
1610
2140
  }
1611
2141
 
1612
2142
  // dist/culling/lib/algorithms/bounding-box-from-points.js
1613
- var import_core14 = require("@math.gl/core");
2143
+ var import_core15 = require("@math.gl/core");
1614
2144
 
1615
2145
  // dist/culling/lib/algorithms/compute-eigen-decomposition.js
1616
- var import_core13 = require("@math.gl/core");
1617
- var scratchMatrix = new import_core13.Matrix3();
1618
- var scratchUnitary = new import_core13.Matrix3();
1619
- var scratchDiagonal = new import_core13.Matrix3();
1620
- var jMatrix = new import_core13.Matrix3();
1621
- var jMatrixTranspose = new import_core13.Matrix3();
2146
+ var import_core14 = require("@math.gl/core");
2147
+ var scratchMatrix = new import_core14.Matrix3();
2148
+ var scratchUnitary = new import_core14.Matrix3();
2149
+ var scratchDiagonal = new import_core14.Matrix3();
2150
+ var jMatrix = new import_core14.Matrix3();
2151
+ var jMatrixTranspose = new import_core14.Matrix3();
1622
2152
  function computeEigenDecomposition(matrix, result = {}) {
1623
- const EIGEN_TOLERANCE = import_core13._MathUtils.EPSILON20;
2153
+ const EIGEN_TOLERANCE = import_core14._MathUtils.EPSILON20;
1624
2154
  const EIGEN_MAX_SWEEPS = 10;
1625
2155
  let count = 0;
1626
2156
  let sweep = 0;
@@ -1663,7 +2193,7 @@ function offDiagonalFrobeniusNorm(matrix) {
1663
2193
  return Math.sqrt(norm);
1664
2194
  }
1665
2195
  function shurDecomposition(matrix, result) {
1666
- const tolerance = import_core13._MathUtils.EPSILON15;
2196
+ const tolerance = import_core14._MathUtils.EPSILON15;
1667
2197
  let maxDiagonal = 0;
1668
2198
  let rotAxis = 1;
1669
2199
  for (let i = 0; i < 3; ++i) {
@@ -1691,7 +2221,7 @@ function shurDecomposition(matrix, result) {
1691
2221
  c = 1 / Math.sqrt(1 + t * t);
1692
2222
  s = t * c;
1693
2223
  }
1694
- import_core13.Matrix3.IDENTITY.to(result);
2224
+ import_core14.Matrix3.IDENTITY.to(result);
1695
2225
  result[scratchMatrix.getElementIndex(p, p)] = result[scratchMatrix.getElementIndex(q, q)] = c;
1696
2226
  result[scratchMatrix.getElementIndex(q, p)] = s;
1697
2227
  result[scratchMatrix.getElementIndex(p, q)] = -s;
@@ -1699,24 +2229,24 @@ function shurDecomposition(matrix, result) {
1699
2229
  }
1700
2230
 
1701
2231
  // dist/culling/lib/algorithms/bounding-box-from-points.js
1702
- var scratchVector23 = new import_core14.Vector3();
1703
- var scratchVector32 = new import_core14.Vector3();
1704
- var scratchVector4 = new import_core14.Vector3();
1705
- var scratchVector5 = new import_core14.Vector3();
1706
- var scratchVector6 = new import_core14.Vector3();
1707
- var scratchCovarianceResult = new import_core14.Matrix3();
2232
+ var scratchVector23 = new import_core15.Vector3();
2233
+ var scratchVector32 = new import_core15.Vector3();
2234
+ var scratchVector4 = new import_core15.Vector3();
2235
+ var scratchVector5 = new import_core15.Vector3();
2236
+ var scratchVector6 = new import_core15.Vector3();
2237
+ var scratchCovarianceResult = new import_core15.Matrix3();
1708
2238
  var scratchEigenResult = {
1709
- diagonal: new import_core14.Matrix3(),
1710
- unitary: new import_core14.Matrix3()
2239
+ diagonal: new import_core15.Matrix3(),
2240
+ unitary: new import_core15.Matrix3()
1711
2241
  };
1712
2242
  function makeOrientedBoundingBoxFromPoints(positions, result = new OrientedBoundingBox()) {
1713
2243
  if (!positions || positions.length === 0) {
1714
- result.halfAxes = new import_core14.Matrix3([0, 0, 0, 0, 0, 0, 0, 0, 0]);
1715
- result.center = new import_core14.Vector3();
2244
+ result.halfAxes = new import_core15.Matrix3([0, 0, 0, 0, 0, 0, 0, 0, 0]);
2245
+ result.center = new import_core15.Vector3();
1716
2246
  return result;
1717
2247
  }
1718
2248
  const length = positions.length;
1719
- const meanPoint = new import_core14.Vector3(0, 0, 0);
2249
+ const meanPoint = new import_core15.Vector3(0, 0, 0);
1720
2250
  for (const position of positions) {
1721
2251
  meanPoint.add(position);
1722
2252
  }
@@ -1778,7 +2308,7 @@ function makeOrientedBoundingBoxFromPoints(positions, result = new OrientedBound
1778
2308
  v3 = v3.multiplyByScalar(0.5 * (l3 + u3));
1779
2309
  result.center.copy(v1).add(v2).add(v3);
1780
2310
  const scale = scratchVector32.set(u1 - l1, u2 - l2, u3 - l3).multiplyByScalar(0.5);
1781
- const scaleMatrix = new import_core14.Matrix3([scale[0], 0, 0, 0, scale[1], 0, 0, 0, scale[2]]);
2311
+ const scaleMatrix = new import_core15.Matrix3([scale[0], 0, 0, 0, scale[1], 0, 0, 0, scale[2]]);
1782
2312
  result.halfAxes.multiplyRight(scaleMatrix);
1783
2313
  return result;
1784
2314
  }
@@ -1814,245 +2344,6 @@ function makeAxisAlignedBoundingBoxFromPoints(positions, result = new AxisAligne
1814
2344
  return result;
1815
2345
  }
1816
2346
 
1817
- // dist/culling/queries.js
1818
- function validateQueryPoint(point, dimension) {
1819
- if (point.length !== dimension)
1820
- throw new RangeError("Query dimension must match the index");
1821
- for (let i = 0; i < dimension; i++) {
1822
- if (!Number.isFinite(point[i]))
1823
- throw new RangeError("Coordinates must be finite");
1824
- }
1825
- }
1826
- function validateQueryDistance(distance) {
1827
- if (Number.isNaN(distance) || distance < 0)
1828
- throw new RangeError("Distance must be nonnegative");
1829
- }
1830
- function normalizeQueryDirection(direction, dimension) {
1831
- validateQueryPoint(direction, dimension);
1832
- const scale = Math.max(...Array.from(direction, Math.abs));
1833
- if (scale === 0)
1834
- throw new RangeError("Ray direction must be nonzero");
1835
- const scaled = Array.from(direction, (x) => x / scale);
1836
- const length = Math.hypot(...scaled);
1837
- return scaled.map((x) => x / length);
1838
- }
1839
- function intersectRayBounds(origin, direction, minimum, maximum, maxT = Infinity) {
1840
- const dimension = origin.length;
1841
- if (dimension !== 2 && dimension !== 3)
1842
- throw new RangeError("Bounds must be 2D or 3D");
1843
- validateQueryPoint(origin, dimension);
1844
- validateQueryPoint(direction, dimension);
1845
- validateQueryPoint(minimum, dimension);
1846
- validateQueryPoint(maximum, dimension);
1847
- validateQueryDistance(maxT);
1848
- let near = 0, far = maxT, nonzero = false;
1849
- for (let i = 0; i < dimension; i++) {
1850
- if (minimum[i] > maximum[i])
1851
- throw new RangeError("Bounds must be ordered");
1852
- nonzero || (nonzero = direction[i] !== 0);
1853
- }
1854
- if (!nonzero)
1855
- throw new RangeError("Ray direction must be nonzero");
1856
- for (let i = 0; i < dimension; i++) {
1857
- if (direction[i] === 0) {
1858
- if (origin[i] < minimum[i] || origin[i] > maximum[i])
1859
- return null;
1860
- continue;
1861
- }
1862
- let a = (minimum[i] - origin[i]) / direction[i];
1863
- let b = (maximum[i] - origin[i]) / direction[i];
1864
- if (a > b)
1865
- [a, b] = [b, a];
1866
- near = Math.max(near, a);
1867
- far = Math.min(far, b);
1868
- if (near > far)
1869
- return null;
1870
- }
1871
- return Number.isFinite(near) ? near : null;
1872
- }
1873
- function intersectRayTriangle(origin, direction, a, b, c, options = {}) {
1874
- for (const point of [origin, direction, a, b, c])
1875
- validateQueryPoint(point, 3);
1876
- if (direction[0] === 0 && direction[1] === 0 && direction[2] === 0) {
1877
- throw new RangeError("Ray direction must be nonzero");
1878
- }
1879
- const maxT = options.maxT ?? Infinity;
1880
- validateQueryDistance(maxT);
1881
- const e1 = [b[0] - a[0], b[1] - a[1], b[2] - a[2]];
1882
- const e2 = [c[0] - a[0], c[1] - a[1], c[2] - a[2]];
1883
- const p = cross(direction, e2);
1884
- const determinant = dot3(e1, p);
1885
- if (determinant === 0 || options.backfaceCulling && determinant < 0)
1886
- return null;
1887
- const offset = [origin[0] - a[0], origin[1] - a[1], origin[2] - a[2]];
1888
- const u = dot3(offset, p) / determinant;
1889
- if (u < 0 || u > 1)
1890
- return null;
1891
- const q = cross(offset, e1);
1892
- const v = dot3(direction, q) / determinant;
1893
- if (v < 0 || u + v > 1)
1894
- return null;
1895
- const t = dot3(e2, q) / determinant;
1896
- if (!Number.isFinite(t) || t < 0 || t > maxT)
1897
- return null;
1898
- return { t: Math.max(0, t), barycentric: [1 - u - v, u, v] };
1899
- }
1900
- function getClosestPointOnTriangle(point, a, b, c) {
1901
- for (const value of [point, a, b, c])
1902
- validateQueryPoint(value, 3);
1903
- const ab = [b[0] - a[0], b[1] - a[1], b[2] - a[2]];
1904
- const ac = [c[0] - a[0], c[1] - a[1], c[2] - a[2]];
1905
- const ap = [point[0] - a[0], point[1] - a[1], point[2] - a[2]];
1906
- const aa = dot3(ab, ab), bb = dot3(ac, ac), cc = dot3(ab, ac);
1907
- const denominator = aa * bb - cc * cc;
1908
- if (denominator > 0 && Number.isFinite(denominator)) {
1909
- const u = (bb * dot3(ap, ab) - cc * dot3(ap, ac)) / denominator;
1910
- const v = (aa * dot3(ap, ac) - cc * dot3(ap, ab)) / denominator;
1911
- if (u >= 0 && v >= 0 && u + v <= 1) {
1912
- return [
1913
- a[0] + u * ab[0] + v * ac[0],
1914
- a[1] + u * ab[1] + v * ac[1],
1915
- a[2] + u * ab[2] + v * ac[2]
1916
- ];
1917
- }
1918
- }
1919
- let best = [a[0], a[1], a[2]];
1920
- let distance = Infinity;
1921
- for (const [start, end] of [
1922
- [a, b],
1923
- [b, c],
1924
- [c, a]
1925
- ]) {
1926
- const edge = [end[0] - start[0], end[1] - start[1], end[2] - start[2]];
1927
- const offset = [point[0] - start[0], point[1] - start[1], point[2] - start[2]];
1928
- const squared = dot3(edge, edge);
1929
- const t = squared > 0 ? Math.max(0, Math.min(1, dot3(offset, edge) / squared)) : 0;
1930
- const candidate = [
1931
- start[0] + t * edge[0],
1932
- start[1] + t * edge[1],
1933
- start[2] + t * edge[2]
1934
- ];
1935
- const d = Math.hypot(point[0] - candidate[0], point[1] - candidate[1], point[2] - candidate[2]);
1936
- if (d < distance) {
1937
- distance = d;
1938
- best = candidate;
1939
- }
1940
- }
1941
- return best;
1942
- }
1943
- function getClosestPointsOnSegments(a0, a1, b0, b1) {
1944
- const frame = queryFrame([a0, a1, b0, b1]);
1945
- const pair = closestSegments(...frame.points);
1946
- const pointA = interpolatePoint(a0, a1, pair.fractionA);
1947
- const pointB = interpolatePoint(b0, b1, pair.fractionB);
1948
- return {
1949
- distance: finiteDistance(pointA, pointB),
1950
- pointA,
1951
- pointB,
1952
- fractionA: pair.fractionA,
1953
- fractionB: pair.fractionB
1954
- };
1955
- }
1956
- function getClosestPointsSegmentTriangle(start, end, a, b, c) {
1957
- const frame = queryFrame([start, end, a, b, c]);
1958
- const [s, e, va, vb, vc] = frame.points;
1959
- const direction = subtract(e, s);
1960
- if (direction.some((value) => value !== 0)) {
1961
- const hit = intersectRayTriangle(s, direction, va, vb, vc, { maxT: 1 });
1962
- if (hit) {
1963
- const point = interpolatePoint(start, end, hit.t);
1964
- return { distance: 0, segmentPoint: point, trianglePoint: [...point], segmentFraction: hit.t };
1965
- }
1966
- }
1967
- let best = { distance: Infinity, segmentFraction: 0, trianglePoint: va };
1968
- const consider = (point, trianglePoint2, segmentFraction) => {
1969
- const distance = Math.hypot(...subtract(point, trianglePoint2));
1970
- if (distance < best.distance || distance === best.distance && segmentFraction < best.segmentFraction)
1971
- best = { distance, segmentFraction, trianglePoint: trianglePoint2 };
1972
- };
1973
- consider(s, getClosestPointOnTriangle(s, va, vb, vc), 0);
1974
- consider(e, getClosestPointOnTriangle(e, va, vb, vc), 1);
1975
- for (const [v0, v1] of [
1976
- [va, vb],
1977
- [vb, vc],
1978
- [vc, va]
1979
- ]) {
1980
- const pair = closestSegments(s, e, v0, v1);
1981
- consider(interpolatePoint(s, e, pair.fractionA), interpolatePoint(v0, v1, pair.fractionB), pair.fractionA);
1982
- }
1983
- 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)));
1984
- if (!trianglePoint.every(Number.isFinite))
1985
- throw new RangeError("Closest-point result overflow");
1986
- const segmentPoint = interpolatePoint(start, end, best.segmentFraction);
1987
- return {
1988
- distance: finiteDistance(segmentPoint, trianglePoint),
1989
- segmentPoint,
1990
- trianglePoint,
1991
- segmentFraction: best.segmentFraction
1992
- };
1993
- }
1994
- function queryFrame(input) {
1995
- input.forEach((point) => validateQueryPoint(point, 3));
1996
- const offsets = input.map((point) => subtract(point, input[0]));
1997
- let scale = 0;
1998
- for (const offset of offsets)
1999
- for (const value of offset) {
2000
- if (!Number.isFinite(value))
2001
- throw new RangeError("Closest-point coordinate span overflow");
2002
- scale = Math.max(scale, Math.abs(value));
2003
- }
2004
- scale || (scale = 1);
2005
- return { points: offsets.map((point) => point.map((value) => value / scale)), scale };
2006
- }
2007
- function closestSegments(a0, a1, b0, b1) {
2008
- const da = subtract(a1, a0), db = subtract(b1, b0);
2009
- const lengthA = Math.hypot(...da), lengthB = Math.hypot(...db);
2010
- const ua = da.map((value) => lengthA ? value / lengthA : 0);
2011
- const ub = db.map((value) => lengthB ? value / lengthB : 0);
2012
- let best = { distance: Infinity, fractionA: 0, fractionB: 0 };
2013
- const consider = (fractionA, fractionB) => {
2014
- const distance = Math.hypot(...subtract(interpolatePoint(a0, a1, fractionA), interpolatePoint(b0, b1, fractionB)));
2015
- if (distance < best.distance || distance === best.distance && (fractionA < best.fractionA || fractionA === best.fractionA && fractionB < best.fractionB))
2016
- best = { distance, fractionA, fractionB };
2017
- };
2018
- for (const t of [0, 1]) {
2019
- consider(t, lengthB ? clampUnit(dot3(subtract(t ? a1 : a0, b0), ub) / lengthB) : 0);
2020
- consider(lengthA ? clampUnit(dot3(subtract(t ? b1 : b0, a0), ua) / lengthA) : 0, t);
2021
- }
2022
- const normal = cross(ua, ub);
2023
- const sine = Math.hypot(...normal);
2024
- if (sine > 0) {
2025
- const unit = normal.map((value) => value / sine);
2026
- const offset = subtract(b0, a0);
2027
- const fractionA = dot3(cross(offset, ub), unit) / sine / lengthA;
2028
- const fractionB = dot3(cross(offset, ua), unit) / sine / lengthB;
2029
- if (fractionA >= 0 && fractionA <= 1 && fractionB >= 0 && fractionB <= 1)
2030
- consider(fractionA, fractionB);
2031
- }
2032
- return best;
2033
- }
2034
- function subtract(a, b) {
2035
- return [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
2036
- }
2037
- function interpolatePoint(a, b, t) {
2038
- 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])));
2039
- }
2040
- function clampUnit(value) {
2041
- return Math.max(0, Math.min(1, value));
2042
- }
2043
- function finiteDistance(a, b) {
2044
- const distance = Math.hypot(...subtract(a, b));
2045
- if (!Number.isFinite(distance))
2046
- throw new RangeError("Closest-point distance overflow");
2047
- return distance;
2048
- }
2049
- function dot3(a, b) {
2050
- return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
2051
- }
2052
- function cross(a, b) {
2053
- 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]];
2054
- }
2055
-
2056
2347
  // dist/culling/oriented-box-2d.js
2057
2348
  function intersectOrientedBoxes2D(first, second, epsilon = 0) {
2058
2349
  validateBox(first);
@@ -2103,22 +2394,167 @@ function validateVector(vector) {
2103
2394
  }
2104
2395
  }
2105
2396
 
2397
+ // dist/culling/screen-ray.js
2398
+ var import_core16 = require("@math.gl/core");
2399
+ function unprojectScreenRay(inverseClipMatrix, viewport, pixel, depthRange = [-1, 1]) {
2400
+ const x = viewport.x ?? 0;
2401
+ const y = viewport.y ?? 0;
2402
+ if (inverseClipMatrix.length !== 16 || !Array.from(inverseClipMatrix).every(Number.isFinite) || ![x, y, viewport.width, viewport.height, ...pixel, ...depthRange].every(Number.isFinite) || viewport.width <= 0 || viewport.height <= 0 || pixel.length !== 2 || depthRange.length !== 2 || depthRange[0] === depthRange[1])
2403
+ return null;
2404
+ const matrix = new import_core16.Matrix4(Array.from(inverseClipMatrix));
2405
+ const determinant = matrix.determinant();
2406
+ if (!Number.isFinite(determinant) || determinant === 0)
2407
+ return null;
2408
+ const horizontal = 2 * (pixel[0] - x) / viewport.width - 1;
2409
+ const vertical = 1 - 2 * (pixel[1] - y) / viewport.height;
2410
+ const points = depthRange.map((depth) => matrix.transform([horizontal, vertical, depth, 1]));
2411
+ if (points.some((point2) => point2[3] === 0 || !point2.every(Number.isFinite)))
2412
+ return null;
2413
+ if (points[0][3] < 0 !== points[1][3] < 0)
2414
+ return null;
2415
+ const origin = [
2416
+ points[0][0] / points[0][3],
2417
+ points[0][1] / points[0][3],
2418
+ points[0][2] / points[0][3]
2419
+ ];
2420
+ const direction2 = [
2421
+ points[1][0] / points[1][3] - origin[0],
2422
+ points[1][1] / points[1][3] - origin[1],
2423
+ points[1][2] / points[1][3] - origin[2]
2424
+ ];
2425
+ const distance = Math.hypot(...direction2);
2426
+ return origin.every(Number.isFinite) && direction2.every(Number.isFinite) && Number.isFinite(distance) && distance > 0 ? { origin, direction: direction2 } : null;
2427
+ }
2428
+
2106
2429
  // dist/culling/lib/algorithms/oriented-bounding-box-quaternion.js
2107
- var import_core15 = require("@math.gl/core");
2430
+ var import_core17 = require("@math.gl/core");
2108
2431
  function getOrientedBoundingBoxQuaternion(box) {
2109
- const x = new import_core15.Vector3(box.halfAxes.getColumn(0)).normalize();
2110
- const y = new import_core15.Vector3(box.halfAxes.getColumn(1)).normalize();
2111
- const z = new import_core15.Vector3(box.halfAxes.getColumn(2)).normalize();
2112
- return new import_core15.Quaternion().fromMatrix3(new import_core15.Matrix3([...x, ...y, ...z]));
2432
+ const x = new import_core17.Vector3(box.halfAxes.getColumn(0)).normalize();
2433
+ const y = new import_core17.Vector3(box.halfAxes.getColumn(1)).normalize();
2434
+ const z = new import_core17.Vector3(box.halfAxes.getColumn(2)).normalize();
2435
+ return new import_core17.Quaternion().fromMatrix3(new import_core17.Matrix3([...x, ...y, ...z]));
2113
2436
  }
2114
2437
  function makeOrientedBoundingBoxFromQuaternion(center, halfSize, quaternion, result = new OrientedBoundingBox()) {
2115
- const halfAxes = new import_core15.Matrix3().fromQuaternion(quaternion);
2438
+ const halfAxes = new import_core17.Matrix3().fromQuaternion(quaternion);
2116
2439
  for (let column = 0; column < 3; column++) {
2117
2440
  for (let row = 0; row < 3; row++)
2118
2441
  halfAxes[column * 3 + row] *= halfSize[column];
2119
2442
  }
2120
- result.center = new import_core15.Vector3(center);
2443
+ result.center = new import_core17.Vector3(center);
2121
2444
  result.halfAxes = halfAxes;
2122
2445
  return result;
2123
2446
  }
2447
+
2448
+ // dist/culling/bounds.js
2449
+ function dimension(bounds) {
2450
+ const n = bounds[0].length;
2451
+ if (n !== 2 && n !== 3 || bounds[1].length !== n || [...Array.from(bounds[0]), ...Array.from(bounds[1])].some(Number.isNaN)) {
2452
+ throw new RangeError("Expected 2D or 3D bounds without NaN");
2453
+ }
2454
+ const empty = Array.from({ length: n }, (_, i) => bounds[0][i] > bounds[1][i]).some(Boolean);
2455
+ if (!empty && [...Array.from(bounds[0]), ...Array.from(bounds[1])].some((x) => !Number.isFinite(x))) {
2456
+ throw new RangeError("Nonempty bounds must be finite");
2457
+ }
2458
+ return n;
2459
+ }
2460
+ function pair(a, b) {
2461
+ const n = dimension(a);
2462
+ if (dimension(b) !== n)
2463
+ throw new RangeError("Bounds dimensions must match");
2464
+ return n;
2465
+ }
2466
+ function point(p, n) {
2467
+ if (p.length !== n || Array.from(p).some((x) => !Number.isFinite(x)))
2468
+ throw new RangeError("Expected a finite point of matching dimension");
2469
+ }
2470
+ function createEmptyBounds(dimension2) {
2471
+ if (dimension2 !== 2 && dimension2 !== 3)
2472
+ throw new RangeError("Expected dimension 2 or 3");
2473
+ return [new Array(dimension2).fill(Infinity), new Array(dimension2).fill(-Infinity)];
2474
+ }
2475
+ function isEmptyBounds(bounds) {
2476
+ return Array.from({ length: dimension(bounds) }, (_, i) => bounds[0][i] > bounds[1][i]).some(Boolean);
2477
+ }
2478
+ function boundsContainsPoint(bounds, p) {
2479
+ point(p, dimension(bounds));
2480
+ return !isEmptyBounds(bounds) && Array.from(p).every((x, i) => x >= bounds[0][i] && x <= bounds[1][i]);
2481
+ }
2482
+ function boundsContainsBounds(a, b) {
2483
+ const n = pair(a, b);
2484
+ return isEmptyBounds(b) || !isEmptyBounds(a) && Array.from({ length: n }, (_, i) => a[0][i] <= b[0][i] && a[1][i] >= b[1][i]).every(Boolean);
2485
+ }
2486
+ function boundsIntersect(a, b) {
2487
+ const n = pair(a, b);
2488
+ return !isEmptyBounds(a) && !isEmptyBounds(b) && Array.from({ length: n }, (_, i) => a[0][i] <= b[1][i] && b[0][i] <= a[1][i]).every(Boolean);
2489
+ }
2490
+ function store(values, out = createEmptyBounds(values[0].length)) {
2491
+ if (out[0].length !== values[0].length || out[1].length !== values[0].length) {
2492
+ throw new RangeError("Output bounds dimensions must match");
2493
+ }
2494
+ for (let j = 0; j < 2; j++)
2495
+ for (let i = 0; i < values[j].length; i++)
2496
+ out[j][i] = values[j][i];
2497
+ return out;
2498
+ }
2499
+ function unionBounds(a, b, out) {
2500
+ const n = pair(a, b);
2501
+ const values = createEmptyBounds(n);
2502
+ const ea = isEmptyBounds(a), eb = isEmptyBounds(b);
2503
+ for (let i = 0; i < n; i++) {
2504
+ values[0][i] = Math.min(ea ? Infinity : a[0][i], eb ? Infinity : b[0][i]);
2505
+ values[1][i] = Math.max(ea ? -Infinity : a[1][i], eb ? -Infinity : b[1][i]);
2506
+ }
2507
+ return store(values, out);
2508
+ }
2509
+ function intersectBounds(a, b, out) {
2510
+ const n = pair(a, b), values = createEmptyBounds(n);
2511
+ if (boundsIntersect(a, b))
2512
+ for (let i = 0; i < n; i++) {
2513
+ values[0][i] = Math.max(a[0][i], b[0][i]);
2514
+ values[1][i] = Math.min(a[1][i], b[1][i]);
2515
+ }
2516
+ return store(values, out);
2517
+ }
2518
+ function expandBoundsByPoint(bounds, p, out) {
2519
+ point(p, dimension(bounds));
2520
+ return unionBounds(bounds, [p, p], out);
2521
+ }
2522
+ function expandBounds(bounds, padding, out) {
2523
+ if (!Number.isFinite(padding))
2524
+ throw new RangeError("Padding must be finite");
2525
+ const n = dimension(bounds), values = createEmptyBounds(n);
2526
+ if (!isEmptyBounds(bounds))
2527
+ for (let i = 0; i < n; i++) {
2528
+ values[0][i] = bounds[0][i] - padding;
2529
+ values[1][i] = bounds[1][i] + padding;
2530
+ }
2531
+ return store(isEmptyBounds(values) ? createEmptyBounds(n) : values, out);
2532
+ }
2533
+ function clampPointToBounds(bounds, p, out = new Array(p.length)) {
2534
+ point(p, dimension(bounds));
2535
+ if (out.length < p.length)
2536
+ throw new RangeError("Result buffer is too short");
2537
+ if (isEmptyBounds(bounds))
2538
+ return null;
2539
+ const result = Array.from(p, (x, i) => Math.max(bounds[0][i], Math.min(bounds[1][i], x)));
2540
+ for (let i = 0; i < result.length; i++)
2541
+ out[i] = result[i];
2542
+ return out;
2543
+ }
2544
+ function radius(r) {
2545
+ if (!Number.isFinite(r) || r < 0)
2546
+ throw new RangeError("Radius must be finite and nonnegative");
2547
+ }
2548
+ function spheresIntersect(a, ar, b, br) {
2549
+ point(a, 3);
2550
+ point(b, 3);
2551
+ radius(ar);
2552
+ radius(br);
2553
+ return Math.hypot(a[0] - b[0], a[1] - b[1], a[2] - b[2]) <= ar + br;
2554
+ }
2555
+ function boundsIntersectSphere(bounds, center, r) {
2556
+ radius(r);
2557
+ const closest = clampPointToBounds(bounds, center);
2558
+ return closest !== null && Math.hypot(...Array.from(center, (x, i) => x - closest[i])) <= r;
2559
+ }
2124
2560
  //# sourceMappingURL=index.cjs.map