@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.
Files changed (27) hide show
  1. package/dist/es5/constants.js +1 -1
  2. package/dist/es5/index.js +12 -12
  3. package/dist/es5/lib/algorithms/bounding-box-from-points.js +123 -72
  4. package/dist/es5/lib/algorithms/bounding-box-from-points.js.map +1 -1
  5. package/dist/es5/lib/algorithms/bounding-sphere-from-points.js +109 -81
  6. package/dist/es5/lib/algorithms/bounding-sphere-from-points.js.map +1 -1
  7. package/dist/es5/lib/algorithms/compute-eigen-decomposition.js +37 -36
  8. package/dist/es5/lib/algorithms/compute-eigen-decomposition.js.map +1 -1
  9. package/dist/es5/lib/bounding-volumes/axis-aligned-bounding-box.js +75 -63
  10. package/dist/es5/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -1
  11. package/dist/es5/lib/bounding-volumes/bounding-sphere.js +111 -90
  12. package/dist/es5/lib/bounding-volumes/bounding-sphere.js.map +1 -1
  13. package/dist/es5/lib/bounding-volumes/oriented-bounding-box.js +212 -187
  14. package/dist/es5/lib/bounding-volumes/oriented-bounding-box.js.map +1 -1
  15. package/dist/es5/lib/culling-volume.js +111 -74
  16. package/dist/es5/lib/culling-volume.js.map +1 -1
  17. package/dist/es5/lib/perspective-frustum.js +78 -57
  18. package/dist/es5/lib/perspective-frustum.js.map +1 -1
  19. package/dist/es5/lib/perspective-off-center-frustum.js +113 -98
  20. package/dist/es5/lib/perspective-off-center-frustum.js.map +1 -1
  21. package/dist/es5/lib/plane.js +70 -52
  22. package/dist/es5/lib/plane.js.map +1 -1
  23. package/dist/esm/lib/algorithms/bounding-sphere-from-points.js.map +1 -1
  24. package/dist/lib/algorithms/bounding-sphere-from-points.d.ts.map +1 -1
  25. package/dist/lib/algorithms/bounding-sphere-from-points.js +0 -2
  26. package/package.json +4 -4
  27. package/src/lib/algorithms/bounding-sphere-from-points.ts +0 -2
@@ -2,11 +2,17 @@
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
 
5
+ var _typeof = require("@babel/runtime/helpers/typeof");
6
+
5
7
  Object.defineProperty(exports, "__esModule", {
6
8
  value: true
7
9
  });
8
10
  exports.default = void 0;
9
11
 
12
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
13
+
14
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
15
+
10
16
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
17
 
12
18
  var _core = require("@math.gl/core");
@@ -15,15 +21,18 @@ var mat4 = _interopRequireWildcard(require("gl-matrix/mat4"));
15
21
 
16
22
  var _constants = require("../../constants");
17
23
 
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); }
24
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
19
25
 
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; }
26
+ 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; }
21
27
 
22
- const scratchVector = new _core.Vector3();
23
- const scratchVector2 = new _core.Vector3();
28
+ var scratchVector = new _core.Vector3();
29
+ var scratchVector2 = new _core.Vector3();
24
30
 
25
- class BoundingSphere {
26
- constructor(center = [0, 0, 0], radius = 0.0) {
31
+ var BoundingSphere = function () {
32
+ function BoundingSphere() {
33
+ var center = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [0, 0, 0];
34
+ var radius = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.0;
35
+ (0, _classCallCheck2.default)(this, BoundingSphere);
27
36
  (0, _defineProperty2.default)(this, "center", void 0);
28
37
  (0, _defineProperty2.default)(this, "radius", void 0);
29
38
  this.radius = -0;
@@ -31,97 +40,109 @@ class BoundingSphere {
31
40
  this.fromCenterRadius(center, radius);
32
41
  }
33
42
 
34
- fromCenterRadius(center, radius) {
35
- this.center.from(center);
36
- this.radius = radius;
37
- return this;
38
- }
39
-
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
- }
54
-
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();
43
+ (0, _createClass2.default)(BoundingSphere, [{
44
+ key: "fromCenterRadius",
45
+ value: function fromCenterRadius(center, radius) {
46
+ this.center.from(center);
47
+ this.radius = radius;
48
+ return this;
65
49
  }
66
-
67
- if (rightRadius >= centerSeparation + leftRadius) {
68
- return boundingSphere.clone();
50
+ }, {
51
+ key: "fromCornerPoints",
52
+ value: function fromCornerPoints(corner, oppositeCorner) {
53
+ oppositeCorner = scratchVector.from(oppositeCorner);
54
+ this.center = new _core.Vector3().from(corner).add(oppositeCorner).scale(0.5);
55
+ this.radius = this.center.distance(oppositeCorner);
56
+ return this;
69
57
  }
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;
58
+ }, {
59
+ key: "equals",
60
+ value: function equals(right) {
61
+ return this === right || Boolean(right) && this.center.equals(right.center) && this.radius === right.radius;
84
62
  }
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;
63
+ }, {
64
+ key: "clone",
65
+ value: function clone() {
66
+ return new BoundingSphere(this.center, this.radius);
115
67
  }
116
-
117
- if (distanceToPlane < radius) {
118
- return _constants.INTERSECTION.INTERSECTING;
68
+ }, {
69
+ key: "union",
70
+ value: function union(boundingSphere) {
71
+ var leftCenter = this.center;
72
+ var leftRadius = this.radius;
73
+ var rightCenter = boundingSphere.center;
74
+ var rightRadius = boundingSphere.radius;
75
+ var toRightCenter = scratchVector.copy(rightCenter).subtract(leftCenter);
76
+ var centerSeparation = toRightCenter.magnitude();
77
+
78
+ if (leftRadius >= centerSeparation + rightRadius) {
79
+ return this.clone();
80
+ }
81
+
82
+ if (rightRadius >= centerSeparation + leftRadius) {
83
+ return boundingSphere.clone();
84
+ }
85
+
86
+ var halfDistanceBetweenTangentPoints = (leftRadius + centerSeparation + rightRadius) * 0.5;
87
+ scratchVector2.copy(toRightCenter).scale((-leftRadius + halfDistanceBetweenTangentPoints) / centerSeparation).add(leftCenter);
88
+ this.center.copy(scratchVector2);
89
+ this.radius = halfDistanceBetweenTangentPoints;
90
+ return this;
119
91
  }
92
+ }, {
93
+ key: "expand",
94
+ value: function expand(point) {
95
+ var scratchPoint = scratchVector.from(point);
96
+ var radius = scratchPoint.subtract(this.center).magnitude();
120
97
 
121
- return _constants.INTERSECTION.INSIDE;
122
- }
98
+ if (radius > this.radius) {
99
+ this.radius = radius;
100
+ }
123
101
 
124
- }
102
+ return this;
103
+ }
104
+ }, {
105
+ key: "transform",
106
+ value: function transform(_transform) {
107
+ this.center.transform(_transform);
108
+ var scale = mat4.getScaling(scratchVector, _transform);
109
+ this.radius = Math.max(scale[0], Math.max(scale[1], scale[2])) * this.radius;
110
+ return this;
111
+ }
112
+ }, {
113
+ key: "distanceSquaredTo",
114
+ value: function distanceSquaredTo(point) {
115
+ var d = this.distanceTo(point);
116
+ return d * d;
117
+ }
118
+ }, {
119
+ key: "distanceTo",
120
+ value: function distanceTo(point) {
121
+ var scratchPoint = scratchVector.from(point);
122
+ var delta = scratchPoint.subtract(this.center);
123
+ return Math.max(0, delta.len() - this.radius);
124
+ }
125
+ }, {
126
+ key: "intersectPlane",
127
+ value: function intersectPlane(plane) {
128
+ var center = this.center;
129
+ var radius = this.radius;
130
+ var normal = plane.normal;
131
+ var distanceToPlane = normal.dot(center) + plane.distance;
132
+
133
+ if (distanceToPlane < -radius) {
134
+ return _constants.INTERSECTION.OUTSIDE;
135
+ }
136
+
137
+ if (distanceToPlane < radius) {
138
+ return _constants.INTERSECTION.INTERSECTING;
139
+ }
140
+
141
+ return _constants.INTERSECTION.INSIDE;
142
+ }
143
+ }]);
144
+ return BoundingSphere;
145
+ }();
125
146
 
126
147
  exports.default = BoundingSphere;
127
148
  //# sourceMappingURL=bounding-sphere.js.map
@@ -1 +1 @@
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","distanceToP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D;;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"}
1
+ {"version":3,"sources":["../../../../src/lib/bounding-volumes/bounding-sphere.ts"],"names":["scratchVector","Vector3","scratchVector2","BoundingSphere","center","radius","fromCenterRadius","from","corner","oppositeCorner","add","scale","distance","right","Boolean","equals","boundingSphere","leftCenter","leftRadius","rightCenter","rightRadius","toRightCenter","copy","subtract","centerSeparation","magnitude","clone","halfDistanceBetweenTangentPoints","point","scratchPoint","transform","mat4","getScaling","Math","max","d","distanceTo","delta","len","plane","normal","distanceToPlane","dot","INTERSECTION","OUTSIDE","INTERSECTING","INSIDE"],"mappings":";;;;;;;;;;;;;;;;;AAGA;;AACA;;AACA;;;;;;AAIA,IAAMA,aAAa,GAAG,IAAIC,aAAJ,EAAtB;AACA,IAAMC,cAAc,GAAG,IAAID,aAAJ,EAAvB;;IAGqBE,c;AAKnB,4BAAyE;AAAA,QAA7DC,MAA6D,uEAAjC,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAiC;AAAA,QAAtBC,MAAsB,uEAAL,GAAK;AAAA;AAAA;AAAA;AACvE,SAAKA,MAAL,GAAc,CAAC,CAAf;AACA,SAAKD,MAAL,GAAc,IAAIH,aAAJ,EAAd;AACA,SAAKK,gBAAL,CAAsBF,MAAtB,EAA8BC,MAA9B;AACD;;;;WAGD,0BAAiBD,MAAjB,EAA4CC,MAA5C,EAAkE;AAChE,WAAKD,MAAL,CAAYG,IAAZ,CAAiBH,MAAjB;AACA,WAAKC,MAAL,GAAcA,MAAd;AACA,aAAO,IAAP;AACD;;;WAMD,0BAAiBG,MAAjB,EAA4CC,cAA5C,EAAqF;AACnFA,MAAAA,cAAc,GAAGT,aAAa,CAAC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,CAAS,CAAT,EAAYG,KAAK,CAACC,GAAN,KAAc,KAAKjC,MAA/B,CAAP;AACD;;;WAGD,wBAAekC,KAAf,EAA2C;AACzC,UAAMnC,MAAM,GAAG,KAAKA,MAApB;AACA,UAAMC,MAAM,GAAG,KAAKA,MAApB;AACA,UAAMmC,MAAM,GAAGD,KAAK,CAACC,MAArB;AACA,UAAMC,eAAe,GAAGD,MAAM,CAACE,GAAP,CAAWtC,MAAX,IAAqBmC,KAAK,CAAC3B,QAAnD;;AAGA,UAAI6B,eAAe,GAAG,CAACpC,MAAvB,EAA+B;AAC7B,eAAOsC,wBAAaC,OAApB;AACD;;AAED,UAAIH,eAAe,GAAGpC,MAAtB,EAA8B;AAC5B,eAAOsC,wBAAaE,YAApB;AACD;;AAED,aAAOF,wBAAaG,MAApB;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 {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"}