@math.gl/culling 4.0.0-beta.1 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist/constants.d.ts +0 -1
  2. package/dist/constants.js +5 -4
  3. package/dist/index.cjs +27 -45
  4. package/dist/index.cjs.map +7 -0
  5. package/dist/index.d.ts +11 -12
  6. package/dist/index.js +2 -1
  7. package/dist/lib/algorithms/bounding-box-from-points.d.ts +2 -3
  8. package/dist/lib/algorithms/bounding-box-from-points.js +113 -113
  9. package/dist/lib/algorithms/bounding-sphere-from-points.d.ts +1 -2
  10. package/dist/lib/algorithms/bounding-sphere-from-points.js +117 -103
  11. package/dist/lib/algorithms/compute-eigen-decomposition.d.ts +1 -2
  12. package/dist/lib/algorithms/compute-eigen-decomposition.js +113 -85
  13. package/dist/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +2 -3
  14. package/dist/lib/bounding-volumes/axis-aligned-bounding-box.js +100 -80
  15. package/dist/lib/bounding-volumes/bounding-sphere.d.ts +2 -3
  16. package/dist/lib/bounding-volumes/bounding-sphere.js +106 -97
  17. package/dist/lib/bounding-volumes/bounding-volume.d.ts +1 -2
  18. package/dist/lib/bounding-volumes/bounding-volume.js +0 -1
  19. package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts +3 -4
  20. package/dist/lib/bounding-volumes/oriented-bounding-box.js +238 -196
  21. package/dist/lib/culling-volume.d.ts +3 -4
  22. package/dist/lib/culling-volume.js +109 -90
  23. package/dist/lib/perspective-frustum.d.ts +2 -3
  24. package/dist/lib/perspective-frustum.js +184 -136
  25. package/dist/lib/perspective-off-center-frustum.d.ts +2 -3
  26. package/dist/lib/perspective-off-center-frustum.js +259 -158
  27. package/dist/lib/plane.d.ts +0 -1
  28. package/dist/lib/plane.js +58 -59
  29. package/package.json +5 -6
  30. package/dist/constants.d.ts.map +0 -1
  31. package/dist/constants.js.map +0 -1
  32. package/dist/index.d.ts.map +0 -1
  33. package/dist/index.js.map +0 -1
  34. package/dist/lib/algorithms/bounding-box-from-points.d.ts.map +0 -1
  35. package/dist/lib/algorithms/bounding-box-from-points.js.map +0 -1
  36. package/dist/lib/algorithms/bounding-sphere-from-points.d.ts.map +0 -1
  37. package/dist/lib/algorithms/bounding-sphere-from-points.js.map +0 -1
  38. package/dist/lib/algorithms/compute-eigen-decomposition.d.ts.map +0 -1
  39. package/dist/lib/algorithms/compute-eigen-decomposition.js.map +0 -1
  40. package/dist/lib/bounding-volumes/axis-aligned-bounding-box.d.ts.map +0 -1
  41. package/dist/lib/bounding-volumes/axis-aligned-bounding-box.js.map +0 -1
  42. package/dist/lib/bounding-volumes/bounding-sphere.d.ts.map +0 -1
  43. package/dist/lib/bounding-volumes/bounding-sphere.js.map +0 -1
  44. package/dist/lib/bounding-volumes/bounding-volume.d.ts.map +0 -1
  45. package/dist/lib/bounding-volumes/bounding-volume.js.map +0 -1
  46. package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts.map +0 -1
  47. package/dist/lib/bounding-volumes/oriented-bounding-box.js.map +0 -1
  48. package/dist/lib/culling-volume.d.ts.map +0 -1
  49. package/dist/lib/culling-volume.js.map +0 -1
  50. package/dist/lib/perspective-frustum.d.ts.map +0 -1
  51. package/dist/lib/perspective-frustum.js.map +0 -1
  52. package/dist/lib/perspective-off-center-frustum.d.ts.map +0 -1
  53. package/dist/lib/perspective-off-center-frustum.js.map +0 -1
  54. package/dist/lib/plane.d.ts.map +0 -1
  55. package/dist/lib/plane.js.map +0 -1
@@ -1,4 +1,8 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
1
+ // This file is derived from the Cesium math library under Apache 2 license
2
+ // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
3
+ // Note: This class is still an experimental export, mainly used by other test cases
4
+ // - It has not been fully adapted to math.gl conventions
5
+ // - Documentation has not been ported
2
6
  import { Vector3, Matrix4, assert } from '@math.gl/core';
3
7
  import { CullingVolume } from "./culling-volume.js";
4
8
  import { Plane } from "./plane.js";
@@ -8,162 +12,259 @@ const scratchPlaneNearCenter = new Vector3();
8
12
  const scratchPlaneFarCenter = new Vector3();
9
13
  const scratchPlaneNormal = new Vector3();
10
14
  export class PerspectiveOffCenterFrustum {
11
- constructor(options = {}) {
12
- _defineProperty(this, "left", void 0);
13
-
14
- _defineProperty(this, "_left", void 0);
15
-
16
- _defineProperty(this, "right", void 0);
17
-
18
- _defineProperty(this, "_right", void 0);
19
-
20
- _defineProperty(this, "top", void 0);
21
-
22
- _defineProperty(this, "_top", void 0);
23
-
24
- _defineProperty(this, "bottom", void 0);
25
-
26
- _defineProperty(this, "_bottom", void 0);
27
-
28
- _defineProperty(this, "near", void 0);
29
-
30
- _defineProperty(this, "_near", void 0);
31
-
32
- _defineProperty(this, "far", void 0);
33
-
34
- _defineProperty(this, "_far", void 0);
35
-
36
- _defineProperty(this, "_cullingVolume", new CullingVolume([new Plane(), new Plane(), new Plane(), new Plane(), new Plane(), new Plane()]));
37
-
38
- _defineProperty(this, "_perspectiveMatrix", new Matrix4());
39
-
40
- _defineProperty(this, "_infinitePerspective", new Matrix4());
41
-
42
- const {
43
- near = 1.0,
44
- far = 500000000.0
45
- } = options;
46
- this.left = options.left;
47
- this._left = undefined;
48
- this.right = options.right;
49
- this._right = undefined;
50
- this.top = options.top;
51
- this._top = undefined;
52
- this.bottom = options.bottom;
53
- this._bottom = undefined;
54
- this.near = near;
55
- this._near = near;
56
- this.far = far;
57
- this._far = far;
58
- }
59
-
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
- this._update();
77
-
78
- return this._perspectiveMatrix;
79
- }
80
-
81
- get infiniteProjectionMatrix() {
82
- this._update();
83
-
84
- return this._infinitePerspective;
85
- }
86
-
87
- computeCullingVolume(position, direction, up) {
88
- assert(position, 'position is required.');
89
- assert(direction, 'direction is required.');
90
- assert(up, 'up is required.');
91
- const planes = this._cullingVolume.planes;
92
- up = scratchPlaneUpVector.copy(up).normalize();
93
- const right = scratchPlaneRightVector.copy(direction).cross(up).normalize();
94
- const nearCenter = scratchPlaneNearCenter.copy(direction).multiplyByScalar(this.near).add(position);
95
- const farCenter = scratchPlaneFarCenter.copy(direction).multiplyByScalar(this.far).add(position);
96
- let normal = scratchPlaneNormal;
97
- normal.copy(right).multiplyByScalar(this.left).add(nearCenter).subtract(position).cross(up);
98
- planes[0].fromPointNormal(position, normal);
99
- normal.copy(right).multiplyByScalar(this.right).add(nearCenter).subtract(position).cross(up).negate();
100
- planes[1].fromPointNormal(position, normal);
101
- normal.copy(up).multiplyByScalar(this.bottom).add(nearCenter).subtract(position).cross(right).negate();
102
- planes[2].fromPointNormal(position, normal);
103
- normal.copy(up).multiplyByScalar(this.top).add(nearCenter).subtract(position).cross(right);
104
- planes[3].fromPointNormal(position, normal);
105
- normal = new Vector3().copy(direction);
106
- planes[4].fromPointNormal(nearCenter, normal);
107
- normal.negate();
108
- planes[5].fromPointNormal(farCenter, normal);
109
- return this._cullingVolume;
110
- }
111
-
112
- getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {
113
- this._update();
114
-
115
- assert(Number.isFinite(drawingBufferWidth) && Number.isFinite(drawingBufferHeight));
116
- assert(drawingBufferWidth > 0);
117
- assert(drawingBufferHeight > 0);
118
- assert(distance > 0);
119
- assert(result);
120
- const inverseNear = 1.0 / this.near;
121
- let tanTheta = this.top * inverseNear;
122
- const pixelHeight = 2.0 * distance * tanTheta / drawingBufferHeight;
123
- tanTheta = this.right * inverseNear;
124
- const pixelWidth = 2.0 * distance * tanTheta / drawingBufferWidth;
125
- result.x = pixelWidth;
126
- result.y = pixelHeight;
127
- return result;
128
- }
129
-
130
- _update() {
131
- assert(Number.isFinite(this.right) && Number.isFinite(this.left) && Number.isFinite(this.top) && Number.isFinite(this.bottom) && Number.isFinite(this.near) && Number.isFinite(this.far));
132
- const {
133
- top,
134
- bottom,
135
- right,
136
- left,
137
- near,
138
- far
139
- } = this;
140
-
141
- if (top !== this._top || bottom !== this._bottom || left !== this._left || right !== this._right || near !== this._near || far !== this._far) {
142
- assert(this.near > 0 && this.near < this.far, 'near must be greater than zero and less than far.');
143
- this._left = left;
144
- this._right = right;
145
- this._top = top;
146
- this._bottom = bottom;
147
- this._near = near;
148
- this._far = far;
149
- this._perspectiveMatrix = new Matrix4().frustum({
150
- left,
151
- right,
152
- bottom,
153
- top,
154
- near,
155
- far
156
- });
157
- this._infinitePerspective = new Matrix4().frustum({
158
- left,
159
- right,
160
- bottom,
161
- top,
162
- near,
163
- far: Infinity
164
- });
15
+ /**
16
+ * The viewing frustum is defined by 6 planes.
17
+ * Each plane is represented by a {@link Vector4} object, where the x, y, and z components
18
+ * define the unit vector normal to the plane, and the w component is the distance of the
19
+ * plane from the origin/camera position.
20
+ *
21
+ * @alias PerspectiveOffCenterFrustum
22
+ *
23
+ * @example
24
+ * const frustum = new PerspectiveOffCenterFrustum({
25
+ * left : -1.0,
26
+ * right : 1.0,
27
+ * top : 1.0,
28
+ * bottom : -1.0,
29
+ * near : 1.0,
30
+ * far : 100.0
31
+ * });
32
+ *
33
+ * @see PerspectiveFrustum
34
+ */
35
+ constructor(options = {}) {
36
+ this._cullingVolume = new CullingVolume([
37
+ new Plane(),
38
+ new Plane(),
39
+ new Plane(),
40
+ new Plane(),
41
+ new Plane(),
42
+ new Plane()
43
+ ]);
44
+ this._perspectiveMatrix = new Matrix4();
45
+ this._infinitePerspective = new Matrix4();
46
+ const { near = 1.0, far = 500000000.0 } = options;
47
+ this.left = options.left;
48
+ this._left = undefined;
49
+ this.right = options.right;
50
+ this._right = undefined;
51
+ this.top = options.top;
52
+ this._top = undefined;
53
+ this.bottom = options.bottom;
54
+ this._bottom = undefined;
55
+ this.near = near;
56
+ this._near = near;
57
+ this.far = far;
58
+ this._far = far;
59
+ }
60
+ /**
61
+ * Returns a duplicate of a PerspectiveOffCenterFrustum instance.
62
+ * @returns {PerspectiveOffCenterFrustum} A new PerspectiveFrustum instance.
63
+ * */
64
+ clone() {
65
+ return new PerspectiveOffCenterFrustum({
66
+ right: this.right,
67
+ left: this.left,
68
+ top: this.top,
69
+ bottom: this.bottom,
70
+ near: this.near,
71
+ far: this.far
72
+ });
73
+ }
74
+ /**
75
+ * Compares the provided PerspectiveOffCenterFrustum componentwise and returns
76
+ * <code>true</code> if they are equal, <code>false</code> otherwise.
77
+ *
78
+ * @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
79
+ */
80
+ equals(other) {
81
+ return (other &&
82
+ other instanceof PerspectiveOffCenterFrustum &&
83
+ this.right === other.right &&
84
+ this.left === other.left &&
85
+ this.top === other.top &&
86
+ this.bottom === other.bottom &&
87
+ this.near === other.near &&
88
+ this.far === other.far);
89
+ }
90
+ /**
91
+ * Gets the perspective projection matrix computed from the view frustum.
92
+ * @memberof PerspectiveOffCenterFrustum.prototype
93
+ * @type {Matrix4}
94
+ *
95
+ * @see PerspectiveOffCenterFrustum#infiniteProjectionMatrix
96
+ */
97
+ get projectionMatrix() {
98
+ this._update();
99
+ return this._perspectiveMatrix;
100
+ }
101
+ /**
102
+ * Gets the perspective projection matrix computed from the view frustum with an infinite far plane.
103
+ * @memberof PerspectiveOffCenterFrustum.prototype
104
+ * @type {Matrix4}
105
+ *
106
+ * @see PerspectiveOffCenterFrustum#projectionMatrix
107
+ */
108
+ get infiniteProjectionMatrix() {
109
+ this._update();
110
+ return this._infinitePerspective;
111
+ }
112
+ /**
113
+ * Creates a culling volume for this frustum.
114
+ * @returns {CullingVolume} A culling volume at the given position and orientation.
115
+ *
116
+ * @example
117
+ * // Check if a bounding volume intersects the frustum.
118
+ * const cullingVolume = frustum.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);
119
+ * const intersect = cullingVolume.computeVisibility(boundingVolume);
120
+ */
121
+ // eslint-disable-next-line complexity, max-statements
122
+ computeCullingVolume(
123
+ /** A Vector3 defines the eye position. */
124
+ position,
125
+ /** A Vector3 defines the view direction. */
126
+ direction,
127
+ /** A Vector3 defines the up direction. */
128
+ up) {
129
+ assert(position, 'position is required.');
130
+ assert(direction, 'direction is required.');
131
+ assert(up, 'up is required.');
132
+ const planes = this._cullingVolume.planes;
133
+ up = scratchPlaneUpVector.copy(up).normalize();
134
+ const right = scratchPlaneRightVector.copy(direction).cross(up).normalize();
135
+ const nearCenter = scratchPlaneNearCenter
136
+ .copy(direction)
137
+ .multiplyByScalar(this.near)
138
+ .add(position);
139
+ const farCenter = scratchPlaneFarCenter
140
+ .copy(direction)
141
+ .multiplyByScalar(this.far)
142
+ .add(position);
143
+ let normal = scratchPlaneNormal;
144
+ // Left plane computation
145
+ normal.copy(right).multiplyByScalar(this.left).add(nearCenter).subtract(position).cross(up);
146
+ planes[0].fromPointNormal(position, normal);
147
+ // Right plane computation
148
+ normal
149
+ .copy(right)
150
+ .multiplyByScalar(this.right)
151
+ .add(nearCenter)
152
+ .subtract(position)
153
+ .cross(up)
154
+ .negate();
155
+ planes[1].fromPointNormal(position, normal);
156
+ // Bottom plane computation
157
+ normal
158
+ .copy(up)
159
+ .multiplyByScalar(this.bottom)
160
+ .add(nearCenter)
161
+ .subtract(position)
162
+ .cross(right)
163
+ .negate();
164
+ planes[2].fromPointNormal(position, normal);
165
+ // Top plane computation
166
+ normal.copy(up).multiplyByScalar(this.top).add(nearCenter).subtract(position).cross(right);
167
+ planes[3].fromPointNormal(position, normal);
168
+ normal = new Vector3().copy(direction);
169
+ // Near plane computation
170
+ planes[4].fromPointNormal(nearCenter, normal);
171
+ // Far plane computation
172
+ normal.negate();
173
+ planes[5].fromPointNormal(farCenter, normal);
174
+ return this._cullingVolume;
175
+ }
176
+ /**
177
+ * Returns the pixel's width and height in meters.
178
+ *
179
+ * @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.
180
+ *
181
+ * @exception {DeveloperError} drawingBufferWidth must be greater than zero.
182
+ * @exception {DeveloperError} drawingBufferHeight must be greater than zero.
183
+ *
184
+ * @example
185
+ * // Example 1
186
+ * // Get the width and height of a pixel.
187
+ * const pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 1.0, new Vector2());
188
+ *
189
+ * @example
190
+ * // Example 2
191
+ * // Get the width and height of a pixel if the near plane was set to 'distance'.
192
+ * // For example, get the size of a pixel of an image on a billboard.
193
+ * const position = camera.position;
194
+ * const direction = camera.direction;
195
+ * const toCenter = Vector3.subtract(primitive.boundingVolume.center, position, new Vector3()); // vector from camera to a primitive
196
+ * const toCenterProj = Vector3.multiplyByScalar(direction, Vector3.dot(direction, toCenter), new Vector3()); // project vector onto camera direction vector
197
+ * const distance = Vector3.magnitude(toCenterProj);
198
+ * const pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, new Vector2());
199
+ */
200
+ getPixelDimensions(
201
+ /** The width of the drawing buffer. */
202
+ drawingBufferWidth,
203
+ /** The height of the drawing buffer. */
204
+ drawingBufferHeight,
205
+ /** The distance to the near plane in meters. */
206
+ distance,
207
+ /** The object onto which to store the result. */
208
+ result) {
209
+ this._update();
210
+ assert(Number.isFinite(drawingBufferWidth) && Number.isFinite(drawingBufferHeight));
211
+ // 'Both drawingBufferWidth and drawingBufferHeight are required.'
212
+ assert(drawingBufferWidth > 0);
213
+ // 'drawingBufferWidth must be greater than zero.'
214
+ assert(drawingBufferHeight > 0);
215
+ // 'drawingBufferHeight must be greater than zero.'
216
+ assert(distance > 0);
217
+ // 'distance is required.');
218
+ assert(result);
219
+ // 'A result object is required.');
220
+ const inverseNear = 1.0 / this.near;
221
+ let tanTheta = this.top * inverseNear;
222
+ const pixelHeight = (2.0 * distance * tanTheta) / drawingBufferHeight;
223
+ tanTheta = this.right * inverseNear;
224
+ const pixelWidth = (2.0 * distance * tanTheta) / drawingBufferWidth;
225
+ result.x = pixelWidth;
226
+ result.y = pixelHeight;
227
+ return result;
228
+ }
229
+ // eslint-disable-next-line complexity, max-statements
230
+ _update() {
231
+ assert(Number.isFinite(this.right) &&
232
+ Number.isFinite(this.left) &&
233
+ Number.isFinite(this.top) &&
234
+ Number.isFinite(this.bottom) &&
235
+ Number.isFinite(this.near) &&
236
+ Number.isFinite(this.far));
237
+ // throw new DeveloperError('right, left, top, bottom, near, or far parameters are not set.');
238
+ const { top, bottom, right, left, near, far } = this;
239
+ if (top !== this._top ||
240
+ bottom !== this._bottom ||
241
+ left !== this._left ||
242
+ right !== this._right ||
243
+ near !== this._near ||
244
+ far !== this._far) {
245
+ assert(this.near > 0 && this.near < this.far, 'near must be greater than zero and less than far.');
246
+ this._left = left;
247
+ this._right = right;
248
+ this._top = top;
249
+ this._bottom = bottom;
250
+ this._near = near;
251
+ this._far = far;
252
+ this._perspectiveMatrix = new Matrix4().frustum({
253
+ left,
254
+ right,
255
+ bottom,
256
+ top,
257
+ near,
258
+ far
259
+ });
260
+ this._infinitePerspective = new Matrix4().frustum({
261
+ left,
262
+ right,
263
+ bottom,
264
+ top,
265
+ near,
266
+ far: Infinity
267
+ });
268
+ }
165
269
  }
166
- }
167
-
168
270
  }
169
- //# sourceMappingURL=perspective-off-center-frustum.js.map
@@ -23,4 +23,3 @@ export declare class Plane {
23
23
  projectPointOntoPlane(point: Readonly<NumericArray>, result: Vector3): Vector3;
24
24
  projectPointOntoPlane(point: Readonly<NumericArray>, result?: readonly number[]): readonly number[];
25
25
  }
26
- //# sourceMappingURL=plane.d.ts.map
package/dist/lib/plane.js CHANGED
@@ -1,64 +1,63 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
1
+ // This file is derived from the Cesium math library under Apache 2 license
2
+ // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
3
+ /* eslint-disable */
2
4
  import { Vector3, equals, assert } from '@math.gl/core';
3
5
  const scratchPosition = new Vector3();
4
6
  const scratchNormal = new Vector3();
7
+ // A plane in Hessian Normal Form
5
8
  export class Plane {
6
- constructor(normal = [0, 0, 1], distance = 0) {
7
- _defineProperty(this, "normal", void 0);
8
-
9
- _defineProperty(this, "distance", void 0);
10
-
11
- this.normal = new Vector3();
12
- this.distance = -0;
13
- this.fromNormalDistance(normal, distance);
14
- }
15
-
16
- fromNormalDistance(normal, distance) {
17
- assert(Number.isFinite(distance));
18
- this.normal.from(normal).normalize();
19
- this.distance = distance;
20
- return this;
21
- }
22
-
23
- fromPointNormal(point, normal) {
24
- point = scratchPosition.from(point);
25
- this.normal.from(normal).normalize();
26
- const distance = -this.normal.dot(point);
27
- this.distance = distance;
28
- return this;
29
- }
30
-
31
- fromCoefficients(a, b, c, d) {
32
- this.normal.set(a, b, c);
33
- assert(equals(this.normal.len(), 1));
34
- this.distance = d;
35
- return this;
36
- }
37
-
38
- clone() {
39
- return new Plane(this.normal, this.distance);
40
- }
41
-
42
- equals(right) {
43
- return equals(this.distance, right.distance) && equals(this.normal, right.normal);
44
- }
45
-
46
- getPointDistance(point) {
47
- return this.normal.dot(point) + this.distance;
48
- }
49
-
50
- transform(matrix4) {
51
- const normal = scratchNormal.copy(this.normal).transformAsVector(matrix4).normalize();
52
- const point = this.normal.scale(-this.distance).transform(matrix4);
53
- return this.fromPointNormal(point, normal);
54
- }
55
-
56
- projectPointOntoPlane(point, result = [0, 0, 0]) {
57
- const scratchPoint = scratchPosition.from(point);
58
- const pointDistance = this.getPointDistance(scratchPoint);
59
- const scaledNormal = scratchNormal.copy(this.normal).scale(pointDistance);
60
- return scratchPoint.subtract(scaledNormal).to(result);
61
- }
62
-
9
+ constructor(normal = [0, 0, 1], distance = 0) {
10
+ this.normal = new Vector3();
11
+ this.distance = -0;
12
+ this.fromNormalDistance(normal, distance);
13
+ }
14
+ /** Creates a plane from a normal and a distance from the origin. */
15
+ fromNormalDistance(normal, distance) {
16
+ assert(Number.isFinite(distance));
17
+ this.normal.from(normal).normalize();
18
+ this.distance = distance;
19
+ return this;
20
+ }
21
+ /** Creates a plane from a normal and a point on the plane. */
22
+ fromPointNormal(point, normal) {
23
+ point = scratchPosition.from(point);
24
+ this.normal.from(normal).normalize();
25
+ const distance = -this.normal.dot(point);
26
+ this.distance = distance;
27
+ return this;
28
+ }
29
+ /** Creates a plane from the general equation */
30
+ fromCoefficients(a, b, c, d) {
31
+ this.normal.set(a, b, c);
32
+ assert(equals(this.normal.len(), 1));
33
+ this.distance = d;
34
+ return this;
35
+ }
36
+ /** Duplicates a Plane instance. */
37
+ clone() {
38
+ return new Plane(this.normal, this.distance);
39
+ }
40
+ /** Compares the provided Planes by normal and distance */
41
+ equals(right) {
42
+ return equals(this.distance, right.distance) && equals(this.normal, right.normal);
43
+ }
44
+ /** Computes the signed shortest distance of a point to a plane.
45
+ * The sign of the distance determines which side of the plane the point is on.
46
+ */
47
+ getPointDistance(point) {
48
+ return this.normal.dot(point) + this.distance;
49
+ }
50
+ /** Transforms the plane by the given transformation matrix. */
51
+ transform(matrix4) {
52
+ const normal = scratchNormal.copy(this.normal).transformAsVector(matrix4).normalize();
53
+ const point = this.normal.scale(-this.distance).transform(matrix4);
54
+ return this.fromPointNormal(point, normal);
55
+ }
56
+ projectPointOntoPlane(point, result = [0, 0, 0]) {
57
+ const scratchPoint = scratchPosition.from(point);
58
+ // projectedPoint = point - (normal.point + scale) * normal
59
+ const pointDistance = this.getPointDistance(scratchPoint);
60
+ const scaledNormal = scratchNormal.copy(this.normal).scale(pointDistance);
61
+ return scratchPoint.subtract(scaledNormal).to(result);
62
+ }
63
63
  }
64
- //# sourceMappingURL=plane.js.map
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
9
- "version": "4.0.0-beta.1",
9
+ "version": "4.0.1",
10
10
  "keywords": [
11
11
  "webgl",
12
12
  "javascript",
@@ -32,9 +32,9 @@
32
32
  "module": "dist/index.js",
33
33
  "exports": {
34
34
  ".": {
35
+ "types": "./dist/index.d.ts",
35
36
  "import": "./dist/index.js",
36
- "require": "./dist/index.cjs",
37
- "types": "./dist/index.d.ts"
37
+ "require": "./dist/index.cjs"
38
38
  }
39
39
  },
40
40
  "files": [
@@ -42,8 +42,7 @@
42
42
  "src"
43
43
  ],
44
44
  "dependencies": {
45
- "@babel/runtime": "^7.12.0",
46
- "@math.gl/core": "4.0.0-beta.1"
45
+ "@math.gl/core": "4.0.1"
47
46
  },
48
- "gitHead": "5a2364216b6aadbece690e05b9b5b71753aee472"
47
+ "gitHead": "33f369ba3a259f79acc3fa8181190c9da8841648"
49
48
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,YAAY;;;;CAIf,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/constants.ts"],"names":["INTERSECTION","OUTSIDE","INTERSECTING","INSIDE"],"mappings":"AAGA,OAAO,MAAMA,YAAY,GAAG;AAC1BC,EAAAA,OAAO,EAAE,CAAC,CADgB;AAE1BC,EAAAA,YAAY,EAAE,CAFY;AAG1BC,EAAAA,MAAM,EAAE;AAHkB,CAArB","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\nexport const INTERSECTION = {\n OUTSIDE: -1, // Represents that an object is not contained within the frustum.\n INTERSECTING: 0, // Represents that an object intersects one of the frustum's planes.\n INSIDE: 1 // Represents that an object is fully within the frustum.\n} as const;\n"],"file":"constants.js"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAC,sBAAsB,EAAC,MAAM,kDAAkD,CAAC;AACxF,OAAO,EAAC,cAAc,EAAC,MAAM,wCAAwC,CAAC;AACtE,OAAO,EAAC,mBAAmB,EAAC,MAAM,8CAA8C,CAAC;AACjF,OAAO,EAAC,aAAa,EAAC,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAC,KAAK,EAAC,MAAM,aAAa,CAAC;AAElC,OAAO,EAAC,2BAA2B,IAAI,4BAA4B,EAAC,MAAM,sCAAsC,CAAC;AACjH,OAAO,EAAC,kBAAkB,IAAI,mBAAmB,EAAC,MAAM,2BAA2B,CAAC;AAEpF,OAAO,EAAC,4BAA4B,EAAC,MAAM,8CAA8C,CAAC;AAC1F,OAAO,EACL,oCAAoC,EACpC,iCAAiC,EAClC,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAC,yBAAyB,EAAC,MAAM,8CAA8C,CAAC"}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["INTERSECTION","AxisAlignedBoundingBox","BoundingSphere","OrientedBoundingBox","CullingVolume","Plane","PerspectiveOffCenterFrustum","_PerspectiveOffCenterFrustum","PerspectiveFrustum","_PerspectiveFrustum","makeBoundingSphereFromPoints","makeAxisAlignedBoundingBoxFromPoints","makeOrientedBoundingBoxFromPoints","computeEigenDecomposition"],"mappings":"SAGQA,Y;SAEAC,sB;SACAC,c;SACAC,mB;SACAC,a;SACAC,K;SAEAC,2BAA2B,IAAIC,4B;SAC/BC,kBAAkB,IAAIC,mB;SAEtBC,4B;SAENC,oC,EACAC,iC;SAEMC,yB","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\nexport {INTERSECTION} from './constants';\n\nexport {AxisAlignedBoundingBox} from './lib/bounding-volumes/axis-aligned-bounding-box';\nexport {BoundingSphere} from './lib/bounding-volumes/bounding-sphere';\nexport {OrientedBoundingBox} from './lib/bounding-volumes/oriented-bounding-box';\nexport {CullingVolume} from './lib/culling-volume';\nexport {Plane} from './lib/plane';\n\nexport {PerspectiveOffCenterFrustum as _PerspectiveOffCenterFrustum} from './lib/perspective-off-center-frustum';\nexport {PerspectiveFrustum as _PerspectiveFrustum} from './lib/perspective-frustum';\n\nexport {makeBoundingSphereFromPoints} from './lib/algorithms/bounding-sphere-from-points';\nexport {\n makeAxisAlignedBoundingBoxFromPoints,\n makeOrientedBoundingBoxFromPoints\n} from './lib/algorithms/bounding-box-from-points';\nexport {computeEigenDecomposition} from './lib/algorithms/compute-eigen-decomposition';\n"],"file":"index.js"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"bounding-box-from-points.d.ts","sourceRoot":"","sources":["../../../src/lib/algorithms/bounding-box-from-points.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,mBAAmB,EAAC,MAAM,2CAA2C,CAAC;AAC9E,OAAO,EAAC,sBAAsB,EAAC,MAAM,+CAA+C,CAAC;AAmBrF;;;;;GAKG;AAEH,wBAAgB,iCAAiC,CAC/C,SAAS,EAAE,MAAM,EAAE,EAAE,EACrB,MAAM,GAAE,mBAA+C,GACtD,mBAAmB,CAuFrB;AAED;;;GAGG;AACH,wBAAgB,oCAAoC,CAClD,SAAS,EAAE,SAAS,MAAM,EAAE,EAAE,EAC9B,MAAM,GAAE,sBAAqD,GAC5D,sBAAsB,CAoCxB"}