@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/bounding-volumes/axis-aligned-bounding-box.
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/bounding-volumes/axis-aligned-bounding-box.ts"],"names":["scratchVector","Vector3","scratchNormal","AxisAlignedBoundingBox","constructor","minimum","maximum","center","copy","add","scale","halfDiagonal","subtract","clone","equals","right","Boolean","transform","transformAsPoint","intersectPlane","plane","normal","from","e","x","Math","abs","y","z","s","dot","distance","INTERSECTION","INSIDE","OUTSIDE","INTERSECTING","distanceTo","point","sqrt","distanceSquaredTo","offset","distanceSquared","d"],"mappings":";;;;;;;;;;;AACA;;AAEA;;AAEA,MAAMA,aAAa,GAAG,IAAIC,aAAJ,EAAtB;AACA,MAAMC,aAAa,GAAG,IAAID,aAAJ,EAAtB;;AAQe,MAAME,sBAAN,CAAuD;AAgBpEC,EAAAA,WAAW,CACTC,OAA0B,GAAG,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CADpB,EAETC,OAA0B,GAAG,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAFpB,EAGTC,MAHS,EAIT;AAAA;AAAA;AAAA;AAAA;AAEAA,IAAAA,MAAM,GAAGA,MAAM,IAAIP,aAAa,CAACQ,IAAd,CAAmBH,OAAnB,EAA4BI,GAA5B,CAAgCH,OAAhC,EAAyCI,KAAzC,CAA+C,GAA/C,CAAnB;AACA,SAAKH,MAAL,GAAc,IAAIN,aAAJ,CAAYM,MAAZ,CAAd;AACA,SAAKI,YAAL,GAAoB,IAAIV,aAAJ,CAAYK,OAAZ,EAAqBM,QAArB,CAA8B,KAAKL,MAAnC,CAApB;A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ACD;;AAnImE","sourcesContent":["import {BoundingVolume} from './bounding-volume';\nimport {Vector3} from '@math.gl/core';\nimport Plane from '../plane';\nimport {INTERSECTION} from '../../constants';\n\nconst scratchVector = new Vector3();\nconst scratchNormal = new Vector3();\n\n/**\n * An axis aligned bounding box - aligned with coordinate axes\n * @see BoundingVolume\n * @see BoundingRectangle\n * @see OrientedBoundingBox\n */\nexport default class AxisAlignedBoundingBox implements BoundingVolume {\n /** The center point of the bounding box. */\n readonly center: Vector3;\n /** The positive half diagonal of the bounding box. */\n readonly halfDiagonal: Vector3;\n /** The minimum point defining the bounding box. [0, 0, 0] for empty box */\n readonly minimum: Vector3;\n /** The maximum point defining the bounding box. [0, 0, 0] for empty box */\n readonly maximum: Vector3;\n\n /**\n * Creates an instance of an AxisAlignedBoundingBox from the minimum and maximum points along the x, y, and z axes.\n * @param minimum=[0, 0, 0] The minimum point along the x, y, and z axes.\n * @param maximum=[0, 0, 0] The maximum point along the x, y, and z axes.\n * @param center The center of the box; automatically computed if not supplied.\n */\n constructor(\n minimum: readonly number[] = [0, 0, 0],\n maximum: readonly number[] = [0, 0, 0],\n center?: readonly number[]\n ) {\n // If center was not defined, compute it.\n center = center || scratchVector.copy(minimum).add(maximum).scale(0.5);\n this.center = new Vector3(center);\n this.halfDiagonal = new Vector3(maximum).subtract(this.center);\n\n /**\n * The minimum point defining the bounding box.\n * @type {Vector3}\n * @default {@link 0, 0, 0}\n */\n this.minimum = new Vector3(minimum);\n\n /**\n * The maximum point defining the bounding box.\n * @type {Vector3}\n * @default {@link 0, 0, 0}\n */\n this.maximum = new Vector3(maximum);\n }\n\n /**\n * Duplicates a AxisAlignedBoundingBox instance.\n *\n * @returns {AxisAlignedBoundingBox} A new AxisAlignedBoundingBox instance.\n */\n clone() {\n return new AxisAlignedBoundingBox(this.minimum, this.maximum, this.center);\n }\n\n /**\n * Compares the provided AxisAlignedBoundingBox componentwise and returns\n * <code>true</code> if they are equal, <code>false</code> otherwise.\n *\n * @param {AxisAlignedBoundingBox} [right] The second AxisAlignedBoundingBox to compare with.\n * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.\n */\n equals(right) {\n return (\n this === right ||\n (Boolean(right) && this.minimum.equals(right.minimum) && this.maximum.equals(right.maximum))\n );\n }\n\n /**\n * Applies a 4x4 affine transformation matrix to a bounding sphere.\n * @param transform The transformation matrix to apply to the bounding sphere.\n * @returns itself, i.e. the modified BoundingVolume.\n */\n transform(transform: readonly number[]): this {\n this.center.transformAsPoint(transform);\n // TODO - this.halfDiagonal.transformAsVector(transform);\n this.halfDiagonal.transform(transform);\n this.minimum.transform(transform);\n this.maximum.transform(transform);\n return this;\n }\n\n /**\n * Determines which side of a plane a box is located.\n */\n intersectPlane(plane: Plane): INTERSECTION {\n const {halfDiagonal} = this;\n const normal = scratchNormal.from(plane.normal);\n const e =\n halfDiagonal.x * Math.abs(normal.x) +\n halfDiagonal.y * Math.abs(normal.y) +\n halfDiagonal.z * Math.abs(normal.z);\n const s = this.center.dot(normal) + plane.distance; // signed distance from center\n\n if (s - e > 0) {\n return INTERSECTION.INSIDE;\n }\n\n if (s + e < 0) {\n // Not in front because normals point inward\n return INTERSECTION.OUTSIDE;\n }\n\n return INTERSECTION.INTERSECTING;\n }\n\n /** Computes the estimated distance from the closest point on a bounding box to a point. */\n distanceTo(point: readonly number[]): number {\n return Math.sqrt(this.distanceSquaredTo(point));\n }\n\n /** Computes the estimated distance squared from the closest point on a bounding box to a point. */\n distanceSquaredTo(point: readonly number[]): number {\n const offset = scratchVector.from(point).subtract(this.center);\n const {halfDiagonal} = this;\n\n let distanceSquared = 0.0;\n let d;\n\n d = Math.abs(offset.x) - halfDiagonal.x;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.y) - halfDiagonal.y;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.z) - halfDiagonal.z;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n return distanceSquared;\n }\n}\n"],"file":"axis-aligned-bounding-box.js"}
|
|
@@ -2,16 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
4
|
|
|
5
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
8
|
exports.default = void 0;
|
|
11
9
|
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
11
|
|
|
16
12
|
var _core = require("@math.gl/core");
|
|
17
13
|
|
|
@@ -19,126 +15,113 @@ var mat4 = _interopRequireWildcard(require("gl-matrix/mat4"));
|
|
|
19
15
|
|
|
20
16
|
var _constants = require("../../constants");
|
|
21
17
|
|
|
22
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function
|
|
18
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
23
19
|
|
|
24
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null ||
|
|
20
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
25
21
|
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
const scratchVector = new _core.Vector3();
|
|
23
|
+
const scratchVector2 = new _core.Vector3();
|
|
28
24
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
(0, _classCallCheck2.default)(this, BoundingSphere);
|
|
25
|
+
class BoundingSphere {
|
|
26
|
+
constructor(center = [0, 0, 0], radius = 0.0) {
|
|
27
|
+
(0, _defineProperty2.default)(this, "center", void 0);
|
|
28
|
+
(0, _defineProperty2.default)(this, "radius", void 0);
|
|
34
29
|
this.radius = -0;
|
|
35
30
|
this.center = new _core.Vector3();
|
|
36
31
|
this.fromCenterRadius(center, radius);
|
|
37
32
|
}
|
|
38
33
|
|
|
39
|
-
(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return this;
|
|
45
|
-
}
|
|
46
|
-
}, {
|
|
47
|
-
key: "fromCornerPoints",
|
|
48
|
-
value: function fromCornerPoints(corner, oppositeCorner) {
|
|
49
|
-
oppositeCorner = scratchVector.from(oppositeCorner);
|
|
50
|
-
this.center = new _core.Vector3().from(corner).add(oppositeCorner).scale(0.5);
|
|
51
|
-
this.radius = this.center.distance(oppositeCorner);
|
|
52
|
-
return this;
|
|
53
|
-
}
|
|
54
|
-
}, {
|
|
55
|
-
key: "equals",
|
|
56
|
-
value: function equals(right) {
|
|
57
|
-
return this === right || Boolean(right) && this.center.equals(right.center) && this.radius === right.radius;
|
|
58
|
-
}
|
|
59
|
-
}, {
|
|
60
|
-
key: "clone",
|
|
61
|
-
value: function clone() {
|
|
62
|
-
return new BoundingSphere(this.center, this.radius);
|
|
63
|
-
}
|
|
64
|
-
}, {
|
|
65
|
-
key: "union",
|
|
66
|
-
value: function union(boundingSphere) {
|
|
67
|
-
var leftCenter = this.center;
|
|
68
|
-
var leftRadius = this.radius;
|
|
69
|
-
var rightCenter = boundingSphere.center;
|
|
70
|
-
var rightRadius = boundingSphere.radius;
|
|
71
|
-
var toRightCenter = scratchVector.copy(rightCenter).subtract(leftCenter);
|
|
72
|
-
var centerSeparation = toRightCenter.magnitude();
|
|
73
|
-
|
|
74
|
-
if (leftRadius >= centerSeparation + rightRadius) {
|
|
75
|
-
return this.clone();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (rightRadius >= centerSeparation + leftRadius) {
|
|
79
|
-
return boundingSphere.clone();
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
var halfDistanceBetweenTangentPoints = (leftRadius + centerSeparation + rightRadius) * 0.5;
|
|
83
|
-
scratchVector2.copy(toRightCenter).scale((-leftRadius + halfDistanceBetweenTangentPoints) / centerSeparation).add(leftCenter);
|
|
84
|
-
this.center.copy(scratchVector2);
|
|
85
|
-
this.radius = halfDistanceBetweenTangentPoints;
|
|
86
|
-
return this;
|
|
87
|
-
}
|
|
88
|
-
}, {
|
|
89
|
-
key: "expand",
|
|
90
|
-
value: function expand(point) {
|
|
91
|
-
point = scratchVector.from(point);
|
|
92
|
-
var radius = point.subtract(this.center).magnitude();
|
|
34
|
+
fromCenterRadius(center, radius) {
|
|
35
|
+
this.center.from(center);
|
|
36
|
+
this.radius = radius;
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
93
39
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
40
|
+
fromCornerPoints(corner, oppositeCorner) {
|
|
41
|
+
oppositeCorner = scratchVector.from(oppositeCorner);
|
|
42
|
+
this.center = new _core.Vector3().from(corner).add(oppositeCorner).scale(0.5);
|
|
43
|
+
this.radius = this.center.distance(oppositeCorner);
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
equals(right) {
|
|
48
|
+
return this === right || Boolean(right) && this.center.equals(right.center) && this.radius === right.radius;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
clone() {
|
|
52
|
+
return new BoundingSphere(this.center, this.radius);
|
|
53
|
+
}
|
|
97
54
|
|
|
98
|
-
|
|
55
|
+
union(boundingSphere) {
|
|
56
|
+
const leftCenter = this.center;
|
|
57
|
+
const leftRadius = this.radius;
|
|
58
|
+
const rightCenter = boundingSphere.center;
|
|
59
|
+
const rightRadius = boundingSphere.radius;
|
|
60
|
+
const toRightCenter = scratchVector.copy(rightCenter).subtract(leftCenter);
|
|
61
|
+
const centerSeparation = toRightCenter.magnitude();
|
|
62
|
+
|
|
63
|
+
if (leftRadius >= centerSeparation + rightRadius) {
|
|
64
|
+
return this.clone();
|
|
99
65
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
this.center.transform(_transform);
|
|
104
|
-
var scale = mat4.getScaling(scratchVector, _transform);
|
|
105
|
-
this.radius = Math.max(scale[0], Math.max(scale[1], scale[2])) * this.radius;
|
|
106
|
-
return this;
|
|
66
|
+
|
|
67
|
+
if (rightRadius >= centerSeparation + leftRadius) {
|
|
68
|
+
return boundingSphere.clone();
|
|
107
69
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
70
|
+
|
|
71
|
+
const halfDistanceBetweenTangentPoints = (leftRadius + centerSeparation + rightRadius) * 0.5;
|
|
72
|
+
scratchVector2.copy(toRightCenter).scale((-leftRadius + halfDistanceBetweenTangentPoints) / centerSeparation).add(leftCenter);
|
|
73
|
+
this.center.copy(scratchVector2);
|
|
74
|
+
this.radius = halfDistanceBetweenTangentPoints;
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
expand(point) {
|
|
79
|
+
const scratchPoint = scratchVector.from(point);
|
|
80
|
+
const radius = scratchPoint.subtract(this.center).magnitude();
|
|
81
|
+
|
|
82
|
+
if (radius > this.radius) {
|
|
83
|
+
this.radius = radius;
|
|
113
84
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
85
|
+
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
transform(transform) {
|
|
90
|
+
this.center.transform(transform);
|
|
91
|
+
const scale = mat4.getScaling(scratchVector, transform);
|
|
92
|
+
this.radius = Math.max(scale[0], Math.max(scale[1], scale[2])) * this.radius;
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
distanceSquaredTo(point) {
|
|
97
|
+
const d = this.distanceTo(point);
|
|
98
|
+
return d * d;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
distanceTo(point) {
|
|
102
|
+
const scratchPoint = scratchVector.from(point);
|
|
103
|
+
const delta = scratchPoint.subtract(this.center);
|
|
104
|
+
return Math.max(0, delta.len() - this.radius);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
intersectPlane(plane) {
|
|
108
|
+
const center = this.center;
|
|
109
|
+
const radius = this.radius;
|
|
110
|
+
const normal = plane.normal;
|
|
111
|
+
const distanceToPlane = normal.dot(center) + plane.distance;
|
|
112
|
+
|
|
113
|
+
if (distanceToPlane < -radius) {
|
|
114
|
+
return _constants.INTERSECTION.OUTSIDE;
|
|
120
115
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
var center = this.center;
|
|
125
|
-
var radius = this.radius;
|
|
126
|
-
var normal = plane.normal;
|
|
127
|
-
var distanceToPlane = normal.dot(center) + plane.distance;
|
|
128
|
-
|
|
129
|
-
if (distanceToPlane < -radius) {
|
|
130
|
-
return _constants.INTERSECTION.OUTSIDE;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (distanceToPlane < radius) {
|
|
134
|
-
return _constants.INTERSECTION.INTERSECTING;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return _constants.INTERSECTION.INSIDE;
|
|
116
|
+
|
|
117
|
+
if (distanceToPlane < radius) {
|
|
118
|
+
return _constants.INTERSECTION.INTERSECTING;
|
|
138
119
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
120
|
+
|
|
121
|
+
return _constants.INTERSECTION.INSIDE;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
}
|
|
142
125
|
|
|
143
126
|
exports.default = BoundingSphere;
|
|
144
127
|
//# sourceMappingURL=bounding-sphere.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/bounding-volumes/bounding-sphere.
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/bounding-volumes/bounding-sphere.ts"],"names":["scratchVector","Vector3","scratchVector2","BoundingSphere","constructor","center","radius","fromCenterRadius","from","fromCornerPoints","corner","oppositeCorner","add","scale","distance","equals","right","Boolean","clone","union","boundingSphere","leftCenter","leftRadius","rightCenter","rightRadius","toRightCenter","copy","subtract","centerSeparation","magnitude","halfDistanceBetweenTangentPoints","expand","point","scratchPoint","transform","mat4","getScaling","Math","max","distanceSquaredTo","d","distanceTo","delta","len","intersectPlane","plane","normal","distanceToPlane","dot","INTERSECTION","OUTSIDE","INTERSECTING","INSIDE"],"mappings":";;;;;;;;;;;AAGA;;AACA;;AACA;;;;;;AAIA,MAAMA,aAAa,GAAG,IAAIC,aAAJ,EAAtB;AACA,MAAMC,cAAc,GAAG,IAAID,aAAJ,EAAvB;;AAGe,MAAME,cAAN,CAA+C;AAK5DC,EAAAA,WAAW,CAACC,MAAyB,GAAG,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAA7B,EAAwCC,MAAc,GAAG,GAAzD,EAA8D;AAAA;AAAA;AACvE,SAAKA,MAAL,GAAc,CAAC,CAAf;AACA,SAAKD,MAAL,GAAc,IAAIJ,aAAJ,EAAd;AACA,SAAKM,gBAAL,CAAs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tE;AACA,WAAO,IAAP;AACD;;AAGDiC,EAAAA,iBAAiB,CAACP,KAAD,EAAwC;AACvD,UAAMQ,CAAC,GAAG,KAAKC,UAAL,CAAgBT,KAAhB,CAAV;AACA,WAAOQ,CAAC,GAAGA,CAAX;AACD;;AAGDC,EAAAA,UAAU,CAACT,KAAD,EAAwC;AAChD,UAAMC,YAAY,GAAGjC,aAAa,CAACQ,IAAd,CAAmBwB,KAAnB,CAArB;AACA,UAAMU,KAAK,GAAGT,YAAY,CAACN,QAAb,CAAsB,KAAKtB,MAA3B,CAAd;AACA,WAAOgC,IAAI,CAACC,GAAL,CAAS,CAAT,EAAYI,KAAK,CAACC,GAAN,KAAc,KAAKrC,MAA/B,CAAP;AACD;;AAGDsC,EAAAA,cAAc,CAACC,KAAD,EAA6B;AACzC,UAAMxC,MAAM,GAAG,KAAKA,MAApB;AACA,UAAMC,MAAM,GAAG,KAAKA,MAApB;AACA,UAAMwC,MAAM,GAAGD,KAAK,CAACC,MAArB;AACA,UAAMC,eAAe,GAAGD,MAAM,CAACE,GAAP,CAAW3C,MAAX,IAAqBwC,KAAK,CAAC/B,QAAnD;;AAGA,QAAIiC,eAAe,GAAG,CAACzC,MAAvB,EAA+B;AAC7B,aAAO2C,wBAAaC,OAApB;AACD;;AAED,QAAIH,eAAe,GAAGzC,MAAtB,EAA8B;AAC5B,aAAO2C,wBAAaE,YAApB;AACD;;AAED,WAAOF,wBAAaG,MAApB;AACD;;AApI2D","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 {NumericArray, Vector3} from '@math.gl/core';\nimport * as mat4 from 'gl-matrix/mat4';\nimport {INTERSECTION} from '../../constants';\nimport {BoundingVolume} from './bounding-volume';\nimport Plane from '../plane';\n\nconst scratchVector = new Vector3();\nconst scratchVector2 = new Vector3();\n\n/** A BoundingSphere */\nexport default class BoundingSphere implements BoundingVolume {\n center: Vector3;\n radius: number;\n\n /** Creates a bounding sphere */\n constructor(center: readonly number[] = [0, 0, 0], radius: number = 0.0) {\n this.radius = -0;\n this.center = new Vector3();\n this.fromCenterRadius(center, radius);\n }\n\n /** Sets the bounding sphere from `center` and `radius`. */\n fromCenterRadius(center: readonly number[], radius: number): this {\n this.center.from(center);\n this.radius = radius;\n return this;\n }\n\n /**\n * Computes a bounding sphere from the corner points of an axis-aligned bounding box. The sphere\n * tightly and fully encompasses the box.\n */\n fromCornerPoints(corner: readonly number[], oppositeCorner: readonly number[]): this {\n oppositeCorner = scratchVector.from(oppositeCorner);\n this.center = new Vector3().from(corner).add(oppositeCorner).scale(0.5);\n this.radius = this.center.distance(oppositeCorner);\n return this;\n }\n\n /** Compares the provided BoundingSphere component wise */\n equals(right: BoundingSphere): boolean {\n return (\n this === right ||\n (Boolean(right) && this.center.equals(right.center) && this.radius === right.radius)\n );\n }\n\n /** Duplicates a BoundingSphere instance. */\n clone(): BoundingSphere {\n return new BoundingSphere(this.center, this.radius);\n }\n\n /** Computes a bounding sphere that contains both the left and right bounding spheres. */\n union(boundingSphere: BoundingSphere): BoundingSphere {\n const leftCenter = this.center;\n const leftRadius = this.radius;\n const rightCenter = boundingSphere.center;\n const rightRadius = boundingSphere.radius;\n\n const toRightCenter = scratchVector.copy(rightCenter).subtract(leftCenter);\n const centerSeparation = toRightCenter.magnitude();\n\n if (leftRadius >= centerSeparation + rightRadius) {\n // Left sphere wins.\n return this.clone();\n }\n\n if (rightRadius >= centerSeparation + leftRadius) {\n // Right sphere wins.\n return boundingSphere.clone();\n }\n\n // There are two tangent points, one on far side of each sphere.\n const halfDistanceBetweenTangentPoints = (leftRadius + centerSeparation + rightRadius) * 0.5;\n\n // Compute the center point halfway between the two tangent points.\n scratchVector2\n .copy(toRightCenter)\n .scale((-leftRadius + halfDistanceBetweenTangentPoints) / centerSeparation)\n .add(leftCenter);\n\n this.center.copy(scratchVector2);\n this.radius = halfDistanceBetweenTangentPoints;\n\n return this;\n }\n\n /** Computes a bounding sphere by enlarging the provided sphere to contain the provided point. */\n expand(point: readonly number[]): this {\n const scratchPoint = scratchVector.from(point);\n const radius = scratchPoint.subtract(this.center).magnitude();\n if (radius > this.radius) {\n this.radius = radius;\n }\n return this;\n }\n\n // BoundingVolume interface\n\n /**\n * Applies a 4x4 affine transformation matrix to a bounding sphere.\n * @param sphere The bounding sphere to apply the transformation to.\n * @param transform The transformation matrix to apply to the bounding sphere.\n * @returns self.\n */\n transform(transform: readonly number[]): this {\n this.center.transform(transform);\n const scale = mat4.getScaling(scratchVector, transform);\n this.radius = Math.max(scale[0], Math.max(scale[1], scale[2])) * this.radius;\n return this;\n }\n\n /** Computes the estimated distance squared from the closest point on a bounding sphere to a point. */\n distanceSquaredTo(point: Readonly<NumericArray>): number {\n const d = this.distanceTo(point);\n return d * d;\n }\n\n /** Computes the estimated distance from the closest point on a bounding sphere to a point. */\n distanceTo(point: Readonly<NumericArray>): number {\n const scratchPoint = scratchVector.from(point);\n const delta = scratchPoint.subtract(this.center);\n return Math.max(0, delta.len() - this.radius);\n }\n\n /** Determines which side of a plane a sphere is located. */\n intersectPlane(plane: Plane): INTERSECTION {\n const center = this.center;\n const radius = this.radius;\n const normal = plane.normal;\n const distanceToPlane = normal.dot(center) + plane.distance;\n\n // The center point is negative side of the plane normal\n if (distanceToPlane < -radius) {\n return INTERSECTION.OUTSIDE;\n }\n // The center point is positive side of the plane, but radius extends beyond it; partial overlap\n if (distanceToPlane < radius) {\n return INTERSECTION.INTERSECTING;\n }\n // The center point and radius is positive side of the plane\n return INTERSECTION.INSIDE;\n }\n}\n"],"file":"bounding-sphere.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"bounding-volume.js"}
|