toosoon-utils 4.1.9 → 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.
Files changed (62) 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/CatmullRomCurve.d.ts +20 -5
  7. package/lib/extras/curves/CatmullRomCurve.js +23 -5
  8. package/lib/extras/curves/CatmullRomCurve3.d.ts +101 -0
  9. package/lib/extras/curves/CatmullRomCurve3.js +122 -0
  10. package/lib/extras/curves/CubicBezierCurve.d.ts +20 -5
  11. package/lib/extras/curves/CubicBezierCurve.js +23 -5
  12. package/lib/extras/curves/CubicBezierCurve3.d.ts +101 -0
  13. package/lib/extras/curves/CubicBezierCurve3.js +122 -0
  14. package/lib/extras/curves/Curve.d.ts +23 -24
  15. package/lib/extras/curves/Curve.js +19 -26
  16. package/lib/extras/curves/EllipseCurve.d.ts +21 -5
  17. package/lib/extras/curves/EllipseCurve.js +55 -6
  18. package/lib/extras/curves/LineCurve.d.ts +34 -10
  19. package/lib/extras/curves/LineCurve.js +35 -13
  20. package/lib/extras/curves/LineCurve3.d.ts +87 -0
  21. package/lib/extras/curves/LineCurve3.js +108 -0
  22. package/lib/extras/curves/PolylineCurve.d.ts +9 -8
  23. package/lib/extras/curves/PolylineCurve.js +6 -6
  24. package/lib/extras/curves/PolylineCurve3.d.ts +28 -0
  25. package/lib/extras/curves/PolylineCurve3.js +39 -0
  26. package/lib/extras/curves/QuadraticBezierCurve.d.ts +19 -5
  27. package/lib/extras/curves/QuadraticBezierCurve.js +22 -5
  28. package/lib/extras/curves/QuadraticBezierCurve3.d.ts +84 -0
  29. package/lib/extras/curves/QuadraticBezierCurve3.js +102 -0
  30. package/lib/extras/curves/SplineCurve.d.ts +12 -8
  31. package/lib/extras/curves/SplineCurve.js +9 -6
  32. package/lib/extras/curves/SplineCurve3.d.ts +28 -0
  33. package/lib/extras/curves/SplineCurve3.js +41 -0
  34. package/lib/extras/curves/index.d.ts +6 -0
  35. package/lib/extras/curves/index.js +6 -0
  36. package/lib/extras/geometry/Matrix2.d.ts +1 -0
  37. package/lib/extras/geometry/Matrix2.js +230 -0
  38. package/lib/extras/geometry/Matrix4.d.ts +1 -0
  39. package/lib/extras/geometry/Matrix4.js +632 -0
  40. package/lib/extras/geometry/Vector.d.ts +42 -0
  41. package/lib/extras/geometry/Vector.js +1 -0
  42. package/lib/extras/geometry/Vector2.d.ts +480 -0
  43. package/lib/extras/geometry/Vector2.js +709 -0
  44. package/lib/extras/geometry/Vector3.d.ts +486 -0
  45. package/lib/extras/geometry/Vector3.js +765 -0
  46. package/lib/extras/geometry/index.d.ts +3 -0
  47. package/lib/extras/geometry/index.js +2 -0
  48. package/lib/extras/paths/Path.d.ts +24 -18
  49. package/lib/extras/paths/Path.js +48 -35
  50. package/lib/extras/paths/PathContext.d.ts +97 -67
  51. package/lib/extras/paths/PathContext.js +326 -183
  52. package/lib/extras/paths/PathSVG.d.ts +43 -31
  53. package/lib/extras/paths/PathSVG.js +69 -56
  54. package/lib/geometry.d.ts +0 -135
  55. package/lib/geometry.js +1 -219
  56. package/lib/maths.d.ts +54 -22
  57. package/lib/maths.js +77 -27
  58. package/lib/random.d.ts +12 -16
  59. package/lib/random.js +19 -27
  60. package/lib/tsconfig.tsbuildinfo +1 -1
  61. package/lib/types.d.ts +43 -1
  62. package/package.json +2 -1
@@ -1,4 +1,4 @@
1
- import type { Point } from '../../types';
1
+ import { type Vector, Vector2, Vector3 } from '../geometry';
2
2
  /**
3
3
  * Utility abstract class for manipulating curves
4
4
  *
@@ -6,7 +6,7 @@ import type { Point } from '../../types';
6
6
  * @class Curve
7
7
  * @abstract
8
8
  */
9
- export default abstract class Curve {
9
+ export default abstract class Curve<V extends Vector = Vector2 | Vector3> {
10
10
  readonly isCurve = true;
11
11
  readonly type: string;
12
12
  /**
@@ -19,42 +19,42 @@ export default abstract class Curve {
19
19
  needsUpdate: boolean;
20
20
  protected _cacheArcLengths: number[];
21
21
  /**
22
- * Interpolate a point on the curve
22
+ * Interpolate a point on this curve
23
23
  *
24
24
  * @abstract
25
25
  * @param {number} t Normalized time value to interpolate
26
- * @returns {Point} Interpolated coordinates on the curve
26
+ * @returns {Vector} Interpolated coordinates on this curve
27
27
  */
28
- abstract getPoint(t: number): Point;
28
+ abstract getPoint(t: number): V;
29
29
  /**
30
- * Interpolate a point on the curve
30
+ * Interpolate a point on this curve
31
31
  *
32
32
  * @param {number} u Normalized position value to interpolate
33
- * @returns {Point} Interpolated coordinates on the curve
33
+ * @returns {Vector} Interpolated coordinates on this curve
34
34
  */
35
- getPointAt(u: number): Point;
35
+ getPointAt(u: number): V;
36
36
  /**
37
- * Compute the curve shape into an array of points
37
+ * Compute this curve shape into an array of points
38
38
  *
39
39
  * @param {number} [divisions=5] Number of divisions
40
- * @returns {Point[]}
40
+ * @returns {Vector[]}
41
41
  */
42
- getPoints(divisions?: number): Point[];
42
+ getPoints(divisions?: number): V[];
43
43
  /**
44
- * Compute the curve shape into an array of equi-spaced points across the entire curve
44
+ * Compute this curve shape into an array of equi-spaced points across the entire curve
45
45
  *
46
46
  * @param {number} [divisions=5] Number of divisions
47
- * @returns {Point[]}
47
+ * @returns {Vector[]}
48
48
  */
49
- getSpacedPoints(divisions?: number): Point[];
49
+ getSpacedPoints(divisions?: number): V[];
50
50
  /**
51
- * Compute the total arc length of the curve
51
+ * Compute the total arc length of this curve
52
52
  *
53
53
  * @returns {number}
54
54
  */
55
55
  getLength(): number;
56
56
  /**
57
- * Compute the cumulative segment lengths of the curve
57
+ * Compute the cumulative segment lengths of this curve
58
58
  *
59
59
  * @param {number} [divisions=this.arcLengthDivisions] Number of divisions
60
60
  * @returns {number[]}
@@ -68,7 +68,7 @@ export default abstract class Curve {
68
68
  * Re-map a normalized position value into normalized time
69
69
  *
70
70
  * @param {number} u Normalized position value to interpolate
71
- * @param {number} [targetArcLength] Distance on the curve
71
+ * @param {number} [targetArcLength] Distance on this curve
72
72
  * @returns {number} Updated interpolation value
73
73
  */
74
74
  getUtoTmapping(u: number, targetArcLength?: number): number;
@@ -76,21 +76,20 @@ export default abstract class Curve {
76
76
  * Compute an unit vector tangent for the given normalized time value
77
77
  *
78
78
  * @param {number} t Normalized time value
79
- * @returns {[number, number]} Tangent vector
79
+ * @returns {Vector} Tangent vector
80
80
  */
81
- getTangent(t: number): Point;
81
+ getTangent(t: number): V;
82
82
  /**
83
83
  * Compute an unit vector tangent for the given normalized position value
84
84
  *
85
85
  * @param {number} u Normalized position value
86
- * @returns {[number, number]} Tangent vector
86
+ * @returns {Vector} Tangent vector
87
87
  */
88
- getTangentAt(u: number): [number, number];
88
+ getTangentAt(u: number): V;
89
89
  /**
90
- * Static method to check if given points are defining a closed curve
90
+ * Check if this curve is closed
91
91
  *
92
- * @param {Point[]} points Points to check
93
92
  * @returns {boolean} True if the curve is closed, false otherwise
94
93
  */
95
- static isClosed(points: Point[]): boolean;
94
+ isClosed(): boolean;
96
95
  }
@@ -1,4 +1,3 @@
1
- import { distance, isCoincident } from '../../geometry';
2
1
  /**
3
2
  * Utility abstract class for manipulating curves
4
3
  *
@@ -19,20 +18,20 @@ export default class Curve {
19
18
  needsUpdate = false;
20
19
  _cacheArcLengths = [];
21
20
  /**
22
- * Interpolate a point on the curve
21
+ * Interpolate a point on this curve
23
22
  *
24
23
  * @param {number} u Normalized position value to interpolate
25
- * @returns {Point} Interpolated coordinates on the curve
24
+ * @returns {Vector} Interpolated coordinates on this curve
26
25
  */
27
26
  getPointAt(u) {
28
27
  const t = this.getUtoTmapping(u);
29
28
  return this.getPoint(t);
30
29
  }
31
30
  /**
32
- * Compute the curve shape into an array of points
31
+ * Compute this curve shape into an array of points
33
32
  *
34
33
  * @param {number} [divisions=5] Number of divisions
35
- * @returns {Point[]}
34
+ * @returns {Vector[]}
36
35
  */
37
36
  getPoints(divisions = 5) {
38
37
  const points = [];
@@ -42,10 +41,10 @@ export default class Curve {
42
41
  return points;
43
42
  }
44
43
  /**
45
- * Compute the curve shape into an array of equi-spaced points across the entire curve
44
+ * Compute this curve shape into an array of equi-spaced points across the entire curve
46
45
  *
47
46
  * @param {number} [divisions=5] Number of divisions
48
- * @returns {Point[]}
47
+ * @returns {Vector[]}
49
48
  */
50
49
  getSpacedPoints(divisions = 5) {
51
50
  const points = [];
@@ -55,7 +54,7 @@ export default class Curve {
55
54
  return points;
56
55
  }
57
56
  /**
58
- * Compute the total arc length of the curve
57
+ * Compute the total arc length of this curve
59
58
  *
60
59
  * @returns {number}
61
60
  */
@@ -64,7 +63,7 @@ export default class Curve {
64
63
  return lengths[lengths.length - 1];
65
64
  }
66
65
  /**
67
- * Compute the cumulative segment lengths of the curve
66
+ * Compute the cumulative segment lengths of this curve
68
67
  *
69
68
  * @param {number} [divisions=this.arcLengthDivisions] Number of divisions
70
69
  * @returns {number[]}
@@ -80,7 +79,7 @@ export default class Curve {
80
79
  let sum = 0;
81
80
  for (let i = 1; i <= divisions; i++) {
82
81
  currentPoint = this.getPoint(i / divisions);
83
- sum += distance(...currentPoint, ...lastPoint);
82
+ sum += currentPoint.distanceTo(lastPoint);
84
83
  lengths.push(sum);
85
84
  lastPoint = currentPoint;
86
85
  }
@@ -98,7 +97,7 @@ export default class Curve {
98
97
  * Re-map a normalized position value into normalized time
99
98
  *
100
99
  * @param {number} u Normalized position value to interpolate
101
- * @param {number} [targetArcLength] Distance on the curve
100
+ * @param {number} [targetArcLength] Distance on this curve
102
101
  * @returns {number} Updated interpolation value
103
102
  */
104
103
  getUtoTmapping(u, targetArcLength) {
@@ -138,38 +137,32 @@ export default class Curve {
138
137
  * Compute an unit vector tangent for the given normalized time value
139
138
  *
140
139
  * @param {number} t Normalized time value
141
- * @returns {[number, number]} Tangent vector
140
+ * @returns {Vector} Tangent vector
142
141
  */
143
142
  getTangent(t) {
144
143
  const delta = 0.0001;
145
- let t1 = Math.max(0, t - delta);
146
- let t2 = Math.min(1, t + delta);
144
+ let t0 = Math.max(0, t - delta);
145
+ let t1 = Math.min(1, t + delta);
146
+ const p0 = this.getPoint(t0);
147
147
  const p1 = this.getPoint(t1);
148
- const p2 = this.getPoint(t2);
149
- let x = p2[0] - p1[0];
150
- let y = p2[1] - p1[1];
151
- const length = Math.sqrt(x * x + y * y);
152
- x /= length;
153
- y /= length;
154
- return [x, y];
148
+ return p1.clone().sub(p0).normalize();
155
149
  }
156
150
  /**
157
151
  * Compute an unit vector tangent for the given normalized position value
158
152
  *
159
153
  * @param {number} u Normalized position value
160
- * @returns {[number, number]} Tangent vector
154
+ * @returns {Vector} Tangent vector
161
155
  */
162
156
  getTangentAt(u) {
163
157
  const t = this.getUtoTmapping(u);
164
158
  return this.getTangent(t);
165
159
  }
166
160
  /**
167
- * Static method to check if given points are defining a closed curve
161
+ * Check if this curve is closed
168
162
  *
169
- * @param {Point[]} points Points to check
170
163
  * @returns {boolean} True if the curve is closed, false otherwise
171
164
  */
172
- static isClosed(points) {
173
- return points.length > 1 && !isCoincident(...points[0], ...points[points.length - 1]);
165
+ isClosed() {
166
+ return this.getPoint(0).equals(this.getPoint(1));
174
167
  }
175
168
  }
@@ -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 ellipses
@@ -7,7 +8,7 @@ import Curve from './Curve';
7
8
  * @class EllipseCurve
8
9
  * @extends Curve
9
10
  */
10
- export default class EllipseCurve extends Curve {
11
+ export default class EllipseCurve extends Curve<Vector2> {
11
12
  readonly type: string;
12
13
  /**
13
14
  * X-axis coordinate of the center of the ellipse
@@ -53,11 +54,26 @@ export default class EllipseCurve extends Curve {
53
54
  */
54
55
  constructor(cx: number, cy: number, rx: number, ry: number, rotation?: number, startAngle?: number, endAngle?: number, counterclockwise?: boolean);
55
56
  /**
56
- * Interpolate a point on the Ellipse curve
57
+ * Interpolate a point on this curve
57
58
  *
58
59
  * @abstract
59
60
  * @param {number} t Normalized time value to interpolate
60
- * @returns {Point} Interpolated coordinates on the curve
61
+ * @returns {Vector2} Interpolated coordinates on this curve
61
62
  */
62
- getPoint(t: number): Point;
63
+ getPoint(t: number): Vector2;
64
+ /**
65
+ * Interpolate a point on an elliptical arc
66
+ *
67
+ * @param {number} t Normalized time value to interpolate
68
+ * @param {number} cx X-axis coordinate of the center of the ellipse
69
+ * @param {number} cy Y-axis coordinate of the center of the ellipse
70
+ * @param {number} rx X-radius of the ellipse
71
+ * @param {number} ry Y-radius of the ellipse
72
+ * @param {number} [rotation=0] Rotation angle of the ellipse (in radians), counterclockwise from the positive X-axis
73
+ * @param {number} [startAngle=0] Start angle of the arc (in radians)
74
+ * @param {number} [endAngle=2*PI] End angle of the arc (in radians)
75
+ * @param {boolean} [counterclockwise=false] Flag indicating the direction of the arc
76
+ * @returns {Point2} Interpolated coordinates on the arc
77
+ */
78
+ static interpolate(t: number, cx: number, cy: number, rx: number, ry: number, rotation?: number, startAngle?: number, endAngle?: number, counterclockwise?: boolean): Point2;
63
79
  }
@@ -1,5 +1,5 @@
1
- import { TWO_PI } from '../../constants';
2
- import { ellipse } from '../../geometry';
1
+ import { EPSILON, TWO_PI } from '../../constants';
2
+ import { Vector2 } from '../geometry';
3
3
  import Curve from './Curve';
4
4
  /**
5
5
  * Utility class for manipulating ellipses
@@ -64,14 +64,63 @@ export default class EllipseCurve extends Curve {
64
64
  this.counterclockwise = counterclockwise ?? false;
65
65
  }
66
66
  /**
67
- * Interpolate a point on the Ellipse curve
67
+ * Interpolate a point on this curve
68
68
  *
69
69
  * @abstract
70
70
  * @param {number} t Normalized time value to interpolate
71
- * @returns {Point} Interpolated coordinates on the curve
71
+ * @returns {Vector2} Interpolated coordinates on this curve
72
72
  */
73
73
  getPoint(t) {
74
- const point = ellipse(t, this.cx, this.cy, this.rx, this.ry, this.rotation, this.startAngle, this.endAngle, this.counterclockwise);
75
- return point;
74
+ return new Vector2(...EllipseCurve.interpolate(t, this.cx, this.cy, this.rx, this.ry, this.rotation, this.startAngle, this.endAngle, this.counterclockwise));
75
+ }
76
+ /**
77
+ * Interpolate a point on an elliptical arc
78
+ *
79
+ * @param {number} t Normalized time value to interpolate
80
+ * @param {number} cx X-axis coordinate of the center of the ellipse
81
+ * @param {number} cy Y-axis coordinate of the center of the ellipse
82
+ * @param {number} rx X-radius of the ellipse
83
+ * @param {number} ry Y-radius of the ellipse
84
+ * @param {number} [rotation=0] Rotation angle of the ellipse (in radians), counterclockwise from the positive X-axis
85
+ * @param {number} [startAngle=0] Start angle of the arc (in radians)
86
+ * @param {number} [endAngle=2*PI] End angle of the arc (in radians)
87
+ * @param {boolean} [counterclockwise=false] Flag indicating the direction of the arc
88
+ * @returns {Point2} Interpolated coordinates on the arc
89
+ */
90
+ static interpolate(t, cx, cy, rx, ry, rotation = 0, startAngle = 0, endAngle = TWO_PI, counterclockwise = false) {
91
+ let deltaAngle = endAngle - startAngle;
92
+ const isEmpty = Math.abs(deltaAngle) <= EPSILON;
93
+ while (deltaAngle < 0)
94
+ deltaAngle += TWO_PI;
95
+ while (deltaAngle > TWO_PI)
96
+ deltaAngle -= TWO_PI;
97
+ if (deltaAngle <= EPSILON) {
98
+ if (isEmpty) {
99
+ deltaAngle = 0;
100
+ }
101
+ else {
102
+ deltaAngle = TWO_PI;
103
+ }
104
+ }
105
+ if (counterclockwise === true && !isEmpty) {
106
+ if (deltaAngle === TWO_PI) {
107
+ deltaAngle = -TWO_PI;
108
+ }
109
+ else {
110
+ deltaAngle = deltaAngle - TWO_PI;
111
+ }
112
+ }
113
+ const angle = startAngle + t * deltaAngle;
114
+ let x = cx + rx * Math.cos(angle);
115
+ let y = cy + ry * Math.sin(angle);
116
+ if (rotation !== 0) {
117
+ const cos = Math.cos(rotation);
118
+ const sin = Math.sin(rotation);
119
+ const deltaX = x - cx;
120
+ const deltaY = y - cy;
121
+ x = deltaX * cos - deltaY * sin + cx;
122
+ y = deltaX * sin + deltaY * cos + cy;
123
+ }
124
+ return [x, y];
76
125
  }
77
126
  }
@@ -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 lines
@@ -7,7 +8,7 @@ import Curve from './Curve';
7
8
  * @class LineCurve
8
9
  * @extends Curve
9
10
  */
10
- export default class LineCurve extends Curve {
11
+ export default class LineCurve extends Curve<Vector2> {
11
12
  readonly type: string;
12
13
  /**
13
14
  * X-axis coordinate of the start point
@@ -33,19 +34,42 @@ export default class LineCurve extends Curve {
33
34
  */
34
35
  constructor(x1: number, y1: number, x2: number, y2: number);
35
36
  /**
36
- * Interpolate a point on the line
37
+ * Interpolate a point on this curve
37
38
  *
38
39
  * @param {number} t Normalized time value to interpolate
39
- * @returns {Point} Interpolated coordinates on the line
40
+ * @returns {Vector2} Interpolated coordinates on this curve
40
41
  */
41
- getPoint(t: number): Point;
42
- getPointAt(u: number): Point;
42
+ getPoint(t: number): Vector2;
43
43
  /**
44
- * Compute an unit vector tangent for the given normalized time value
44
+ * Interpolate a point on this line
45
+ *
46
+ * @param {number} u Normalized position value to interpolate
47
+ * @returns {Vector2} Interpolated coordinates on this line
48
+ */
49
+ getPointAt(u: number): Vector2;
50
+ /**
51
+ * Compute an unit vector tangent for a given normalized time value
45
52
  *
46
53
  * @param {number} t Normalized time value
47
- * @returns {[number, number]} Tangent vector
54
+ * @returns {Vector2} Tangent vector
55
+ */
56
+ getTangent(t?: number): Vector2;
57
+ /**
58
+ * Compute an unit vector tangent for a given normalized position value
59
+ *
60
+ * @param {number} u Normalized position value
61
+ * @returns {Vector2} Tangent vector
62
+ */
63
+ getTangentAt(u?: number): Vector2;
64
+ /**
65
+ * Interpolate a point on a line
66
+ *
67
+ * @param {number} t Normalized time value to interpolate
68
+ * @param {number} x1 X-axis coordinate of the start point
69
+ * @param {number} y1 Y-axis coordinate of the start point
70
+ * @param {number} x2 X-axis coordinate of the end point
71
+ * @param {number} y2 Y-axis coordinate of the end point
72
+ * @returns {Point2} Interpolated coordinates on the line
48
73
  */
49
- getTangent(t?: number): [number, number];
50
- getTangentAt(u: number): [number, number];
74
+ static interpolate(t: number, x1: number, y1: number, x2: number, y2: number): Point2;
51
75
  }
@@ -1,4 +1,5 @@
1
- import { line } from '../../geometry';
1
+ import { lerp } from '../../maths';
2
+ import { Vector2 } from '../geometry';
2
3
  import Curve from './Curve';
3
4
  /**
4
5
  * Utility class for manipulating lines
@@ -39,33 +40,54 @@ export default class LineCurve extends Curve {
39
40
  this.y2 = y2;
40
41
  }
41
42
  /**
42
- * Interpolate a point on the line
43
+ * Interpolate a point on this curve
43
44
  *
44
45
  * @param {number} t Normalized time value to interpolate
45
- * @returns {Point} Interpolated coordinates on the line
46
+ * @returns {Vector2} Interpolated coordinates on this curve
46
47
  */
47
48
  getPoint(t) {
48
- const point = line(t, this.x1, this.y1, this.x2, this.y2);
49
- return point;
49
+ return new Vector2(...LineCurve.interpolate(t, this.x1, this.y1, this.x2, this.y2));
50
50
  }
51
+ /**
52
+ * Interpolate a point on this line
53
+ *
54
+ * @param {number} u Normalized position value to interpolate
55
+ * @returns {Vector2} Interpolated coordinates on this line
56
+ */
51
57
  getPointAt(u) {
52
58
  return this.getPoint(u);
53
59
  }
54
60
  /**
55
- * Compute an unit vector tangent for the given normalized time value
61
+ * Compute an unit vector tangent for a given normalized time value
56
62
  *
57
63
  * @param {number} t Normalized time value
58
- * @returns {[number, number]} Tangent vector
64
+ * @returns {Vector2} Tangent vector
59
65
  */
60
66
  getTangent(t) {
61
- let x = this.x2 - this.x1;
62
- let y = this.y2 - this.y1;
63
- const length = Math.sqrt(x * x + y * y);
64
- x /= length;
65
- y /= length;
66
- return [x, y];
67
+ return new Vector2(...Vector2.sub([this.x1, this.y1], [this.x2, this.y2])).normalize();
67
68
  }
69
+ /**
70
+ * Compute an unit vector tangent for a given normalized position value
71
+ *
72
+ * @param {number} u Normalized position value
73
+ * @returns {Vector2} Tangent vector
74
+ */
68
75
  getTangentAt(u) {
69
76
  return this.getTangent(u);
70
77
  }
78
+ /**
79
+ * Interpolate a point on a line
80
+ *
81
+ * @param {number} t Normalized time value to interpolate
82
+ * @param {number} x1 X-axis coordinate of the start point
83
+ * @param {number} y1 Y-axis coordinate of the start 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 line
87
+ */
88
+ static interpolate(t, x1, y1, x2, y2) {
89
+ const x = lerp(t, x1, x2);
90
+ const y = lerp(t, y1, y2);
91
+ return [x, y];
92
+ }
71
93
  }
@@ -0,0 +1,87 @@
1
+ import type { Point3 } from '../../types';
2
+ import { Vector3 } from '../geometry';
3
+ import Curve from './Curve';
4
+ /**
5
+ * Utility class for manipulating 3D lines
6
+ *
7
+ * @exports
8
+ * @class LineCurve3
9
+ * @extends Curve
10
+ */
11
+ export default class LineCurve3 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 end point
27
+ */
28
+ x2: number;
29
+ /**
30
+ * Y-axis coordinate of the end point
31
+ */
32
+ y2: number;
33
+ /**
34
+ * Z-axis coordinate of the end point
35
+ */
36
+ z2: number;
37
+ /**
38
+ * @param {number} x1 X-axis coordinate of the start point
39
+ * @param {number} y1 Y-axis coordinate of the start point
40
+ * @param {number} z1 Z-axis coordinate of the start point
41
+ * @param {number} x2 X-axis coordinate of the end point
42
+ * @param {number} y2 Y-axis coordinate of the end point
43
+ * @param {number} z2 Z-axis coordinate of the end point
44
+ */
45
+ constructor(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number);
46
+ /**
47
+ * Interpolate a point on this curve
48
+ *
49
+ * @param {number} t Normalized time value to interpolate
50
+ * @returns {Vector3} Interpolated coordinates on this curve
51
+ */
52
+ getPoint(t: number): Vector3;
53
+ /**
54
+ * Interpolate a point on this curve
55
+ *
56
+ * @param {number} u Normalized position value to interpolate
57
+ * @returns {Vector3} Interpolated coordinates on this curve
58
+ */
59
+ getPointAt(u: number): Vector3;
60
+ /**
61
+ * Compute an unit vector tangent for a given normalized time value
62
+ *
63
+ * @param {number} t Normalized time value
64
+ * @returns {Vector3} Tangent vector
65
+ */
66
+ getTangent(t?: number): Vector3;
67
+ /**
68
+ * Compute an unit vector tangent for a given normalized position value
69
+ *
70
+ * @param {number} u Normalized position value
71
+ * @returns {Vector3} Tangent vector
72
+ */
73
+ getTangentAt(u?: number): Vector3;
74
+ /**
75
+ * Interpolate a point on a 3D line
76
+ *
77
+ * @param {number} t Normalized time value to interpolate
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} z1 Z-axis coordinate of the start point
81
+ * @param {number} x2 X-axis coordinate of the end point
82
+ * @param {number} y2 Y-axis coordinate of the end point
83
+ * @param {number} z2 Z-axis coordinate of the end point
84
+ * @returns {Point3} Interpolated coordinates on the line
85
+ */
86
+ static interpolate(t: number, x1: number, y1: number, z1: number, x2: number, y2: number, z2: number): Point3;
87
+ }