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