@math.gl/culling 3.6.0-alpha.4 → 3.6.0-alpha.7

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 (35) hide show
  1. package/dist/es5/lib/algorithms/compute-eigen-decomposition.js.map +1 -1
  2. package/dist/es5/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -1
  3. package/dist/es5/lib/bounding-volumes/oriented-bounding-box.js.map +1 -1
  4. package/dist/es5/lib/perspective-frustum.js +63 -58
  5. package/dist/es5/lib/perspective-frustum.js.map +1 -1
  6. package/dist/es5/lib/perspective-off-center-frustum.js +51 -51
  7. package/dist/es5/lib/perspective-off-center-frustum.js.map +1 -1
  8. package/dist/es5/lib/plane.js.map +1 -1
  9. package/dist/esm/lib/algorithms/compute-eigen-decomposition.js.map +1 -1
  10. package/dist/esm/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -1
  11. package/dist/esm/lib/bounding-volumes/oriented-bounding-box.js.map +1 -1
  12. package/dist/esm/lib/perspective-frustum.js +60 -55
  13. package/dist/esm/lib/perspective-frustum.js.map +1 -1
  14. package/dist/esm/lib/perspective-off-center-frustum.js +48 -46
  15. package/dist/esm/lib/perspective-off-center-frustum.js.map +1 -1
  16. package/dist/esm/lib/plane.js.map +1 -1
  17. package/dist/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +1 -1
  18. package/dist/lib/bounding-volumes/axis-aligned-bounding-box.d.ts.map +1 -1
  19. package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts +2 -2
  20. package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts.map +1 -1
  21. package/dist/lib/perspective-frustum.d.ts +52 -40
  22. package/dist/lib/perspective-frustum.d.ts.map +1 -1
  23. package/dist/lib/perspective-frustum.js +81 -96
  24. package/dist/lib/perspective-off-center-frustum.d.ts +74 -38
  25. package/dist/lib/perspective-off-center-frustum.d.ts.map +1 -1
  26. package/dist/lib/perspective-off-center-frustum.js +64 -99
  27. package/dist/lib/plane.d.ts +8 -8
  28. package/dist/lib/plane.d.ts.map +1 -1
  29. package/package.json +3 -3
  30. package/src/lib/algorithms/compute-eigen-decomposition.ts +3 -3
  31. package/src/lib/bounding-volumes/axis-aligned-bounding-box.ts +2 -2
  32. package/src/lib/bounding-volumes/oriented-bounding-box.ts +2 -2
  33. package/src/lib/perspective-frustum.ts +115 -118
  34. package/src/lib/perspective-off-center-frustum.ts +137 -131
  35. package/src/lib/plane.ts +11 -8
@@ -3,7 +3,6 @@
3
3
  // Note: This class is still an experimental export, mainly used by other test cases
4
4
  // - It has not been fully adapted to math.gl conventions
5
5
  // - Documentation has not been ported
6
- // @ts-nocheck
7
6
  import { Vector3, Matrix4, assert } from '@math.gl/core';
8
7
  import CullingVolume from './culling-volume';
9
8
  import Plane from './plane';
@@ -20,15 +19,6 @@ export default class PerspectiveOffCenterFrustum {
20
19
  * plane from the origin/camera position.
21
20
  *
22
21
  * @alias PerspectiveOffCenterFrustum
23
- * @constructor
24
- *
25
- * @param {Object} [options] An object with the following properties:
26
- * @param {Number} [options.left] The left clipping plane distance.
27
- * @param {Number} [options.right] The right clipping plane distance.
28
- * @param {Number} [options.top] The top clipping plane distance.
29
- * @param {Number} [options.bottom] The bottom clipping plane distance.
30
- * @param {Number} [options.near=1.0] The near clipping plane distance.
31
- * @param {Number} [options.far=500000000.0] The far clipping plane distance.
32
22
  *
33
23
  * @example
34
24
  * const frustum = new PerspectiveOffCenterFrustum({
@@ -53,49 +43,19 @@ export default class PerspectiveOffCenterFrustum {
53
43
  ]);
54
44
  this._perspectiveMatrix = new Matrix4();
55
45
  this._infinitePerspective = new Matrix4();
56
- options = { near: 1.0, far: 500000000.0, ...options };
57
- /**
58
- * Defines the left clipping plane.
59
- * @type {Number}
60
- * @default undefined
61
- */
46
+ const { near = 1.0, far = 500000000.0 } = options;
62
47
  this.left = options.left;
63
48
  this._left = undefined;
64
- /**
65
- * Defines the right clipping plane.
66
- * @type {Number}
67
- * @default undefined
68
- */
69
49
  this.right = options.right;
70
50
  this._right = undefined;
71
- /**
72
- * Defines the top clipping plane.
73
- * @type {Number}
74
- * @default undefined
75
- */
76
51
  this.top = options.top;
77
52
  this._top = undefined;
78
- /**
79
- * Defines the bottom clipping plane.
80
- * @type {Number}
81
- * @default undefined
82
- */
83
53
  this.bottom = options.bottom;
84
54
  this._bottom = undefined;
85
- /**
86
- * The distance of the near plane.
87
- * @type {Number}
88
- * @default 1.0
89
- */
90
- this.near = options.near;
91
- this._near = this.near;
92
- /**
93
- * The distance of the far plane.
94
- * @type {Number}
95
- * @default 500000000.0
96
- */
97
- this.far = options.far;
98
- this._far = this.far;
55
+ this.near = near;
56
+ this._near = near;
57
+ this.far = far;
58
+ this._far = far;
99
59
  }
100
60
  /**
101
61
  * Returns a duplicate of a PerspectiveOffCenterFrustum instance.
@@ -115,7 +75,6 @@ export default class PerspectiveOffCenterFrustum {
115
75
  * Compares the provided PerspectiveOffCenterFrustum componentwise and returns
116
76
  * <code>true</code> if they are equal, <code>false</code> otherwise.
117
77
  *
118
- * @param {PerspectiveOffCenterFrustum} [other] The right hand side PerspectiveOffCenterFrustum.
119
78
  * @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
120
79
  */
121
80
  equals(other) {
@@ -136,7 +95,7 @@ export default class PerspectiveOffCenterFrustum {
136
95
  * @see PerspectiveOffCenterFrustum#infiniteProjectionMatrix
137
96
  */
138
97
  get projectionMatrix() {
139
- update(this);
98
+ this._update();
140
99
  return this._perspectiveMatrix;
141
100
  }
142
101
  /**
@@ -147,15 +106,11 @@ export default class PerspectiveOffCenterFrustum {
147
106
  * @see PerspectiveOffCenterFrustum#projectionMatrix
148
107
  */
149
108
  get infiniteProjectionMatrix() {
150
- update(this);
109
+ this._update();
151
110
  return this._infinitePerspective;
152
111
  }
153
112
  /**
154
113
  * Creates a culling volume for this frustum.
155
- *
156
- * @param {Vector3} position The eye position.
157
- * @param {Vector3} direction The view direction.
158
- * @param {Vector3} up The up direction.
159
114
  * @returns {CullingVolume} A culling volume at the given position and orientation.
160
115
  *
161
116
  * @example
@@ -164,7 +119,13 @@ export default class PerspectiveOffCenterFrustum {
164
119
  * const intersect = cullingVolume.computeVisibility(boundingVolume);
165
120
  */
166
121
  // eslint-disable-next-line complexity, max-statements
167
- computeCullingVolume(position, direction, up) {
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) {
168
129
  assert(position, 'position is required.');
169
130
  assert(direction, 'direction is required.');
170
131
  assert(up, 'up is required.');
@@ -215,10 +176,6 @@ export default class PerspectiveOffCenterFrustum {
215
176
  /**
216
177
  * Returns the pixel's width and height in meters.
217
178
  *
218
- * @param {Number} drawingBufferWidth The width of the drawing buffer.
219
- * @param {Number} drawingBufferHeight The height of the drawing buffer.
220
- * @param {Number} distance The distance to the near plane in meters.
221
- * @param {Vector2} result The object onto which to store the result.
222
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.
223
180
  *
224
181
  * @exception {DeveloperError} drawingBufferWidth must be greater than zero.
@@ -240,8 +197,16 @@ export default class PerspectiveOffCenterFrustum {
240
197
  * const distance = Vector3.magnitude(toCenterProj);
241
198
  * const pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, new Vector2());
242
199
  */
243
- getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {
244
- update(this);
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();
245
210
  assert(Number.isFinite(drawingBufferWidth) && Number.isFinite(drawingBufferHeight));
246
211
  // 'Both drawingBufferWidth and drawingBufferHeight are required.'
247
212
  assert(drawingBufferWidth > 0);
@@ -261,45 +226,45 @@ export default class PerspectiveOffCenterFrustum {
261
226
  result.y = pixelHeight;
262
227
  return result;
263
228
  }
264
- }
265
- // eslint-disable-next-line complexity, max-statements
266
- function update(frustum) {
267
- assert(Number.isFinite(frustum.right) &&
268
- Number.isFinite(frustum.left) &&
269
- Number.isFinite(frustum.top) &&
270
- Number.isFinite(frustum.bottom) &&
271
- Number.isFinite(frustum.near) &&
272
- Number.isFinite(frustum.far));
273
- // throw new DeveloperError('right, left, top, bottom, near, or far parameters are not set.');
274
- const { top, bottom, right, left, near, far } = frustum;
275
- if (top !== frustum._top ||
276
- bottom !== frustum._bottom ||
277
- left !== frustum._left ||
278
- right !== frustum._right ||
279
- near !== frustum._near ||
280
- far !== frustum._far) {
281
- assert(frustum.near > 0 && frustum.near < frustum.far, 'near must be greater than zero and less than far.');
282
- frustum._left = left;
283
- frustum._right = right;
284
- frustum._top = top;
285
- frustum._bottom = bottom;
286
- frustum._near = near;
287
- frustum._far = far;
288
- frustum._perspectiveMatrix = new Matrix4().frustum({
289
- left,
290
- right,
291
- bottom,
292
- top,
293
- near,
294
- far
295
- });
296
- frustum._infinitePerspective = new Matrix4().frustum({
297
- left,
298
- right,
299
- bottom,
300
- top,
301
- near,
302
- far: Infinity
303
- });
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
+ }
304
269
  }
305
270
  }
@@ -1,12 +1,12 @@
1
- import { Vector3 } from '@math.gl/core';
1
+ import { Vector3, NumericArray } from '@math.gl/core';
2
2
  export default class Plane {
3
3
  readonly normal: Vector3;
4
4
  distance: number;
5
- constructor(normal?: readonly number[], distance?: number);
5
+ constructor(normal?: Readonly<NumericArray>, distance?: number);
6
6
  /** Creates a plane from a normal and a distance from the origin. */
7
- fromNormalDistance(normal: readonly number[], distance: number): this;
7
+ fromNormalDistance(normal: Readonly<NumericArray>, distance: number): this;
8
8
  /** Creates a plane from a normal and a point on the plane. */
9
- fromPointNormal(point: readonly number[], normal: readonly number[]): this;
9
+ fromPointNormal(point: Readonly<NumericArray>, normal: Readonly<NumericArray>): this;
10
10
  /** Creates a plane from the general equation */
11
11
  fromCoefficients(a: number, b: number, c: number, d: number): this;
12
12
  /** Duplicates a Plane instance. */
@@ -16,11 +16,11 @@ export default class Plane {
16
16
  /** Computes the signed shortest distance of a point to a plane.
17
17
  * The sign of the distance determines which side of the plane the point is on.
18
18
  */
19
- getPointDistance(point: readonly number[]): number;
19
+ getPointDistance(point: Readonly<NumericArray>): number;
20
20
  /** Transforms the plane by the given transformation matrix. */
21
- transform(matrix4: readonly number[]): this;
21
+ transform(matrix4: Readonly<NumericArray>): this;
22
22
  /** Projects a point onto the plane. */
23
- projectPointOntoPlane(point: readonly number[], result: Vector3): Vector3;
24
- projectPointOntoPlane(point: readonly number[], result?: readonly number[]): readonly number[];
23
+ projectPointOntoPlane(point: Readonly<NumericArray>, result: Vector3): Vector3;
24
+ projectPointOntoPlane(point: Readonly<NumericArray>, result?: readonly number[]): readonly number[];
25
25
  }
26
26
  //# sourceMappingURL=plane.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"plane.d.ts","sourceRoot":"","sources":["../../src/lib/plane.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,OAAO,EAAiB,MAAM,eAAe,CAAC;AAMtD,MAAM,CAAC,OAAO,OAAO,KAAK;IACxB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;gBAEL,MAAM,GAAE,SAAS,MAAM,EAAc,EAAE,QAAQ,GAAE,MAAU;IAMvE,oEAAoE;IACpE,kBAAkB,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IAOrE,8DAA8D;IAC9D,eAAe,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI;IAQ1E,gDAAgD;IAChD,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI;IAOlE,mCAAmC;IACnC,KAAK,IAAI,KAAK;IAId,0DAA0D;IAC1D,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO;IAI7B;;OAEG;IACH,gBAAgB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM;IAIlD,+DAA+D;IAC/D,SAAS,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI;IAM3C,uCAAuC;IACvC,qBAAqB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO;IACzE,qBAAqB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,MAAM,EAAE;CAU/F"}
1
+ {"version":3,"file":"pl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fig": {
6
6
  "access": "public"
7
7
  },
8
- "version": "3.6.0-alpha.4",
8
+ "version": "3.6.0-alpha.7",
9
9
  "keywords": [
10
10
  "webgl",
11
11
  "javascript",
@@ -35,8 +35,8 @@
35
35
  ],
36
36
  "dependencies": {
37
37
  "@babel/runtime": "^7.12.0",
38
- "@math.gl/core": "3.6.0-alpha.4",
38
+ "@math.gl/core": "3.6.0-alpha.7",
39
39
  "gl-matrix": "^3.4.0"
40
40
  },
41
- "gitHead": "d2ce86da8b6f07f0af0236818138442f68e1d8e4"
41
+ "gitHead": "166f7411d07d545e6a3f247b55b56f5cb8efccde"
42
42
  }
@@ -85,7 +85,7 @@ export default function computeEigenDecomposition(
85
85
  return result;
86
86
  }
87
87
 
88
- function computeFrobeniusNorm(matrix) {
88
+ function computeFrobeniusNorm(matrix: Matrix3): number {
89
89
  let norm = 0.0;
90
90
  for (let i = 0; i < 9; ++i) {
91
91
  const temp = matrix[i];
@@ -99,7 +99,7 @@ const colVal = [2, 2, 1];
99
99
 
100
100
  // Computes the "off-diagonal" Frobenius norm.
101
101
  // Assumes matrix is symmetric.
102
- function offDiagonalFrobeniusNorm(matrix) {
102
+ function offDiagonalFrobeniusNorm(matrix: Matrix3): number {
103
103
  let norm = 0.0;
104
104
  for (let i = 0; i < 3; ++i) {
105
105
  const temp = matrix[scratchMatrix.getElementIndex(colVal[i], rowVal[i])];
@@ -116,7 +116,7 @@ function offDiagonalFrobeniusNorm(matrix) {
116
116
  // section 8.4.2 The 2by2 Symmetric Schur Decomposition.
117
117
  //
118
118
  // eslint-disable-next-line max-statements
119
- function shurDecomposition(matrix, result) {
119
+ function shurDecomposition(matrix: Matrix3, result: Matrix3): Matrix3 {
120
120
  const tolerance = _MathUtils.EPSILON15;
121
121
 
122
122
  let maxDiagonal = 0.0;
@@ -58,7 +58,7 @@ export default class AxisAlignedBoundingBox implements BoundingVolume {
58
58
  *
59
59
  * @returns {AxisAlignedBoundingBox} A new AxisAlignedBoundingBox instance.
60
60
  */
61
- clone() {
61
+ clone(): AxisAlignedBoundingBox {
62
62
  return new AxisAlignedBoundingBox(this.minimum, this.maximum, this.center);
63
63
  }
64
64
 
@@ -69,7 +69,7 @@ export default class AxisAlignedBoundingBox implements BoundingVolume {
69
69
  * @param {AxisAlignedBoundingBox} [right] The second AxisAlignedBoundingBox to compare with.
70
70
  * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
71
71
  */
72
- equals(right) {
72
+ equals(right: AxisAlignedBoundingBox): boolean {
73
73
  return (
74
74
  this === right ||
75
75
  (Boolean(right) && this.minimum.equals(right.minimum) && this.maximum.equals(right.maximum))
@@ -1,7 +1,7 @@
1
1
  // This file is derived from the Cesium math library under Apache 2 license
2
2
  // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
3
3
 
4
- import {Vector3, Matrix3, Quaternion, NumericArray} from '@math.gl/core';
4
+ import {Vector3, Matrix3, Matrix4, Quaternion, NumericArray} from '@math.gl/core';
5
5
  import type {BoundingVolume} from './bounding-volume';
6
6
  import BoundingSphere from './bounding-sphere';
7
7
  import type Plane from '../plane';
@@ -336,7 +336,7 @@ export default class OrientedBoundingBox implements BoundingVolume {
336
336
  return this;
337
337
  }
338
338
 
339
- getTransform() {
339
+ getTransform(): Matrix4 {
340
340
  // const modelMatrix = Matrix4.fromRotationTranslation(this.boundingVolume.halfAxes, this.boundingVolume.center);
341
341
  // return modelMatrix;
342
342
  throw new Error('not implemented');