@math.gl/core 3.6.0 → 3.6.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/package.json +3 -3
- package/dist/classes/base/math-array.js +0 -216
- package/dist/classes/base/matrix.js +0 -61
- package/dist/classes/base/vector.js +0 -126
- package/dist/classes/euler.js +0 -485
- package/dist/classes/matrix3.js +0 -202
- package/dist/classes/matrix4.js +0 -540
- package/dist/classes/pose.js +0 -109
- package/dist/classes/quaternion.js +0 -262
- package/dist/classes/spherical-coordinates.js +0 -148
- package/dist/classes/vector2.js +0 -111
- package/dist/classes/vector3.js +0 -133
- package/dist/classes/vector4.js +0 -114
- package/dist/index.js +0 -24
- package/dist/lib/assert.js +0 -5
- package/dist/lib/common.js +0 -210
- package/dist/lib/gl-matrix-extras.js +0 -49
- package/dist/lib/math-utils.js +0 -28
- package/dist/lib/validators.js +0 -33
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2017 Uber Technologies, Inc.
|
|
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
|
-
const IDENTITY_QUATERNION = [0, 0, 0, 1];
|
|
9
|
-
export default class Quaternion extends MathArray {
|
|
10
|
-
constructor(x = 0, y = 0, z = 0, w = 1) {
|
|
11
|
-
// PERF NOTE: initialize elements as double precision numbers
|
|
12
|
-
super(-0, -0, -0, -0);
|
|
13
|
-
// eslint-disable-next-line prefer-rest-params
|
|
14
|
-
if (Array.isArray(x) && arguments.length === 1) {
|
|
15
|
-
this.copy(x);
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
this.set(x, y, z, w);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
copy(array) {
|
|
22
|
-
this[0] = array[0];
|
|
23
|
-
this[1] = array[1];
|
|
24
|
-
this[2] = array[2];
|
|
25
|
-
this[3] = array[3];
|
|
26
|
-
return this.check();
|
|
27
|
-
}
|
|
28
|
-
set(x, y, z, w) {
|
|
29
|
-
this[0] = x;
|
|
30
|
-
this[1] = y;
|
|
31
|
-
this[2] = z;
|
|
32
|
-
this[3] = w;
|
|
33
|
-
return this.check();
|
|
34
|
-
}
|
|
35
|
-
fromObject(object) {
|
|
36
|
-
this[0] = object.x;
|
|
37
|
-
this[1] = object.y;
|
|
38
|
-
this[2] = object.z;
|
|
39
|
-
this[3] = object.w;
|
|
40
|
-
return this.check();
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Creates a quaternion from the given 3x3 rotation matrix.
|
|
44
|
-
* NOTE: The resultant quaternion is not normalized, so you should
|
|
45
|
-
* be sure to renormalize the quaternion yourself where necessary.
|
|
46
|
-
* @param m
|
|
47
|
-
* @returns
|
|
48
|
-
*/
|
|
49
|
-
fromMatrix3(m) {
|
|
50
|
-
quat.fromMat3(this, m);
|
|
51
|
-
return this.check();
|
|
52
|
-
}
|
|
53
|
-
fromAxisRotation(axis, rad) {
|
|
54
|
-
quat.setAxisAngle(this, axis, rad);
|
|
55
|
-
return this.check();
|
|
56
|
-
}
|
|
57
|
-
/** Set a quat to the identity quaternion */
|
|
58
|
-
identity() {
|
|
59
|
-
quat.identity(this);
|
|
60
|
-
return this.check();
|
|
61
|
-
}
|
|
62
|
-
// Set the components of a quat to the given values
|
|
63
|
-
// set(i, j, k, l) {
|
|
64
|
-
// quat.set(this, i, j, k, l);
|
|
65
|
-
// return this.check();
|
|
66
|
-
// }
|
|
67
|
-
// Sets a quat from the given angle and rotation axis, then returns it.
|
|
68
|
-
setAxisAngle(axis, rad) {
|
|
69
|
-
return this.fromAxisRotation(axis, rad);
|
|
70
|
-
}
|
|
71
|
-
// Getters/setters
|
|
72
|
-
get ELEMENTS() {
|
|
73
|
-
return 4;
|
|
74
|
-
}
|
|
75
|
-
get x() {
|
|
76
|
-
return this[0];
|
|
77
|
-
}
|
|
78
|
-
set x(value) {
|
|
79
|
-
this[0] = checkNumber(value);
|
|
80
|
-
}
|
|
81
|
-
get y() {
|
|
82
|
-
return this[1];
|
|
83
|
-
}
|
|
84
|
-
set y(value) {
|
|
85
|
-
this[1] = checkNumber(value);
|
|
86
|
-
}
|
|
87
|
-
get z() {
|
|
88
|
-
return this[2];
|
|
89
|
-
}
|
|
90
|
-
set z(value) {
|
|
91
|
-
this[2] = checkNumber(value);
|
|
92
|
-
}
|
|
93
|
-
get w() {
|
|
94
|
-
return this[3];
|
|
95
|
-
}
|
|
96
|
-
set w(value) {
|
|
97
|
-
this[3] = checkNumber(value);
|
|
98
|
-
}
|
|
99
|
-
// Calculates the length of a quat
|
|
100
|
-
len() {
|
|
101
|
-
return quat.length(this);
|
|
102
|
-
}
|
|
103
|
-
// Calculates the squared length of a quat
|
|
104
|
-
lengthSquared() {
|
|
105
|
-
return quat.squaredLength(this);
|
|
106
|
-
}
|
|
107
|
-
// Calculates the dot product of two quat's
|
|
108
|
-
// @return {Number}
|
|
109
|
-
dot(a) {
|
|
110
|
-
return quat.dot(this, a);
|
|
111
|
-
}
|
|
112
|
-
// Gets the rotation axis and angle for a given quaternion.
|
|
113
|
-
// If a quaternion is created with setAxisAngle, this method will
|
|
114
|
-
// return the same values as providied in the original parameter
|
|
115
|
-
// list OR functionally equivalent values.
|
|
116
|
-
// Example: The quaternion formed by axis [0, 0, 1] and angle -90
|
|
117
|
-
// is the same as the quaternion formed by [0, 0, 1] and 270.
|
|
118
|
-
// This method favors the latter.
|
|
119
|
-
// @return {{[x,y,z], Number}}
|
|
120
|
-
// getAxisAngle() {
|
|
121
|
-
// const axis = [];
|
|
122
|
-
// const angle = quat.getAxisAngle(axis, this);
|
|
123
|
-
// return {axis, angle};
|
|
124
|
-
// }
|
|
125
|
-
// MODIFIERS
|
|
126
|
-
// Sets a quaternion to represent the shortest rotation from one vector
|
|
127
|
-
// to another. Both vectors are assumed to be unit length.
|
|
128
|
-
rotationTo(vectorA, vectorB) {
|
|
129
|
-
quat.rotationTo(this, vectorA, vectorB);
|
|
130
|
-
return this.check();
|
|
131
|
-
}
|
|
132
|
-
// Sets the specified quaternion with values corresponding to the given axes.
|
|
133
|
-
// Each axis is a vec3 and is expected to be unit length and perpendicular
|
|
134
|
-
// to all other specified axes.
|
|
135
|
-
// setAxes() {
|
|
136
|
-
// Number
|
|
137
|
-
// }
|
|
138
|
-
// Performs a spherical linear interpolation with two control points
|
|
139
|
-
// sqlerp() {
|
|
140
|
-
// Number;
|
|
141
|
-
// }
|
|
142
|
-
// Adds two quat's
|
|
143
|
-
add(a) {
|
|
144
|
-
quat.add(this, this, a);
|
|
145
|
-
return this.check();
|
|
146
|
-
}
|
|
147
|
-
// Calculates the W component of a quat from the X, Y, and Z components.
|
|
148
|
-
// Any existing W component will be ignored.
|
|
149
|
-
calculateW() {
|
|
150
|
-
quat.calculateW(this, this);
|
|
151
|
-
return this.check();
|
|
152
|
-
}
|
|
153
|
-
// Calculates the conjugate of a quat If the quaternion is normalized,
|
|
154
|
-
// this function is faster than quat.inverse and produces the same result.
|
|
155
|
-
conjugate() {
|
|
156
|
-
quat.conjugate(this, this);
|
|
157
|
-
return this.check();
|
|
158
|
-
}
|
|
159
|
-
// Calculates the inverse of a quat
|
|
160
|
-
invert() {
|
|
161
|
-
quat.invert(this, this);
|
|
162
|
-
return this.check();
|
|
163
|
-
}
|
|
164
|
-
// Performs a linear interpolation between two quat's
|
|
165
|
-
lerp(a, b, t) {
|
|
166
|
-
if (t === undefined) {
|
|
167
|
-
return this.lerp(this, a, b);
|
|
168
|
-
}
|
|
169
|
-
quat.lerp(this, a, b, t);
|
|
170
|
-
return this.check();
|
|
171
|
-
}
|
|
172
|
-
// Multiplies two quat's
|
|
173
|
-
multiplyRight(a) {
|
|
174
|
-
quat.multiply(this, this, a);
|
|
175
|
-
return this.check();
|
|
176
|
-
}
|
|
177
|
-
multiplyLeft(a) {
|
|
178
|
-
quat.multiply(this, a, this);
|
|
179
|
-
return this.check();
|
|
180
|
-
}
|
|
181
|
-
// Normalize a quat
|
|
182
|
-
normalize() {
|
|
183
|
-
// Handle 0 case
|
|
184
|
-
const length = this.len();
|
|
185
|
-
const l = length > 0 ? 1 / length : 0;
|
|
186
|
-
this[0] = this[0] * l;
|
|
187
|
-
this[1] = this[1] * l;
|
|
188
|
-
this[2] = this[2] * l;
|
|
189
|
-
this[3] = this[3] * l;
|
|
190
|
-
// Set to [0, 0, 0, 1] if length is 0
|
|
191
|
-
if (length === 0) {
|
|
192
|
-
this[3] = 1;
|
|
193
|
-
}
|
|
194
|
-
return this.check();
|
|
195
|
-
}
|
|
196
|
-
// Rotates a quaternion by the given angle about the X axis
|
|
197
|
-
rotateX(rad) {
|
|
198
|
-
quat.rotateX(this, this, rad);
|
|
199
|
-
return this.check();
|
|
200
|
-
}
|
|
201
|
-
// Rotates a quaternion by the given angle about the Y axis
|
|
202
|
-
rotateY(rad) {
|
|
203
|
-
quat.rotateY(this, this, rad);
|
|
204
|
-
return this.check();
|
|
205
|
-
}
|
|
206
|
-
// Rotates a quaternion by the given angle about the Z axis
|
|
207
|
-
rotateZ(rad) {
|
|
208
|
-
quat.rotateZ(this, this, rad);
|
|
209
|
-
return this.check();
|
|
210
|
-
}
|
|
211
|
-
// Scales a quat by a scalar number
|
|
212
|
-
scale(b) {
|
|
213
|
-
quat.scale(this, this, b);
|
|
214
|
-
return this.check();
|
|
215
|
-
}
|
|
216
|
-
// Performs a spherical linear interpolation between two quat
|
|
217
|
-
slerp(arg0, arg1, arg2) {
|
|
218
|
-
let start;
|
|
219
|
-
let target;
|
|
220
|
-
let ratio;
|
|
221
|
-
// eslint-disable-next-line prefer-rest-params
|
|
222
|
-
switch (arguments.length) {
|
|
223
|
-
case 1: // Deprecated signature ({start, target, ratio})
|
|
224
|
-
// eslint-disable-next-line prefer-rest-params
|
|
225
|
-
({
|
|
226
|
-
start = IDENTITY_QUATERNION,
|
|
227
|
-
target,
|
|
228
|
-
ratio
|
|
229
|
-
} = arg0);
|
|
230
|
-
break;
|
|
231
|
-
case 2: // THREE.js compatibility signature (target, ration)
|
|
232
|
-
start = this; // eslint-disable-line
|
|
233
|
-
target = arg0;
|
|
234
|
-
ratio = arg1;
|
|
235
|
-
break;
|
|
236
|
-
default:
|
|
237
|
-
// Default signature: (start, target, ratio)
|
|
238
|
-
start = arg0;
|
|
239
|
-
target = arg1;
|
|
240
|
-
ratio = arg2;
|
|
241
|
-
}
|
|
242
|
-
quat.slerp(this, start, target, ratio);
|
|
243
|
-
return this.check();
|
|
244
|
-
}
|
|
245
|
-
transformVector4(vector, result = new Vector4()) {
|
|
246
|
-
vec4.transformQuat(result, vector, this);
|
|
247
|
-
return checkVector(result, 4);
|
|
248
|
-
}
|
|
249
|
-
// THREE.js Math API compatibility
|
|
250
|
-
lengthSq() {
|
|
251
|
-
return this.lengthSquared();
|
|
252
|
-
}
|
|
253
|
-
setFromAxisAngle(axis, rad) {
|
|
254
|
-
return this.setAxisAngle(axis, rad);
|
|
255
|
-
}
|
|
256
|
-
premultiply(a) {
|
|
257
|
-
return this.multiplyLeft(a);
|
|
258
|
-
}
|
|
259
|
-
multiply(a) {
|
|
260
|
-
return this.multiplyRight(a);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2017 Uber Technologies, Inc.
|
|
2
|
-
// MIT License
|
|
3
|
-
// Adaptation of THREE.js Spherical class, under MIT license
|
|
4
|
-
import Vector3 from './vector3';
|
|
5
|
-
import { formatValue, equals, config } from '../lib/common';
|
|
6
|
-
import { degrees, radians, clamp } from '../lib/common';
|
|
7
|
-
import * as vec3 from 'gl-matrix/vec3';
|
|
8
|
-
// TODO - import epsilon
|
|
9
|
-
const EPSILON = 0.000001;
|
|
10
|
-
const EARTH_RADIUS_METERS = 6371000;
|
|
11
|
-
/**
|
|
12
|
-
* The poles (phi) are at the positive and negative y axis.
|
|
13
|
-
* The equator starts at positive z.
|
|
14
|
-
* @link https://en.wikipedia.org/wiki/Spherical_coordinate_system
|
|
15
|
-
*/
|
|
16
|
-
export default class SphericalCoordinates {
|
|
17
|
-
// bearing: number;
|
|
18
|
-
// pitch: number;
|
|
19
|
-
// altitude: number;
|
|
20
|
-
// lnglatZ coordinates
|
|
21
|
-
// longitude: number;
|
|
22
|
-
// latitude: number;
|
|
23
|
-
// lng: number;
|
|
24
|
-
// lat: number;
|
|
25
|
-
// z: number;
|
|
26
|
-
/**
|
|
27
|
-
* Creates a new SphericalCoordinates object
|
|
28
|
-
* @param options
|
|
29
|
-
* @param [options.phi] =0 - rotation around X (latitude)
|
|
30
|
-
* @param [options.theta] =0 - rotation around Y (longitude)
|
|
31
|
-
* @param [options.radius] =1 - Distance from center
|
|
32
|
-
* @param [options.bearing]
|
|
33
|
-
* @param [options.pitch]
|
|
34
|
-
* @param [options.altitude]
|
|
35
|
-
* @param [options.radiusScale] =1
|
|
36
|
-
*/
|
|
37
|
-
// eslint-disable-next-line complexity
|
|
38
|
-
constructor({ phi = 0, theta = 0, radius = 1, bearing, pitch, altitude, radiusScale = EARTH_RADIUS_METERS } = {}) {
|
|
39
|
-
this.phi = phi;
|
|
40
|
-
this.theta = theta;
|
|
41
|
-
// TODO - silently accepts illegal 0
|
|
42
|
-
this.radius = radius || altitude || 1; // radial distance from center
|
|
43
|
-
this.radiusScale = radiusScale || 1; // Used by lngLatZ
|
|
44
|
-
if (bearing !== undefined) {
|
|
45
|
-
this.bearing = bearing; // up / down towards top and bottom pole
|
|
46
|
-
}
|
|
47
|
-
if (pitch !== undefined) {
|
|
48
|
-
this.pitch = pitch; // around the equator of the sphere
|
|
49
|
-
}
|
|
50
|
-
this.check();
|
|
51
|
-
}
|
|
52
|
-
toString() {
|
|
53
|
-
return this.formatString(config);
|
|
54
|
-
}
|
|
55
|
-
formatString({ printTypes = false }) {
|
|
56
|
-
const f = formatValue;
|
|
57
|
-
return `${printTypes ? 'Spherical' : ''}\
|
|
58
|
-
[rho:${f(this.radius)},theta:${f(this.theta)},phi:${f(this.phi)}]`;
|
|
59
|
-
}
|
|
60
|
-
equals(other) {
|
|
61
|
-
return (equals(this.radius, other.radius) &&
|
|
62
|
-
equals(this.theta, other.theta) &&
|
|
63
|
-
equals(this.phi, other.phi));
|
|
64
|
-
}
|
|
65
|
-
exactEquals(other) {
|
|
66
|
-
return this.radius === other.radius && this.theta === other.theta && this.phi === other.phi;
|
|
67
|
-
}
|
|
68
|
-
/* eslint-disable brace-style */
|
|
69
|
-
// Cartographic (bearing 0 north, pitch 0 look from above)
|
|
70
|
-
get bearing() {
|
|
71
|
-
return 180 - degrees(this.phi);
|
|
72
|
-
}
|
|
73
|
-
set bearing(v) {
|
|
74
|
-
this.phi = Math.PI - radians(v);
|
|
75
|
-
}
|
|
76
|
-
get pitch() {
|
|
77
|
-
return degrees(this.theta);
|
|
78
|
-
}
|
|
79
|
-
set pitch(v) {
|
|
80
|
-
this.theta = radians(v);
|
|
81
|
-
}
|
|
82
|
-
// get pitch() { return 90 - degrees(this.phi); }
|
|
83
|
-
// set pitch(v) { this.phi = radians(v) + Math.PI / 2; }
|
|
84
|
-
// get altitude() { return this.radius - 1; } // relative altitude
|
|
85
|
-
// lnglatZ coordinates
|
|
86
|
-
get longitude() {
|
|
87
|
-
return degrees(this.phi);
|
|
88
|
-
}
|
|
89
|
-
get latitude() {
|
|
90
|
-
return degrees(this.theta);
|
|
91
|
-
}
|
|
92
|
-
get lng() {
|
|
93
|
-
return degrees(this.phi);
|
|
94
|
-
}
|
|
95
|
-
get lat() {
|
|
96
|
-
return degrees(this.theta);
|
|
97
|
-
}
|
|
98
|
-
get z() {
|
|
99
|
-
return (this.radius - 1) * this.radiusScale;
|
|
100
|
-
}
|
|
101
|
-
/* eslint-enable brace-style */
|
|
102
|
-
set(radius, phi, theta) {
|
|
103
|
-
this.radius = radius;
|
|
104
|
-
this.phi = phi;
|
|
105
|
-
this.theta = theta;
|
|
106
|
-
return this.check();
|
|
107
|
-
}
|
|
108
|
-
clone() {
|
|
109
|
-
return new SphericalCoordinates().copy(this);
|
|
110
|
-
}
|
|
111
|
-
copy(other) {
|
|
112
|
-
this.radius = other.radius;
|
|
113
|
-
this.phi = other.phi;
|
|
114
|
-
this.theta = other.theta;
|
|
115
|
-
return this.check();
|
|
116
|
-
}
|
|
117
|
-
fromLngLatZ([lng, lat, z]) {
|
|
118
|
-
this.radius = 1 + z / this.radiusScale;
|
|
119
|
-
this.phi = radians(lat);
|
|
120
|
-
this.theta = radians(lng);
|
|
121
|
-
return this.check();
|
|
122
|
-
}
|
|
123
|
-
fromVector3(v) {
|
|
124
|
-
this.radius = vec3.length(v);
|
|
125
|
-
if (this.radius > 0) {
|
|
126
|
-
this.theta = Math.atan2(v[0], v[1]); // equator angle around y-up axis
|
|
127
|
-
this.phi = Math.acos(clamp(v[2] / this.radius, -1, 1)); // polar angle
|
|
128
|
-
}
|
|
129
|
-
return this.check();
|
|
130
|
-
}
|
|
131
|
-
toVector3() {
|
|
132
|
-
return new Vector3(0, 0, this.radius)
|
|
133
|
-
.rotateX({ radians: this.theta })
|
|
134
|
-
.rotateZ({ radians: this.phi });
|
|
135
|
-
}
|
|
136
|
-
// restrict phi to be betwee EPS and PI-EPS
|
|
137
|
-
makeSafe() {
|
|
138
|
-
this.phi = Math.max(EPSILON, Math.min(Math.PI - EPSILON, this.phi));
|
|
139
|
-
return this;
|
|
140
|
-
}
|
|
141
|
-
check() {
|
|
142
|
-
// this.makeSafe();
|
|
143
|
-
if (!Number.isFinite(this.phi) || !Number.isFinite(this.theta) || !(this.radius > 0)) {
|
|
144
|
-
throw new Error('SphericalCoordinates: some fields set to invalid numbers');
|
|
145
|
-
}
|
|
146
|
-
return this;
|
|
147
|
-
}
|
|
148
|
-
}
|
package/dist/classes/vector2.js
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2017 Uber Technologies, Inc.
|
|
2
|
-
// MIT License
|
|
3
|
-
import Vector from './base/vector';
|
|
4
|
-
import { config, isArray } from '../lib/common';
|
|
5
|
-
import { checkNumber } from '../lib/validators';
|
|
6
|
-
import * as vec2 from 'gl-matrix/vec2';
|
|
7
|
-
/* eslint-disable camelcase */
|
|
8
|
-
import { vec2_transformMat4AsVector } from '../lib/gl-matrix-extras';
|
|
9
|
-
/**
|
|
10
|
-
* Two-element vector class.
|
|
11
|
-
* Subclass of Array<number>
|
|
12
|
-
*/
|
|
13
|
-
export default class Vector2 extends Vector {
|
|
14
|
-
// Creates a new, empty vec2
|
|
15
|
-
constructor(x = 0, y = 0) {
|
|
16
|
-
// PERF NOTE: initialize elements as double precision numbers
|
|
17
|
-
super(2); // -0, -0);
|
|
18
|
-
if (isArray(x) && arguments.length === 1) {
|
|
19
|
-
this.copy(x);
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
if (config.debug) {
|
|
23
|
-
checkNumber(x);
|
|
24
|
-
checkNumber(y);
|
|
25
|
-
}
|
|
26
|
-
this[0] = x;
|
|
27
|
-
this[1] = y;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
set(x, y) {
|
|
31
|
-
this[0] = x;
|
|
32
|
-
this[1] = y;
|
|
33
|
-
return this.check();
|
|
34
|
-
}
|
|
35
|
-
copy(array) {
|
|
36
|
-
this[0] = array[0];
|
|
37
|
-
this[1] = array[1];
|
|
38
|
-
return this.check();
|
|
39
|
-
}
|
|
40
|
-
fromObject(object) {
|
|
41
|
-
if (config.debug) {
|
|
42
|
-
checkNumber(object.x);
|
|
43
|
-
checkNumber(object.y);
|
|
44
|
-
}
|
|
45
|
-
this[0] = object.x;
|
|
46
|
-
this[1] = object.y;
|
|
47
|
-
return this.check();
|
|
48
|
-
}
|
|
49
|
-
toObject(object) {
|
|
50
|
-
object.x = this[0];
|
|
51
|
-
object.y = this[1];
|
|
52
|
-
return object;
|
|
53
|
-
}
|
|
54
|
-
// Getters/setters
|
|
55
|
-
get ELEMENTS() {
|
|
56
|
-
return 2;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Returns angle from x axis
|
|
60
|
-
* @returns
|
|
61
|
-
*/
|
|
62
|
-
horizontalAngle() {
|
|
63
|
-
return Math.atan2(this.y, this.x);
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Returns angle from y axis
|
|
67
|
-
* @returns
|
|
68
|
-
*/
|
|
69
|
-
verticalAngle() {
|
|
70
|
-
return Math.atan2(this.x, this.y);
|
|
71
|
-
}
|
|
72
|
-
// Transforms
|
|
73
|
-
/**
|
|
74
|
-
* Transforms as point
|
|
75
|
-
* @param matrix4
|
|
76
|
-
* @returns
|
|
77
|
-
*/
|
|
78
|
-
transform(matrix4) {
|
|
79
|
-
return this.transformAsPoint(matrix4);
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* transforms as point (4th component is implicitly 1)
|
|
83
|
-
* @param matrix4
|
|
84
|
-
* @returns
|
|
85
|
-
*/
|
|
86
|
-
transformAsPoint(matrix4) {
|
|
87
|
-
vec2.transformMat4(this, this, matrix4);
|
|
88
|
-
return this.check();
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* transforms as vector (4th component is implicitly 0, ignores translation. slightly faster)
|
|
92
|
-
* @param matrix4
|
|
93
|
-
* @returns
|
|
94
|
-
*/
|
|
95
|
-
transformAsVector(matrix4) {
|
|
96
|
-
vec2_transformMat4AsVector(this, this, matrix4);
|
|
97
|
-
return this.check();
|
|
98
|
-
}
|
|
99
|
-
transformByMatrix3(matrix3) {
|
|
100
|
-
vec2.transformMat3(this, this, matrix3);
|
|
101
|
-
return this.check();
|
|
102
|
-
}
|
|
103
|
-
transformByMatrix2x3(matrix2x3) {
|
|
104
|
-
vec2.transformMat2d(this, this, matrix2x3);
|
|
105
|
-
return this.check();
|
|
106
|
-
}
|
|
107
|
-
transformByMatrix2(matrix2) {
|
|
108
|
-
vec2.transformMat2(this, this, matrix2);
|
|
109
|
-
return this.check();
|
|
110
|
-
}
|
|
111
|
-
}
|
package/dist/classes/vector3.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import Vector from './base/vector';
|
|
2
|
-
import { config, isArray } from '../lib/common';
|
|
3
|
-
import { checkNumber } from '../lib/validators';
|
|
4
|
-
import * as vec3 from 'gl-matrix/vec3';
|
|
5
|
-
/* eslint-disable camelcase */
|
|
6
|
-
import { vec3_transformMat2, vec3_transformMat4AsVector } from '../lib/gl-matrix-extras';
|
|
7
|
-
const ORIGIN = [0, 0, 0];
|
|
8
|
-
let ZERO;
|
|
9
|
-
/**
|
|
10
|
-
* Three-element vector class.
|
|
11
|
-
* Subclass of Array<number>
|
|
12
|
-
*/
|
|
13
|
-
export default class Vector3 extends Vector {
|
|
14
|
-
static get ZERO() {
|
|
15
|
-
if (!ZERO) {
|
|
16
|
-
ZERO = new Vector3(0, 0, 0);
|
|
17
|
-
Object.freeze(ZERO);
|
|
18
|
-
}
|
|
19
|
-
return ZERO;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* @class
|
|
23
|
-
* @param x
|
|
24
|
-
* @param y
|
|
25
|
-
* @param z
|
|
26
|
-
*/
|
|
27
|
-
constructor(x = 0, y = 0, z = 0) {
|
|
28
|
-
// PERF NOTE: initialize elements as double precision numbers
|
|
29
|
-
super(-0, -0, -0);
|
|
30
|
-
if (arguments.length === 1 && isArray(x)) {
|
|
31
|
-
this.copy(x);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
// this.set(x, y, z);
|
|
35
|
-
if (config.debug) {
|
|
36
|
-
checkNumber(x);
|
|
37
|
-
checkNumber(y);
|
|
38
|
-
checkNumber(z);
|
|
39
|
-
}
|
|
40
|
-
// @ts-expect-error TS2412: Property '0' of type 'number | [number, number, number]' is not assignable to numeric index type 'number'
|
|
41
|
-
this[0] = x;
|
|
42
|
-
this[1] = y;
|
|
43
|
-
this[2] = z;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
set(x, y, z) {
|
|
47
|
-
this[0] = x;
|
|
48
|
-
this[1] = y;
|
|
49
|
-
this[2] = z;
|
|
50
|
-
return this.check();
|
|
51
|
-
}
|
|
52
|
-
copy(array) {
|
|
53
|
-
this[0] = array[0];
|
|
54
|
-
this[1] = array[1];
|
|
55
|
-
this[2] = array[2];
|
|
56
|
-
return this.check();
|
|
57
|
-
}
|
|
58
|
-
fromObject(object) {
|
|
59
|
-
if (config.debug) {
|
|
60
|
-
checkNumber(object.x);
|
|
61
|
-
checkNumber(object.y);
|
|
62
|
-
checkNumber(object.z);
|
|
63
|
-
}
|
|
64
|
-
this[0] = object.x;
|
|
65
|
-
this[1] = object.y;
|
|
66
|
-
this[2] = object.z;
|
|
67
|
-
return this.check();
|
|
68
|
-
}
|
|
69
|
-
toObject(object) {
|
|
70
|
-
object.x = this[0];
|
|
71
|
-
object.y = this[1];
|
|
72
|
-
object.z = this[2];
|
|
73
|
-
return object;
|
|
74
|
-
}
|
|
75
|
-
// Getters/setters
|
|
76
|
-
get ELEMENTS() {
|
|
77
|
-
return 3;
|
|
78
|
-
}
|
|
79
|
-
get z() {
|
|
80
|
-
return this[2];
|
|
81
|
-
}
|
|
82
|
-
set z(value) {
|
|
83
|
-
this[2] = checkNumber(value);
|
|
84
|
-
}
|
|
85
|
-
// ACCESSORS
|
|
86
|
-
angle(vector) {
|
|
87
|
-
return vec3.angle(this, vector);
|
|
88
|
-
}
|
|
89
|
-
// MODIFIERS
|
|
90
|
-
cross(vector) {
|
|
91
|
-
vec3.cross(this, this, vector);
|
|
92
|
-
return this.check();
|
|
93
|
-
}
|
|
94
|
-
rotateX({ radians, origin = ORIGIN }) {
|
|
95
|
-
vec3.rotateX(this, this, origin, radians);
|
|
96
|
-
return this.check();
|
|
97
|
-
}
|
|
98
|
-
rotateY({ radians, origin = ORIGIN }) {
|
|
99
|
-
vec3.rotateY(this, this, origin, radians);
|
|
100
|
-
return this.check();
|
|
101
|
-
}
|
|
102
|
-
rotateZ({ radians, origin = ORIGIN }) {
|
|
103
|
-
vec3.rotateZ(this, this, origin, radians);
|
|
104
|
-
return this.check();
|
|
105
|
-
}
|
|
106
|
-
// Transforms
|
|
107
|
-
// transforms as point (4th component is implicitly 1)
|
|
108
|
-
transform(matrix4) {
|
|
109
|
-
return this.transformAsPoint(matrix4);
|
|
110
|
-
}
|
|
111
|
-
// transforms as point (4th component is implicitly 1)
|
|
112
|
-
transformAsPoint(matrix4) {
|
|
113
|
-
vec3.transformMat4(this, this, matrix4);
|
|
114
|
-
return this.check();
|
|
115
|
-
}
|
|
116
|
-
// transforms as vector (4th component is implicitly 0, ignores translation. slightly faster)
|
|
117
|
-
transformAsVector(matrix4) {
|
|
118
|
-
vec3_transformMat4AsVector(this, this, matrix4);
|
|
119
|
-
return this.check();
|
|
120
|
-
}
|
|
121
|
-
transformByMatrix3(matrix3) {
|
|
122
|
-
vec3.transformMat3(this, this, matrix3);
|
|
123
|
-
return this.check();
|
|
124
|
-
}
|
|
125
|
-
transformByMatrix2(matrix2) {
|
|
126
|
-
vec3_transformMat2(this, this, matrix2);
|
|
127
|
-
return this.check();
|
|
128
|
-
}
|
|
129
|
-
transformByQuaternion(quaternion) {
|
|
130
|
-
vec3.transformQuat(this, this, quaternion);
|
|
131
|
-
return this.check();
|
|
132
|
-
}
|
|
133
|
-
}
|