@math.gl/core 3.5.7 → 3.6.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 +66 -0
- package/dist/classes/base/math-array.d.ts.map +1 -0
- package/dist/classes/base/math-array.js +216 -0
- package/dist/classes/base/matrix.d.ts +14 -0
- package/dist/classes/base/matrix.d.ts.map +1 -0
- package/dist/classes/base/matrix.js +61 -0
- package/dist/classes/base/vector.d.ts +44 -0
- package/dist/classes/base/vector.d.ts.map +1 -0
- package/dist/classes/base/vector.js +126 -0
- package/dist/classes/euler.d.ts +77 -0
- package/dist/classes/euler.d.ts.map +1 -0
- package/dist/classes/euler.js +485 -0
- package/dist/classes/matrix3.d.ts +60 -0
- package/dist/classes/matrix3.d.ts.map +1 -0
- package/dist/classes/matrix3.js +201 -0
- package/dist/classes/matrix4.d.ts +226 -0
- package/dist/classes/matrix4.d.ts.map +1 -0
- package/dist/classes/matrix4.js +538 -0
- package/dist/classes/pose.d.ts +40 -0
- package/dist/classes/pose.d.ts.map +1 -0
- package/dist/classes/pose.js +109 -0
- package/dist/classes/quaternion.d.ts +63 -0
- package/dist/classes/quaternion.d.ts.map +1 -0
- package/dist/classes/quaternion.js +262 -0
- package/dist/classes/spherical-coordinates.d.ts +60 -0
- package/dist/classes/spherical-coordinates.d.ts.map +1 -0
- package/dist/classes/spherical-coordinates.js +148 -0
- package/dist/classes/vector2.d.ts +55 -0
- package/dist/classes/vector2.d.ts.map +1 -0
- package/dist/classes/vector2.js +111 -0
- package/dist/classes/vector3.d.ts +56 -0
- package/dist/classes/vector3.d.ts.map +1 -0
- package/dist/classes/vector3.js +133 -0
- package/dist/classes/vector4.d.ts +41 -0
- package/dist/classes/vector4.d.ts.map +1 -0
- package/dist/classes/vector4.js +114 -0
- package/dist/es5/classes/base/math-array.js +57 -61
- package/dist/es5/classes/base/math-array.js.map +1 -1
- package/dist/es5/classes/base/matrix.js +0 -14
- package/dist/es5/classes/base/matrix.js.map +1 -1
- package/dist/es5/classes/base/vector.js +0 -12
- package/dist/es5/classes/base/vector.js.map +1 -1
- package/dist/es5/classes/euler.js +63 -49
- package/dist/es5/classes/euler.js.map +1 -1
- package/dist/es5/classes/matrix3.js +60 -33
- package/dist/es5/classes/matrix3.js.map +1 -1
- package/dist/es5/classes/matrix4.js +167 -164
- package/dist/es5/classes/matrix4.js.map +1 -1
- package/dist/es5/classes/pose.js +7 -6
- package/dist/es5/classes/pose.js.map +1 -1
- package/dist/es5/classes/quaternion.js +44 -36
- package/dist/es5/classes/quaternion.js.map +1 -1
- package/dist/es5/classes/spherical-coordinates.js +12 -8
- package/dist/es5/classes/spherical-coordinates.js.map +1 -1
- package/dist/es5/classes/vector2.js.map +1 -1
- package/dist/es5/classes/vector3.js +7 -2
- package/dist/es5/classes/vector3.js.map +1 -1
- package/dist/es5/classes/vector4.js +7 -2
- package/dist/es5/classes/vector4.js.map +1 -1
- package/dist/es5/docs/README.md +0 -0
- package/dist/es5/index.js +71 -89
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/assert.js.map +1 -1
- package/dist/es5/lib/common.js +40 -43
- package/dist/es5/lib/common.js.map +1 -1
- package/dist/es5/lib/gl-matrix-extras.js.map +1 -1
- package/dist/es5/lib/gl-matrix.d.js +2 -0
- package/dist/es5/lib/gl-matrix.d.js.map +1 -0
- package/dist/es5/lib/math-utils.js.map +1 -1
- package/dist/es5/lib/validators.js.map +1 -1
- package/dist/esm/classes/base/math-array.js +45 -47
- package/dist/esm/classes/base/math-array.js.map +1 -1
- package/dist/esm/classes/base/matrix.js +0 -11
- package/dist/esm/classes/base/matrix.js.map +1 -1
- package/dist/esm/classes/base/vector.js +0 -10
- package/dist/esm/classes/base/vector.js.map +1 -1
- package/dist/esm/classes/euler.js +61 -48
- package/dist/esm/classes/euler.js.map +1 -1
- package/dist/esm/classes/matrix3.js +55 -33
- package/dist/esm/classes/matrix3.js.map +1 -1
- package/dist/esm/classes/matrix4.js +156 -136
- package/dist/esm/classes/matrix4.js.map +1 -1
- package/dist/esm/classes/pose.js +8 -4
- package/dist/esm/classes/pose.js.map +1 -1
- package/dist/esm/classes/quaternion.js +37 -27
- package/dist/esm/classes/quaternion.js.map +1 -1
- package/dist/esm/classes/spherical-coordinates.js +15 -5
- package/dist/esm/classes/spherical-coordinates.js.map +1 -1
- package/dist/esm/classes/vector2.js.map +1 -1
- package/dist/esm/classes/vector3.js +7 -2
- package/dist/esm/classes/vector3.js.map +1 -1
- package/dist/esm/classes/vector4.js +7 -2
- package/dist/esm/classes/vector4.js.map +1 -1
- package/dist/esm/docs/README.md +0 -0
- package/dist/esm/index.js +2 -13
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/assert.js.map +1 -1
- package/dist/esm/lib/common.js +41 -44
- package/dist/esm/lib/common.js.map +1 -1
- package/dist/esm/lib/gl-matrix-extras.js.map +1 -1
- package/dist/esm/lib/gl-matrix.d.js +2 -0
- package/dist/esm/lib/gl-matrix.d.js.map +1 -0
- package/dist/esm/lib/math-utils.js.map +1 -1
- package/dist/esm/lib/validators.js.map +1 -1
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/lib/assert.d.ts +2 -0
- package/dist/lib/assert.d.ts.map +1 -0
- package/dist/lib/assert.js +5 -0
- package/dist/lib/common.d.ts +93 -0
- package/dist/lib/common.d.ts.map +1 -0
- package/dist/lib/common.js +210 -0
- package/dist/lib/gl-matrix-extras.d.ts +7 -0
- package/dist/lib/gl-matrix-extras.d.ts.map +1 -0
- package/dist/lib/gl-matrix-extras.js +49 -0
- package/dist/lib/math-utils.d.ts +28 -0
- package/dist/lib/math-utils.d.ts.map +1 -0
- package/dist/lib/math-utils.js +28 -0
- package/dist/lib/validators.d.ts +6 -0
- package/dist/lib/validators.d.ts.map +1 -0
- package/dist/lib/validators.js +33 -0
- package/package.json +5 -4
- package/src/classes/base/math-array.ts +265 -0
- package/src/classes/base/{matrix.js → matrix.ts} +15 -19
- package/src/classes/base/{vector.js → vector.ts} +47 -54
- package/src/classes/{euler.js → euler.ts} +121 -221
- package/src/classes/matrix3.ts +253 -0
- package/src/classes/matrix4.ts +668 -0
- package/src/classes/{pose.js → pose.ts} +52 -49
- package/src/classes/{quaternion.js → quaternion.ts} +107 -95
- package/src/classes/{spherical-coordinates.js → spherical-coordinates.ts} +84 -54
- package/src/classes/vector2.ts +127 -0
- package/src/classes/{vector3.js → vector3.ts} +43 -55
- package/src/classes/{vector4.js → vector4.ts} +44 -48
- package/src/docs/README.md +0 -0
- package/{dist/esm/index.d.ts → src/index.ts} +32 -34
- package/src/lib/{assert.js → assert.ts} +1 -1
- package/src/lib/common.ts +304 -0
- package/src/lib/{gl-matrix-extras.js → gl-matrix-extras.ts} +26 -5
- package/src/lib/gl-matrix.d.ts +266 -0
- package/src/lib/{math-utils.js → math-utils.ts} +0 -0
- package/src/lib/{validators.js → validators.ts} +10 -6
- package/dist/es5/addons/polygon.d.ts +0 -17
- package/dist/es5/classes/base/math-array.d.ts +0 -56
- package/dist/es5/classes/base/matrix.d.ts +0 -15
- package/dist/es5/classes/base/vector.d.ts +0 -45
- package/dist/es5/classes/euler.d.ts +0 -92
- package/dist/es5/classes/matrix3.d.ts +0 -91
- package/dist/es5/classes/matrix4.d.ts +0 -161
- package/dist/es5/classes/pose.d.ts +0 -92
- package/dist/es5/classes/quaternion.d.ts +0 -107
- package/dist/es5/classes/spherical-coordinates.d.ts +0 -87
- package/dist/es5/classes/vector2.d.ts +0 -65
- package/dist/es5/classes/vector3.d.ts +0 -65
- package/dist/es5/classes/vector4.d.ts +0 -34
- package/dist/es5/index.d.ts +0 -54
- package/dist/es5/lib/common.d.ts +0 -80
- package/dist/esm/addons/polygon.d.ts +0 -17
- package/dist/esm/classes/base/math-array.d.ts +0 -56
- package/dist/esm/classes/base/matrix.d.ts +0 -15
- package/dist/esm/classes/base/vector.d.ts +0 -45
- package/dist/esm/classes/euler.d.ts +0 -92
- package/dist/esm/classes/matrix3.d.ts +0 -91
- package/dist/esm/classes/matrix4.d.ts +0 -161
- package/dist/esm/classes/pose.d.ts +0 -92
- package/dist/esm/classes/quaternion.d.ts +0 -107
- package/dist/esm/classes/spherical-coordinates.d.ts +0 -87
- package/dist/esm/classes/vector2.d.ts +0 -65
- package/dist/esm/classes/vector3.d.ts +0 -65
- package/dist/esm/classes/vector4.d.ts +0 -34
- package/dist/esm/lib/common.d.ts +0 -80
- package/src/addons/polygon.d.ts +0 -17
- package/src/classes/base/math-array.d.ts +0 -56
- package/src/classes/base/math-array.js +0 -250
- package/src/classes/base/matrix.d.ts +0 -15
- package/src/classes/base/vector.d.ts +0 -45
- package/src/classes/euler.d.ts +0 -92
- package/src/classes/matrix3.d.ts +0 -91
- package/src/classes/matrix3.js +0 -225
- package/src/classes/matrix4.d.ts +0 -161
- package/src/classes/matrix4.js +0 -530
- package/src/classes/pose.d.ts +0 -92
- package/src/classes/quaternion.d.ts +0 -107
- package/src/classes/spherical-coordinates.d.ts +0 -87
- package/src/classes/vector2.d.ts +0 -65
- package/src/classes/vector2.js +0 -122
- package/src/classes/vector3.d.ts +0 -65
- package/src/classes/vector4.d.ts +0 -34
- package/src/index.d.ts +0 -54
- package/src/index.js +0 -86
- package/src/lib/common.d.ts +0 -80
- package/src/lib/common.js +0 -222
|
@@ -1,28 +1,25 @@
|
|
|
1
1
|
// Copyright (c) 2017 Uber Technologies, Inc.
|
|
2
|
-
//
|
|
3
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
-
// of this software and associated documentation files (the "Software"), to deal
|
|
5
|
-
// in the Software without restriction, including without limitation the rights
|
|
6
|
-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
-
// copies of the Software, and to permit persons to whom the Software is
|
|
8
|
-
// furnished to do so, subject to the following conditions:
|
|
9
|
-
//
|
|
10
|
-
// The above copyright notice and this permission notice shall be included in
|
|
11
|
-
// all copies or substantial portions of the Software.
|
|
12
|
-
//
|
|
13
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
-
// THE SOFTWARE.
|
|
2
|
+
// MIT License
|
|
20
3
|
import Matrix4 from './matrix4';
|
|
21
4
|
import Vector3 from './vector3';
|
|
22
5
|
import Euler from './euler';
|
|
6
|
+
import {NumericArray} from '@math.gl/types';
|
|
7
|
+
|
|
8
|
+
type PoseOptions = {
|
|
9
|
+
position?: Readonly<NumericArray>;
|
|
10
|
+
orientation?: Readonly<NumericArray>;
|
|
11
|
+
x?: number;
|
|
12
|
+
y?: number;
|
|
13
|
+
z?: number;
|
|
14
|
+
roll?: number;
|
|
15
|
+
pitch?: number;
|
|
16
|
+
yaw?: number;
|
|
17
|
+
};
|
|
23
18
|
|
|
24
19
|
export default class Pose {
|
|
25
|
-
|
|
20
|
+
readonly position: Vector3;
|
|
21
|
+
readonly orientation: Euler;
|
|
22
|
+
|
|
26
23
|
constructor({
|
|
27
24
|
x = 0,
|
|
28
25
|
y = 0,
|
|
@@ -30,74 +27,85 @@ export default class Pose {
|
|
|
30
27
|
roll = 0,
|
|
31
28
|
pitch = 0,
|
|
32
29
|
yaw = 0,
|
|
33
|
-
position
|
|
34
|
-
orientation
|
|
35
|
-
} = {}) {
|
|
30
|
+
position,
|
|
31
|
+
orientation
|
|
32
|
+
}: PoseOptions = {}) {
|
|
36
33
|
if (Array.isArray(position) && position.length === 3) {
|
|
37
34
|
this.position = new Vector3(position);
|
|
38
35
|
} else {
|
|
39
36
|
this.position = new Vector3(x, y, z);
|
|
40
37
|
}
|
|
41
38
|
if (Array.isArray(orientation) && orientation.length === 4) {
|
|
39
|
+
// @ts-expect-error
|
|
42
40
|
this.orientation = new Euler(orientation, orientation[3]);
|
|
43
41
|
} else {
|
|
44
42
|
this.orientation = new Euler(roll, pitch, yaw, Euler.RollPitchYaw);
|
|
45
43
|
}
|
|
46
44
|
}
|
|
47
45
|
|
|
48
|
-
get x() {
|
|
46
|
+
get x(): number {
|
|
49
47
|
return this.position.x;
|
|
50
48
|
}
|
|
51
|
-
|
|
49
|
+
|
|
50
|
+
set x(value: number) {
|
|
52
51
|
this.position.x = value;
|
|
53
52
|
}
|
|
54
|
-
|
|
53
|
+
|
|
54
|
+
get y(): number {
|
|
55
55
|
return this.position.y;
|
|
56
56
|
}
|
|
57
|
-
|
|
57
|
+
|
|
58
|
+
set y(value: number) {
|
|
58
59
|
this.position.y = value;
|
|
59
60
|
}
|
|
60
|
-
|
|
61
|
+
|
|
62
|
+
get z(): number {
|
|
61
63
|
return this.position.z;
|
|
62
64
|
}
|
|
63
|
-
|
|
65
|
+
|
|
66
|
+
set z(value: number) {
|
|
64
67
|
this.position.z = value;
|
|
65
68
|
}
|
|
66
|
-
|
|
69
|
+
|
|
70
|
+
get roll(): number {
|
|
67
71
|
return this.orientation.roll;
|
|
68
72
|
}
|
|
69
|
-
|
|
73
|
+
|
|
74
|
+
set roll(value: number) {
|
|
70
75
|
this.orientation.roll = value;
|
|
71
76
|
}
|
|
72
|
-
|
|
77
|
+
|
|
78
|
+
get pitch(): number {
|
|
73
79
|
return this.orientation.pitch;
|
|
74
80
|
}
|
|
75
|
-
set pitch(value) {
|
|
81
|
+
set pitch(value: number) {
|
|
76
82
|
this.orientation.pitch = value;
|
|
77
83
|
}
|
|
78
|
-
|
|
84
|
+
|
|
85
|
+
get yaw(): number {
|
|
79
86
|
return this.orientation.yaw;
|
|
80
87
|
}
|
|
81
|
-
|
|
88
|
+
|
|
89
|
+
set yaw(value: number) {
|
|
82
90
|
this.orientation.yaw = value;
|
|
83
91
|
}
|
|
84
92
|
|
|
85
|
-
getPosition() {
|
|
93
|
+
getPosition(): Vector3 {
|
|
86
94
|
return this.position;
|
|
87
95
|
}
|
|
88
96
|
|
|
89
|
-
getOrientation() {
|
|
97
|
+
getOrientation(): Euler {
|
|
90
98
|
return this.orientation;
|
|
91
99
|
}
|
|
92
100
|
|
|
93
|
-
equals(pose) {
|
|
101
|
+
equals(pose: Pose): boolean {
|
|
94
102
|
if (!pose) {
|
|
95
103
|
return false;
|
|
96
104
|
}
|
|
97
105
|
return this.position.equals(pose.position) && this.orientation.equals(pose.orientation);
|
|
98
106
|
}
|
|
99
107
|
|
|
100
|
-
exactEquals(pose) {
|
|
108
|
+
exactEquals(pose: Pose): boolean {
|
|
101
109
|
if (!pose) {
|
|
102
110
|
return false;
|
|
103
111
|
}
|
|
@@ -106,48 +114,43 @@ export default class Pose {
|
|
|
106
114
|
);
|
|
107
115
|
}
|
|
108
116
|
|
|
109
|
-
getTransformationMatrix() {
|
|
110
|
-
// setup
|
|
117
|
+
getTransformationMatrix(): Matrix4 {
|
|
118
|
+
// setup pre computations for the sin/cos of the angles
|
|
111
119
|
const sr = Math.sin(this.roll);
|
|
112
120
|
const sp = Math.sin(this.pitch);
|
|
113
121
|
const sw = Math.sin(this.yaw);
|
|
114
|
-
|
|
115
122
|
const cr = Math.cos(this.roll);
|
|
116
123
|
const cp = Math.cos(this.pitch);
|
|
117
124
|
const cw = Math.cos(this.yaw);
|
|
118
125
|
|
|
119
|
-
|
|
126
|
+
// Create matrix
|
|
127
|
+
return new Matrix4().setRowMajor(
|
|
120
128
|
cw * cp, // 0,0
|
|
121
129
|
-sw * cr + cw * sp * sr, // 0,1
|
|
122
130
|
sw * sr + cw * sp * cr, // 0,2
|
|
123
131
|
this.x, // 0,3
|
|
124
|
-
|
|
125
132
|
sw * cp, // 1,0
|
|
126
133
|
cw * cr + sw * sp * sr, // 1,1
|
|
127
134
|
-cw * sr + sw * sp * cr, // 1,2
|
|
128
135
|
this.y, // 1,3
|
|
129
|
-
|
|
130
136
|
-sp, // 2,0
|
|
131
137
|
cp * sr, // 2,1
|
|
132
138
|
cp * cr, // 2,2
|
|
133
139
|
this.z, // 2,3
|
|
134
|
-
|
|
135
140
|
0,
|
|
136
141
|
0,
|
|
137
142
|
0,
|
|
138
143
|
1
|
|
139
144
|
);
|
|
140
|
-
|
|
141
|
-
return matrix;
|
|
142
145
|
}
|
|
143
146
|
|
|
144
|
-
getTransformationMatrixFromPose(pose) {
|
|
147
|
+
getTransformationMatrixFromPose(pose: Pose): Matrix4 {
|
|
145
148
|
return new Matrix4()
|
|
146
149
|
.multiplyRight(this.getTransformationMatrix())
|
|
147
150
|
.multiplyRight(pose.getTransformationMatrix().invert());
|
|
148
151
|
}
|
|
149
152
|
|
|
150
|
-
getTransformationMatrixToPose(pose) {
|
|
153
|
+
getTransformationMatrixToPose(pose: Pose): Matrix4 {
|
|
151
154
|
return new Matrix4()
|
|
152
155
|
.multiplyRight(pose.getTransformationMatrix())
|
|
153
156
|
.multiplyRight(this.getTransformationMatrix().invert());
|
|
@@ -1,47 +1,27 @@
|
|
|
1
1
|
// Copyright (c) 2017 Uber Technologies, Inc.
|
|
2
|
-
//
|
|
3
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
-
// of this software and associated documentation files (the "Software"), to deal
|
|
5
|
-
// in the Software without restriction, including without limitation the rights
|
|
6
|
-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
-
// copies of the Software, and to permit persons to whom the Software is
|
|
8
|
-
// furnished to do so, subject to the following conditions:
|
|
9
|
-
//
|
|
10
|
-
// The above copyright notice and this permission notice shall be included in
|
|
11
|
-
// all copies or substantial portions of the Software.
|
|
12
|
-
//
|
|
13
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
-
// THE SOFTWARE.
|
|
20
|
-
|
|
2
|
+
// MIT License
|
|
21
3
|
import MathArray from './base/math-array';
|
|
22
4
|
import {checkNumber, checkVector} from '../lib/validators';
|
|
23
|
-
import
|
|
24
|
-
|
|
25
|
-
// @ts-ignore: error TS2307: Cannot find module 'gl-matrix/...'.
|
|
5
|
+
import Vector4 from './vector4';
|
|
26
6
|
import * as quat from 'gl-matrix/quat';
|
|
27
|
-
// @ts-ignore: error TS2307: Cannot find module 'gl-matrix/...'.
|
|
28
7
|
import * as vec4 from 'gl-matrix/vec4';
|
|
8
|
+
import {NumericArray} from '@math.gl/types';
|
|
29
9
|
|
|
30
|
-
const IDENTITY_QUATERNION = [0, 0, 0, 1];
|
|
10
|
+
const IDENTITY_QUATERNION = [0, 0, 0, 1] as const;
|
|
31
11
|
|
|
32
12
|
export default class Quaternion extends MathArray {
|
|
33
|
-
constructor(x = 0, y = 0, z = 0, w = 1) {
|
|
13
|
+
constructor(x: number | Readonly<NumericArray> = 0, y = 0, z = 0, w = 1) {
|
|
34
14
|
// PERF NOTE: initialize elements as double precision numbers
|
|
35
15
|
super(-0, -0, -0, -0);
|
|
36
16
|
// eslint-disable-next-line prefer-rest-params
|
|
37
17
|
if (Array.isArray(x) && arguments.length === 1) {
|
|
38
18
|
this.copy(x);
|
|
39
19
|
} else {
|
|
40
|
-
this.set(x, y, z, w);
|
|
20
|
+
this.set(x as number, y, z, w);
|
|
41
21
|
}
|
|
42
22
|
}
|
|
43
23
|
|
|
44
|
-
copy(array) {
|
|
24
|
+
copy(array: Readonly<NumericArray>): this {
|
|
45
25
|
this[0] = array[0];
|
|
46
26
|
this[1] = array[1];
|
|
47
27
|
this[2] = array[2];
|
|
@@ -49,7 +29,7 @@ export default class Quaternion extends MathArray {
|
|
|
49
29
|
return this.check();
|
|
50
30
|
}
|
|
51
31
|
|
|
52
|
-
set(x, y, z, w) {
|
|
32
|
+
set(x: number, y: number, z: number, w: number): this {
|
|
53
33
|
this[0] = x;
|
|
54
34
|
this[1] = y;
|
|
55
35
|
this[2] = z;
|
|
@@ -57,25 +37,37 @@ export default class Quaternion extends MathArray {
|
|
|
57
37
|
return this.check();
|
|
58
38
|
}
|
|
59
39
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
40
|
+
fromObject(object: {x: number; y: number; z: number; w: number}): this {
|
|
41
|
+
this[0] = object.x;
|
|
42
|
+
this[1] = object.y;
|
|
43
|
+
this[2] = object.z;
|
|
44
|
+
this[3] = object.w;
|
|
65
45
|
return this.check();
|
|
66
46
|
}
|
|
67
47
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Creates a quaternion from the given 3x3 rotation matrix.
|
|
50
|
+
* NOTE: The resultant quaternion is not normalized, so you should
|
|
51
|
+
* be sure to renormalize the quaternion yourself where necessary.
|
|
52
|
+
* @param m
|
|
53
|
+
* @returns
|
|
54
|
+
*/
|
|
55
|
+
fromMatrix3(m: Readonly<NumericArray>): this {
|
|
56
|
+
quat.fromMat3(this, m);
|
|
71
57
|
return this.check();
|
|
72
58
|
}
|
|
73
59
|
|
|
74
|
-
fromAxisRotation(axis
|
|
60
|
+
fromAxisRotation(axis: Readonly<NumericArray>, rad: number): this {
|
|
75
61
|
quat.setAxisAngle(this, axis, rad);
|
|
76
62
|
return this.check();
|
|
77
63
|
}
|
|
78
64
|
|
|
65
|
+
/** Set a quat to the identity quaternion */
|
|
66
|
+
identity(): this {
|
|
67
|
+
quat.identity(this);
|
|
68
|
+
return this.check();
|
|
69
|
+
}
|
|
70
|
+
|
|
79
71
|
// Set the components of a quat to the given values
|
|
80
72
|
// set(i, j, k, l) {
|
|
81
73
|
// quat.set(this, i, j, k, l);
|
|
@@ -83,66 +75,56 @@ export default class Quaternion extends MathArray {
|
|
|
83
75
|
// }
|
|
84
76
|
|
|
85
77
|
// Sets a quat from the given angle and rotation axis, then returns it.
|
|
86
|
-
setAxisAngle(axis
|
|
78
|
+
setAxisAngle(axis: Readonly<NumericArray>, rad: number): this {
|
|
87
79
|
return this.fromAxisRotation(axis, rad);
|
|
88
80
|
}
|
|
89
81
|
|
|
90
82
|
// Getters/setters
|
|
91
|
-
|
|
92
|
-
get ELEMENTS() {
|
|
83
|
+
get ELEMENTS(): number {
|
|
93
84
|
return 4;
|
|
94
85
|
}
|
|
95
86
|
|
|
96
|
-
get x() {
|
|
87
|
+
get x(): number {
|
|
97
88
|
return this[0];
|
|
98
89
|
}
|
|
99
|
-
|
|
100
|
-
set x(value) {
|
|
90
|
+
set x(value: number) {
|
|
101
91
|
this[0] = checkNumber(value);
|
|
102
92
|
}
|
|
103
93
|
|
|
104
|
-
get y() {
|
|
94
|
+
get y(): number {
|
|
105
95
|
return this[1];
|
|
106
96
|
}
|
|
107
|
-
|
|
108
|
-
set y(value) {
|
|
97
|
+
set y(value: number) {
|
|
109
98
|
this[1] = checkNumber(value);
|
|
110
99
|
}
|
|
111
100
|
|
|
112
|
-
get z() {
|
|
101
|
+
get z(): number {
|
|
113
102
|
return this[2];
|
|
114
103
|
}
|
|
115
|
-
|
|
116
|
-
set z(value) {
|
|
104
|
+
set z(value: number) {
|
|
117
105
|
this[2] = checkNumber(value);
|
|
118
106
|
}
|
|
119
107
|
|
|
120
|
-
get w() {
|
|
108
|
+
get w(): number {
|
|
121
109
|
return this[3];
|
|
122
110
|
}
|
|
123
|
-
|
|
124
|
-
set w(value) {
|
|
111
|
+
set w(value: number) {
|
|
125
112
|
this[3] = checkNumber(value);
|
|
126
113
|
}
|
|
127
114
|
|
|
128
|
-
/* eslint-enable no-multi-spaces, brace-style, no-return-assign */
|
|
129
|
-
|
|
130
115
|
// Calculates the length of a quat
|
|
131
|
-
len() {
|
|
116
|
+
len(): number {
|
|
132
117
|
return quat.length(this);
|
|
133
118
|
}
|
|
134
119
|
|
|
135
120
|
// Calculates the squared length of a quat
|
|
136
|
-
lengthSquared() {
|
|
121
|
+
lengthSquared(): number {
|
|
137
122
|
return quat.squaredLength(this);
|
|
138
123
|
}
|
|
139
124
|
|
|
140
125
|
// Calculates the dot product of two quat's
|
|
141
126
|
// @return {Number}
|
|
142
|
-
dot(a
|
|
143
|
-
if (b !== undefined) {
|
|
144
|
-
throw new Error('Quaternion.dot only takes one argument');
|
|
145
|
-
}
|
|
127
|
+
dot(a: Readonly<NumericArray>): number {
|
|
146
128
|
return quat.dot(this, a);
|
|
147
129
|
}
|
|
148
130
|
|
|
@@ -159,12 +141,10 @@ export default class Quaternion extends MathArray {
|
|
|
159
141
|
// const angle = quat.getAxisAngle(axis, this);
|
|
160
142
|
// return {axis, angle};
|
|
161
143
|
// }
|
|
162
|
-
|
|
163
144
|
// MODIFIERS
|
|
164
|
-
|
|
165
145
|
// Sets a quaternion to represent the shortest rotation from one vector
|
|
166
146
|
// to another. Both vectors are assumed to be unit length.
|
|
167
|
-
rotationTo(vectorA, vectorB) {
|
|
147
|
+
rotationTo(vectorA: NumericArray, vectorB: NumericArray): this {
|
|
168
148
|
quat.rotationTo(this, vectorA, vectorB);
|
|
169
149
|
return this.check();
|
|
170
150
|
}
|
|
@@ -175,62 +155,58 @@ export default class Quaternion extends MathArray {
|
|
|
175
155
|
// setAxes() {
|
|
176
156
|
// Number
|
|
177
157
|
// }
|
|
178
|
-
|
|
179
158
|
// Performs a spherical linear interpolation with two control points
|
|
180
159
|
// sqlerp() {
|
|
181
160
|
// Number;
|
|
182
161
|
// }
|
|
183
|
-
|
|
184
162
|
// Adds two quat's
|
|
185
|
-
add(a
|
|
186
|
-
if (b !== undefined) {
|
|
187
|
-
throw new Error('Quaternion.add only takes one argument');
|
|
188
|
-
}
|
|
163
|
+
add(a: Readonly<NumericArray>): this {
|
|
189
164
|
quat.add(this, this, a);
|
|
190
165
|
return this.check();
|
|
191
166
|
}
|
|
192
167
|
|
|
193
168
|
// Calculates the W component of a quat from the X, Y, and Z components.
|
|
194
169
|
// Any existing W component will be ignored.
|
|
195
|
-
calculateW() {
|
|
170
|
+
calculateW(): this {
|
|
196
171
|
quat.calculateW(this, this);
|
|
197
172
|
return this.check();
|
|
198
173
|
}
|
|
199
174
|
|
|
200
175
|
// Calculates the conjugate of a quat If the quaternion is normalized,
|
|
201
176
|
// this function is faster than quat.inverse and produces the same result.
|
|
202
|
-
conjugate() {
|
|
177
|
+
conjugate(): this {
|
|
203
178
|
quat.conjugate(this, this);
|
|
204
179
|
return this.check();
|
|
205
180
|
}
|
|
206
181
|
|
|
207
182
|
// Calculates the inverse of a quat
|
|
208
|
-
invert() {
|
|
183
|
+
invert(): this {
|
|
209
184
|
quat.invert(this, this);
|
|
210
185
|
return this.check();
|
|
211
186
|
}
|
|
212
187
|
|
|
213
188
|
// Performs a linear interpolation between two quat's
|
|
214
|
-
lerp(a
|
|
215
|
-
|
|
189
|
+
lerp(a: Readonly<NumericArray>, b: Readonly<NumericArray> | number, t?: number): this {
|
|
190
|
+
if (t === undefined) {
|
|
191
|
+
return this.lerp(this, a, b as number);
|
|
192
|
+
}
|
|
193
|
+
quat.lerp(this, a, b as NumericArray, t);
|
|
216
194
|
return this.check();
|
|
217
195
|
}
|
|
218
196
|
|
|
219
197
|
// Multiplies two quat's
|
|
220
|
-
multiplyRight(a
|
|
221
|
-
assert(!b); // Quaternion.multiply only takes one argument
|
|
198
|
+
multiplyRight(a: Readonly<NumericArray>): this {
|
|
222
199
|
quat.multiply(this, this, a);
|
|
223
200
|
return this.check();
|
|
224
201
|
}
|
|
225
202
|
|
|
226
|
-
multiplyLeft(a
|
|
227
|
-
assert(!b); // Quaternion.multiply only takes one argument
|
|
203
|
+
multiplyLeft(a: Readonly<NumericArray>): this {
|
|
228
204
|
quat.multiply(this, a, this);
|
|
229
205
|
return this.check();
|
|
230
206
|
}
|
|
231
207
|
|
|
232
208
|
// Normalize a quat
|
|
233
|
-
normalize() {
|
|
209
|
+
normalize(): this {
|
|
234
210
|
// Handle 0 case
|
|
235
211
|
const length = this.len();
|
|
236
212
|
const l = length > 0 ? 1 / length : 0;
|
|
@@ -246,67 +222,103 @@ export default class Quaternion extends MathArray {
|
|
|
246
222
|
}
|
|
247
223
|
|
|
248
224
|
// Rotates a quaternion by the given angle about the X axis
|
|
249
|
-
rotateX(rad) {
|
|
225
|
+
rotateX(rad: number): this {
|
|
250
226
|
quat.rotateX(this, this, rad);
|
|
251
227
|
return this.check();
|
|
252
228
|
}
|
|
253
229
|
|
|
254
230
|
// Rotates a quaternion by the given angle about the Y axis
|
|
255
|
-
rotateY(rad) {
|
|
231
|
+
rotateY(rad: number): this {
|
|
256
232
|
quat.rotateY(this, this, rad);
|
|
257
233
|
return this.check();
|
|
258
234
|
}
|
|
259
235
|
|
|
260
236
|
// Rotates a quaternion by the given angle about the Z axis
|
|
261
|
-
rotateZ(rad) {
|
|
237
|
+
rotateZ(rad: number): this {
|
|
262
238
|
quat.rotateZ(this, this, rad);
|
|
263
239
|
return this.check();
|
|
264
240
|
}
|
|
265
241
|
|
|
266
242
|
// Scales a quat by a scalar number
|
|
267
|
-
scale(b) {
|
|
243
|
+
scale(b: number): this {
|
|
268
244
|
quat.scale(this, this, b);
|
|
269
245
|
return this.check();
|
|
270
246
|
}
|
|
271
247
|
|
|
248
|
+
slerp(target: Readonly<NumericArray>, ratio: number): this;
|
|
249
|
+
slerp(start: Readonly<NumericArray>, target: Readonly<NumericArray>, ratio: number): this;
|
|
250
|
+
slerp(params: {
|
|
251
|
+
start: Readonly<NumericArray>;
|
|
252
|
+
target: Readonly<NumericArray>;
|
|
253
|
+
ratio: number;
|
|
254
|
+
}): this;
|
|
255
|
+
|
|
272
256
|
// Performs a spherical linear interpolation between two quat
|
|
273
|
-
slerp(
|
|
257
|
+
slerp(
|
|
258
|
+
arg0:
|
|
259
|
+
| Readonly<NumericArray>
|
|
260
|
+
| {
|
|
261
|
+
start: Readonly<NumericArray>;
|
|
262
|
+
target: Readonly<NumericArray>;
|
|
263
|
+
ratio: number;
|
|
264
|
+
},
|
|
265
|
+
arg1?: Readonly<NumericArray> | number,
|
|
266
|
+
arg2?: number
|
|
267
|
+
) {
|
|
268
|
+
let start: Readonly<NumericArray>;
|
|
269
|
+
let target: Readonly<NumericArray>;
|
|
270
|
+
let ratio: number;
|
|
274
271
|
// eslint-disable-next-line prefer-rest-params
|
|
275
272
|
switch (arguments.length) {
|
|
276
273
|
case 1: // Deprecated signature ({start, target, ratio})
|
|
277
274
|
// eslint-disable-next-line prefer-rest-params
|
|
278
|
-
({
|
|
275
|
+
({
|
|
276
|
+
start = IDENTITY_QUATERNION,
|
|
277
|
+
target,
|
|
278
|
+
ratio
|
|
279
|
+
} = arg0 as {
|
|
280
|
+
start: Readonly<NumericArray>;
|
|
281
|
+
target: Readonly<NumericArray>;
|
|
282
|
+
ratio: number;
|
|
283
|
+
});
|
|
279
284
|
break;
|
|
280
285
|
case 2: // THREE.js compatibility signature (target, ration)
|
|
281
|
-
// eslint-disable-next-line prefer-rest-params
|
|
282
|
-
[target, ratio] = arguments;
|
|
283
286
|
start = this; // eslint-disable-line
|
|
287
|
+
target = arg0 as Readonly<NumericArray>;
|
|
288
|
+
ratio = arg1 as number;
|
|
284
289
|
break;
|
|
285
|
-
default:
|
|
290
|
+
default:
|
|
291
|
+
// Default signature: (start, target, ratio)
|
|
292
|
+
start = arg0 as Readonly<NumericArray>;
|
|
293
|
+
target = arg1 as Readonly<NumericArray>;
|
|
294
|
+
ratio = arg2;
|
|
286
295
|
}
|
|
287
296
|
quat.slerp(this, start, target, ratio);
|
|
288
297
|
return this.check();
|
|
289
298
|
}
|
|
290
299
|
|
|
291
|
-
transformVector4(
|
|
300
|
+
transformVector4(
|
|
301
|
+
vector: Readonly<NumericArray>,
|
|
302
|
+
result: NumericArray = new Vector4()
|
|
303
|
+
): NumericArray {
|
|
292
304
|
vec4.transformQuat(result, vector, this);
|
|
293
305
|
return checkVector(result, 4);
|
|
294
306
|
}
|
|
295
307
|
|
|
296
308
|
// THREE.js Math API compatibility
|
|
297
|
-
lengthSq() {
|
|
309
|
+
lengthSq(): number {
|
|
298
310
|
return this.lengthSquared();
|
|
299
311
|
}
|
|
300
312
|
|
|
301
|
-
setFromAxisAngle(axis
|
|
313
|
+
setFromAxisAngle(axis: Readonly<NumericArray>, rad: number): this {
|
|
302
314
|
return this.setAxisAngle(axis, rad);
|
|
303
315
|
}
|
|
304
316
|
|
|
305
|
-
premultiply(a
|
|
306
|
-
return this.multiplyLeft(a
|
|
317
|
+
premultiply(a: Readonly<NumericArray>): this {
|
|
318
|
+
return this.multiplyLeft(a);
|
|
307
319
|
}
|
|
308
320
|
|
|
309
|
-
multiply(a
|
|
310
|
-
return this.multiplyRight(a
|
|
321
|
+
multiply(a: Readonly<NumericArray>) {
|
|
322
|
+
return this.multiplyRight(a);
|
|
311
323
|
}
|
|
312
324
|
}
|