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