@math.gl/culling 3.5.3 → 3.6.0-alpha.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.
- package/dist/constants.d.ts +6 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +8 -0
- package/dist/es5/constants.js +7 -5
- package/dist/es5/constants.js.map +1 -1
- package/dist/es5/index.js +12 -24
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/algorithms/bounding-box-from-points.js +72 -122
- package/dist/es5/lib/algorithms/bounding-box-from-points.js.map +1 -1
- package/dist/es5/lib/algorithms/bounding-sphere-from-points.js +81 -109
- package/dist/es5/lib/algorithms/bounding-sphere-from-points.js.map +1 -1
- package/dist/es5/lib/algorithms/compute-eigen-decomposition.js +36 -37
- package/dist/es5/lib/algorithms/compute-eigen-decomposition.js.map +1 -1
- package/dist/es5/lib/bounding-volumes/axis-aligned-bounding-box.js +68 -74
- package/dist/es5/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -1
- package/dist/es5/lib/bounding-volumes/bounding-sphere.js +93 -109
- package/dist/es5/lib/bounding-volumes/bounding-sphere.js.map +1 -1
- package/dist/es5/lib/bounding-volumes/bounding-volume.js +2 -0
- package/dist/es5/lib/bounding-volumes/bounding-volume.js.map +1 -0
- package/dist/es5/lib/bounding-volumes/oriented-bounding-box.js +190 -211
- package/dist/es5/lib/bounding-volumes/oriented-bounding-box.js.map +1 -1
- package/dist/es5/lib/culling-volume.js +80 -131
- package/dist/es5/lib/culling-volume.js.map +1 -1
- package/dist/es5/lib/perspective-frustum.js +73 -84
- package/dist/es5/lib/perspective-frustum.js.map +1 -1
- package/dist/es5/lib/perspective-off-center-frustum.js +114 -117
- package/dist/es5/lib/perspective-off-center-frustum.js.map +1 -1
- package/dist/es5/lib/plane.js +55 -69
- package/dist/es5/lib/plane.js.map +1 -1
- package/dist/esm/constants.js +7 -5
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/index.js +0 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/algorithms/bounding-box-from-points.js +7 -6
- package/dist/esm/lib/algorithms/bounding-box-from-points.js.map +1 -1
- package/dist/esm/lib/algorithms/bounding-sphere-from-points.js +6 -6
- package/dist/esm/lib/algorithms/bounding-sphere-from-points.js.map +1 -1
- package/dist/esm/lib/algorithms/compute-eigen-decomposition.js.map +1 -1
- package/dist/esm/lib/bounding-volumes/axis-aligned-bounding-box.js +15 -6
- package/dist/esm/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -1
- package/dist/esm/lib/bounding-volumes/bounding-sphere.js +12 -6
- package/dist/esm/lib/bounding-volumes/bounding-sphere.js.map +1 -1
- package/dist/esm/lib/bounding-volumes/bounding-volume.js +2 -0
- package/dist/esm/lib/bounding-volumes/bounding-volume.js.map +1 -0
- package/dist/esm/lib/bounding-volumes/oriented-bounding-box.js +5 -0
- package/dist/esm/lib/bounding-volumes/oriented-bounding-box.js.map +1 -1
- package/dist/esm/lib/culling-volume.js +10 -16
- package/dist/esm/lib/culling-volume.js.map +1 -1
- package/dist/esm/lib/perspective-frustum.js +31 -5
- package/dist/esm/lib/perspective-frustum.js.map +1 -1
- package/dist/esm/lib/perspective-off-center-frustum.js +31 -3
- package/dist/esm/lib/perspective-off-center-frustum.js.map +1 -1
- package/dist/esm/lib/plane.js +6 -1
- package/dist/esm/lib/plane.js.map +1 -1
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/{src → dist}/lib/algorithms/bounding-box-from-points.d.ts +3 -10
- package/dist/lib/algorithms/bounding-box-from-points.d.ts.map +1 -0
- package/dist/lib/algorithms/bounding-box-from-points.js +131 -0
- package/dist/{esm/lib → lib}/algorithms/bounding-sphere-from-points.d.ts +2 -5
- package/dist/lib/algorithms/bounding-sphere-from-points.d.ts.map +1 -0
- package/dist/lib/algorithms/bounding-sphere-from-points.js +142 -0
- package/dist/{es5/lib → lib}/algorithms/compute-eigen-decomposition.d.ts +7 -9
- package/dist/lib/algorithms/compute-eigen-decomposition.d.ts.map +1 -0
- package/dist/lib/algorithms/compute-eigen-decomposition.js +131 -0
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +56 -0
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.d.ts.map +1 -0
- package/dist/lib/bounding-volumes/axis-aligned-bounding-box.js +111 -0
- package/dist/lib/bounding-volumes/bounding-sphere.d.ts +40 -0
- package/dist/lib/bounding-volumes/bounding-sphere.d.ts.map +1 -0
- package/dist/lib/bounding-volumes/bounding-sphere.js +118 -0
- package/dist/lib/bounding-volumes/bounding-volume.d.ts +30 -0
- package/dist/lib/bounding-volumes/bounding-volume.d.ts.map +1 -0
- package/dist/lib/bounding-volumes/bounding-volume.js +1 -0
- package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts +67 -0
- package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts.map +1 -0
- package/dist/lib/bounding-volumes/oriented-bounding-box.js +256 -0
- package/dist/lib/culling-volume.d.ts +46 -0
- package/dist/lib/culling-volume.d.ts.map +1 -0
- package/dist/lib/culling-volume.js +121 -0
- package/dist/lib/perspective-frustum.d.ts +140 -0
- package/dist/lib/perspective-frustum.d.ts.map +1 -0
- package/dist/lib/perspective-frustum.js +205 -0
- package/dist/lib/perspective-off-center-frustum.d.ts +122 -0
- package/dist/lib/perspective-off-center-frustum.d.ts.map +1 -0
- package/dist/lib/perspective-off-center-frustum.js +305 -0
- package/dist/lib/plane.d.ts +26 -0
- package/dist/lib/plane.d.ts.map +1 -0
- package/dist/lib/plane.js +63 -0
- package/package.json +5 -5
- package/src/constants.ts +8 -0
- package/src/{index.js → index.ts} +0 -4
- package/src/lib/algorithms/{bounding-box-from-points.js → bounding-box-from-points.ts} +25 -10
- package/src/lib/algorithms/{bounding-sphere-from-points.js → bounding-sphere-from-points.ts} +21 -7
- package/src/lib/algorithms/{compute-eigen-decomposition.js → compute-eigen-decomposition.ts} +40 -1
- package/src/lib/bounding-volumes/{axis-aligned-bounding-box.js → axis-aligned-bounding-box.ts} +45 -14
- package/src/lib/bounding-volumes/{bounding-sphere.js → bounding-sphere.ts} +47 -31
- package/src/lib/bounding-volumes/{bounding-volume.d.ts → bounding-volume.ts} +7 -7
- package/src/lib/bounding-volumes/{oriented-bounding-box.js → oriented-bounding-box.ts} +72 -14
- package/src/lib/{culling-volume.js → culling-volume.ts} +42 -34
- package/src/lib/{perspective-frustum.js → perspective-frustum.ts} +48 -66
- package/src/lib/{perspective-off-center-frustum.js → perspective-off-center-frustum.ts} +24 -14
- package/src/lib/{plane.js → plane.ts} +24 -17
- package/dist/es5/constants.d.ts +0 -6
- package/dist/es5/index.d.ts +0 -20
- package/dist/es5/lib/algorithms/bounding-box-from-points.d.ts +0 -22
- package/dist/es5/lib/algorithms/bounding-sphere-from-points.d.ts +0 -17
- package/dist/es5/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +0 -51
- package/dist/es5/lib/bounding-volumes/bounding-sphere.d.ts +0 -52
- package/dist/es5/lib/bounding-volumes/bounding-volume.d.ts +0 -32
- package/dist/es5/lib/bounding-volumes/oriented-bounding-box.d.ts +0 -83
- package/dist/es5/lib/culling-volume.d.ts +0 -55
- package/dist/es5/lib/plane.d.ts +0 -38
- package/dist/esm/constants.d.ts +0 -6
- package/dist/esm/index.d.ts +0 -20
- package/dist/esm/lib/algorithms/bounding-box-from-points.d.ts +0 -22
- package/dist/esm/lib/algorithms/compute-eigen-decomposition.d.ts +0 -39
- package/dist/esm/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +0 -51
- package/dist/esm/lib/bounding-volumes/bounding-sphere.d.ts +0 -52
- package/dist/esm/lib/bounding-volumes/bounding-volume.d.ts +0 -32
- package/dist/esm/lib/bounding-volumes/oriented-bounding-box.d.ts +0 -83
- package/dist/esm/lib/culling-volume.d.ts +0 -55
- package/dist/esm/lib/plane.d.ts +0 -38
- package/src/constants.d.ts +0 -6
- package/src/constants.js +0 -8
- package/src/index.d.ts +0 -20
- package/src/lib/algorithms/bounding-sphere-from-points.d.ts +0 -17
- package/src/lib/algorithms/compute-eigen-decomposition.d.ts +0 -39
- package/src/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +0 -51
- package/src/lib/bounding-volumes/bounding-sphere.d.ts +0 -52
- package/src/lib/bounding-volumes/oriented-bounding-box.d.ts +0 -83
- package/src/lib/culling-volume.d.ts +0 -55
- package/src/lib/plane.d.ts +0 -38
|
@@ -11,88 +11,70 @@ var _core = require("@math.gl/core");
|
|
|
11
11
|
|
|
12
12
|
var _boundingSphere = _interopRequireDefault(require("../bounding-volumes/bounding-sphere"));
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
const fromPointsXMin = new _core.Vector3();
|
|
15
|
+
const fromPointsYMin = new _core.Vector3();
|
|
16
|
+
const fromPointsZMin = new _core.Vector3();
|
|
17
|
+
const fromPointsXMax = new _core.Vector3();
|
|
18
|
+
const fromPointsYMax = new _core.Vector3();
|
|
19
|
+
const fromPointsZMax = new _core.Vector3();
|
|
20
|
+
const fromPointsCurrentPos = new _core.Vector3();
|
|
21
|
+
const fromPointsScratch = new _core.Vector3();
|
|
22
|
+
const fromPointsRitterCenter = new _core.Vector3();
|
|
23
|
+
const fromPointsMinBoxPt = new _core.Vector3();
|
|
24
|
+
const fromPointsMaxBoxPt = new _core.Vector3();
|
|
25
|
+
const fromPointsNaiveCenterScratch = new _core.Vector3();
|
|
26
|
+
const volumeConstant = 4.0 / 3.0 * Math.PI;
|
|
27
|
+
|
|
28
|
+
function makeBoundingSphereFromPoints(positions, result = new _boundingSphere.default()) {
|
|
29
|
+
if (!positions || positions.length === 0) {
|
|
30
|
+
return result.fromCenterRadius([0, 0, 0], 0);
|
|
31
|
+
}
|
|
15
32
|
|
|
16
|
-
|
|
33
|
+
const currentPos = fromPointsCurrentPos.copy(positions[0]);
|
|
34
|
+
const xMin = fromPointsXMin.copy(currentPos);
|
|
35
|
+
const yMin = fromPointsYMin.copy(currentPos);
|
|
36
|
+
const zMin = fromPointsZMin.copy(currentPos);
|
|
37
|
+
const xMax = fromPointsXMax.copy(currentPos);
|
|
38
|
+
const yMax = fromPointsYMax.copy(currentPos);
|
|
39
|
+
const zMax = fromPointsZMax.copy(currentPos);
|
|
40
|
+
|
|
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
|
+
|
|
47
|
+
if (x < xMin.x) {
|
|
48
|
+
xMin.copy(currentPos);
|
|
49
|
+
}
|
|
17
50
|
|
|
18
|
-
|
|
51
|
+
if (x > xMax.x) {
|
|
52
|
+
xMax.copy(currentPos);
|
|
53
|
+
}
|
|
19
54
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
var fromPointsXMax = new _core.Vector3();
|
|
24
|
-
var fromPointsYMax = new _core.Vector3();
|
|
25
|
-
var fromPointsZMax = new _core.Vector3();
|
|
26
|
-
var fromPointsCurrentPos = new _core.Vector3();
|
|
27
|
-
var fromPointsScratch = new _core.Vector3();
|
|
28
|
-
var fromPointsRitterCenter = new _core.Vector3();
|
|
29
|
-
var fromPointsMinBoxPt = new _core.Vector3();
|
|
30
|
-
var fromPointsMaxBoxPt = new _core.Vector3();
|
|
31
|
-
var fromPointsNaiveCenterScratch = new _core.Vector3();
|
|
32
|
-
var volumeConstant = 4.0 / 3.0 * Math.PI;
|
|
55
|
+
if (y < yMin.y) {
|
|
56
|
+
yMin.copy(currentPos);
|
|
57
|
+
}
|
|
33
58
|
|
|
34
|
-
|
|
35
|
-
|
|
59
|
+
if (y > yMax.y) {
|
|
60
|
+
yMax.copy(currentPos);
|
|
61
|
+
}
|
|
36
62
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
63
|
+
if (z < zMin.z) {
|
|
64
|
+
zMin.copy(currentPos);
|
|
65
|
+
}
|
|
40
66
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
var yMin = fromPointsYMin.copy(currentPos);
|
|
44
|
-
var zMin = fromPointsZMin.copy(currentPos);
|
|
45
|
-
var xMax = fromPointsXMax.copy(currentPos);
|
|
46
|
-
var yMax = fromPointsYMax.copy(currentPos);
|
|
47
|
-
var zMax = fromPointsZMax.copy(currentPos);
|
|
48
|
-
|
|
49
|
-
var _iterator = _createForOfIteratorHelper(positions),
|
|
50
|
-
_step;
|
|
51
|
-
|
|
52
|
-
try {
|
|
53
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
54
|
-
var position = _step.value;
|
|
55
|
-
currentPos.copy(position);
|
|
56
|
-
var x = currentPos.x;
|
|
57
|
-
var y = currentPos.y;
|
|
58
|
-
var z = currentPos.z;
|
|
59
|
-
|
|
60
|
-
if (x < xMin.x) {
|
|
61
|
-
currentPos.copy(xMin);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (x > xMax.x) {
|
|
65
|
-
currentPos.copy(xMax);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (y < yMin.y) {
|
|
69
|
-
currentPos.copy(yMin);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (y > yMax.y) {
|
|
73
|
-
currentPos.copy(yMax);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (z < zMin.z) {
|
|
77
|
-
currentPos.copy(zMin);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (z > zMax.z) {
|
|
81
|
-
currentPos.copy(zMax);
|
|
82
|
-
}
|
|
67
|
+
if (z > zMax.z) {
|
|
68
|
+
zMax.copy(currentPos);
|
|
83
69
|
}
|
|
84
|
-
} catch (err) {
|
|
85
|
-
_iterator.e(err);
|
|
86
|
-
} finally {
|
|
87
|
-
_iterator.f();
|
|
88
70
|
}
|
|
89
71
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
72
|
+
const xSpan = fromPointsScratch.copy(xMax).subtract(xMin).magnitudeSquared();
|
|
73
|
+
const ySpan = fromPointsScratch.copy(yMax).subtract(yMin).magnitudeSquared();
|
|
74
|
+
const zSpan = fromPointsScratch.copy(zMax).subtract(zMin).magnitudeSquared();
|
|
75
|
+
let diameter1 = xMin;
|
|
76
|
+
let diameter2 = xMax;
|
|
77
|
+
let maxSpan = xSpan;
|
|
96
78
|
|
|
97
79
|
if (ySpan > maxSpan) {
|
|
98
80
|
maxSpan = ySpan;
|
|
@@ -106,52 +88,42 @@ function makeBoundingSphereFromPoints(positions) {
|
|
|
106
88
|
diameter2 = zMax;
|
|
107
89
|
}
|
|
108
90
|
|
|
109
|
-
|
|
91
|
+
const ritterCenter = fromPointsRitterCenter;
|
|
110
92
|
ritterCenter.x = (diameter1.x + diameter2.x) * 0.5;
|
|
111
93
|
ritterCenter.y = (diameter1.y + diameter2.y) * 0.5;
|
|
112
94
|
ritterCenter.z = (diameter1.z + diameter2.z) * 0.5;
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
95
|
+
let radiusSquared = fromPointsScratch.copy(diameter2).subtract(ritterCenter).magnitudeSquared();
|
|
96
|
+
let ritterRadius = Math.sqrt(radiusSquared);
|
|
97
|
+
const minBoxPt = fromPointsMinBoxPt;
|
|
116
98
|
minBoxPt.x = xMin.x;
|
|
117
99
|
minBoxPt.y = yMin.y;
|
|
118
100
|
minBoxPt.z = zMin.z;
|
|
119
|
-
|
|
101
|
+
const maxBoxPt = fromPointsMaxBoxPt;
|
|
120
102
|
maxBoxPt.x = xMax.x;
|
|
121
103
|
maxBoxPt.y = yMax.y;
|
|
122
104
|
maxBoxPt.z = zMax.z;
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
radiusSquared = ritterRadius * ritterRadius;
|
|
145
|
-
var oldToNew = oldCenterToPoint - ritterRadius;
|
|
146
|
-
ritterCenter.x = (ritterRadius * ritterCenter.x + oldToNew * currentPos.x) / oldCenterToPoint;
|
|
147
|
-
ritterCenter.y = (ritterRadius * ritterCenter.y + oldToNew * currentPos.y) / oldCenterToPoint;
|
|
148
|
-
ritterCenter.z = (ritterRadius * ritterCenter.z + oldToNew * currentPos.z) / oldCenterToPoint;
|
|
149
|
-
}
|
|
105
|
+
const naiveCenter = fromPointsNaiveCenterScratch.copy(minBoxPt).add(maxBoxPt).multiplyByScalar(0.5);
|
|
106
|
+
let naiveRadius = 0;
|
|
107
|
+
|
|
108
|
+
for (const position of positions) {
|
|
109
|
+
currentPos.copy(position);
|
|
110
|
+
const r = fromPointsScratch.copy(currentPos).subtract(naiveCenter).magnitude();
|
|
111
|
+
|
|
112
|
+
if (r > naiveRadius) {
|
|
113
|
+
naiveRadius = r;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const oldCenterToPointSquared = fromPointsScratch.copy(currentPos).subtract(ritterCenter).magnitudeSquared();
|
|
117
|
+
|
|
118
|
+
if (oldCenterToPointSquared > radiusSquared) {
|
|
119
|
+
const oldCenterToPoint = Math.sqrt(oldCenterToPointSquared);
|
|
120
|
+
ritterRadius = (ritterRadius + oldCenterToPoint) * 0.5;
|
|
121
|
+
radiusSquared = ritterRadius * ritterRadius;
|
|
122
|
+
const oldToNew = oldCenterToPoint - ritterRadius;
|
|
123
|
+
ritterCenter.x = (ritterRadius * ritterCenter.x + oldToNew * currentPos.x) / oldCenterToPoint;
|
|
124
|
+
ritterCenter.y = (ritterRadius * ritterCenter.y + oldToNew * currentPos.y) / oldCenterToPoint;
|
|
125
|
+
ritterCenter.z = (ritterRadius * ritterCenter.z + oldToNew * currentPos.z) / oldCenterToPoint;
|
|
150
126
|
}
|
|
151
|
-
} catch (err) {
|
|
152
|
-
_iterator2.e(err);
|
|
153
|
-
} finally {
|
|
154
|
-
_iterator2.f();
|
|
155
127
|
}
|
|
156
128
|
|
|
157
129
|
if (ritterRadius < naiveRadius) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/algorithms/bounding-sphere-from-points.js"],"names":["fromPointsXMin","Vector3","fromPointsYMin","fromPointsZMin","fromPointsXMax","fromPointsYMax","fromPointsZMax","fromPointsCurrentPos","fromPointsScratch","fromPointsRitterCenter","fromPointsMinBoxPt","fromPointsMaxBoxPt","fromPointsNaiveCenterScratch","volumeConstant","Math","PI","makeBoundingSphereFromPoints","positions","result","BoundingSphere","length","fromCenterRadius","currentPos","copy","xMin","yMin","zMin","xMax","yMax","zMax","position","x","y","z","xSpan","subtract","magnitudeSquared","ySpan","zSpan","diameter1","diameter2","maxSpan","ritterCenter","radiusSquared","ritterRadius","sqrt","minBoxPt","maxBoxPt","naiveCenter","add","multiplyByScalar","naiveRadius","r","magnitude","oldCenterToPointSquared","oldCenterToPoint","oldToNew","to","center","radius"],"mappings":";;;;;;;;;AAGA;;AACA;;;;;;;;AAGA,IAAMA,cAAc,GAAG,IAAIC,aAAJ,EAAvB;AACA,IAAMC,cAAc,GAAG,IAAID,aAAJ,EAAvB;AACA,IAAME,cAAc,GAAG,IAAIF,aAAJ,EAAvB;AACA,IAAMG,cAAc,GAAG,IAAIH,aAAJ,EAAvB;AACA,IAAMI,cAAc,GAAG,IAAIJ,aAAJ,EAAvB;AACA,IAAMK,cAAc,GAAG,IAAIL,aAAJ,EAAvB;AACA,IAAMM,oBAAoB,GAAG,IAAIN,aAAJ,EAA7B;AACA,IAAMO,iBAAiB,GAAG,IAAIP,aAAJ,EAA1B;AACA,IAAMQ,sBAAsB,GAAG,IAAIR,aAAJ,EAA/B;AACA,IAAMS,kBAAkB,GAAG,IAAIT,aAAJ,EAA3B;AACA,IAAMU,kBAAkB,GAAG,IAAIV,aAAJ,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C;AAC9BT,IAAAA,YAAY,CAACe,EAAb,CAAgBvC,MAAM,CAACwC,MAAvB;AAEAxC,IAAAA,MAAM,CAACyC,MAAP,GAAgBf,YAAhB;AACD,GAJD,MAIO;AACLI,IAAAA,WAAW,CAACS,EAAZ,CAAevC,MAAM,CAACwC,MAAtB;AAEAxC,IAAAA,MAAM,CAACyC,MAAP,GAAgBR,WAAhB;AACD;;AAED,SAAOjC,MAAP;AACD","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\nimport {Vector3} from '@math.gl/core';\nimport BoundingSphere from '../bounding-volumes/bounding-sphere';\n\n/* eslint-disable */\nconst fromPointsXMin = new Vector3();\nconst fromPointsYMin = new Vector3();\nconst fromPointsZMin = new Vector3();\nconst fromPointsXMax = new Vector3();\nconst fromPointsYMax = new Vector3();\nconst fromPointsZMax = new Vector3();\nconst fromPointsCurrentPos = new Vector3();\nconst fromPointsScratch = new Vector3();\nconst fromPointsRitterCenter = new Vector3();\nconst fromPointsMinBoxPt = new Vector3();\nconst fromPointsMaxBoxPt = new Vector3();\nconst fromPointsNaiveCenterScratch = new Vector3();\nconst volumeConstant = (4.0 / 3.0) * Math.PI;\n\nexport default function makeBoundingSphereFromPoints(positions, result = new BoundingSphere()) {\n if (!positions || positions.length === 0) {\n return result.fromCenterRadius([0, 0, 0], 0);\n }\n\n const currentPos = fromPointsCurrentPos.copy(positions[0]);\n\n const xMin = fromPointsXMin.copy(currentPos);\n const yMin = fromPointsYMin.copy(currentPos);\n const zMin = fromPointsZMin.copy(currentPos);\n\n const xMax = fromPointsXMax.copy(currentPos);\n const yMax = fromPointsYMax.copy(currentPos);\n const zMax = fromPointsZMax.copy(currentPos);\n\n for (const position of positions) {\n currentPos.copy(position);\n\n const x = currentPos.x;\n const y = currentPos.y;\n const z = currentPos.z;\n\n // Store points containing the the smallest and largest components\n if (x < xMin.x) {\n currentPos.copy(xMin);\n }\n\n if (x > xMax.x) {\n currentPos.copy(xMax);\n }\n\n if (y < yMin.y) {\n currentPos.copy(yMin);\n }\n\n if (y > yMax.y) {\n currentPos.copy(yMax);\n }\n\n if (z < zMin.z) {\n currentPos.copy(zMin);\n }\n\n if (z > zMax.z) {\n currentPos.copy(zMax);\n }\n }\n\n // Compute x-, y-, and z-spans (Squared distances b/n each component's min. and max.).\n const xSpan = fromPointsScratch.copy(xMax).subtract(xMin).magnitudeSquared();\n const ySpan = fromPointsScratch.copy(yMax).subtract(yMin).magnitudeSquared();\n const zSpan = fromPointsScratch.copy(zMax).subtract(zMin).magnitudeSquared();\n\n // Set the diameter endpoints to the largest span.\n let diameter1 = xMin;\n let diameter2 = xMax;\n let maxSpan = xSpan;\n if (ySpan > maxSpan) {\n maxSpan = ySpan;\n diameter1 = yMin;\n diameter2 = yMax;\n }\n if (zSpan > maxSpan) {\n maxSpan = zSpan;\n diameter1 = zMin;\n diameter2 = zMax;\n }\n\n // Calculate the center of the initial sphere found by Ritter's algorithm\n const ritterCenter = fromPointsRitterCenter;\n ritterCenter.x = (diameter1.x + diameter2.x) * 0.5;\n ritterCenter.y = (diameter1.y + diameter2.y) * 0.5;\n ritterCenter.z = (diameter1.z + diameter2.z) * 0.5;\n\n // Calculate the radius of the initial sphere found by Ritter's algorithm\n let radiusSquared = fromPointsScratch.copy(diameter2).subtract(ritterCenter).magnitudeSquared();\n let ritterRadius = Math.sqrt(radiusSquared);\n\n // Find the center of the sphere found using the Naive method.\n const minBoxPt = fromPointsMinBoxPt;\n minBoxPt.x = xMin.x;\n minBoxPt.y = yMin.y;\n minBoxPt.z = zMin.z;\n\n const maxBoxPt = fromPointsMaxBoxPt;\n maxBoxPt.x = xMax.x;\n maxBoxPt.y = yMax.y;\n maxBoxPt.z = zMax.z;\n\n const naiveCenter = fromPointsNaiveCenterScratch\n .copy(minBoxPt)\n .add(maxBoxPt)\n .multiplyByScalar(0.5);\n\n // Begin 2nd pass to find naive radius and modify the ritter sphere.\n let naiveRadius = 0;\n for (const position of positions) {\n currentPos.copy(position);\n\n // Find the furthest point from the naive center to calculate the naive radius.\n const r = fromPointsScratch.copy(currentPos).subtract(naiveCenter).magnitude();\n if (r > naiveRadius) {\n naiveRadius = r;\n }\n\n // Make adjustments to the Ritter Sphere to include all points.\n const oldCenterToPointSquared = fromPointsScratch\n .copy(currentPos)\n .subtract(ritterCenter)\n .magnitudeSquared();\n\n if (oldCenterToPointSquared > radiusSquared) {\n const oldCenterToPoint = Math.sqrt(oldCenterToPointSquared);\n // Calculate new radius to include the point that lies outside\n ritterRadius = (ritterRadius + oldCenterToPoint) * 0.5;\n radiusSquared = ritterRadius * ritterRadius;\n // Calculate center of new Ritter sphere\n const oldToNew = oldCenterToPoint - ritterRadius;\n ritterCenter.x = (ritterRadius * ritterCenter.x + oldToNew * currentPos.x) / oldCenterToPoint;\n ritterCenter.y = (ritterRadius * ritterCenter.y + oldToNew * currentPos.y) / oldCenterToPoint;\n ritterCenter.z = (ritterRadius * ritterCenter.z + oldToNew * currentPos.z) / oldCenterToPoint;\n }\n }\n\n if (ritterRadius < naiveRadius) {\n ritterCenter.to(result.center);\n // @ts-ignore TS2540: Cannot assign to 'radius' because it is a read-only property.\n result.radius = ritterRadius;\n } else {\n naiveCenter.to(result.center);\n // @ts-ignore TS2540: Cannot assign to 'radius' because it is a read-only property.\n result.radius = naiveRadius;\n }\n\n return result;\n}\n"],"file":"bounding-sphere-from-points.js"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/algorithms/bounding-sphere-from-points.ts"],"names":["fromPointsXMin","Vector3","fromPointsYMin","fromPointsZMin","fromPointsXMax","fromPointsYMax","fromPointsZMax","fromPointsCurrentPos","fromPointsScratch","fromPointsRitterCenter","fromPointsMinBoxPt","fromPointsMaxBoxPt","fromPointsNaiveCenterScratch","volumeConstant","Math","PI","makeBoundingSphereFromPoints","positions","result","BoundingSphere","length","fromCenterRadius","currentPos","copy","xMin","yMin","zMin","xMax","yMax","zMax","position","x","y","z","xSpan","subtract","magnitudeSquared","ySpan","zSpan","diameter1","diameter2","maxSpan","ritterCenter","radiusSquared","ritterRadius","sqrt","minBoxPt","maxBoxPt","naiveCenter","add","multiplyByScalar","naiveRadius","r","magnitude","oldCenterToPointSquared","oldCenterToPoint","oldToNew","to","center","radius"],"mappings":";;;;;;;;;AAGA;;AACA;;AAGA,MAAMA,cAAc,GAAG,IAAIC,aAAJ,EAAvB;AACA,MAAMC,cAAc,GAAG,IAAID,aAAJ,EAAvB;AACA,MAAME,cAAc,GAAG,IAAIF,aAAJ,EAAvB;AACA,MAAMG,cAAc,GAAG,IAAIH,aAAJ,EAAvB;AACA,MAAMI,cAAc,GAAG,IAAIJ,aAAJ,EAAvB;AACA,MAAMK,cAAc,GAAG,IAAIL,aAAJ,EAAvB;AACA,MAAMM,oBAAoB,GAAG,IAAIN,aAAJ,EAA7B;AACA,MAAMO,iBAAiB,GAAG,IAAIP,aAAJ,EAA1B;AACA,MAAMQ,sBAAsB,GAAG,IAAIR,aAAJ,EAA/B;AACA,MAAMS,kBAAkB,GAAG,IAAIT,aAAJ,EAA3B;AACA,MAAMU,kBAAkB,GAAG,IAAIV,aAAJ,EAA3B;AACA,MAAMW,4BAA4B,GAAG,IAAIX,aAAJ,EAArC;AACA,MAAMY,cAAc,GAAI,MAAM,GAAP,GAAcC,IAAI,CAACC,EAA1C;;AAae,SAASC,4BAAT,CACbC,SADa,EAEbC,MAAsB,GAAG,IAAIC,uBAAJ,EAFZ,EAGG;AAChB,MAAI,CAACF,SAAD,IAAcA,SAAS,CAACG,MAAV,KAAqB,CAAvC,EAA0C;AACxC,WAAOF,MAAM,CAACG,gBAAP,CAAwB,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAxB,EAAmC,CAAnC,CAAP;AACD;;AAED,QAAMC,UAAU,GAAGf,oBAAoB,CAACgB,IAArB,CAA0BN,SAAS,CAAC,CAAD,CAAnC,CAAnB;AAEA,QAAMO,IAAI,GAAGxB,cAAc,CAACu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,GAAnD;AACAZ,MAAAA,aAAa,GAAGC,YAAY,GAAGA,YAA/B;AAEA,YAAMY,QAAQ,GAAGD,gBAAgB,GAAGX,YAApC;AACAF,MAAAA,YAAY,CAACX,CAAb,GAAiB,CAACa,YAAY,GAAGF,YAAY,CAACX,CAA5B,GAAgCyB,QAAQ,GAAGlC,UAAU,CAACS,CAAvD,IAA4DwB,gBAA7E;AACAb,MAAAA,YAAY,CAACV,CAAb,GAAiB,CAACY,YAAY,GAAGF,YAAY,CAACV,CAA5B,GAAgCwB,QAAQ,GAAGlC,UAAU,CAACU,CAAvD,IAA4DuB,gBAA7E;AACAb,MAAAA,YAAY,CAACT,CAAb,GAAiB,CAACW,YAAY,GAAGF,YAAY,CAACT,CAA5B,GAAgCuB,QAAQ,GAAGlC,UAAU,CAACW,CAAvD,IAA4DsB,gBAA7E;AACD;AACF;;AAED,MAAIX,YAAY,GAAGO,WAAnB,EAAgC;AAC9BT,IAAAA,YAAY,CAACe,EAAb,CAAgBvC,MAAM,CAACwC,MAAvB;AAEAxC,IAAAA,MAAM,CAACyC,MAAP,GAAgBf,YAAhB;AACD,GAJD,MAIO;AACLI,IAAAA,WAAW,CAACS,EAAZ,CAAevC,MAAM,CAACwC,MAAtB;AAEAxC,IAAAA,MAAM,CAACyC,MAAP,GAAgBR,WAAhB;AACD;;AAED,SAAOjC,MAAP;AACD","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\nimport {Vector3} from '@math.gl/core';\nimport BoundingSphere from '../bounding-volumes/bounding-sphere';\n\n/* eslint-disable */\nconst fromPointsXMin = new Vector3();\nconst fromPointsYMin = new Vector3();\nconst fromPointsZMin = new Vector3();\nconst fromPointsXMax = new Vector3();\nconst fromPointsYMax = new Vector3();\nconst fromPointsZMax = new Vector3();\nconst fromPointsCurrentPos = new Vector3();\nconst fromPointsScratch = new Vector3();\nconst fromPointsRitterCenter = new Vector3();\nconst fromPointsMinBoxPt = new Vector3();\nconst fromPointsMaxBoxPt = new Vector3();\nconst fromPointsNaiveCenterScratch = new Vector3();\nconst volumeConstant = (4.0 / 3.0) * Math.PI;\n\n/**\n * Computes a tight-fitting bounding sphere enclosing a list of 3D Cartesian points.\n *\n * The bounding sphere is computed by running two algorithms, a naive algorithm and\n * Ritter's algorithm. The smaller of the two spheres is used to ensure a tight fit.\n * Bounding sphere computation article http://blogs.agi.com/insight3d/index.php/2008/02/04/a-bounding\n *\n * @param positions An array of points that the bounding sphere will enclose.\n * @param result Optional object onto which to store the result.\n * @returns The modified result parameter or a new `BoundingSphere` instance if not provided.\n */\nexport default function makeBoundingSphereFromPoints(\n positions: number[][],\n result: BoundingSphere = new BoundingSphere()\n): BoundingSphere {\n if (!positions || positions.length === 0) {\n return result.fromCenterRadius([0, 0, 0], 0);\n }\n\n const currentPos = fromPointsCurrentPos.copy(positions[0]);\n\n const xMin = fromPointsXMin.copy(currentPos);\n const yMin = fromPointsYMin.copy(currentPos);\n const zMin = fromPointsZMin.copy(currentPos);\n\n const xMax = fromPointsXMax.copy(currentPos);\n const yMax = fromPointsYMax.copy(currentPos);\n const zMax = fromPointsZMax.copy(currentPos);\n\n for (const position of positions) {\n currentPos.copy(position);\n\n const x = currentPos.x;\n const y = currentPos.y;\n const z = currentPos.z;\n\n // Store points containing the the smallest and largest components\n if (x < xMin.x) {\n xMin.copy(currentPos);\n }\n\n if (x > xMax.x) {\n xMax.copy(currentPos);\n }\n\n if (y < yMin.y) {\n yMin.copy(currentPos);\n }\n\n if (y > yMax.y) {\n yMax.copy(currentPos);\n }\n\n if (z < zMin.z) {\n zMin.copy(currentPos);\n }\n\n if (z > zMax.z) {\n zMax.copy(currentPos);\n }\n }\n\n // Compute x-, y-, and z-spans (Squared distances b/n each component's min. and max.).\n const xSpan = fromPointsScratch.copy(xMax).subtract(xMin).magnitudeSquared();\n const ySpan = fromPointsScratch.copy(yMax).subtract(yMin).magnitudeSquared();\n const zSpan = fromPointsScratch.copy(zMax).subtract(zMin).magnitudeSquared();\n\n // Set the diameter endpoints to the largest span.\n let diameter1 = xMin;\n let diameter2 = xMax;\n let maxSpan = xSpan;\n if (ySpan > maxSpan) {\n maxSpan = ySpan;\n diameter1 = yMin;\n diameter2 = yMax;\n }\n if (zSpan > maxSpan) {\n maxSpan = zSpan;\n diameter1 = zMin;\n diameter2 = zMax;\n }\n\n // Calculate the center of the initial sphere found by Ritter's algorithm\n const ritterCenter = fromPointsRitterCenter;\n ritterCenter.x = (diameter1.x + diameter2.x) * 0.5;\n ritterCenter.y = (diameter1.y + diameter2.y) * 0.5;\n ritterCenter.z = (diameter1.z + diameter2.z) * 0.5;\n\n // Calculate the radius of the initial sphere found by Ritter's algorithm\n let radiusSquared = fromPointsScratch.copy(diameter2).subtract(ritterCenter).magnitudeSquared();\n let ritterRadius = Math.sqrt(radiusSquared);\n\n // Find the center of the sphere found using the Naive method.\n const minBoxPt = fromPointsMinBoxPt;\n minBoxPt.x = xMin.x;\n minBoxPt.y = yMin.y;\n minBoxPt.z = zMin.z;\n\n const maxBoxPt = fromPointsMaxBoxPt;\n maxBoxPt.x = xMax.x;\n maxBoxPt.y = yMax.y;\n maxBoxPt.z = zMax.z;\n\n const naiveCenter = fromPointsNaiveCenterScratch\n .copy(minBoxPt)\n .add(maxBoxPt)\n .multiplyByScalar(0.5);\n\n // Begin 2nd pass to find naive radius and modify the ritter sphere.\n let naiveRadius = 0;\n for (const position of positions) {\n currentPos.copy(position);\n\n // Find the furthest point from the naive center to calculate the naive radius.\n const r = fromPointsScratch.copy(currentPos).subtract(naiveCenter).magnitude();\n if (r > naiveRadius) {\n naiveRadius = r;\n }\n\n // Make adjustments to the Ritter Sphere to include all points.\n const oldCenterToPointSquared = fromPointsScratch\n .copy(currentPos)\n .subtract(ritterCenter)\n .magnitudeSquared();\n\n if (oldCenterToPointSquared > radiusSquared) {\n const oldCenterToPoint = Math.sqrt(oldCenterToPointSquared);\n // Calculate new radius to include the point that lies outside\n ritterRadius = (ritterRadius + oldCenterToPoint) * 0.5;\n radiusSquared = ritterRadius * ritterRadius;\n // Calculate center of new Ritter sphere\n const oldToNew = oldCenterToPoint - ritterRadius;\n ritterCenter.x = (ritterRadius * ritterCenter.x + oldToNew * currentPos.x) / oldCenterToPoint;\n ritterCenter.y = (ritterRadius * ritterCenter.y + oldToNew * currentPos.y) / oldCenterToPoint;\n ritterCenter.z = (ritterRadius * ritterCenter.z + oldToNew * currentPos.z) / oldCenterToPoint;\n }\n }\n\n if (ritterRadius < naiveRadius) {\n ritterCenter.to(result.center);\n // @ts-ignore TS2540: Cannot assign to 'radius' because it is a read-only property.\n result.radius = ritterRadius;\n } else {\n naiveCenter.to(result.center);\n // @ts-ignore TS2540: Cannot assign to 'radius' because it is a read-only property.\n result.radius = naiveRadius;\n }\n\n return result;\n}\n"],"file":"bounding-sphere-from-points.js"}
|
|
@@ -7,23 +7,22 @@ exports.default = computeEigenDecomposition;
|
|
|
7
7
|
|
|
8
8
|
var _core = require("@math.gl/core");
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
function computeEigenDecomposition(matrix) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
var diagonalMatrix = scratchDiagonal;
|
|
10
|
+
const scratchMatrix = new _core.Matrix3();
|
|
11
|
+
const scratchUnitary = new _core.Matrix3();
|
|
12
|
+
const scratchDiagonal = new _core.Matrix3();
|
|
13
|
+
const jMatrix = new _core.Matrix3();
|
|
14
|
+
const jMatrixTranspose = new _core.Matrix3();
|
|
15
|
+
|
|
16
|
+
function computeEigenDecomposition(matrix, result = {}) {
|
|
17
|
+
const EIGEN_TOLERANCE = _core._MathUtils.EPSILON20;
|
|
18
|
+
const EIGEN_MAX_SWEEPS = 10;
|
|
19
|
+
let count = 0;
|
|
20
|
+
let sweep = 0;
|
|
21
|
+
const unitaryMatrix = scratchUnitary;
|
|
22
|
+
const diagonalMatrix = scratchDiagonal;
|
|
24
23
|
unitaryMatrix.identity();
|
|
25
24
|
diagonalMatrix.copy(matrix);
|
|
26
|
-
|
|
25
|
+
const epsilon = EIGEN_TOLERANCE * computeFrobeniusNorm(diagonalMatrix);
|
|
27
26
|
|
|
28
27
|
while (sweep < EIGEN_MAX_SWEEPS && offDiagonalFrobeniusNorm(diagonalMatrix) > epsilon) {
|
|
29
28
|
shurDecomposition(diagonalMatrix, jMatrix);
|
|
@@ -44,24 +43,24 @@ function computeEigenDecomposition(matrix) {
|
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
function computeFrobeniusNorm(matrix) {
|
|
47
|
-
|
|
46
|
+
let norm = 0.0;
|
|
48
47
|
|
|
49
|
-
for (
|
|
50
|
-
|
|
48
|
+
for (let i = 0; i < 9; ++i) {
|
|
49
|
+
const temp = matrix[i];
|
|
51
50
|
norm += temp * temp;
|
|
52
51
|
}
|
|
53
52
|
|
|
54
53
|
return Math.sqrt(norm);
|
|
55
54
|
}
|
|
56
55
|
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
const rowVal = [1, 0, 0];
|
|
57
|
+
const colVal = [2, 2, 1];
|
|
59
58
|
|
|
60
59
|
function offDiagonalFrobeniusNorm(matrix) {
|
|
61
|
-
|
|
60
|
+
let norm = 0.0;
|
|
62
61
|
|
|
63
|
-
for (
|
|
64
|
-
|
|
62
|
+
for (let i = 0; i < 3; ++i) {
|
|
63
|
+
const temp = matrix[scratchMatrix.getElementIndex(colVal[i], rowVal[i])];
|
|
65
64
|
norm += 2.0 * temp * temp;
|
|
66
65
|
}
|
|
67
66
|
|
|
@@ -69,12 +68,12 @@ function offDiagonalFrobeniusNorm(matrix) {
|
|
|
69
68
|
}
|
|
70
69
|
|
|
71
70
|
function shurDecomposition(matrix, result) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
const tolerance = _core._MathUtils.EPSILON15;
|
|
72
|
+
let maxDiagonal = 0.0;
|
|
73
|
+
let rotAxis = 1;
|
|
75
74
|
|
|
76
|
-
for (
|
|
77
|
-
|
|
75
|
+
for (let i = 0; i < 3; ++i) {
|
|
76
|
+
const temp = Math.abs(matrix[scratchMatrix.getElementIndex(colVal[i], rowVal[i])]);
|
|
78
77
|
|
|
79
78
|
if (temp > maxDiagonal) {
|
|
80
79
|
rotAxis = i;
|
|
@@ -82,17 +81,17 @@ function shurDecomposition(matrix, result) {
|
|
|
82
81
|
}
|
|
83
82
|
}
|
|
84
83
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
84
|
+
const p = rowVal[rotAxis];
|
|
85
|
+
const q = colVal[rotAxis];
|
|
86
|
+
let c = 1.0;
|
|
87
|
+
let s = 0.0;
|
|
89
88
|
|
|
90
89
|
if (Math.abs(matrix[scratchMatrix.getElementIndex(q, p)]) > tolerance) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
90
|
+
const qq = matrix[scratchMatrix.getElementIndex(q, q)];
|
|
91
|
+
const pp = matrix[scratchMatrix.getElementIndex(p, p)];
|
|
92
|
+
const qp = matrix[scratchMatrix.getElementIndex(q, p)];
|
|
93
|
+
const tau = (qq - pp) / 2.0 / qp;
|
|
94
|
+
let t;
|
|
96
95
|
|
|
97
96
|
if (tau < 0.0) {
|
|
98
97
|
t = -1.0 / (-tau + Math.sqrt(1.0 + tau * tau));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/algorithms/compute-eigen-decomposition.
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/algorithms/compute-eigen-decomposition.ts"],"names":["scratchMatrix","Matrix3","scratchUnitary","scratchDiagonal","jMatrix","jMatrixTranspose","computeEigenDecomposition","matrix","result","EIGEN_TOLERANCE","_MathUtils","EPSILON20","EIGEN_MAX_SWEEPS","count","sweep","unitaryMatrix","diagonalMatrix","identity","copy","epsilon","computeFrobeniusNorm","offDiagonalFrobeniusNorm","shurDecomposition","transpose","multiplyRight","multiplyLeft","unitary","toTarget","diagonal","norm","i","temp","Math","sqrt","rowVal","colVal","getElementIndex","tolerance","EPSILON15","maxDiagonal","rotAxis","abs","p","q","c","s","qq","pp","qp","tau","t","IDENTITY","to"],"mappings":";;;;;;;AAGA;;AAEA,MAAMA,aAAa,GAAG,IAAIC,aAAJ,EAAtB;AACA,MAAMC,cAAc,GAAG,IAAID,aAAJ,EAAvB;AACA,MAAME,eAAe,GAAG,IAAIF,aAAJ,EAAxB;AAEA,MAAMG,OAAO,GAAG,IAAIH,aAAJ,EAAhB;AACA,MAAMI,gBAAgB,GAAG,IAAIJ,aAAJ,EAAzB;;AAqCe,SAASK,yBAAT,CACbC,MADa,EAGbC,MAA0B,GAAG,EAHhB,EAIO;AACpB,QAAMC,eAAe,GAAGC,iBAAWC,SAAnC;AACA,QAAMC,gBAAgB,GAAG,EAAzB;AAEA,MAAIC,KAAK,GAAG,CAAZ;AACA,MAAIC,KAAK,GAAG,CAAZ;AAEA,QAAMC,aAAa,GAAGb,cAAtB;AACA,QAAMc,cAAc,GAAGb,eAAvB;AAEAY,EAAAA,aAAa,CAACE,QAAd;AACAD,EAAAA,cAAc,CAACE,IAAf,CAAoBX,MAApB;AAEA,QAAMY,OAAO,GAAGV,eAAe,GAAGW,oBAAoB,CAACJ,cAAD,CAAtD;;AAEA,SAAOF,KAAK,GAAGF,gBAAR,IAA4BS,wBAAwB,CAACL,cAAD,CAAxB,GAA2CG,OAA9E,EAAuF;AACrFG,IAAAA,iBAAiB,CAACN,cAAD,EAAiBZ,OAAjB,CAAjB;AAEAC,IAAAA,gBAAgB,CAACa,IAAjB,CAAsBd,OAAtB,EAA+BmB,SAA/B;AAEAP,IAAAA,cAAc,CAACQ,aAAf,CAA6BpB,OAA7B;AACAY,IAAAA,cAAc,CAACS,YAAf,CAA4BpB,gBAA5B;AACAU,IAAAA,aAAa,CAACS,aAAd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9B;AACA,QAAIE,CAAJ;;AAEA,QAAID,GAAG,GAAG,GAAV,EAAe;AACbC,MAAAA,CAAC,GAAG,CAAC,GAAD,IAAQ,CAACD,GAAD,GAAOjB,IAAI,CAACC,IAAL,CAAU,MAAMgB,GAAG,GAAGA,GAAtB,CAAf,CAAJ;AACD,KAFD,MAEO;AACLC,MAAAA,CAAC,GAAG,OAAOD,GAAG,GAAGjB,IAAI,CAACC,IAAL,CAAU,MAAMgB,GAAG,GAAGA,GAAtB,CAAb,CAAJ;AACD;;AAEDL,IAAAA,CAAC,GAAG,MAAMZ,IAAI,CAACC,IAAL,CAAU,MAAMiB,CAAC,GAAGA,CAApB,CAAV;AACAL,IAAAA,CAAC,GAAGK,CAAC,GAAGN,CAAR;AACD;;AAGD3C,gBAAQkD,QAAR,CAAiBC,EAAjB,CAAoB5C,MAApB;;AACAA,EAAAA,MAAM,CAACR,aAAa,CAACoC,eAAd,CAA8BM,CAA9B,EAAiCA,CAAjC,CAAD,CAAN,GAA8ClC,MAAM,CAACR,aAAa,CAACoC,eAAd,CAA8BO,CAA9B,EAAiCA,CAAjC,CAAD,CAAN,GAA8CC,CAA5F;AACApC,EAAAA,MAAM,CAACR,aAAa,CAACoC,eAAd,CAA8BO,CAA9B,EAAiCD,CAAjC,CAAD,CAAN,GAA8CG,CAA9C;AACArC,EAAAA,MAAM,CAACR,aAAa,CAACoC,eAAd,CAA8BM,CAA9B,EAAiCC,CAAjC,CAAD,CAAN,GAA8C,CAACE,CAA/C;AAEA,SAAOrC,MAAP;AACD","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\nimport {Matrix3, _MathUtils} from '@math.gl/core';\n\nconst scratchMatrix = new Matrix3();\nconst scratchUnitary = new Matrix3();\nconst scratchDiagonal = new Matrix3();\n\nconst jMatrix = new Matrix3();\nconst jMatrixTranspose = new Matrix3();\n\nexport type EigenDecomposition = {\n unitary: Matrix3;\n diagonal: Matrix3;\n};\n\n/**\n * Computes the eigenvectors and eigenvalues of a symmetric matrix.\n *\n * - Returns a diagonal matrix and unitary matrix such that:\n * `matrix = unitary matrix * diagonal matrix * transpose(unitary matrix)`\n * - The values along the diagonal of the diagonal matrix are the eigenvalues. The columns\n * of the unitary matrix are the corresponding eigenvectors.\n * - This routine was created based upon Matrix Computations, 3rd ed., by Golub and Van Loan,\n * section 8.4.3 The Classical Jacobi Algorithm\n *\n * @param matrix The 3x3 matrix to decompose into diagonal and unitary matrix. Expected to be symmetric.\n * @param result Optional object with unitary and diagonal properties which are matrices onto which to store the result.\n * @returns An object with unitary and diagonal properties which are the unitary and diagonal matrices, respectively.\n *\n * @example\n * const a = //... symmetric matrix\n * const result = {\n * unitary : new Matrix3(),\n * diagonal : new Matrix3()\n * };\n * computeEigenDecomposition(a, result);\n *\n * const unitaryTranspose = Matrix3.transpose(result.unitary, new Matrix3());\n * const b = Matrix3.multiply(result.unitary, result.diagonal, new Matrix3());\n * Matrix3.multiply(b, unitaryTranspose, b); // b is now equal to a\n *\n * const lambda = result.diagonal.getColumn(0, new Vector3()).x; // first eigenvalue\n * const v = result.unitary.getColumn(0, new Vector3()); // first eigenvector\n * const c = v.multiplyByScalar(lambda); // equal to v.transformByMatrix3(a)\n */\nexport default function computeEigenDecomposition(\n matrix: number[],\n // @ts-expect-error accept empty object type\n result: EigenDecomposition = {}\n): EigenDecomposition {\n const EIGEN_TOLERANCE = _MathUtils.EPSILON20;\n const EIGEN_MAX_SWEEPS = 10;\n\n let count = 0;\n let sweep = 0;\n\n const unitaryMatrix = scratchUnitary;\n const diagonalMatrix = scratchDiagonal;\n\n unitaryMatrix.identity();\n diagonalMatrix.copy(matrix);\n\n const epsilon = EIGEN_TOLERANCE * computeFrobeniusNorm(diagonalMatrix);\n\n while (sweep < EIGEN_MAX_SWEEPS && offDiagonalFrobeniusNorm(diagonalMatrix) > epsilon) {\n shurDecomposition(diagonalMatrix, jMatrix);\n\n jMatrixTranspose.copy(jMatrix).transpose();\n\n diagonalMatrix.multiplyRight(jMatrix);\n diagonalMatrix.multiplyLeft(jMatrixTranspose);\n unitaryMatrix.multiplyRight(jMatrix);\n\n if (++count > 2) {\n ++sweep;\n count = 0;\n }\n }\n\n result.unitary = unitaryMatrix.toTarget(result.unitary);\n result.diagonal = diagonalMatrix.toTarget(result.diagonal);\n\n return result;\n}\n\nfunction computeFrobeniusNorm(matrix) {\n let norm = 0.0;\n for (let i = 0; i < 9; ++i) {\n const temp = matrix[i];\n norm += temp * temp;\n }\n return Math.sqrt(norm);\n}\n\nconst rowVal = [1, 0, 0];\nconst colVal = [2, 2, 1];\n\n// Computes the \"off-diagonal\" Frobenius norm.\n// Assumes matrix is symmetric.\nfunction offDiagonalFrobeniusNorm(matrix) {\n let norm = 0.0;\n for (let i = 0; i < 3; ++i) {\n const temp = matrix[scratchMatrix.getElementIndex(colVal[i], rowVal[i])];\n norm += 2.0 * temp * temp;\n }\n return Math.sqrt(norm);\n}\n\n// The routine takes a matrix, which is assumed to be symmetric, and\n// finds the largest off-diagonal term, and then creates\n// a matrix (result) which can be used to help reduce it\n//\n// This routine was created based upon Matrix Computations, 3rd ed., by Golub and Van Loan,\n// section 8.4.2 The 2by2 Symmetric Schur Decomposition.\n//\n// eslint-disable-next-line max-statements\nfunction shurDecomposition(matrix, result) {\n const tolerance = _MathUtils.EPSILON15;\n\n let maxDiagonal = 0.0;\n let rotAxis = 1;\n\n // find pivot (rotAxis) based on max diagonal of matrix\n for (let i = 0; i < 3; ++i) {\n const temp = Math.abs(matrix[scratchMatrix.getElementIndex(colVal[i], rowVal[i])]);\n if (temp > maxDiagonal) {\n rotAxis = i;\n maxDiagonal = temp;\n }\n }\n\n const p = rowVal[rotAxis];\n const q = colVal[rotAxis];\n\n let c = 1.0;\n let s = 0.0;\n\n if (Math.abs(matrix[scratchMatrix.getElementIndex(q, p)]) > tolerance) {\n const qq = matrix[scratchMatrix.getElementIndex(q, q)];\n const pp = matrix[scratchMatrix.getElementIndex(p, p)];\n const qp = matrix[scratchMatrix.getElementIndex(q, p)];\n\n const tau = (qq - pp) / 2.0 / qp;\n let t;\n\n if (tau < 0.0) {\n t = -1.0 / (-tau + Math.sqrt(1.0 + tau * tau));\n } else {\n t = 1.0 / (tau + Math.sqrt(1.0 + tau * tau));\n }\n\n c = 1.0 / Math.sqrt(1.0 + t * t);\n s = t * c;\n }\n\n // Copy into result\n Matrix3.IDENTITY.to(result);\n result[scratchMatrix.getElementIndex(p, p)] = result[scratchMatrix.getElementIndex(q, q)] = c;\n result[scratchMatrix.getElementIndex(q, p)] = s;\n result[scratchMatrix.getElementIndex(p, q)] = -s;\n\n return result;\n}\n"],"file":"compute-eigen-decomposition.js"}
|
|
@@ -7,23 +7,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.default = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
11
|
|
|
14
12
|
var _core = require("@math.gl/core");
|
|
15
13
|
|
|
16
14
|
var _constants = require("../../constants");
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
const scratchVector = new _core.Vector3();
|
|
17
|
+
const scratchNormal = new _core.Vector3();
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
(0,
|
|
19
|
+
class AxisAlignedBoundingBox {
|
|
20
|
+
constructor(minimum = [0, 0, 0], maximum = [0, 0, 0], center) {
|
|
21
|
+
(0, _defineProperty2.default)(this, "center", void 0);
|
|
22
|
+
(0, _defineProperty2.default)(this, "halfDiagonal", void 0);
|
|
23
|
+
(0, _defineProperty2.default)(this, "minimum", void 0);
|
|
24
|
+
(0, _defineProperty2.default)(this, "maximum", void 0);
|
|
27
25
|
center = center || scratchVector.copy(minimum).add(maximum).scale(0.5);
|
|
28
26
|
this.center = new _core.Vector3(center);
|
|
29
27
|
this.halfDiagonal = new _core.Vector3(maximum).subtract(this.center);
|
|
@@ -31,78 +29,74 @@ var AxisAlignedBoundingBox = function () {
|
|
|
31
29
|
this.maximum = new _core.Vector3(maximum);
|
|
32
30
|
}
|
|
33
31
|
|
|
34
|
-
(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (s - e > 0) {
|
|
62
|
-
return _constants.INTERSECTION.INSIDE;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (s + e < 0) {
|
|
66
|
-
return _constants.INTERSECTION.OUTSIDE;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return _constants.INTERSECTION.INTERSECTING;
|
|
32
|
+
clone() {
|
|
33
|
+
return new AxisAlignedBoundingBox(this.minimum, this.maximum, this.center);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
equals(right) {
|
|
37
|
+
return this === right || Boolean(right) && this.minimum.equals(right.minimum) && this.maximum.equals(right.maximum);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
transform(transform) {
|
|
41
|
+
this.center.transformAsPoint(transform);
|
|
42
|
+
this.halfDiagonal.transform(transform);
|
|
43
|
+
this.minimum.transform(transform);
|
|
44
|
+
this.maximum.transform(transform);
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
intersectPlane(plane) {
|
|
49
|
+
const {
|
|
50
|
+
halfDiagonal
|
|
51
|
+
} = this;
|
|
52
|
+
const normal = scratchNormal.from(plane.normal);
|
|
53
|
+
const e = halfDiagonal.x * Math.abs(normal.x) + halfDiagonal.y * Math.abs(normal.y) + halfDiagonal.z * Math.abs(normal.z);
|
|
54
|
+
const s = this.center.dot(normal) + plane.distance;
|
|
55
|
+
|
|
56
|
+
if (s - e > 0) {
|
|
57
|
+
return _constants.INTERSECTION.INSIDE;
|
|
70
58
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return Math.sqrt(this.distanceSquaredTo(point));
|
|
59
|
+
|
|
60
|
+
if (s + e < 0) {
|
|
61
|
+
return _constants.INTERSECTION.OUTSIDE;
|
|
75
62
|
}
|
|
76
|
-
}, {
|
|
77
|
-
key: "distanceSquaredTo",
|
|
78
|
-
value: function distanceSquaredTo(point) {
|
|
79
|
-
var offset = scratchVector.from(point).subtract(this.center);
|
|
80
|
-
var halfDiagonal = this.halfDiagonal;
|
|
81
|
-
var distanceSquared = 0.0;
|
|
82
|
-
var d;
|
|
83
|
-
d = Math.abs(offset.x) - halfDiagonal.x;
|
|
84
63
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
64
|
+
return _constants.INTERSECTION.INTERSECTING;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
distanceTo(point) {
|
|
68
|
+
return Math.sqrt(this.distanceSquaredTo(point));
|
|
69
|
+
}
|
|
88
70
|
|
|
89
|
-
|
|
71
|
+
distanceSquaredTo(point) {
|
|
72
|
+
const offset = scratchVector.from(point).subtract(this.center);
|
|
73
|
+
const {
|
|
74
|
+
halfDiagonal
|
|
75
|
+
} = this;
|
|
76
|
+
let distanceSquared = 0.0;
|
|
77
|
+
let d;
|
|
78
|
+
d = Math.abs(offset.x) - halfDiagonal.x;
|
|
79
|
+
|
|
80
|
+
if (d > 0) {
|
|
81
|
+
distanceSquared += d * d;
|
|
82
|
+
}
|
|
90
83
|
|
|
91
|
-
|
|
92
|
-
distanceSquared += d * d;
|
|
93
|
-
}
|
|
84
|
+
d = Math.abs(offset.y) - halfDiagonal.y;
|
|
94
85
|
|
|
95
|
-
|
|
86
|
+
if (d > 0) {
|
|
87
|
+
distanceSquared += d * d;
|
|
88
|
+
}
|
|
96
89
|
|
|
97
|
-
|
|
98
|
-
distanceSquared += d * d;
|
|
99
|
-
}
|
|
90
|
+
d = Math.abs(offset.z) - halfDiagonal.z;
|
|
100
91
|
|
|
101
|
-
|
|
92
|
+
if (d > 0) {
|
|
93
|
+
distanceSquared += d * d;
|
|
102
94
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
95
|
+
|
|
96
|
+
return distanceSquared;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
}
|
|
106
100
|
|
|
107
101
|
exports.default = AxisAlignedBoundingBox;
|
|
108
102
|
//# sourceMappingURL=axis-aligned-bounding-box.js.map
|