@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
@@ -7,6 +7,10 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.default = void 0;
9
9
 
10
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
+
12
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
+
10
14
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
15
 
12
16
  var _core = require("@math.gl/core");
@@ -15,14 +19,20 @@ var _cullingVolume = _interopRequireDefault(require("./culling-volume"));
15
19
 
16
20
  var _plane = _interopRequireDefault(require("./plane"));
17
21
 
18
- const scratchPlaneUpVector = new _core.Vector3();
19
- const scratchPlaneRightVector = new _core.Vector3();
20
- const scratchPlaneNearCenter = new _core.Vector3();
21
- const scratchPlaneFarCenter = new _core.Vector3();
22
- const scratchPlaneNormal = new _core.Vector3();
22
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
23
+
24
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
23
25
 
24
- class PerspectiveOffCenterFrustum {
25
- constructor(options = {}) {
26
+ var scratchPlaneUpVector = new _core.Vector3();
27
+ var scratchPlaneRightVector = new _core.Vector3();
28
+ var scratchPlaneNearCenter = new _core.Vector3();
29
+ var scratchPlaneFarCenter = new _core.Vector3();
30
+ var scratchPlaneNormal = new _core.Vector3();
31
+
32
+ var PerspectiveOffCenterFrustum = function () {
33
+ function PerspectiveOffCenterFrustum() {
34
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
35
+ (0, _classCallCheck2.default)(this, PerspectiveOffCenterFrustum);
26
36
  (0, _defineProperty2.default)(this, "left", void 0);
27
37
  (0, _defineProperty2.default)(this, "_left", void 0);
28
38
  (0, _defineProperty2.default)(this, "right", void 0);
@@ -38,11 +48,10 @@ class PerspectiveOffCenterFrustum {
38
48
  (0, _defineProperty2.default)(this, "_cullingVolume", new _cullingVolume.default([new _plane.default(), new _plane.default(), new _plane.default(), new _plane.default(), new _plane.default(), new _plane.default()]));
39
49
  (0, _defineProperty2.default)(this, "_perspectiveMatrix", new _core.Matrix4());
40
50
  (0, _defineProperty2.default)(this, "_infinitePerspective", new _core.Matrix4());
41
- options = {
51
+ options = _objectSpread({
42
52
  near: 1.0,
43
- far: 500000000.0,
44
- ...options
45
- };
53
+ far: 500000000.0
54
+ }, options);
46
55
  this.left = options.left;
47
56
  this._left = undefined;
48
57
  this.right = options.right;
@@ -57,87 +66,93 @@ class PerspectiveOffCenterFrustum {
57
66
  this._far = this.far;
58
67
  }
59
68
 
60
- clone() {
61
- return new PerspectiveOffCenterFrustum({
62
- right: this.right,
63
- left: this.left,
64
- top: this.top,
65
- bottom: this.bottom,
66
- near: this.near,
67
- far: this.far
68
- });
69
- }
70
-
71
- equals(other) {
72
- return other && other instanceof PerspectiveOffCenterFrustum && this.right === other.right && this.left === other.left && this.top === other.top && this.bottom === other.bottom && this.near === other.near && this.far === other.far;
73
- }
74
-
75
- get projectionMatrix() {
76
- update(this);
77
- return this._perspectiveMatrix;
78
- }
79
-
80
- get infiniteProjectionMatrix() {
81
- update(this);
82
- return this._infinitePerspective;
83
- }
84
-
85
- computeCullingVolume(position, direction, up) {
86
- (0, _core.assert)(position, 'position is required.');
87
- (0, _core.assert)(direction, 'direction is required.');
88
- (0, _core.assert)(up, 'up is required.');
89
- const planes = this._cullingVolume.planes;
90
- up = scratchPlaneUpVector.copy(up).normalize();
91
- const right = scratchPlaneRightVector.copy(direction).cross(up).normalize();
92
- const nearCenter = scratchPlaneNearCenter.copy(direction).multiplyByScalar(this.near).add(position);
93
- const farCenter = scratchPlaneFarCenter.copy(direction).multiplyByScalar(this.far).add(position);
94
- let normal = scratchPlaneNormal;
95
- normal.copy(right).multiplyByScalar(this.left).add(nearCenter).subtract(position).cross(up);
96
- planes[0].fromPointNormal(position, normal);
97
- normal.copy(right).multiplyByScalar(this.right).add(nearCenter).subtract(position).cross(up).negate();
98
- planes[1].fromPointNormal(position, normal);
99
- normal.copy(up).multiplyByScalar(this.bottom).add(nearCenter).subtract(position).cross(right).negate();
100
- planes[2].fromPointNormal(position, normal);
101
- normal.copy(up).multiplyByScalar(this.top).add(nearCenter).subtract(position).cross(right);
102
- planes[3].fromPointNormal(position, normal);
103
- normal = new _core.Vector3().copy(direction);
104
- planes[4].fromPointNormal(nearCenter, normal);
105
- normal.negate();
106
- planes[5].fromPointNormal(farCenter, normal);
107
- return this._cullingVolume;
108
- }
109
-
110
- getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {
111
- update(this);
112
- (0, _core.assert)(Number.isFinite(drawingBufferWidth) && Number.isFinite(drawingBufferHeight));
113
- (0, _core.assert)(drawingBufferWidth > 0);
114
- (0, _core.assert)(drawingBufferHeight > 0);
115
- (0, _core.assert)(distance > 0);
116
- (0, _core.assert)(result);
117
- const inverseNear = 1.0 / this.near;
118
- let tanTheta = this.top * inverseNear;
119
- const pixelHeight = 2.0 * distance * tanTheta / drawingBufferHeight;
120
- tanTheta = this.right * inverseNear;
121
- const pixelWidth = 2.0 * distance * tanTheta / drawingBufferWidth;
122
- result.x = pixelWidth;
123
- result.y = pixelHeight;
124
- return result;
125
- }
126
-
127
- }
69
+ (0, _createClass2.default)(PerspectiveOffCenterFrustum, [{
70
+ key: "clone",
71
+ value: function clone() {
72
+ return new PerspectiveOffCenterFrustum({
73
+ right: this.right,
74
+ left: this.left,
75
+ top: this.top,
76
+ bottom: this.bottom,
77
+ near: this.near,
78
+ far: this.far
79
+ });
80
+ }
81
+ }, {
82
+ key: "equals",
83
+ value: function equals(other) {
84
+ return other && other instanceof PerspectiveOffCenterFrustum && this.right === other.right && this.left === other.left && this.top === other.top && this.bottom === other.bottom && this.near === other.near && this.far === other.far;
85
+ }
86
+ }, {
87
+ key: "projectionMatrix",
88
+ get: function get() {
89
+ update(this);
90
+ return this._perspectiveMatrix;
91
+ }
92
+ }, {
93
+ key: "infiniteProjectionMatrix",
94
+ get: function get() {
95
+ update(this);
96
+ return this._infinitePerspective;
97
+ }
98
+ }, {
99
+ key: "computeCullingVolume",
100
+ value: function computeCullingVolume(position, direction, up) {
101
+ (0, _core.assert)(position, 'position is required.');
102
+ (0, _core.assert)(direction, 'direction is required.');
103
+ (0, _core.assert)(up, 'up is required.');
104
+ var planes = this._cullingVolume.planes;
105
+ up = scratchPlaneUpVector.copy(up).normalize();
106
+ var right = scratchPlaneRightVector.copy(direction).cross(up).normalize();
107
+ var nearCenter = scratchPlaneNearCenter.copy(direction).multiplyByScalar(this.near).add(position);
108
+ var farCenter = scratchPlaneFarCenter.copy(direction).multiplyByScalar(this.far).add(position);
109
+ var normal = scratchPlaneNormal;
110
+ normal.copy(right).multiplyByScalar(this.left).add(nearCenter).subtract(position).cross(up);
111
+ planes[0].fromPointNormal(position, normal);
112
+ normal.copy(right).multiplyByScalar(this.right).add(nearCenter).subtract(position).cross(up).negate();
113
+ planes[1].fromPointNormal(position, normal);
114
+ normal.copy(up).multiplyByScalar(this.bottom).add(nearCenter).subtract(position).cross(right).negate();
115
+ planes[2].fromPointNormal(position, normal);
116
+ normal.copy(up).multiplyByScalar(this.top).add(nearCenter).subtract(position).cross(right);
117
+ planes[3].fromPointNormal(position, normal);
118
+ normal = new _core.Vector3().copy(direction);
119
+ planes[4].fromPointNormal(nearCenter, normal);
120
+ normal.negate();
121
+ planes[5].fromPointNormal(farCenter, normal);
122
+ return this._cullingVolume;
123
+ }
124
+ }, {
125
+ key: "getPixelDimensions",
126
+ value: function getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {
127
+ update(this);
128
+ (0, _core.assert)(Number.isFinite(drawingBufferWidth) && Number.isFinite(drawingBufferHeight));
129
+ (0, _core.assert)(drawingBufferWidth > 0);
130
+ (0, _core.assert)(drawingBufferHeight > 0);
131
+ (0, _core.assert)(distance > 0);
132
+ (0, _core.assert)(result);
133
+ var inverseNear = 1.0 / this.near;
134
+ var tanTheta = this.top * inverseNear;
135
+ var pixelHeight = 2.0 * distance * tanTheta / drawingBufferHeight;
136
+ tanTheta = this.right * inverseNear;
137
+ var pixelWidth = 2.0 * distance * tanTheta / drawingBufferWidth;
138
+ result.x = pixelWidth;
139
+ result.y = pixelHeight;
140
+ return result;
141
+ }
142
+ }]);
143
+ return PerspectiveOffCenterFrustum;
144
+ }();
128
145
 
129
146
  exports.default = PerspectiveOffCenterFrustum;
130
147
 
131
148
  function update(frustum) {
132
149
  (0, _core.assert)(Number.isFinite(frustum.right) && Number.isFinite(frustum.left) && Number.isFinite(frustum.top) && Number.isFinite(frustum.bottom) && Number.isFinite(frustum.near) && Number.isFinite(frustum.far));
133
- const {
134
- top,
135
- bottom,
136
- right,
137
- left,
138
- near,
139
- far
140
- } = frustum;
150
+ var top = frustum.top,
151
+ bottom = frustum.bottom,
152
+ right = frustum.right,
153
+ left = frustum.left,
154
+ near = frustum.near,
155
+ far = frustum.far;
141
156
 
142
157
  if (top !== frustum._top || bottom !== frustum._bottom || left !== frustum._left || right !== frustum._right || near !== frustum._near || far !== frustum._far) {
143
158
  (0, _core.assert)(frustum.near > 0 && frustum.near < frustum.far, 'near must be greater than zero and less than far.');
@@ -148,19 +163,19 @@ function update(frustum) {
148
163
  frustum._near = near;
149
164
  frustum._far = far;
150
165
  frustum._perspectiveMatrix = new _core.Matrix4().frustum({
151
- left,
152
- right,
153
- bottom,
154
- top,
155
- near,
156
- far
166
+ left: left,
167
+ right: right,
168
+ bottom: bottom,
169
+ top: top,
170
+ near: near,
171
+ far: far
157
172
  });
158
173
  frustum._infinitePerspective = new _core.Matrix4().frustum({
159
- left,
160
- right,
161
- bottom,
162
- top,
163
- near,
174
+ left: left,
175
+ right: right,
176
+ bottom: bottom,
177
+ top: top,
178
+ near: near,
164
179
  far: Infinity
165
180
  });
166
181
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/perspective-off-center-frustum.ts"],"names":["scratchPlaneUpVector","Vector3","scratchPlaneRightVector","scratchPlaneNearCenter","scratchPlaneFarCenter","scratchPlaneNormal","PerspectiveOffCenterFrustum","constructor","options","CullingVolume","Plane","Matrix4","near","far","left","_left","undefined","right","_right","top","_top","bottom","_bottom","_near","_far","clone","equals","other","projectionMatrix","update","_perspectiveMatrix","infiniteProjectionMatrix","_infinitePerspective","computeCullingVolume","position","direction","up","planes","_cullingVolume","copy","normalize","cross","nearCenter","multiplyByScalar","add","farCenter","normal","subtract","fromPointNormal","negate","getPixelDimensions","drawingBufferWidth","drawingBufferHeight","distance","result","Number","isFinite","inverseNear","tanTheta","pixelHeight","pixelWidth","x","y","frustum","Infinity"],"mappings":";;;;;;;;;;;AASA;;AACA;;AACA;;AAEA,MAAMA,oBAAoB,GAAG,IAAIC,aAAJ,EAA7B;AACA,MAAMC,uBAAuB,GAAG,IAAID,aAAJ,EAAhC;AACA,MAAME,sBAAsB,GAAG,IAAIF,aAAJ,EAA/B;AACA,MAAMG,qBAAqB,GAAG,IAAIH,aAAJ,EAA9B;AACA,MAAMI,kBAAkB,GAAG,IAAIJ,aAAJ,EAA3B;;AAEe,MAAMK,2BAAN,CAAkC;AAqD/CC,EAAAA,WAAW,CAACC,OAA4B,GAAG,EAAhC,EAAoC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0DAxC9B,IAAIC,sBAAJ,CAAkB,CACjC,IAAIC,cAAJ,EADiC,EAEjC,IAAIA,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D,MAAAA,IADmD;AAEnDG,MAAAA,KAFmD;AAGnDI,MAAAA,MAHmD;AAInDF,MAAAA,GAJmD;AAKnDP,MAAAA,IALmD;AAMnDC,MAAAA,GAAG,EAAEmD;AAN8C,KAAtB,CAA/B;AAQD;AACF","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\n// Note: This class is still an experimental export, mainly used by other test cases\n// - It has not been fully adapted to math.gl conventions\n// - Documentation has not been ported\n\n// @ts-nocheck\n\nimport {Vector3, Matrix4, assert} from '@math.gl/core';\nimport CullingVolume from './culling-volume';\nimport Plane from './plane';\n\nconst scratchPlaneUpVector = new Vector3();\nconst scratchPlaneRightVector = new Vector3();\nconst scratchPlaneNearCenter = new Vector3();\nconst scratchPlaneFarCenter = new Vector3();\nconst scratchPlaneNormal = new Vector3();\n\nexport default class PerspectiveOffCenterFrustum {\n left;\n _left;\n right;\n _right;\n top;\n _top;\n bottom;\n _bottom;\n near;\n _near;\n far;\n _far;\n _cullingVolume = new CullingVolume([\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane()\n ]);\n _perspectiveMatrix = new Matrix4();\n _infinitePerspective = new Matrix4();\n\n /**\n * The viewing frustum is defined by 6 planes.\n * Each plane is represented by a {@link Vector4} object, where the x, y, and z components\n * define the unit vector normal to the plane, and the w component is the distance of the\n * plane from the origin/camera position.\n *\n * @alias PerspectiveOffCenterFrustum\n * @constructor\n *\n * @param {Object} [options] An object with the following properties:\n * @param {Number} [options.left] The left clipping plane distance.\n * @param {Number} [options.right] The right clipping plane distance.\n * @param {Number} [options.top] The top clipping plane distance.\n * @param {Number} [options.bottom] The bottom clipping plane distance.\n * @param {Number} [options.near=1.0] The near clipping plane distance.\n * @param {Number} [options.far=500000000.0] The far clipping plane distance.\n *\n * @example\n * const frustum = new PerspectiveOffCenterFrustum({\n * left : -1.0,\n * right : 1.0,\n * top : 1.0,\n * bottom : -1.0,\n * near : 1.0,\n * far : 100.0\n * });\n *\n * @see PerspectiveFrustum\n */\n constructor(options: Record<string, any> = {}) {\n options = {near: 1.0, far: 500000000.0, ...options};\n\n /**\n * Defines the left clipping plane.\n * @type {Number}\n * @default undefined\n */\n this.left = options.left;\n this._left = undefined;\n\n /**\n * Defines the right clipping plane.\n * @type {Number}\n * @default undefined\n */\n this.right = options.right;\n this._right = undefined;\n\n /**\n * Defines the top clipping plane.\n * @type {Number}\n * @default undefined\n */\n this.top = options.top;\n this._top = undefined;\n\n /**\n * Defines the bottom clipping plane.\n * @type {Number}\n * @default undefined\n */\n this.bottom = options.bottom;\n this._bottom = undefined;\n\n /**\n * The distance of the near plane.\n * @type {Number}\n * @default 1.0\n */\n this.near = options.near;\n this._near = this.near;\n\n /**\n * The distance of the far plane.\n * @type {Number}\n * @default 500000000.0\n */\n this.far = options.far;\n this._far = this.far;\n }\n\n /**\n * Returns a duplicate of a PerspectiveOffCenterFrustum instance.\n * @returns {PerspectiveOffCenterFrustum} A new PerspectiveFrustum instance.\n * */\n clone() {\n return new PerspectiveOffCenterFrustum({\n right: this.right,\n left: this.left,\n top: this.top,\n bottom: this.bottom,\n near: this.near,\n far: this.far\n });\n }\n\n /**\n * Compares the provided PerspectiveOffCenterFrustum componentwise and returns\n * <code>true</code> if they are equal, <code>false</code> otherwise.\n *\n * @param {PerspectiveOffCenterFrustum} [other] The right hand side PerspectiveOffCenterFrustum.\n * @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.\n */\n equals(other) {\n return (\n other &&\n other instanceof PerspectiveOffCenterFrustum &&\n this.right === other.right &&\n this.left === other.left &&\n this.top === other.top &&\n this.bottom === other.bottom &&\n this.near === other.near &&\n this.far === other.far\n );\n }\n\n /**\n * Gets the perspective projection matrix computed from the view frustum.\n * @memberof PerspectiveOffCenterFrustum.prototype\n * @type {Matrix4}\n *\n * @see PerspectiveOffCenterFrustum#infiniteProjectionMatrix\n */\n get projectionMatrix() {\n update(this);\n return this._perspectiveMatrix;\n }\n\n /**\n * Gets the perspective projection matrix computed from the view frustum with an infinite far plane.\n * @memberof PerspectiveOffCenterFrustum.prototype\n * @type {Matrix4}\n *\n * @see PerspectiveOffCenterFrustum#projectionMatrix\n */\n get infiniteProjectionMatrix() {\n update(this);\n return this._infinitePerspective;\n }\n\n /**\n * Creates a culling volume for this frustum.\n *\n * @param {Vector3} position The eye position.\n * @param {Vector3} direction The view direction.\n * @param {Vector3} up The up direction.\n * @returns {CullingVolume} A culling volume at the given position and orientation.\n *\n * @example\n * // Check if a bounding volume intersects the frustum.\n * const cullingVolume = frustum.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);\n * const intersect = cullingVolume.computeVisibility(boundingVolume);\n */\n // eslint-disable-next-line complexity, max-statements\n computeCullingVolume(position, direction, up) {\n assert(position, 'position is required.');\n assert(direction, 'direction is required.');\n assert(up, 'up is required.');\n\n const planes = this._cullingVolume.planes;\n\n up = scratchPlaneUpVector.copy(up).normalize();\n const right = scratchPlaneRightVector.copy(direction).cross(up).normalize();\n\n const nearCenter = scratchPlaneNearCenter\n .copy(direction)\n .multiplyByScalar(this.near)\n .add(position);\n\n const farCenter = scratchPlaneFarCenter\n .copy(direction)\n .multiplyByScalar(this.far)\n .add(position);\n\n let normal = scratchPlaneNormal;\n\n // Left plane computation\n normal.copy(right).multiplyByScalar(this.left).add(nearCenter).subtract(position).cross(up);\n\n planes[0].fromPointNormal(position, normal);\n\n // Right plane computation\n normal\n .copy(right)\n .multiplyByScalar(this.right)\n .add(nearCenter)\n .subtract(position)\n .cross(up)\n .negate();\n\n planes[1].fromPointNormal(position, normal);\n\n // Bottom plane computation\n normal\n .copy(up)\n .multiplyByScalar(this.bottom)\n .add(nearCenter)\n .subtract(position)\n .cross(right)\n .negate();\n\n planes[2].fromPointNormal(position, normal);\n\n // Top plane computation\n normal.copy(up).multiplyByScalar(this.top).add(nearCenter).subtract(position).cross(right);\n\n planes[3].fromPointNormal(position, normal);\n\n normal = new Vector3().copy(direction);\n\n // Near plane computation\n planes[4].fromPointNormal(nearCenter, normal);\n\n // Far plane computation\n normal.negate();\n\n planes[5].fromPointNormal(farCenter, normal);\n\n return this._cullingVolume;\n }\n\n /**\n * Returns the pixel's width and height in meters.\n *\n * @param {Number} drawingBufferWidth The width of the drawing buffer.\n * @param {Number} drawingBufferHeight The height of the drawing buffer.\n * @param {Number} distance The distance to the near plane in meters.\n * @param {Vector2} result The object onto which to store the result.\n * @returns {Vector2} The modified result parameter or a new instance of {@link Vector2} with the pixel's width and height in the x and y properties, respectively.\n *\n * @exception {DeveloperError} drawingBufferWidth must be greater than zero.\n * @exception {DeveloperError} drawingBufferHeight must be greater than zero.\n *\n * @example\n * // Example 1\n * // Get the width and height of a pixel.\n * const pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 1.0, new Vector2());\n *\n * @example\n * // Example 2\n * // Get the width and height of a pixel if the near plane was set to 'distance'.\n * // For example, get the size of a pixel of an image on a billboard.\n * const position = camera.position;\n * const direction = camera.direction;\n * const toCenter = Vector3.subtract(primitive.boundingVolume.center, position, new Vector3()); // vector from camera to a primitive\n * const toCenterProj = Vector3.multiplyByScalar(direction, Vector3.dot(direction, toCenter), new Vector3()); // project vector onto camera direction vector\n * const distance = Vector3.magnitude(toCenterProj);\n * const pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, new Vector2());\n */\n getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {\n update(this);\n\n assert(Number.isFinite(drawingBufferWidth) && Number.isFinite(drawingBufferHeight));\n // 'Both drawingBufferWidth and drawingBufferHeight are required.'\n assert(drawingBufferWidth > 0);\n // 'drawingBufferWidth must be greater than zero.'\n assert(drawingBufferHeight > 0);\n // 'drawingBufferHeight must be greater than zero.'\n assert(distance > 0);\n // 'distance is required.');\n assert(result);\n // 'A result object is required.');\n\n const inverseNear = 1.0 / this.near;\n let tanTheta = this.top * inverseNear;\n const pixelHeight = (2.0 * distance * tanTheta) / drawingBufferHeight;\n tanTheta = this.right * inverseNear;\n const pixelWidth = (2.0 * distance * tanTheta) / drawingBufferWidth;\n\n result.x = pixelWidth;\n result.y = pixelHeight;\n return result;\n }\n}\n\n// eslint-disable-next-line complexity, max-statements\nfunction update(frustum) {\n assert(\n Number.isFinite(frustum.right) &&\n Number.isFinite(frustum.left) &&\n Number.isFinite(frustum.top) &&\n Number.isFinite(frustum.bottom) &&\n Number.isFinite(frustum.near) &&\n Number.isFinite(frustum.far)\n );\n // throw new DeveloperError('right, left, top, bottom, near, or far parameters are not set.');\n\n const {top, bottom, right, left, near, far} = frustum;\n\n if (\n top !== frustum._top ||\n bottom !== frustum._bottom ||\n left !== frustum._left ||\n right !== frustum._right ||\n near !== frustum._near ||\n far !== frustum._far\n ) {\n assert(\n frustum.near > 0 && frustum.near < frustum.far,\n 'near must be greater than zero and less than far.'\n );\n\n frustum._left = left;\n frustum._right = right;\n frustum._top = top;\n frustum._bottom = bottom;\n frustum._near = near;\n frustum._far = far;\n frustum._perspectiveMatrix = new Matrix4().frustum({\n left,\n right,\n bottom,\n top,\n near,\n far\n });\n frustum._infinitePerspective = new Matrix4().frustum({\n left,\n right,\n bottom,\n top,\n near,\n far: Infinity\n });\n }\n}\n"],"file":"perspective-off-center-frustum.js"}
1
+ {"version":3,"sources":["../../../src/lib/perspective-off-center-frustum.ts"],"names":["scratchPlaneUpVector","Vector3","scratchPlaneRightVector","scratchPlaneNearCenter","scratchPlaneFarCenter","scratchPlaneNormal","PerspectiveOffCenterFrustum","options","CullingVolume","Plane","Matrix4","near","far","left","_left","undefined","right","_right","top","_top","bottom","_bottom","_near","_far","other","update","_perspectiveMatrix","_infinitePerspective","position","direction","up","planes","_cullingVolume","copy","normalize","cross","nearCenter","multiplyByScalar","add","farCenter","normal","subtract","fromPointNormal","negate","drawingBufferWidth","drawingBufferHeight","distance","result","Number","isFinite","inverseNear","tanTheta","pixelHeight","pixelWidth","x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KA4C,IAAAA,OAAO,CAAC1C,KAAR,GAAgBD,IAAhB;AACA2C,IAAAA,OAAO,CAACvC,MAAR,GAAiBD,KAAjB;AACAwC,IAAAA,OAAO,CAACrC,IAAR,GAAeD,GAAf;AACAsC,IAAAA,OAAO,CAACnC,OAAR,GAAkBD,MAAlB;AACAoC,IAAAA,OAAO,CAAClC,KAAR,GAAgBX,IAAhB;AACA6C,IAAAA,OAAO,CAACjC,IAAR,GAAeX,GAAf;AACA4C,IAAAA,OAAO,CAAC9B,kBAAR,GAA6B,IAAIhB,aAAJ,GAAc8C,OAAd,CAAsB;AACjD3C,MAAAA,IAAI,EAAJA,IADiD;AAEjDG,MAAAA,KAAK,EAALA,KAFiD;AAGjDI,MAAAA,MAAM,EAANA,MAHiD;AAIjDF,MAAAA,GAAG,EAAHA,GAJiD;AAKjDP,MAAAA,IAAI,EAAJA,IALiD;AAMjDC,MAAAA,GAAG,EAAHA;AANiD,KAAtB,CAA7B;AAQA4C,IAAAA,OAAO,CAAC7B,oBAAR,GAA+B,IAAIjB,aAAJ,GAAc8C,OAAd,CAAsB;AACnD3C,MAAAA,IAAI,EAAJA,IADmD;AAEnDG,MAAAA,KAAK,EAALA,KAFmD;AAGnDI,MAAAA,MAAM,EAANA,MAHmD;AAInDF,MAAAA,GAAG,EAAHA,GAJmD;AAKnDP,MAAAA,IAAI,EAAJA,IALmD;AAMnDC,MAAAA,GAAG,EAAE6C;AAN8C,KAAtB,CAA/B;AAQD;AACF","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\n// Note: This class is still an experimental export, mainly used by other test cases\n// - It has not been fully adapted to math.gl conventions\n// - Documentation has not been ported\n\n// @ts-nocheck\n\nimport {Vector3, Matrix4, assert} from '@math.gl/core';\nimport CullingVolume from './culling-volume';\nimport Plane from './plane';\n\nconst scratchPlaneUpVector = new Vector3();\nconst scratchPlaneRightVector = new Vector3();\nconst scratchPlaneNearCenter = new Vector3();\nconst scratchPlaneFarCenter = new Vector3();\nconst scratchPlaneNormal = new Vector3();\n\nexport default class PerspectiveOffCenterFrustum {\n left;\n _left;\n right;\n _right;\n top;\n _top;\n bottom;\n _bottom;\n near;\n _near;\n far;\n _far;\n _cullingVolume = new CullingVolume([\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane()\n ]);\n _perspectiveMatrix = new Matrix4();\n _infinitePerspective = new Matrix4();\n\n /**\n * The viewing frustum is defined by 6 planes.\n * Each plane is represented by a {@link Vector4} object, where the x, y, and z components\n * define the unit vector normal to the plane, and the w component is the distance of the\n * plane from the origin/camera position.\n *\n * @alias PerspectiveOffCenterFrustum\n * @constructor\n *\n * @param {Object} [options] An object with the following properties:\n * @param {Number} [options.left] The left clipping plane distance.\n * @param {Number} [options.right] The right clipping plane distance.\n * @param {Number} [options.top] The top clipping plane distance.\n * @param {Number} [options.bottom] The bottom clipping plane distance.\n * @param {Number} [options.near=1.0] The near clipping plane distance.\n * @param {Number} [options.far=500000000.0] The far clipping plane distance.\n *\n * @example\n * const frustum = new PerspectiveOffCenterFrustum({\n * left : -1.0,\n * right : 1.0,\n * top : 1.0,\n * bottom : -1.0,\n * near : 1.0,\n * far : 100.0\n * });\n *\n * @see PerspectiveFrustum\n */\n constructor(options: Record<string, any> = {}) {\n options = {near: 1.0, far: 500000000.0, ...options};\n\n /**\n * Defines the left clipping plane.\n * @type {Number}\n * @default undefined\n */\n this.left = options.left;\n this._left = undefined;\n\n /**\n * Defines the right clipping plane.\n * @type {Number}\n * @default undefined\n */\n this.right = options.right;\n this._right = undefined;\n\n /**\n * Defines the top clipping plane.\n * @type {Number}\n * @default undefined\n */\n this.top = options.top;\n this._top = undefined;\n\n /**\n * Defines the bottom clipping plane.\n * @type {Number}\n * @default undefined\n */\n this.bottom = options.bottom;\n this._bottom = undefined;\n\n /**\n * The distance of the near plane.\n * @type {Number}\n * @default 1.0\n */\n this.near = options.near;\n this._near = this.near;\n\n /**\n * The distance of the far plane.\n * @type {Number}\n * @default 500000000.0\n */\n this.far = options.far;\n this._far = this.far;\n }\n\n /**\n * Returns a duplicate of a PerspectiveOffCenterFrustum instance.\n * @returns {PerspectiveOffCenterFrustum} A new PerspectiveFrustum instance.\n * */\n clone() {\n return new PerspectiveOffCenterFrustum({\n right: this.right,\n left: this.left,\n top: this.top,\n bottom: this.bottom,\n near: this.near,\n far: this.far\n });\n }\n\n /**\n * Compares the provided PerspectiveOffCenterFrustum componentwise and returns\n * <code>true</code> if they are equal, <code>false</code> otherwise.\n *\n * @param {PerspectiveOffCenterFrustum} [other] The right hand side PerspectiveOffCenterFrustum.\n * @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.\n */\n equals(other) {\n return (\n other &&\n other instanceof PerspectiveOffCenterFrustum &&\n this.right === other.right &&\n this.left === other.left &&\n this.top === other.top &&\n this.bottom === other.bottom &&\n this.near === other.near &&\n this.far === other.far\n );\n }\n\n /**\n * Gets the perspective projection matrix computed from the view frustum.\n * @memberof PerspectiveOffCenterFrustum.prototype\n * @type {Matrix4}\n *\n * @see PerspectiveOffCenterFrustum#infiniteProjectionMatrix\n */\n get projectionMatrix() {\n update(this);\n return this._perspectiveMatrix;\n }\n\n /**\n * Gets the perspective projection matrix computed from the view frustum with an infinite far plane.\n * @memberof PerspectiveOffCenterFrustum.prototype\n * @type {Matrix4}\n *\n * @see PerspectiveOffCenterFrustum#projectionMatrix\n */\n get infiniteProjectionMatrix() {\n update(this);\n return this._infinitePerspective;\n }\n\n /**\n * Creates a culling volume for this frustum.\n *\n * @param {Vector3} position The eye position.\n * @param {Vector3} direction The view direction.\n * @param {Vector3} up The up direction.\n * @returns {CullingVolume} A culling volume at the given position and orientation.\n *\n * @example\n * // Check if a bounding volume intersects the frustum.\n * const cullingVolume = frustum.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);\n * const intersect = cullingVolume.computeVisibility(boundingVolume);\n */\n // eslint-disable-next-line complexity, max-statements\n computeCullingVolume(position, direction, up) {\n assert(position, 'position is required.');\n assert(direction, 'direction is required.');\n assert(up, 'up is required.');\n\n const planes = this._cullingVolume.planes;\n\n up = scratchPlaneUpVector.copy(up).normalize();\n const right = scratchPlaneRightVector.copy(direction).cross(up).normalize();\n\n const nearCenter = scratchPlaneNearCenter\n .copy(direction)\n .multiplyByScalar(this.near)\n .add(position);\n\n const farCenter = scratchPlaneFarCenter\n .copy(direction)\n .multiplyByScalar(this.far)\n .add(position);\n\n let normal = scratchPlaneNormal;\n\n // Left plane computation\n normal.copy(right).multiplyByScalar(this.left).add(nearCenter).subtract(position).cross(up);\n\n planes[0].fromPointNormal(position, normal);\n\n // Right plane computation\n normal\n .copy(right)\n .multiplyByScalar(this.right)\n .add(nearCenter)\n .subtract(position)\n .cross(up)\n .negate();\n\n planes[1].fromPointNormal(position, normal);\n\n // Bottom plane computation\n normal\n .copy(up)\n .multiplyByScalar(this.bottom)\n .add(nearCenter)\n .subtract(position)\n .cross(right)\n .negate();\n\n planes[2].fromPointNormal(position, normal);\n\n // Top plane computation\n normal.copy(up).multiplyByScalar(this.top).add(nearCenter).subtract(position).cross(right);\n\n planes[3].fromPointNormal(position, normal);\n\n normal = new Vector3().copy(direction);\n\n // Near plane computation\n planes[4].fromPointNormal(nearCenter, normal);\n\n // Far plane computation\n normal.negate();\n\n planes[5].fromPointNormal(farCenter, normal);\n\n return this._cullingVolume;\n }\n\n /**\n * Returns the pixel's width and height in meters.\n *\n * @param {Number} drawingBufferWidth The width of the drawing buffer.\n * @param {Number} drawingBufferHeight The height of the drawing buffer.\n * @param {Number} distance The distance to the near plane in meters.\n * @param {Vector2} result The object onto which to store the result.\n * @returns {Vector2} The modified result parameter or a new instance of {@link Vector2} with the pixel's width and height in the x and y properties, respectively.\n *\n * @exception {DeveloperError} drawingBufferWidth must be greater than zero.\n * @exception {DeveloperError} drawingBufferHeight must be greater than zero.\n *\n * @example\n * // Example 1\n * // Get the width and height of a pixel.\n * const pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 1.0, new Vector2());\n *\n * @example\n * // Example 2\n * // Get the width and height of a pixel if the near plane was set to 'distance'.\n * // For example, get the size of a pixel of an image on a billboard.\n * const position = camera.position;\n * const direction = camera.direction;\n * const toCenter = Vector3.subtract(primitive.boundingVolume.center, position, new Vector3()); // vector from camera to a primitive\n * const toCenterProj = Vector3.multiplyByScalar(direction, Vector3.dot(direction, toCenter), new Vector3()); // project vector onto camera direction vector\n * const distance = Vector3.magnitude(toCenterProj);\n * const pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, new Vector2());\n */\n getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {\n update(this);\n\n assert(Number.isFinite(drawingBufferWidth) && Number.isFinite(drawingBufferHeight));\n // 'Both drawingBufferWidth and drawingBufferHeight are required.'\n assert(drawingBufferWidth > 0);\n // 'drawingBufferWidth must be greater than zero.'\n assert(drawingBufferHeight > 0);\n // 'drawingBufferHeight must be greater than zero.'\n assert(distance > 0);\n // 'distance is required.');\n assert(result);\n // 'A result object is required.');\n\n const inverseNear = 1.0 / this.near;\n let tanTheta = this.top * inverseNear;\n const pixelHeight = (2.0 * distance * tanTheta) / drawingBufferHeight;\n tanTheta = this.right * inverseNear;\n const pixelWidth = (2.0 * distance * tanTheta) / drawingBufferWidth;\n\n result.x = pixelWidth;\n result.y = pixelHeight;\n return result;\n }\n}\n\n// eslint-disable-next-line complexity, max-statements\nfunction update(frustum) {\n assert(\n Number.isFinite(frustum.right) &&\n Number.isFinite(frustum.left) &&\n Number.isFinite(frustum.top) &&\n Number.isFinite(frustum.bottom) &&\n Number.isFinite(frustum.near) &&\n Number.isFinite(frustum.far)\n );\n // throw new DeveloperError('right, left, top, bottom, near, or far parameters are not set.');\n\n const {top, bottom, right, left, near, far} = frustum;\n\n if (\n top !== frustum._top ||\n bottom !== frustum._bottom ||\n left !== frustum._left ||\n right !== frustum._right ||\n near !== frustum._near ||\n far !== frustum._far\n ) {\n assert(\n frustum.near > 0 && frustum.near < frustum.far,\n 'near must be greater than zero and less than far.'\n );\n\n frustum._left = left;\n frustum._right = right;\n frustum._top = top;\n frustum._bottom = bottom;\n frustum._near = near;\n frustum._far = far;\n frustum._perspectiveMatrix = new Matrix4().frustum({\n left,\n right,\n bottom,\n top,\n near,\n far\n });\n frustum._infinitePerspective = new Matrix4().frustum({\n left,\n right,\n bottom,\n top,\n near,\n far: Infinity\n });\n }\n}\n"],"file":"perspective-off-center-frustum.js"}
@@ -7,15 +7,22 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.default = void 0;
9
9
 
10
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
+
12
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
+
10
14
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
15
 
12
16
  var _core = require("@math.gl/core");
13
17
 
14
- const scratchPosition = new _core.Vector3();
15
- const scratchNormal = new _core.Vector3();
18
+ var scratchPosition = new _core.Vector3();
19
+ var scratchNormal = new _core.Vector3();
16
20
 
17
- class Plane {
18
- constructor(normal = [0, 0, 1], distance = 0) {
21
+ var Plane = function () {
22
+ function Plane() {
23
+ var normal = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [0, 0, 1];
24
+ var distance = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
25
+ (0, _classCallCheck2.default)(this, Plane);
19
26
  (0, _defineProperty2.default)(this, "normal", void 0);
20
27
  (0, _defineProperty2.default)(this, "distance", void 0);
21
28
  this.normal = new _core.Vector3();
@@ -23,54 +30,65 @@ class Plane {
23
30
  this.fromNormalDistance(normal, distance);
24
31
  }
25
32
 
26
- fromNormalDistance(normal, distance) {
27
- (0, _core.assert)(Number.isFinite(distance));
28
- this.normal.from(normal).normalize();
29
- this.distance = distance;
30
- return this;
31
- }
32
-
33
- fromPointNormal(point, normal) {
34
- point = scratchPosition.from(point);
35
- this.normal.from(normal).normalize();
36
- const distance = -this.normal.dot(point);
37
- this.distance = distance;
38
- return this;
39
- }
40
-
41
- fromCoefficients(a, b, c, d) {
42
- this.normal.set(a, b, c);
43
- (0, _core.assert)((0, _core.equals)(this.normal.len(), 1));
44
- this.distance = d;
45
- return this;
46
- }
47
-
48
- clone() {
49
- return new Plane(this.normal, this.distance);
50
- }
51
-
52
- equals(right) {
53
- return (0, _core.equals)(this.distance, right.distance) && (0, _core.equals)(this.normal, right.normal);
54
- }
55
-
56
- getPointDistance(point) {
57
- return this.normal.dot(point) + this.distance;
58
- }
59
-
60
- transform(matrix4) {
61
- const normal = scratchNormal.copy(this.normal).transformAsVector(matrix4).normalize();
62
- const point = this.normal.scale(-this.distance).transform(matrix4);
63
- return this.fromPointNormal(point, normal);
64
- }
65
-
66
- projectPointOntoPlane(point, result = [0, 0, 0]) {
67
- point = scratchPosition.from(point);
68
- const pointDistance = this.getPointDistance(point);
69
- const scaledNormal = scratchNormal.copy(this.normal).scale(pointDistance);
70
- return point.subtract(scaledNormal).to(result);
71
- }
72
-
73
- }
33
+ (0, _createClass2.default)(Plane, [{
34
+ key: "fromNormalDistance",
35
+ value: function fromNormalDistance(normal, distance) {
36
+ (0, _core.assert)(Number.isFinite(distance));
37
+ this.normal.from(normal).normalize();
38
+ this.distance = distance;
39
+ return this;
40
+ }
41
+ }, {
42
+ key: "fromPointNormal",
43
+ value: function fromPointNormal(point, normal) {
44
+ point = scratchPosition.from(point);
45
+ this.normal.from(normal).normalize();
46
+ var distance = -this.normal.dot(point);
47
+ this.distance = distance;
48
+ return this;
49
+ }
50
+ }, {
51
+ key: "fromCoefficients",
52
+ value: function fromCoefficients(a, b, c, d) {
53
+ this.normal.set(a, b, c);
54
+ (0, _core.assert)((0, _core.equals)(this.normal.len(), 1));
55
+ this.distance = d;
56
+ return this;
57
+ }
58
+ }, {
59
+ key: "clone",
60
+ value: function clone() {
61
+ return new Plane(this.normal, this.distance);
62
+ }
63
+ }, {
64
+ key: "equals",
65
+ value: function equals(right) {
66
+ return (0, _core.equals)(this.distance, right.distance) && (0, _core.equals)(this.normal, right.normal);
67
+ }
68
+ }, {
69
+ key: "getPointDistance",
70
+ value: function getPointDistance(point) {
71
+ return this.normal.dot(point) + this.distance;
72
+ }
73
+ }, {
74
+ key: "transform",
75
+ value: function transform(matrix4) {
76
+ var normal = scratchNormal.copy(this.normal).transformAsVector(matrix4).normalize();
77
+ var point = this.normal.scale(-this.distance).transform(matrix4);
78
+ return this.fromPointNormal(point, normal);
79
+ }
80
+ }, {
81
+ key: "projectPointOntoPlane",
82
+ value: function projectPointOntoPlane(point) {
83
+ var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [0, 0, 0];
84
+ point = scratchPosition.from(point);
85
+ var pointDistance = this.getPointDistance(point);
86
+ var scaledNormal = scratchNormal.copy(this.normal).scale(pointDistance);
87
+ return point.subtract(scaledNormal).to(result);
88
+ }
89
+ }]);
90
+ return Plane;
91
+ }();
74
92
 
75
93
  exports.default = Plane;
76
94
  //# sourceMappingURL=plane.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/plane.ts"],"names":["scratchPosition","Vector3","scratchNormal","Plane","constructor","normal","distance","fromNormalDistance","Number","isFinite","from","normalize","fromPointNormal","point","dot","fromCoefficients","a","b","c","d","set","len","clone","equals","right","getPointDistance","transform","matrix4","copy","transformAsVector","scale","projectPointOntoPlane","result","pointDistance","scaledNormal","subtract","to"],"mappings":";;;;;;;;;;;AAIA;;AAEA,MAAMA,eAAe,GAAG,IAAIC,aAAJ,EAAxB;AACA,MAAMC,aAAa,GAAG,IAAID,aAAJ,EAAtB;;AAGe,MAAME,KAAN,CAAY;AAIzBC,EAAAA,WAAW,CAACC,MAAyB,GAAG,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAA7B,EAAwCC,QAAgB,GAAG,CAA3D,EAA8D;AAAA;AAAA;AACvE,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,EAAoBmB,KAAK,CAACnB,MAA1B,CAAhD;AACD;;AAKDoB,EAAAA,gBAAgB,CAACZ,KAAD,EAAmC;AACjD,WAAO,KAAKR,MAAL,CAAYS,GAAZ,CAAgBD,KAAhB,IAAyB,KAAKP,QAArC;AACD;;AAGDoB,EAAAA,SAAS,CAACC,OAAD,EAAmC;AAC1C,UAAMtB,MAAM,GAAGH,aAAa,CAAC0B,IAAd,CAAmB,KAAKvB,MAAxB,EAAgCwB,iBAAhC,CAAkDF,OAAlD,EAA2DhB,SAA3D,EAAf;AACA,UAAME,KAAK,GAAG,KAAKR,MAAL,CAAYyB,KAAZ,CAAkB,CAAC,KAAKxB,QAAxB,EAAkCoB,SAAlC,CAA4CC,OAA5C,CAAd;AACA,WAAO,KAAKf,eAAL,CAAqBC,KAArB,EAA4BR,MAA5B,CAAP;AACD;;AAMD0B,EAAAA,qBAAqB,CAAClB,KAAD,EAAQmB,MAAM,GAAG,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAjB,EAA4B;AAC/CnB,IAAAA,KAAK,GAAGb,eAAe,CAACU,IAAhB,CAAqBG,KAArB,CAAR;AAEA,UAAMoB,aAAa,GAAG,KAAKR,gBAAL,CAAsBZ,KAAtB,CAAtB;AACA,UAAMqB,YAAY,GAAGhC,aAAa,CAAC0B,IAAd,CAAmB,KAAKvB,MAAxB,EAAgCyB,KAAhC,CAAsCG,aAAtC,CAArB;AAEA,WAAOpB,KAAK,CAACsB,QAAN,CAAeD,YAAf,EAA6BE,EAA7B,CAAgCJ,MAAhC,CAAP;AACD;;AAtEwB","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\n/* eslint-disable */\nimport {Vector3, equals, assert} from '@math.gl/core';\n\nconst scratchPosition = new Vector3();\nconst scratchNormal = new Vector3();\n\n// A plane in Hessian Normal Form\nexport default class Plane {\n readonly normal: Vector3;\n distance: number;\n\n constructor(normal: readonly number[] = [0, 0, 1], distance: number = 0) {\n this.normal = new Vector3();\n this.distance = -0;\n this.fromNormalDistance(normal, distance);\n }\n\n /** Creates a plane from a normal and a distance from the origin. */\n fromNormalDistance(normal: readonly number[], distance: number): this {\n assert(Number.isFinite(distance));\n this.normal.from(normal).normalize();\n this.distance = distance;\n return this;\n }\n\n /** Creates a plane from a normal and a point on the plane. */\n fromPointNormal(point: readonly number[], normal: readonly number[]): this {\n point = scratchPosition.from(point);\n this.normal.from(normal).normalize();\n const distance = -this.normal.dot(point);\n this.distance = distance;\n return this;\n }\n\n /** Creates a plane from the general equation */\n fromCoefficients(a: number, b: number, c: number, d: number): this {\n this.normal.set(a, b, c);\n assert(equals(this.normal.len(), 1));\n this.distance = d;\n return this;\n }\n\n /** Duplicates a Plane instance. */\n clone(): Plane {\n return new Plane(this.normal, this.distance);\n }\n\n /** Compares the provided Planes by normal and distance */\n equals(right: Plane): boolean {\n return equals(this.distance, right.distance) && equals(this.normal, right.normal);\n }\n\n /** Computes the signed shortest distance of a point to a plane.\n * The sign of the distance determines which side of the plane the point is on.\n */\n getPointDistance(point: readonly number[]): number {\n return this.normal.dot(point) + this.distance;\n }\n\n /** Transforms the plane by the given transformation matrix. */\n transform(matrix4: readonly number[]): this {\n const normal = scratchNormal.copy(this.normal).transformAsVector(matrix4).normalize();\n const point = this.normal.scale(-this.distance).transform(matrix4);\n return this.fromPointNormal(point, normal);\n }\n\n /** Projects a point onto the plane. */\n projectPointOntoPlane(point: readonly number[], result: Vector3): Vector3;\n projectPointOntoPlane(point: readonly number[], result?: readonly number[]): readonly number[];\n\n projectPointOntoPlane(point, result = [0, 0, 0]) {\n point = scratchPosition.from(point);\n // projectedPoint = point - (normal.point + scale) * normal\n const pointDistance = this.getPointDistance(point);\n const scaledNormal = scratchNormal.copy(this.normal).scale(pointDistance);\n\n return point.subtract(scaledNormal).to(result);\n }\n}\n"],"file":"plane.js"}
1
+ {"version":3,"sources":["../../../src/lib/plane.ts"],"names":["scratchPosition","Vector3","scratchNormal","Plane","normal","distance","fromNormalDistance","Number","isFinite","from","normalize","point","dot","a","b","c","d","set","len","right","matrix4","copy","transformAsVector","scale","transform","fromPointNormal","result","pointDistance","getPointDistance","scaledNormal","subtract","to"],"mappings":";;;;;;;;;;;;;;;AAIA;;AAEA,IAAMA,eAAe,GAAG,IAAIC,aAAJ,EAAxB;AACA,IAAMC,aAAa,GAAG,IAAID,aAAJ,EAAtB;;IAGqBE,K;AAInB,mBAAyE;AAAA,QAA7DC,MAA6D,uEAAjC,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAiC;AAAA,QAAtBC,QAAsB,uEAAH,CAAG;AAAA;AAAA;AAAA;AACvE,SAAKD,MAAL,GAAc,IAAIH,aAAJ,EAAd;AACA,SAAKI,QAAL,GAAgB,CAAC,CAAjB;AACA,SAAKC,kBAAL,CAAwBF,MAAxB,EAAgCC,QAAhC;AACD;;;;WAGD,4BAAmBD,MAAnB,EAA8CC,QAA9C,EAAsE;AACpE,wBAAOE,MAAM,CAACC,QAAP,CAAgBH,QAAhB,CAAP;AACA,WAAKD,MAAL,CAAYK,IAAZ,CAAiBL,MAAjB,EAAyBM,SAAzB;AACA,WAAKL,QAAL,GAAgBA,QAAhB;AACA,aAAO,IAAP;AACD;;;WAGD,yBAAgBM,KAAhB,EAA0CP,MAA1C,EAA2E;AACzEO,MAAAA,KAAK,GAAGX,eAAe,CAACS,IAAhB,CAAqBE,KAArB,CAAR;AACA,WAAKP,MAAL,CAAYK,IAAZ,CAAiBL,MAAjB,EAAyBM,SAAzB;AACA,UAAML,QAAQ,GAAG,CAAC,KAAKD,MAAL,CAAYQ,GAAZ,CAAgBD,KAAhB,CAAlB;AACA,WAAKN,QAAL,GAAgBA,QAAhB;AACA,aAAO,IAAP;AACD;;;WAGD,0BAAiBQ,CAAjB,EAA4BC,CAA5B,EAAuCC,CAAvC,EAAkDC,CAAlD,EAAmE;AACjE,WAAKZ,MAAL,CAAYa,GAAZ,CAAgBJ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,aAAOhB,KAAK,CAACmB,QAAN,CAAeD,YAAf,EAA6BE,EAA7B,CAAgCL,MAAhC,CAAP;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\n/* eslint-disable */\nimport {Vector3, equals, assert} from '@math.gl/core';\n\nconst scratchPosition = new Vector3();\nconst scratchNormal = new Vector3();\n\n// A plane in Hessian Normal Form\nexport default class Plane {\n readonly normal: Vector3;\n distance: number;\n\n constructor(normal: readonly number[] = [0, 0, 1], distance: number = 0) {\n this.normal = new Vector3();\n this.distance = -0;\n this.fromNormalDistance(normal, distance);\n }\n\n /** Creates a plane from a normal and a distance from the origin. */\n fromNormalDistance(normal: readonly number[], distance: number): this {\n assert(Number.isFinite(distance));\n this.normal.from(normal).normalize();\n this.distance = distance;\n return this;\n }\n\n /** Creates a plane from a normal and a point on the plane. */\n fromPointNormal(point: readonly number[], normal: readonly number[]): this {\n point = scratchPosition.from(point);\n this.normal.from(normal).normalize();\n const distance = -this.normal.dot(point);\n this.distance = distance;\n return this;\n }\n\n /** Creates a plane from the general equation */\n fromCoefficients(a: number, b: number, c: number, d: number): this {\n this.normal.set(a, b, c);\n assert(equals(this.normal.len(), 1));\n this.distance = d;\n return this;\n }\n\n /** Duplicates a Plane instance. */\n clone(): Plane {\n return new Plane(this.normal, this.distance);\n }\n\n /** Compares the provided Planes by normal and distance */\n equals(right: Plane): boolean {\n return equals(this.distance, right.distance) && equals(this.normal, right.normal);\n }\n\n /** Computes the signed shortest distance of a point to a plane.\n * The sign of the distance determines which side of the plane the point is on.\n */\n getPointDistance(point: readonly number[]): number {\n return this.normal.dot(point) + this.distance;\n }\n\n /** Transforms the plane by the given transformation matrix. */\n transform(matrix4: readonly number[]): this {\n const normal = scratchNormal.copy(this.normal).transformAsVector(matrix4).normalize();\n const point = this.normal.scale(-this.distance).transform(matrix4);\n return this.fromPointNormal(point, normal);\n }\n\n /** Projects a point onto the plane. */\n projectPointOntoPlane(point: readonly number[], result: Vector3): Vector3;\n projectPointOntoPlane(point: readonly number[], result?: readonly number[]): readonly number[];\n\n projectPointOntoPlane(point, result = [0, 0, 0]) {\n point = scratchPosition.from(point);\n // projectedPoint = point - (normal.point + scale) * normal\n const pointDistance = this.getPointDistance(point);\n const scaledNormal = scratchNormal.copy(this.normal).scale(pointDistance);\n\n return point.subtract(scaledNormal).to(result);\n }\n}\n"],"file":"plane.js"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/algorithms/bounding-sphere-from-points.ts"],"names":["Vector3","BoundingSphere","fromPointsXMin","fromPointsYMin","fromPointsZMin","fromPointsXMax","fromPointsYMax","fromPointsZMax","fromPointsCurrentPos","fromPointsScratch","fromPointsRitterCenter","fromPointsMinBoxPt","fromPointsMaxBoxPt","fromPointsNaiveCenterScratch","volumeConstant","Math","PI","makeBoundingSphereFromPoints","positions","result","length","fromCenterRadius","currentPos","copy","xMin","yMin","zMin","xMax","yMax","zMax","position","x","y","z","xSpan","subtract","magnitudeSquared","ySpan","zSpan","diameter1","diameter2","maxSpan","ritterCenter","radiusSquared","ritterRadius","sqrt","minBoxPt","maxBoxPt","naiveCenter","add","multiplyByScalar","naiveRadius","r","magnitude","oldCenterToPointSquared","oldCenterToPoint","oldToNew","to","center","radius"],"mappings":"AAGA,SAAQA,OAAR,QAAsB,eAAtB;AACA,OAAOC,cAAP,MAA2B,qCAA3B;AAGA,MAAMC,cAAc,GAAG,IAAIF,OAAJ,EAAvB;AACA,MAAMG,cAAc,GAAG,IAAIH,OAAJ,EAAvB;AACA,MAAMI,cAAc,GAAG,IAAIJ,OAAJ,EAAvB;AACA,MAAMK,cAAc,GAAG,IAAIL,OAAJ,EAAvB;AACA,MAAMM,cAAc,GAAG,IAAIN,OAAJ,EAAvB;AACA,MAAMO,cAAc,GAAG,IAAIP,OAAJ,EAAvB;AACA,MAAMQ,oBAAoB,GAAG,IAAIR,OAAJ,EAA7B;AACA,MAA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AAIX,YAAY,GAAGO,WAAnB,EAAgC;AAC9BT,IAAAA,YAAY,CAACe,EAAb,CAAgBtC,MAAM,CAACuC,MAAvB;AAEAvC,IAAAA,MAAM,CAACwC,MAAP,GAAgBf,YAAhB;AACD,GAJD,MAIO;AACLI,IAAAA,WAAW,CAACS,EAAZ,CAAetC,MAAM,CAACuC,MAAtB;AAEAvC,IAAAA,MAAM,CAACwC,MAAP,GAAgBR,WAAhB;AACD;;AAED,SAAOhC,MAAP;AACD","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\nimport {Vector3} from '@math.gl/core';\nimport BoundingSphere from '../bounding-volumes/bounding-sphere';\n\n/* eslint-disable */\nconst fromPointsXMin = new Vector3();\nconst fromPointsYMin = new Vector3();\nconst fromPointsZMin = new Vector3();\nconst fromPointsXMax = new Vector3();\nconst fromPointsYMax = new Vector3();\nconst fromPointsZMax = new Vector3();\nconst fromPointsCurrentPos = new Vector3();\nconst fromPointsScratch = new Vector3();\nconst fromPointsRitterCenter = new Vector3();\nconst fromPointsMinBoxPt = new Vector3();\nconst fromPointsMaxBoxPt = new Vector3();\nconst fromPointsNaiveCenterScratch = new Vector3();\nconst volumeConstant = (4.0 / 3.0) * Math.PI;\n\n/**\n * Computes a tight-fitting bounding sphere enclosing a list of 3D Cartesian points.\n *\n * The bounding sphere is computed by running two algorithms, a naive algorithm and\n * Ritter's algorithm. The smaller of the two spheres is used to ensure a tight fit.\n * Bounding sphere computation article http://blogs.agi.com/insight3d/index.php/2008/02/04/a-bounding\n *\n * @param positions An array of points that the bounding sphere will enclose.\n * @param result Optional object onto which to store the result.\n * @returns The modified result parameter or a new `BoundingSphere` instance if not provided.\n */\nexport default function makeBoundingSphereFromPoints(\n positions: number[][],\n result: BoundingSphere = new BoundingSphere()\n): BoundingSphere {\n if (!positions || positions.length === 0) {\n return result.fromCenterRadius([0, 0, 0], 0);\n }\n\n const currentPos = fromPointsCurrentPos.copy(positions[0]);\n\n const xMin = fromPointsXMin.copy(currentPos);\n const yMin = fromPointsYMin.copy(currentPos);\n const zMin = fromPointsZMin.copy(currentPos);\n\n const xMax = fromPointsXMax.copy(currentPos);\n const yMax = fromPointsYMax.copy(currentPos);\n const zMax = fromPointsZMax.copy(currentPos);\n\n for (const position of positions) {\n currentPos.copy(position);\n\n const x = currentPos.x;\n const y = currentPos.y;\n const z = currentPos.z;\n\n // Store points containing the the smallest and largest components\n if (x < xMin.x) {\n xMin.copy(currentPos);\n }\n\n if (x > xMax.x) {\n xMax.copy(currentPos);\n }\n\n if (y < yMin.y) {\n yMin.copy(currentPos);\n }\n\n if (y > yMax.y) {\n yMax.copy(currentPos);\n }\n\n if (z < zMin.z) {\n zMin.copy(currentPos);\n }\n\n if (z > zMax.z) {\n zMax.copy(currentPos);\n }\n }\n\n // Compute x-, y-, and z-spans (Squared distances b/n each component's min. and max.).\n const xSpan = fromPointsScratch.copy(xMax).subtract(xMin).magnitudeSquared();\n const ySpan = fromPointsScratch.copy(yMax).subtract(yMin).magnitudeSquared();\n const zSpan = fromPointsScratch.copy(zMax).subtract(zMin).magnitudeSquared();\n\n // Set the diameter endpoints to the largest span.\n let diameter1 = xMin;\n let diameter2 = xMax;\n let maxSpan = xSpan;\n if (ySpan > maxSpan) {\n maxSpan = ySpan;\n diameter1 = yMin;\n diameter2 = yMax;\n }\n if (zSpan > maxSpan) {\n maxSpan = zSpan;\n diameter1 = zMin;\n diameter2 = zMax;\n }\n\n // Calculate the center of the initial sphere found by Ritter's algorithm\n const ritterCenter = fromPointsRitterCenter;\n ritterCenter.x = (diameter1.x + diameter2.x) * 0.5;\n ritterCenter.y = (diameter1.y + diameter2.y) * 0.5;\n ritterCenter.z = (diameter1.z + diameter2.z) * 0.5;\n\n // Calculate the radius of the initial sphere found by Ritter's algorithm\n let radiusSquared = fromPointsScratch.copy(diameter2).subtract(ritterCenter).magnitudeSquared();\n let ritterRadius = Math.sqrt(radiusSquared);\n\n // Find the center of the sphere found using the Naive method.\n const minBoxPt = fromPointsMinBoxPt;\n minBoxPt.x = xMin.x;\n minBoxPt.y = yMin.y;\n minBoxPt.z = zMin.z;\n\n const maxBoxPt = fromPointsMaxBoxPt;\n maxBoxPt.x = xMax.x;\n maxBoxPt.y = yMax.y;\n maxBoxPt.z = zMax.z;\n\n const naiveCenter = fromPointsNaiveCenterScratch\n .copy(minBoxPt)\n .add(maxBoxPt)\n .multiplyByScalar(0.5);\n\n // Begin 2nd pass to find naive radius and modify the ritter sphere.\n let naiveRadius = 0;\n for (const position of positions) {\n currentPos.copy(position);\n\n // Find the furthest point from the naive center to calculate the naive radius.\n const r = fromPointsScratch.copy(currentPos).subtract(naiveCenter).magnitude();\n if (r > naiveRadius) {\n naiveRadius = r;\n }\n\n // Make adjustments to the Ritter Sphere to include all points.\n const oldCenterToPointSquared = fromPointsScratch\n .copy(currentPos)\n .subtract(ritterCenter)\n .magnitudeSquared();\n\n if (oldCenterToPointSquared > radiusSquared) {\n const oldCenterToPoint = Math.sqrt(oldCenterToPointSquared);\n // Calculate new radius to include the point that lies outside\n ritterRadius = (ritterRadius + oldCenterToPoint) * 0.5;\n radiusSquared = ritterRadius * ritterRadius;\n // Calculate center of new Ritter sphere\n const oldToNew = oldCenterToPoint - ritterRadius;\n ritterCenter.x = (ritterRadius * ritterCenter.x + oldToNew * currentPos.x) / oldCenterToPoint;\n ritterCenter.y = (ritterRadius * ritterCenter.y + oldToNew * currentPos.y) / oldCenterToPoint;\n ritterCenter.z = (ritterRadius * ritterCenter.z + oldToNew * currentPos.z) / oldCenterToPoint;\n }\n }\n\n if (ritterRadius < naiveRadius) {\n ritterCenter.to(result.center);\n // @ts-ignore TS2540: Cannot assign to 'radius' because it is a read-only property.\n result.radius = ritterRadius;\n } else {\n naiveCenter.to(result.center);\n // @ts-ignore TS2540: Cannot assign to 'radius' because it is a read-only property.\n result.radius = naiveRadius;\n }\n\n return result;\n}\n"],"file":"bounding-sphere-from-points.js"}
1
+ {"version":3,"sources":["../../../../src/lib/algorithms/bounding-sphere-from-points.ts"],"names":["Vector3","BoundingSphere","fromPointsXMin","fromPointsYMin","fromPointsZMin","fromPointsXMax","fromPointsYMax","fromPointsZMax","fromPointsCurrentPos","fromPointsScratch","fromPointsRitterCenter","fromPointsMinBoxPt","fromPointsMaxBoxPt","fromPointsNaiveCenterScratch","volumeConstant","Math","PI","makeBoundingSphereFromPoints","positions","result","length","fromCenterRadius","currentPos","copy","xMin","yMin","zMin","xMax","yMax","zMax","position","x","y","z","xSpan","subtract","magnitudeSquared","ySpan","zSpan","diameter1","diameter2","maxSpan","ritterCenter","radiusSquared","ritterRadius","sqrt","minBoxPt","maxBoxPt","naiveCenter","add","multiplyByScalar","naiveRadius","r","magnitude","oldCenterToPointSquared","oldCenterToPoint","oldToNew","to","center","radius"],"mappings":"AAGA,SAAQA,OAAR,QAAsB,eAAtB;AACA,OAAOC,cAAP,MAA2B,qCAA3B;AAGA,MAAMC,cAAc,GAAG,IAAIF,OAAJ,EAAvB;AACA,MAAMG,cAAc,GAAG,IAAIH,OAAJ,EAAvB;AACA,MAAMI,cAAc,GAAG,IAAIJ,OAAJ,EAAvB;AACA,MAAMK,cAAc,GAAG,IAAIL,OAAJ,EAAvB;AACA,MAAMM,cAAc,GAAG,IAAIN,OAAJ,EAAvB;AACA,MAAMO,cAAc,GAAG,IAAIP,OAAJ,EAAvB;AACA,MAAMQ,oBAAoB,GAAG,IAAIR,OAAJ,EAA7B;AACA,MAAMS,iBAAiB,GAAG,IAAIT,OAAJ,EAA1B;AACA,MAAMU,sBAAsB,GAAG,IAAIV,OAAJ,EAA/B;AACA,MAAMW,kBAAkB,GAAG,IAAIX,OAAJ,EAA3B;AACA,MAAMY,kBAAkB,GAAG,IAAIZ,OAAJ,EAA3B;AACA,MAAMa,4BAA4B,GAAG,IAAIb,OAAJ,EAArC;AACA,MAAMc,cAAc,GAAI,MAAM,GAAP,GAAcC,IAAI,CAACC,EAA1C;AAaA,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D","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\nimport {Vector3} from '@math.gl/core';\nimport BoundingSphere from '../bounding-volumes/bounding-sphere';\n\n/* eslint-disable */\nconst fromPointsXMin = new Vector3();\nconst fromPointsYMin = new Vector3();\nconst fromPointsZMin = new Vector3();\nconst fromPointsXMax = new Vector3();\nconst fromPointsYMax = new Vector3();\nconst fromPointsZMax = new Vector3();\nconst fromPointsCurrentPos = new Vector3();\nconst fromPointsScratch = new Vector3();\nconst fromPointsRitterCenter = new Vector3();\nconst fromPointsMinBoxPt = new Vector3();\nconst fromPointsMaxBoxPt = new Vector3();\nconst fromPointsNaiveCenterScratch = new Vector3();\nconst volumeConstant = (4.0 / 3.0) * Math.PI;\n\n/**\n * Computes a tight-fitting bounding sphere enclosing a list of 3D Cartesian points.\n *\n * The bounding sphere is computed by running two algorithms, a naive algorithm and\n * Ritter's algorithm. The smaller of the two spheres is used to ensure a tight fit.\n * Bounding sphere computation article http://blogs.agi.com/insight3d/index.php/2008/02/04/a-bounding\n *\n * @param positions An array of points that the bounding sphere will enclose.\n * @param result Optional object onto which to store the result.\n * @returns The modified result parameter or a new `BoundingSphere` instance if not provided.\n */\nexport default function makeBoundingSphereFromPoints(\n positions: number[][],\n result: BoundingSphere = new BoundingSphere()\n): BoundingSphere {\n if (!positions || positions.length === 0) {\n return result.fromCenterRadius([0, 0, 0], 0);\n }\n\n const currentPos = fromPointsCurrentPos.copy(positions[0]);\n\n const xMin = fromPointsXMin.copy(currentPos);\n const yMin = fromPointsYMin.copy(currentPos);\n const zMin = fromPointsZMin.copy(currentPos);\n\n const xMax = fromPointsXMax.copy(currentPos);\n const yMax = fromPointsYMax.copy(currentPos);\n const zMax = fromPointsZMax.copy(currentPos);\n\n for (const position of positions) {\n currentPos.copy(position);\n\n const x = currentPos.x;\n const y = currentPos.y;\n const z = currentPos.z;\n\n // Store points containing the the smallest and largest components\n if (x < xMin.x) {\n xMin.copy(currentPos);\n }\n\n if (x > xMax.x) {\n xMax.copy(currentPos);\n }\n\n if (y < yMin.y) {\n yMin.copy(currentPos);\n }\n\n if (y > yMax.y) {\n yMax.copy(currentPos);\n }\n\n if (z < zMin.z) {\n zMin.copy(currentPos);\n }\n\n if (z > zMax.z) {\n zMax.copy(currentPos);\n }\n }\n\n // Compute x-, y-, and z-spans (Squared distances b/n each component's min. and max.).\n const xSpan = fromPointsScratch.copy(xMax).subtract(xMin).magnitudeSquared();\n const ySpan = fromPointsScratch.copy(yMax).subtract(yMin).magnitudeSquared();\n const zSpan = fromPointsScratch.copy(zMax).subtract(zMin).magnitudeSquared();\n\n // Set the diameter endpoints to the largest span.\n let diameter1 = xMin;\n let diameter2 = xMax;\n let maxSpan = xSpan;\n if (ySpan > maxSpan) {\n maxSpan = ySpan;\n diameter1 = yMin;\n diameter2 = yMax;\n }\n if (zSpan > maxSpan) {\n maxSpan = zSpan;\n diameter1 = zMin;\n diameter2 = zMax;\n }\n\n // Calculate the center of the initial sphere found by Ritter's algorithm\n const ritterCenter = fromPointsRitterCenter;\n ritterCenter.x = (diameter1.x + diameter2.x) * 0.5;\n ritterCenter.y = (diameter1.y + diameter2.y) * 0.5;\n ritterCenter.z = (diameter1.z + diameter2.z) * 0.5;\n\n // Calculate the radius of the initial sphere found by Ritter's algorithm\n let radiusSquared = fromPointsScratch.copy(diameter2).subtract(ritterCenter).magnitudeSquared();\n let ritterRadius = Math.sqrt(radiusSquared);\n\n // Find the center of the sphere found using the Naive method.\n const minBoxPt = fromPointsMinBoxPt;\n minBoxPt.x = xMin.x;\n minBoxPt.y = yMin.y;\n minBoxPt.z = zMin.z;\n\n const maxBoxPt = fromPointsMaxBoxPt;\n maxBoxPt.x = xMax.x;\n maxBoxPt.y = yMax.y;\n maxBoxPt.z = zMax.z;\n\n const naiveCenter = fromPointsNaiveCenterScratch\n .copy(minBoxPt)\n .add(maxBoxPt)\n .multiplyByScalar(0.5);\n\n // Begin 2nd pass to find naive radius and modify the ritter sphere.\n let naiveRadius = 0;\n for (const position of positions) {\n currentPos.copy(position);\n\n // Find the furthest point from the naive center to calculate the naive radius.\n const r = fromPointsScratch.copy(currentPos).subtract(naiveCenter).magnitude();\n if (r > naiveRadius) {\n naiveRadius = r;\n }\n\n // Make adjustments to the Ritter Sphere to include all points.\n const oldCenterToPointSquared = fromPointsScratch\n .copy(currentPos)\n .subtract(ritterCenter)\n .magnitudeSquared();\n\n if (oldCenterToPointSquared > radiusSquared) {\n const oldCenterToPoint = Math.sqrt(oldCenterToPointSquared);\n // Calculate new radius to include the point that lies outside\n ritterRadius = (ritterRadius + oldCenterToPoint) * 0.5;\n radiusSquared = ritterRadius * ritterRadius;\n // Calculate center of new Ritter sphere\n const oldToNew = oldCenterToPoint - ritterRadius;\n ritterCenter.x = (ritterRadius * ritterCenter.x + oldToNew * currentPos.x) / oldCenterToPoint;\n ritterCenter.y = (ritterRadius * ritterCenter.y + oldToNew * currentPos.y) / oldCenterToPoint;\n ritterCenter.z = (ritterRadius * ritterCenter.z + oldToNew * currentPos.z) / oldCenterToPoint;\n }\n }\n\n if (ritterRadius < naiveRadius) {\n ritterCenter.to(result.center);\n result.radius = ritterRadius;\n } else {\n naiveCenter.to(result.center);\n result.radius = naiveRadius;\n }\n\n return result;\n}\n"],"file":"bounding-sphere-from-points.js"}
@@ -1 +1 @@
1
- {"version":3,"file":"bounding-sphere-from-points.d.ts","sourceRoot":"","sources":["../../../src/lib/algorithms/bounding-sphere-from-points.ts"],"names":[],"mappings":"AAIA,OAAO,cAAc,MAAM,qCAAqC,CAAC;AAiBjE;;;;;;;;;;GAUG;AACH,MAAM,CAAC,OAAO,UAAU,4BAA4B,CAClD,SAAS,EAAE,MAAM,EAAE,EAAE,EACrB,MAAM,GAAE,cAAqC,GAC5C,cAAc,CAuIhB"}
1
+ {"version":3,"file":"bounding-sphere-from-points.d.ts","sourceRoot":"","sources":["../../../src/lib/algorithms/bounding-sphere-from-points.ts"],"names":[],"mappings":"AAIA,OAAO,cAAc,MAAM,qCAAqC,CAAC;AAiBjE;;;;;;;;;;GAUG;AACH,MAAM,CAAC,OAAO,UAAU,4BAA4B,CAClD,SAAS,EAAE,MAAM,EAAE,EAAE,EACrB,MAAM,GAAE,cAAqC,GAC5C,cAAc,CAqIhB"}
@@ -130,12 +130,10 @@ export default function makeBoundingSphereFromPoints(positions, result = new Bou
130
130
  }
131
131
  if (ritterRadius < naiveRadius) {
132
132
  ritterCenter.to(result.center);
133
- // @ts-ignore TS2540: Cannot assign to 'radius' because it is a read-only property.
134
133
  result.radius = ritterRadius;
135
134
  }
136
135
  else {
137
136
  naiveCenter.to(result.center);
138
- // @ts-ignore TS2540: Cannot assign to 'radius' because it is a read-only property.
139
137
  result.radius = naiveRadius;
140
138
  }
141
139
  return result;