toosoon-utils 4.1.8 → 4.2.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/README.md +97 -885
- package/lib/constants.d.ts +0 -1
- package/lib/constants.js +3 -1
- package/lib/extras/color-scale/ColorScale.d.ts +2 -2
- package/lib/extras/color-scale/ColorScale.js +2 -2
- package/lib/extras/curves/CatmullRomCurve.d.ts +20 -5
- package/lib/extras/curves/CatmullRomCurve.js +23 -5
- package/lib/extras/curves/CatmullRomCurve3.d.ts +101 -0
- package/lib/extras/curves/CatmullRomCurve3.js +122 -0
- package/lib/extras/curves/CubicBezierCurve.d.ts +20 -5
- package/lib/extras/curves/CubicBezierCurve.js +23 -5
- package/lib/extras/curves/CubicBezierCurve3.d.ts +101 -0
- package/lib/extras/curves/CubicBezierCurve3.js +122 -0
- package/lib/extras/curves/Curve.d.ts +23 -24
- package/lib/extras/curves/Curve.js +19 -26
- package/lib/extras/curves/EllipseCurve.d.ts +21 -5
- package/lib/extras/curves/EllipseCurve.js +55 -6
- package/lib/extras/curves/LineCurve.d.ts +34 -10
- package/lib/extras/curves/LineCurve.js +35 -13
- package/lib/extras/curves/LineCurve3.d.ts +87 -0
- package/lib/extras/curves/LineCurve3.js +108 -0
- package/lib/extras/curves/PolylineCurve.d.ts +9 -8
- package/lib/extras/curves/PolylineCurve.js +6 -6
- package/lib/extras/curves/PolylineCurve3.d.ts +28 -0
- package/lib/extras/curves/PolylineCurve3.js +39 -0
- package/lib/extras/curves/QuadraticBezierCurve.d.ts +19 -5
- package/lib/extras/curves/QuadraticBezierCurve.js +22 -5
- package/lib/extras/curves/QuadraticBezierCurve3.d.ts +84 -0
- package/lib/extras/curves/QuadraticBezierCurve3.js +102 -0
- package/lib/extras/curves/SplineCurve.d.ts +12 -8
- package/lib/extras/curves/SplineCurve.js +9 -6
- package/lib/extras/curves/SplineCurve3.d.ts +28 -0
- package/lib/extras/curves/SplineCurve3.js +41 -0
- package/lib/extras/curves/index.d.ts +6 -0
- package/lib/extras/curves/index.js +6 -0
- package/lib/extras/geometry/Matrix2.d.ts +1 -0
- package/lib/extras/geometry/Matrix2.js +230 -0
- package/lib/extras/geometry/Matrix4.d.ts +1 -0
- package/lib/extras/geometry/Matrix4.js +632 -0
- package/lib/extras/geometry/Vector.d.ts +42 -0
- package/lib/extras/geometry/Vector.js +1 -0
- package/lib/extras/geometry/Vector2.d.ts +480 -0
- package/lib/extras/geometry/Vector2.js +709 -0
- package/lib/extras/geometry/Vector3.d.ts +486 -0
- package/lib/extras/geometry/Vector3.js +765 -0
- package/lib/extras/geometry/index.d.ts +3 -0
- package/lib/extras/geometry/index.js +2 -0
- package/lib/extras/paths/Path.d.ts +24 -18
- package/lib/extras/paths/Path.js +48 -35
- package/lib/extras/paths/PathContext.d.ts +97 -67
- package/lib/extras/paths/PathContext.js +326 -183
- package/lib/extras/paths/PathSVG.d.ts +43 -31
- package/lib/extras/paths/PathSVG.js +68 -50
- package/lib/geometry.d.ts +0 -135
- package/lib/geometry.js +1 -219
- package/lib/maths.d.ts +54 -22
- package/lib/maths.js +77 -27
- package/lib/random.d.ts +12 -16
- package/lib/random.js +19 -27
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +43 -1
- package/package.json +2 -1
|
@@ -0,0 +1,632 @@
|
|
|
1
|
+
// import { EPSILON } from '../../constants';
|
|
2
|
+
// import Vector3 from './Vector3';
|
|
3
|
+
// import type { Matrix4x4, Vector3D } from '../../types';
|
|
4
|
+
export {};
|
|
5
|
+
// // prettier-ignore
|
|
6
|
+
// export const IDENTITY_MATRIX_4: Matrix4x4 = [
|
|
7
|
+
// 1, 0, 0, 0,
|
|
8
|
+
// 0, 1, 0, 0,
|
|
9
|
+
// 0, 0, 1, 0,
|
|
10
|
+
// 0, 0, 0, 1,
|
|
11
|
+
// ] as const;
|
|
12
|
+
// /**
|
|
13
|
+
// * Represent a 4×4 matrix
|
|
14
|
+
// *
|
|
15
|
+
// * Note on Row-Major and Column-Major Ordering
|
|
16
|
+
// * The constructor and methods take arguments in row-major order:
|
|
17
|
+
// * n11, n12, n13, n14
|
|
18
|
+
// * n21, n22, n23, n24
|
|
19
|
+
// * n31, n32, n33, n34
|
|
20
|
+
// * n41, n42, n43, n44
|
|
21
|
+
// *
|
|
22
|
+
// * Meanwhile, the intern values are stored in column-major order:
|
|
23
|
+
// * m11, m21, m31, m41
|
|
24
|
+
// * m12, m22, m32, m42
|
|
25
|
+
// * m13, m23, m33, m43
|
|
26
|
+
// * m14, m24, m34, m44
|
|
27
|
+
// *
|
|
28
|
+
// * 2D matrix transform aliases:
|
|
29
|
+
// * | 2D | 3D equivalent |
|
|
30
|
+
// * | --- | ------------ |
|
|
31
|
+
// * | `a` | `n11` | `m11` |
|
|
32
|
+
// * | `b` | `n21` | `m12` |
|
|
33
|
+
// * | `c` | `n12` | `m21` |
|
|
34
|
+
// * | `d` | `n22` | `m22` |
|
|
35
|
+
// * | `e` | `n14` | `m41` |
|
|
36
|
+
// * | `f` | `n24` | `m42` |
|
|
37
|
+
// *
|
|
38
|
+
// * a, b | a, c, 0, e
|
|
39
|
+
// * c, d | b, d, 0, f
|
|
40
|
+
// * 0, 0 |
|
|
41
|
+
// * e, f |
|
|
42
|
+
// *
|
|
43
|
+
// * @exports
|
|
44
|
+
// * @class Matrix4
|
|
45
|
+
// */
|
|
46
|
+
// export default class Matrix4 {
|
|
47
|
+
// readonly isMatrix4 = true;
|
|
48
|
+
// readonly type: string = 'Matrix4';
|
|
49
|
+
// public values!: Matrix4x4;
|
|
50
|
+
// static identity = new Matrix4();
|
|
51
|
+
// /**
|
|
52
|
+
// * Create a new matrix and set its values (in row-major order)
|
|
53
|
+
// *
|
|
54
|
+
// * @param {number} [n11] 1-1 matrix value
|
|
55
|
+
// * @param {number} [n12] 1-2 matrix value
|
|
56
|
+
// * @param {number} [n13] 1-3 matrix value
|
|
57
|
+
// * @param {number} [n14] 1-4 matrix value
|
|
58
|
+
// * @param {number} [n21] 2-1 matrix value
|
|
59
|
+
// * @param {number} [n22] 2-2 matrix value
|
|
60
|
+
// * @param {number} [n23] 2-3 matrix value
|
|
61
|
+
// * @param {number} [n24] 2-4 matrix value
|
|
62
|
+
// * @param {number} [n31] 3-1 matrix value
|
|
63
|
+
// * @param {number} [n32] 3-2 matrix value
|
|
64
|
+
// * @param {number} [n33] 3-3 matrix value
|
|
65
|
+
// * @param {number} [n34] 3-4 matrix value
|
|
66
|
+
// * @param {number} [n41] 4-1 matrix value
|
|
67
|
+
// * @param {number} [n42] 4-2 matrix value
|
|
68
|
+
// * @param {number} [n43] 4-3 matrix value
|
|
69
|
+
// * @param {number} [n44] 4-4 matrix value
|
|
70
|
+
// */
|
|
71
|
+
// constructor(
|
|
72
|
+
// n11: number = IDENTITY_MATRIX_4[0],
|
|
73
|
+
// n12: number = IDENTITY_MATRIX_4[1],
|
|
74
|
+
// n13: number = IDENTITY_MATRIX_4[2],
|
|
75
|
+
// n14: number = IDENTITY_MATRIX_4[3],
|
|
76
|
+
// n21: number = IDENTITY_MATRIX_4[4],
|
|
77
|
+
// n22: number = IDENTITY_MATRIX_4[5],
|
|
78
|
+
// n23: number = IDENTITY_MATRIX_4[6],
|
|
79
|
+
// n24: number = IDENTITY_MATRIX_4[7],
|
|
80
|
+
// n31: number = IDENTITY_MATRIX_4[8],
|
|
81
|
+
// n32: number = IDENTITY_MATRIX_4[9],
|
|
82
|
+
// n33: number = IDENTITY_MATRIX_4[10],
|
|
83
|
+
// n34: number = IDENTITY_MATRIX_4[11],
|
|
84
|
+
// n41: number = IDENTITY_MATRIX_4[12],
|
|
85
|
+
// n42: number = IDENTITY_MATRIX_4[13],
|
|
86
|
+
// n43: number = IDENTITY_MATRIX_4[14],
|
|
87
|
+
// n44: number = IDENTITY_MATRIX_4[15]
|
|
88
|
+
// ) {
|
|
89
|
+
// this.set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44);
|
|
90
|
+
// }
|
|
91
|
+
// /**
|
|
92
|
+
// * Set this matrix values (in row-major order)
|
|
93
|
+
// *
|
|
94
|
+
// * @param {number} n11 1-1 matrix value
|
|
95
|
+
// * @param {number} n12 1-2 matrix value
|
|
96
|
+
// * @param {number} n13 1-3 matrix value
|
|
97
|
+
// * @param {number} n14 1-4 matrix value
|
|
98
|
+
// * @param {number} n21 2-1 matrix value
|
|
99
|
+
// * @param {number} n22 2-2 matrix value
|
|
100
|
+
// * @param {number} n23 2-3 matrix value
|
|
101
|
+
// * @param {number} n24 2-4 matrix value
|
|
102
|
+
// * @param {number} n31 3-1 matrix value
|
|
103
|
+
// * @param {number} n32 3-2 matrix value
|
|
104
|
+
// * @param {number} n33 3-3 matrix value
|
|
105
|
+
// * @param {number} n34 3-4 matrix value
|
|
106
|
+
// * @param {number} n41 4-1 matrix value
|
|
107
|
+
// * @param {number} n42 4-2 matrix value
|
|
108
|
+
// * @param {number} n43 4-3 matrix value
|
|
109
|
+
// * @param {number} n44 4-4 matrix value
|
|
110
|
+
// * @returns {this}
|
|
111
|
+
// */
|
|
112
|
+
// public set(
|
|
113
|
+
// n11: number,
|
|
114
|
+
// n12: number,
|
|
115
|
+
// n13: number,
|
|
116
|
+
// n14: number,
|
|
117
|
+
// n21: number,
|
|
118
|
+
// n22: number,
|
|
119
|
+
// n23: number,
|
|
120
|
+
// n24: number,
|
|
121
|
+
// n31: number,
|
|
122
|
+
// n32: number,
|
|
123
|
+
// n33: number,
|
|
124
|
+
// n34: number,
|
|
125
|
+
// n41: number,
|
|
126
|
+
// n42: number,
|
|
127
|
+
// n43: number,
|
|
128
|
+
// n44: number
|
|
129
|
+
// ): this {
|
|
130
|
+
// (this.values[0] = n11), (this.values[4] = n12), (this.values[8] = n13), (this.values[12] = n14);
|
|
131
|
+
// (this.values[1] = n21), (this.values[5] = n22), (this.values[9] = n23), (this.values[13] = n24);
|
|
132
|
+
// (this.values[2] = n31), (this.values[6] = n32), (this.values[10] = n33), (this.values[14] = n34);
|
|
133
|
+
// (this.values[3] = n41), (this.values[7] = n42), (this.values[11] = n43), (this.values[15] = n44);
|
|
134
|
+
// return this;
|
|
135
|
+
// }
|
|
136
|
+
// /**
|
|
137
|
+
// * Set this matrix to the 4x4 identity matrix
|
|
138
|
+
// *
|
|
139
|
+
// * @returns {this}
|
|
140
|
+
// */
|
|
141
|
+
// public identity(): this {
|
|
142
|
+
// return this.set(...IDENTITY_MATRIX_4);
|
|
143
|
+
// }
|
|
144
|
+
// /**
|
|
145
|
+
// * Set this matrix values from a given array
|
|
146
|
+
// *
|
|
147
|
+
// * @param {number[]} values Matrix values (in column-major order)
|
|
148
|
+
// * @returns {this}
|
|
149
|
+
// */
|
|
150
|
+
// public fromArray(values: number[]): this {
|
|
151
|
+
// for (let i = 0; i < 16; i++) {
|
|
152
|
+
// this.values[i] = values[i] ?? IDENTITY_MATRIX_4[i];
|
|
153
|
+
// }
|
|
154
|
+
// return this;
|
|
155
|
+
// }
|
|
156
|
+
// /**
|
|
157
|
+
// * Return this matrix values into an array (in column-major order)
|
|
158
|
+
// *
|
|
159
|
+
// * @returns {Matrix4x4}
|
|
160
|
+
// */
|
|
161
|
+
// public toArray(): Matrix4x4 {
|
|
162
|
+
// return [...this.values];
|
|
163
|
+
// }
|
|
164
|
+
// /**
|
|
165
|
+
// * Check if this matrix is equal with another given 4x4 matrix
|
|
166
|
+
// *
|
|
167
|
+
// * @param {Matrix4} matrix The matrix to test for equality
|
|
168
|
+
// * @returns {boolean}
|
|
169
|
+
// */
|
|
170
|
+
// public equals(matrix: Matrix4): boolean {
|
|
171
|
+
// for (let i = 0; i < 16; i++) {
|
|
172
|
+
// if (Math.abs(this.values[i] - matrix.values[i]) > EPSILON) return false;
|
|
173
|
+
// }
|
|
174
|
+
// return true;
|
|
175
|
+
// }
|
|
176
|
+
// /**
|
|
177
|
+
// * Post-multiply this matrix by a given 4x4 matrix
|
|
178
|
+
// *
|
|
179
|
+
// * @param {Matrix4} matrix The matrix to multiply with
|
|
180
|
+
// * @returns {this}
|
|
181
|
+
// */
|
|
182
|
+
// public multiply(matrix: Matrix4): this {
|
|
183
|
+
// return this.set(...Matrix4.multiplyMatrices(this, matrix));
|
|
184
|
+
// }
|
|
185
|
+
// /**
|
|
186
|
+
// * Pre-multiply this matrix by a given 4x4 matrix
|
|
187
|
+
// *
|
|
188
|
+
// * @param {Matrix4} matrix The matrix to multiply with
|
|
189
|
+
// * @returns {this}
|
|
190
|
+
// */
|
|
191
|
+
// public premultiply(matrix: Matrix4): this {
|
|
192
|
+
// return this.set(...Matrix4.multiplyMatrices(matrix, this));
|
|
193
|
+
// }
|
|
194
|
+
// /**
|
|
195
|
+
// * Multipliy all values of this matrix
|
|
196
|
+
// *
|
|
197
|
+
// * @param {number} s The scalar to multiply with
|
|
198
|
+
// * @returns {this}
|
|
199
|
+
// */
|
|
200
|
+
// public multiplyScalar(s: number): this {
|
|
201
|
+
// (this.values[0] *= s), (this.values[4] *= s), (this.values[8] *= s), (this.values[12] *= s);
|
|
202
|
+
// (this.values[1] *= s), (this.values[5] *= s), (this.values[9] *= s), (this.values[13] *= s);
|
|
203
|
+
// (this.values[2] *= s), (this.values[6] *= s), (this.values[10] *= s), (this.values[14] *= s);
|
|
204
|
+
// (this.values[3] *= s), (this.values[7] *= s), (this.values[11] *= s), (this.values[15] *= s);
|
|
205
|
+
// return this;
|
|
206
|
+
// }
|
|
207
|
+
// /**
|
|
208
|
+
// * Transpose this matrix
|
|
209
|
+
// *
|
|
210
|
+
// * @returns {this}
|
|
211
|
+
// */
|
|
212
|
+
// public transpose(): this {
|
|
213
|
+
// const values = [...this.values];
|
|
214
|
+
// (this.values[1] = values[4]), (this.values[4] = values[1]);
|
|
215
|
+
// (this.values[2] = values[8]), (this.values[8] = values[2]);
|
|
216
|
+
// (this.values[6] = values[9]), (this.values[9] = values[6]);
|
|
217
|
+
// (this.values[3] = values[12]), (this.values[12] = values[3]);
|
|
218
|
+
// (this.values[7] = values[13]), (this.values[13] = values[7]);
|
|
219
|
+
// (this.values[11] = values[14]), (this.values[14] = values[11]);
|
|
220
|
+
// return this;
|
|
221
|
+
// }
|
|
222
|
+
// // public invert() {}
|
|
223
|
+
// /**
|
|
224
|
+
// * Set the position values of this matrix
|
|
225
|
+
// *
|
|
226
|
+
// * @param {Vector3|Vector3D} vector Vector to set values from
|
|
227
|
+
// * @returns {this}
|
|
228
|
+
// */
|
|
229
|
+
// public setPosition([x, y, z]: Vector3 | Vector3D): this {
|
|
230
|
+
// this.values[12] = x;
|
|
231
|
+
// this.values[13] = y;
|
|
232
|
+
// this.values[14] = z;
|
|
233
|
+
// return this;
|
|
234
|
+
// }
|
|
235
|
+
// /**
|
|
236
|
+
// * Multiply the columns of this matrix
|
|
237
|
+
// *
|
|
238
|
+
// * @param {Vector3|Vector3D} vector Scale vector
|
|
239
|
+
// * @returns {this}
|
|
240
|
+
// */
|
|
241
|
+
// public scale([x, y, z]: Vector3 | Vector3D): this {
|
|
242
|
+
// (this.values[0] *= x), (this.values[4] *= y), (this.values[8] *= z);
|
|
243
|
+
// (this.values[1] *= x), (this.values[5] *= y), (this.values[9] *= z);
|
|
244
|
+
// (this.values[2] *= x), (this.values[6] *= y), (this.values[10] *= z);
|
|
245
|
+
// (this.values[3] *= x), (this.values[7] *= y), (this.values[11] *= z);
|
|
246
|
+
// return this;
|
|
247
|
+
// }
|
|
248
|
+
// /**
|
|
249
|
+
// * Set this matrix as a translation transformation
|
|
250
|
+
// *
|
|
251
|
+
// * @param {Vector3|Vector3D} vector Translation vector
|
|
252
|
+
// * @returns {this}
|
|
253
|
+
// */
|
|
254
|
+
// public makeTranslation([x, y, z]: Vector3 | Vector3D): this {
|
|
255
|
+
// // prettier-ignore
|
|
256
|
+
// return this.set(
|
|
257
|
+
// 1, 0, 0, x,
|
|
258
|
+
// 0, 1, 0, y,
|
|
259
|
+
// 0, 0, 1, z,
|
|
260
|
+
// 0, 0, 0, 1
|
|
261
|
+
// );
|
|
262
|
+
// }
|
|
263
|
+
// /**
|
|
264
|
+
// * Set this matrix as a rotational transformation around the X-axis
|
|
265
|
+
// *
|
|
266
|
+
// * @param {number} theta Rotation angle (in radians)
|
|
267
|
+
// * @returns {this}
|
|
268
|
+
// */
|
|
269
|
+
// public makeRotationX(theta: number): this {
|
|
270
|
+
// const cos = Math.cos(theta);
|
|
271
|
+
// const sin = Math.sin(theta);
|
|
272
|
+
// // prettier-ignore
|
|
273
|
+
// return this.set(
|
|
274
|
+
// 1, 0, 0, 0,
|
|
275
|
+
// 0, cos, -sin, 0,
|
|
276
|
+
// 0, sin, cos, 0,
|
|
277
|
+
// 0, 0, 0, 1,
|
|
278
|
+
// );
|
|
279
|
+
// }
|
|
280
|
+
// /**
|
|
281
|
+
// * Set this matrix as a rotational transformation around the Y-axis
|
|
282
|
+
// *
|
|
283
|
+
// * @param {number} theta Rotation angle (in radians)
|
|
284
|
+
// * @returns {this}
|
|
285
|
+
// */
|
|
286
|
+
// public makeRotationY(theta: number): this {
|
|
287
|
+
// const cos = Math.cos(theta);
|
|
288
|
+
// const sin = Math.sin(theta);
|
|
289
|
+
// // prettier-ignore
|
|
290
|
+
// return this.set(
|
|
291
|
+
// cos, 0, sin, 0,
|
|
292
|
+
// 0, 1, 0, 0,
|
|
293
|
+
// -sin, 0, cos, 0,
|
|
294
|
+
// 0, 0, 0, 1,
|
|
295
|
+
// );
|
|
296
|
+
// }
|
|
297
|
+
// /**
|
|
298
|
+
// * Set this matrix as a rotational transformation around the Z-axis
|
|
299
|
+
// *
|
|
300
|
+
// * @param {number} theta Rotation angle (in radians)
|
|
301
|
+
// * @returns {this}
|
|
302
|
+
// */
|
|
303
|
+
// public makeRotationZ(theta: number): this {
|
|
304
|
+
// const cos = Math.cos(theta);
|
|
305
|
+
// const sin = Math.sin(theta);
|
|
306
|
+
// // prettier-ignore
|
|
307
|
+
// return this.set(
|
|
308
|
+
// cos, -sin, 0, 0,
|
|
309
|
+
// sin, cos, 0, 0,
|
|
310
|
+
// 0, 0, 1, 0,
|
|
311
|
+
// 0, 0, 0, 1,
|
|
312
|
+
// );
|
|
313
|
+
// }
|
|
314
|
+
// /**
|
|
315
|
+
// * Set this matrix as a rotational transformation
|
|
316
|
+
// *
|
|
317
|
+
// * @param {Vector3|Vector3D} vector Rotation normalized vector
|
|
318
|
+
// * @param {number} angle Rotation angle (in radians)
|
|
319
|
+
// * @returns {this}
|
|
320
|
+
// */
|
|
321
|
+
// public makeRotationAxis([x, y, z]: Vector3 | Vector3D, angle: number): this {
|
|
322
|
+
// const cos = Math.cos(angle);
|
|
323
|
+
// const sin = Math.sin(angle);
|
|
324
|
+
// const t = 1 - cos;
|
|
325
|
+
// const tx = t * x;
|
|
326
|
+
// const ty = t * y;
|
|
327
|
+
// // prettier-ignore
|
|
328
|
+
// return this.set(
|
|
329
|
+
// tx * x + cos, tx * y - sin * z, tx * z + sin * y, 0,
|
|
330
|
+
// tx * y + sin * z, ty * y + cos, ty * z - sin * x, 0,
|
|
331
|
+
// tx * z - sin * y, ty * z + sin * x, t * z * z + cos, 0,
|
|
332
|
+
// 0, 0, 0, 1,
|
|
333
|
+
// );
|
|
334
|
+
// }
|
|
335
|
+
// /**
|
|
336
|
+
// * Set this matrix as a scale transformation
|
|
337
|
+
// *
|
|
338
|
+
// * @param {Vector3|Vector3D} vector Scale vector
|
|
339
|
+
// * @returns
|
|
340
|
+
// */
|
|
341
|
+
// public makeScale([x, y, z]: Vector3 | Vector3D): this {
|
|
342
|
+
// // prettier-ignore
|
|
343
|
+
// return this.set(
|
|
344
|
+
// x, 0, 0, 0,
|
|
345
|
+
// 0, y, 0, 0,
|
|
346
|
+
// 0, 0, z, 0,
|
|
347
|
+
// 0, 0, 0, 1,
|
|
348
|
+
// );
|
|
349
|
+
// }
|
|
350
|
+
// /**
|
|
351
|
+
// * Set this matrix as a shear transformation
|
|
352
|
+
// *
|
|
353
|
+
// * @param {number} xy The amount to shear X by Y
|
|
354
|
+
// * @param {number} xz The amount to shear X by Y
|
|
355
|
+
// * @param {number} yx The amount to shear X by Y
|
|
356
|
+
// * @param {number} yz The amount to shear X by Y
|
|
357
|
+
// * @param {number} zx The amount to shear X by Y
|
|
358
|
+
// * @param {number} zy The amount to shear X by Y
|
|
359
|
+
// * @returns {this}
|
|
360
|
+
// */
|
|
361
|
+
// public makeShear(xy: number, xz: number, yx: number, yz: number, zx: number, zy: number): this {
|
|
362
|
+
// // prettier-ignore
|
|
363
|
+
// return this.set(
|
|
364
|
+
// 1, yx, zx, 0,
|
|
365
|
+
// xy, 1, zy, 0,
|
|
366
|
+
// xz, yz, 1, 0,
|
|
367
|
+
// 0, 0, 0, 1,
|
|
368
|
+
// );
|
|
369
|
+
// }
|
|
370
|
+
// /**
|
|
371
|
+
// * Copy all values of a given matrix to this one
|
|
372
|
+
// *
|
|
373
|
+
// * @param {Matrix4} matrix Matrix to copy values from
|
|
374
|
+
// * @returns {this}
|
|
375
|
+
// */
|
|
376
|
+
// public copy(matrix: Matrix4): this {
|
|
377
|
+
// this.values[0] = matrix.values[0];
|
|
378
|
+
// this.values[1] = matrix.values[1];
|
|
379
|
+
// this.values[2] = matrix.values[2];
|
|
380
|
+
// this.values[3] = matrix.values[3];
|
|
381
|
+
// this.values[4] = matrix.values[4];
|
|
382
|
+
// this.values[5] = matrix.values[5];
|
|
383
|
+
// this.values[6] = matrix.values[6];
|
|
384
|
+
// this.values[7] = matrix.values[7];
|
|
385
|
+
// this.values[8] = matrix.values[8];
|
|
386
|
+
// this.values[9] = matrix.values[9];
|
|
387
|
+
// this.values[10] = matrix.values[10];
|
|
388
|
+
// this.values[11] = matrix.values[11];
|
|
389
|
+
// this.values[12] = matrix.values[12];
|
|
390
|
+
// this.values[13] = matrix.values[13];
|
|
391
|
+
// this.values[14] = matrix.values[14];
|
|
392
|
+
// this.values[15] = matrix.values[15];
|
|
393
|
+
// return this;
|
|
394
|
+
// }
|
|
395
|
+
// /**
|
|
396
|
+
// * Create a new matrix from this one
|
|
397
|
+
// *
|
|
398
|
+
// * @returns {Matrix4}
|
|
399
|
+
// */
|
|
400
|
+
// public clone(): Matrix4 {
|
|
401
|
+
// return new Matrix4().fromArray(this.values);
|
|
402
|
+
// }
|
|
403
|
+
// /**
|
|
404
|
+
// * Check if this matrix is equal to the 4x4 identity matrix
|
|
405
|
+
// *
|
|
406
|
+
// * @returns {boolean}
|
|
407
|
+
// */
|
|
408
|
+
// public isIdentity(): boolean {
|
|
409
|
+
// return this.equals(Matrix4.identity);
|
|
410
|
+
// }
|
|
411
|
+
// /**
|
|
412
|
+
// * Check if this matrix does not contain any 3D transformation
|
|
413
|
+
// *
|
|
414
|
+
// * @returns {boolean}
|
|
415
|
+
// */
|
|
416
|
+
// public is2D(): boolean {
|
|
417
|
+
// const { a, b, c, d, e, f } = this;
|
|
418
|
+
// // prettier-ignore
|
|
419
|
+
// return this.equals(
|
|
420
|
+
// new Matrix4(
|
|
421
|
+
// a, c, 0, e,
|
|
422
|
+
// b, d, 0, f,
|
|
423
|
+
// 0, 0, 1, 0,
|
|
424
|
+
// 0, 0, 0, 1
|
|
425
|
+
// )
|
|
426
|
+
// );
|
|
427
|
+
// }
|
|
428
|
+
// /**
|
|
429
|
+
// * Multiply given 4x4 matrices
|
|
430
|
+
// *
|
|
431
|
+
// * @param matrix1 The first matrix
|
|
432
|
+
// * @param matrix2 The second matrix
|
|
433
|
+
// * @returns {Matrix4x4} Matrix values (in row-major order)
|
|
434
|
+
// */
|
|
435
|
+
// static multiplyMatrices(matrix1: Matrix4, matrix2: Matrix4): Matrix4x4 {
|
|
436
|
+
// const m1 = matrix1.toArray();
|
|
437
|
+
// const m2 = matrix2.toArray();
|
|
438
|
+
// // prettier-ignore
|
|
439
|
+
// const
|
|
440
|
+
// a11 = m1[0], a12 = m1[4], a13 = m1[8], a14 = m1[12],
|
|
441
|
+
// a21 = m1[1], a22 = m1[5], a23 = m1[9], a24 = m1[13],
|
|
442
|
+
// a31 = m1[2], a32 = m1[6], a33 = m1[10], a34 = m1[14],
|
|
443
|
+
// a41 = m1[3], a42 = m1[7], a43 = m1[11], a44 = m1[15],
|
|
444
|
+
// b11 = m2[0], b12 = m2[4], b13 = m2[8], b14 = m2[12],
|
|
445
|
+
// b21 = m2[1], b22 = m2[5], b23 = m2[9], b24 = m2[13],
|
|
446
|
+
// b31 = m2[2], b32 = m2[6], b33 = m2[10], b34 = m2[14],
|
|
447
|
+
// b41 = m2[3], b42 = m2[7], b43 = m2[11], b44 = m2[15];
|
|
448
|
+
// const values: Matrix4x4 = [...IDENTITY_MATRIX_4];
|
|
449
|
+
// values[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
|
|
450
|
+
// values[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
|
|
451
|
+
// values[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
|
|
452
|
+
// values[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
|
|
453
|
+
// values[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
|
|
454
|
+
// values[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
|
|
455
|
+
// values[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
|
|
456
|
+
// values[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
|
|
457
|
+
// values[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
|
|
458
|
+
// values[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
|
|
459
|
+
// values[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
|
|
460
|
+
// values[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
|
|
461
|
+
// values[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
|
|
462
|
+
// values[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
|
|
463
|
+
// values[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
|
|
464
|
+
// values[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
|
|
465
|
+
// return values;
|
|
466
|
+
// }
|
|
467
|
+
// /**
|
|
468
|
+
// * n11, n12, n13, n14
|
|
469
|
+
// * n21, n22, n23, n24
|
|
470
|
+
// * n31, n32, n33, n34
|
|
471
|
+
// * n41, n42, n43, n44
|
|
472
|
+
// */
|
|
473
|
+
// get n11(): number {
|
|
474
|
+
// return this.values[0];
|
|
475
|
+
// }
|
|
476
|
+
// get n12(): number {
|
|
477
|
+
// return this.values[1];
|
|
478
|
+
// }
|
|
479
|
+
// get n13(): number {
|
|
480
|
+
// return this.values[2];
|
|
481
|
+
// }
|
|
482
|
+
// get n14(): number {
|
|
483
|
+
// return this.values[3];
|
|
484
|
+
// }
|
|
485
|
+
// get n21(): number {
|
|
486
|
+
// return this.values[4];
|
|
487
|
+
// }
|
|
488
|
+
// get n22(): number {
|
|
489
|
+
// return this.values[5];
|
|
490
|
+
// }
|
|
491
|
+
// get n23(): number {
|
|
492
|
+
// return this.values[6];
|
|
493
|
+
// }
|
|
494
|
+
// get n24(): number {
|
|
495
|
+
// return this.values[7];
|
|
496
|
+
// }
|
|
497
|
+
// get n31(): number {
|
|
498
|
+
// return this.values[8];
|
|
499
|
+
// }
|
|
500
|
+
// get n32(): number {
|
|
501
|
+
// return this.values[9];
|
|
502
|
+
// }
|
|
503
|
+
// get n33(): number {
|
|
504
|
+
// return this.values[10];
|
|
505
|
+
// }
|
|
506
|
+
// get n34(): number {
|
|
507
|
+
// return this.values[11];
|
|
508
|
+
// }
|
|
509
|
+
// get n41(): number {
|
|
510
|
+
// return this.values[12];
|
|
511
|
+
// }
|
|
512
|
+
// get n42(): number {
|
|
513
|
+
// return this.values[13];
|
|
514
|
+
// }
|
|
515
|
+
// get n43(): number {
|
|
516
|
+
// return this.values[14];
|
|
517
|
+
// }
|
|
518
|
+
// get n44(): number {
|
|
519
|
+
// return this.values[15];
|
|
520
|
+
// }
|
|
521
|
+
// /**
|
|
522
|
+
// * m11, m21, m31, m41
|
|
523
|
+
// * m12, m22, m32, m42
|
|
524
|
+
// * m13, m23, m33, m43
|
|
525
|
+
// * m14, m24, m34, m44
|
|
526
|
+
// */
|
|
527
|
+
// get m11(): number {
|
|
528
|
+
// return this.values[0];
|
|
529
|
+
// }
|
|
530
|
+
// get m21(): number {
|
|
531
|
+
// return this.values[1];
|
|
532
|
+
// }
|
|
533
|
+
// get m31(): number {
|
|
534
|
+
// return this.values[2];
|
|
535
|
+
// }
|
|
536
|
+
// get m41(): number {
|
|
537
|
+
// return this.values[3];
|
|
538
|
+
// }
|
|
539
|
+
// get m12(): number {
|
|
540
|
+
// return this.values[4];
|
|
541
|
+
// }
|
|
542
|
+
// get m22(): number {
|
|
543
|
+
// return this.values[5];
|
|
544
|
+
// }
|
|
545
|
+
// get m32(): number {
|
|
546
|
+
// return this.values[6];
|
|
547
|
+
// }
|
|
548
|
+
// get m42(): number {
|
|
549
|
+
// return this.values[7];
|
|
550
|
+
// }
|
|
551
|
+
// get m13(): number {
|
|
552
|
+
// return this.values[8];
|
|
553
|
+
// }
|
|
554
|
+
// get m23(): number {
|
|
555
|
+
// return this.values[9];
|
|
556
|
+
// }
|
|
557
|
+
// get m33(): number {
|
|
558
|
+
// return this.values[10];
|
|
559
|
+
// }
|
|
560
|
+
// get m43(): number {
|
|
561
|
+
// return this.values[11];
|
|
562
|
+
// }
|
|
563
|
+
// get m14(): number {
|
|
564
|
+
// return this.values[12];
|
|
565
|
+
// }
|
|
566
|
+
// get m24(): number {
|
|
567
|
+
// return this.values[13];
|
|
568
|
+
// }
|
|
569
|
+
// get m34(): number {
|
|
570
|
+
// return this.values[14];
|
|
571
|
+
// }
|
|
572
|
+
// get m44(): number {
|
|
573
|
+
// return this.values[15];
|
|
574
|
+
// }
|
|
575
|
+
// /**
|
|
576
|
+
// * a, b | a, c, 0, e
|
|
577
|
+
// * c, d | b, d, 0, f
|
|
578
|
+
// * 0, 0 |
|
|
579
|
+
// * e, f |
|
|
580
|
+
// */
|
|
581
|
+
// get a(): number {
|
|
582
|
+
// return this.n11;
|
|
583
|
+
// }
|
|
584
|
+
// get b(): number {
|
|
585
|
+
// return this.n12;
|
|
586
|
+
// }
|
|
587
|
+
// get c(): number {
|
|
588
|
+
// return this.n21;
|
|
589
|
+
// }
|
|
590
|
+
// get d(): number {
|
|
591
|
+
// return this.n22;
|
|
592
|
+
// }
|
|
593
|
+
// get e(): number {
|
|
594
|
+
// return this.n41;
|
|
595
|
+
// }
|
|
596
|
+
// get f(): number {
|
|
597
|
+
// return this.n42;
|
|
598
|
+
// }
|
|
599
|
+
// get translateX(): number {
|
|
600
|
+
// return this.e;
|
|
601
|
+
// }
|
|
602
|
+
// get translateY(): number {
|
|
603
|
+
// return this.f;
|
|
604
|
+
// }
|
|
605
|
+
// get scaleX(): number {
|
|
606
|
+
// return Math.hypot(this.a, this.b);
|
|
607
|
+
// }
|
|
608
|
+
// get scaleY(): number {
|
|
609
|
+
// return Math.hypot(this.c, this.d);
|
|
610
|
+
// }
|
|
611
|
+
// get rotationXY(): number {
|
|
612
|
+
// return Math.atan2(this.b, this.a);
|
|
613
|
+
// }
|
|
614
|
+
// *[Symbol.iterator](): Iterator<number> {
|
|
615
|
+
// yield this.n11;
|
|
616
|
+
// yield this.n12;
|
|
617
|
+
// yield this.n13;
|
|
618
|
+
// yield this.n14;
|
|
619
|
+
// yield this.n21;
|
|
620
|
+
// yield this.n22;
|
|
621
|
+
// yield this.n23;
|
|
622
|
+
// yield this.n24;
|
|
623
|
+
// yield this.n31;
|
|
624
|
+
// yield this.n32;
|
|
625
|
+
// yield this.n33;
|
|
626
|
+
// yield this.n34;
|
|
627
|
+
// yield this.n41;
|
|
628
|
+
// yield this.n42;
|
|
629
|
+
// yield this.n43;
|
|
630
|
+
// yield this.n44;
|
|
631
|
+
// }
|
|
632
|
+
// }
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export interface Vector<V = any> {
|
|
2
|
+
set(...values: number[]): this;
|
|
3
|
+
setScalar(scalar: number): this;
|
|
4
|
+
setValue(index: string | number, value: number): this;
|
|
5
|
+
getValue(index: string | number): number;
|
|
6
|
+
add(vector: V): this;
|
|
7
|
+
addScalar(scalar: number): this;
|
|
8
|
+
sub(vector: V): this;
|
|
9
|
+
subScalar(scalar: number): this;
|
|
10
|
+
multiply(vector: V): this;
|
|
11
|
+
multiplyScalar(scalar: number): this;
|
|
12
|
+
divide(vector: V): this;
|
|
13
|
+
divideScalar(scalar: number): this;
|
|
14
|
+
min(vector: V): this;
|
|
15
|
+
max(vector: V): this;
|
|
16
|
+
clamp(min: V, max: V): this;
|
|
17
|
+
clampScalar(min: number, max: number): this;
|
|
18
|
+
floor(): this;
|
|
19
|
+
ceil(): this;
|
|
20
|
+
round(): this;
|
|
21
|
+
trunc(): this;
|
|
22
|
+
negate(): this;
|
|
23
|
+
lerp(vector: V, t: number): this;
|
|
24
|
+
normalize(): this;
|
|
25
|
+
setLength(length: number): this;
|
|
26
|
+
length(): number;
|
|
27
|
+
squaredLength(): number;
|
|
28
|
+
manhattanLength(): number;
|
|
29
|
+
equals(vector: V): boolean;
|
|
30
|
+
collinear(vector1: V, vector2: V): boolean;
|
|
31
|
+
dot(vector: V): number;
|
|
32
|
+
cross(vector: V): number | number[];
|
|
33
|
+
angleTo(vector: V): number;
|
|
34
|
+
distanceTo(vector: V): number;
|
|
35
|
+
squaredDistanceTo(vector: V): number;
|
|
36
|
+
manhattanDistanceTo(vector: V): number;
|
|
37
|
+
toArray(): number[];
|
|
38
|
+
fromArray(values: number[]): this;
|
|
39
|
+
copy(vector: V): this;
|
|
40
|
+
clone(): V;
|
|
41
|
+
[Symbol.iterator](): Iterator<number>;
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|