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
@@ -4,7 +4,6 @@ export declare const TWO_PI: number;
4
4
  export declare const TAU: number;
5
5
  export declare const HALF_PI: number;
6
6
  export declare const QUARTER_PI: number;
7
- export declare const TAU_EPSILON: number;
8
7
  export declare const W3CX11: {
9
8
  aliceblue: number;
10
9
  antiquewhite: number;
package/lib/constants.js CHANGED
@@ -2,12 +2,14 @@
2
2
  // Maths
3
3
  // *********************
4
4
  export const EPSILON = 1e-10;
5
+ // *********************
6
+ // Geometry
7
+ // *********************
5
8
  export const PI = Math.PI;
6
9
  export const TWO_PI = PI * 2;
7
10
  export const TAU = PI * 2;
8
11
  export const HALF_PI = PI / 2;
9
12
  export const QUARTER_PI = PI / 4;
10
- export const TAU_EPSILON = TAU - EPSILON;
11
13
  // *********************
12
14
  // Colors
13
15
  // *********************
@@ -40,7 +40,7 @@ export default class ColorScale {
40
40
  */
41
41
  constructor(input: ColorRepresentation, target: ColorRepresentation, length?: number, settings?: ColorScaleSettings);
42
42
  /**
43
- * Static method for generating a color scale
43
+ * Generate a color scale
44
44
  *
45
45
  * @param {ColorRepresentation} input Input color representation
46
46
  * @param {ColorRepresentation} target Target color representation
@@ -50,7 +50,7 @@ export default class ColorScale {
50
50
  */
51
51
  static generate(input: ColorRepresentation, target: ColorRepresentation, length: number, settings?: ColorScaleSettings): Array<[number, number, number]>;
52
52
  /**
53
- * Static method for interpolating between colors
53
+ * Interpolate between colors
54
54
  *
55
55
  * @param {[number,number,number]} inputColor Input color
56
56
  * @param {[number,number,number]} targetColor Target color
@@ -24,7 +24,7 @@ export default class ColorScale {
24
24
  this.colors = ColorScale.generate(input, target, length, settings);
25
25
  }
26
26
  /**
27
- * Static method for generating a color scale
27
+ * Generate a color scale
28
28
  *
29
29
  * @param {ColorRepresentation} input Input color representation
30
30
  * @param {ColorRepresentation} target Target color representation
@@ -43,7 +43,7 @@ export default class ColorScale {
43
43
  return colors;
44
44
  }
45
45
  /**
46
- * Static method for interpolating between colors
46
+ * Interpolate between colors
47
47
  *
48
48
  * @param {[number,number,number]} inputColor Input color
49
49
  * @param {[number,number,number]} targetColor Target color
@@ -11,9 +11,9 @@ export default class ArcCurve extends EllipseCurve {
11
11
  * @param {number} cx X-axis coordinate of the center of the circle
12
12
  * @param {number} cy Y-axis coordinate of the center of the circle
13
13
  * @param {number} radius Radius of the circle
14
- * @param {number} [startAngle] Rotation angle of the arc (in radians)
15
- * @param {number} [endAngle] Rotation angle of the arc (in radians)
16
- * @param {boolean} [counterclockwise] Flag indicating the direction of the arc
14
+ * @param {number} [startAngle=0] Start angle of the arc (in radians)
15
+ * @param {number} [endAngle=2*PI] End angle of the arc (in radians)
16
+ * @param {boolean} [counterclockwise=false] Flag indicating the direction of the arc
17
17
  */
18
18
  constructor(cx: number, cy: number, radius: number, startAngle?: number, endAngle?: number, counterclockwise?: boolean);
19
19
  }
@@ -1,3 +1,4 @@
1
+ import { TWO_PI } from '../../constants';
1
2
  import EllipseCurve from './EllipseCurve';
2
3
  /**
3
4
  * Utility class for manipulating arcs
@@ -11,11 +12,11 @@ export default class ArcCurve extends EllipseCurve {
11
12
  * @param {number} cx X-axis coordinate of the center of the circle
12
13
  * @param {number} cy Y-axis coordinate of the center of the circle
13
14
  * @param {number} radius Radius of the circle
14
- * @param {number} [startAngle] Rotation angle of the arc (in radians)
15
- * @param {number} [endAngle] Rotation angle of the arc (in radians)
16
- * @param {boolean} [counterclockwise] Flag indicating the direction of the arc
15
+ * @param {number} [startAngle=0] Start angle of the arc (in radians)
16
+ * @param {number} [endAngle=2*PI] End angle of the arc (in radians)
17
+ * @param {boolean} [counterclockwise=false] Flag indicating the direction of the arc
17
18
  */
18
- constructor(cx, cy, radius, startAngle, endAngle, counterclockwise) {
19
+ constructor(cx, cy, radius, startAngle = 0, endAngle = TWO_PI, counterclockwise = false) {
19
20
  super(cx, cy, radius, radius, 0, startAngle, endAngle, counterclockwise);
20
21
  }
21
22
  }
@@ -1,4 +1,5 @@
1
- import type { Point } from '../../types';
1
+ import type { Point2 } from '../../types';
2
+ import { Vector2 } from '../geometry';
2
3
  import Curve from './Curve';
3
4
  /**
4
5
  * Utility class for manipulating Catmull-Rom curves
@@ -7,7 +8,7 @@ import Curve from './Curve';
7
8
  * @class CatmullRomCurve
8
9
  * @extends Curve
9
10
  */
10
- export default class CatmullRomCurve extends Curve {
11
+ export default class CatmullRomCurve extends Curve<Vector2> {
11
12
  readonly type: string;
12
13
  /**
13
14
  * X-axis coordinate of the start point
@@ -53,10 +54,24 @@ export default class CatmullRomCurve extends Curve {
53
54
  */
54
55
  constructor(x1: number, y1: number, cp1x: number, cp1y: number, cp2x: number, cp2y: number, x2: number, y2: number);
55
56
  /**
56
- * Interpolate a point on the Catmull-Rom curve
57
+ * Interpolate a point on this curve
57
58
  *
58
59
  * @param {number} t Normalized time value to interpolate
59
- * @returns {Point} Interpolated coordinates on the curve
60
+ * @returns {Vector2} Interpolated coordinates on this curve
60
61
  */
61
- getPoint(t: number): Point;
62
+ getPoint(t: number): Vector2;
63
+ /**
64
+ * Interpolate a point on a Catmull-Rom curve
65
+ *
66
+ * @param {number} x1 X-axis coordinate of the start point
67
+ * @param {number} y1 Y-axis coordinate of the start point
68
+ * @param {number} cp1x X-axis coordinate of the first control point
69
+ * @param {number} cp1y Y-axis coordinate of the first control point
70
+ * @param {number} cp2x X-axis coordinate of the second control point
71
+ * @param {number} cp2y Y-axis coordinate of the second control point
72
+ * @param {number} x2 X-axis coordinate of the end point
73
+ * @param {number} y2 Y-axis coordinate of the end point
74
+ * @returns {Point2} Interpolated coordinates on the curve
75
+ */
76
+ static interpolate(t: number, x1: number, y1: number, cp1x: number, cp1y: number, cp2x: number, cp2y: number, x2: number, y2: number): Point2;
62
77
  }
@@ -1,4 +1,5 @@
1
- import { catmullRom } from '../../geometry';
1
+ import { catmullRom } from '../../maths';
2
+ import { Vector2 } from '../geometry';
2
3
  import Curve from './Curve';
3
4
  /**
4
5
  * Utility class for manipulating Catmull-Rom curves
@@ -63,13 +64,30 @@ export default class CatmullRomCurve extends Curve {
63
64
  this.y2 = y2;
64
65
  }
65
66
  /**
66
- * Interpolate a point on the Catmull-Rom curve
67
+ * Interpolate a point on this curve
67
68
  *
68
69
  * @param {number} t Normalized time value to interpolate
69
- * @returns {Point} Interpolated coordinates on the curve
70
+ * @returns {Vector2} Interpolated coordinates on this curve
70
71
  */
71
72
  getPoint(t) {
72
- const point = catmullRom(t, this.x1, this.y1, this.cp1x, this.cp1y, this.cp2x, this.cp2y, this.x2, this.y2);
73
- return point;
73
+ return new Vector2(...CatmullRomCurve.interpolate(t, this.x1, this.y1, this.cp1x, this.cp1y, this.cp2x, this.cp2y, this.x2, this.y2));
74
+ }
75
+ /**
76
+ * Interpolate a point on a Catmull-Rom curve
77
+ *
78
+ * @param {number} x1 X-axis coordinate of the start point
79
+ * @param {number} y1 Y-axis coordinate of the start point
80
+ * @param {number} cp1x X-axis coordinate of the first control point
81
+ * @param {number} cp1y Y-axis coordinate of the first control point
82
+ * @param {number} cp2x X-axis coordinate of the second control point
83
+ * @param {number} cp2y Y-axis coordinate of the second control point
84
+ * @param {number} x2 X-axis coordinate of the end point
85
+ * @param {number} y2 Y-axis coordinate of the end point
86
+ * @returns {Point2} Interpolated coordinates on the curve
87
+ */
88
+ static interpolate(t, x1, y1, cp1x, cp1y, cp2x, cp2y, x2, y2) {
89
+ const x = catmullRom(t, x1, cp1x, cp2x, x2);
90
+ const y = catmullRom(t, y1, cp1y, cp2y, y2);
91
+ return [x, y];
74
92
  }
75
93
  }
@@ -0,0 +1,101 @@
1
+ import type { Point3 } from '../../types';
2
+ import { Vector3 } from '../geometry';
3
+ import Curve from './Curve';
4
+ /**
5
+ * Utility class for manipulating Catmull-Rom 3D curves
6
+ *
7
+ * @exports
8
+ * @class CatmullRomCurve3
9
+ * @extends Curve
10
+ */
11
+ export default class CatmullRomCurve3 extends Curve<Vector3> {
12
+ readonly type: string;
13
+ /**
14
+ * X-axis coordinate of the start point
15
+ */
16
+ x1: number;
17
+ /**
18
+ * Y-axis coordinate of the start point
19
+ */
20
+ y1: number;
21
+ /**
22
+ * Z-axis coordinate of the start point
23
+ */
24
+ z1: number;
25
+ /**
26
+ * X-axis coordinate of the first control point
27
+ */
28
+ cp1x: number;
29
+ /**
30
+ * Y-axis coordinate of the first control point
31
+ */
32
+ cp1y: number;
33
+ /**
34
+ * Z-axis coordinate of the first control point
35
+ */
36
+ cp1z: number;
37
+ /**
38
+ * X-axis coordinate of the second control point
39
+ */
40
+ cp2x: number;
41
+ /**
42
+ * Y-axis coordinate of the second control point
43
+ */
44
+ cp2y: number;
45
+ /**
46
+ * Z-axis coordinate of the second control point
47
+ */
48
+ cp2z: number;
49
+ /**
50
+ * X-axis coordinate of the end point
51
+ */
52
+ x2: number;
53
+ /**
54
+ * Y-axis coordinate of the end point
55
+ */
56
+ y2: number;
57
+ /**
58
+ * Z-axis coordinate of the end point
59
+ */
60
+ z2: number;
61
+ /**
62
+ * @param {number} x1 X-axis coordinate of the start point
63
+ * @param {number} y1 Y-axis coordinate of the start point
64
+ * @param {number} z1 Z-axis coordinate of the start point
65
+ * @param {number} cp1x X-axis coordinate of the first control point
66
+ * @param {number} cp1y Y-axis coordinate of the first control point
67
+ * @param {number} cp1z Z-axis coordinate of the first control point
68
+ * @param {number} cp2x X-axis coordinate of the second control point
69
+ * @param {number} cp2y Y-axis coordinate of the second control point
70
+ * @param {number} cp2z Z-axis coordinate of the second control point
71
+ * @param {number} x2 X-axis coordinate of the end point
72
+ * @param {number} y2 Y-axis coordinate of the end point
73
+ * @param {number} z2 Z-axis coordinate of the end point
74
+ */
75
+ constructor(x1: number, y1: number, z1: number, cp1x: number, cp1y: number, cp1z: number, cp2x: number, cp2y: number, cp2z: number, x2: number, y2: number, z2: number);
76
+ /**
77
+ * Interpolate a point on this curve
78
+ *
79
+ * @param {number} t Normalized time value to interpolate
80
+ * @returns {Vector2} Interpolated coordinates on this curve
81
+ */
82
+ getPoint(t: number): Vector3;
83
+ /**
84
+ * Interpolate a point on a Catmull-Rom curve
85
+ *
86
+ * @param {number} x1 X-axis coordinate of the start point
87
+ * @param {number} y1 Y-axis coordinate of the start point
88
+ * @param {number} z1 Z-axis coordinate of the start point
89
+ * @param {number} cp1x X-axis coordinate of the first control point
90
+ * @param {number} cp1y Y-axis coordinate of the first control point
91
+ * @param {number} cp1z Z-axis coordinate of the first control point
92
+ * @param {number} cp2x X-axis coordinate of the second control point
93
+ * @param {number} cp2y Y-axis coordinate of the second control point
94
+ * @param {number} cp2z Z-axis coordinate of the second control point
95
+ * @param {number} x2 X-axis coordinate of the end point
96
+ * @param {number} y2 Y-axis coordinate of the end point
97
+ * @param {number} z2 Z-axis coordinate of the end point
98
+ * @returns {Point3} Interpolated coordinates on the curve
99
+ */
100
+ static interpolate(t: number, x1: number, y1: number, z1: number, cp1x: number, cp1y: number, cp1z: number, cp2x: number, cp2y: number, cp2z: number, x2: number, y2: number, z2: number): Point3;
101
+ }
@@ -0,0 +1,122 @@
1
+ import { catmullRom } from '../../maths';
2
+ import { Vector3 } from '../geometry';
3
+ import Curve from './Curve';
4
+ /**
5
+ * Utility class for manipulating Catmull-Rom 3D curves
6
+ *
7
+ * @exports
8
+ * @class CatmullRomCurve3
9
+ * @extends Curve
10
+ */
11
+ export default class CatmullRomCurve3 extends Curve {
12
+ type = 'CatmullRomCurve3';
13
+ /**
14
+ * X-axis coordinate of the start point
15
+ */
16
+ x1;
17
+ /**
18
+ * Y-axis coordinate of the start point
19
+ */
20
+ y1;
21
+ /**
22
+ * Z-axis coordinate of the start point
23
+ */
24
+ z1;
25
+ /**
26
+ * X-axis coordinate of the first control point
27
+ */
28
+ cp1x;
29
+ /**
30
+ * Y-axis coordinate of the first control point
31
+ */
32
+ cp1y;
33
+ /**
34
+ * Z-axis coordinate of the first control point
35
+ */
36
+ cp1z;
37
+ /**
38
+ * X-axis coordinate of the second control point
39
+ */
40
+ cp2x;
41
+ /**
42
+ * Y-axis coordinate of the second control point
43
+ */
44
+ cp2y;
45
+ /**
46
+ * Z-axis coordinate of the second control point
47
+ */
48
+ cp2z;
49
+ /**
50
+ * X-axis coordinate of the end point
51
+ */
52
+ x2;
53
+ /**
54
+ * Y-axis coordinate of the end point
55
+ */
56
+ y2;
57
+ /**
58
+ * Z-axis coordinate of the end point
59
+ */
60
+ z2;
61
+ /**
62
+ * @param {number} x1 X-axis coordinate of the start point
63
+ * @param {number} y1 Y-axis coordinate of the start point
64
+ * @param {number} z1 Z-axis coordinate of the start point
65
+ * @param {number} cp1x X-axis coordinate of the first control point
66
+ * @param {number} cp1y Y-axis coordinate of the first control point
67
+ * @param {number} cp1z Z-axis coordinate of the first control point
68
+ * @param {number} cp2x X-axis coordinate of the second control point
69
+ * @param {number} cp2y Y-axis coordinate of the second control point
70
+ * @param {number} cp2z Z-axis coordinate of the second control point
71
+ * @param {number} x2 X-axis coordinate of the end point
72
+ * @param {number} y2 Y-axis coordinate of the end point
73
+ * @param {number} z2 Z-axis coordinate of the end point
74
+ */
75
+ constructor(x1, y1, z1, cp1x, cp1y, cp1z, cp2x, cp2y, cp2z, x2, y2, z2) {
76
+ super();
77
+ this.x1 = x1;
78
+ this.y1 = y1;
79
+ this.z1 = z1;
80
+ this.cp1x = cp1x;
81
+ this.cp1y = cp1y;
82
+ this.cp1z = cp1z;
83
+ this.cp2x = cp2x;
84
+ this.cp2y = cp2y;
85
+ this.cp2z = cp2z;
86
+ this.x2 = x2;
87
+ this.y2 = y2;
88
+ this.z2 = z2;
89
+ }
90
+ /**
91
+ * Interpolate a point on this curve
92
+ *
93
+ * @param {number} t Normalized time value to interpolate
94
+ * @returns {Vector2} Interpolated coordinates on this curve
95
+ */
96
+ getPoint(t) {
97
+ return new Vector3(...CatmullRomCurve3.interpolate(t, this.x1, this.y1, this.z1, this.cp1x, this.cp1y, this.cp1z, this.cp2x, this.cp2y, this.cp2z, this.x2, this.y2, this.z2));
98
+ }
99
+ /**
100
+ * Interpolate a point on a Catmull-Rom curve
101
+ *
102
+ * @param {number} x1 X-axis coordinate of the start point
103
+ * @param {number} y1 Y-axis coordinate of the start point
104
+ * @param {number} z1 Z-axis coordinate of the start point
105
+ * @param {number} cp1x X-axis coordinate of the first control point
106
+ * @param {number} cp1y Y-axis coordinate of the first control point
107
+ * @param {number} cp1z Z-axis coordinate of the first control point
108
+ * @param {number} cp2x X-axis coordinate of the second control point
109
+ * @param {number} cp2y Y-axis coordinate of the second control point
110
+ * @param {number} cp2z Z-axis coordinate of the second control point
111
+ * @param {number} x2 X-axis coordinate of the end point
112
+ * @param {number} y2 Y-axis coordinate of the end point
113
+ * @param {number} z2 Z-axis coordinate of the end point
114
+ * @returns {Point3} Interpolated coordinates on the curve
115
+ */
116
+ static interpolate(t, x1, y1, z1, cp1x, cp1y, cp1z, cp2x, cp2y, cp2z, x2, y2, z2) {
117
+ const x = catmullRom(t, x1, cp1x, cp2x, x2);
118
+ const y = catmullRom(t, y1, cp1y, cp2y, y2);
119
+ const z = catmullRom(t, z1, cp1z, cp2z, z2);
120
+ return [x, y, z];
121
+ }
122
+ }
@@ -1,4 +1,5 @@
1
- import type { Point } from '../../types';
1
+ import type { Point2 } from '../../types';
2
+ import { Vector2 } from '../geometry';
2
3
  import Curve from './Curve';
3
4
  /**
4
5
  * Utility class for manipulating Cubic Bézier curves
@@ -7,7 +8,7 @@ import Curve from './Curve';
7
8
  * @class CubicBezierCurve
8
9
  * @extends Curve
9
10
  */
10
- export default class CubicBezierCurve extends Curve {
11
+ export default class CubicBezierCurve extends Curve<Vector2> {
11
12
  readonly type: string;
12
13
  /**
13
14
  * X-axis coordinate of the start point
@@ -53,10 +54,24 @@ export default class CubicBezierCurve extends Curve {
53
54
  */
54
55
  constructor(x1: number, y1: number, cp1x: number, cp1y: number, cp2x: number, cp2y: number, x2: number, y2: number);
55
56
  /**
56
- * Interpolate a point on the Cubic Bézier curve
57
+ * Interpolate a point on this curve
57
58
  *
58
59
  * @param {number} t Normalized time value to interpolate
59
- * @returns {Point} Interpolated coordinates on the curve
60
+ * @returns {Vector2} Interpolated coordinates on this curve
60
61
  */
61
- getPoint(t: number): Point;
62
+ getPoint(t: number): Vector2;
63
+ /**
64
+ * Interpolate a point on a Cubic Bézier curve
65
+ *
66
+ * @param {number} x1 X-axis coordinate of the start point
67
+ * @param {number} y1 Y-axis coordinate of the start point
68
+ * @param {number} cp1x X-axis coordinate of the first control point
69
+ * @param {number} cp1y Y-axis coordinate of the first control point
70
+ * @param {number} cp2x X-axis coordinate of the second control point
71
+ * @param {number} cp2y Y-axis coordinate of the second control point
72
+ * @param {number} x2 X-axis coordinate of the end point
73
+ * @param {number} y2 Y-axis coordinate of the end point
74
+ * @returns {Point2} Interpolated coordinates on the curve
75
+ */
76
+ static interpolate(t: number, x1: number, y1: number, cp1x: number, cp1y: number, cp2x: number, cp2y: number, x2: number, y2: number): Point2;
62
77
  }
@@ -1,4 +1,5 @@
1
- import { cubicBezier } from '../../geometry';
1
+ import { cubicBezier } from '../../maths';
2
+ import { Vector2 } from '../geometry';
2
3
  import Curve from './Curve';
3
4
  /**
4
5
  * Utility class for manipulating Cubic Bézier curves
@@ -63,13 +64,30 @@ export default class CubicBezierCurve extends Curve {
63
64
  this.y2 = y2;
64
65
  }
65
66
  /**
66
- * Interpolate a point on the Cubic Bézier curve
67
+ * Interpolate a point on this curve
67
68
  *
68
69
  * @param {number} t Normalized time value to interpolate
69
- * @returns {Point} Interpolated coordinates on the curve
70
+ * @returns {Vector2} Interpolated coordinates on this curve
70
71
  */
71
72
  getPoint(t) {
72
- const point = cubicBezier(t, this.x1, this.y1, this.cp1x, this.cp1y, this.cp2x, this.cp2y, this.x2, this.y2);
73
- return point;
73
+ return new Vector2(...CubicBezierCurve.interpolate(t, this.x1, this.y1, this.cp1x, this.cp1y, this.cp2x, this.cp2y, this.x2, this.y2));
74
+ }
75
+ /**
76
+ * Interpolate a point on a Cubic Bézier curve
77
+ *
78
+ * @param {number} x1 X-axis coordinate of the start point
79
+ * @param {number} y1 Y-axis coordinate of the start point
80
+ * @param {number} cp1x X-axis coordinate of the first control point
81
+ * @param {number} cp1y Y-axis coordinate of the first control point
82
+ * @param {number} cp2x X-axis coordinate of the second control point
83
+ * @param {number} cp2y Y-axis coordinate of the second control point
84
+ * @param {number} x2 X-axis coordinate of the end point
85
+ * @param {number} y2 Y-axis coordinate of the end point
86
+ * @returns {Point2} Interpolated coordinates on the curve
87
+ */
88
+ static interpolate(t, x1, y1, cp1x, cp1y, cp2x, cp2y, x2, y2) {
89
+ const x = cubicBezier(t, x1, cp1x, cp2x, x2);
90
+ const y = cubicBezier(t, y1, cp1y, cp2y, y2);
91
+ return [x, y];
74
92
  }
75
93
  }
@@ -0,0 +1,101 @@
1
+ import type { Point3 } from '../../types';
2
+ import { Vector3 } from '../geometry';
3
+ import Curve from './Curve';
4
+ /**
5
+ * Utility class for manipulating Cubic Bézier 3D curves
6
+ *
7
+ * @exports
8
+ * @class CubicBezierCurve3
9
+ * @extends Curve
10
+ */
11
+ export default class CubicBezierCurve3 extends Curve<Vector3> {
12
+ readonly type: string;
13
+ /**
14
+ * X-axis coordinate of the start point
15
+ */
16
+ x1: number;
17
+ /**
18
+ * Y-axis coordinate of the start point
19
+ */
20
+ y1: number;
21
+ /**
22
+ * Z-axis coordinate of the start point
23
+ */
24
+ z1: number;
25
+ /**
26
+ * X-axis coordinate of the first control point
27
+ */
28
+ cp1x: number;
29
+ /**
30
+ * Y-axis coordinate of the first control point
31
+ */
32
+ cp1y: number;
33
+ /**
34
+ * Z-axis coordinate of the first control point
35
+ */
36
+ cp1z: number;
37
+ /**
38
+ * X-axis coordinate of the second control point
39
+ */
40
+ cp2x: number;
41
+ /**
42
+ * Y-axis coordinate of the second control point
43
+ */
44
+ cp2y: number;
45
+ /**
46
+ * Z-axis coordinate of the second control point
47
+ */
48
+ cp2z: number;
49
+ /**
50
+ * X-axis coordinate of the end point
51
+ */
52
+ x2: number;
53
+ /**
54
+ * Y-axis coordinate of the end point
55
+ */
56
+ y2: number;
57
+ /**
58
+ * Z-axis coordinate of the end point
59
+ */
60
+ z2: number;
61
+ /**
62
+ * @param {number} x1 X-axis coordinate of the start point
63
+ * @param {number} y1 Y-axis coordinate of the start point
64
+ * @param {number} z1 Z-axis coordinate of the start point
65
+ * @param {number} cp1x X-axis coordinate of the first control point
66
+ * @param {number} cp1y Y-axis coordinate of the first control point
67
+ * @param {number} cp1z Z-axis coordinate of the first control point
68
+ * @param {number} cp2x X-axis coordinate of the second control point
69
+ * @param {number} cp2y Y-axis coordinate of the second control point
70
+ * @param {number} cp2z Z-axis coordinate of the second control point
71
+ * @param {number} x2 X-axis coordinate of the end point
72
+ * @param {number} y2 Y-axis coordinate of the end point
73
+ * @param {number} z2 Z-axis coordinate of the end point
74
+ */
75
+ constructor(x1: number, y1: number, z1: number, cp1x: number, cp1y: number, cp1z: number, cp2x: number, cp2y: number, cp2z: number, x2: number, y2: number, z2: number);
76
+ /**
77
+ * Interpolate a point on this curve
78
+ *
79
+ * @param {number} t Normalized time value to interpolate
80
+ * @returns {Vector3} Interpolated coordinates on this curve
81
+ */
82
+ getPoint(t: number): Vector3;
83
+ /**
84
+ * Interpolate a point on a 3D Cubic Bézier curve
85
+ *
86
+ * @param {number} x1 X-axis coordinate of the start point
87
+ * @param {number} y1 Y-axis coordinate of the start point
88
+ * @param {number} z1 Z-axis coordinate of the start point
89
+ * @param {number} cp1x X-axis coordinate of the first control point
90
+ * @param {number} cp1y Y-axis coordinate of the first control point
91
+ * @param {number} cp1z Z-axis coordinate of the first control point
92
+ * @param {number} cp2x X-axis coordinate of the second control point
93
+ * @param {number} cp2y Y-axis coordinate of the second control point
94
+ * @param {number} cp2z Z-axis coordinate of the second control point
95
+ * @param {number} x2 X-axis coordinate of the end point
96
+ * @param {number} y2 Y-axis coordinate of the end point
97
+ * @param {number} z2 Z-axis coordinate of the end point
98
+ * @returns {Point2} Interpolated coordinates on the curve
99
+ */
100
+ static interpolate(t: number, x1: number, y1: number, z1: number, cp1x: number, cp1y: number, cp1z: number, cp2x: number, cp2y: number, cp2z: number, x2: number, y2: number, z2: number): Point3;
101
+ }