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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/README.md +58 -0
  2. package/THIRD-PARTY-NOTICES.md +1 -1
  3. package/dist/color/color-lut-types.d.ts +16 -0
  4. package/dist/color/color-lut-types.d.ts.map +1 -0
  5. package/dist/color/color-lut-types.js +5 -0
  6. package/dist/color/color-lut-types.js.map +1 -0
  7. package/dist/color/index.cjs +132 -0
  8. package/dist/color/index.cjs.map +6 -0
  9. package/dist/color/index.d.ts +4 -0
  10. package/dist/color/index.d.ts.map +1 -0
  11. package/dist/color/index.js +5 -0
  12. package/dist/color/index.js.map +1 -0
  13. package/dist/color/sample-lut.d.ts +13 -0
  14. package/dist/color/sample-lut.d.ts.map +1 -0
  15. package/dist/color/sample-lut.js +132 -0
  16. package/dist/color/sample-lut.js.map +1 -0
  17. package/dist/culling/bounds.d.ts +20 -0
  18. package/dist/culling/bounds.d.ts.map +1 -0
  19. package/dist/culling/bounds.js +121 -0
  20. package/dist/culling/bounds.js.map +1 -0
  21. package/dist/culling/frustum-planes.d.ts +5 -0
  22. package/dist/culling/frustum-planes.d.ts.map +1 -0
  23. package/dist/culling/frustum-planes.js +37 -0
  24. package/dist/culling/frustum-planes.js.map +1 -0
  25. package/dist/culling/geometric-queries.d.ts +34 -0
  26. package/dist/culling/geometric-queries.d.ts.map +1 -0
  27. package/dist/culling/geometric-queries.js +208 -0
  28. package/dist/culling/geometric-queries.js.map +1 -0
  29. package/dist/culling/index.cjs +917 -514
  30. package/dist/culling/index.cjs.map +3 -3
  31. package/dist/culling/index.d.ts +5 -1
  32. package/dist/culling/index.d.ts.map +1 -1
  33. package/dist/culling/index.js +3 -0
  34. package/dist/culling/index.js.map +1 -1
  35. package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +3 -3
  36. package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.d.ts.map +1 -1
  37. package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.js +25 -8
  38. package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -1
  39. package/dist/culling/lib/culling-volume.d.ts +3 -0
  40. package/dist/culling/lib/culling-volume.d.ts.map +1 -1
  41. package/dist/culling/lib/culling-volume.js +7 -0
  42. package/dist/culling/lib/culling-volume.js.map +1 -1
  43. package/dist/culling/lib/ray.d.ts +5 -0
  44. package/dist/culling/lib/ray.d.ts.map +1 -1
  45. package/dist/culling/lib/ray.js +21 -0
  46. package/dist/culling/lib/ray.js.map +1 -1
  47. package/dist/curves/adaptive-sampling.d.ts +16 -0
  48. package/dist/curves/adaptive-sampling.d.ts.map +1 -0
  49. package/dist/curves/adaptive-sampling.js +59 -0
  50. package/dist/curves/adaptive-sampling.js.map +1 -0
  51. package/dist/curves/index.d.ts +4 -0
  52. package/dist/curves/index.d.ts.map +1 -1
  53. package/dist/curves/index.js +2 -0
  54. package/dist/curves/index.js.map +1 -1
  55. package/dist/curves/parallel-transport.d.ts +12 -0
  56. package/dist/curves/parallel-transport.d.ts.map +1 -0
  57. package/dist/curves/parallel-transport.js +83 -0
  58. package/dist/curves/parallel-transport.js.map +1 -0
  59. package/dist/index.cjs +1225 -699
  60. package/dist/index.cjs.map +3 -3
  61. package/dist/index.d.ts +6 -1
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.js +3 -0
  64. package/dist/index.js.map +1 -1
  65. package/dist/lighting/index.cjs +175 -0
  66. package/dist/lighting/index.cjs.map +6 -0
  67. package/dist/lighting/index.d.ts +4 -0
  68. package/dist/lighting/index.d.ts.map +1 -0
  69. package/dist/lighting/index.js +5 -0
  70. package/dist/lighting/index.js.map +1 -0
  71. package/dist/lighting/lighting-types.d.ts +16 -0
  72. package/dist/lighting/lighting-types.d.ts.map +1 -0
  73. package/dist/lighting/lighting-types.js +5 -0
  74. package/dist/lighting/lighting-types.js.map +1 -0
  75. package/dist/lighting/photometry.d.ts +36 -0
  76. package/dist/lighting/photometry.d.ts.map +1 -0
  77. package/dist/lighting/photometry.js +181 -0
  78. package/dist/lighting/photometry.js.map +1 -0
  79. package/package.json +15 -3
  80. package/src/color/color-lut-types.ts +19 -0
  81. package/src/color/index.ts +6 -0
  82. package/src/color/sample-lut.ts +175 -0
  83. package/src/culling/bounds.ts +152 -0
  84. package/src/culling/frustum-planes.ts +41 -0
  85. package/src/culling/geometric-queries.ts +299 -0
  86. package/src/culling/index.ts +37 -1
  87. package/src/culling/lib/bounding-volumes/axis-aligned-bounding-box.ts +26 -8
  88. package/src/culling/lib/culling-volume.ts +9 -1
  89. package/src/culling/lib/ray.ts +21 -0
  90. package/src/curves/adaptive-sampling.ts +85 -0
  91. package/src/curves/index.ts +4 -0
  92. package/src/curves/parallel-transport.ts +104 -0
  93. package/src/index.ts +35 -0
  94. package/src/lighting/index.ts +10 -0
  95. package/src/lighting/lighting-types.ts +20 -0
  96. package/src/lighting/photometry.ts +264 -0
@@ -32,19 +32,45 @@ __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,
48
74
  unprojectScreenRay: () => unprojectScreenRay,
49
75
  validateQueryDistance: () => validateQueryDistance,
50
76
  validateQueryPoint: () => validateQueryPoint
@@ -88,15 +114,25 @@ var AxisAlignedBoundingBox = class _AxisAlignedBoundingBox {
88
114
  return this === right || Boolean(right) && this.minimum.equals(right.minimum) && this.maximum.equals(right.maximum);
89
115
  }
90
116
  /**
91
- * Applies a 4x4 affine transformation matrix to a bounding sphere.
92
- * @param transform The transformation matrix to apply to the bounding sphere.
93
- * @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.
94
120
  */
95
121
  transform(transform) {
96
- this.center.transformAsPoint(transform);
97
- this.halfDiagonal.transform(transform);
98
- this.minimum.transform(transform);
99
- 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);
100
136
  return this;
101
137
  }
102
138
  /**
@@ -116,12 +152,12 @@ var AxisAlignedBoundingBox = class _AxisAlignedBoundingBox {
116
152
  return "intersecting";
117
153
  }
118
154
  /** Computes the estimated distance from the closest point on a bounding box to a point. */
119
- distanceTo(point) {
120
- return Math.sqrt(this.distanceSquaredTo(point));
155
+ distanceTo(point2) {
156
+ return Math.sqrt(this.distanceSquaredTo(point2));
121
157
  }
122
158
  /** Computes the estimated distance squared from the closest point on a bounding box to a point. */
123
- distanceSquaredTo(point) {
124
- const offset = scratchVector.from(point).subtract(this.center);
159
+ distanceSquaredTo(point2) {
160
+ const offset = scratchVector.from(point2).subtract(this.center);
125
161
  const { halfDiagonal } = this;
126
162
  let distanceSquared = 0;
127
163
  let d;
@@ -148,15 +184,15 @@ var scratchVector2 = new import_core2.Vector3();
148
184
  var scratchVector22 = new import_core2.Vector3();
149
185
  var BoundingSphere = class _BoundingSphere {
150
186
  /** Creates a bounding sphere */
151
- constructor(center = [0, 0, 0], radius = 0) {
187
+ constructor(center = [0, 0, 0], radius2 = 0) {
152
188
  this.radius = -0;
153
189
  this.center = new import_core2.Vector3();
154
- this.fromCenterRadius(center, radius);
190
+ this.fromCenterRadius(center, radius2);
155
191
  }
156
192
  /** Sets the bounding sphere from `center` and `radius`. */
157
- fromCenterRadius(center, radius) {
193
+ fromCenterRadius(center, radius2) {
158
194
  this.center.from(center);
159
- this.radius = radius;
195
+ this.radius = radius2;
160
196
  return this;
161
197
  }
162
198
  /**
@@ -198,11 +234,11 @@ var BoundingSphere = class _BoundingSphere {
198
234
  return this;
199
235
  }
200
236
  /** Computes a bounding sphere by enlarging the provided sphere to contain the provided point. */
201
- expand(point) {
202
- const scratchPoint = scratchVector2.from(point);
203
- const radius = scratchPoint.subtract(this.center).magnitude();
204
- if (radius > this.radius) {
205
- 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;
206
242
  }
207
243
  return this;
208
244
  }
@@ -220,26 +256,26 @@ var BoundingSphere = class _BoundingSphere {
220
256
  return this;
221
257
  }
222
258
  /** Computes the estimated distance squared from the closest point on a bounding sphere to a point. */
223
- distanceSquaredTo(point) {
224
- const d = this.distanceTo(point);
259
+ distanceSquaredTo(point2) {
260
+ const d = this.distanceTo(point2);
225
261
  return d * d;
226
262
  }
227
263
  /** Computes the estimated distance from the closest point on a bounding sphere to a point. */
228
- distanceTo(point) {
229
- const scratchPoint = scratchVector2.from(point);
264
+ distanceTo(point2) {
265
+ const scratchPoint = scratchVector2.from(point2);
230
266
  const delta = scratchPoint.subtract(this.center);
231
267
  return Math.max(0, delta.len() - this.radius);
232
268
  }
233
269
  /** Determines which side of a plane a sphere is located. */
234
270
  intersectPlane(plane) {
235
271
  const center = this.center;
236
- const radius = this.radius;
272
+ const radius2 = this.radius;
237
273
  const normal = plane.normal;
238
274
  const distanceToPlane = normal.dot(center) + plane.distance;
239
- if (distanceToPlane < -radius) {
275
+ if (distanceToPlane < -radius2) {
240
276
  return "outside";
241
277
  }
242
- if (distanceToPlane < radius) {
278
+ if (distanceToPlane < radius2) {
243
279
  return "intersecting";
244
280
  }
245
281
  return "inside";
@@ -315,16 +351,16 @@ var OrientedBoundingBox = class _OrientedBoundingBox {
315
351
  return "intersecting";
316
352
  }
317
353
  /** Computes the estimated distance from the closest point on a bounding box to a point. */
318
- distanceTo(point) {
319
- return Math.sqrt(this.distanceSquaredTo(point));
354
+ distanceTo(point2) {
355
+ return Math.sqrt(this.distanceSquaredTo(point2));
320
356
  }
321
357
  /**
322
358
  * Computes the estimated distance squared from the closest point
323
359
  * on a bounding box to a point.
324
360
  * See Geometric Tools for Computer Graphics 10.4.2
325
361
  */
326
- distanceSquaredTo(point) {
327
- const offset = scratchOffset.from(point).subtract(this.center);
362
+ distanceSquaredTo(point2) {
363
+ const offset = scratchOffset.from(point2).subtract(this.center);
328
364
  const halfAxes = this.halfAxes;
329
365
  const u = halfAxes.getColumn(0, scratchVectorU);
330
366
  const v = halfAxes.getColumn(1, scratchVectorV);
@@ -366,7 +402,7 @@ var OrientedBoundingBox = class _OrientedBoundingBox {
366
402
  * on the bounding box from position in direction.
367
403
  */
368
404
  // eslint-disable-next-line max-statements
369
- computePlaneDistances(position, direction, result = [-0, -0]) {
405
+ computePlaneDistances(position, direction2, result = [-0, -0]) {
370
406
  let minDist = Number.POSITIVE_INFINITY;
371
407
  let maxDist = Number.NEGATIVE_INFINITY;
372
408
  const center = this.center;
@@ -376,42 +412,42 @@ var OrientedBoundingBox = class _OrientedBoundingBox {
376
412
  const w = halfAxes.getColumn(2, scratchVectorW);
377
413
  const corner = scratchCorner.copy(u).add(v).add(w).add(center);
378
414
  const toCenter = scratchToCenter.copy(corner).subtract(position);
379
- let mag = direction.dot(toCenter);
415
+ let mag = direction2.dot(toCenter);
380
416
  minDist = Math.min(mag, minDist);
381
417
  maxDist = Math.max(mag, maxDist);
382
418
  corner.copy(center).add(u).add(v).subtract(w);
383
419
  toCenter.copy(corner).subtract(position);
384
- mag = direction.dot(toCenter);
420
+ mag = direction2.dot(toCenter);
385
421
  minDist = Math.min(mag, minDist);
386
422
  maxDist = Math.max(mag, maxDist);
387
423
  corner.copy(center).add(u).subtract(v).add(w);
388
424
  toCenter.copy(corner).subtract(position);
389
- mag = direction.dot(toCenter);
425
+ mag = direction2.dot(toCenter);
390
426
  minDist = Math.min(mag, minDist);
391
427
  maxDist = Math.max(mag, maxDist);
392
428
  corner.copy(center).add(u).subtract(v).subtract(w);
393
429
  toCenter.copy(corner).subtract(position);
394
- mag = direction.dot(toCenter);
430
+ mag = direction2.dot(toCenter);
395
431
  minDist = Math.min(mag, minDist);
396
432
  maxDist = Math.max(mag, maxDist);
397
433
  center.copy(corner).subtract(u).add(v).add(w);
398
434
  toCenter.copy(corner).subtract(position);
399
- mag = direction.dot(toCenter);
435
+ mag = direction2.dot(toCenter);
400
436
  minDist = Math.min(mag, minDist);
401
437
  maxDist = Math.max(mag, maxDist);
402
438
  center.copy(corner).subtract(u).add(v).subtract(w);
403
439
  toCenter.copy(corner).subtract(position);
404
- mag = direction.dot(toCenter);
440
+ mag = direction2.dot(toCenter);
405
441
  minDist = Math.min(mag, minDist);
406
442
  maxDist = Math.max(mag, maxDist);
407
443
  center.copy(corner).subtract(u).subtract(v).add(w);
408
444
  toCenter.copy(corner).subtract(position);
409
- mag = direction.dot(toCenter);
445
+ mag = direction2.dot(toCenter);
410
446
  minDist = Math.min(mag, minDist);
411
447
  maxDist = Math.max(mag, maxDist);
412
448
  center.copy(corner).subtract(u).subtract(v).subtract(w);
413
449
  toCenter.copy(corner).subtract(position);
414
- mag = direction.dot(toCenter);
450
+ mag = direction2.dot(toCenter);
415
451
  minDist = Math.min(mag, minDist);
416
452
  maxDist = Math.max(mag, maxDist);
417
453
  result[0] = minDist;
@@ -440,6 +476,9 @@ var OrientedBoundingBox = class _OrientedBoundingBox {
440
476
  };
441
477
 
442
478
  // dist/culling/lib/culling-volume.js
479
+ var import_core7 = require("@math.gl/core");
480
+
481
+ // dist/culling/frustum-planes.js
443
482
  var import_core6 = require("@math.gl/core");
444
483
 
445
484
  // dist/culling/lib/plane.js
@@ -460,10 +499,10 @@ var Plane = class _Plane {
460
499
  return this;
461
500
  }
462
501
  /** Creates a plane from a normal and a point on the plane. */
463
- fromPointNormal(point, normal) {
464
- point = scratchPosition.from(point);
502
+ fromPointNormal(point2, normal) {
503
+ point2 = scratchPosition.from(point2);
465
504
  this.normal.from(normal).normalize();
466
- const distance = -this.normal.dot(point);
505
+ const distance = -this.normal.dot(point2);
467
506
  this.distance = distance;
468
507
  return this;
469
508
  }
@@ -485,17 +524,17 @@ var Plane = class _Plane {
485
524
  /** Computes the signed shortest distance of a point to a plane.
486
525
  * The sign of the distance determines which side of the plane the point is on.
487
526
  */
488
- getPointDistance(point) {
489
- return this.normal.dot(point) + this.distance;
527
+ getPointDistance(point2) {
528
+ return this.normal.dot(point2) + this.distance;
490
529
  }
491
530
  /** Transforms the plane by the given transformation matrix. */
492
531
  transform(matrix4) {
493
532
  const normal = scratchNormal2.copy(this.normal).transformAsVector(matrix4).normalize();
494
- const point = this.normal.scale(-this.distance).transform(matrix4);
495
- return this.fromPointNormal(point, normal);
533
+ const point2 = this.normal.scale(-this.distance).transform(matrix4);
534
+ return this.fromPointNormal(point2, normal);
496
535
  }
497
- projectPointOntoPlane(point, result = [0, 0, 0]) {
498
- const scratchPoint = scratchPosition.from(point);
536
+ projectPointOntoPlane(point2, result = [0, 0, 0]) {
537
+ const scratchPoint = scratchPosition.from(point2);
499
538
  const pointDistance = this.getPointDistance(scratchPoint);
500
539
  const scaledNormal = scratchNormal2.copy(this.normal).scale(pointDistance);
501
540
  return scratchPoint.subtract(scaledNormal).to(result);
@@ -509,9 +548,9 @@ var Plane = class _Plane {
509
548
  */
510
549
  intersectWithRay(ray, result = new import_core5.Vector3()) {
511
550
  const origin = ray.origin;
512
- const direction = ray.direction;
551
+ const direction2 = ray.direction;
513
552
  const normal = this.normal;
514
- const denominator = normal.dot(direction);
553
+ const denominator = normal.dot(direction2);
515
554
  if (Math.abs(denominator) < import_core5._MathUtils.EPSILON15) {
516
555
  return void 0;
517
556
  }
@@ -519,14 +558,45 @@ var Plane = class _Plane {
519
558
  if (t < 0) {
520
559
  return void 0;
521
560
  }
522
- return result.copy(direction).multiplyByScalar(t).add(origin);
561
+ return result.copy(direction2).multiplyByScalar(t).add(origin);
523
562
  }
524
563
  };
525
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
+
526
596
  // dist/culling/lib/culling-volume.js
527
- var faces = [new import_core6.Vector3([1, 0, 0]), new import_core6.Vector3([0, 1, 0]), new import_core6.Vector3([0, 0, 1])];
528
- var scratchPlaneCenter = new import_core6.Vector3();
529
- 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();
530
600
  var CullingVolume = class _CullingVolume {
531
601
  /**
532
602
  * Create a new `CullingVolume` bounded by an array of clipping planed
@@ -542,7 +612,7 @@ var CullingVolume = class _CullingVolume {
542
612
  fromBoundingSphere(boundingSphere) {
543
613
  this.planes.length = 2 * faces.length;
544
614
  const center = boundingSphere.center;
545
- const radius = boundingSphere.radius;
615
+ const radius2 = boundingSphere.radius;
546
616
  let planeIndex = 0;
547
617
  for (const faceNormal of faces) {
548
618
  let plane0 = this.planes[planeIndex];
@@ -553,15 +623,21 @@ var CullingVolume = class _CullingVolume {
553
623
  if (!plane1) {
554
624
  plane1 = this.planes[planeIndex + 1] = new Plane();
555
625
  }
556
- const plane0Center = scratchPlaneCenter.copy(faceNormal).scale(-radius).add(center);
626
+ const plane0Center = scratchPlaneCenter.copy(faceNormal).scale(-radius2).add(center);
557
627
  plane0.fromPointNormal(plane0Center, faceNormal);
558
- const plane1Center = scratchPlaneCenter.copy(faceNormal).scale(radius).add(center);
628
+ const plane1Center = scratchPlaneCenter.copy(faceNormal).scale(radius2).add(center);
559
629
  const negatedFaceNormal = scratchPlaneNormal.copy(faceNormal).negate();
560
630
  plane1.fromPointNormal(plane1Center, negatedFaceNormal);
561
631
  planeIndex += 2;
562
632
  }
563
633
  return this;
564
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
+ }
565
641
  /** Determines whether a bounding volume intersects the culling volume. */
566
642
  computeVisibility(boundingVolume) {
567
643
  let intersect = "inside";
@@ -587,7 +663,7 @@ var CullingVolume = class _CullingVolume {
587
663
  * and that plane check can be skipped.
588
664
  */
589
665
  computeVisibilityWithPlaneMask(boundingVolume, parentPlaneMask) {
590
- (0, import_core6.assert)(Number.isFinite(parentPlaneMask), "parentPlaneMask is required.");
666
+ (0, import_core7.assert)(Number.isFinite(parentPlaneMask), "parentPlaneMask is required.");
591
667
  if (parentPlaneMask === _CullingVolume.MASK_OUTSIDE || parentPlaneMask === _CullingVolume.MASK_INSIDE) {
592
668
  return parentPlaneMask;
593
669
  }
@@ -614,7 +690,441 @@ CullingVolume.MASK_INSIDE = 0;
614
690
  CullingVolume.MASK_INDETERMINATE = 2147483647;
615
691
 
616
692
  // dist/culling/lib/ray.js
617
- 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
618
1128
  var Ray = class {
619
1129
  /**
620
1130
  * Creates a new ray that extends infinitely from the provided origin in the provided direction.
@@ -622,25 +1132,44 @@ var Ray = class {
622
1132
  * @param [origin=Vector3] The origin of the ray.
623
1133
  * @param [direction=Vector3] The direction of the ray.
624
1134
  */
625
- constructor(origin, direction) {
1135
+ constructor(origin, direction2) {
626
1136
  if (origin)
627
1137
  origin = origin.clone();
628
1138
  else
629
- origin = new import_core7.Vector3();
630
- if (direction)
631
- direction = direction.clone().normalize();
1139
+ origin = new import_core8.Vector3();
1140
+ if (direction2)
1141
+ direction2 = direction2.clone().normalize();
632
1142
  else
633
- direction = new import_core7.Vector3();
1143
+ direction2 = new import_core8.Vector3();
634
1144
  this.origin = origin;
635
- 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;
636
1165
  }
637
1166
  };
638
1167
 
639
1168
  // dist/culling/lib/shapes/implicit-shape.js
640
- var import_core8 = require("@math.gl/core");
1169
+ var import_core9 = require("@math.gl/core");
641
1170
  var ImplicitShapeBase = class {
642
1171
  constructor(matrix) {
643
- this.matrix = new import_core8.Matrix4();
1172
+ this.matrix = new import_core9.Matrix4();
644
1173
  if (matrix)
645
1174
  this.matrix.copy(matrix);
646
1175
  validateAffineMatrix(this.matrix);
@@ -655,23 +1184,23 @@ var ImplicitShapeBase = class {
655
1184
  return true;
656
1185
  }
657
1186
  transform(transform) {
658
- const next = new import_core8.Matrix4().copy(transform);
1187
+ const next = new import_core9.Matrix4().copy(transform);
659
1188
  validateAffineMatrix(next);
660
1189
  this.matrix.multiplyLeft(next);
661
1190
  validateAffineMatrix(this.matrix);
662
1191
  this.inverseMatrix.copy(this.matrix).invert();
663
1192
  return this;
664
1193
  }
665
- containsPoint(point) {
666
- return this.containsLocalPoint(this.inverseMatrix.transformAsPoint(point));
1194
+ containsPoint(point2) {
1195
+ return this.containsLocalPoint(this.inverseMatrix.transformAsPoint(point2));
667
1196
  }
668
- distanceSquaredTo(point) {
669
- const distance = this.distanceTo(point);
1197
+ distanceSquaredTo(point2) {
1198
+ const distance = this.distanceTo(point2);
670
1199
  return distance * distance;
671
1200
  }
672
1201
  /** Exact for rigid/uniform transforms; conservative estimate for non-uniform scale or shear. */
673
- distanceTo(point) {
674
- const localPoint = this.inverseMatrix.transformAsPoint(point);
1202
+ distanceTo(point2) {
1203
+ const localPoint = this.inverseMatrix.transformAsPoint(point2);
675
1204
  const localDistance = this.distanceToLocalPoint(localPoint);
676
1205
  const scales = this.matrix.getScale();
677
1206
  return localDistance * Math.min(scales[0], scales[1], scales[2]);
@@ -693,20 +1222,20 @@ var ImplicitShapeBase = class {
693
1222
  const hit = this.intersectLocalRay(localOrigin, localDirection);
694
1223
  if (!hit || hit.distance < 0)
695
1224
  return void 0;
696
- 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);
697
1226
  const inverse = this.inverseMatrix;
698
- 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();
699
- 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 };
700
1229
  }
701
1230
  getAxisAlignedBoundingBox() {
702
- const minimum = new import_core8.Vector3();
703
- const maximum = new import_core8.Vector3();
1231
+ const minimum = new import_core9.Vector3();
1232
+ const maximum = new import_core9.Vector3();
704
1233
  for (let axis = 0; axis < 3; axis++) {
705
- const direction = [0, 0, 0];
706
- direction[axis] = 1;
707
- maximum[axis] = this.getSupportPoint(direction)[axis];
708
- direction[axis] = -1;
709
- 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];
710
1239
  }
711
1240
  return new AxisAlignedBoundingBox(minimum, maximum);
712
1241
  }
@@ -723,7 +1252,7 @@ var ImplicitShapeBase = class {
723
1252
  matrix[4] * worldDirection[0] + matrix[5] * worldDirection[1] + matrix[6] * worldDirection[2],
724
1253
  matrix[8] * worldDirection[0] + matrix[9] * worldDirection[1] + matrix[10] * worldDirection[2]
725
1254
  ];
726
- return new import_core8.Vector3(this.supportLocal(localDirection)).transform(this.matrix);
1255
+ return new import_core9.Vector3(this.supportLocal(localDirection)).transform(this.matrix);
727
1256
  }
728
1257
  };
729
1258
  function validateAffineMatrix(matrix) {
@@ -733,7 +1262,7 @@ function validateAffineMatrix(matrix) {
733
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) {
734
1263
  throw new Error("Shape matrix must be affine");
735
1264
  }
736
- 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)
737
1266
  throw new Error("Shape matrix must be invertible");
738
1267
  }
739
1268
  function solveQuadratic(a, b, c) {
@@ -752,19 +1281,19 @@ function closestDistanceToSegment2D(px, py, ax, ay, bx, by) {
752
1281
  const t = denominator ? Math.max(0, Math.min(1, ((px - ax) * dx + (py - ay) * dy) / denominator)) : 0;
753
1282
  return Math.hypot(px - (ax + t * dx), py - (ay + t * dy));
754
1283
  }
755
- function closestDistanceToCircleArc2D(px, py, centerY, radius, minimumNormalY, maximumNormalY) {
756
- if (radius === 0)
1284
+ function closestDistanceToCircleArc2D(px, py, centerY, radius2, minimumNormalY, maximumNormalY) {
1285
+ if (radius2 === 0)
757
1286
  return Math.hypot(px, py - centerY);
758
1287
  const dx = px;
759
1288
  const dy = py - centerY;
760
1289
  const length = Math.hypot(dx, dy);
761
1290
  const normalY = length ? dy / length : 0;
762
1291
  if (normalY >= minimumNormalY && normalY <= maximumNormalY) {
763
- return Math.abs(length - radius);
1292
+ return Math.abs(length - radius2);
764
1293
  }
765
- const minimumRadius = radius * Math.sqrt(Math.max(0, 1 - minimumNormalY ** 2));
766
- const maximumRadius = radius * Math.sqrt(Math.max(0, 1 - maximumNormalY ** 2));
767
- 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)));
768
1297
  }
769
1298
 
770
1299
  // dist/culling/lib/shapes/box-shape.js
@@ -784,28 +1313,28 @@ var BoxShape = class _BoxShape extends ImplicitShapeBase {
784
1313
  equals(shape) {
785
1314
  return shape instanceof _BoxShape && super.equals(shape) && this.size.every((value, i) => value === shape.size[i]);
786
1315
  }
787
- containsLocalPoint(point) {
788
- 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);
789
1318
  }
790
- distanceToLocalPoint(point) {
791
- 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])));
792
1321
  }
793
- supportLocal(direction) {
794
- 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]);
795
1324
  }
796
- intersectLocalRay(origin, direction) {
1325
+ intersectLocalRay(origin, direction2) {
797
1326
  let near = -Infinity;
798
1327
  let far = Infinity;
799
1328
  let nearAxis = 0;
800
1329
  let farAxis = 0;
801
1330
  for (let axis2 = 0; axis2 < 3; axis2++) {
802
- if (Math.abs(direction[axis2]) < 1e-15) {
1331
+ if (Math.abs(direction2[axis2]) < 1e-15) {
803
1332
  if (Math.abs(origin[axis2]) > this.halfSize[axis2])
804
1333
  return void 0;
805
1334
  continue;
806
1335
  }
807
- let t1 = (-this.halfSize[axis2] - origin[axis2]) / direction[axis2];
808
- 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];
809
1338
  if (t1 > t2)
810
1339
  [t1, t2] = [t2, t1];
811
1340
  if (t1 > near) {
@@ -823,7 +1352,7 @@ var BoxShape = class _BoxShape extends ImplicitShapeBase {
823
1352
  if (distance < 0 || !Number.isFinite(distance))
824
1353
  return void 0;
825
1354
  const axis = near >= 0 ? nearAxis : farAxis;
826
- const pointCoordinate = origin[axis] + distance * direction[axis];
1355
+ const pointCoordinate = origin[axis] + distance * direction2[axis];
827
1356
  const normal = [0, 0, 0];
828
1357
  normal[axis] = pointCoordinate < 0 ? -1 : 1;
829
1358
  return { distance, normal };
@@ -857,35 +1386,35 @@ var CapsuleShape = class _CapsuleShape extends ImplicitShapeBase {
857
1386
  equals(shape) {
858
1387
  return shape instanceof _CapsuleShape && super.equals(shape) && this.height === shape.height && this.radiusBottom === shape.radiusBottom && this.radiusTop === shape.radiusTop;
859
1388
  }
860
- containsLocalPoint(point) {
1389
+ containsLocalPoint(point2) {
861
1390
  const profile = this.getProfile();
862
- const radial = Math.hypot(point[0], point[2]);
1391
+ const radial = Math.hypot(point2[0], point2[2]);
863
1392
  if (profile.sphere)
864
- return Math.hypot(radial, point[1] - profile.sphere.center) <= profile.sphere.radius + EPSILON2;
865
- if (point[1] < profile.bottom.y)
866
- return Math.hypot(radial, point[1] + this.height / 2) <= this.radiusBottom + EPSILON2;
867
- if (point[1] > profile.top.y)
868
- return Math.hypot(radial, point[1] - this.height / 2) <= this.radiusTop + EPSILON2;
869
- 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);
870
1399
  return radial <= profile.bottom.radius + (profile.top.radius - profile.bottom.radius) * t + EPSILON2;
871
1400
  }
872
- distanceToLocalPoint(point) {
873
- if (this.containsLocalPoint(point))
1401
+ distanceToLocalPoint(point2) {
1402
+ if (this.containsLocalPoint(point2))
874
1403
  return 0;
875
1404
  const profile = this.getProfile();
876
- const radial = Math.hypot(point[0], point[2]);
1405
+ const radial = Math.hypot(point2[0], point2[2]);
877
1406
  if (profile.sphere)
878
- 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);
879
1408
  const delta = this.radiusTop - this.radiusBottom;
880
1409
  const sideNormalY = -delta / this.height;
881
- const bottomArc = closestDistanceToCircleArc2D(radial, point[1], -this.height / 2, this.radiusBottom, -1, sideNormalY);
882
- const topArc = closestDistanceToCircleArc2D(radial, point[1], this.height / 2, this.radiusTop, sideNormalY, 1);
883
- 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);
884
1413
  return Math.min(bottomArc, topArc, side);
885
1414
  }
886
- supportLocal(direction) {
887
- const length = Math.hypot(...direction);
888
- 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];
889
1418
  const bottom = [
890
1419
  unit[0] * this.radiusBottom,
891
1420
  -this.height / 2 + unit[1] * this.radiusBottom,
@@ -896,35 +1425,35 @@ var CapsuleShape = class _CapsuleShape extends ImplicitShapeBase {
896
1425
  this.height / 2 + unit[1] * this.radiusTop,
897
1426
  unit[2] * this.radiusTop
898
1427
  ];
899
- return dot(top, direction) >= dot(bottom, direction) ? top : bottom;
1428
+ return dot3(top, direction2) >= dot3(bottom, direction2) ? top : bottom;
900
1429
  }
901
- intersectLocalRay(origin, direction) {
1430
+ intersectLocalRay(origin, direction2) {
902
1431
  const profile = this.getProfile();
903
1432
  if (profile.sphere)
904
- return intersectSphere(origin, direction, profile.sphere.center, profile.sphere.radius);
1433
+ return intersectSphere(origin, direction2, profile.sphere.center, profile.sphere.radius);
905
1434
  const candidates = [];
906
1435
  const slope = (profile.top.radius - profile.bottom.radius) / (profile.top.y - profile.bottom.y);
907
1436
  const intercept = profile.bottom.radius - slope * profile.bottom.y;
908
1437
  const radialAtOrigin = intercept + slope * origin[1];
909
- const radialAlongRay = slope * direction[1];
910
- 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)) {
911
- 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];
912
1441
  if (distance >= 0 && y >= profile.bottom.y - EPSILON2 && y <= profile.top.y + EPSILON2) {
913
- const x = origin[0] + distance * direction[0];
914
- const z = origin[2] + distance * direction[2];
1442
+ const x = origin[0] + distance * direction2[0];
1443
+ const z = origin[2] + distance * direction2[2];
915
1444
  const radial = Math.hypot(x, z) || 1;
916
1445
  const normal = [x / radial, -slope, z / radial];
917
1446
  const length = Math.hypot(...normal);
918
1447
  candidates.push({ distance, normal: normal.map((value) => value / length) });
919
1448
  }
920
1449
  }
921
- for (const bottomHit of intersectSphereRoots(origin, direction, -this.height / 2, this.radiusBottom)) {
922
- 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];
923
1452
  if (y <= profile.bottom.y + EPSILON2)
924
1453
  candidates.push(bottomHit);
925
1454
  }
926
- for (const topHit of intersectSphereRoots(origin, direction, this.height / 2, this.radiusTop)) {
927
- 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];
928
1457
  if (y >= profile.top.y - EPSILON2)
929
1458
  candidates.push(topHit);
930
1459
  }
@@ -955,19 +1484,19 @@ var CapsuleShape = class _CapsuleShape extends ImplicitShapeBase {
955
1484
  };
956
1485
  }
957
1486
  };
958
- function intersectSphere(origin, direction, centerY, radius) {
959
- return intersectSphereRoots(origin, direction, centerY, radius)[0];
1487
+ function intersectSphere(origin, direction2, centerY, radius2) {
1488
+ return intersectSphereRoots(origin, direction2, centerY, radius2)[0];
960
1489
  }
961
- function intersectSphereRoots(origin, direction, centerY, radius) {
962
- if (radius === 0)
1490
+ function intersectSphereRoots(origin, direction2, centerY, radius2) {
1491
+ if (radius2 === 0)
963
1492
  return [];
964
1493
  const relative = [origin[0], origin[1] - centerY, origin[2]];
965
- 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) => ({
966
1495
  distance,
967
- normal: relative.map((value, i) => (value + distance * direction[i]) / radius)
1496
+ normal: relative.map((value, i) => (value + distance * direction2[i]) / radius2)
968
1497
  }));
969
1498
  }
970
- function dot(a, b) {
1499
+ function dot3(a, b) {
971
1500
  return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
972
1501
  }
973
1502
 
@@ -998,61 +1527,61 @@ var CylinderShape = class _CylinderShape extends ImplicitShapeBase {
998
1527
  equals(shape) {
999
1528
  return shape instanceof _CylinderShape && super.equals(shape) && this.height === shape.height && this.radiusBottom === shape.radiusBottom && this.radiusTop === shape.radiusTop;
1000
1529
  }
1001
- containsLocalPoint(point) {
1530
+ containsLocalPoint(point2) {
1002
1531
  const half = this.height / 2;
1003
- if (point[1] < -half - EPSILON3 || point[1] > half + EPSILON3)
1532
+ if (point2[1] < -half - EPSILON3 || point2[1] > half + EPSILON3)
1004
1533
  return false;
1005
- const t = (point[1] + half) / this.height;
1006
- const radius = this.radiusBottom + (this.radiusTop - this.radiusBottom) * t;
1007
- 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;
1008
1537
  }
1009
- distanceToLocalPoint(point) {
1010
- if (this.containsLocalPoint(point))
1538
+ distanceToLocalPoint(point2) {
1539
+ if (this.containsLocalPoint(point2))
1011
1540
  return 0;
1012
- const radial = Math.hypot(point[0], point[2]);
1541
+ const radial = Math.hypot(point2[0], point2[2]);
1013
1542
  const half = this.height / 2;
1014
- const side = closestDistanceToSegment2D(radial, point[1], this.radiusBottom, -half, this.radiusTop, half);
1015
- const bottom = closestDistanceToSegment2D(radial, point[1], 0, -half, this.radiusBottom, -half);
1016
- 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);
1017
1546
  return Math.min(side, bottom, top);
1018
1547
  }
1019
- supportLocal(direction) {
1020
- const radialLength = Math.hypot(direction[0], direction[2]);
1021
- const x = radialLength ? direction[0] / radialLength : 1;
1022
- 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;
1023
1552
  const half = this.height / 2;
1024
- const bottomValue = radialLength * this.radiusBottom - direction[1] * half;
1025
- 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;
1026
1555
  return topValue >= bottomValue ? [x * this.radiusTop, half, z * this.radiusTop] : [x * this.radiusBottom, -half, z * this.radiusBottom];
1027
1556
  }
1028
- intersectLocalRay(origin, direction) {
1557
+ intersectLocalRay(origin, direction2) {
1029
1558
  const half = this.height / 2;
1030
1559
  const slope = (this.radiusTop - this.radiusBottom) / this.height;
1031
1560
  const intercept = (this.radiusTop + this.radiusBottom) / 2;
1032
1561
  const radialAtOrigin = intercept + slope * origin[1];
1033
- const radialAlongRay = slope * direction[1];
1562
+ const radialAlongRay = slope * direction2[1];
1034
1563
  const candidates = [];
1035
- 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);
1036
1565
  for (const distance of roots) {
1037
- const y = origin[1] + distance * direction[1];
1566
+ const y = origin[1] + distance * direction2[1];
1038
1567
  if (distance >= 0 && y >= -half - EPSILON3 && y <= half + EPSILON3) {
1039
- const x = origin[0] + distance * direction[0];
1040
- const z = origin[2] + distance * direction[2];
1568
+ const x = origin[0] + distance * direction2[0];
1569
+ const z = origin[2] + distance * direction2[2];
1041
1570
  const radial = Math.hypot(x, z) || 1;
1042
1571
  const normal = [x / radial, -slope, z / radial];
1043
1572
  const length = Math.hypot(...normal);
1044
1573
  candidates.push({ distance, normal: normal.map((value) => value / length) });
1045
1574
  }
1046
1575
  }
1047
- if (Math.abs(direction[1]) > 1e-15) {
1048
- for (const [y, radius, normalY] of [
1576
+ if (Math.abs(direction2[1]) > 1e-15) {
1577
+ for (const [y, radius2, normalY] of [
1049
1578
  [-half, this.radiusBottom, -1],
1050
1579
  [half, this.radiusTop, 1]
1051
1580
  ]) {
1052
- const distance = (y - origin[1]) / direction[1];
1053
- const x = origin[0] + distance * direction[0];
1054
- const z = origin[2] + distance * direction[2];
1055
- 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)
1056
1585
  candidates.push({ distance, normal: [0, normalY, 0] });
1057
1586
  }
1058
1587
  }
@@ -1061,7 +1590,7 @@ var CylinderShape = class _CylinderShape extends ImplicitShapeBase {
1061
1590
  };
1062
1591
 
1063
1592
  // dist/culling/lib/shapes/plane-shape.js
1064
- var import_core9 = require("@math.gl/core");
1593
+ var import_core10 = require("@math.gl/core");
1065
1594
  var PlaneShape = class _PlaneShape extends ImplicitShapeBase {
1066
1595
  constructor(props = {}) {
1067
1596
  super(props.matrix);
@@ -1079,23 +1608,23 @@ var PlaneShape = class _PlaneShape extends ImplicitShapeBase {
1079
1608
  equals(shape) {
1080
1609
  return shape instanceof _PlaneShape && super.equals(shape) && this.sizeX === shape.sizeX && this.sizeZ === shape.sizeZ;
1081
1610
  }
1082
- containsLocalPoint(point) {
1083
- return point[1] <= 1e-12;
1611
+ containsLocalPoint(point2) {
1612
+ return point2[1] <= 1e-12;
1084
1613
  }
1085
- distanceToLocalPoint(point) {
1086
- return Math.max(0, point[1]);
1614
+ distanceToLocalPoint(point2) {
1615
+ return Math.max(0, point2[1]);
1087
1616
  }
1088
1617
  supportLocal() {
1089
1618
  throw new Error("An unbounded plane half-space has no finite support point");
1090
1619
  }
1091
- intersectLocalRay(origin, direction) {
1092
- if (Math.abs(direction[1]) < 1e-15)
1620
+ intersectLocalRay(origin, direction2) {
1621
+ if (Math.abs(direction2[1]) < 1e-15)
1093
1622
  return void 0;
1094
- const distance = -origin[1] / direction[1];
1623
+ const distance = -origin[1] / direction2[1];
1095
1624
  if (distance < 0)
1096
1625
  return void 0;
1097
- const x = origin[0] + distance * direction[0];
1098
- const z = origin[2] + distance * direction[2];
1626
+ const x = origin[0] + distance * direction2[0];
1627
+ const z = origin[2] + distance * direction2[2];
1099
1628
  if (this.sizeX !== void 0 && Math.abs(x) > this.sizeX / 2 + 1e-12)
1100
1629
  return void 0;
1101
1630
  if (this.sizeZ !== void 0 && Math.abs(z) > this.sizeZ / 2 + 1e-12)
@@ -1103,9 +1632,9 @@ var PlaneShape = class _PlaneShape extends ImplicitShapeBase {
1103
1632
  return { distance, normal: [0, 1, 0] };
1104
1633
  }
1105
1634
  intersectPlane(plane) {
1106
- 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);
1107
1636
  const inverse = this.inverseMatrix;
1108
- 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();
1109
1638
  const alignment = boundaryNormal.dot(plane.normal);
1110
1639
  if (Math.abs(Math.abs(alignment) - 1) > 1e-10)
1111
1640
  return "intersecting";
@@ -1140,36 +1669,36 @@ var SphereShape = class _SphereShape extends ImplicitShapeBase {
1140
1669
  equals(shape) {
1141
1670
  return shape instanceof _SphereShape && super.equals(shape) && this.radius === shape.radius;
1142
1671
  }
1143
- containsLocalPoint(point) {
1144
- return Math.hypot(...point) <= this.radius + EPSILON4;
1672
+ containsLocalPoint(point2) {
1673
+ return Math.hypot(...point2) <= this.radius + EPSILON4;
1145
1674
  }
1146
- distanceToLocalPoint(point) {
1147
- return Math.max(0, Math.hypot(...point) - this.radius);
1675
+ distanceToLocalPoint(point2) {
1676
+ return Math.max(0, Math.hypot(...point2) - this.radius);
1148
1677
  }
1149
- supportLocal(direction) {
1150
- const length = Math.hypot(...direction);
1151
- 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];
1152
1681
  }
1153
- intersectLocalRay(origin, direction) {
1154
- 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);
1155
1684
  const distance = roots.find((value) => value >= 0);
1156
1685
  if (distance === void 0)
1157
1686
  return void 0;
1158
- const point = origin.map((value, i) => value + distance * direction[i]);
1159
- 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) };
1160
1689
  }
1161
1690
  };
1162
- function dot2(a, b) {
1691
+ function dot4(a, b) {
1163
1692
  return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
1164
1693
  }
1165
1694
 
1166
1695
  // dist/culling/lib/perspective-off-center-frustum.js
1167
- var import_core10 = require("@math.gl/core");
1168
- var scratchPlaneUpVector = new import_core10.Vector3();
1169
- var scratchPlaneRightVector = new import_core10.Vector3();
1170
- var scratchPlaneNearCenter = new import_core10.Vector3();
1171
- var scratchPlaneFarCenter = new import_core10.Vector3();
1172
- 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();
1173
1702
  var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
1174
1703
  /**
1175
1704
  * The viewing frustum is defined by 6 planes.
@@ -1200,8 +1729,8 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
1200
1729
  new Plane(),
1201
1730
  new Plane()
1202
1731
  ]);
1203
- this._perspectiveMatrix = new import_core10.Matrix4();
1204
- this._infinitePerspective = new import_core10.Matrix4();
1732
+ this._perspectiveMatrix = new import_core11.Matrix4();
1733
+ this._infinitePerspective = new import_core11.Matrix4();
1205
1734
  const { near = 1, far = 5e8 } = options;
1206
1735
  this.left = options.left;
1207
1736
  this._left = void 0;
@@ -1271,15 +1800,15 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
1271
1800
  * const intersect = cullingVolume.computeVisibility(boundingVolume);
1272
1801
  */
1273
1802
  // eslint-disable-next-line complexity, max-statements
1274
- computeCullingVolume(position, direction, up) {
1275
- (0, import_core10.assert)(position, "position is required.");
1276
- (0, import_core10.assert)(direction, "direction is required.");
1277
- (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.");
1278
1807
  const planes = this._cullingVolume.planes;
1279
1808
  up = scratchPlaneUpVector.copy(up).normalize();
1280
- const right = scratchPlaneRightVector.copy(direction).cross(up).normalize();
1281
- const nearCenter = scratchPlaneNearCenter.copy(direction).multiplyByScalar(this.near).add(position);
1282
- 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);
1283
1812
  let normal = scratchPlaneNormal2;
1284
1813
  normal.copy(right).multiplyByScalar(this.left).add(nearCenter).subtract(position).cross(up);
1285
1814
  planes[0].fromPointNormal(position, normal);
@@ -1289,7 +1818,7 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
1289
1818
  planes[2].fromPointNormal(position, normal);
1290
1819
  normal.copy(up).multiplyByScalar(this.top).add(nearCenter).subtract(position).cross(right);
1291
1820
  planes[3].fromPointNormal(position, normal);
1292
- normal = new import_core10.Vector3().copy(direction);
1821
+ normal = new import_core11.Vector3().copy(direction2);
1293
1822
  planes[4].fromPointNormal(nearCenter, normal);
1294
1823
  normal.negate();
1295
1824
  planes[5].fromPointNormal(farCenter, normal);
@@ -1321,11 +1850,11 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
1321
1850
  */
1322
1851
  getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {
1323
1852
  this._update();
1324
- (0, import_core10.assert)(Number.isFinite(drawingBufferWidth) && Number.isFinite(drawingBufferHeight));
1325
- (0, import_core10.assert)(drawingBufferWidth > 0);
1326
- (0, import_core10.assert)(drawingBufferHeight > 0);
1327
- (0, import_core10.assert)(distance > 0);
1328
- (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);
1329
1858
  const inverseNear = 1 / this.near;
1330
1859
  let tanTheta = this.top * inverseNear;
1331
1860
  const pixelHeight = 2 * distance * tanTheta / drawingBufferHeight;
@@ -1337,17 +1866,17 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
1337
1866
  }
1338
1867
  // eslint-disable-next-line complexity, max-statements
1339
1868
  _update() {
1340
- (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));
1341
1870
  const { top, bottom, right, left, near, far } = this;
1342
1871
  if (top !== this._top || bottom !== this._bottom || left !== this._left || right !== this._right || near !== this._near || far !== this._far) {
1343
- (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.");
1344
1873
  this._left = left;
1345
1874
  this._right = right;
1346
1875
  this._top = top;
1347
1876
  this._bottom = bottom;
1348
1877
  this._near = near;
1349
1878
  this._far = far;
1350
- this._perspectiveMatrix = new import_core10.Matrix4().frustum({
1879
+ this._perspectiveMatrix = new import_core11.Matrix4().frustum({
1351
1880
  left,
1352
1881
  right,
1353
1882
  bottom,
@@ -1355,7 +1884,7 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
1355
1884
  near,
1356
1885
  far
1357
1886
  });
1358
- this._infinitePerspective = new import_core10.Matrix4().frustum({
1887
+ this._infinitePerspective = new import_core11.Matrix4().frustum({
1359
1888
  left,
1360
1889
  right,
1361
1890
  bottom,
@@ -1368,7 +1897,7 @@ var PerspectiveOffCenterFrustum = class _PerspectiveOffCenterFrustum {
1368
1897
  };
1369
1898
 
1370
1899
  // dist/culling/lib/perspective-frustum.js
1371
- var import_core11 = require("@math.gl/core");
1900
+ var import_core12 = require("@math.gl/core");
1372
1901
  var defined = (val) => val !== null && typeof val !== "undefined";
1373
1902
  var PerspectiveFrustum = class _PerspectiveFrustum {
1374
1903
  constructor(options = {}) {
@@ -1441,9 +1970,9 @@ var PerspectiveFrustum = class _PerspectiveFrustum {
1441
1970
  * var cullingVolume = this.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);
1442
1971
  * var intersect = cullingVolume.computeVisibility(boundingVolume);
1443
1972
  */
1444
- computeCullingVolume(position, direction, up) {
1973
+ computeCullingVolume(position, direction2, up) {
1445
1974
  this._update();
1446
- return this._offCenterFrustum.computeCullingVolume(position, direction, up);
1975
+ return this._offCenterFrustum.computeCullingVolume(position, direction2, up);
1447
1976
  }
1448
1977
  /**
1449
1978
  * Returns the pixel's width and height in meters.
@@ -1470,16 +1999,16 @@ var PerspectiveFrustum = class _PerspectiveFrustum {
1470
1999
  */
1471
2000
  getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {
1472
2001
  this._update();
1473
- 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());
1474
2003
  }
1475
2004
  // eslint-disable-next-line complexity, max-statements
1476
2005
  _update() {
1477
- (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));
1478
2007
  const f = this._offCenterFrustum;
1479
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) {
1480
- (0, import_core11.assert)(this.fov >= 0 && this.fov < Math.PI);
1481
- (0, import_core11.assert)(this.aspectRatio > 0);
1482
- (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);
1483
2012
  this._aspectRatio = this.aspectRatio;
1484
2013
  this._fov = this.fov;
1485
2014
  this._fovy = this.aspectRatio <= 1 ? this.fov : Math.atan(Math.tan(this.fov * 0.5) / this.aspectRatio) * 2;
@@ -1503,19 +2032,19 @@ var PerspectiveFrustum = class _PerspectiveFrustum {
1503
2032
  };
1504
2033
 
1505
2034
  // dist/culling/lib/algorithms/bounding-sphere-from-points.js
1506
- var import_core12 = require("@math.gl/core");
1507
- var fromPointsXMin = new import_core12.Vector3();
1508
- var fromPointsYMin = new import_core12.Vector3();
1509
- var fromPointsZMin = new import_core12.Vector3();
1510
- var fromPointsXMax = new import_core12.Vector3();
1511
- var fromPointsYMax = new import_core12.Vector3();
1512
- var fromPointsZMax = new import_core12.Vector3();
1513
- var fromPointsCurrentPos = new import_core12.Vector3();
1514
- var fromPointsScratch = new import_core12.Vector3();
1515
- var fromPointsRitterCenter = new import_core12.Vector3();
1516
- var fromPointsMinBoxPt = new import_core12.Vector3();
1517
- var fromPointsMaxBoxPt = new import_core12.Vector3();
1518
- 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();
1519
2048
  function makeBoundingSphereFromPoints(positions, result = new BoundingSphere()) {
1520
2049
  if (!positions || positions.length === 0) {
1521
2050
  return result.fromCenterRadius([0, 0, 0], 0);
@@ -1611,17 +2140,17 @@ function makeBoundingSphereFromPoints(positions, result = new BoundingSphere())
1611
2140
  }
1612
2141
 
1613
2142
  // dist/culling/lib/algorithms/bounding-box-from-points.js
1614
- var import_core14 = require("@math.gl/core");
2143
+ var import_core15 = require("@math.gl/core");
1615
2144
 
1616
2145
  // dist/culling/lib/algorithms/compute-eigen-decomposition.js
1617
- var import_core13 = require("@math.gl/core");
1618
- var scratchMatrix = new import_core13.Matrix3();
1619
- var scratchUnitary = new import_core13.Matrix3();
1620
- var scratchDiagonal = new import_core13.Matrix3();
1621
- var jMatrix = new import_core13.Matrix3();
1622
- 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();
1623
2152
  function computeEigenDecomposition(matrix, result = {}) {
1624
- const EIGEN_TOLERANCE = import_core13._MathUtils.EPSILON20;
2153
+ const EIGEN_TOLERANCE = import_core14._MathUtils.EPSILON20;
1625
2154
  const EIGEN_MAX_SWEEPS = 10;
1626
2155
  let count = 0;
1627
2156
  let sweep = 0;
@@ -1664,7 +2193,7 @@ function offDiagonalFrobeniusNorm(matrix) {
1664
2193
  return Math.sqrt(norm);
1665
2194
  }
1666
2195
  function shurDecomposition(matrix, result) {
1667
- const tolerance = import_core13._MathUtils.EPSILON15;
2196
+ const tolerance = import_core14._MathUtils.EPSILON15;
1668
2197
  let maxDiagonal = 0;
1669
2198
  let rotAxis = 1;
1670
2199
  for (let i = 0; i < 3; ++i) {
@@ -1692,7 +2221,7 @@ function shurDecomposition(matrix, result) {
1692
2221
  c = 1 / Math.sqrt(1 + t * t);
1693
2222
  s = t * c;
1694
2223
  }
1695
- import_core13.Matrix3.IDENTITY.to(result);
2224
+ import_core14.Matrix3.IDENTITY.to(result);
1696
2225
  result[scratchMatrix.getElementIndex(p, p)] = result[scratchMatrix.getElementIndex(q, q)] = c;
1697
2226
  result[scratchMatrix.getElementIndex(q, p)] = s;
1698
2227
  result[scratchMatrix.getElementIndex(p, q)] = -s;
@@ -1700,24 +2229,24 @@ function shurDecomposition(matrix, result) {
1700
2229
  }
1701
2230
 
1702
2231
  // dist/culling/lib/algorithms/bounding-box-from-points.js
1703
- var scratchVector23 = new import_core14.Vector3();
1704
- var scratchVector32 = new import_core14.Vector3();
1705
- var scratchVector4 = new import_core14.Vector3();
1706
- var scratchVector5 = new import_core14.Vector3();
1707
- var scratchVector6 = new import_core14.Vector3();
1708
- 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();
1709
2238
  var scratchEigenResult = {
1710
- diagonal: new import_core14.Matrix3(),
1711
- unitary: new import_core14.Matrix3()
2239
+ diagonal: new import_core15.Matrix3(),
2240
+ unitary: new import_core15.Matrix3()
1712
2241
  };
1713
2242
  function makeOrientedBoundingBoxFromPoints(positions, result = new OrientedBoundingBox()) {
1714
2243
  if (!positions || positions.length === 0) {
1715
- result.halfAxes = new import_core14.Matrix3([0, 0, 0, 0, 0, 0, 0, 0, 0]);
1716
- 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();
1717
2246
  return result;
1718
2247
  }
1719
2248
  const length = positions.length;
1720
- const meanPoint = new import_core14.Vector3(0, 0, 0);
2249
+ const meanPoint = new import_core15.Vector3(0, 0, 0);
1721
2250
  for (const position of positions) {
1722
2251
  meanPoint.add(position);
1723
2252
  }
@@ -1779,7 +2308,7 @@ function makeOrientedBoundingBoxFromPoints(positions, result = new OrientedBound
1779
2308
  v3 = v3.multiplyByScalar(0.5 * (l3 + u3));
1780
2309
  result.center.copy(v1).add(v2).add(v3);
1781
2310
  const scale = scratchVector32.set(u1 - l1, u2 - l2, u3 - l3).multiplyByScalar(0.5);
1782
- 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]]);
1783
2312
  result.halfAxes.multiplyRight(scaleMatrix);
1784
2313
  return result;
1785
2314
  }
@@ -1815,245 +2344,6 @@ function makeAxisAlignedBoundingBoxFromPoints(positions, result = new AxisAligne
1815
2344
  return result;
1816
2345
  }
1817
2346
 
1818
- // dist/culling/queries.js
1819
- function validateQueryPoint(point, dimension) {
1820
- if (point.length !== dimension)
1821
- throw new RangeError("Query dimension must match the index");
1822
- for (let i = 0; i < dimension; i++) {
1823
- if (!Number.isFinite(point[i]))
1824
- throw new RangeError("Coordinates must be finite");
1825
- }
1826
- }
1827
- function validateQueryDistance(distance) {
1828
- if (Number.isNaN(distance) || distance < 0)
1829
- throw new RangeError("Distance must be nonnegative");
1830
- }
1831
- function normalizeQueryDirection(direction, dimension) {
1832
- validateQueryPoint(direction, dimension);
1833
- const scale = Math.max(...Array.from(direction, Math.abs));
1834
- if (scale === 0)
1835
- throw new RangeError("Ray direction must be nonzero");
1836
- const scaled = Array.from(direction, (x) => x / scale);
1837
- const length = Math.hypot(...scaled);
1838
- return scaled.map((x) => x / length);
1839
- }
1840
- function intersectRayBounds(origin, direction, minimum, maximum, maxT = Infinity) {
1841
- const dimension = origin.length;
1842
- if (dimension !== 2 && dimension !== 3)
1843
- throw new RangeError("Bounds must be 2D or 3D");
1844
- validateQueryPoint(origin, dimension);
1845
- validateQueryPoint(direction, dimension);
1846
- validateQueryPoint(minimum, dimension);
1847
- validateQueryPoint(maximum, dimension);
1848
- validateQueryDistance(maxT);
1849
- let near = 0, far = maxT, nonzero = false;
1850
- for (let i = 0; i < dimension; i++) {
1851
- if (minimum[i] > maximum[i])
1852
- throw new RangeError("Bounds must be ordered");
1853
- nonzero || (nonzero = direction[i] !== 0);
1854
- }
1855
- if (!nonzero)
1856
- throw new RangeError("Ray direction must be nonzero");
1857
- for (let i = 0; i < dimension; i++) {
1858
- if (direction[i] === 0) {
1859
- if (origin[i] < minimum[i] || origin[i] > maximum[i])
1860
- return null;
1861
- continue;
1862
- }
1863
- let a = (minimum[i] - origin[i]) / direction[i];
1864
- let b = (maximum[i] - origin[i]) / direction[i];
1865
- if (a > b)
1866
- [a, b] = [b, a];
1867
- near = Math.max(near, a);
1868
- far = Math.min(far, b);
1869
- if (near > far)
1870
- return null;
1871
- }
1872
- return Number.isFinite(near) ? near : null;
1873
- }
1874
- function intersectRayTriangle(origin, direction, a, b, c, options = {}) {
1875
- for (const point of [origin, direction, a, b, c])
1876
- validateQueryPoint(point, 3);
1877
- if (direction[0] === 0 && direction[1] === 0 && direction[2] === 0) {
1878
- throw new RangeError("Ray direction must be nonzero");
1879
- }
1880
- const maxT = options.maxT ?? Infinity;
1881
- validateQueryDistance(maxT);
1882
- const e1 = [b[0] - a[0], b[1] - a[1], b[2] - a[2]];
1883
- const e2 = [c[0] - a[0], c[1] - a[1], c[2] - a[2]];
1884
- const p = cross(direction, e2);
1885
- const determinant = dot3(e1, p);
1886
- if (determinant === 0 || options.backfaceCulling && determinant < 0)
1887
- return null;
1888
- const offset = [origin[0] - a[0], origin[1] - a[1], origin[2] - a[2]];
1889
- const u = dot3(offset, p) / determinant;
1890
- if (u < 0 || u > 1)
1891
- return null;
1892
- const q = cross(offset, e1);
1893
- const v = dot3(direction, q) / determinant;
1894
- if (v < 0 || u + v > 1)
1895
- return null;
1896
- const t = dot3(e2, q) / determinant;
1897
- if (!Number.isFinite(t) || t < 0 || t > maxT)
1898
- return null;
1899
- return { t: Math.max(0, t), barycentric: [1 - u - v, u, v] };
1900
- }
1901
- function getClosestPointOnTriangle(point, a, b, c) {
1902
- for (const value of [point, a, b, c])
1903
- validateQueryPoint(value, 3);
1904
- const ab = [b[0] - a[0], b[1] - a[1], b[2] - a[2]];
1905
- const ac = [c[0] - a[0], c[1] - a[1], c[2] - a[2]];
1906
- const ap = [point[0] - a[0], point[1] - a[1], point[2] - a[2]];
1907
- const aa = dot3(ab, ab), bb = dot3(ac, ac), cc = dot3(ab, ac);
1908
- const denominator = aa * bb - cc * cc;
1909
- if (denominator > 0 && Number.isFinite(denominator)) {
1910
- const u = (bb * dot3(ap, ab) - cc * dot3(ap, ac)) / denominator;
1911
- const v = (aa * dot3(ap, ac) - cc * dot3(ap, ab)) / denominator;
1912
- if (u >= 0 && v >= 0 && u + v <= 1) {
1913
- return [
1914
- a[0] + u * ab[0] + v * ac[0],
1915
- a[1] + u * ab[1] + v * ac[1],
1916
- a[2] + u * ab[2] + v * ac[2]
1917
- ];
1918
- }
1919
- }
1920
- let best = [a[0], a[1], a[2]];
1921
- let distance = Infinity;
1922
- for (const [start, end] of [
1923
- [a, b],
1924
- [b, c],
1925
- [c, a]
1926
- ]) {
1927
- const edge = [end[0] - start[0], end[1] - start[1], end[2] - start[2]];
1928
- const offset = [point[0] - start[0], point[1] - start[1], point[2] - start[2]];
1929
- const squared = dot3(edge, edge);
1930
- const t = squared > 0 ? Math.max(0, Math.min(1, dot3(offset, edge) / squared)) : 0;
1931
- const candidate = [
1932
- start[0] + t * edge[0],
1933
- start[1] + t * edge[1],
1934
- start[2] + t * edge[2]
1935
- ];
1936
- const d = Math.hypot(point[0] - candidate[0], point[1] - candidate[1], point[2] - candidate[2]);
1937
- if (d < distance) {
1938
- distance = d;
1939
- best = candidate;
1940
- }
1941
- }
1942
- return best;
1943
- }
1944
- function getClosestPointsOnSegments(a0, a1, b0, b1) {
1945
- const frame = queryFrame([a0, a1, b0, b1]);
1946
- const pair = closestSegments(...frame.points);
1947
- const pointA = interpolatePoint(a0, a1, pair.fractionA);
1948
- const pointB = interpolatePoint(b0, b1, pair.fractionB);
1949
- return {
1950
- distance: finiteDistance(pointA, pointB),
1951
- pointA,
1952
- pointB,
1953
- fractionA: pair.fractionA,
1954
- fractionB: pair.fractionB
1955
- };
1956
- }
1957
- function getClosestPointsSegmentTriangle(start, end, a, b, c) {
1958
- const frame = queryFrame([start, end, a, b, c]);
1959
- const [s, e, va, vb, vc] = frame.points;
1960
- const direction = subtract(e, s);
1961
- if (direction.some((value) => value !== 0)) {
1962
- const hit = intersectRayTriangle(s, direction, va, vb, vc, { maxT: 1 });
1963
- if (hit) {
1964
- const point = interpolatePoint(start, end, hit.t);
1965
- return { distance: 0, segmentPoint: point, trianglePoint: [...point], segmentFraction: hit.t };
1966
- }
1967
- }
1968
- let best = { distance: Infinity, segmentFraction: 0, trianglePoint: va };
1969
- const consider = (point, trianglePoint2, segmentFraction) => {
1970
- const distance = Math.hypot(...subtract(point, trianglePoint2));
1971
- if (distance < best.distance || distance === best.distance && segmentFraction < best.segmentFraction)
1972
- best = { distance, segmentFraction, trianglePoint: trianglePoint2 };
1973
- };
1974
- consider(s, getClosestPointOnTriangle(s, va, vb, vc), 0);
1975
- consider(e, getClosestPointOnTriangle(e, va, vb, vc), 1);
1976
- for (const [v0, v1] of [
1977
- [va, vb],
1978
- [vb, vc],
1979
- [vc, va]
1980
- ]) {
1981
- const pair = closestSegments(s, e, v0, v1);
1982
- consider(interpolatePoint(s, e, pair.fractionA), interpolatePoint(v0, v1, pair.fractionB), pair.fractionA);
1983
- }
1984
- 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)));
1985
- if (!trianglePoint.every(Number.isFinite))
1986
- throw new RangeError("Closest-point result overflow");
1987
- const segmentPoint = interpolatePoint(start, end, best.segmentFraction);
1988
- return {
1989
- distance: finiteDistance(segmentPoint, trianglePoint),
1990
- segmentPoint,
1991
- trianglePoint,
1992
- segmentFraction: best.segmentFraction
1993
- };
1994
- }
1995
- function queryFrame(input) {
1996
- input.forEach((point) => validateQueryPoint(point, 3));
1997
- const offsets = input.map((point) => subtract(point, input[0]));
1998
- let scale = 0;
1999
- for (const offset of offsets)
2000
- for (const value of offset) {
2001
- if (!Number.isFinite(value))
2002
- throw new RangeError("Closest-point coordinate span overflow");
2003
- scale = Math.max(scale, Math.abs(value));
2004
- }
2005
- scale || (scale = 1);
2006
- return { points: offsets.map((point) => point.map((value) => value / scale)), scale };
2007
- }
2008
- function closestSegments(a0, a1, b0, b1) {
2009
- const da = subtract(a1, a0), db = subtract(b1, b0);
2010
- const lengthA = Math.hypot(...da), lengthB = Math.hypot(...db);
2011
- const ua = da.map((value) => lengthA ? value / lengthA : 0);
2012
- const ub = db.map((value) => lengthB ? value / lengthB : 0);
2013
- let best = { distance: Infinity, fractionA: 0, fractionB: 0 };
2014
- const consider = (fractionA, fractionB) => {
2015
- const distance = Math.hypot(...subtract(interpolatePoint(a0, a1, fractionA), interpolatePoint(b0, b1, fractionB)));
2016
- if (distance < best.distance || distance === best.distance && (fractionA < best.fractionA || fractionA === best.fractionA && fractionB < best.fractionB))
2017
- best = { distance, fractionA, fractionB };
2018
- };
2019
- for (const t of [0, 1]) {
2020
- consider(t, lengthB ? clampUnit(dot3(subtract(t ? a1 : a0, b0), ub) / lengthB) : 0);
2021
- consider(lengthA ? clampUnit(dot3(subtract(t ? b1 : b0, a0), ua) / lengthA) : 0, t);
2022
- }
2023
- const normal = cross(ua, ub);
2024
- const sine = Math.hypot(...normal);
2025
- if (sine > 0) {
2026
- const unit = normal.map((value) => value / sine);
2027
- const offset = subtract(b0, a0);
2028
- const fractionA = dot3(cross(offset, ub), unit) / sine / lengthA;
2029
- const fractionB = dot3(cross(offset, ua), unit) / sine / lengthB;
2030
- if (fractionA >= 0 && fractionA <= 1 && fractionB >= 0 && fractionB <= 1)
2031
- consider(fractionA, fractionB);
2032
- }
2033
- return best;
2034
- }
2035
- function subtract(a, b) {
2036
- return [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
2037
- }
2038
- function interpolatePoint(a, b, t) {
2039
- 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])));
2040
- }
2041
- function clampUnit(value) {
2042
- return Math.max(0, Math.min(1, value));
2043
- }
2044
- function finiteDistance(a, b) {
2045
- const distance = Math.hypot(...subtract(a, b));
2046
- if (!Number.isFinite(distance))
2047
- throw new RangeError("Closest-point distance overflow");
2048
- return distance;
2049
- }
2050
- function dot3(a, b) {
2051
- return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
2052
- }
2053
- function cross(a, b) {
2054
- 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]];
2055
- }
2056
-
2057
2347
  // dist/culling/oriented-box-2d.js
2058
2348
  function intersectOrientedBoxes2D(first, second, epsilon = 0) {
2059
2349
  validateBox(first);
@@ -2105,20 +2395,20 @@ function validateVector(vector) {
2105
2395
  }
2106
2396
 
2107
2397
  // dist/culling/screen-ray.js
2108
- var import_core15 = require("@math.gl/core");
2398
+ var import_core16 = require("@math.gl/core");
2109
2399
  function unprojectScreenRay(inverseClipMatrix, viewport, pixel, depthRange = [-1, 1]) {
2110
2400
  const x = viewport.x ?? 0;
2111
2401
  const y = viewport.y ?? 0;
2112
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])
2113
2403
  return null;
2114
- const matrix = new import_core15.Matrix4(Array.from(inverseClipMatrix));
2404
+ const matrix = new import_core16.Matrix4(Array.from(inverseClipMatrix));
2115
2405
  const determinant = matrix.determinant();
2116
2406
  if (!Number.isFinite(determinant) || determinant === 0)
2117
2407
  return null;
2118
2408
  const horizontal = 2 * (pixel[0] - x) / viewport.width - 1;
2119
2409
  const vertical = 1 - 2 * (pixel[1] - y) / viewport.height;
2120
2410
  const points = depthRange.map((depth) => matrix.transform([horizontal, vertical, depth, 1]));
2121
- if (points.some((point) => point[3] === 0 || !point.every(Number.isFinite)))
2411
+ if (points.some((point2) => point2[3] === 0 || !point2.every(Number.isFinite)))
2122
2412
  return null;
2123
2413
  if (points[0][3] < 0 !== points[1][3] < 0)
2124
2414
  return null;
@@ -2127,31 +2417,144 @@ function unprojectScreenRay(inverseClipMatrix, viewport, pixel, depthRange = [-1
2127
2417
  points[0][1] / points[0][3],
2128
2418
  points[0][2] / points[0][3]
2129
2419
  ];
2130
- const direction = [
2420
+ const direction2 = [
2131
2421
  points[1][0] / points[1][3] - origin[0],
2132
2422
  points[1][1] / points[1][3] - origin[1],
2133
2423
  points[1][2] / points[1][3] - origin[2]
2134
2424
  ];
2135
- const distance = Math.hypot(...direction);
2136
- return origin.every(Number.isFinite) && direction.every(Number.isFinite) && Number.isFinite(distance) && distance > 0 ? { origin, direction } : null;
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;
2137
2427
  }
2138
2428
 
2139
2429
  // dist/culling/lib/algorithms/oriented-bounding-box-quaternion.js
2140
- var import_core16 = require("@math.gl/core");
2430
+ var import_core17 = require("@math.gl/core");
2141
2431
  function getOrientedBoundingBoxQuaternion(box) {
2142
- const x = new import_core16.Vector3(box.halfAxes.getColumn(0)).normalize();
2143
- const y = new import_core16.Vector3(box.halfAxes.getColumn(1)).normalize();
2144
- const z = new import_core16.Vector3(box.halfAxes.getColumn(2)).normalize();
2145
- return new import_core16.Quaternion().fromMatrix3(new import_core16.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]));
2146
2436
  }
2147
2437
  function makeOrientedBoundingBoxFromQuaternion(center, halfSize, quaternion, result = new OrientedBoundingBox()) {
2148
- const halfAxes = new import_core16.Matrix3().fromQuaternion(quaternion);
2438
+ const halfAxes = new import_core17.Matrix3().fromQuaternion(quaternion);
2149
2439
  for (let column = 0; column < 3; column++) {
2150
2440
  for (let row = 0; row < 3; row++)
2151
2441
  halfAxes[column * 3 + row] *= halfSize[column];
2152
2442
  }
2153
- result.center = new import_core16.Vector3(center);
2443
+ result.center = new import_core17.Vector3(center);
2154
2444
  result.halfAxes = halfAxes;
2155
2445
  return result;
2156
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
+ }
2157
2560
  //# sourceMappingURL=index.cjs.map