@math.gl/core 4.0.0-alpha.1 → 4.0.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/classes/base/math-array.d.ts +2 -1
- package/dist/classes/base/math-array.d.ts.map +1 -1
- package/dist/classes/base/math-array.js +5 -1
- package/dist/classes/base/math-array.js.map +1 -1
- package/dist/classes/base/matrix.d.ts +2 -2
- package/dist/classes/base/matrix.d.ts.map +1 -1
- package/dist/classes/base/matrix.js +2 -2
- package/dist/classes/base/matrix.js.map +1 -1
- package/dist/classes/base/vector.d.ts +2 -2
- package/dist/classes/base/vector.d.ts.map +1 -1
- package/dist/classes/base/vector.js +3 -3
- package/dist/classes/base/vector.js.map +1 -1
- package/dist/classes/euler.d.ts +3 -3
- package/dist/classes/euler.d.ts.map +1 -1
- package/dist/classes/euler.js +4 -4
- package/dist/classes/euler.js.map +1 -1
- package/dist/classes/matrix3.d.ts +5 -2
- package/dist/classes/matrix3.d.ts.map +1 -1
- package/dist/classes/matrix3.js +17 -17
- package/dist/classes/matrix3.js.map +1 -1
- package/dist/classes/matrix4.d.ts +2 -2
- package/dist/classes/matrix4.d.ts.map +1 -1
- package/dist/classes/matrix4.js +25 -25
- package/dist/classes/matrix4.js.map +1 -1
- package/dist/classes/pose.d.ts +5 -5
- package/dist/classes/pose.d.ts.map +1 -1
- package/dist/classes/pose.js +4 -4
- package/dist/classes/pose.js.map +1 -1
- package/dist/classes/quaternion.d.ts +2 -2
- package/dist/classes/quaternion.d.ts.map +1 -1
- package/dist/classes/quaternion.js +25 -25
- package/dist/classes/quaternion.js.map +1 -1
- package/dist/classes/spherical-coordinates.d.ts +4 -4
- package/dist/classes/spherical-coordinates.d.ts.map +1 -1
- package/dist/classes/spherical-coordinates.js +3 -3
- package/dist/classes/spherical-coordinates.js.map +1 -1
- package/dist/classes/vector2.d.ts +2 -2
- package/dist/classes/vector2.d.ts.map +1 -1
- package/dist/classes/vector2.js +7 -7
- package/dist/classes/vector2.js.map +1 -1
- package/dist/classes/vector3.d.ts +2 -2
- package/dist/classes/vector3.d.ts.map +1 -1
- package/dist/classes/vector3.js +11 -11
- package/dist/classes/vector3.js.map +1 -1
- package/dist/classes/vector4.d.ts +3 -3
- package/dist/classes/vector4.d.ts.map +1 -1
- package/dist/classes/vector4.js +5 -5
- package/dist/classes/vector4.js.map +1 -1
- package/dist/gl-matrix/common.d.ts +38 -0
- package/dist/gl-matrix/common.d.ts.map +1 -0
- package/dist/gl-matrix/common.js +19 -0
- package/dist/gl-matrix/common.js.map +1 -0
- package/dist/gl-matrix/mat3.d.ts +295 -0
- package/dist/gl-matrix/mat3.d.ts.map +1 -0
- package/dist/gl-matrix/mat3.js +489 -0
- package/dist/gl-matrix/mat3.js.map +1 -0
- package/dist/gl-matrix/mat4.d.ts +577 -0
- package/dist/gl-matrix/mat4.d.ts.map +1 -0
- package/dist/gl-matrix/mat4.js +1455 -0
- package/dist/gl-matrix/mat4.js.map +1 -0
- package/dist/gl-matrix/quat.d.ts +357 -0
- package/dist/gl-matrix/quat.d.ts.map +1 -0
- package/dist/gl-matrix/quat.js +315 -0
- package/dist/gl-matrix/quat.js.map +1 -0
- package/dist/gl-matrix/vec2.d.ts +373 -0
- package/dist/gl-matrix/vec2.d.ts.map +1 -0
- package/dist/gl-matrix/vec2.js +257 -0
- package/dist/gl-matrix/vec2.js.map +1 -0
- package/dist/gl-matrix/vec3.d.ts +416 -0
- package/dist/gl-matrix/vec3.d.ts.map +1 -0
- package/dist/gl-matrix/vec3.js +384 -0
- package/dist/gl-matrix/vec3.js.map +1 -0
- package/dist/gl-matrix/vec4.d.ts +340 -0
- package/dist/gl-matrix/vec4.d.ts.map +1 -0
- package/dist/gl-matrix/vec4.js +334 -0
- package/dist/gl-matrix/vec4.js.map +1 -0
- package/dist/gl-matrix/wip/index.d.ts +5 -0
- package/dist/gl-matrix/wip/index.d.ts.map +1 -0
- package/dist/gl-matrix/wip/index.js +12 -0
- package/dist/gl-matrix/wip/index.js.map +1 -0
- package/dist/gl-matrix/wip/mat2.d.ts +229 -0
- package/dist/gl-matrix/wip/mat2.d.ts.map +1 -0
- package/dist/gl-matrix/wip/mat2.js +208 -0
- package/dist/gl-matrix/wip/mat2.js.map +1 -0
- package/dist/gl-matrix/wip/mat2d.d.ts +244 -0
- package/dist/gl-matrix/wip/mat2d.d.ts.map +1 -0
- package/dist/gl-matrix/wip/mat2d.js +251 -0
- package/dist/gl-matrix/wip/mat2d.js.map +1 -0
- package/dist/gl-matrix/wip/quat2.d.ts +352 -0
- package/dist/gl-matrix/wip/quat2.d.ts.map +1 -0
- package/dist/gl-matrix/wip/quat2.js +482 -0
- package/dist/gl-matrix/wip/quat2.js.map +1 -0
- package/dist/gl-matrix/wip/types.d.js +2 -0
- package/dist/gl-matrix/wip/types.d.js.map +1 -0
- package/dist/index.cjs +1614 -150
- package/dist/index.d.ts +15 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -14
- package/dist/index.js.map +1 -1
- package/dist/lib/assert.d.ts +1 -1
- package/dist/lib/assert.d.ts.map +1 -1
- package/dist/lib/assert.js +1 -1
- package/dist/lib/assert.js.map +1 -1
- package/dist/lib/common.d.ts +11 -6
- package/dist/lib/common.d.ts.map +1 -1
- package/dist/lib/common.js +8 -2
- package/dist/lib/common.js.map +1 -1
- package/dist/lib/math-utils.d.ts +24 -27
- package/dist/lib/math-utils.d.ts.map +1 -1
- package/dist/lib/math-utils.js +24 -26
- package/dist/lib/math-utils.js.map +1 -1
- package/dist/lib/validators.js +1 -1
- package/dist/lib/validators.js.map +1 -1
- package/package.json +3 -4
- package/src/classes/base/math-array.ts +6 -2
- package/src/classes/base/matrix.ts +6 -3
- package/src/classes/base/vector.ts +3 -3
- package/src/classes/euler.ts +5 -4
- package/src/classes/matrix3.ts +32 -23
- package/src/classes/matrix4.ts +45 -31
- package/src/classes/pose.ts +4 -4
- package/src/classes/quaternion.ts +48 -28
- package/src/classes/spherical-coordinates.ts +3 -3
- package/src/classes/vector2.ts +13 -10
- package/src/classes/vector3.ts +25 -12
- package/src/classes/vector4.ts +10 -8
- package/src/gl-matrix/common.js +58 -0
- package/src/gl-matrix/mat3.js +842 -0
- package/src/gl-matrix/mat4.js +2169 -0
- package/src/gl-matrix/quat.ts +789 -0
- package/src/gl-matrix/vec2.js +629 -0
- package/src/gl-matrix/vec3.js +827 -0
- package/src/gl-matrix/vec4.js +675 -0
- package/src/gl-matrix/wip/index.js +15 -0
- package/src/gl-matrix/wip/mat2.js +442 -0
- package/src/gl-matrix/wip/mat2d.js +505 -0
- package/src/gl-matrix/wip/quat2.ts +886 -0
- package/src/gl-matrix/wip/types.d.ts +93 -0
- package/src/index.ts +16 -14
- package/src/lib/assert.ts +1 -1
- package/src/lib/common.ts +29 -13
- package/src/lib/math-utils.ts +24 -26
- package/src/lib/validators.ts +1 -1
- package/dist/docs/README.md +0 -0
- package/src/docs/README.md +0 -0
package/src/classes/matrix3.ts
CHANGED
|
@@ -2,16 +2,23 @@
|
|
|
2
2
|
// MIT License
|
|
3
3
|
|
|
4
4
|
import {NumericArray} from '@math.gl/types';
|
|
5
|
-
import Matrix from './base/matrix';
|
|
5
|
+
import {Matrix} from './base/matrix';
|
|
6
6
|
import {checkVector} from '../lib/validators';
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
import {vec4_transformMat3} from '../lib/gl-matrix-extras';
|
|
9
|
-
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
fromQuat as mat3_fromQuat,
|
|
12
|
+
determinant as mat3_determinant,
|
|
13
|
+
transpose as mat3_transpose,
|
|
14
|
+
invert as mat3_invert,
|
|
15
|
+
multiply as mat3_multiply,
|
|
16
|
+
rotate as mat3_rotate,
|
|
17
|
+
scale as mat3_scale,
|
|
18
|
+
translate as mat3_translate
|
|
19
|
+
} from '../gl-matrix/mat3';
|
|
20
|
+
import {transformMat3 as vec2_transformMat3} from '../gl-matrix/vec2';
|
|
21
|
+
import {transformMat3 as vec3_transformMat3} from '../gl-matrix/vec3';
|
|
15
22
|
|
|
16
23
|
enum INDICES {
|
|
17
24
|
COL0ROW0 = 0,
|
|
@@ -27,7 +34,7 @@ enum INDICES {
|
|
|
27
34
|
|
|
28
35
|
const IDENTITY_MATRIX = Object.freeze([1, 0, 0, 0, 1, 0, 0, 0, 1]);
|
|
29
36
|
|
|
30
|
-
export
|
|
37
|
+
export class Matrix3 extends Matrix {
|
|
31
38
|
static get IDENTITY(): Readonly<Matrix3> {
|
|
32
39
|
return getIdentityMatrix();
|
|
33
40
|
}
|
|
@@ -89,14 +96,16 @@ export default class Matrix3 extends Matrix {
|
|
|
89
96
|
* @param object
|
|
90
97
|
* @returns self
|
|
91
98
|
*/
|
|
99
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
92
100
|
fromObject(object: {[key: string]: any}): this {
|
|
93
101
|
return this.check();
|
|
94
102
|
}
|
|
95
103
|
|
|
96
|
-
|
|
97
|
-
|
|
104
|
+
/** Calculates a 3x3 matrix from the given quaternion
|
|
105
|
+
* q quat Quaternion to create matrix from
|
|
106
|
+
*/
|
|
98
107
|
fromQuaternion(q: Readonly<NumericArray>): this {
|
|
99
|
-
|
|
108
|
+
mat3_fromQuat(this, q);
|
|
100
109
|
return this.check();
|
|
101
110
|
}
|
|
102
111
|
|
|
@@ -157,48 +166,48 @@ export default class Matrix3 extends Matrix {
|
|
|
157
166
|
// Accessors
|
|
158
167
|
|
|
159
168
|
determinant(): number {
|
|
160
|
-
return
|
|
169
|
+
return mat3_determinant(this);
|
|
161
170
|
}
|
|
162
171
|
|
|
163
172
|
// Modifiers
|
|
164
173
|
transpose(): this {
|
|
165
|
-
|
|
174
|
+
mat3_transpose(this, this);
|
|
166
175
|
return this.check();
|
|
167
176
|
}
|
|
168
177
|
|
|
169
178
|
/** Invert a matrix. Note that this can fail if the matrix is not invertible */
|
|
170
179
|
invert(): this {
|
|
171
|
-
|
|
180
|
+
mat3_invert(this, this);
|
|
172
181
|
return this.check();
|
|
173
182
|
}
|
|
174
183
|
|
|
175
184
|
// Operations
|
|
176
185
|
multiplyLeft(a: NumericArray): this {
|
|
177
|
-
|
|
186
|
+
mat3_multiply(this, a, this);
|
|
178
187
|
return this.check();
|
|
179
188
|
}
|
|
180
189
|
|
|
181
190
|
multiplyRight(a: NumericArray): this {
|
|
182
|
-
|
|
191
|
+
mat3_multiply(this, this, a);
|
|
183
192
|
return this.check();
|
|
184
193
|
}
|
|
185
194
|
|
|
186
195
|
rotate(radians: number): NumericArray {
|
|
187
|
-
|
|
196
|
+
mat3_rotate(this, this, radians);
|
|
188
197
|
return this.check();
|
|
189
198
|
}
|
|
190
199
|
|
|
191
200
|
override scale(factor: NumericArray | number): this {
|
|
192
201
|
if (Array.isArray(factor)) {
|
|
193
|
-
|
|
202
|
+
mat3_scale(this, this, factor);
|
|
194
203
|
} else {
|
|
195
|
-
|
|
204
|
+
mat3_scale(this, this, [factor as number, factor as number]);
|
|
196
205
|
}
|
|
197
206
|
return this.check();
|
|
198
207
|
}
|
|
199
208
|
|
|
200
209
|
translate(vec: NumericArray): this {
|
|
201
|
-
|
|
210
|
+
mat3_translate(this, this, vec);
|
|
202
211
|
return this.check();
|
|
203
212
|
}
|
|
204
213
|
|
|
@@ -207,10 +216,10 @@ export default class Matrix3 extends Matrix {
|
|
|
207
216
|
let out: NumericArray;
|
|
208
217
|
switch (vector.length) {
|
|
209
218
|
case 2:
|
|
210
|
-
out =
|
|
219
|
+
out = vec2_transformMat3(result || [-0, -0], vector, this) as NumericArray;
|
|
211
220
|
break;
|
|
212
221
|
case 3:
|
|
213
|
-
out =
|
|
222
|
+
out = vec3_transformMat3(result || [-0, -0, -0], vector, this) as NumericArray;
|
|
214
223
|
break;
|
|
215
224
|
case 4:
|
|
216
225
|
out = vec4_transformMat3(result || [-0, -0, -0, -0], vector, this);
|
package/src/classes/matrix4.ts
CHANGED
|
@@ -2,19 +2,32 @@
|
|
|
2
2
|
// MIT License
|
|
3
3
|
|
|
4
4
|
import {NumericArray} from '@math.gl/types';
|
|
5
|
-
import Matrix from './base/matrix';
|
|
5
|
+
import {Matrix} from './base/matrix';
|
|
6
6
|
import {checkVector} from '../lib/validators';
|
|
7
7
|
|
|
8
8
|
/* eslint-disable camelcase */
|
|
9
9
|
import {vec2_transformMat4AsVector, vec3_transformMat4AsVector} from '../lib/gl-matrix-extras';
|
|
10
10
|
// @ts-ignore gl-matrix types...
|
|
11
|
-
import
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
import {
|
|
12
|
+
fromQuat as mat4_fromQuat,
|
|
13
|
+
frustum as mat4_frustum,
|
|
14
|
+
lookAt as mat4_lookAt,
|
|
15
|
+
ortho as mat4_ortho,
|
|
16
|
+
perspective as mat4_perspective,
|
|
17
|
+
determinant as mat4_determinant,
|
|
18
|
+
transpose as mat4_transpose,
|
|
19
|
+
invert as mat4_invert,
|
|
20
|
+
multiply as mat4_multiply,
|
|
21
|
+
rotateX as mat4_rotateX,
|
|
22
|
+
rotateY as mat4_rotateY,
|
|
23
|
+
rotateZ as mat4_rotateZ,
|
|
24
|
+
rotate as mat4_rotate,
|
|
25
|
+
scale as mat4_scale,
|
|
26
|
+
translate as mat4_translate
|
|
27
|
+
} from '../gl-matrix/mat4';
|
|
28
|
+
import {transformMat4 as vec2_transformMat4} from '../gl-matrix/vec2';
|
|
29
|
+
import {transformMat4 as vec3_transformMat4} from '../gl-matrix/vec3';
|
|
30
|
+
import {transformMat4 as vec4_transformMat4} from '../gl-matrix/vec4';
|
|
18
31
|
|
|
19
32
|
enum INDICES {
|
|
20
33
|
COL0ROW0 = 0,
|
|
@@ -43,7 +56,7 @@ const DEFAULT_FAR = 500;
|
|
|
43
56
|
const IDENTITY_MATRIX = Object.freeze([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
|
|
44
57
|
|
|
45
58
|
/** 4x4 matrix */
|
|
46
|
-
export
|
|
59
|
+
export class Matrix4 extends Matrix {
|
|
47
60
|
static get IDENTITY(): Readonly<Matrix4> {
|
|
48
61
|
return getIdentityMatrix();
|
|
49
62
|
}
|
|
@@ -203,6 +216,7 @@ export default class Matrix4 extends Matrix {
|
|
|
203
216
|
* @param object
|
|
204
217
|
* @returns self
|
|
205
218
|
*/
|
|
219
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
206
220
|
fromObject(object: {[key: string]: any}): this {
|
|
207
221
|
return this.check();
|
|
208
222
|
}
|
|
@@ -213,7 +227,7 @@ export default class Matrix4 extends Matrix {
|
|
|
213
227
|
* @returns self
|
|
214
228
|
*/
|
|
215
229
|
fromQuaternion(quaternion: Readonly<NumericArray>): this {
|
|
216
|
-
|
|
230
|
+
mat4_fromQuat(this, quaternion);
|
|
217
231
|
return this.check();
|
|
218
232
|
}
|
|
219
233
|
|
|
@@ -239,7 +253,7 @@ export default class Matrix4 extends Matrix {
|
|
|
239
253
|
if (far === Infinity) {
|
|
240
254
|
computeInfinitePerspectiveOffCenter(this, left, right, bottom, top, near);
|
|
241
255
|
} else {
|
|
242
|
-
|
|
256
|
+
mat4_frustum(this, left, right, bottom, top, near, far);
|
|
243
257
|
}
|
|
244
258
|
return this.check();
|
|
245
259
|
}
|
|
@@ -258,7 +272,7 @@ export default class Matrix4 extends Matrix {
|
|
|
258
272
|
up?: Readonly<NumericArray>;
|
|
259
273
|
}): this {
|
|
260
274
|
const {eye, center = [0, 0, 0], up = [0, 1, 0]} = view;
|
|
261
|
-
|
|
275
|
+
mat4_lookAt(this, eye, center, up);
|
|
262
276
|
return this.check();
|
|
263
277
|
}
|
|
264
278
|
|
|
@@ -282,7 +296,7 @@ export default class Matrix4 extends Matrix {
|
|
|
282
296
|
far?: number;
|
|
283
297
|
}): this {
|
|
284
298
|
const {left, right, bottom, top, near = DEFAULT_NEAR, far = DEFAULT_FAR} = view;
|
|
285
|
-
|
|
299
|
+
mat4_ortho(this, left, right, bottom, top, near, far);
|
|
286
300
|
return this.check();
|
|
287
301
|
}
|
|
288
302
|
|
|
@@ -338,14 +352,14 @@ export default class Matrix4 extends Matrix {
|
|
|
338
352
|
perspective(view: {fovy: number; aspect?: number; near?: number; far?: number}): this {
|
|
339
353
|
const {fovy = (45 * Math.PI) / 180, aspect = 1, near = 0.1, far = 500} = view;
|
|
340
354
|
checkRadians(fovy);
|
|
341
|
-
|
|
355
|
+
mat4_perspective(this, fovy, aspect, near, far);
|
|
342
356
|
return this.check();
|
|
343
357
|
}
|
|
344
358
|
|
|
345
359
|
// Accessors
|
|
346
360
|
|
|
347
361
|
determinant(): number {
|
|
348
|
-
return
|
|
362
|
+
return mat4_determinant(this);
|
|
349
363
|
}
|
|
350
364
|
|
|
351
365
|
/**
|
|
@@ -437,38 +451,38 @@ export default class Matrix4 extends Matrix {
|
|
|
437
451
|
// Modifiers
|
|
438
452
|
|
|
439
453
|
transpose(): this {
|
|
440
|
-
|
|
454
|
+
mat4_transpose(this, this);
|
|
441
455
|
return this.check();
|
|
442
456
|
}
|
|
443
457
|
|
|
444
458
|
invert(): this {
|
|
445
|
-
|
|
459
|
+
mat4_invert(this, this);
|
|
446
460
|
return this.check();
|
|
447
461
|
}
|
|
448
462
|
|
|
449
463
|
// Operations
|
|
450
464
|
|
|
451
465
|
multiplyLeft(a: Readonly<NumericArray>): this {
|
|
452
|
-
|
|
466
|
+
mat4_multiply(this, a, this);
|
|
453
467
|
return this.check();
|
|
454
468
|
}
|
|
455
469
|
|
|
456
470
|
multiplyRight(a: Readonly<NumericArray>): this {
|
|
457
|
-
|
|
471
|
+
mat4_multiply(this, this, a);
|
|
458
472
|
return this.check();
|
|
459
473
|
}
|
|
460
474
|
|
|
461
475
|
// Rotates a matrix by the given angle around the X axis
|
|
462
476
|
rotateX(radians: number): this {
|
|
463
|
-
|
|
464
|
-
//
|
|
477
|
+
mat4_rotateX(this, this, radians);
|
|
478
|
+
// mat4_rotate(this, this, radians, [1, 0, 0]);
|
|
465
479
|
return this.check();
|
|
466
480
|
}
|
|
467
481
|
|
|
468
482
|
// Rotates a matrix by the given angle around the Y axis.
|
|
469
483
|
rotateY(radians: number): this {
|
|
470
|
-
|
|
471
|
-
//
|
|
484
|
+
mat4_rotateY(this, this, radians);
|
|
485
|
+
// mat4_rotate(this, this, radians, [0, 1, 0]);
|
|
472
486
|
return this.check();
|
|
473
487
|
}
|
|
474
488
|
|
|
@@ -478,8 +492,8 @@ export default class Matrix4 extends Matrix {
|
|
|
478
492
|
* @returns self
|
|
479
493
|
*/
|
|
480
494
|
rotateZ(radians: number): this {
|
|
481
|
-
|
|
482
|
-
//
|
|
495
|
+
mat4_rotateZ(this, this, radians);
|
|
496
|
+
// mat4_rotate(this, this, radians, [0, 0, 1]);
|
|
483
497
|
return this.check();
|
|
484
498
|
}
|
|
485
499
|
|
|
@@ -499,7 +513,7 @@ export default class Matrix4 extends Matrix {
|
|
|
499
513
|
* @returns self
|
|
500
514
|
*/
|
|
501
515
|
rotateAxis(radians: number, axis: Readonly<NumericArray>): this {
|
|
502
|
-
|
|
516
|
+
mat4_rotate(this, this, radians, axis);
|
|
503
517
|
return this.check();
|
|
504
518
|
}
|
|
505
519
|
|
|
@@ -509,7 +523,7 @@ export default class Matrix4 extends Matrix {
|
|
|
509
523
|
* @returns self
|
|
510
524
|
*/
|
|
511
525
|
override scale(factor: number | Readonly<NumericArray>): this {
|
|
512
|
-
|
|
526
|
+
mat4_scale(this, this, Array.isArray(factor) ? factor : [factor, factor, factor]);
|
|
513
527
|
return this.check();
|
|
514
528
|
}
|
|
515
529
|
|
|
@@ -519,7 +533,7 @@ export default class Matrix4 extends Matrix {
|
|
|
519
533
|
* @returns self
|
|
520
534
|
*/
|
|
521
535
|
translate(vector: Readonly<NumericArray>): this {
|
|
522
|
-
|
|
536
|
+
mat4_translate(this, this, vector);
|
|
523
537
|
return this.check();
|
|
524
538
|
}
|
|
525
539
|
|
|
@@ -533,7 +547,7 @@ export default class Matrix4 extends Matrix {
|
|
|
533
547
|
*/
|
|
534
548
|
transform(vector: Readonly<NumericArray>, result?: NumericArray): NumericArray {
|
|
535
549
|
if (vector.length === 4) {
|
|
536
|
-
result =
|
|
550
|
+
result = vec4_transformMat4(result || [-0, -0, -0, -0], vector, this) as NumericArray;
|
|
537
551
|
checkVector(result, 4);
|
|
538
552
|
return result;
|
|
539
553
|
}
|
|
@@ -551,10 +565,10 @@ export default class Matrix4 extends Matrix {
|
|
|
551
565
|
let out: NumericArray;
|
|
552
566
|
switch (length) {
|
|
553
567
|
case 2:
|
|
554
|
-
out =
|
|
568
|
+
out = vec2_transformMat4(result || [-0, -0], vector, this) as NumericArray;
|
|
555
569
|
break;
|
|
556
570
|
case 3:
|
|
557
|
-
out =
|
|
571
|
+
out = vec3_transformMat4(result || [-0, -0, -0], vector, this) as NumericArray;
|
|
558
572
|
break;
|
|
559
573
|
default:
|
|
560
574
|
throw new Error('Illegal vector');
|
package/src/classes/pose.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Copyright (c) 2017 Uber Technologies, Inc.
|
|
2
2
|
// MIT License
|
|
3
|
-
import Matrix4 from './matrix4';
|
|
4
|
-
import Vector3 from './vector3';
|
|
5
|
-
import Euler from './euler';
|
|
3
|
+
import {Matrix4} from './matrix4';
|
|
4
|
+
import {Vector3} from './vector3';
|
|
5
|
+
import {Euler} from './euler';
|
|
6
6
|
import {NumericArray} from '@math.gl/types';
|
|
7
7
|
|
|
8
8
|
type PoseOptions = {
|
|
@@ -16,7 +16,7 @@ type PoseOptions = {
|
|
|
16
16
|
yaw?: number;
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
export
|
|
19
|
+
export class Pose {
|
|
20
20
|
readonly position: Vector3;
|
|
21
21
|
readonly orientation: Euler;
|
|
22
22
|
|
|
@@ -1,17 +1,37 @@
|
|
|
1
1
|
// Copyright (c) 2017 Uber Technologies, Inc.
|
|
2
2
|
// MIT License
|
|
3
3
|
import {NumericArray} from '@math.gl/types';
|
|
4
|
-
import MathArray from './base/math-array';
|
|
4
|
+
import {MathArray} from './base/math-array';
|
|
5
5
|
import {checkNumber, checkVector} from '../lib/validators';
|
|
6
|
-
import Vector4 from './vector4';
|
|
6
|
+
import {Vector4} from './vector4';
|
|
7
7
|
// @ts-ignore gl-matrix types...
|
|
8
|
-
import
|
|
8
|
+
import {
|
|
9
|
+
fromMat3 as quat_fromMat3,
|
|
10
|
+
setAxisAngle as quat_setAxisAngle,
|
|
11
|
+
identity as quat_identity,
|
|
12
|
+
length as quat_length,
|
|
13
|
+
squaredLength as quat_squaredLength,
|
|
14
|
+
dot as quat_dot,
|
|
15
|
+
// getAxisAngle as quat_getAxisAngle,
|
|
16
|
+
rotationTo as quat_rotationTo,
|
|
17
|
+
add as quat_add,
|
|
18
|
+
calculateW as quat_calculateW,
|
|
19
|
+
conjugate as quat_conjugate,
|
|
20
|
+
invert as quat_invert,
|
|
21
|
+
lerp as quat_lerp,
|
|
22
|
+
multiply as quat_multiply,
|
|
23
|
+
rotateX as quat_rotateX,
|
|
24
|
+
rotateY as quat_rotateY,
|
|
25
|
+
rotateZ as quat_rotateZ,
|
|
26
|
+
scale as quat_scale,
|
|
27
|
+
slerp as quat_slerp
|
|
28
|
+
} from '../gl-matrix/quat';
|
|
9
29
|
// @ts-ignore gl-matrix types...
|
|
10
|
-
import
|
|
30
|
+
import {transformQuat as vec4_transformQuat} from '../gl-matrix/vec4';
|
|
11
31
|
|
|
12
32
|
const IDENTITY_QUATERNION = [0, 0, 0, 1] as const;
|
|
13
33
|
|
|
14
|
-
export
|
|
34
|
+
export class Quaternion extends MathArray {
|
|
15
35
|
constructor(x: number | Readonly<NumericArray> = 0, y = 0, z = 0, w = 1) {
|
|
16
36
|
// PERF NOTE: initialize elements as double precision numbers
|
|
17
37
|
super(-0, -0, -0, -0);
|
|
@@ -55,24 +75,24 @@ export default class Quaternion extends MathArray {
|
|
|
55
75
|
* @returns
|
|
56
76
|
*/
|
|
57
77
|
fromMatrix3(m: Readonly<NumericArray>): this {
|
|
58
|
-
|
|
78
|
+
quat_fromMat3(this, m);
|
|
59
79
|
return this.check();
|
|
60
80
|
}
|
|
61
81
|
|
|
62
82
|
fromAxisRotation(axis: Readonly<NumericArray>, rad: number): this {
|
|
63
|
-
|
|
83
|
+
quat_setAxisAngle(this, axis, rad);
|
|
64
84
|
return this.check();
|
|
65
85
|
}
|
|
66
86
|
|
|
67
87
|
/** Set a quat to the identity quaternion */
|
|
68
88
|
identity(): this {
|
|
69
|
-
|
|
89
|
+
quat_identity(this);
|
|
70
90
|
return this.check();
|
|
71
91
|
}
|
|
72
92
|
|
|
73
93
|
// Set the components of a quat to the given values
|
|
74
94
|
// set(i, j, k, l) {
|
|
75
|
-
//
|
|
95
|
+
// quat_set(this, i, j, k, l);
|
|
76
96
|
// return this.check();
|
|
77
97
|
// }
|
|
78
98
|
|
|
@@ -116,18 +136,18 @@ export default class Quaternion extends MathArray {
|
|
|
116
136
|
|
|
117
137
|
// Calculates the length of a quat
|
|
118
138
|
len(): number {
|
|
119
|
-
return
|
|
139
|
+
return quat_length(this);
|
|
120
140
|
}
|
|
121
141
|
|
|
122
142
|
// Calculates the squared length of a quat
|
|
123
143
|
lengthSquared(): number {
|
|
124
|
-
return
|
|
144
|
+
return quat_squaredLength(this);
|
|
125
145
|
}
|
|
126
146
|
|
|
127
147
|
// Calculates the dot product of two quat's
|
|
128
148
|
// @return {Number}
|
|
129
149
|
dot(a: Readonly<NumericArray>): number {
|
|
130
|
-
return
|
|
150
|
+
return quat_dot(this, a);
|
|
131
151
|
}
|
|
132
152
|
|
|
133
153
|
// Gets the rotation axis and angle for a given quaternion.
|
|
@@ -140,14 +160,14 @@ export default class Quaternion extends MathArray {
|
|
|
140
160
|
// @return {{[x,y,z], Number}}
|
|
141
161
|
// getAxisAngle() {
|
|
142
162
|
// const axis = [];
|
|
143
|
-
// const angle =
|
|
163
|
+
// // const angle = quat_getAxisAngle(axis, this);
|
|
144
164
|
// return {axis, angle};
|
|
145
165
|
// }
|
|
146
166
|
// MODIFIERS
|
|
147
167
|
// Sets a quaternion to represent the shortest rotation from one vector
|
|
148
168
|
// to another. Both vectors are assumed to be unit length.
|
|
149
169
|
rotationTo(vectorA: NumericArray, vectorB: NumericArray): this {
|
|
150
|
-
|
|
170
|
+
quat_rotationTo(this, vectorA, vectorB);
|
|
151
171
|
return this.check();
|
|
152
172
|
}
|
|
153
173
|
|
|
@@ -163,27 +183,27 @@ export default class Quaternion extends MathArray {
|
|
|
163
183
|
// }
|
|
164
184
|
// Adds two quat's
|
|
165
185
|
override add(a: Readonly<NumericArray>): this {
|
|
166
|
-
|
|
186
|
+
quat_add(this, this, a);
|
|
167
187
|
return this.check();
|
|
168
188
|
}
|
|
169
189
|
|
|
170
190
|
// Calculates the W component of a quat from the X, Y, and Z components.
|
|
171
191
|
// Any existing W component will be ignored.
|
|
172
192
|
calculateW(): this {
|
|
173
|
-
|
|
193
|
+
quat_calculateW(this, this);
|
|
174
194
|
return this.check();
|
|
175
195
|
}
|
|
176
196
|
|
|
177
197
|
// Calculates the conjugate of a quat If the quaternion is normalized,
|
|
178
|
-
// this function is faster than
|
|
198
|
+
// this function is faster than quat_invert and produces the same result.
|
|
179
199
|
conjugate(): this {
|
|
180
|
-
|
|
200
|
+
quat_conjugate(this, this);
|
|
181
201
|
return this.check();
|
|
182
202
|
}
|
|
183
203
|
|
|
184
204
|
// Calculates the inverse of a quat
|
|
185
205
|
invert(): this {
|
|
186
|
-
|
|
206
|
+
quat_invert(this, this);
|
|
187
207
|
return this.check();
|
|
188
208
|
}
|
|
189
209
|
|
|
@@ -192,18 +212,18 @@ export default class Quaternion extends MathArray {
|
|
|
192
212
|
if (t === undefined) {
|
|
193
213
|
return this.lerp(this, a, b as number);
|
|
194
214
|
}
|
|
195
|
-
|
|
215
|
+
quat_lerp(this, a, b as NumericArray, t);
|
|
196
216
|
return this.check();
|
|
197
217
|
}
|
|
198
218
|
|
|
199
219
|
// Multiplies two quat's
|
|
200
220
|
multiplyRight(a: Readonly<NumericArray>): this {
|
|
201
|
-
|
|
221
|
+
quat_multiply(this, this, a);
|
|
202
222
|
return this.check();
|
|
203
223
|
}
|
|
204
224
|
|
|
205
225
|
multiplyLeft(a: Readonly<NumericArray>): this {
|
|
206
|
-
|
|
226
|
+
quat_multiply(this, a, this);
|
|
207
227
|
return this.check();
|
|
208
228
|
}
|
|
209
229
|
|
|
@@ -225,25 +245,25 @@ export default class Quaternion extends MathArray {
|
|
|
225
245
|
|
|
226
246
|
// Rotates a quaternion by the given angle about the X axis
|
|
227
247
|
rotateX(rad: number): this {
|
|
228
|
-
|
|
248
|
+
quat_rotateX(this, this, rad);
|
|
229
249
|
return this.check();
|
|
230
250
|
}
|
|
231
251
|
|
|
232
252
|
// Rotates a quaternion by the given angle about the Y axis
|
|
233
253
|
rotateY(rad: number): this {
|
|
234
|
-
|
|
254
|
+
quat_rotateY(this, this, rad);
|
|
235
255
|
return this.check();
|
|
236
256
|
}
|
|
237
257
|
|
|
238
258
|
// Rotates a quaternion by the given angle about the Z axis
|
|
239
259
|
rotateZ(rad: number): this {
|
|
240
|
-
|
|
260
|
+
quat_rotateZ(this, this, rad);
|
|
241
261
|
return this.check();
|
|
242
262
|
}
|
|
243
263
|
|
|
244
264
|
// Scales a quat by a scalar number
|
|
245
265
|
override scale(b: number): this {
|
|
246
|
-
|
|
266
|
+
quat_scale(this, this, b);
|
|
247
267
|
return this.check();
|
|
248
268
|
}
|
|
249
269
|
|
|
@@ -295,7 +315,7 @@ export default class Quaternion extends MathArray {
|
|
|
295
315
|
target = arg1 as Readonly<NumericArray>;
|
|
296
316
|
ratio = arg2;
|
|
297
317
|
}
|
|
298
|
-
|
|
318
|
+
quat_slerp(this, start, target, ratio);
|
|
299
319
|
return this.check();
|
|
300
320
|
}
|
|
301
321
|
|
|
@@ -303,7 +323,7 @@ export default class Quaternion extends MathArray {
|
|
|
303
323
|
vector: Readonly<NumericArray>,
|
|
304
324
|
result: NumericArray = new Vector4()
|
|
305
325
|
): NumericArray {
|
|
306
|
-
|
|
326
|
+
vec4_transformQuat(result, vector, this);
|
|
307
327
|
return checkVector(result, 4);
|
|
308
328
|
}
|
|
309
329
|
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
// MIT License
|
|
3
3
|
// Adaptation of THREE.js Spherical class, under MIT license
|
|
4
4
|
import {NumericArray} from '@math.gl/types';
|
|
5
|
-
import Vector3 from './vector3';
|
|
5
|
+
import {Vector3} from './vector3';
|
|
6
6
|
import {formatValue, equals, config} from '../lib/common';
|
|
7
7
|
import {degrees, radians, clamp} from '../lib/common';
|
|
8
8
|
// @ts-ignore gl-matrix types...
|
|
9
|
-
import * as vec3 from 'gl-matrix/vec3';
|
|
9
|
+
import * as vec3 from '../gl-matrix/vec3';
|
|
10
10
|
|
|
11
11
|
type SphericalCoordinatesOptions = {
|
|
12
12
|
phi?: number;
|
|
@@ -31,7 +31,7 @@ const EARTH_RADIUS_METERS = 6371000;
|
|
|
31
31
|
* The equator starts at positive z.
|
|
32
32
|
* @link https://en.wikipedia.org/wiki/Spherical_coordinate_system
|
|
33
33
|
*/
|
|
34
|
-
export
|
|
34
|
+
export class SphericalCoordinates {
|
|
35
35
|
phi: number;
|
|
36
36
|
theta: number;
|
|
37
37
|
radius: number;
|
package/src/classes/vector2.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
// Copyright (c) 2017 Uber Technologies, Inc.
|
|
2
2
|
// MIT License
|
|
3
|
-
import Vector from './base/vector';
|
|
3
|
+
import {Vector} from './base/vector';
|
|
4
4
|
import {config, isArray} from '../lib/common';
|
|
5
5
|
import {checkNumber} from '../lib/validators';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
import {
|
|
7
|
+
transformMat4 as vec2_transformMat4,
|
|
8
|
+
transformMat3 as vec2_transformMat3,
|
|
9
|
+
transformMat2d as vec2_transformMat2d,
|
|
10
|
+
transformMat2 as vec2_transformMat2
|
|
11
|
+
} from '../gl-matrix/vec2';
|
|
9
12
|
import {vec2_transformMat4AsVector} from '../lib/gl-matrix-extras';
|
|
10
13
|
import {NumericArray} from '@math.gl/types';
|
|
11
14
|
|
|
@@ -13,7 +16,7 @@ import {NumericArray} from '@math.gl/types';
|
|
|
13
16
|
* Two-element vector class.
|
|
14
17
|
* Subclass of Array<number>
|
|
15
18
|
*/
|
|
16
|
-
export
|
|
19
|
+
export class Vector2 extends Vector {
|
|
17
20
|
// Creates a new, empty vec2
|
|
18
21
|
constructor(x: number | Readonly<NumericArray> = 0, y: number = 0) {
|
|
19
22
|
// PERF NOTE: initialize elements as double precision numbers
|
|
@@ -52,7 +55,7 @@ export default class Vector2 extends Vector {
|
|
|
52
55
|
return this.check();
|
|
53
56
|
}
|
|
54
57
|
|
|
55
|
-
toObject(object: {x?: number; y?: number}): {x: number; y: number} {
|
|
58
|
+
override toObject(object: {x?: number; y?: number}): {x: number; y: number} {
|
|
56
59
|
object.x = this[0];
|
|
57
60
|
object.y = this[1];
|
|
58
61
|
return object as {x: number; y: number};
|
|
@@ -97,7 +100,7 @@ export default class Vector2 extends Vector {
|
|
|
97
100
|
* @returns
|
|
98
101
|
*/
|
|
99
102
|
transformAsPoint(matrix4: Readonly<NumericArray>): this {
|
|
100
|
-
|
|
103
|
+
vec2_transformMat4(this, this, matrix4);
|
|
101
104
|
return this.check();
|
|
102
105
|
}
|
|
103
106
|
|
|
@@ -112,17 +115,17 @@ export default class Vector2 extends Vector {
|
|
|
112
115
|
}
|
|
113
116
|
|
|
114
117
|
transformByMatrix3(matrix3: Readonly<NumericArray>): this {
|
|
115
|
-
|
|
118
|
+
vec2_transformMat3(this, this, matrix3);
|
|
116
119
|
return this.check();
|
|
117
120
|
}
|
|
118
121
|
|
|
119
122
|
transformByMatrix2x3(matrix2x3: Readonly<NumericArray>): this {
|
|
120
|
-
|
|
123
|
+
vec2_transformMat2d(this, this, matrix2x3);
|
|
121
124
|
return this.check();
|
|
122
125
|
}
|
|
123
126
|
|
|
124
127
|
transformByMatrix2(matrix2: Readonly<NumericArray>): this {
|
|
125
|
-
|
|
128
|
+
vec2_transformMat2(this, this, matrix2);
|
|
126
129
|
return this.check();
|
|
127
130
|
}
|
|
128
131
|
}
|