@math.gl/core 3.6.1 → 3.6.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/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
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
-
"version": "3.6.
|
|
8
|
+
"version": "3.6.2",
|
|
9
9
|
"keywords": [
|
|
10
10
|
"webgl",
|
|
11
11
|
"javascript",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@babel/runtime": "^7.12.0",
|
|
41
|
-
"@math.gl/types": "3.6.
|
|
41
|
+
"@math.gl/types": "3.6.2",
|
|
42
42
|
"gl-matrix": "^3.4.0"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "517015873bbd7143bfc4bb761e70071c7a86771b"
|
|
45
45
|
}
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
import { config, formatValue, equals, isArray } from '../../lib/common';
|
|
2
|
-
/** Base class for vectors and matrices */
|
|
3
|
-
export default class MathArray extends Array {
|
|
4
|
-
// Common methods
|
|
5
|
-
/**
|
|
6
|
-
* Clone the current object
|
|
7
|
-
* @returns a new copy of this object
|
|
8
|
-
*/
|
|
9
|
-
clone() {
|
|
10
|
-
// @ts-expect-error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
|
11
|
-
return new this.constructor().copy(this); // eslint-disable-line
|
|
12
|
-
}
|
|
13
|
-
fromArray(array, offset = 0) {
|
|
14
|
-
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
15
|
-
this[i] = array[i + offset];
|
|
16
|
-
}
|
|
17
|
-
return this.check();
|
|
18
|
-
}
|
|
19
|
-
toArray(targetArray = [], offset = 0) {
|
|
20
|
-
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
21
|
-
targetArray[offset + i] = this[i];
|
|
22
|
-
}
|
|
23
|
-
return targetArray;
|
|
24
|
-
}
|
|
25
|
-
from(arrayOrObject) {
|
|
26
|
-
return Array.isArray(arrayOrObject) ? this.copy(arrayOrObject) : this.fromObject(arrayOrObject);
|
|
27
|
-
}
|
|
28
|
-
to(arrayOrObject) {
|
|
29
|
-
// @ts-ignore
|
|
30
|
-
if (arrayOrObject === this) {
|
|
31
|
-
return this;
|
|
32
|
-
}
|
|
33
|
-
// @ts-expect-error TS2339: Property 'toObject' does not exist on type 'MathArray'.
|
|
34
|
-
return isArray(arrayOrObject) ? this.toArray(arrayOrObject) : this.toObject(arrayOrObject);
|
|
35
|
-
}
|
|
36
|
-
toTarget(target) {
|
|
37
|
-
return target ? this.to(target) : this;
|
|
38
|
-
}
|
|
39
|
-
/** @deprecated */
|
|
40
|
-
toFloat32Array() {
|
|
41
|
-
return new Float32Array(this);
|
|
42
|
-
}
|
|
43
|
-
toString() {
|
|
44
|
-
return this.formatString(config);
|
|
45
|
-
}
|
|
46
|
-
/** Formats string according to options */
|
|
47
|
-
formatString(opts) {
|
|
48
|
-
let string = '';
|
|
49
|
-
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
50
|
-
string += (i > 0 ? ', ' : '') + formatValue(this[i], opts);
|
|
51
|
-
}
|
|
52
|
-
return `${opts.printTypes ? this.constructor.name : ''}[${string}]`;
|
|
53
|
-
}
|
|
54
|
-
equals(array) {
|
|
55
|
-
if (!array || this.length !== array.length) {
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
59
|
-
if (!equals(this[i], array[i])) {
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
exactEquals(array) {
|
|
66
|
-
if (!array || this.length !== array.length) {
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
70
|
-
if (this[i] !== array[i]) {
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return true;
|
|
75
|
-
}
|
|
76
|
-
// Modifiers
|
|
77
|
-
/** Negates all values in this object */
|
|
78
|
-
negate() {
|
|
79
|
-
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
80
|
-
this[i] = -this[i];
|
|
81
|
-
}
|
|
82
|
-
return this.check();
|
|
83
|
-
}
|
|
84
|
-
lerp(a, b, t) {
|
|
85
|
-
if (t === undefined) {
|
|
86
|
-
return this.lerp(this, a, b);
|
|
87
|
-
}
|
|
88
|
-
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
89
|
-
const ai = a[i];
|
|
90
|
-
this[i] = ai + t * (b[i] - ai);
|
|
91
|
-
}
|
|
92
|
-
return this.check();
|
|
93
|
-
}
|
|
94
|
-
/** Minimal */
|
|
95
|
-
min(vector) {
|
|
96
|
-
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
97
|
-
this[i] = Math.min(vector[i], this[i]);
|
|
98
|
-
}
|
|
99
|
-
return this.check();
|
|
100
|
-
}
|
|
101
|
-
/** Maximal */
|
|
102
|
-
max(vector) {
|
|
103
|
-
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
104
|
-
this[i] = Math.max(vector[i], this[i]);
|
|
105
|
-
}
|
|
106
|
-
return this.check();
|
|
107
|
-
}
|
|
108
|
-
clamp(minVector, maxVector) {
|
|
109
|
-
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
110
|
-
this[i] = Math.min(Math.max(this[i], minVector[i]), maxVector[i]);
|
|
111
|
-
}
|
|
112
|
-
return this.check();
|
|
113
|
-
}
|
|
114
|
-
add(...vectors) {
|
|
115
|
-
for (const vector of vectors) {
|
|
116
|
-
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
117
|
-
this[i] += vector[i];
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return this.check();
|
|
121
|
-
}
|
|
122
|
-
subtract(...vectors) {
|
|
123
|
-
for (const vector of vectors) {
|
|
124
|
-
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
125
|
-
this[i] -= vector[i];
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
return this.check();
|
|
129
|
-
}
|
|
130
|
-
scale(scale) {
|
|
131
|
-
if (typeof scale === 'number') {
|
|
132
|
-
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
133
|
-
this[i] *= scale;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
for (let i = 0; i < this.ELEMENTS && i < scale.length; ++i) {
|
|
138
|
-
this[i] *= scale[i];
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
return this.check();
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Multiplies all elements by `scale`
|
|
145
|
-
* Note: `Matrix4.multiplyByScalar` only scales its 3x3 "minor"
|
|
146
|
-
*/
|
|
147
|
-
multiplyByScalar(scalar) {
|
|
148
|
-
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
149
|
-
this[i] *= scalar;
|
|
150
|
-
}
|
|
151
|
-
return this.check();
|
|
152
|
-
}
|
|
153
|
-
// Debug checks
|
|
154
|
-
/** Throws an error if array length is incorrect or contains illegal values */
|
|
155
|
-
check() {
|
|
156
|
-
if (config.debug && !this.validate()) {
|
|
157
|
-
throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);
|
|
158
|
-
}
|
|
159
|
-
return this;
|
|
160
|
-
}
|
|
161
|
-
/** Returns false if the array length is incorrect or contains illegal values */
|
|
162
|
-
validate() {
|
|
163
|
-
let valid = this.length === this.ELEMENTS;
|
|
164
|
-
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
165
|
-
valid = valid && Number.isFinite(this[i]);
|
|
166
|
-
}
|
|
167
|
-
return valid;
|
|
168
|
-
}
|
|
169
|
-
// three.js compatibility
|
|
170
|
-
/** @deprecated */
|
|
171
|
-
sub(a) {
|
|
172
|
-
return this.subtract(a);
|
|
173
|
-
}
|
|
174
|
-
/** @deprecated */
|
|
175
|
-
setScalar(a) {
|
|
176
|
-
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
177
|
-
this[i] = a;
|
|
178
|
-
}
|
|
179
|
-
return this.check();
|
|
180
|
-
}
|
|
181
|
-
/** @deprecated */
|
|
182
|
-
addScalar(a) {
|
|
183
|
-
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
184
|
-
this[i] += a;
|
|
185
|
-
}
|
|
186
|
-
return this.check();
|
|
187
|
-
}
|
|
188
|
-
/** @deprecated */
|
|
189
|
-
subScalar(a) {
|
|
190
|
-
return this.addScalar(-a);
|
|
191
|
-
}
|
|
192
|
-
/** @deprecated */
|
|
193
|
-
multiplyScalar(scalar) {
|
|
194
|
-
// Multiplies all elements
|
|
195
|
-
// `Matrix4.scale` only scales its 3x3 "minor"
|
|
196
|
-
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
197
|
-
this[i] *= scalar;
|
|
198
|
-
}
|
|
199
|
-
return this.check();
|
|
200
|
-
}
|
|
201
|
-
/** @deprecated */
|
|
202
|
-
divideScalar(a) {
|
|
203
|
-
return this.multiplyByScalar(1 / a);
|
|
204
|
-
}
|
|
205
|
-
/** @deprecated */
|
|
206
|
-
clampScalar(min, max) {
|
|
207
|
-
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
208
|
-
this[i] = Math.min(Math.max(this[i], min), max);
|
|
209
|
-
}
|
|
210
|
-
return this.check();
|
|
211
|
-
}
|
|
212
|
-
/** @deprecated */
|
|
213
|
-
get elements() {
|
|
214
|
-
return this;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import MathArray from './math-array';
|
|
2
|
-
import { checkNumber } from '../../lib/validators';
|
|
3
|
-
import { config } from '../../lib/common';
|
|
4
|
-
/** Base class for matrices */
|
|
5
|
-
export default class Matrix extends MathArray {
|
|
6
|
-
// fromObject(object) {
|
|
7
|
-
// const array = object.elements;
|
|
8
|
-
// return this.fromRowMajor(array);
|
|
9
|
-
// }
|
|
10
|
-
// toObject(object) {
|
|
11
|
-
// const array = object.elements;
|
|
12
|
-
// this.toRowMajor(array);
|
|
13
|
-
// return object;
|
|
14
|
-
// }
|
|
15
|
-
// TODO better override formatString?
|
|
16
|
-
toString() {
|
|
17
|
-
let string = '[';
|
|
18
|
-
if (config.printRowMajor) {
|
|
19
|
-
string += 'row-major:';
|
|
20
|
-
for (let row = 0; row < this.RANK; ++row) {
|
|
21
|
-
for (let col = 0; col < this.RANK; ++col) {
|
|
22
|
-
string += ` ${this[col * this.RANK + row]}`;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
string += 'column-major:';
|
|
28
|
-
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
29
|
-
string += ` ${this[i]}`;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
string += ']';
|
|
33
|
-
return string;
|
|
34
|
-
}
|
|
35
|
-
getElementIndex(row, col) {
|
|
36
|
-
return col * this.RANK + row;
|
|
37
|
-
}
|
|
38
|
-
// By default assumes row major indices
|
|
39
|
-
getElement(row, col) {
|
|
40
|
-
return this[col * this.RANK + row];
|
|
41
|
-
}
|
|
42
|
-
// By default assumes row major indices
|
|
43
|
-
setElement(row, col, value) {
|
|
44
|
-
this[col * this.RANK + row] = checkNumber(value);
|
|
45
|
-
return this;
|
|
46
|
-
}
|
|
47
|
-
getColumn(columnIndex, result = new Array(this.RANK).fill(-0)) {
|
|
48
|
-
const firstIndex = columnIndex * this.RANK;
|
|
49
|
-
for (let i = 0; i < this.RANK; ++i) {
|
|
50
|
-
result[i] = this[firstIndex + i];
|
|
51
|
-
}
|
|
52
|
-
return result;
|
|
53
|
-
}
|
|
54
|
-
setColumn(columnIndex, columnVector) {
|
|
55
|
-
const firstIndex = columnIndex * this.RANK;
|
|
56
|
-
for (let i = 0; i < this.RANK; ++i) {
|
|
57
|
-
this[firstIndex + i] = columnVector[i];
|
|
58
|
-
}
|
|
59
|
-
return this;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import MathArray from './math-array';
|
|
2
|
-
import { checkNumber } from '../../lib/validators';
|
|
3
|
-
import assert from '../../lib/assert';
|
|
4
|
-
/** Base class for vectors with at least 2 elements */
|
|
5
|
-
export default class Vector extends MathArray {
|
|
6
|
-
// ACCESSORS
|
|
7
|
-
get x() {
|
|
8
|
-
return this[0];
|
|
9
|
-
}
|
|
10
|
-
set x(value) {
|
|
11
|
-
this[0] = checkNumber(value);
|
|
12
|
-
}
|
|
13
|
-
get y() {
|
|
14
|
-
return this[1];
|
|
15
|
-
}
|
|
16
|
-
set y(value) {
|
|
17
|
-
this[1] = checkNumber(value);
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Returns the length of the vector from the origin to the point described by this vector
|
|
21
|
-
*
|
|
22
|
-
* @note `length` is a reserved word for Arrays, so `v.length()` will return number of elements
|
|
23
|
-
* Instead we provide `len` and `magnitude`
|
|
24
|
-
*/
|
|
25
|
-
len() {
|
|
26
|
-
return Math.sqrt(this.lengthSquared());
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Returns the length of the vector from the origin to the point described by this vector
|
|
30
|
-
*/
|
|
31
|
-
magnitude() {
|
|
32
|
-
return this.len();
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Returns the squared length of the vector from the origin to the point described by this vector
|
|
36
|
-
*/
|
|
37
|
-
lengthSquared() {
|
|
38
|
-
let length = 0;
|
|
39
|
-
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
40
|
-
length += this[i] * this[i];
|
|
41
|
-
}
|
|
42
|
-
return length;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Returns the squared length of the vector from the origin to the point described by this vector
|
|
46
|
-
*/
|
|
47
|
-
magnitudeSquared() {
|
|
48
|
-
return this.lengthSquared();
|
|
49
|
-
}
|
|
50
|
-
distance(mathArray) {
|
|
51
|
-
return Math.sqrt(this.distanceSquared(mathArray));
|
|
52
|
-
}
|
|
53
|
-
distanceSquared(mathArray) {
|
|
54
|
-
let length = 0;
|
|
55
|
-
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
56
|
-
const dist = this[i] - mathArray[i];
|
|
57
|
-
length += dist * dist;
|
|
58
|
-
}
|
|
59
|
-
return checkNumber(length);
|
|
60
|
-
}
|
|
61
|
-
dot(mathArray) {
|
|
62
|
-
let product = 0;
|
|
63
|
-
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
64
|
-
product += this[i] * mathArray[i];
|
|
65
|
-
}
|
|
66
|
-
return checkNumber(product);
|
|
67
|
-
}
|
|
68
|
-
// MODIFIERS
|
|
69
|
-
normalize() {
|
|
70
|
-
const length = this.magnitude();
|
|
71
|
-
if (length !== 0) {
|
|
72
|
-
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
73
|
-
this[i] /= length;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return this.check();
|
|
77
|
-
}
|
|
78
|
-
multiply(...vectors) {
|
|
79
|
-
for (const vector of vectors) {
|
|
80
|
-
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
81
|
-
this[i] *= vector[i];
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return this.check();
|
|
85
|
-
}
|
|
86
|
-
divide(...vectors) {
|
|
87
|
-
for (const vector of vectors) {
|
|
88
|
-
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
89
|
-
this[i] /= vector[i];
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return this.check();
|
|
93
|
-
}
|
|
94
|
-
// THREE.js compatibility
|
|
95
|
-
lengthSq() {
|
|
96
|
-
return this.lengthSquared();
|
|
97
|
-
}
|
|
98
|
-
distanceTo(vector) {
|
|
99
|
-
return this.distance(vector);
|
|
100
|
-
}
|
|
101
|
-
distanceToSquared(vector) {
|
|
102
|
-
return this.distanceSquared(vector);
|
|
103
|
-
}
|
|
104
|
-
getComponent(i) {
|
|
105
|
-
assert(i >= 0 && i < this.ELEMENTS, 'index is out of range');
|
|
106
|
-
return checkNumber(this[i]);
|
|
107
|
-
}
|
|
108
|
-
setComponent(i, value) {
|
|
109
|
-
assert(i >= 0 && i < this.ELEMENTS, 'index is out of range');
|
|
110
|
-
this[i] = value;
|
|
111
|
-
return this.check();
|
|
112
|
-
}
|
|
113
|
-
addVectors(a, b) {
|
|
114
|
-
return this.copy(a).add(b);
|
|
115
|
-
}
|
|
116
|
-
subVectors(a, b) {
|
|
117
|
-
return this.copy(a).subtract(b);
|
|
118
|
-
}
|
|
119
|
-
multiplyVectors(a, b) {
|
|
120
|
-
return this.copy(a).multiply(b);
|
|
121
|
-
}
|
|
122
|
-
addScaledVector(a, b) {
|
|
123
|
-
// @ts-expect-error error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
|
124
|
-
return this.add(new this.constructor(a).multiplyScalar(b));
|
|
125
|
-
}
|
|
126
|
-
}
|