@math.gl/culling 4.0.0-beta.1 → 4.0.1

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 (55) hide show
  1. package/dist/constants.d.ts +0 -1
  2. package/dist/constants.js +5 -4
  3. package/dist/index.cjs +27 -45
  4. package/dist/index.cjs.map +7 -0
  5. package/dist/index.d.ts +11 -12
  6. package/dist/index.js +2 -1
  7. package/dist/lib/algorithms/bounding-box-from-points.d.ts +2 -3
  8. package/dist/lib/algorithms/bounding-box-from-points.js +113 -113
  9. package/dist/lib/algorithms/bounding-sphere-from-points.d.ts +1 -2
  10. package/dist/lib/algorithms/bounding-sphere-from-points.js +117 -103
  11. package/dist/lib/algorithms/compute-eigen-decomposition.d.ts +1 -2
  12. package/dist/lib/algorithms/compute-eigen-decomposition.js +113 -85
  13. package/dist/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +2 -3
  14. package/dist/lib/bounding-volumes/axis-aligned-bounding-box.js +100 -80
  15. package/dist/lib/bounding-volumes/bounding-sphere.d.ts +2 -3
  16. package/dist/lib/bounding-volumes/bounding-sphere.js +106 -97
  17. package/dist/lib/bounding-volumes/bounding-volume.d.ts +1 -2
  18. package/dist/lib/bounding-volumes/bounding-volume.js +0 -1
  19. package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts +3 -4
  20. package/dist/lib/bounding-volumes/oriented-bounding-box.js +238 -196
  21. package/dist/lib/culling-volume.d.ts +3 -4
  22. package/dist/lib/culling-volume.js +109 -90
  23. package/dist/lib/perspective-frustum.d.ts +2 -3
  24. package/dist/lib/perspective-frustum.js +184 -136
  25. package/dist/lib/perspective-off-center-frustum.d.ts +2 -3
  26. package/dist/lib/perspective-off-center-frustum.js +259 -158
  27. package/dist/lib/plane.d.ts +0 -1
  28. package/dist/lib/plane.js +58 -59
  29. package/package.json +5 -6
  30. package/dist/constants.d.ts.map +0 -1
  31. package/dist/constants.js.map +0 -1
  32. package/dist/index.d.ts.map +0 -1
  33. package/dist/index.js.map +0 -1
  34. package/dist/lib/algorithms/bounding-box-from-points.d.ts.map +0 -1
  35. package/dist/lib/algorithms/bounding-box-from-points.js.map +0 -1
  36. package/dist/lib/algorithms/bounding-sphere-from-points.d.ts.map +0 -1
  37. package/dist/lib/algorithms/bounding-sphere-from-points.js.map +0 -1
  38. package/dist/lib/algorithms/compute-eigen-decomposition.d.ts.map +0 -1
  39. package/dist/lib/algorithms/compute-eigen-decomposition.js.map +0 -1
  40. package/dist/lib/bounding-volumes/axis-aligned-bounding-box.d.ts.map +0 -1
  41. package/dist/lib/bounding-volumes/axis-aligned-bounding-box.js.map +0 -1
  42. package/dist/lib/bounding-volumes/bounding-sphere.d.ts.map +0 -1
  43. package/dist/lib/bounding-volumes/bounding-sphere.js.map +0 -1
  44. package/dist/lib/bounding-volumes/bounding-volume.d.ts.map +0 -1
  45. package/dist/lib/bounding-volumes/bounding-volume.js.map +0 -1
  46. package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts.map +0 -1
  47. package/dist/lib/bounding-volumes/oriented-bounding-box.js.map +0 -1
  48. package/dist/lib/culling-volume.d.ts.map +0 -1
  49. package/dist/lib/culling-volume.js.map +0 -1
  50. package/dist/lib/perspective-frustum.d.ts.map +0 -1
  51. package/dist/lib/perspective-frustum.js.map +0 -1
  52. package/dist/lib/perspective-off-center-frustum.d.ts.map +0 -1
  53. package/dist/lib/perspective-off-center-frustum.js.map +0 -1
  54. package/dist/lib/plane.d.ts.map +0 -1
  55. package/dist/lib/plane.js.map +0 -1
@@ -1,3 +1,5 @@
1
+ // This file is derived from the Cesium math library under Apache 2 license
2
+ // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
1
3
  import { Vector3, Matrix3 } from '@math.gl/core';
2
4
  import { computeEigenDecomposition } from "./compute-eigen-decomposition.js";
3
5
  import { OrientedBoundingBox } from "../bounding-volumes/oriented-bounding-box.js";
@@ -9,123 +11,121 @@ const scratchVector5 = new Vector3();
9
11
  const scratchVector6 = new Vector3();
10
12
  const scratchCovarianceResult = new Matrix3();
11
13
  const scratchEigenResult = {
12
- diagonal: new Matrix3(),
13
- unitary: new Matrix3()
14
+ diagonal: new Matrix3(),
15
+ unitary: new Matrix3()
14
16
  };
17
+ /**
18
+ * Computes an instance of an OrientedBoundingBox of the given positions.
19
+ *
20
+ * This is an implementation of Stefan Gottschalk's Collision Queries using Oriented Bounding Boxes solution (PHD thesis).
21
+ * Reference: http://gamma.cs.unc.edu/users/gottschalk/main.pdf
22
+ */
23
+ /* eslint-disable max-statements */
15
24
  export function makeOrientedBoundingBoxFromPoints(positions, result = new OrientedBoundingBox()) {
16
- if (!positions || positions.length === 0) {
17
- result.halfAxes = new Matrix3([0, 0, 0, 0, 0, 0, 0, 0, 0]);
18
- result.center = new Vector3();
25
+ if (!positions || positions.length === 0) {
26
+ result.halfAxes = new Matrix3([0, 0, 0, 0, 0, 0, 0, 0, 0]);
27
+ result.center = new Vector3();
28
+ return result;
29
+ }
30
+ const length = positions.length;
31
+ const meanPoint = new Vector3(0, 0, 0);
32
+ for (const position of positions) {
33
+ meanPoint.add(position);
34
+ }
35
+ const invLength = 1.0 / length;
36
+ meanPoint.multiplyByScalar(invLength);
37
+ let exx = 0.0;
38
+ let exy = 0.0;
39
+ let exz = 0.0;
40
+ let eyy = 0.0;
41
+ let eyz = 0.0;
42
+ let ezz = 0.0;
43
+ for (const position of positions) {
44
+ const p = scratchVector2.copy(position).subtract(meanPoint);
45
+ exx += p.x * p.x;
46
+ exy += p.x * p.y;
47
+ exz += p.x * p.z;
48
+ eyy += p.y * p.y;
49
+ eyz += p.y * p.z;
50
+ ezz += p.z * p.z;
51
+ }
52
+ exx *= invLength;
53
+ exy *= invLength;
54
+ exz *= invLength;
55
+ eyy *= invLength;
56
+ eyz *= invLength;
57
+ ezz *= invLength;
58
+ const covarianceMatrix = scratchCovarianceResult;
59
+ covarianceMatrix[0] = exx;
60
+ covarianceMatrix[1] = exy;
61
+ covarianceMatrix[2] = exz;
62
+ covarianceMatrix[3] = exy;
63
+ covarianceMatrix[4] = eyy;
64
+ covarianceMatrix[5] = eyz;
65
+ covarianceMatrix[6] = exz;
66
+ covarianceMatrix[7] = eyz;
67
+ covarianceMatrix[8] = ezz;
68
+ const { unitary } = computeEigenDecomposition(covarianceMatrix, scratchEigenResult);
69
+ const rotation = result.halfAxes.copy(unitary);
70
+ let v1 = rotation.getColumn(0, scratchVector4);
71
+ let v2 = rotation.getColumn(1, scratchVector5);
72
+ let v3 = rotation.getColumn(2, scratchVector6);
73
+ let u1 = -Number.MAX_VALUE;
74
+ let u2 = -Number.MAX_VALUE;
75
+ let u3 = -Number.MAX_VALUE;
76
+ let l1 = Number.MAX_VALUE;
77
+ let l2 = Number.MAX_VALUE;
78
+ let l3 = Number.MAX_VALUE;
79
+ for (const position of positions) {
80
+ scratchVector2.copy(position);
81
+ u1 = Math.max(scratchVector2.dot(v1), u1);
82
+ u2 = Math.max(scratchVector2.dot(v2), u2);
83
+ u3 = Math.max(scratchVector2.dot(v3), u3);
84
+ l1 = Math.min(scratchVector2.dot(v1), l1);
85
+ l2 = Math.min(scratchVector2.dot(v2), l2);
86
+ l3 = Math.min(scratchVector2.dot(v3), l3);
87
+ }
88
+ v1 = v1.multiplyByScalar(0.5 * (l1 + u1));
89
+ v2 = v2.multiplyByScalar(0.5 * (l2 + u2));
90
+ v3 = v3.multiplyByScalar(0.5 * (l3 + u3));
91
+ result.center.copy(v1).add(v2).add(v3);
92
+ const scale = scratchVector3.set(u1 - l1, u2 - l2, u3 - l3).multiplyByScalar(0.5);
93
+ const scaleMatrix = new Matrix3([scale[0], 0, 0, 0, scale[1], 0, 0, 0, scale[2]]);
94
+ result.halfAxes.multiplyRight(scaleMatrix);
19
95
  return result;
20
- }
21
-
22
- const length = positions.length;
23
- const meanPoint = new Vector3(0, 0, 0);
24
-
25
- for (const position of positions) {
26
- meanPoint.add(position);
27
- }
28
-
29
- const invLength = 1.0 / length;
30
- meanPoint.multiplyByScalar(invLength);
31
- let exx = 0.0;
32
- let exy = 0.0;
33
- let exz = 0.0;
34
- let eyy = 0.0;
35
- let eyz = 0.0;
36
- let ezz = 0.0;
37
-
38
- for (const position of positions) {
39
- const p = scratchVector2.copy(position).subtract(meanPoint);
40
- exx += p.x * p.x;
41
- exy += p.x * p.y;
42
- exz += p.x * p.z;
43
- eyy += p.y * p.y;
44
- eyz += p.y * p.z;
45
- ezz += p.z * p.z;
46
- }
47
-
48
- exx *= invLength;
49
- exy *= invLength;
50
- exz *= invLength;
51
- eyy *= invLength;
52
- eyz *= invLength;
53
- ezz *= invLength;
54
- const covarianceMatrix = scratchCovarianceResult;
55
- covarianceMatrix[0] = exx;
56
- covarianceMatrix[1] = exy;
57
- covarianceMatrix[2] = exz;
58
- covarianceMatrix[3] = exy;
59
- covarianceMatrix[4] = eyy;
60
- covarianceMatrix[5] = eyz;
61
- covarianceMatrix[6] = exz;
62
- covarianceMatrix[7] = eyz;
63
- covarianceMatrix[8] = ezz;
64
- const {
65
- unitary
66
- } = computeEigenDecomposition(covarianceMatrix, scratchEigenResult);
67
- const rotation = result.halfAxes.copy(unitary);
68
- let v1 = rotation.getColumn(0, scratchVector4);
69
- let v2 = rotation.getColumn(1, scratchVector5);
70
- let v3 = rotation.getColumn(2, scratchVector6);
71
- let u1 = -Number.MAX_VALUE;
72
- let u2 = -Number.MAX_VALUE;
73
- let u3 = -Number.MAX_VALUE;
74
- let l1 = Number.MAX_VALUE;
75
- let l2 = Number.MAX_VALUE;
76
- let l3 = Number.MAX_VALUE;
77
-
78
- for (const position of positions) {
79
- scratchVector2.copy(position);
80
- u1 = Math.max(scratchVector2.dot(v1), u1);
81
- u2 = Math.max(scratchVector2.dot(v2), u2);
82
- u3 = Math.max(scratchVector2.dot(v3), u3);
83
- l1 = Math.min(scratchVector2.dot(v1), l1);
84
- l2 = Math.min(scratchVector2.dot(v2), l2);
85
- l3 = Math.min(scratchVector2.dot(v3), l3);
86
- }
87
-
88
- v1 = v1.multiplyByScalar(0.5 * (l1 + u1));
89
- v2 = v2.multiplyByScalar(0.5 * (l2 + u2));
90
- v3 = v3.multiplyByScalar(0.5 * (l3 + u3));
91
- result.center.copy(v1).add(v2).add(v3);
92
- const scale = scratchVector3.set(u1 - l1, u2 - l2, u3 - l3).multiplyByScalar(0.5);
93
- const scaleMatrix = new Matrix3([scale[0], 0, 0, 0, scale[1], 0, 0, 0, scale[2]]);
94
- result.halfAxes.multiplyRight(scaleMatrix);
95
- return result;
96
96
  }
97
+ /**
98
+ * Computes an instance of an AxisAlignedBoundingBox. The box is determined by
99
+ * finding the points spaced the farthest apart on the x, y, and z axes.
100
+ */
97
101
  export function makeAxisAlignedBoundingBoxFromPoints(positions, result = new AxisAlignedBoundingBox()) {
98
- if (!positions || positions.length === 0) {
99
- result.minimum.set(0, 0, 0);
100
- result.maximum.set(0, 0, 0);
101
- result.center.set(0, 0, 0);
102
- result.halfDiagonal.set(0, 0, 0);
102
+ if (!positions || positions.length === 0) {
103
+ result.minimum.set(0, 0, 0);
104
+ result.maximum.set(0, 0, 0);
105
+ result.center.set(0, 0, 0);
106
+ result.halfDiagonal.set(0, 0, 0);
107
+ return result;
108
+ }
109
+ let minimumX = positions[0][0];
110
+ let minimumY = positions[0][1];
111
+ let minimumZ = positions[0][2];
112
+ let maximumX = positions[0][0];
113
+ let maximumY = positions[0][1];
114
+ let maximumZ = positions[0][2];
115
+ for (const p of positions) {
116
+ const x = p[0];
117
+ const y = p[1];
118
+ const z = p[2];
119
+ minimumX = Math.min(x, minimumX);
120
+ maximumX = Math.max(x, maximumX);
121
+ minimumY = Math.min(y, minimumY);
122
+ maximumY = Math.max(y, maximumY);
123
+ minimumZ = Math.min(z, minimumZ);
124
+ maximumZ = Math.max(z, maximumZ);
125
+ }
126
+ result.minimum.set(minimumX, minimumY, minimumZ);
127
+ result.maximum.set(maximumX, maximumY, maximumZ);
128
+ result.center.copy(result.minimum).add(result.maximum).scale(0.5);
129
+ result.halfDiagonal.copy(result.maximum).subtract(result.center);
103
130
  return result;
104
- }
105
-
106
- let minimumX = positions[0][0];
107
- let minimumY = positions[0][1];
108
- let minimumZ = positions[0][2];
109
- let maximumX = positions[0][0];
110
- let maximumY = positions[0][1];
111
- let maximumZ = positions[0][2];
112
-
113
- for (const p of positions) {
114
- const x = p[0];
115
- const y = p[1];
116
- const z = p[2];
117
- minimumX = Math.min(x, minimumX);
118
- maximumX = Math.max(x, maximumX);
119
- minimumY = Math.min(y, minimumY);
120
- maximumY = Math.max(y, maximumY);
121
- minimumZ = Math.min(z, minimumZ);
122
- maximumZ = Math.max(z, maximumZ);
123
- }
124
-
125
- result.minimum.set(minimumX, minimumY, minimumZ);
126
- result.maximum.set(maximumX, maximumY, maximumZ);
127
- result.center.copy(result.minimum).add(result.maximum).scale(0.5);
128
- result.halfDiagonal.copy(result.maximum).subtract(result.center);
129
- return result;
130
131
  }
131
- //# sourceMappingURL=bounding-box-from-points.js.map
@@ -1,4 +1,4 @@
1
- import { BoundingSphere } from '../bounding-volumes/bounding-sphere';
1
+ import { BoundingSphere } from "../bounding-volumes/bounding-sphere.js";
2
2
  /**
3
3
  * Computes a tight-fitting bounding sphere enclosing a list of 3D Cartesian points.
4
4
  *
@@ -11,4 +11,3 @@ import { BoundingSphere } from '../bounding-volumes/bounding-sphere';
11
11
  * @returns The modified result parameter or a new `BoundingSphere` instance if not provided.
12
12
  */
13
13
  export declare function makeBoundingSphereFromPoints(positions: number[][], result?: BoundingSphere): BoundingSphere;
14
- //# sourceMappingURL=bounding-sphere-from-points.d.ts.map
@@ -1,5 +1,8 @@
1
+ // This file is derived from the Cesium math library under Apache 2 license
2
+ // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
1
3
  import { Vector3 } from '@math.gl/core';
2
4
  import { BoundingSphere } from "../bounding-volumes/bounding-sphere.js";
5
+ /* eslint-disable */
3
6
  const fromPointsXMin = new Vector3();
4
7
  const fromPointsYMin = new Vector3();
5
8
  const fromPointsZMin = new Vector3();
@@ -12,115 +15,126 @@ const fromPointsRitterCenter = new Vector3();
12
15
  const fromPointsMinBoxPt = new Vector3();
13
16
  const fromPointsMaxBoxPt = new Vector3();
14
17
  const fromPointsNaiveCenterScratch = new Vector3();
18
+ // const volumeConstant = (4.0 / 3.0) * Math.PI;
19
+ /**
20
+ * Computes a tight-fitting bounding sphere enclosing a list of 3D Cartesian points.
21
+ *
22
+ * The bounding sphere is computed by running two algorithms, a naive algorithm and
23
+ * Ritter's algorithm. The smaller of the two spheres is used to ensure a tight fit.
24
+ * Bounding sphere computation article http://blogs.agi.com/insight3d/index.php/2008/02/04/a-bounding
25
+ *
26
+ * @param positions An array of points that the bounding sphere will enclose.
27
+ * @param result Optional object onto which to store the result.
28
+ * @returns The modified result parameter or a new `BoundingSphere` instance if not provided.
29
+ */
15
30
  export function makeBoundingSphereFromPoints(positions, result = new BoundingSphere()) {
16
- if (!positions || positions.length === 0) {
17
- return result.fromCenterRadius([0, 0, 0], 0);
18
- }
19
-
20
- const currentPos = fromPointsCurrentPos.copy(positions[0]);
21
- const xMin = fromPointsXMin.copy(currentPos);
22
- const yMin = fromPointsYMin.copy(currentPos);
23
- const zMin = fromPointsZMin.copy(currentPos);
24
- const xMax = fromPointsXMax.copy(currentPos);
25
- const yMax = fromPointsYMax.copy(currentPos);
26
- const zMax = fromPointsZMax.copy(currentPos);
27
-
28
- for (const position of positions) {
29
- currentPos.copy(position);
30
- const x = currentPos.x;
31
- const y = currentPos.y;
32
- const z = currentPos.z;
33
-
34
- if (x < xMin.x) {
35
- xMin.copy(currentPos);
31
+ if (!positions || positions.length === 0) {
32
+ return result.fromCenterRadius([0, 0, 0], 0);
36
33
  }
37
-
38
- if (x > xMax.x) {
39
- xMax.copy(currentPos);
34
+ const currentPos = fromPointsCurrentPos.copy(positions[0]);
35
+ const xMin = fromPointsXMin.copy(currentPos);
36
+ const yMin = fromPointsYMin.copy(currentPos);
37
+ const zMin = fromPointsZMin.copy(currentPos);
38
+ const xMax = fromPointsXMax.copy(currentPos);
39
+ const yMax = fromPointsYMax.copy(currentPos);
40
+ const zMax = fromPointsZMax.copy(currentPos);
41
+ for (const position of positions) {
42
+ currentPos.copy(position);
43
+ const x = currentPos.x;
44
+ const y = currentPos.y;
45
+ const z = currentPos.z;
46
+ // Store points containing the the smallest and largest components
47
+ if (x < xMin.x) {
48
+ xMin.copy(currentPos);
49
+ }
50
+ if (x > xMax.x) {
51
+ xMax.copy(currentPos);
52
+ }
53
+ if (y < yMin.y) {
54
+ yMin.copy(currentPos);
55
+ }
56
+ if (y > yMax.y) {
57
+ yMax.copy(currentPos);
58
+ }
59
+ if (z < zMin.z) {
60
+ zMin.copy(currentPos);
61
+ }
62
+ if (z > zMax.z) {
63
+ zMax.copy(currentPos);
64
+ }
40
65
  }
41
-
42
- if (y < yMin.y) {
43
- yMin.copy(currentPos);
66
+ // Compute x-, y-, and z-spans (Squared distances b/n each component's min. and max.).
67
+ const xSpan = fromPointsScratch.copy(xMax).subtract(xMin).magnitudeSquared();
68
+ const ySpan = fromPointsScratch.copy(yMax).subtract(yMin).magnitudeSquared();
69
+ const zSpan = fromPointsScratch.copy(zMax).subtract(zMin).magnitudeSquared();
70
+ // Set the diameter endpoints to the largest span.
71
+ let diameter1 = xMin;
72
+ let diameter2 = xMax;
73
+ let maxSpan = xSpan;
74
+ if (ySpan > maxSpan) {
75
+ maxSpan = ySpan;
76
+ diameter1 = yMin;
77
+ diameter2 = yMax;
44
78
  }
45
-
46
- if (y > yMax.y) {
47
- yMax.copy(currentPos);
79
+ if (zSpan > maxSpan) {
80
+ maxSpan = zSpan;
81
+ diameter1 = zMin;
82
+ diameter2 = zMax;
48
83
  }
49
-
50
- if (z < zMin.z) {
51
- zMin.copy(currentPos);
84
+ // Calculate the center of the initial sphere found by Ritter's algorithm
85
+ const ritterCenter = fromPointsRitterCenter;
86
+ ritterCenter.x = (diameter1.x + diameter2.x) * 0.5;
87
+ ritterCenter.y = (diameter1.y + diameter2.y) * 0.5;
88
+ ritterCenter.z = (diameter1.z + diameter2.z) * 0.5;
89
+ // Calculate the radius of the initial sphere found by Ritter's algorithm
90
+ let radiusSquared = fromPointsScratch.copy(diameter2).subtract(ritterCenter).magnitudeSquared();
91
+ let ritterRadius = Math.sqrt(radiusSquared);
92
+ // Find the center of the sphere found using the Naive method.
93
+ const minBoxPt = fromPointsMinBoxPt;
94
+ minBoxPt.x = xMin.x;
95
+ minBoxPt.y = yMin.y;
96
+ minBoxPt.z = zMin.z;
97
+ const maxBoxPt = fromPointsMaxBoxPt;
98
+ maxBoxPt.x = xMax.x;
99
+ maxBoxPt.y = yMax.y;
100
+ maxBoxPt.z = zMax.z;
101
+ const naiveCenter = fromPointsNaiveCenterScratch
102
+ .copy(minBoxPt)
103
+ .add(maxBoxPt)
104
+ .multiplyByScalar(0.5);
105
+ // Begin 2nd pass to find naive radius and modify the ritter sphere.
106
+ let naiveRadius = 0;
107
+ for (const position of positions) {
108
+ currentPos.copy(position);
109
+ // Find the furthest point from the naive center to calculate the naive radius.
110
+ const r = fromPointsScratch.copy(currentPos).subtract(naiveCenter).magnitude();
111
+ if (r > naiveRadius) {
112
+ naiveRadius = r;
113
+ }
114
+ // Make adjustments to the Ritter Sphere to include all points.
115
+ const oldCenterToPointSquared = fromPointsScratch
116
+ .copy(currentPos)
117
+ .subtract(ritterCenter)
118
+ .magnitudeSquared();
119
+ if (oldCenterToPointSquared > radiusSquared) {
120
+ const oldCenterToPoint = Math.sqrt(oldCenterToPointSquared);
121
+ // Calculate new radius to include the point that lies outside
122
+ ritterRadius = (ritterRadius + oldCenterToPoint) * 0.5;
123
+ radiusSquared = ritterRadius * ritterRadius;
124
+ // Calculate center of new Ritter sphere
125
+ const oldToNew = oldCenterToPoint - ritterRadius;
126
+ ritterCenter.x = (ritterRadius * ritterCenter.x + oldToNew * currentPos.x) / oldCenterToPoint;
127
+ ritterCenter.y = (ritterRadius * ritterCenter.y + oldToNew * currentPos.y) / oldCenterToPoint;
128
+ ritterCenter.z = (ritterRadius * ritterCenter.z + oldToNew * currentPos.z) / oldCenterToPoint;
129
+ }
52
130
  }
53
-
54
- if (z > zMax.z) {
55
- zMax.copy(currentPos);
131
+ if (ritterRadius < naiveRadius) {
132
+ ritterCenter.to(result.center);
133
+ result.radius = ritterRadius;
56
134
  }
57
- }
58
-
59
- const xSpan = fromPointsScratch.copy(xMax).subtract(xMin).magnitudeSquared();
60
- const ySpan = fromPointsScratch.copy(yMax).subtract(yMin).magnitudeSquared();
61
- const zSpan = fromPointsScratch.copy(zMax).subtract(zMin).magnitudeSquared();
62
- let diameter1 = xMin;
63
- let diameter2 = xMax;
64
- let maxSpan = xSpan;
65
-
66
- if (ySpan > maxSpan) {
67
- maxSpan = ySpan;
68
- diameter1 = yMin;
69
- diameter2 = yMax;
70
- }
71
-
72
- if (zSpan > maxSpan) {
73
- maxSpan = zSpan;
74
- diameter1 = zMin;
75
- diameter2 = zMax;
76
- }
77
-
78
- const ritterCenter = fromPointsRitterCenter;
79
- ritterCenter.x = (diameter1.x + diameter2.x) * 0.5;
80
- ritterCenter.y = (diameter1.y + diameter2.y) * 0.5;
81
- ritterCenter.z = (diameter1.z + diameter2.z) * 0.5;
82
- let radiusSquared = fromPointsScratch.copy(diameter2).subtract(ritterCenter).magnitudeSquared();
83
- let ritterRadius = Math.sqrt(radiusSquared);
84
- const minBoxPt = fromPointsMinBoxPt;
85
- minBoxPt.x = xMin.x;
86
- minBoxPt.y = yMin.y;
87
- minBoxPt.z = zMin.z;
88
- const maxBoxPt = fromPointsMaxBoxPt;
89
- maxBoxPt.x = xMax.x;
90
- maxBoxPt.y = yMax.y;
91
- maxBoxPt.z = zMax.z;
92
- const naiveCenter = fromPointsNaiveCenterScratch.copy(minBoxPt).add(maxBoxPt).multiplyByScalar(0.5);
93
- let naiveRadius = 0;
94
-
95
- for (const position of positions) {
96
- currentPos.copy(position);
97
- const r = fromPointsScratch.copy(currentPos).subtract(naiveCenter).magnitude();
98
-
99
- if (r > naiveRadius) {
100
- naiveRadius = r;
135
+ else {
136
+ naiveCenter.to(result.center);
137
+ result.radius = naiveRadius;
101
138
  }
102
-
103
- const oldCenterToPointSquared = fromPointsScratch.copy(currentPos).subtract(ritterCenter).magnitudeSquared();
104
-
105
- if (oldCenterToPointSquared > radiusSquared) {
106
- const oldCenterToPoint = Math.sqrt(oldCenterToPointSquared);
107
- ritterRadius = (ritterRadius + oldCenterToPoint) * 0.5;
108
- radiusSquared = ritterRadius * ritterRadius;
109
- const oldToNew = oldCenterToPoint - ritterRadius;
110
- ritterCenter.x = (ritterRadius * ritterCenter.x + oldToNew * currentPos.x) / oldCenterToPoint;
111
- ritterCenter.y = (ritterRadius * ritterCenter.y + oldToNew * currentPos.y) / oldCenterToPoint;
112
- ritterCenter.z = (ritterRadius * ritterCenter.z + oldToNew * currentPos.z) / oldCenterToPoint;
113
- }
114
- }
115
-
116
- if (ritterRadius < naiveRadius) {
117
- ritterCenter.to(result.center);
118
- result.radius = ritterRadius;
119
- } else {
120
- naiveCenter.to(result.center);
121
- result.radius = naiveRadius;
122
- }
123
-
124
- return result;
139
+ return result;
125
140
  }
126
- //# sourceMappingURL=bounding-sphere-from-points.js.map
@@ -1,5 +1,5 @@
1
1
  import { Matrix3 } from '@math.gl/core';
2
- export declare type EigenDecomposition = {
2
+ export type EigenDecomposition = {
3
3
  unitary: Matrix3;
4
4
  diagonal: Matrix3;
5
5
  };
@@ -34,4 +34,3 @@ export declare type EigenDecomposition = {
34
34
  * const c = v.multiplyByScalar(lambda); // equal to v.transformByMatrix3(a)
35
35
  */
36
36
  export declare function computeEigenDecomposition(matrix: number[], result?: EigenDecomposition): EigenDecomposition;
37
- //# sourceMappingURL=compute-eigen-decomposition.d.ts.map