@math.gl/culling 3.5.6 → 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 -123
- 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 -110
- 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.map +1 -1
- 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 +9 -4
- 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 +4 -4
- 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} +17 -4
- package/src/lib/algorithms/{bounding-sphere-from-points.js → bounding-sphere-from-points.ts} +15 -1
- 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} +44 -29
- 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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAGA,oBAAY,YAAY;IACtB,OAAO,KAAK;IACZ,YAAY,IAAI;IAChB,MAAM,IAAI;CACX"}
|
|
@@ -0,0 +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
|
|
3
|
+
export var INTERSECTION;
|
|
4
|
+
(function (INTERSECTION) {
|
|
5
|
+
INTERSECTION[INTERSECTION["OUTSIDE"] = -1] = "OUTSIDE";
|
|
6
|
+
INTERSECTION[INTERSECTION["INTERSECTING"] = 0] = "INTERSECTING";
|
|
7
|
+
INTERSECTION[INTERSECTION["INSIDE"] = 1] = "INSIDE"; // Represents that an object is fully within the frustum.
|
|
8
|
+
})(INTERSECTION || (INTERSECTION = {}));
|
package/dist/es5/constants.js
CHANGED
|
@@ -4,10 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.INTERSECTION = void 0;
|
|
7
|
-
|
|
8
|
-
OUTSIDE: -1,
|
|
9
|
-
INTERSECTING: 0,
|
|
10
|
-
INSIDE: 1
|
|
11
|
-
});
|
|
7
|
+
let INTERSECTION;
|
|
12
8
|
exports.INTERSECTION = INTERSECTION;
|
|
9
|
+
|
|
10
|
+
(function (INTERSECTION) {
|
|
11
|
+
INTERSECTION[INTERSECTION["OUTSIDE"] = -1] = "OUTSIDE";
|
|
12
|
+
INTERSECTION[INTERSECTION["INTERSECTING"] = 0] = "INTERSECTING";
|
|
13
|
+
INTERSECTION[INTERSECTION["INSIDE"] = 1] = "INSIDE";
|
|
14
|
+
})(INTERSECTION || (exports.INTERSECTION = INTERSECTION = {}));
|
|
13
15
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/constants.
|
|
1
|
+
{"version":3,"sources":["../../src/constants.ts"],"names":["INTERSECTION"],"mappings":";;;;;;IAGYA,Y;;;WAAAA,Y;AAAAA,EAAAA,Y,CAAAA,Y;AAAAA,EAAAA,Y,CAAAA,Y;AAAAA,EAAAA,Y,CAAAA,Y;GAAAA,Y,4BAAAA,Y","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\nexport enum INTERSECTION {\n OUTSIDE = -1, // Represents that an object is not contained within the frustum.\n INTERSECTING = 0, // Represents that an object intersects one of the frustum's planes.\n INSIDE = 1 // Represents that an object is fully within the frustum.\n}\n"],"file":"constants.js"}
|
package/dist/es5/index.js
CHANGED
|
@@ -7,85 +7,73 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
Object.defineProperty(exports, "INTERSECTION", {
|
|
9
9
|
enumerable: true,
|
|
10
|
-
get: function
|
|
11
|
-
return _constants.INTERSECTION;
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
Object.defineProperty(exports, "Intersect", {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: function get() {
|
|
17
|
-
return _constants.INTERSECTION;
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
Object.defineProperty(exports, "INTERSECT", {
|
|
21
|
-
enumerable: true,
|
|
22
|
-
get: function get() {
|
|
10
|
+
get: function () {
|
|
23
11
|
return _constants.INTERSECTION;
|
|
24
12
|
}
|
|
25
13
|
});
|
|
26
14
|
Object.defineProperty(exports, "AxisAlignedBoundingBox", {
|
|
27
15
|
enumerable: true,
|
|
28
|
-
get: function
|
|
16
|
+
get: function () {
|
|
29
17
|
return _axisAlignedBoundingBox.default;
|
|
30
18
|
}
|
|
31
19
|
});
|
|
32
20
|
Object.defineProperty(exports, "BoundingSphere", {
|
|
33
21
|
enumerable: true,
|
|
34
|
-
get: function
|
|
22
|
+
get: function () {
|
|
35
23
|
return _boundingSphere.default;
|
|
36
24
|
}
|
|
37
25
|
});
|
|
38
26
|
Object.defineProperty(exports, "OrientedBoundingBox", {
|
|
39
27
|
enumerable: true,
|
|
40
|
-
get: function
|
|
28
|
+
get: function () {
|
|
41
29
|
return _orientedBoundingBox.default;
|
|
42
30
|
}
|
|
43
31
|
});
|
|
44
32
|
Object.defineProperty(exports, "CullingVolume", {
|
|
45
33
|
enumerable: true,
|
|
46
|
-
get: function
|
|
34
|
+
get: function () {
|
|
47
35
|
return _cullingVolume.default;
|
|
48
36
|
}
|
|
49
37
|
});
|
|
50
38
|
Object.defineProperty(exports, "Plane", {
|
|
51
39
|
enumerable: true,
|
|
52
|
-
get: function
|
|
40
|
+
get: function () {
|
|
53
41
|
return _plane.default;
|
|
54
42
|
}
|
|
55
43
|
});
|
|
56
44
|
Object.defineProperty(exports, "_PerspectiveOffCenterFrustum", {
|
|
57
45
|
enumerable: true,
|
|
58
|
-
get: function
|
|
46
|
+
get: function () {
|
|
59
47
|
return _perspectiveOffCenterFrustum.default;
|
|
60
48
|
}
|
|
61
49
|
});
|
|
62
50
|
Object.defineProperty(exports, "_PerspectiveFrustum", {
|
|
63
51
|
enumerable: true,
|
|
64
|
-
get: function
|
|
52
|
+
get: function () {
|
|
65
53
|
return _perspectiveFrustum.default;
|
|
66
54
|
}
|
|
67
55
|
});
|
|
68
56
|
Object.defineProperty(exports, "makeBoundingSphereFromPoints", {
|
|
69
57
|
enumerable: true,
|
|
70
|
-
get: function
|
|
58
|
+
get: function () {
|
|
71
59
|
return _boundingSphereFromPoints.default;
|
|
72
60
|
}
|
|
73
61
|
});
|
|
74
62
|
Object.defineProperty(exports, "makeAxisAlignedBoundingBoxFromPoints", {
|
|
75
63
|
enumerable: true,
|
|
76
|
-
get: function
|
|
64
|
+
get: function () {
|
|
77
65
|
return _boundingBoxFromPoints.makeAxisAlignedBoundingBoxFromPoints;
|
|
78
66
|
}
|
|
79
67
|
});
|
|
80
68
|
Object.defineProperty(exports, "makeOrientedBoundingBoxFromPoints", {
|
|
81
69
|
enumerable: true,
|
|
82
|
-
get: function
|
|
70
|
+
get: function () {
|
|
83
71
|
return _boundingBoxFromPoints.makeOrientedBoundingBoxFromPoints;
|
|
84
72
|
}
|
|
85
73
|
});
|
|
86
74
|
Object.defineProperty(exports, "computeEigenDecomposition", {
|
|
87
75
|
enumerable: true,
|
|
88
|
-
get: function
|
|
76
|
+
get: function () {
|
|
89
77
|
return _computeEigenDecomposition.default;
|
|
90
78
|
}
|
|
91
79
|
});
|
package/dist/es5/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AAEA;;AACA;;AAIA","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\nexport {INTERSECTION} from './constants';\n\nexport {default as AxisAlignedBoundingBox} from './lib/bounding-volumes/axis-aligned-bounding-box';\nexport {default as BoundingSphere} from './lib/bounding-volumes/bounding-sphere';\nexport {default as OrientedBoundingBox} from './lib/bounding-volumes/oriented-bounding-box';\nexport {default as CullingVolume} from './lib/culling-volume';\nexport {default as Plane} from './lib/plane';\n\nexport {default as _PerspectiveOffCenterFrustum} from './lib/perspective-off-center-frustum';\nexport {default as _PerspectiveFrustum} from './lib/perspective-frustum';\n\nexport {default as makeBoundingSphereFromPoints} from './lib/algorithms/bounding-sphere-from-points';\nexport {\n makeAxisAlignedBoundingBoxFromPoints,\n makeOrientedBoundingBoxFromPoints\n} from './lib/algorithms/bounding-box-from-points';\nexport {default as computeEigenDecomposition} from './lib/algorithms/compute-eigen-decomposition';\n"],"file":"index.js"}
|
|
@@ -16,76 +16,48 @@ 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
|
-
|
|
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 = {
|
|
19
|
+
const scratchVector2 = new _core.Vector3();
|
|
20
|
+
const scratchVector3 = new _core.Vector3();
|
|
21
|
+
const scratchVector4 = new _core.Vector3();
|
|
22
|
+
const scratchVector5 = new _core.Vector3();
|
|
23
|
+
const scratchVector6 = new _core.Vector3();
|
|
24
|
+
const scratchCovarianceResult = new _core.Matrix3();
|
|
25
|
+
const scratchEigenResult = {
|
|
32
26
|
diagonal: new _core.Matrix3(),
|
|
33
27
|
unitary: new _core.Matrix3()
|
|
34
28
|
};
|
|
35
29
|
|
|
36
|
-
function makeOrientedBoundingBoxFromPoints(positions) {
|
|
37
|
-
var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new _orientedBoundingBox.default();
|
|
38
|
-
|
|
30
|
+
function makeOrientedBoundingBoxFromPoints(positions, result = new _orientedBoundingBox.default()) {
|
|
39
31
|
if (!positions || positions.length === 0) {
|
|
40
32
|
result.halfAxes = new _core.Matrix3([0, 0, 0, 0, 0, 0, 0, 0, 0]);
|
|
41
33
|
result.center = new _core.Vector3();
|
|
42
34
|
return result;
|
|
43
35
|
}
|
|
44
36
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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();
|
|
37
|
+
const length = positions.length;
|
|
38
|
+
const meanPoint = new _core.Vector3(0, 0, 0);
|
|
39
|
+
|
|
40
|
+
for (const position of positions) {
|
|
41
|
+
meanPoint.add(position);
|
|
60
42
|
}
|
|
61
43
|
|
|
62
|
-
|
|
44
|
+
const invLength = 1.0 / length;
|
|
63
45
|
meanPoint.multiplyByScalar(invLength);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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();
|
|
46
|
+
let exx = 0.0;
|
|
47
|
+
let exy = 0.0;
|
|
48
|
+
let exz = 0.0;
|
|
49
|
+
let eyy = 0.0;
|
|
50
|
+
let eyz = 0.0;
|
|
51
|
+
let ezz = 0.0;
|
|
52
|
+
|
|
53
|
+
for (const position of positions) {
|
|
54
|
+
const p = scratchVector2.copy(position).subtract(meanPoint);
|
|
55
|
+
exx += p.x * p.x;
|
|
56
|
+
exy += p.x * p.y;
|
|
57
|
+
exz += p.x * p.z;
|
|
58
|
+
eyy += p.y * p.y;
|
|
59
|
+
eyz += p.y * p.z;
|
|
60
|
+
ezz += p.z * p.z;
|
|
89
61
|
}
|
|
90
62
|
|
|
91
63
|
exx *= invLength;
|
|
@@ -94,7 +66,7 @@ function makeOrientedBoundingBoxFromPoints(positions) {
|
|
|
94
66
|
eyy *= invLength;
|
|
95
67
|
eyz *= invLength;
|
|
96
68
|
ezz *= invLength;
|
|
97
|
-
|
|
69
|
+
const covarianceMatrix = scratchCovarianceResult;
|
|
98
70
|
covarianceMatrix[0] = exx;
|
|
99
71
|
covarianceMatrix[1] = exy;
|
|
100
72
|
covarianceMatrix[2] = exz;
|
|
@@ -104,54 +76,41 @@ function makeOrientedBoundingBoxFromPoints(positions) {
|
|
|
104
76
|
covarianceMatrix[6] = exz;
|
|
105
77
|
covarianceMatrix[7] = eyz;
|
|
106
78
|
covarianceMatrix[8] = ezz;
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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();
|
|
79
|
+
const {
|
|
80
|
+
unitary
|
|
81
|
+
} = (0, _computeEigenDecomposition.default)(covarianceMatrix, scratchEigenResult);
|
|
82
|
+
const rotation = result.halfAxes.copy(unitary);
|
|
83
|
+
let v1 = rotation.getColumn(0, scratchVector4);
|
|
84
|
+
let v2 = rotation.getColumn(1, scratchVector5);
|
|
85
|
+
let v3 = rotation.getColumn(2, scratchVector6);
|
|
86
|
+
let u1 = -Number.MAX_VALUE;
|
|
87
|
+
let u2 = -Number.MAX_VALUE;
|
|
88
|
+
let u3 = -Number.MAX_VALUE;
|
|
89
|
+
let l1 = Number.MAX_VALUE;
|
|
90
|
+
let l2 = Number.MAX_VALUE;
|
|
91
|
+
let l3 = Number.MAX_VALUE;
|
|
92
|
+
|
|
93
|
+
for (const position of positions) {
|
|
94
|
+
scratchVector2.copy(position);
|
|
95
|
+
u1 = Math.max(scratchVector2.dot(v1), u1);
|
|
96
|
+
u2 = Math.max(scratchVector2.dot(v2), u2);
|
|
97
|
+
u3 = Math.max(scratchVector2.dot(v3), u3);
|
|
98
|
+
l1 = Math.min(scratchVector2.dot(v1), l1);
|
|
99
|
+
l2 = Math.min(scratchVector2.dot(v2), l2);
|
|
100
|
+
l3 = Math.min(scratchVector2.dot(v3), l3);
|
|
140
101
|
}
|
|
141
102
|
|
|
142
103
|
v1 = v1.multiplyByScalar(0.5 * (l1 + u1));
|
|
143
104
|
v2 = v2.multiplyByScalar(0.5 * (l2 + u2));
|
|
144
105
|
v3 = v3.multiplyByScalar(0.5 * (l3 + u3));
|
|
145
106
|
result.center.copy(v1).add(v2).add(v3);
|
|
146
|
-
|
|
147
|
-
|
|
107
|
+
const scale = scratchVector3.set(u1 - l1, u2 - l2, u3 - l3).multiplyByScalar(0.5);
|
|
108
|
+
const scaleMatrix = new _core.Matrix3([scale[0], 0, 0, 0, scale[1], 0, 0, 0, scale[2]]);
|
|
148
109
|
result.halfAxes.multiplyRight(scaleMatrix);
|
|
149
110
|
return result;
|
|
150
111
|
}
|
|
151
112
|
|
|
152
|
-
function makeAxisAlignedBoundingBoxFromPoints(positions) {
|
|
153
|
-
var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new _axisAlignedBoundingBox.default();
|
|
154
|
-
|
|
113
|
+
function makeAxisAlignedBoundingBoxFromPoints(positions, result = new _axisAlignedBoundingBox.default()) {
|
|
155
114
|
if (!positions || positions.length === 0) {
|
|
156
115
|
result.minimum.set(0, 0, 0);
|
|
157
116
|
result.maximum.set(0, 0, 0);
|
|
@@ -160,33 +119,23 @@ function makeAxisAlignedBoundingBoxFromPoints(positions) {
|
|
|
160
119
|
return result;
|
|
161
120
|
}
|
|
162
121
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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();
|
|
122
|
+
let minimumX = positions[0][0];
|
|
123
|
+
let minimumY = positions[0][1];
|
|
124
|
+
let minimumZ = positions[0][2];
|
|
125
|
+
let maximumX = positions[0][0];
|
|
126
|
+
let maximumY = positions[0][1];
|
|
127
|
+
let maximumZ = positions[0][2];
|
|
128
|
+
|
|
129
|
+
for (const p of positions) {
|
|
130
|
+
const x = p[0];
|
|
131
|
+
const y = p[1];
|
|
132
|
+
const z = p[2];
|
|
133
|
+
minimumX = Math.min(x, minimumX);
|
|
134
|
+
maximumX = Math.max(x, maximumX);
|
|
135
|
+
minimumY = Math.min(y, minimumY);
|
|
136
|
+
maximumY = Math.max(y, maximumY);
|
|
137
|
+
minimumZ = Math.min(z, minimumZ);
|
|
138
|
+
maximumZ = Math.max(z, maximumZ);
|
|
190
139
|
}
|
|
191
140
|
|
|
192
141
|
result.minimum.set(minimumX, minimumY, minimumZ);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/algorithms/bounding-box-from-points.js"],"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,EAD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C,MAAAA,QAAQ,GAAGb,IAAI,CAACG,GAAL,CAASpB,CAAT,EAAY8B,QAAZ,CAAX;AACAG,MAAAA,QAAQ,GAAGhB,IAAI,CAACC,GAAL,CAASlB,CAAT,EAAYiC,QAAZ,CAAX;AACAF,MAAAA,QAAQ,GAAGd,IAAI,CAACG,GAAL,CAASnB,CAAT,EAAY8B,QAAZ,CAAX;AACAG,MAAAA,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;AA5BD;AAAA;AAAA;AAAA;AAAA;;AA8BAtD,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/* eslint-disable max-statements */\nexport function makeOrientedBoundingBoxFromPoints(positions, result = new 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\nexport function makeAxisAlignedBoundingBoxFromPoints(\n positions,\n result = new AxisAlignedBoundingBox()\n) {\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,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,CAA3B;;AAYO,SAASI,iCAAT,CACLC,SADK,EAELC,MAA2B,GAAG,IAAIC,4BAAJ,EAFzB,EAGgB;AACrB,MAAI,CAACF,SAAD,IAAcA,SAAS,CAACG,MAAV,KAAqB,CAAvC,EAA0C;AACxCF,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AT,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"}
|