@math.gl/culling 3.6.0-alpha.1 → 3.6.0-alpha.2
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/es5/constants.js +1 -1
- package/dist/es5/index.js +12 -12
- package/dist/es5/lib/algorithms/bounding-box-from-points.js +123 -72
- package/dist/es5/lib/algorithms/bounding-box-from-points.js.map +1 -1
- package/dist/es5/lib/algorithms/bounding-sphere-from-points.js +109 -81
- package/dist/es5/lib/algorithms/bounding-sphere-from-points.js.map +1 -1
- package/dist/es5/lib/algorithms/compute-eigen-decomposition.js +37 -36
- package/dist/es5/lib/algorithms/compute-eigen-decomposition.js.map +1 -1
- package/dist/es5/lib/bounding-volumes/axis-aligned-bounding-box.js +75 -63
- package/dist/es5/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -1
- package/dist/es5/lib/bounding-volumes/bounding-sphere.js +111 -90
- package/dist/es5/lib/bounding-volumes/bounding-sphere.js.map +1 -1
- package/dist/es5/lib/bounding-volumes/oriented-bounding-box.js +212 -187
- package/dist/es5/lib/bounding-volumes/oriented-bounding-box.js.map +1 -1
- package/dist/es5/lib/culling-volume.js +111 -74
- package/dist/es5/lib/culling-volume.js.map +1 -1
- package/dist/es5/lib/perspective-frustum.js +78 -57
- package/dist/es5/lib/perspective-frustum.js.map +1 -1
- package/dist/es5/lib/perspective-off-center-frustum.js +113 -98
- package/dist/es5/lib/perspective-off-center-frustum.js.map +1 -1
- package/dist/es5/lib/plane.js +70 -52
- package/dist/es5/lib/plane.js.map +1 -1
- package/dist/esm/lib/algorithms/bounding-sphere-from-points.js.map +1 -1
- package/dist/lib/algorithms/bounding-sphere-from-points.d.ts.map +1 -1
- package/dist/lib/algorithms/bounding-sphere-from-points.js +0 -2
- package/package.json +4 -4
- package/src/lib/algorithms/bounding-sphere-from-points.ts +0 -2
package/dist/es5/constants.js
CHANGED
package/dist/es5/index.js
CHANGED
|
@@ -7,73 +7,73 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
Object.defineProperty(exports, "INTERSECTION", {
|
|
9
9
|
enumerable: true,
|
|
10
|
-
get: function () {
|
|
10
|
+
get: function get() {
|
|
11
11
|
return _constants.INTERSECTION;
|
|
12
12
|
}
|
|
13
13
|
});
|
|
14
14
|
Object.defineProperty(exports, "AxisAlignedBoundingBox", {
|
|
15
15
|
enumerable: true,
|
|
16
|
-
get: function () {
|
|
16
|
+
get: function get() {
|
|
17
17
|
return _axisAlignedBoundingBox.default;
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
20
|
Object.defineProperty(exports, "BoundingSphere", {
|
|
21
21
|
enumerable: true,
|
|
22
|
-
get: function () {
|
|
22
|
+
get: function get() {
|
|
23
23
|
return _boundingSphere.default;
|
|
24
24
|
}
|
|
25
25
|
});
|
|
26
26
|
Object.defineProperty(exports, "OrientedBoundingBox", {
|
|
27
27
|
enumerable: true,
|
|
28
|
-
get: function () {
|
|
28
|
+
get: function get() {
|
|
29
29
|
return _orientedBoundingBox.default;
|
|
30
30
|
}
|
|
31
31
|
});
|
|
32
32
|
Object.defineProperty(exports, "CullingVolume", {
|
|
33
33
|
enumerable: true,
|
|
34
|
-
get: function () {
|
|
34
|
+
get: function get() {
|
|
35
35
|
return _cullingVolume.default;
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
38
|
Object.defineProperty(exports, "Plane", {
|
|
39
39
|
enumerable: true,
|
|
40
|
-
get: function () {
|
|
40
|
+
get: function get() {
|
|
41
41
|
return _plane.default;
|
|
42
42
|
}
|
|
43
43
|
});
|
|
44
44
|
Object.defineProperty(exports, "_PerspectiveOffCenterFrustum", {
|
|
45
45
|
enumerable: true,
|
|
46
|
-
get: function () {
|
|
46
|
+
get: function get() {
|
|
47
47
|
return _perspectiveOffCenterFrustum.default;
|
|
48
48
|
}
|
|
49
49
|
});
|
|
50
50
|
Object.defineProperty(exports, "_PerspectiveFrustum", {
|
|
51
51
|
enumerable: true,
|
|
52
|
-
get: function () {
|
|
52
|
+
get: function get() {
|
|
53
53
|
return _perspectiveFrustum.default;
|
|
54
54
|
}
|
|
55
55
|
});
|
|
56
56
|
Object.defineProperty(exports, "makeBoundingSphereFromPoints", {
|
|
57
57
|
enumerable: true,
|
|
58
|
-
get: function () {
|
|
58
|
+
get: function get() {
|
|
59
59
|
return _boundingSphereFromPoints.default;
|
|
60
60
|
}
|
|
61
61
|
});
|
|
62
62
|
Object.defineProperty(exports, "makeAxisAlignedBoundingBoxFromPoints", {
|
|
63
63
|
enumerable: true,
|
|
64
|
-
get: function () {
|
|
64
|
+
get: function get() {
|
|
65
65
|
return _boundingBoxFromPoints.makeAxisAlignedBoundingBoxFromPoints;
|
|
66
66
|
}
|
|
67
67
|
});
|
|
68
68
|
Object.defineProperty(exports, "makeOrientedBoundingBoxFromPoints", {
|
|
69
69
|
enumerable: true,
|
|
70
|
-
get: function () {
|
|
70
|
+
get: function get() {
|
|
71
71
|
return _boundingBoxFromPoints.makeOrientedBoundingBoxFromPoints;
|
|
72
72
|
}
|
|
73
73
|
});
|
|
74
74
|
Object.defineProperty(exports, "computeEigenDecomposition", {
|
|
75
75
|
enumerable: true,
|
|
76
|
-
get: function () {
|
|
76
|
+
get: function get() {
|
|
77
77
|
return _computeEigenDecomposition.default;
|
|
78
78
|
}
|
|
79
79
|
});
|
|
@@ -16,48 +16,76 @@ var _orientedBoundingBox = _interopRequireDefault(require("../bounding-volumes/o
|
|
|
16
16
|
|
|
17
17
|
var _axisAlignedBoundingBox = _interopRequireDefault(require("../bounding-volumes/axis-aligned-bounding-box"));
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
20
|
+
|
|
21
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
22
|
+
|
|
23
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
24
|
+
|
|
25
|
+
var scratchVector2 = new _core.Vector3();
|
|
26
|
+
var scratchVector3 = new _core.Vector3();
|
|
27
|
+
var scratchVector4 = new _core.Vector3();
|
|
28
|
+
var scratchVector5 = new _core.Vector3();
|
|
29
|
+
var scratchVector6 = new _core.Vector3();
|
|
30
|
+
var scratchCovarianceResult = new _core.Matrix3();
|
|
31
|
+
var scratchEigenResult = {
|
|
26
32
|
diagonal: new _core.Matrix3(),
|
|
27
33
|
unitary: new _core.Matrix3()
|
|
28
34
|
};
|
|
29
35
|
|
|
30
|
-
function makeOrientedBoundingBoxFromPoints(positions
|
|
36
|
+
function makeOrientedBoundingBoxFromPoints(positions) {
|
|
37
|
+
var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new _orientedBoundingBox.default();
|
|
38
|
+
|
|
31
39
|
if (!positions || positions.length === 0) {
|
|
32
40
|
result.halfAxes = new _core.Matrix3([0, 0, 0, 0, 0, 0, 0, 0, 0]);
|
|
33
41
|
result.center = new _core.Vector3();
|
|
34
42
|
return result;
|
|
35
43
|
}
|
|
36
44
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
var length = positions.length;
|
|
46
|
+
var meanPoint = new _core.Vector3(0, 0, 0);
|
|
47
|
+
|
|
48
|
+
var _iterator = _createForOfIteratorHelper(positions),
|
|
49
|
+
_step;
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
53
|
+
var position = _step.value;
|
|
54
|
+
meanPoint.add(position);
|
|
55
|
+
}
|
|
56
|
+
} catch (err) {
|
|
57
|
+
_iterator.e(err);
|
|
58
|
+
} finally {
|
|
59
|
+
_iterator.f();
|
|
42
60
|
}
|
|
43
61
|
|
|
44
|
-
|
|
62
|
+
var invLength = 1.0 / length;
|
|
45
63
|
meanPoint.multiplyByScalar(invLength);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
64
|
+
var exx = 0.0;
|
|
65
|
+
var exy = 0.0;
|
|
66
|
+
var exz = 0.0;
|
|
67
|
+
var eyy = 0.0;
|
|
68
|
+
var eyz = 0.0;
|
|
69
|
+
var ezz = 0.0;
|
|
70
|
+
|
|
71
|
+
var _iterator2 = _createForOfIteratorHelper(positions),
|
|
72
|
+
_step2;
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
76
|
+
var _position = _step2.value;
|
|
77
|
+
var p = scratchVector2.copy(_position).subtract(meanPoint);
|
|
78
|
+
exx += p.x * p.x;
|
|
79
|
+
exy += p.x * p.y;
|
|
80
|
+
exz += p.x * p.z;
|
|
81
|
+
eyy += p.y * p.y;
|
|
82
|
+
eyz += p.y * p.z;
|
|
83
|
+
ezz += p.z * p.z;
|
|
84
|
+
}
|
|
85
|
+
} catch (err) {
|
|
86
|
+
_iterator2.e(err);
|
|
87
|
+
} finally {
|
|
88
|
+
_iterator2.f();
|
|
61
89
|
}
|
|
62
90
|
|
|
63
91
|
exx *= invLength;
|
|
@@ -66,7 +94,7 @@ function makeOrientedBoundingBoxFromPoints(positions, result = new _orientedBoun
|
|
|
66
94
|
eyy *= invLength;
|
|
67
95
|
eyz *= invLength;
|
|
68
96
|
ezz *= invLength;
|
|
69
|
-
|
|
97
|
+
var covarianceMatrix = scratchCovarianceResult;
|
|
70
98
|
covarianceMatrix[0] = exx;
|
|
71
99
|
covarianceMatrix[1] = exy;
|
|
72
100
|
covarianceMatrix[2] = exz;
|
|
@@ -76,41 +104,54 @@ function makeOrientedBoundingBoxFromPoints(positions, result = new _orientedBoun
|
|
|
76
104
|
covarianceMatrix[6] = exz;
|
|
77
105
|
covarianceMatrix[7] = eyz;
|
|
78
106
|
covarianceMatrix[8] = ezz;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
107
|
+
|
|
108
|
+
var _computeEigenDecompos = (0, _computeEigenDecomposition.default)(covarianceMatrix, scratchEigenResult),
|
|
109
|
+
unitary = _computeEigenDecompos.unitary;
|
|
110
|
+
|
|
111
|
+
var rotation = result.halfAxes.copy(unitary);
|
|
112
|
+
var v1 = rotation.getColumn(0, scratchVector4);
|
|
113
|
+
var v2 = rotation.getColumn(1, scratchVector5);
|
|
114
|
+
var v3 = rotation.getColumn(2, scratchVector6);
|
|
115
|
+
var u1 = -Number.MAX_VALUE;
|
|
116
|
+
var u2 = -Number.MAX_VALUE;
|
|
117
|
+
var u3 = -Number.MAX_VALUE;
|
|
118
|
+
var l1 = Number.MAX_VALUE;
|
|
119
|
+
var l2 = Number.MAX_VALUE;
|
|
120
|
+
var l3 = Number.MAX_VALUE;
|
|
121
|
+
|
|
122
|
+
var _iterator3 = _createForOfIteratorHelper(positions),
|
|
123
|
+
_step3;
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
127
|
+
var _position2 = _step3.value;
|
|
128
|
+
scratchVector2.copy(_position2);
|
|
129
|
+
u1 = Math.max(scratchVector2.dot(v1), u1);
|
|
130
|
+
u2 = Math.max(scratchVector2.dot(v2), u2);
|
|
131
|
+
u3 = Math.max(scratchVector2.dot(v3), u3);
|
|
132
|
+
l1 = Math.min(scratchVector2.dot(v1), l1);
|
|
133
|
+
l2 = Math.min(scratchVector2.dot(v2), l2);
|
|
134
|
+
l3 = Math.min(scratchVector2.dot(v3), l3);
|
|
135
|
+
}
|
|
136
|
+
} catch (err) {
|
|
137
|
+
_iterator3.e(err);
|
|
138
|
+
} finally {
|
|
139
|
+
_iterator3.f();
|
|
101
140
|
}
|
|
102
141
|
|
|
103
142
|
v1 = v1.multiplyByScalar(0.5 * (l1 + u1));
|
|
104
143
|
v2 = v2.multiplyByScalar(0.5 * (l2 + u2));
|
|
105
144
|
v3 = v3.multiplyByScalar(0.5 * (l3 + u3));
|
|
106
145
|
result.center.copy(v1).add(v2).add(v3);
|
|
107
|
-
|
|
108
|
-
|
|
146
|
+
var scale = scratchVector3.set(u1 - l1, u2 - l2, u3 - l3).multiplyByScalar(0.5);
|
|
147
|
+
var scaleMatrix = new _core.Matrix3([scale[0], 0, 0, 0, scale[1], 0, 0, 0, scale[2]]);
|
|
109
148
|
result.halfAxes.multiplyRight(scaleMatrix);
|
|
110
149
|
return result;
|
|
111
150
|
}
|
|
112
151
|
|
|
113
|
-
function makeAxisAlignedBoundingBoxFromPoints(positions
|
|
152
|
+
function makeAxisAlignedBoundingBoxFromPoints(positions) {
|
|
153
|
+
var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new _axisAlignedBoundingBox.default();
|
|
154
|
+
|
|
114
155
|
if (!positions || positions.length === 0) {
|
|
115
156
|
result.minimum.set(0, 0, 0);
|
|
116
157
|
result.maximum.set(0, 0, 0);
|
|
@@ -119,23 +160,33 @@ function makeAxisAlignedBoundingBoxFromPoints(positions, result = new _axisAlign
|
|
|
119
160
|
return result;
|
|
120
161
|
}
|
|
121
162
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
163
|
+
var minimumX = positions[0][0];
|
|
164
|
+
var minimumY = positions[0][1];
|
|
165
|
+
var minimumZ = positions[0][2];
|
|
166
|
+
var maximumX = positions[0][0];
|
|
167
|
+
var maximumY = positions[0][1];
|
|
168
|
+
var maximumZ = positions[0][2];
|
|
169
|
+
|
|
170
|
+
var _iterator4 = _createForOfIteratorHelper(positions),
|
|
171
|
+
_step4;
|
|
172
|
+
|
|
173
|
+
try {
|
|
174
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
175
|
+
var p = _step4.value;
|
|
176
|
+
var x = p[0];
|
|
177
|
+
var y = p[1];
|
|
178
|
+
var z = p[2];
|
|
179
|
+
minimumX = Math.min(x, minimumX);
|
|
180
|
+
maximumX = Math.max(x, maximumX);
|
|
181
|
+
minimumY = Math.min(y, minimumY);
|
|
182
|
+
maximumY = Math.max(y, maximumY);
|
|
183
|
+
minimumZ = Math.min(z, minimumZ);
|
|
184
|
+
maximumZ = Math.max(z, maximumZ);
|
|
185
|
+
}
|
|
186
|
+
} catch (err) {
|
|
187
|
+
_iterator4.e(err);
|
|
188
|
+
} finally {
|
|
189
|
+
_iterator4.f();
|
|
139
190
|
}
|
|
140
191
|
|
|
141
192
|
result.minimum.set(minimumX, minimumY, minimumZ);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/algorithms/bounding-box-from-points.ts"],"names":["scratchVector2","Vector3","scratchVector3","scratchVector4","scratchVector5","scratchVector6","scratchCovarianceResult","Matrix3","scratchEigenResult","diagonal","unitary","makeOrientedBoundingBoxFromPoints","positions","result","OrientedBoundingBox","length","halfAxes","center","meanPoint","position","add","invLength","multiplyByScalar","exx","exy","exz","eyy","eyz","ezz","p","copy","subtract","x","y","z","covarianceMatrix","rotation","v1","getColumn","v2","v3","u1","Number","MAX_VALUE","u2","u3","l1","l2","l3","Math","max","dot","min","scale","set","scaleMatrix","multiplyRight","makeAxisAlignedBoundingBoxFromPoints","AxisAlignedBoundingBox","minimum","maximum","halfDiagonal","minimumX","minimumY","minimumZ","maximumX","maximumY","maximumZ"],"mappings":";;;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AAEA,MAAMA,cAAc,GAAG,IAAIC,aAAJ,EAAvB;AAEA,MAAMC,cAAc,GAAG,IAAID,aAAJ,EAAvB;AAEA,MAAME,cAAc,GAAG,IAAIF,aAAJ,EAAvB;AAEA,MAAMG,cAAc,GAAG,IAAIH,aAAJ,EAAvB;AAEA,MAAMI,cAAc,GAAG,IAAIJ,aAAJ,EAAvB;AAEA,MAAMK,uBAAuB,GAAG,IAAIC,aAAJ,EAAhC;AAEA,MAAMC,kBAAkB,GAAG;AACzBC,EAAAA,QAAQ,EAAE,IAAIF,aAAJ,EADe;AAEzBG,EAAAA,OAAO,EAAE,IAAIH,aAAJ;AAFgB,CA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AAT,EAAYiC,QAAZ,CAAX;AACAF,IAAAA,QAAQ,GAAGf,IAAI,CAACG,GAAL,CAASlB,CAAT,EAAY8B,QAAZ,CAAX;AACAG,IAAAA,QAAQ,GAAGlB,IAAI,CAACC,GAAL,CAAShB,CAAT,EAAYiC,QAAZ,CAAX;AACD;;AAEDtD,EAAAA,MAAM,CAAC8C,OAAP,CAAeL,GAAf,CAAmBQ,QAAnB,EAA6BC,QAA7B,EAAuCC,QAAvC;AACAnD,EAAAA,MAAM,CAAC+C,OAAP,CAAeN,GAAf,CAAmBW,QAAnB,EAA6BC,QAA7B,EAAuCC,QAAvC;AACAtD,EAAAA,MAAM,CAACI,MAAP,CAAca,IAAd,CAAmBjB,MAAM,CAAC8C,OAA1B,EAAmCvC,GAAnC,CAAuCP,MAAM,CAAC+C,OAA9C,EAAuDP,KAAvD,CAA6D,GAA7D;AACAxC,EAAAA,MAAM,CAACgD,YAAP,CAAoB/B,IAApB,CAAyBjB,MAAM,CAAC+C,OAAhC,EAAyC7B,QAAzC,CAAkDlB,MAAM,CAACI,MAAzD;AAEA,SAAOJ,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, Matrix3} from '@math.gl/core';\nimport computeEigenDecomposition from './compute-eigen-decomposition';\nimport OrientedBoundingBox from '../bounding-volumes/oriented-bounding-box';\nimport AxisAlignedBoundingBox from '../bounding-volumes/axis-aligned-bounding-box';\n\nconst scratchVector2 = new Vector3();\n\nconst scratchVector3 = new Vector3();\n\nconst scratchVector4 = new Vector3();\n\nconst scratchVector5 = new Vector3();\n\nconst scratchVector6 = new Vector3();\n\nconst scratchCovarianceResult = new Matrix3();\n\nconst scratchEigenResult = {\n diagonal: new Matrix3(),\n unitary: new Matrix3()\n};\n\n/**\n * Computes an instance of an OrientedBoundingBox of the given positions.\n *\n * This is an implementation of Stefan Gottschalk's Collision Queries using Oriented Bounding Boxes solution (PHD thesis).\n * Reference: http://gamma.cs.unc.edu/users/gottschalk/main.pdf\n */\n/* eslint-disable max-statements */\nexport function makeOrientedBoundingBoxFromPoints(\n positions: number[][],\n result: OrientedBoundingBox = new OrientedBoundingBox()\n): OrientedBoundingBox {\n if (!positions || positions.length === 0) {\n result.halfAxes = new Matrix3([0, 0, 0, 0, 0, 0, 0, 0, 0]);\n result.center = new Vector3();\n return result;\n }\n\n const length = positions.length;\n const meanPoint = new Vector3(0, 0, 0);\n for (const position of positions) {\n meanPoint.add(position);\n }\n const invLength = 1.0 / length;\n meanPoint.multiplyByScalar(invLength);\n\n let exx = 0.0;\n let exy = 0.0;\n let exz = 0.0;\n let eyy = 0.0;\n let eyz = 0.0;\n let ezz = 0.0;\n\n for (const position of positions) {\n const p = scratchVector2.copy(position).subtract(meanPoint);\n exx += p.x * p.x;\n exy += p.x * p.y;\n exz += p.x * p.z;\n eyy += p.y * p.y;\n eyz += p.y * p.z;\n ezz += p.z * p.z;\n }\n\n exx *= invLength;\n exy *= invLength;\n exz *= invLength;\n eyy *= invLength;\n eyz *= invLength;\n ezz *= invLength;\n\n const covarianceMatrix = scratchCovarianceResult;\n covarianceMatrix[0] = exx;\n covarianceMatrix[1] = exy;\n covarianceMatrix[2] = exz;\n covarianceMatrix[3] = exy;\n covarianceMatrix[4] = eyy;\n covarianceMatrix[5] = eyz;\n covarianceMatrix[6] = exz;\n covarianceMatrix[7] = eyz;\n covarianceMatrix[8] = ezz;\n\n const {unitary} = computeEigenDecomposition(covarianceMatrix, scratchEigenResult);\n const rotation = result.halfAxes.copy(unitary);\n\n let v1 = rotation.getColumn(0, scratchVector4);\n let v2 = rotation.getColumn(1, scratchVector5);\n let v3 = rotation.getColumn(2, scratchVector6);\n\n let u1 = -Number.MAX_VALUE;\n let u2 = -Number.MAX_VALUE;\n let u3 = -Number.MAX_VALUE;\n let l1 = Number.MAX_VALUE;\n let l2 = Number.MAX_VALUE;\n let l3 = Number.MAX_VALUE;\n\n for (const position of positions) {\n scratchVector2.copy(position);\n\n u1 = Math.max(scratchVector2.dot(v1), u1);\n u2 = Math.max(scratchVector2.dot(v2), u2);\n u3 = Math.max(scratchVector2.dot(v3), u3);\n\n l1 = Math.min(scratchVector2.dot(v1), l1);\n l2 = Math.min(scratchVector2.dot(v2), l2);\n l3 = Math.min(scratchVector2.dot(v3), l3);\n }\n\n v1 = v1.multiplyByScalar(0.5 * (l1 + u1));\n v2 = v2.multiplyByScalar(0.5 * (l2 + u2));\n v3 = v3.multiplyByScalar(0.5 * (l3 + u3));\n\n result.center.copy(v1).add(v2).add(v3);\n\n const scale = scratchVector3.set(u1 - l1, u2 - l2, u3 - l3).multiplyByScalar(0.5);\n const scaleMatrix = new Matrix3([scale[0], 0, 0, 0, scale[1], 0, 0, 0, scale[2]]);\n result.halfAxes.multiplyRight(scaleMatrix);\n\n return result;\n}\n\n/**\n * Computes an instance of an AxisAlignedBoundingBox. The box is determined by\n * finding the points spaced the farthest apart on the x, y, and z axes.\n */\nexport function makeAxisAlignedBoundingBoxFromPoints(\n positions: readonly number[][],\n result: AxisAlignedBoundingBox = new AxisAlignedBoundingBox()\n): AxisAlignedBoundingBox {\n if (!positions || positions.length === 0) {\n result.minimum.set(0, 0, 0);\n result.maximum.set(0, 0, 0);\n result.center.set(0, 0, 0);\n result.halfDiagonal.set(0, 0, 0);\n return result;\n }\n\n let minimumX = positions[0][0];\n let minimumY = positions[0][1];\n let minimumZ = positions[0][2];\n\n let maximumX = positions[0][0];\n let maximumY = positions[0][1];\n let maximumZ = positions[0][2];\n\n for (const p of positions) {\n const x = p[0];\n const y = p[1];\n const z = p[2];\n\n minimumX = Math.min(x, minimumX);\n maximumX = Math.max(x, maximumX);\n minimumY = Math.min(y, minimumY);\n maximumY = Math.max(y, maximumY);\n minimumZ = Math.min(z, minimumZ);\n maximumZ = Math.max(z, maximumZ);\n }\n\n result.minimum.set(minimumX, minimumY, minimumZ);\n result.maximum.set(maximumX, maximumY, maximumZ);\n result.center.copy(result.minimum).add(result.maximum).scale(0.5);\n result.halfDiagonal.copy(result.maximum).subtract(result.center);\n\n return result;\n}\n"],"file":"bounding-box-from-points.js"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/algorithms/bounding-box-from-points.ts"],"names":["scratchVector2","Vector3","scratchVector3","scratchVector4","scratchVector5","scratchVector6","scratchCovarianceResult","Matrix3","scratchEigenResult","diagonal","unitary","makeOrientedBoundingBoxFromPoints","positions","result","OrientedBoundingBox","length","halfAxes","center","meanPoint","position","add","invLength","multiplyByScalar","exx","exy","exz","eyy","eyz","ezz","p","copy","subtract","x","y","z","covarianceMatrix","rotation","v1","getColumn","v2","v3","u1","Number","MAX_VALUE","u2","u3","l1","l2","l3","Math","max","dot","min","scale","set","scaleMatrix","multiplyRight","makeAxisAlignedBoundingBoxFromPoints","AxisAlignedBoundingBox","minimum","maximum","halfDiagonal","minimumX","minimumY","minimumZ","maximumX","maximumY","maximumZ"],"mappings":";;;;;;;;;;AAGA;;AACA;;AACA;;AACA;;;;;;;;AAEA,IAAMA,cAAc,GAAG,IAAIC,aAAJ,EAAvB;AAEA,IAAMC,cAAc,GAAG,IAAID,aAAJ,EAAvB;AAEA,IAAME,cAAc,GAAG,IAAIF,aAAJ,EAAvB;AAEA,IAAMG,cAAc,GAAG,IAAIH,aAAJ,EAAvB;AAEA,IAAMI,cAAc,GAAG,IAAIJ,aAAJ,EAAvB;AAEA,IAAMK,uBAAuB,GAAG,IAAIC,aAAJ,EAAhC;AAEA,IAAMC,kBAAkB,GAAG;AACzBC,EAAAA,QAAQ,EAAE,IAAIF,aAAJ,EADe;AAEzBG,EAAAA,OAAO,EAAE,IAAIH,aAAJ;AAFgB,CAA3B;;AAYO,SAASI,iCAAT,CACLC,SADK,EAGgB;AAAA,MADrBC,MACqB,uEADS,IAAIC,4BAAJ,EACT;;AACrB,MAAI,CAACF,SAAD,IAAcA,SAAS,CAACG,MAAV,KAAqB,CAAvC,EAA0C;AACxCF,IAAAA,MAAM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A,QAAQ,GAAGjB,IAAI,CAACC,GAAL,CAASjB,CAAT,EAAYiC,QAAZ,CAAX;AACAF,MAAAA,QAAQ,GAAGf,IAAI,CAACG,GAAL,CAASlB,CAAT,EAAY8B,QAAZ,CAAX;AACAG,MAAAA,QAAQ,GAAGlB,IAAI,CAACC,GAAL,CAAShB,CAAT,EAAYiC,QAAZ,CAAX;AACD;AA5BuB;AAAA;AAAA;AAAA;AAAA;;AA8BxBtD,EAAAA,MAAM,CAAC8C,OAAP,CAAeL,GAAf,CAAmBQ,QAAnB,EAA6BC,QAA7B,EAAuCC,QAAvC;AACAnD,EAAAA,MAAM,CAAC+C,OAAP,CAAeN,GAAf,CAAmBW,QAAnB,EAA6BC,QAA7B,EAAuCC,QAAvC;AACAtD,EAAAA,MAAM,CAACI,MAAP,CAAca,IAAd,CAAmBjB,MAAM,CAAC8C,OAA1B,EAAmCvC,GAAnC,CAAuCP,MAAM,CAAC+C,OAA9C,EAAuDP,KAAvD,CAA6D,GAA7D;AACAxC,EAAAA,MAAM,CAACgD,YAAP,CAAoB/B,IAApB,CAAyBjB,MAAM,CAAC+C,OAAhC,EAAyC7B,QAAzC,CAAkDlB,MAAM,CAACI,MAAzD;AAEA,SAAOJ,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, Matrix3} from '@math.gl/core';\nimport computeEigenDecomposition from './compute-eigen-decomposition';\nimport OrientedBoundingBox from '../bounding-volumes/oriented-bounding-box';\nimport AxisAlignedBoundingBox from '../bounding-volumes/axis-aligned-bounding-box';\n\nconst scratchVector2 = new Vector3();\n\nconst scratchVector3 = new Vector3();\n\nconst scratchVector4 = new Vector3();\n\nconst scratchVector5 = new Vector3();\n\nconst scratchVector6 = new Vector3();\n\nconst scratchCovarianceResult = new Matrix3();\n\nconst scratchEigenResult = {\n diagonal: new Matrix3(),\n unitary: new Matrix3()\n};\n\n/**\n * Computes an instance of an OrientedBoundingBox of the given positions.\n *\n * This is an implementation of Stefan Gottschalk's Collision Queries using Oriented Bounding Boxes solution (PHD thesis).\n * Reference: http://gamma.cs.unc.edu/users/gottschalk/main.pdf\n */\n/* eslint-disable max-statements */\nexport function makeOrientedBoundingBoxFromPoints(\n positions: number[][],\n result: OrientedBoundingBox = new OrientedBoundingBox()\n): OrientedBoundingBox {\n if (!positions || positions.length === 0) {\n result.halfAxes = new Matrix3([0, 0, 0, 0, 0, 0, 0, 0, 0]);\n result.center = new Vector3();\n return result;\n }\n\n const length = positions.length;\n const meanPoint = new Vector3(0, 0, 0);\n for (const position of positions) {\n meanPoint.add(position);\n }\n const invLength = 1.0 / length;\n meanPoint.multiplyByScalar(invLength);\n\n let exx = 0.0;\n let exy = 0.0;\n let exz = 0.0;\n let eyy = 0.0;\n let eyz = 0.0;\n let ezz = 0.0;\n\n for (const position of positions) {\n const p = scratchVector2.copy(position).subtract(meanPoint);\n exx += p.x * p.x;\n exy += p.x * p.y;\n exz += p.x * p.z;\n eyy += p.y * p.y;\n eyz += p.y * p.z;\n ezz += p.z * p.z;\n }\n\n exx *= invLength;\n exy *= invLength;\n exz *= invLength;\n eyy *= invLength;\n eyz *= invLength;\n ezz *= invLength;\n\n const covarianceMatrix = scratchCovarianceResult;\n covarianceMatrix[0] = exx;\n covarianceMatrix[1] = exy;\n covarianceMatrix[2] = exz;\n covarianceMatrix[3] = exy;\n covarianceMatrix[4] = eyy;\n covarianceMatrix[5] = eyz;\n covarianceMatrix[6] = exz;\n covarianceMatrix[7] = eyz;\n covarianceMatrix[8] = ezz;\n\n const {unitary} = computeEigenDecomposition(covarianceMatrix, scratchEigenResult);\n const rotation = result.halfAxes.copy(unitary);\n\n let v1 = rotation.getColumn(0, scratchVector4);\n let v2 = rotation.getColumn(1, scratchVector5);\n let v3 = rotation.getColumn(2, scratchVector6);\n\n let u1 = -Number.MAX_VALUE;\n let u2 = -Number.MAX_VALUE;\n let u3 = -Number.MAX_VALUE;\n let l1 = Number.MAX_VALUE;\n let l2 = Number.MAX_VALUE;\n let l3 = Number.MAX_VALUE;\n\n for (const position of positions) {\n scratchVector2.copy(position);\n\n u1 = Math.max(scratchVector2.dot(v1), u1);\n u2 = Math.max(scratchVector2.dot(v2), u2);\n u3 = Math.max(scratchVector2.dot(v3), u3);\n\n l1 = Math.min(scratchVector2.dot(v1), l1);\n l2 = Math.min(scratchVector2.dot(v2), l2);\n l3 = Math.min(scratchVector2.dot(v3), l3);\n }\n\n v1 = v1.multiplyByScalar(0.5 * (l1 + u1));\n v2 = v2.multiplyByScalar(0.5 * (l2 + u2));\n v3 = v3.multiplyByScalar(0.5 * (l3 + u3));\n\n result.center.copy(v1).add(v2).add(v3);\n\n const scale = scratchVector3.set(u1 - l1, u2 - l2, u3 - l3).multiplyByScalar(0.5);\n const scaleMatrix = new Matrix3([scale[0], 0, 0, 0, scale[1], 0, 0, 0, scale[2]]);\n result.halfAxes.multiplyRight(scaleMatrix);\n\n return result;\n}\n\n/**\n * Computes an instance of an AxisAlignedBoundingBox. The box is determined by\n * finding the points spaced the farthest apart on the x, y, and z axes.\n */\nexport function makeAxisAlignedBoundingBoxFromPoints(\n positions: readonly number[][],\n result: AxisAlignedBoundingBox = new AxisAlignedBoundingBox()\n): AxisAlignedBoundingBox {\n if (!positions || positions.length === 0) {\n result.minimum.set(0, 0, 0);\n result.maximum.set(0, 0, 0);\n result.center.set(0, 0, 0);\n result.halfDiagonal.set(0, 0, 0);\n return result;\n }\n\n let minimumX = positions[0][0];\n let minimumY = positions[0][1];\n let minimumZ = positions[0][2];\n\n let maximumX = positions[0][0];\n let maximumY = positions[0][1];\n let maximumZ = positions[0][2];\n\n for (const p of positions) {\n const x = p[0];\n const y = p[1];\n const z = p[2];\n\n minimumX = Math.min(x, minimumX);\n maximumX = Math.max(x, maximumX);\n minimumY = Math.min(y, minimumY);\n maximumY = Math.max(y, maximumY);\n minimumZ = Math.min(z, minimumZ);\n maximumZ = Math.max(z, maximumZ);\n }\n\n result.minimum.set(minimumX, minimumY, minimumZ);\n result.maximum.set(maximumX, maximumY, maximumZ);\n result.center.copy(result.minimum).add(result.maximum).scale(0.5);\n result.halfDiagonal.copy(result.maximum).subtract(result.center);\n\n return result;\n}\n"],"file":"bounding-box-from-points.js"}
|
|
@@ -11,70 +11,88 @@ var _core = require("@math.gl/core");
|
|
|
11
11
|
|
|
12
12
|
var _boundingSphere = _interopRequireDefault(require("../bounding-volumes/bounding-sphere"));
|
|
13
13
|
|
|
14
|
-
|
|
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
|
-
}
|
|
14
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
32
15
|
|
|
33
|
-
|
|
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
|
-
}
|
|
16
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
50
17
|
|
|
51
|
-
|
|
52
|
-
xMax.copy(currentPos);
|
|
53
|
-
}
|
|
18
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
54
19
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
20
|
+
var fromPointsXMin = new _core.Vector3();
|
|
21
|
+
var fromPointsYMin = new _core.Vector3();
|
|
22
|
+
var fromPointsZMin = new _core.Vector3();
|
|
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;
|
|
58
33
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
34
|
+
function makeBoundingSphereFromPoints(positions) {
|
|
35
|
+
var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new _boundingSphere.default();
|
|
62
36
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
37
|
+
if (!positions || positions.length === 0) {
|
|
38
|
+
return result.fromCenterRadius([0, 0, 0], 0);
|
|
39
|
+
}
|
|
66
40
|
|
|
67
|
-
|
|
68
|
-
|
|
41
|
+
var currentPos = fromPointsCurrentPos.copy(positions[0]);
|
|
42
|
+
var xMin = fromPointsXMin.copy(currentPos);
|
|
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
|
+
xMin.copy(currentPos);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (x > xMax.x) {
|
|
65
|
+
xMax.copy(currentPos);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (y < yMin.y) {
|
|
69
|
+
yMin.copy(currentPos);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (y > yMax.y) {
|
|
73
|
+
yMax.copy(currentPos);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (z < zMin.z) {
|
|
77
|
+
zMin.copy(currentPos);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (z > zMax.z) {
|
|
81
|
+
zMax.copy(currentPos);
|
|
82
|
+
}
|
|
69
83
|
}
|
|
84
|
+
} catch (err) {
|
|
85
|
+
_iterator.e(err);
|
|
86
|
+
} finally {
|
|
87
|
+
_iterator.f();
|
|
70
88
|
}
|
|
71
89
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
90
|
+
var xSpan = fromPointsScratch.copy(xMax).subtract(xMin).magnitudeSquared();
|
|
91
|
+
var ySpan = fromPointsScratch.copy(yMax).subtract(yMin).magnitudeSquared();
|
|
92
|
+
var zSpan = fromPointsScratch.copy(zMax).subtract(zMin).magnitudeSquared();
|
|
93
|
+
var diameter1 = xMin;
|
|
94
|
+
var diameter2 = xMax;
|
|
95
|
+
var maxSpan = xSpan;
|
|
78
96
|
|
|
79
97
|
if (ySpan > maxSpan) {
|
|
80
98
|
maxSpan = ySpan;
|
|
@@ -88,42 +106,52 @@ function makeBoundingSphereFromPoints(positions, result = new _boundingSphere.de
|
|
|
88
106
|
diameter2 = zMax;
|
|
89
107
|
}
|
|
90
108
|
|
|
91
|
-
|
|
109
|
+
var ritterCenter = fromPointsRitterCenter;
|
|
92
110
|
ritterCenter.x = (diameter1.x + diameter2.x) * 0.5;
|
|
93
111
|
ritterCenter.y = (diameter1.y + diameter2.y) * 0.5;
|
|
94
112
|
ritterCenter.z = (diameter1.z + diameter2.z) * 0.5;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
113
|
+
var radiusSquared = fromPointsScratch.copy(diameter2).subtract(ritterCenter).magnitudeSquared();
|
|
114
|
+
var ritterRadius = Math.sqrt(radiusSquared);
|
|
115
|
+
var minBoxPt = fromPointsMinBoxPt;
|
|
98
116
|
minBoxPt.x = xMin.x;
|
|
99
117
|
minBoxPt.y = yMin.y;
|
|
100
118
|
minBoxPt.z = zMin.z;
|
|
101
|
-
|
|
119
|
+
var maxBoxPt = fromPointsMaxBoxPt;
|
|
102
120
|
maxBoxPt.x = xMax.x;
|
|
103
121
|
maxBoxPt.y = yMax.y;
|
|
104
122
|
maxBoxPt.z = zMax.z;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
123
|
+
var naiveCenter = fromPointsNaiveCenterScratch.copy(minBoxPt).add(maxBoxPt).multiplyByScalar(0.5);
|
|
124
|
+
var naiveRadius = 0;
|
|
125
|
+
|
|
126
|
+
var _iterator2 = _createForOfIteratorHelper(positions),
|
|
127
|
+
_step2;
|
|
128
|
+
|
|
129
|
+
try {
|
|
130
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
131
|
+
var _position = _step2.value;
|
|
132
|
+
currentPos.copy(_position);
|
|
133
|
+
var r = fromPointsScratch.copy(currentPos).subtract(naiveCenter).magnitude();
|
|
134
|
+
|
|
135
|
+
if (r > naiveRadius) {
|
|
136
|
+
naiveRadius = r;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
var oldCenterToPointSquared = fromPointsScratch.copy(currentPos).subtract(ritterCenter).magnitudeSquared();
|
|
140
|
+
|
|
141
|
+
if (oldCenterToPointSquared > radiusSquared) {
|
|
142
|
+
var oldCenterToPoint = Math.sqrt(oldCenterToPointSquared);
|
|
143
|
+
ritterRadius = (ritterRadius + oldCenterToPoint) * 0.5;
|
|
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
|
+
}
|
|
126
150
|
}
|
|
151
|
+
} catch (err) {
|
|
152
|
+
_iterator2.e(err);
|
|
153
|
+
} finally {
|
|
154
|
+
_iterator2.f();
|
|
127
155
|
}
|
|
128
156
|
|
|
129
157
|
if (ritterRadius < naiveRadius) {
|