toosoon-utils 4.1.9 → 4.2.1

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.
Files changed (65) hide show
  1. package/README.md +97 -885
  2. package/lib/constants.d.ts +0 -1
  3. package/lib/constants.js +3 -1
  4. package/lib/extras/color-scale/ColorScale.d.ts +2 -2
  5. package/lib/extras/color-scale/ColorScale.js +2 -2
  6. package/lib/extras/curves/ArcCurve.d.ts +3 -3
  7. package/lib/extras/curves/ArcCurve.js +5 -4
  8. package/lib/extras/curves/CatmullRomCurve.d.ts +20 -5
  9. package/lib/extras/curves/CatmullRomCurve.js +23 -5
  10. package/lib/extras/curves/CatmullRomCurve3.d.ts +101 -0
  11. package/lib/extras/curves/CatmullRomCurve3.js +122 -0
  12. package/lib/extras/curves/CubicBezierCurve.d.ts +20 -5
  13. package/lib/extras/curves/CubicBezierCurve.js +23 -5
  14. package/lib/extras/curves/CubicBezierCurve3.d.ts +101 -0
  15. package/lib/extras/curves/CubicBezierCurve3.js +122 -0
  16. package/lib/extras/curves/Curve.d.ts +23 -24
  17. package/lib/extras/curves/Curve.js +19 -26
  18. package/lib/extras/curves/EllipseCurve.d.ts +25 -9
  19. package/lib/extras/curves/EllipseCurve.js +64 -15
  20. package/lib/extras/curves/LineCurve.d.ts +34 -10
  21. package/lib/extras/curves/LineCurve.js +35 -13
  22. package/lib/extras/curves/LineCurve3.d.ts +87 -0
  23. package/lib/extras/curves/LineCurve3.js +108 -0
  24. package/lib/extras/curves/PolylineCurve.d.ts +9 -8
  25. package/lib/extras/curves/PolylineCurve.js +6 -6
  26. package/lib/extras/curves/PolylineCurve3.d.ts +28 -0
  27. package/lib/extras/curves/PolylineCurve3.js +39 -0
  28. package/lib/extras/curves/QuadraticBezierCurve.d.ts +19 -5
  29. package/lib/extras/curves/QuadraticBezierCurve.js +22 -5
  30. package/lib/extras/curves/QuadraticBezierCurve3.d.ts +84 -0
  31. package/lib/extras/curves/QuadraticBezierCurve3.js +102 -0
  32. package/lib/extras/curves/SplineCurve.d.ts +12 -8
  33. package/lib/extras/curves/SplineCurve.js +9 -6
  34. package/lib/extras/curves/SplineCurve3.d.ts +28 -0
  35. package/lib/extras/curves/SplineCurve3.js +41 -0
  36. package/lib/extras/curves/index.d.ts +6 -0
  37. package/lib/extras/curves/index.js +6 -0
  38. package/lib/extras/geometry/Matrix2.d.ts +1 -0
  39. package/lib/extras/geometry/Matrix2.js +230 -0
  40. package/lib/extras/geometry/Matrix4.d.ts +1 -0
  41. package/lib/extras/geometry/Matrix4.js +632 -0
  42. package/lib/extras/geometry/Vector.d.ts +42 -0
  43. package/lib/extras/geometry/Vector.js +1 -0
  44. package/lib/extras/geometry/Vector2.d.ts +480 -0
  45. package/lib/extras/geometry/Vector2.js +709 -0
  46. package/lib/extras/geometry/Vector3.d.ts +486 -0
  47. package/lib/extras/geometry/Vector3.js +765 -0
  48. package/lib/extras/geometry/index.d.ts +3 -0
  49. package/lib/extras/geometry/index.js +2 -0
  50. package/lib/extras/paths/Path.d.ts +24 -18
  51. package/lib/extras/paths/Path.js +48 -35
  52. package/lib/extras/paths/PathContext.d.ts +97 -67
  53. package/lib/extras/paths/PathContext.js +326 -183
  54. package/lib/extras/paths/PathSVG.d.ts +43 -31
  55. package/lib/extras/paths/PathSVG.js +69 -56
  56. package/lib/extras/paths/index.d.ts +1 -1
  57. package/lib/geometry.d.ts +0 -135
  58. package/lib/geometry.js +1 -219
  59. package/lib/maths.d.ts +54 -22
  60. package/lib/maths.js +77 -27
  61. package/lib/random.d.ts +12 -16
  62. package/lib/random.js +19 -27
  63. package/lib/tsconfig.tsbuildinfo +1 -1
  64. package/lib/types.d.ts +43 -1
  65. package/package.json +2 -1
@@ -0,0 +1,486 @@
1
+ import type { Point3 } from '../../types';
2
+ import type { Vector } from './Vector';
3
+ type Vec3 = Vector3 | Point3;
4
+ /**
5
+ * Utility class for manipulating a 3D vectors
6
+ *
7
+ * @exports
8
+ * @class Vector3
9
+ * @implements Vector
10
+ */
11
+ export default class Vector3 implements Vector<Vec3> {
12
+ readonly isVector3 = true;
13
+ readonly type: string;
14
+ /**
15
+ * X-axis value of this vector
16
+ */
17
+ x: number;
18
+ /**
19
+ * Y-axis value of this vector
20
+ */
21
+ y: number;
22
+ /**
23
+ * Z-axis value of this vector
24
+ */
25
+ z: number;
26
+ /**
27
+ * @param {number} [x=0] X-axis value
28
+ * @param {number} [y=0] Y-axis value
29
+ * @param {number} [z=0] Z-axis value
30
+ */
31
+ constructor(x?: number, y?: number, z?: number);
32
+ /**
33
+ * Set this vector values
34
+ *
35
+ * @param {number} x X-axis value
36
+ * @param {number} y Y-axis value
37
+ * @param {number} z Z-axis value
38
+ * @returns {this}
39
+ */
40
+ set(x: number, y: number, z: number): this;
41
+ /**
42
+ * Set a given scalar value to all values of this vector
43
+ *
44
+ * @param {number} scalar Value to set for all vector values
45
+ * @returns {this}
46
+ */
47
+ setScalar(scalar: number): this;
48
+ /**
49
+ * Set this vector X-axis value
50
+ *
51
+ * @param {number} x X-axis value to set
52
+ * @returns {this}
53
+ */
54
+ setX(x: number): this;
55
+ /**
56
+ * Set this vector Y-axis value
57
+ *
58
+ * @param {number} y Y-axis value to set
59
+ * @returns {this}
60
+ */
61
+ setY(y: number): this;
62
+ /**
63
+ * Set this vector Z-axis value
64
+ *
65
+ * @param {number} z Z-axis value to set
66
+ * @returns {this}
67
+ */
68
+ setZ(z: number): this;
69
+ /**
70
+ * Set a given value of this vector
71
+ *
72
+ * @param {string|number} index `0` equals to `x`, `1` equals to `y`, `2` equals to `z`
73
+ * @param {number} value Value to set
74
+ * @returns {this}
75
+ */
76
+ setValue(index: 'x' | 'y' | 'z' | number, value: number): this;
77
+ /**
78
+ * Return a value from the vector
79
+ *
80
+ * @param {string|number} index `0` equals to `x`, `1` equals to `y`, `2` equals to `z`
81
+ * @returns {number}
82
+ */
83
+ getValue(index: 'x' | 'y' | 'z' | number): number;
84
+ /**
85
+ * Add a given vector to this vector
86
+ *
87
+ * @param {Vector3|Point3} vector Vector to add
88
+ * @returns {this}
89
+ */
90
+ add([x, y, z]: Vec3): this;
91
+ /**
92
+ * Add a given scalar value to all values of this vector
93
+ *
94
+ * @param {number} scalar Scalar value to add
95
+ * @returns {this}
96
+ */
97
+ addScalar(scalar: number): this;
98
+ /**
99
+ * Subtract a given vector to this vector
100
+ *
101
+ * @param {Vector3|Point3} vector Vector to subtract
102
+ * @returns {this}
103
+ */
104
+ sub([x, y, z]: Vec3): this;
105
+ /**
106
+ * Subtract a given scalar value to all values of this vector
107
+ *
108
+ * @param {number} scalar Scalar value to subtract
109
+ * @returns {this}
110
+ */
111
+ subScalar(scalar: number): this;
112
+ /**
113
+ * Multiply a given vector to this vector
114
+ *
115
+ * @param {Vector3|Point3} vector Vector to multiply
116
+ * @returns {this}
117
+ */
118
+ multiply([x, y, z]: Vec3): this;
119
+ /**
120
+ * Multiply a given scalar value to all values of this vector
121
+ *
122
+ * @param {number} scalar Scalar value to multiply
123
+ * @returns {this}
124
+ */
125
+ multiplyScalar(scalar: number): this;
126
+ /**
127
+ * Divide a given vector to this vector
128
+ *
129
+ * @param {Vector3|Point3} vector Vector to divide
130
+ * @returns {this}
131
+ */
132
+ divide([x, y, z]: Vec3): this;
133
+ /**
134
+ * Divide a given scalar value to all values of this vector
135
+ *
136
+ * @param {number} scalar Scalar value to multiply
137
+ * @returns {this}
138
+ */
139
+ divideScalar(scalar: number): this;
140
+ /**
141
+ * Set this vector values to the min values compared to a given vector
142
+ *
143
+ * @param {Vector3|Point3} vector Vector to compare values with
144
+ * @returns {this}
145
+ */
146
+ min([x, y, z]: Vec3): this;
147
+ /**
148
+ * Set this vector values to the max values compared to a given vector
149
+ *
150
+ * @param {Vector3|Point3} vector Vector to compare values with
151
+ * @returns {this}
152
+ */
153
+ max([x, y, z]: Vec3): this;
154
+ /**
155
+ * Clamp this vector values to given boundaries
156
+ *
157
+ * @param {Vector3|Point3} min Minimum boundaries
158
+ * @param {Vector3|Point3} max Maximum boundaries
159
+ * @returns {this}
160
+ */
161
+ clamp([minX, minY, minZ]: Vec3, [maxX, maxY, maxZ]: Vec3): this;
162
+ /**
163
+ * Clamp this vector values to given scalar values
164
+ *
165
+ * @param {Vector3|Point3} min Minimum scalar boundary
166
+ * @param {Vector3|Point3} max Maximum scalar boundary
167
+ * @returns {this}
168
+ */
169
+ clampScalar(min: number, max: number): this;
170
+ /**
171
+ * Round down to the nearest integer value this vector values
172
+ *
173
+ * @returns {this}
174
+ */
175
+ floor(): this;
176
+ /**
177
+ * Round up to the nearest integer value this vector values
178
+ *
179
+ * @returns {this}
180
+ */
181
+ ceil(): this;
182
+ /**
183
+ * Round to the nearest integer value this vector values
184
+ *
185
+ * @returns {this}
186
+ */
187
+ round(): this;
188
+ /**
189
+ * Remove any fractional digits of this vector values
190
+ *
191
+ * @returns {this}
192
+ */
193
+ trunc(): this;
194
+ /**
195
+ * Set this vector values to their negative values
196
+ *
197
+ * @returns {this}
198
+ */
199
+ negate(): this;
200
+ /**
201
+ * Interpolate this vector values between a given vector and this vector
202
+ *
203
+ * @param {Vector3|Point3} vector Vector to interpolate values towards
204
+ * @param {number} t Normalized time value to interpolate
205
+ * @returns {this}
206
+ */
207
+ lerp([x, y, z]: Vec3, t: number): this;
208
+ /**
209
+ * Convert this vector to a unit vector
210
+ *
211
+ * @returns {this}
212
+ */
213
+ normalize(): this;
214
+ /**
215
+ * Set this vector values to the same direction but with a given length
216
+ *
217
+ * @param {number} length Length value
218
+ * @returns {this}
219
+ */
220
+ setLength(length: number): this;
221
+ /**
222
+ * Project this vector onto a given vector
223
+ *
224
+ * @param {Vector3|Point3} vector Vector to project to
225
+ * @returns {this}
226
+ */
227
+ projectOnVector(vector: Vec3): this;
228
+ /**
229
+ * Calculate the Euclidean length of this vector
230
+ *
231
+ * @returns {number} Computed Euclidean length
232
+ */
233
+ length(): number;
234
+ /**
235
+ * Calculate the squared length of this vector
236
+ *
237
+ * @return {number} Computed squared length
238
+ */
239
+ squaredLength(): number;
240
+ /**
241
+ * Calculate the Manhattan length of this vector
242
+ *
243
+ * @return {number} Computed Manhattan length
244
+ */
245
+ manhattanLength(): number;
246
+ /**
247
+ * Check if this vector is equal with a given vector
248
+ *
249
+ * @param {Vector3|Point3} vector Vector to check
250
+ * @returns {boolean} True if this vector is equal with the given vector, false otherwise
251
+ */
252
+ equals(vector: Vec3): boolean;
253
+ /**
254
+ * Check if this vector is collinear with a given vectors
255
+ *
256
+ * @param {Vector3|Point3} vector1 First vector to check
257
+ * @param {Vector3|Point3} vector2 Second vector to check
258
+ * @returns {boolean} True if this vector is collinear with the given vectors, false otherwise
259
+ */
260
+ collinear(vector1: Vec3, vector2: Vec3): boolean;
261
+ /**
262
+ * Calculate the dot product of a given vector with this vector
263
+ *
264
+ * @param {Vector3|Point3} vector Vector to compute the dot product with
265
+ * @returns {number} Computed dot product
266
+ */
267
+ dot(vector: Vec3): number;
268
+ /**
269
+ * Calculate the cross product of a given vector with this vector
270
+ *
271
+ * @param {Vector3|Point3} vector Vector to compute the cross product with
272
+ * @returns {Point3} Computed cross product
273
+ */
274
+ cross(vector: Vec3): Point3;
275
+ /**
276
+ * Calculate the angle between a given vector and this vector
277
+ *
278
+ * @param {Vector3|Point3} vector Vector to compute the angle with
279
+ * @returns {number} Computed angle (in radians)
280
+ */
281
+ angleTo(vector: Vec3): number;
282
+ /**
283
+ * Calculate the Euclidean distance from a given vector to this vector
284
+ *
285
+ * @param {Vector3|Point3} vector Vector to compute the distance to
286
+ * @returns {number} Computed Euclidean distance
287
+ */
288
+ distanceTo(vector: Vec3): number;
289
+ /**
290
+ * Calculate the squared distance from a given vector to this vector
291
+ *
292
+ * @param {Vector3|Point3} vector Vector to compute the squared distance to
293
+ * @returns {number} Computed squared distance
294
+ */
295
+ squaredDistanceTo(vector: Vec3): number;
296
+ /**
297
+ * Calculate the Manhattan distance from a given vector to this vector
298
+ *
299
+ * @param {Vector3|Point3} vector Vector to compute the Manhattan distance to
300
+ * @returns {number} Computed Manhattan distance
301
+ */
302
+ manhattanDistanceTo(vector: Vec3): number;
303
+ /**
304
+ * Return this vector values into an array
305
+ *
306
+ * @returns {Point3}
307
+ */
308
+ toArray(): Point3;
309
+ /**
310
+ * Set this vector values from a given array
311
+ *
312
+ * @param {number[]} values Values to set
313
+ * @returns
314
+ */
315
+ fromArray([x, y, z]: number[]): this;
316
+ /**
317
+ * Set this vector values from given spherical coordinates
318
+ *
319
+ * @param {number} radius Radius of the sphere
320
+ * @param {number} phi Polar angle from the y (up) axis : [0, PI]
321
+ * @param {number} theta Equator angle around the y (up) axis : [0, 2*PI]
322
+ * @returns {this}
323
+ */
324
+ fromSphericalCoords(radius: number, phi: number, theta: number): this;
325
+ /**
326
+ * Set this vector values from given cylindrical coordinates
327
+ *
328
+ * @param {number} radius Radius of the cylinder
329
+ * @param {number} theta Equator angle around the y (up) axis : [0, 2*PI]
330
+ * @param {number} y Y-axis value
331
+ * @returns {this}
332
+ */
333
+ fromCylindricalCoords(radius: number, theta: number, y: number): this;
334
+ /**
335
+ * Copy the values of a given vector to this vector
336
+ *
337
+ * @param {Vector3|Point3} vector Vector to copy values from
338
+ * @returns {this}
339
+ */
340
+ copy([x, y, z]: Vec3): this;
341
+ /**
342
+ * Create a new 3D vector with copied values from this vector
343
+ *
344
+ * @returns {Vector3}
345
+ */
346
+ clone(): Vector3;
347
+ /**
348
+ * Add two vectors
349
+ *
350
+ * @param {Vector3|Point3} vector1 First vector
351
+ * @param {Vector3|Point3} vector2 Second vector
352
+ * @returns {Point3}
353
+ */
354
+ static add([x1, y1, z1]: Vec3, [x2, y2, z2]: Vec3): Point3;
355
+ /**
356
+ * Subtract two vectors
357
+ *
358
+ * @param {Vector3|Point3} vector1 First vector
359
+ * @param {Vector3|Point3} vector2 Second vector
360
+ * @returns {Point3}
361
+ */
362
+ static sub([x1, y1, z1]: Vec3, [x2, y2, z2]: Vec3): Point3;
363
+ /**
364
+ * Multiply two vectors
365
+ *
366
+ * @param {Vector3|Point3} vector1 First vector
367
+ * @param {Vector3|Point3} vector2 Second vector
368
+ * @returns {Point3}
369
+ */
370
+ static multiply([x1, y1, z1]: Vec3, [x2, y2, z2]: Vec3): Point3;
371
+ /**
372
+ * Divide two vectors
373
+ *
374
+ * @param {Vector3|Point3} vector1 First vector
375
+ * @param {Vector3|Point3} vector2 Second vector
376
+ * @returns {Point3}
377
+ */
378
+ static divide([x1, y1, z1]: Vec3, [x2, y2, z2]: Vec3): Point3;
379
+ /**
380
+ * Interpolate a point between two vectors
381
+ *
382
+ * @param {number} t Normalized time value to interpolate
383
+ * @param {Vector3|Point3} min Minimum boundaries
384
+ * @param {Vector3|Point3} max Maximum boundaries
385
+ * @returns {Point3}
386
+ */
387
+ static lerp(t: number, [x1, y1, z1]: Vec3, [x2, y2, z2]: Vec3): Point3;
388
+ /**
389
+ * Check if two vectors are equal to each other
390
+ *
391
+ * @param {Vector3|Point3} vector1 First vector
392
+ * @param {Vector3|Point3} vector2 Second vector
393
+ * @returns {boolean} True if the given vectors are equal, false otherwise
394
+ */
395
+ static equals([x1, y1, z1]: Vec3, [x2, y2, z2]: Vec3): boolean;
396
+ /**
397
+ * Check if three vectors are collinear (aligned on the same line)
398
+ *
399
+ * @param {Vector3|Point3} vector1 First vector
400
+ * @param {Vector3|Point3} vector2 Second vector
401
+ * @param {Vector3|Point3} vector3 Third vector
402
+ * @returns {boolean} True if the given vectors are collinear, false otherwise
403
+ */
404
+ static collinear([x1, y1, z1]: Vec3, [x2, y2, z2]: Vec3, [x3, y3, z3]: Vec3): boolean;
405
+ /**
406
+ * Calculate the dot product of two vectors
407
+ *
408
+ * @param {Vector3|Point3} vector1 First vector
409
+ * @param {Vector3|Point3} vector2 Second vector
410
+ * @returns {number} Computed dot product
411
+ */
412
+ static dot([x1, y1, z1]: Vec3, [x2, y2, z2]: Vec3): number;
413
+ /**
414
+ * Calculate the cross product of two vectors
415
+ *
416
+ * @param {Vector3|Point3} vector1 First vector
417
+ * @param {Vector3|Point3} vector2 Second vector
418
+ * @returns {Point3} Computed cross product
419
+ */
420
+ static cross([x1, y1, z1]: Vec3, [x2, y2, z2]: Vec3): Point3;
421
+ /**
422
+ * Calculate the Euclidean distance between two vectors
423
+ *
424
+ * @param {Vector3|Point3} vector1 First vector
425
+ * @param {Vector3|Point3} vector2 Second vector
426
+ * @returns {number} Computed Euclidean distance
427
+ */
428
+ static distance(vector1: Vec3, vector2: Vec3): number;
429
+ /**
430
+ * Calculate the squared distance between two vectors
431
+ *
432
+ * @param {Vector3|Point3} vector1 First vector
433
+ * @param {Vector3|Point3} vector2 Second vector
434
+ * @returns {number} Computed squared distance
435
+ */
436
+ static squaredDistance([x1, y1, z1]: Vec3, [x2, y2, z2]: Vec3): number;
437
+ /**
438
+ * Calculate the Manhattan distance between two vectors
439
+ *
440
+ * @param {Vector3|Point3} vector1 First vector
441
+ * @param {Vector3|Point3} vector2 Second vector
442
+ * @return {number} Computed Manhattan distance
443
+ */
444
+ static manhattanDistance([x1, y1, z1]: Vec3, [x2, y2, z2]: Vec3): number;
445
+ /**
446
+ * Calculate the Euclidean length of a vector
447
+ *
448
+ * @param {Vector3|Point3} vector Vector to compute Euclidean length from
449
+ * @returns {number} Computed Euclidean length
450
+ */
451
+ static length(vector: Vec3): number;
452
+ /**
453
+ * Calculate the squared length of a vector
454
+ *
455
+ * @param {Vector3|Point3} vector Vector to compute squared length from
456
+ * @returns {number} Computed squared length
457
+ */
458
+ static squaredLength([x, y, z]: Vec3): number;
459
+ /**
460
+ * Calculate the Manhattan length of a vector
461
+ *
462
+ * @param {Vector3|Point3} vector Vector to compute Manhattan length from
463
+ * @return {number} Computed Manhattan length
464
+ */
465
+ static manhattanLength([x, y, z]: Vec3): number;
466
+ /**
467
+ * Convert spherical coordinates to a 3D point on the surface of a sphere
468
+ *
469
+ * @param {number} phi Polar angle from the y (up) axis : [0, PI]
470
+ * @param {number} theta Equator angle around the y (up) axis : [0, 2*PI]
471
+ * @param {number} [radius=1] Radius of the sphere
472
+ * @returns {Point3}
473
+ */
474
+ static fromSphericalCoords(phi: number, theta: number, radius?: number): Point3;
475
+ /**
476
+ * Convert cylindrical coordinates to a 3D point on the surface of a cylinder
477
+ *
478
+ * @param {number} theta Equator angle around the y (up) axis : [0, 2*PI]
479
+ * @param {number} y Y-axis value
480
+ * @param {number} [radius=1] Radius of the cylinder
481
+ * @returns {Point3}
482
+ */
483
+ static fromCylindricalCoords(theta: number, y: number, radius?: number): Point3;
484
+ [Symbol.iterator](): Iterator<number>;
485
+ }
486
+ export {};