mathue 0.1.0
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/LICENSE +9 -0
- package/README.md +88 -0
- package/dist/index.d.ts +2189 -0
- package/dist/mathue.cjs +1 -0
- package/dist/mathue.js +701 -0
- package/dist/mathue.umd.cjs +1 -0
- package/package.json +56 -0
package/dist/mathue.js
ADDED
|
@@ -0,0 +1,701 @@
|
|
|
1
|
+
function* range(e, t) {
|
|
2
|
+
let n = t?.start ?? 0, r = t?.step ?? 1;
|
|
3
|
+
if (r !== 0 && !(r > 0 && n > e) && !(r < 0 && n < e)) for (let t = n; r > 0 ? t < e : t > e; t += r) yield t;
|
|
4
|
+
}
|
|
5
|
+
function sum(e) {
|
|
6
|
+
let t = 0;
|
|
7
|
+
for (let n of e) t += n;
|
|
8
|
+
return t;
|
|
9
|
+
}
|
|
10
|
+
function sumMap(e, t) {
|
|
11
|
+
let n = 0;
|
|
12
|
+
for (let r of e) n += t(r) ?? 0;
|
|
13
|
+
return n;
|
|
14
|
+
}
|
|
15
|
+
var INDEX_X$3 = 0, INDEX_Y$2 = 1, INDEX_Z$1 = 2, INDEX_W = 3, Vector4 = class e {
|
|
16
|
+
dimension = 4;
|
|
17
|
+
elements;
|
|
18
|
+
static _tmpMatrix4;
|
|
19
|
+
static get tmpMatrix4() {
|
|
20
|
+
return this._tmpMatrix4 ||= Matrix4.identity(), this._tmpMatrix4;
|
|
21
|
+
}
|
|
22
|
+
constructor(e, t, n, r) {
|
|
23
|
+
this.elements = [
|
|
24
|
+
e,
|
|
25
|
+
t,
|
|
26
|
+
n,
|
|
27
|
+
r
|
|
28
|
+
];
|
|
29
|
+
}
|
|
30
|
+
get x() {
|
|
31
|
+
return this.elements[INDEX_X$3];
|
|
32
|
+
}
|
|
33
|
+
set x(e) {
|
|
34
|
+
this.elements[INDEX_X$3] = e;
|
|
35
|
+
}
|
|
36
|
+
get y() {
|
|
37
|
+
return this.elements[INDEX_Y$2];
|
|
38
|
+
}
|
|
39
|
+
set y(e) {
|
|
40
|
+
this.elements[INDEX_Y$2] = e;
|
|
41
|
+
}
|
|
42
|
+
get z() {
|
|
43
|
+
return this.elements[INDEX_Z$1];
|
|
44
|
+
}
|
|
45
|
+
set z(e) {
|
|
46
|
+
this.elements[INDEX_Z$1] = e;
|
|
47
|
+
}
|
|
48
|
+
get w() {
|
|
49
|
+
return this.elements[INDEX_W];
|
|
50
|
+
}
|
|
51
|
+
set w(e) {
|
|
52
|
+
this.elements[INDEX_W] = e;
|
|
53
|
+
}
|
|
54
|
+
static zero() {
|
|
55
|
+
return new e(0, 0, 0, 0);
|
|
56
|
+
}
|
|
57
|
+
static one() {
|
|
58
|
+
return new e(1, 1, 1, 1);
|
|
59
|
+
}
|
|
60
|
+
clone() {
|
|
61
|
+
let { x: t, y: n, z: r, w: i } = this;
|
|
62
|
+
return new e(t, n, r, i);
|
|
63
|
+
}
|
|
64
|
+
isZero() {
|
|
65
|
+
let { x: e, y: t, z: n, w: r } = this;
|
|
66
|
+
return e === 0 && t === 0 && n === 0 && r === 0;
|
|
67
|
+
}
|
|
68
|
+
set(e, t, n, r) {
|
|
69
|
+
this.x = e, this.y = t, this.z = n, this.w = r;
|
|
70
|
+
}
|
|
71
|
+
copy(e) {
|
|
72
|
+
let { x: t, y: n, z: r, w: i } = e;
|
|
73
|
+
this.set(t, n, r, i);
|
|
74
|
+
}
|
|
75
|
+
add(e) {
|
|
76
|
+
return this.x += e.x, this.y += e.y, this.z += e.z, this.w += e.w, this;
|
|
77
|
+
}
|
|
78
|
+
subtract(e) {
|
|
79
|
+
return this.x -= e.x, this.y -= e.y, this.z -= e.z, this.w -= e.w, this;
|
|
80
|
+
}
|
|
81
|
+
multiplyScalar(e) {
|
|
82
|
+
return this.x *= e, this.y *= e, this.z *= e, this.w *= e, this;
|
|
83
|
+
}
|
|
84
|
+
divideScalar(e) {
|
|
85
|
+
return this.x /= e, this.y /= e, this.z /= e, this.w /= e, this;
|
|
86
|
+
}
|
|
87
|
+
length() {
|
|
88
|
+
let { x: e, y: t, z: n, w: r } = this;
|
|
89
|
+
return Math.sqrt(e ** 2 + t ** 2 + n ** 2 + r ** 2);
|
|
90
|
+
}
|
|
91
|
+
normalize() {
|
|
92
|
+
let e = this.length();
|
|
93
|
+
return e <= 0 ? this : this.divideScalar(e);
|
|
94
|
+
}
|
|
95
|
+
applyMatrix4(t) {
|
|
96
|
+
let { tmpMatrix4: n } = e;
|
|
97
|
+
n.copy(t);
|
|
98
|
+
let { x: r, y: i, z: a, w: o } = this, s = n._applyVector(r, i, a, o);
|
|
99
|
+
return this.copy(s), this;
|
|
100
|
+
}
|
|
101
|
+
applyQuaternion(t) {
|
|
102
|
+
let { tmpMatrix4: n } = e;
|
|
103
|
+
n.setQuaternion(t);
|
|
104
|
+
let { x: r, y: i, z: a, w: o } = this, s = n._applyVector(r, i, a, o);
|
|
105
|
+
return this.copy(s), this;
|
|
106
|
+
}
|
|
107
|
+
}, EPSILON$1 = 1e-8, Matrix4 = class t {
|
|
108
|
+
order = 4;
|
|
109
|
+
elements;
|
|
110
|
+
static _tmpMatrix;
|
|
111
|
+
static get tmpMatrix() {
|
|
112
|
+
return this._tmpMatrix ||= t.identity(), this._tmpMatrix;
|
|
113
|
+
}
|
|
114
|
+
static _tmpVector;
|
|
115
|
+
static get tmpVector() {
|
|
116
|
+
return this._tmpVector ||= Vector4.zero(), this._tmpVector;
|
|
117
|
+
}
|
|
118
|
+
constructor(e, t, n, r, i, a, o, s, c, l, u, d, f, p, m, h) {
|
|
119
|
+
this.elements = Float32Array.of(e, t, n, r, i, a, o, s, c, l, u, d, f, p, m, h);
|
|
120
|
+
}
|
|
121
|
+
static identity() {
|
|
122
|
+
return t.zero().setIdentity();
|
|
123
|
+
}
|
|
124
|
+
static zero() {
|
|
125
|
+
return new t(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
126
|
+
}
|
|
127
|
+
clone() {
|
|
128
|
+
let [e, n, r, i, a, o, s, c, l, u, d, f, p, m, h, g] = this.elements;
|
|
129
|
+
return new t(e, n, r, i, a, o, s, c, l, u, d, f, p, m, h, g);
|
|
130
|
+
}
|
|
131
|
+
set(e, t, n, r, i, a, o, s, c, l, u, d, f, p, m, h) {
|
|
132
|
+
return this.elements[0] = e, this.elements[1] = t, this.elements[2] = n, this.elements[3] = r, this.elements[4] = i, this.elements[5] = a, this.elements[6] = o, this.elements[7] = s, this.elements[8] = c, this.elements[9] = l, this.elements[10] = u, this.elements[11] = d, this.elements[12] = f, this.elements[13] = p, this.elements[14] = m, this.elements[15] = h, this;
|
|
133
|
+
}
|
|
134
|
+
copy(e) {
|
|
135
|
+
let [t, n, r, i, a, o, s, c, l, u, d, f, p, m, h, g] = e.elements;
|
|
136
|
+
this.set(t, n, r, i, a, o, s, c, l, u, d, f, p, m, h, g);
|
|
137
|
+
}
|
|
138
|
+
setIdentity() {
|
|
139
|
+
return this.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1), this;
|
|
140
|
+
}
|
|
141
|
+
setQuaternion(e) {
|
|
142
|
+
let { a: t, b: n, c: r, d: i } = e, a = 2 / e.squaredNorm(), o = n ** 2, s = r ** 2, c = i ** 2, l = t * n, u = t * r, d = t * i, f = n * r, p = n * i, m = r * i;
|
|
143
|
+
return this.set(1 - a * (s + c), a * (f - d), a * (p + u), 0, a * (f + d), 1 - a * (o + c), a * (m - l), 0, a * (p - u), a * (m + l), 1 - a * (o + s), 0, 0, 0, 0, 1), this;
|
|
144
|
+
}
|
|
145
|
+
add(t) {
|
|
146
|
+
let { order: n } = this;
|
|
147
|
+
for (let r of range(n ** 2)) this.elements[r] += t.elements[r];
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
150
|
+
subtract(t) {
|
|
151
|
+
let { order: n } = this;
|
|
152
|
+
for (let r of range(n ** 2)) this.elements[r] -= t.elements[r];
|
|
153
|
+
return this;
|
|
154
|
+
}
|
|
155
|
+
multiplyScalar(t) {
|
|
156
|
+
let { order: n } = this;
|
|
157
|
+
for (let r of range(n ** 2)) this.elements[r] *= t;
|
|
158
|
+
return this;
|
|
159
|
+
}
|
|
160
|
+
divideScalar(t) {
|
|
161
|
+
let { order: n } = this;
|
|
162
|
+
for (let r of range(n ** 2)) this.elements[r] /= t;
|
|
163
|
+
return this;
|
|
164
|
+
}
|
|
165
|
+
multiply(e) {
|
|
166
|
+
let [t, n, r, i, a, o, s, c, l, u, d, f, p, m, h, g] = this.elements, [_, v, y, b, x, S, C, w, T, E, D, O, k, A, j, M] = e.elements;
|
|
167
|
+
return this.elements[0] = _ * t + v * a + y * l + b * p, this.elements[1] = _ * n + v * o + y * u + b * m, this.elements[2] = _ * r + v * s + y * d + b * h, this.elements[3] = _ * i + v * c + y * f + b * g, this.elements[4] = x * t + S * a + C * l + w * p, this.elements[5] = x * n + S * o + C * u + w * m, this.elements[6] = x * r + S * s + C * d + w * h, this.elements[7] = x * i + S * c + C * f + w * g, this.elements[8] = T * t + E * a + D * l + O * p, this.elements[9] = T * n + E * o + D * u + O * m, this.elements[10] = T * r + E * s + D * d + O * h, this.elements[11] = T * i + E * c + D * f + O * g, this.elements[12] = k * t + A * a + j * l + M * p, this.elements[13] = k * n + A * o + j * u + M * m, this.elements[14] = k * r + A * s + j * d + M * h, this.elements[15] = k * i + A * c + j * f + M * g, this;
|
|
168
|
+
}
|
|
169
|
+
determinant() {
|
|
170
|
+
let [e, t, n, r, i, a, o, s, c, l, u, d, f, p, m, h] = this.elements;
|
|
171
|
+
return e * (a * (u * h - d * m) - o * (l * h - d * p) + s * (l * m - u * p)) - t * (i * (u * h - d * m) - o * (c * h - d * f) + s * (c * m - u * f)) + n * (i * (l * h - d * p) - a * (c * h - d * f) + s * (c * p - l * f)) - r * (i * (l * m - u * p) - a * (c * m - u * f) + o * (c * p - l * f));
|
|
172
|
+
}
|
|
173
|
+
invert() {
|
|
174
|
+
let e = this.determinant();
|
|
175
|
+
if (Math.abs(e) < EPSILON$1) return null;
|
|
176
|
+
let [t, n, r, i, a, o, s, l, u, d, f, p, m, h, g, _] = this.elements, v = f * _ - p * g, y = d * _ - p * h, b = d * g - f * h, x = s * _ - l * g, S = o * _ - l * h, C = o * g - s * h, w = s * p - l * f, T = o * p - l * d, E = o * f - s * d, D = u * _ - p * m, O = u * g - f * m, k = a * _ - l * m, A = a * g - s * m, j = a * p - l * u, M = a * f - s * u, N = u * h - d * m, P = a * h - o * m, F = a * d - o * u;
|
|
177
|
+
return this.elements[0] = (o * v - s * y + l * b) / e, this.elements[1] = -(n * v - r * y + i * b) / e, this.elements[2] = (n * x - r * S + i * C) / e, this.elements[3] = -(n * w - r * T + i * E) / e, this.elements[4] = -(a * v - s * D + l * O) / e, this.elements[5] = (t * v - r * D + i * O) / e, this.elements[6] = -(t * x - r * k + i * A) / e, this.elements[7] = (t * w - r * j + i * M) / e, this.elements[8] = (a * y - o * D + l * N) / e, this.elements[9] = -(t * y - n * D + i * N) / e, this.elements[10] = (t * S - n * k + i * P) / e, this.elements[11] = -(t * T - n * j + i * F) / e, this.elements[12] = -(a * b - o * O + s * N) / e, this.elements[13] = (t * b - n * O + r * N) / e, this.elements[14] = -(t * C - n * A + r * P) / e, this.elements[15] = (t * E - n * M + r * F) / e, this;
|
|
178
|
+
}
|
|
179
|
+
transpose() {
|
|
180
|
+
let [e, t, n, r, i, a, o, s, c, l, u, d, f, p, m, h] = this.elements;
|
|
181
|
+
return this.elements[1] = i, this.elements[2] = c, this.elements[3] = f, this.elements[4] = t, this.elements[6] = l, this.elements[7] = p, this.elements[8] = n, this.elements[9] = o, this.elements[11] = m, this.elements[12] = r, this.elements[13] = s, this.elements[14] = d, this;
|
|
182
|
+
}
|
|
183
|
+
divide(e) {
|
|
184
|
+
let { tmpMatrix: n } = t;
|
|
185
|
+
return n.copy(e), n.invert() ? this.multiply(n) : null;
|
|
186
|
+
}
|
|
187
|
+
scale(t) {
|
|
188
|
+
let { order: n } = this;
|
|
189
|
+
for (let r of range(n)) {
|
|
190
|
+
let i = r === n - 1 ? 1 : t.elements[r];
|
|
191
|
+
for (let t of range(n)) {
|
|
192
|
+
let e = r * n + t;
|
|
193
|
+
this.elements[e] *= i;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return this;
|
|
197
|
+
}
|
|
198
|
+
translate(e) {
|
|
199
|
+
let { x: t, y: n, z: r } = e, [i, a, o, s, c, l, u, d, f, p, m, h, g, _, v, y] = this.elements;
|
|
200
|
+
return this.elements[12] = i * t + c * n + f * r + g, this.elements[13] = a * t + l * n + p * r + _, this.elements[14] = o * t + u * n + m * r + v, this.elements[15] = s * t + d * n + h * r + y, this;
|
|
201
|
+
}
|
|
202
|
+
lookAt(e, t, n) {
|
|
203
|
+
let { x: r, y: i, z: a } = e, { x: o, y: s, z: l } = n, u = e.x - t.x, d = e.y - t.y, f = e.z - t.z, p = Math.sqrt(u ** 2 + d ** 2 + f ** 2);
|
|
204
|
+
if (p < EPSILON$1) return this;
|
|
205
|
+
u /= p, d /= p, f /= p;
|
|
206
|
+
let m = s * f - l * d, h = l * u - o * f, g = o * d - s * u, _ = Math.sqrt(m ** 2 + h ** 2 + g ** 2);
|
|
207
|
+
_ > 0 && (m /= _, h /= _, g /= _);
|
|
208
|
+
let v = d * g - f * h, y = f * m - u * g, b = u * h - d * m, x = Math.sqrt(v ** 2 + y ** 2 + b ** 2);
|
|
209
|
+
x > 0 && (v /= x, y /= x, b /= x);
|
|
210
|
+
let S = -(m * r + h * i + g * a), C = -(v * r + y * i + b * a), w = -(u * r + d * i + f * a);
|
|
211
|
+
return this.set(m, v, u, 0, h, y, d, 0, g, b, f, 0, S, C, w, 1), this;
|
|
212
|
+
}
|
|
213
|
+
perspective(e, t, n, r) {
|
|
214
|
+
let i = 1 / Math.tan(e / 2);
|
|
215
|
+
return this.set(i / r, 0, 0, 0, 0, i, 0, 0, 0, 0, 1, -1, 0, 0, 1, 0), n === Infinity ? (this.elements[10] = -1, this.elements[14] = -2 * t) : (this.elements[10] = -(n + t) / (n - t), this.elements[14] = -2 * n * t / (n - t)), this;
|
|
216
|
+
}
|
|
217
|
+
_applyVector(e, n, r, i) {
|
|
218
|
+
let { tmpVector: a } = t;
|
|
219
|
+
a.set(e, n, r, i);
|
|
220
|
+
let [o, s, c, l, u, d, f, p, m, h, g, _, v, y, b, x] = this.elements, S = o * e + u * n + m * r + v * i, C = s * e + d * n + h * r + y * i, w = c * e + f * n + g * r + b * i, T = l * e + p * n + _ * r + x * i;
|
|
221
|
+
return a.set(S, C, w, T), a;
|
|
222
|
+
}
|
|
223
|
+
}, INDEX_X$2 = 0, INDEX_Y$1 = 1, INDEX_Z = 2, Vector3 = class e {
|
|
224
|
+
dimension = 3;
|
|
225
|
+
elements;
|
|
226
|
+
static _tmpMatrix3;
|
|
227
|
+
static get tmpMatrix3() {
|
|
228
|
+
return this._tmpMatrix3 ||= Matrix3.identity(), this._tmpMatrix3;
|
|
229
|
+
}
|
|
230
|
+
static _tmpMatrix4;
|
|
231
|
+
static get tmpMatrix4() {
|
|
232
|
+
return this._tmpMatrix4 ||= Matrix4.identity(), this._tmpMatrix4;
|
|
233
|
+
}
|
|
234
|
+
constructor(e, t, n) {
|
|
235
|
+
this.elements = [
|
|
236
|
+
e,
|
|
237
|
+
t,
|
|
238
|
+
n
|
|
239
|
+
];
|
|
240
|
+
}
|
|
241
|
+
get x() {
|
|
242
|
+
return this.elements[INDEX_X$2];
|
|
243
|
+
}
|
|
244
|
+
set x(e) {
|
|
245
|
+
this.elements[INDEX_X$2] = e;
|
|
246
|
+
}
|
|
247
|
+
get y() {
|
|
248
|
+
return this.elements[INDEX_Y$1];
|
|
249
|
+
}
|
|
250
|
+
set y(e) {
|
|
251
|
+
this.elements[INDEX_Y$1] = e;
|
|
252
|
+
}
|
|
253
|
+
get z() {
|
|
254
|
+
return this.elements[INDEX_Z];
|
|
255
|
+
}
|
|
256
|
+
set z(e) {
|
|
257
|
+
this.elements[INDEX_Z] = e;
|
|
258
|
+
}
|
|
259
|
+
static zero() {
|
|
260
|
+
return new e(0, 0, 0);
|
|
261
|
+
}
|
|
262
|
+
static one() {
|
|
263
|
+
return new e(1, 1, 1);
|
|
264
|
+
}
|
|
265
|
+
clone() {
|
|
266
|
+
let { x: t, y: n, z: r } = this;
|
|
267
|
+
return new e(t, n, r);
|
|
268
|
+
}
|
|
269
|
+
isZero() {
|
|
270
|
+
let { x: e, y: t, z: n } = this;
|
|
271
|
+
return e === 0 && t === 0 && n === 0;
|
|
272
|
+
}
|
|
273
|
+
set(e, t, n) {
|
|
274
|
+
return this.x = e, this.y = t, this.z = n, this;
|
|
275
|
+
}
|
|
276
|
+
copy(e) {
|
|
277
|
+
let { x: t, y: n, z: r } = e;
|
|
278
|
+
return this.set(t, n, r);
|
|
279
|
+
}
|
|
280
|
+
add(e) {
|
|
281
|
+
return this.x += e.x, this.y += e.y, this.z += e.z, this;
|
|
282
|
+
}
|
|
283
|
+
subtract(e) {
|
|
284
|
+
return this.x -= e.x, this.y -= e.y, this.z -= e.z, this;
|
|
285
|
+
}
|
|
286
|
+
multiplyScalar(e) {
|
|
287
|
+
return this.x *= e, this.y *= e, this.z *= e, this;
|
|
288
|
+
}
|
|
289
|
+
divideScalar(e) {
|
|
290
|
+
return this.x /= e, this.y /= e, this.z /= e, this;
|
|
291
|
+
}
|
|
292
|
+
length() {
|
|
293
|
+
let { x: e, y: t, z: n } = this;
|
|
294
|
+
return Math.sqrt(e ** 2 + t ** 2 + n ** 2);
|
|
295
|
+
}
|
|
296
|
+
normalize() {
|
|
297
|
+
let e = this.length();
|
|
298
|
+
return e <= 0 ? this : this.divideScalar(e);
|
|
299
|
+
}
|
|
300
|
+
cross(e) {
|
|
301
|
+
let { x: t, y: n, z: r } = this, { x: i, y: a, z: o } = e, s = n * o - r * a, c = r * i - t * o, l = t * a - n * i;
|
|
302
|
+
return this.set(s, c, l);
|
|
303
|
+
}
|
|
304
|
+
crossTo(e, t) {
|
|
305
|
+
return t.copy(this), t.cross(e);
|
|
306
|
+
}
|
|
307
|
+
applyMatrix3(t) {
|
|
308
|
+
let { tmpMatrix3: n } = e;
|
|
309
|
+
n.copy(t);
|
|
310
|
+
let { x: r, y: i, z: a } = n._applyVector(this.x, this.y, this.z);
|
|
311
|
+
return this.set(r, i, a), this;
|
|
312
|
+
}
|
|
313
|
+
applyMatrix4(t) {
|
|
314
|
+
let { tmpMatrix4: n } = e;
|
|
315
|
+
n.copy(t);
|
|
316
|
+
let { x: r, y: i, z: a } = n._applyVector(this.x, this.y, this.z, 0);
|
|
317
|
+
return this.set(r, i, a), this;
|
|
318
|
+
}
|
|
319
|
+
applyQuaternion(t) {
|
|
320
|
+
let { tmpMatrix4: n } = e;
|
|
321
|
+
n.setQuaternion(t);
|
|
322
|
+
let { x: r, y: i, z: a } = n._applyVector(this.x, this.y, this.z, 0);
|
|
323
|
+
return this.set(r, i, a), this;
|
|
324
|
+
}
|
|
325
|
+
}, EPSILON = 1e-8, Matrix3 = class t {
|
|
326
|
+
order = 3;
|
|
327
|
+
elements;
|
|
328
|
+
static _tmpMatrix;
|
|
329
|
+
static get tmpMatrix() {
|
|
330
|
+
return this._tmpMatrix ||= t.identity(), this._tmpMatrix;
|
|
331
|
+
}
|
|
332
|
+
static _tmpVector;
|
|
333
|
+
static get tmpVector() {
|
|
334
|
+
return this._tmpVector ||= Vector3.zero(), this._tmpVector;
|
|
335
|
+
}
|
|
336
|
+
constructor(e, t, n, r, i, a, o, s, c) {
|
|
337
|
+
this.elements = Float32Array.of(e, t, n, r, i, a, o, s, c);
|
|
338
|
+
}
|
|
339
|
+
static identity() {
|
|
340
|
+
return t.zero().setIdentity();
|
|
341
|
+
}
|
|
342
|
+
static zero() {
|
|
343
|
+
return new t(0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
344
|
+
}
|
|
345
|
+
clone() {
|
|
346
|
+
let [e, n, r, i, a, o, s, c, l] = this.elements;
|
|
347
|
+
return new t(e, n, r, i, a, o, s, c, l);
|
|
348
|
+
}
|
|
349
|
+
set(e, t, n, r, i, a, o, s, c) {
|
|
350
|
+
return this.elements[0] = e, this.elements[1] = t, this.elements[2] = n, this.elements[3] = r, this.elements[4] = i, this.elements[5] = a, this.elements[6] = o, this.elements[7] = s, this.elements[8] = c, this;
|
|
351
|
+
}
|
|
352
|
+
copy(e) {
|
|
353
|
+
let [t, n, r, i, a, o, s, c, l] = e.elements;
|
|
354
|
+
this.set(t, n, r, i, a, o, s, c, l);
|
|
355
|
+
}
|
|
356
|
+
setIdentity() {
|
|
357
|
+
return this.set(1, 0, 0, 0, 1, 0, 0, 0, 1), this;
|
|
358
|
+
}
|
|
359
|
+
add(t) {
|
|
360
|
+
let { order: n } = this;
|
|
361
|
+
for (let r of range(n ** 2)) this.elements[r] += t.elements[r];
|
|
362
|
+
return this;
|
|
363
|
+
}
|
|
364
|
+
subtract(t) {
|
|
365
|
+
let { order: n } = this;
|
|
366
|
+
for (let r of range(n ** 2)) this.elements[r] -= t.elements[r];
|
|
367
|
+
return this;
|
|
368
|
+
}
|
|
369
|
+
multiplyScalar(t) {
|
|
370
|
+
let { order: n } = this;
|
|
371
|
+
for (let r of range(n ** 2)) this.elements[r] *= t;
|
|
372
|
+
return this;
|
|
373
|
+
}
|
|
374
|
+
divideScalar(t) {
|
|
375
|
+
let { order: n } = this;
|
|
376
|
+
for (let r of range(n ** 2)) this.elements[r] /= t;
|
|
377
|
+
return this;
|
|
378
|
+
}
|
|
379
|
+
multiply(e) {
|
|
380
|
+
let [t, n, r, i, a, o, s, c, l] = this.elements, [u, d, f, p, m, h, g, _, v] = e.elements;
|
|
381
|
+
return this.elements[0] = u * t + d * i + f * s, this.elements[1] = u * n + d * a + f * c, this.elements[2] = u * r + d * o + f * l, this.elements[3] = p * t + m * i + h * s, this.elements[4] = p * n + m * a + h * c, this.elements[5] = p * r + m * o + h * l, this.elements[6] = g * t + _ * i + v * s, this.elements[7] = g * n + _ * a + v * c, this.elements[8] = g * r + _ * o + v * l, this;
|
|
382
|
+
}
|
|
383
|
+
determinant() {
|
|
384
|
+
let [e, t, n, r, i, a, o, s, c] = this.elements;
|
|
385
|
+
return e * (c * i - a * s) + t * (-c * r + a * o) + n * (s * r - i * o);
|
|
386
|
+
}
|
|
387
|
+
invert() {
|
|
388
|
+
let e = this.determinant();
|
|
389
|
+
if (Math.abs(e) < EPSILON) return null;
|
|
390
|
+
let [t, n, r, i, a, o, s, c, l] = this.elements, u = l * a - o * c, d = -l * i + o * s, f = c * i - a * s;
|
|
391
|
+
return this.elements[0] = u / e, this.elements[1] = (-l * n + r * c) / e, this.elements[2] = (o * n - r * a) / e, this.elements[3] = d / e, this.elements[4] = (l * t - r * s) / e, this.elements[5] = (-o * t + r * i) / e, this.elements[6] = f / e, this.elements[7] = (-c * t + n * s) / e, this.elements[8] = (a * t - n * i) / e, this;
|
|
392
|
+
}
|
|
393
|
+
transpose() {
|
|
394
|
+
let [e, t, n, r, i, a, o, s, c] = this.elements;
|
|
395
|
+
return this.elements[1] = r, this.elements[2] = o, this.elements[3] = t, this.elements[5] = s, this.elements[6] = n, this.elements[7] = a, this;
|
|
396
|
+
}
|
|
397
|
+
divide(e) {
|
|
398
|
+
let { tmpMatrix: n } = t;
|
|
399
|
+
return n.copy(e), n.invert() ? this.multiply(n) : null;
|
|
400
|
+
}
|
|
401
|
+
_applyVector(e, n, r) {
|
|
402
|
+
let { tmpVector: i } = t;
|
|
403
|
+
i.set(e, n, r);
|
|
404
|
+
let [a, o, s, c, l, u, d, f, p] = this.elements, m = a * e + c * n + d * r, h = o * e + l * n + f * r, g = s * e + u * n + p * r;
|
|
405
|
+
return i.set(m, h, g), i;
|
|
406
|
+
}
|
|
407
|
+
}, PolarCoordinate3 = class {
|
|
408
|
+
_phi;
|
|
409
|
+
_theta;
|
|
410
|
+
_radius;
|
|
411
|
+
constructor(e, t, n) {
|
|
412
|
+
this._phi = e, this._theta = t, this._radius = n;
|
|
413
|
+
}
|
|
414
|
+
get phi() {
|
|
415
|
+
return this._phi;
|
|
416
|
+
}
|
|
417
|
+
set phi(e) {
|
|
418
|
+
this._phi = e;
|
|
419
|
+
}
|
|
420
|
+
get theta() {
|
|
421
|
+
return this._theta;
|
|
422
|
+
}
|
|
423
|
+
set theta(e) {
|
|
424
|
+
this._theta = e;
|
|
425
|
+
}
|
|
426
|
+
get radius() {
|
|
427
|
+
return this._radius;
|
|
428
|
+
}
|
|
429
|
+
set radius(e) {
|
|
430
|
+
this._radius = e;
|
|
431
|
+
}
|
|
432
|
+
toVector3(e) {
|
|
433
|
+
let { phi: t, theta: n, radius: r } = this, { cos: i, sin: a } = Math, o = a(n), s = r * o * i(t), c = r * o * a(t), l = r * i(n);
|
|
434
|
+
e.set(s, c, l);
|
|
435
|
+
}
|
|
436
|
+
toTangentZ(e) {
|
|
437
|
+
let { phi: t, theta: n } = this, { cos: r, sin: i } = Math, a = r(n), o = -a * r(t), s = -a * i(t), c = i(n);
|
|
438
|
+
e.set(o, s, c);
|
|
439
|
+
}
|
|
440
|
+
}, Quaternion = class e {
|
|
441
|
+
_a;
|
|
442
|
+
_b;
|
|
443
|
+
_c;
|
|
444
|
+
_d;
|
|
445
|
+
static temporary = e.identity();
|
|
446
|
+
constructor(e, t, n, r) {
|
|
447
|
+
this._a = e, this._b = t, this._c = n, this._d = r;
|
|
448
|
+
}
|
|
449
|
+
get a() {
|
|
450
|
+
return this._a;
|
|
451
|
+
}
|
|
452
|
+
get b() {
|
|
453
|
+
return this._b;
|
|
454
|
+
}
|
|
455
|
+
get c() {
|
|
456
|
+
return this._c;
|
|
457
|
+
}
|
|
458
|
+
get d() {
|
|
459
|
+
return this._d;
|
|
460
|
+
}
|
|
461
|
+
static identity() {
|
|
462
|
+
return new e(1, 0, 0, 0);
|
|
463
|
+
}
|
|
464
|
+
static fromAxisAndAngle(t, n) {
|
|
465
|
+
let r = e.identity();
|
|
466
|
+
return r.setAxisAndAngle(t, n), r;
|
|
467
|
+
}
|
|
468
|
+
clone() {
|
|
469
|
+
let { a: t, b: n, c: r, d: i } = this;
|
|
470
|
+
return new e(t, n, r, i);
|
|
471
|
+
}
|
|
472
|
+
set(e, t, n, r) {
|
|
473
|
+
return this._a = e, this._b = t, this._c = n, this._d = r, this;
|
|
474
|
+
}
|
|
475
|
+
copy(e) {
|
|
476
|
+
let { a: t, b: n, c: r, d: i } = e;
|
|
477
|
+
return this.set(t, n, r, i);
|
|
478
|
+
}
|
|
479
|
+
setIdentity() {
|
|
480
|
+
this.set(1, 0, 0, 0);
|
|
481
|
+
}
|
|
482
|
+
setAxisAndAngle(e, t) {
|
|
483
|
+
if (e.isZero()) return this.setIdentity();
|
|
484
|
+
e.normalize();
|
|
485
|
+
let { x: n, y: r, z: i } = e, a = Math.sin(t / 2);
|
|
486
|
+
this.set(Math.cos(t / 2), n * a, r * a, i * a);
|
|
487
|
+
}
|
|
488
|
+
squaredNorm() {
|
|
489
|
+
let { a: e, b: t, c: n, d: r } = this;
|
|
490
|
+
return e ** 2 + t ** 2 + n ** 2 + r ** 2;
|
|
491
|
+
}
|
|
492
|
+
norm() {
|
|
493
|
+
return Math.sqrt(this.squaredNorm());
|
|
494
|
+
}
|
|
495
|
+
conjugate() {
|
|
496
|
+
return this._b *= -1, this._c *= -1, this._d *= -1, this;
|
|
497
|
+
}
|
|
498
|
+
add(e) {
|
|
499
|
+
let { a: t, b: n, c: r, d: i } = e;
|
|
500
|
+
return this._a += t, this._b += n, this._c += r, this._d += i, this;
|
|
501
|
+
}
|
|
502
|
+
subtract(e) {
|
|
503
|
+
let { a: t, b: n, c: r, d: i } = e;
|
|
504
|
+
return this._a -= t, this._b -= n, this._c -= r, this._d -= i, this;
|
|
505
|
+
}
|
|
506
|
+
multiply(e) {
|
|
507
|
+
let { a: t, b: n, c: r, d: i } = this, { a, b: o, c: s, d: c } = e;
|
|
508
|
+
return this._a = t * a - n * o - r * s - i * c, this._b = t * o + n * a + r * c - i * s, this._c = t * s - n * c + r * a + i * o, this._d = t * c + n * s - r * o + i * a, this;
|
|
509
|
+
}
|
|
510
|
+
invert() {
|
|
511
|
+
let e = this.squaredNorm();
|
|
512
|
+
return e <= 0 ? null : this.conjugate().divideScalar(e);
|
|
513
|
+
}
|
|
514
|
+
divide(t) {
|
|
515
|
+
let { temporary: n } = e;
|
|
516
|
+
return n.copy(t), n.invert() ? this.multiply(n) : null;
|
|
517
|
+
}
|
|
518
|
+
multiplyScalar(e) {
|
|
519
|
+
return this._a *= e, this._b *= e, this._c *= e, this._d *= e, this;
|
|
520
|
+
}
|
|
521
|
+
divideScalar(e) {
|
|
522
|
+
return this._a /= e, this._b /= e, this._c /= e, this._d /= e, this;
|
|
523
|
+
}
|
|
524
|
+
rotateX(t) {
|
|
525
|
+
let { temporary: n } = e;
|
|
526
|
+
return n.setIdentity(), n.setAxisAndAngle(new Vector3(1, 0, 0), t), this.multiply(n);
|
|
527
|
+
}
|
|
528
|
+
rotateY(t) {
|
|
529
|
+
let { temporary: n } = e;
|
|
530
|
+
return n.setIdentity(), n.setAxisAndAngle(new Vector3(0, 1, 0), t), this.multiply(n);
|
|
531
|
+
}
|
|
532
|
+
rotateZ(t) {
|
|
533
|
+
let { temporary: n } = e;
|
|
534
|
+
return n.setIdentity(), n.setAxisAndAngle(new Vector3(0, 0, 1), t), this.multiply(n);
|
|
535
|
+
}
|
|
536
|
+
}, INDEX_X$1 = 0, Vector1 = class e {
|
|
537
|
+
dimension = 1;
|
|
538
|
+
elements;
|
|
539
|
+
static _tmpMatrix3;
|
|
540
|
+
static get tmpMatrix3() {
|
|
541
|
+
return this._tmpMatrix3 ||= Matrix3.identity(), this._tmpMatrix3;
|
|
542
|
+
}
|
|
543
|
+
static _tmpMatrix4;
|
|
544
|
+
static get tmpMatrix4() {
|
|
545
|
+
return this._tmpMatrix4 ||= Matrix4.identity(), this._tmpMatrix4;
|
|
546
|
+
}
|
|
547
|
+
constructor(e) {
|
|
548
|
+
this.elements = [e];
|
|
549
|
+
}
|
|
550
|
+
get x() {
|
|
551
|
+
return this.elements[INDEX_X$1];
|
|
552
|
+
}
|
|
553
|
+
set x(e) {
|
|
554
|
+
this.elements[INDEX_X$1] = e;
|
|
555
|
+
}
|
|
556
|
+
static zero() {
|
|
557
|
+
return new e(0);
|
|
558
|
+
}
|
|
559
|
+
static one() {
|
|
560
|
+
return new e(1);
|
|
561
|
+
}
|
|
562
|
+
clone() {
|
|
563
|
+
let { x: t } = this;
|
|
564
|
+
return new e(t);
|
|
565
|
+
}
|
|
566
|
+
isZero() {
|
|
567
|
+
return this.x === 0;
|
|
568
|
+
}
|
|
569
|
+
set(e) {
|
|
570
|
+
return this.x = e, this;
|
|
571
|
+
}
|
|
572
|
+
copy(e) {
|
|
573
|
+
return this.x = e.x, this;
|
|
574
|
+
}
|
|
575
|
+
add(e) {
|
|
576
|
+
return this.x += e.x, this;
|
|
577
|
+
}
|
|
578
|
+
subtract(e) {
|
|
579
|
+
return this.x -= e.x, this;
|
|
580
|
+
}
|
|
581
|
+
multiplyScalar(e) {
|
|
582
|
+
return this.x *= e, this;
|
|
583
|
+
}
|
|
584
|
+
divideScalar(e) {
|
|
585
|
+
return this.x /= e, this;
|
|
586
|
+
}
|
|
587
|
+
length() {
|
|
588
|
+
return Math.abs(this.x);
|
|
589
|
+
}
|
|
590
|
+
normalize() {
|
|
591
|
+
return this.x /= this.length(), this;
|
|
592
|
+
}
|
|
593
|
+
applyMatrix3(t) {
|
|
594
|
+
let { tmpMatrix3: n } = e;
|
|
595
|
+
n.copy(t);
|
|
596
|
+
let { x: r } = n._applyVector(this.x, 0, 0);
|
|
597
|
+
return this.set(r), this;
|
|
598
|
+
}
|
|
599
|
+
applyMatrix4(t) {
|
|
600
|
+
let { tmpMatrix4: n } = e;
|
|
601
|
+
n.copy(t);
|
|
602
|
+
let { x: r } = n._applyVector(this.x, 0, 0, 0);
|
|
603
|
+
return this.set(r), this;
|
|
604
|
+
}
|
|
605
|
+
applyQuaternion(t) {
|
|
606
|
+
let { tmpMatrix4: n } = e;
|
|
607
|
+
n.setQuaternion(t);
|
|
608
|
+
let { x: r } = n._applyVector(this.x, 0, 0, 0);
|
|
609
|
+
return this.set(r), this;
|
|
610
|
+
}
|
|
611
|
+
}, INDEX_X = 0, INDEX_Y = 1, Vector2 = class e {
|
|
612
|
+
dimension = 2;
|
|
613
|
+
elements;
|
|
614
|
+
static _tmpMatrix3;
|
|
615
|
+
static get tmpMatrix3() {
|
|
616
|
+
return this._tmpMatrix3 ||= Matrix3.identity(), this._tmpMatrix3;
|
|
617
|
+
}
|
|
618
|
+
static _tmpMatrix4;
|
|
619
|
+
static get tmpMatrix4() {
|
|
620
|
+
return this._tmpMatrix4 ||= Matrix4.identity(), this._tmpMatrix4;
|
|
621
|
+
}
|
|
622
|
+
constructor(e, t) {
|
|
623
|
+
this.elements = [e, t];
|
|
624
|
+
}
|
|
625
|
+
get x() {
|
|
626
|
+
return this.elements[INDEX_X];
|
|
627
|
+
}
|
|
628
|
+
set x(e) {
|
|
629
|
+
this.elements[INDEX_X] = e;
|
|
630
|
+
}
|
|
631
|
+
get y() {
|
|
632
|
+
return this.elements[INDEX_Y];
|
|
633
|
+
}
|
|
634
|
+
set y(e) {
|
|
635
|
+
this.elements[INDEX_Y] = e;
|
|
636
|
+
}
|
|
637
|
+
static zero() {
|
|
638
|
+
return new e(0, 0);
|
|
639
|
+
}
|
|
640
|
+
static one() {
|
|
641
|
+
return new e(1, 1);
|
|
642
|
+
}
|
|
643
|
+
clone() {
|
|
644
|
+
let { x: t, y: n } = this;
|
|
645
|
+
return new e(t, n);
|
|
646
|
+
}
|
|
647
|
+
isZero() {
|
|
648
|
+
let { x: e, y: t } = this;
|
|
649
|
+
return e === 0 && t === 0;
|
|
650
|
+
}
|
|
651
|
+
set(e, t) {
|
|
652
|
+
return this.x = e, this.y = t, this;
|
|
653
|
+
}
|
|
654
|
+
copy(e) {
|
|
655
|
+
let { x: t, y: n } = e;
|
|
656
|
+
return this.set(t, n);
|
|
657
|
+
}
|
|
658
|
+
add(e) {
|
|
659
|
+
return this.x += e.x, this.y += e.y, this;
|
|
660
|
+
}
|
|
661
|
+
subtract(e) {
|
|
662
|
+
return this.x -= e.x, this.y -= e.y, this;
|
|
663
|
+
}
|
|
664
|
+
multiplyScalar(e) {
|
|
665
|
+
return this.x *= e, this.y *= e, this;
|
|
666
|
+
}
|
|
667
|
+
divideScalar(e) {
|
|
668
|
+
return this.x /= e, this.y /= e, this;
|
|
669
|
+
}
|
|
670
|
+
length() {
|
|
671
|
+
let { x: e, y: t } = this;
|
|
672
|
+
return Math.sqrt(e ** 2 + t ** 2);
|
|
673
|
+
}
|
|
674
|
+
normalize() {
|
|
675
|
+
let e = this.length();
|
|
676
|
+
return e <= 0 ? this : this.divideScalar(e);
|
|
677
|
+
}
|
|
678
|
+
rotate(e) {
|
|
679
|
+
let { cos: t, sin: n } = Math, r = this.x * t(e) - this.y * n(e), i = this.x * n(e) + this.y * t(e);
|
|
680
|
+
return this.x = r, this.y = i, this;
|
|
681
|
+
}
|
|
682
|
+
applyMatrix3(t) {
|
|
683
|
+
let { tmpMatrix3: n } = e;
|
|
684
|
+
n.copy(t);
|
|
685
|
+
let { x: r, y: i } = n._applyVector(this.x, this.y, 0);
|
|
686
|
+
return this.set(r, i), this;
|
|
687
|
+
}
|
|
688
|
+
applyMatrix4(t) {
|
|
689
|
+
let { tmpMatrix4: n } = e;
|
|
690
|
+
n.copy(t);
|
|
691
|
+
let { x: r, y: i } = n._applyVector(this.x, this.y, 0, 0);
|
|
692
|
+
return this.set(r, i), this;
|
|
693
|
+
}
|
|
694
|
+
applyQuaternion(t) {
|
|
695
|
+
let { tmpMatrix4: n } = e;
|
|
696
|
+
n.setQuaternion(t);
|
|
697
|
+
let { x: r, y: i } = n._applyVector(this.x, this.y, 0, 0);
|
|
698
|
+
return this.set(r, i), this;
|
|
699
|
+
}
|
|
700
|
+
};
|
|
701
|
+
export { Matrix3, Matrix4, PolarCoordinate3, Quaternion, Vector1, Vector2, Vector3, Vector4, range, sum, sumMap };
|