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,108 @@
|
|
|
1
|
+
import { lerp } from '../../maths';
|
|
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 {
|
|
12
|
+
type = 'LineCurve3';
|
|
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 end point
|
|
27
|
+
*/
|
|
28
|
+
x2;
|
|
29
|
+
/**
|
|
30
|
+
* Y-axis coordinate of the end point
|
|
31
|
+
*/
|
|
32
|
+
y2;
|
|
33
|
+
/**
|
|
34
|
+
* Z-axis coordinate of the end point
|
|
35
|
+
*/
|
|
36
|
+
z2;
|
|
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, y1, z1, x2, y2, z2) {
|
|
46
|
+
super();
|
|
47
|
+
this.x1 = x1;
|
|
48
|
+
this.y1 = y1;
|
|
49
|
+
this.z1 = z1;
|
|
50
|
+
this.x2 = x2;
|
|
51
|
+
this.y2 = y2;
|
|
52
|
+
this.z2 = z2;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Interpolate a point on this curve
|
|
56
|
+
*
|
|
57
|
+
* @param {number} t Normalized time value to interpolate
|
|
58
|
+
* @returns {Vector3} Interpolated coordinates on this curve
|
|
59
|
+
*/
|
|
60
|
+
getPoint(t) {
|
|
61
|
+
return new Vector3(...LineCurve3.interpolate(t, this.x1, this.y1, this.z1, this.x2, this.y2, this.z2));
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Interpolate a point on this curve
|
|
65
|
+
*
|
|
66
|
+
* @param {number} u Normalized position value to interpolate
|
|
67
|
+
* @returns {Vector3} Interpolated coordinates on this curve
|
|
68
|
+
*/
|
|
69
|
+
getPointAt(u) {
|
|
70
|
+
return this.getPoint(u);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Compute an unit vector tangent for a given normalized time value
|
|
74
|
+
*
|
|
75
|
+
* @param {number} t Normalized time value
|
|
76
|
+
* @returns {Vector3} Tangent vector
|
|
77
|
+
*/
|
|
78
|
+
getTangent(t) {
|
|
79
|
+
return new Vector3(...Vector3.sub([this.x1, this.y1, this.z1], [this.x2, this.y2, this.z2])).normalize();
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Compute an unit vector tangent for a given normalized position value
|
|
83
|
+
*
|
|
84
|
+
* @param {number} u Normalized position value
|
|
85
|
+
* @returns {Vector3} Tangent vector
|
|
86
|
+
*/
|
|
87
|
+
getTangentAt(u) {
|
|
88
|
+
return this.getTangent(u);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Interpolate a point on a 3D line
|
|
92
|
+
*
|
|
93
|
+
* @param {number} t Normalized time value to interpolate
|
|
94
|
+
* @param {number} x1 X-axis coordinate of the start point
|
|
95
|
+
* @param {number} y1 Y-axis coordinate of the start point
|
|
96
|
+
* @param {number} z1 Z-axis coordinate of the start point
|
|
97
|
+
* @param {number} x2 X-axis coordinate of the end point
|
|
98
|
+
* @param {number} y2 Y-axis coordinate of the end point
|
|
99
|
+
* @param {number} z2 Z-axis coordinate of the end point
|
|
100
|
+
* @returns {Point3} Interpolated coordinates on the line
|
|
101
|
+
*/
|
|
102
|
+
static interpolate(t, x1, y1, z1, x2, y2, z2) {
|
|
103
|
+
const x = lerp(t, x1, x2);
|
|
104
|
+
const y = lerp(t, y1, y2);
|
|
105
|
+
const z = lerp(t, z1, z2);
|
|
106
|
+
return [x, y, z];
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
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 polylines
|
|
@@ -7,21 +8,21 @@ import Curve from './Curve';
|
|
|
7
8
|
* @class PolylineCurve
|
|
8
9
|
* @extends Curve
|
|
9
10
|
*/
|
|
10
|
-
export default class PolylineCurve extends Curve {
|
|
11
|
+
export default class PolylineCurve extends Curve<Vector2> {
|
|
11
12
|
readonly type: string;
|
|
12
13
|
/**
|
|
13
14
|
* Array of points defining the curve
|
|
14
15
|
*/
|
|
15
|
-
points:
|
|
16
|
+
points: Point2[];
|
|
16
17
|
/**
|
|
17
|
-
* @param {
|
|
18
|
+
* @param {Point2[]} [points] Array of points defining the curve
|
|
18
19
|
*/
|
|
19
|
-
constructor(points?:
|
|
20
|
+
constructor(points?: Point2[]);
|
|
20
21
|
/**
|
|
21
|
-
* Interpolate a point on
|
|
22
|
+
* Interpolate a point on this curve
|
|
22
23
|
*
|
|
23
24
|
* @param {number} t Normalized time value to interpolate
|
|
24
|
-
* @returns {
|
|
25
|
+
* @returns {Vector2} Interpolated coordinates on this curve
|
|
25
26
|
*/
|
|
26
|
-
getPoint(t: number):
|
|
27
|
+
getPoint(t: number): Vector2;
|
|
27
28
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Vector2 } from '../geometry';
|
|
2
|
+
import LineCurve from './LineCurve';
|
|
2
3
|
import Curve from './Curve';
|
|
3
4
|
/**
|
|
4
5
|
* Utility class for manipulating polylines
|
|
@@ -14,17 +15,17 @@ export default class PolylineCurve extends Curve {
|
|
|
14
15
|
*/
|
|
15
16
|
points = [];
|
|
16
17
|
/**
|
|
17
|
-
* @param {
|
|
18
|
+
* @param {Point2[]} [points] Array of points defining the curve
|
|
18
19
|
*/
|
|
19
20
|
constructor(points = []) {
|
|
20
21
|
super();
|
|
21
22
|
this.points = points;
|
|
22
23
|
}
|
|
23
24
|
/**
|
|
24
|
-
* Interpolate a point on
|
|
25
|
+
* Interpolate a point on this curve
|
|
25
26
|
*
|
|
26
27
|
* @param {number} t Normalized time value to interpolate
|
|
27
|
-
* @returns {
|
|
28
|
+
* @returns {Vector2} Interpolated coordinates on this curve
|
|
28
29
|
*/
|
|
29
30
|
getPoint(t) {
|
|
30
31
|
const points = this.points;
|
|
@@ -33,7 +34,6 @@ export default class PolylineCurve extends Curve {
|
|
|
33
34
|
const weight = p - index;
|
|
34
35
|
const p1 = points[index === 0 ? index : index - 1];
|
|
35
36
|
const p2 = points[index];
|
|
36
|
-
|
|
37
|
-
return point;
|
|
37
|
+
return new Vector2(...LineCurve.interpolate(weight, ...p1, ...p2));
|
|
38
38
|
}
|
|
39
39
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Point3 } from '../../types';
|
|
2
|
+
import { Vector3 } from '../geometry';
|
|
3
|
+
import Curve from './Curve';
|
|
4
|
+
/**
|
|
5
|
+
* Utility class for manipulating 3D polylines
|
|
6
|
+
*
|
|
7
|
+
* @exports
|
|
8
|
+
* @class PolylineCurve3
|
|
9
|
+
* @extends Curve
|
|
10
|
+
*/
|
|
11
|
+
export default class PolylineCurve3 extends Curve<Vector3> {
|
|
12
|
+
readonly type: string;
|
|
13
|
+
/**
|
|
14
|
+
* Array of points defining the curve
|
|
15
|
+
*/
|
|
16
|
+
points: Point3[];
|
|
17
|
+
/**
|
|
18
|
+
* @param {Point3[]} [points] Array of points defining the curve
|
|
19
|
+
*/
|
|
20
|
+
constructor(points?: Point3[]);
|
|
21
|
+
/**
|
|
22
|
+
* Interpolate a point on this curve
|
|
23
|
+
*
|
|
24
|
+
* @param {number} t Normalized time value to interpolate
|
|
25
|
+
* @returns {Vector3} Interpolated coordinates on this curve
|
|
26
|
+
*/
|
|
27
|
+
getPoint(t: number): Vector3;
|
|
28
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Vector3 } from '../geometry';
|
|
2
|
+
import LineCurve3 from './LineCurve3';
|
|
3
|
+
import Curve from './Curve';
|
|
4
|
+
/**
|
|
5
|
+
* Utility class for manipulating 3D polylines
|
|
6
|
+
*
|
|
7
|
+
* @exports
|
|
8
|
+
* @class PolylineCurve3
|
|
9
|
+
* @extends Curve
|
|
10
|
+
*/
|
|
11
|
+
export default class PolylineCurve3 extends Curve {
|
|
12
|
+
type = 'PolylineCurve3';
|
|
13
|
+
/**
|
|
14
|
+
* Array of points defining the curve
|
|
15
|
+
*/
|
|
16
|
+
points = [];
|
|
17
|
+
/**
|
|
18
|
+
* @param {Point3[]} [points] Array of points defining the curve
|
|
19
|
+
*/
|
|
20
|
+
constructor(points = []) {
|
|
21
|
+
super();
|
|
22
|
+
this.points = points;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Interpolate a point on this curve
|
|
26
|
+
*
|
|
27
|
+
* @param {number} t Normalized time value to interpolate
|
|
28
|
+
* @returns {Vector3} Interpolated coordinates on this curve
|
|
29
|
+
*/
|
|
30
|
+
getPoint(t) {
|
|
31
|
+
const points = this.points;
|
|
32
|
+
const p = (points.length - 1) * t;
|
|
33
|
+
const index = Math.floor(p);
|
|
34
|
+
const weight = p - index;
|
|
35
|
+
const p1 = points[index === 0 ? index : index - 1];
|
|
36
|
+
const p2 = points[index];
|
|
37
|
+
return new Vector3(...LineCurve3.interpolate(weight, ...p1, ...p2));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
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 Quadratic Bézier curves
|
|
@@ -7,7 +8,7 @@ import Curve from './Curve';
|
|
|
7
8
|
* @class QuadraticBezierCurve
|
|
8
9
|
* @extends Curve
|
|
9
10
|
*/
|
|
10
|
-
export default class QuadraticBezierCurve extends Curve {
|
|
11
|
+
export default class QuadraticBezierCurve extends Curve<Vector2> {
|
|
11
12
|
readonly type: string;
|
|
12
13
|
/**
|
|
13
14
|
* X-axis coordinate of the start point
|
|
@@ -43,10 +44,23 @@ export default class QuadraticBezierCurve extends Curve {
|
|
|
43
44
|
*/
|
|
44
45
|
constructor(x1: number, y1: number, cpx: number, cpy: number, x2: number, y2: number);
|
|
45
46
|
/**
|
|
46
|
-
* Interpolate a point on
|
|
47
|
+
* Interpolate a point on this Quadratic Bézier curve
|
|
47
48
|
*
|
|
48
49
|
* @param {number} t Normalized time value to interpolate
|
|
49
|
-
* @returns {
|
|
50
|
+
* @returns {Vector2} Interpolated coordinates on this curve
|
|
50
51
|
*/
|
|
51
|
-
getPoint(t: number):
|
|
52
|
+
getPoint(t: number): Vector2;
|
|
53
|
+
/**
|
|
54
|
+
* Interpolate a point on a Quadratic Bézier curve
|
|
55
|
+
*
|
|
56
|
+
* @param {number} t Normalized time value to interpolate
|
|
57
|
+
* @param {number} x1 X-axis coordinate of the start point
|
|
58
|
+
* @param {number} y1 Y-axis coordinate of the start point
|
|
59
|
+
* @param {number} cpx X-axis coordinate of the control point
|
|
60
|
+
* @param {number} cpy Y-axis coordinate of the control point
|
|
61
|
+
* @param {number} x2 X-axis coordinate of the end point
|
|
62
|
+
* @param {number} y2 Y-axis coordinate of the end point
|
|
63
|
+
* @returns {Point2} Interpolated coordinates on the curve
|
|
64
|
+
*/
|
|
65
|
+
static interpolate(t: number, x1: number, y1: number, cpx: number, cpy: number, x2: number, y2: number): Point2;
|
|
52
66
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { quadraticBezier } from '../../
|
|
1
|
+
import { quadraticBezier } from '../../maths';
|
|
2
|
+
import { Vector2 } from '../geometry';
|
|
2
3
|
import Curve from './Curve';
|
|
3
4
|
/**
|
|
4
5
|
* Utility class for manipulating Quadratic Bézier curves
|
|
@@ -51,13 +52,29 @@ export default class QuadraticBezierCurve extends Curve {
|
|
|
51
52
|
this.y2 = y2;
|
|
52
53
|
}
|
|
53
54
|
/**
|
|
54
|
-
* Interpolate a point on
|
|
55
|
+
* Interpolate a point on this Quadratic Bézier curve
|
|
55
56
|
*
|
|
56
57
|
* @param {number} t Normalized time value to interpolate
|
|
57
|
-
* @returns {
|
|
58
|
+
* @returns {Vector2} Interpolated coordinates on this curve
|
|
58
59
|
*/
|
|
59
60
|
getPoint(t) {
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
return new Vector2(...QuadraticBezierCurve.interpolate(t, this.x1, this.y1, this.cpx, this.cpy, this.x2, this.y2));
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Interpolate a point on a Quadratic Bézier curve
|
|
65
|
+
*
|
|
66
|
+
* @param {number} t Normalized time value to interpolate
|
|
67
|
+
* @param {number} x1 X-axis coordinate of the start point
|
|
68
|
+
* @param {number} y1 Y-axis coordinate of the start point
|
|
69
|
+
* @param {number} cpx X-axis coordinate of the control point
|
|
70
|
+
* @param {number} cpy Y-axis coordinate of the 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
|
+
* @returns {Point2} Interpolated coordinates on the curve
|
|
74
|
+
*/
|
|
75
|
+
static interpolate(t, x1, y1, cpx, cpy, x2, y2) {
|
|
76
|
+
const x = quadraticBezier(t, x1, cpx, x2);
|
|
77
|
+
const y = quadraticBezier(t, y1, cpy, y2);
|
|
78
|
+
return [x, y];
|
|
62
79
|
}
|
|
63
80
|
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { Point3 } from '../../types';
|
|
2
|
+
import { Vector3 } from '../geometry';
|
|
3
|
+
import Curve from './Curve';
|
|
4
|
+
/**
|
|
5
|
+
* Utility class for manipulating Quadratic Bézier 3D curves
|
|
6
|
+
*
|
|
7
|
+
* @exports
|
|
8
|
+
* @class QuadraticBezierCurve3
|
|
9
|
+
* @extends Curve
|
|
10
|
+
*/
|
|
11
|
+
export default class QuadraticBezierCurve3 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 control point
|
|
27
|
+
*/
|
|
28
|
+
cpx: number;
|
|
29
|
+
/**
|
|
30
|
+
* Y-axis coordinate of the control point
|
|
31
|
+
*/
|
|
32
|
+
cpy: number;
|
|
33
|
+
/**
|
|
34
|
+
* Z-axis coordinate of the control point
|
|
35
|
+
*/
|
|
36
|
+
cpz: number;
|
|
37
|
+
/**
|
|
38
|
+
* X-axis coordinate of the end point
|
|
39
|
+
*/
|
|
40
|
+
x2: number;
|
|
41
|
+
/**
|
|
42
|
+
* Y-axis coordinate of the end point
|
|
43
|
+
*/
|
|
44
|
+
y2: number;
|
|
45
|
+
/**
|
|
46
|
+
* Z-axis coordinate of the end point
|
|
47
|
+
*/
|
|
48
|
+
z2: number;
|
|
49
|
+
/**
|
|
50
|
+
* @param {number} x1 X-axis coordinate of the start point
|
|
51
|
+
* @param {number} y1 Y-axis coordinate of the start point
|
|
52
|
+
* @param {number} z1 Z-axis coordinate of the start point
|
|
53
|
+
* @param {number} cpx X-axis coordinate of the control point
|
|
54
|
+
* @param {number} cpy Y-axis coordinate of the control point
|
|
55
|
+
* @param {number} cpz Z-axis coordinate of the control point
|
|
56
|
+
* @param {number} x2 X-axis coordinate of the end point
|
|
57
|
+
* @param {number} y2 Y-axis coordinate of the end point
|
|
58
|
+
* @param {number} z2 Z-axis coordinate of the end point
|
|
59
|
+
*/
|
|
60
|
+
constructor(x1: number, y1: number, z1: number, cpx: number, cpy: number, cpz: number, x2: number, y2: number, z2: number);
|
|
61
|
+
/**
|
|
62
|
+
* Interpolate a point on this curve
|
|
63
|
+
*
|
|
64
|
+
* @param {number} t Normalized time value to interpolate
|
|
65
|
+
* @returns {Vector3} Interpolated coordinates on this curve
|
|
66
|
+
*/
|
|
67
|
+
getPoint(t: number): Vector3;
|
|
68
|
+
/**
|
|
69
|
+
* Interpolate a point on a Quadratic Bézier 3D curve
|
|
70
|
+
*
|
|
71
|
+
* @param {number} t Normalized time value to interpolate
|
|
72
|
+
* @param {number} x1 X-axis coordinate of the start point
|
|
73
|
+
* @param {number} y1 Y-axis coordinate of the start point
|
|
74
|
+
* @param {number} z1 Z-axis coordinate of the start point
|
|
75
|
+
* @param {number} cpx X-axis coordinate of the control point
|
|
76
|
+
* @param {number} cpy Y-axis coordinate of the control point
|
|
77
|
+
* @param {number} cpz Z-axis coordinate of the control point
|
|
78
|
+
* @param {number} x2 X-axis coordinate of the end point
|
|
79
|
+
* @param {number} y2 Y-axis coordinate of the end point
|
|
80
|
+
* @param {number} z2 Z-axis coordinate of the end point
|
|
81
|
+
* @returns {Point3} Interpolated coordinates on the curve
|
|
82
|
+
*/
|
|
83
|
+
static interpolate(t: number, x1: number, y1: number, z1: number, cpx: number, cpy: number, cpz: number, x2: number, y2: number, z2: number): Point3;
|
|
84
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { quadraticBezier } from '../../maths';
|
|
2
|
+
import { Vector3 } from '../geometry';
|
|
3
|
+
import Curve from './Curve';
|
|
4
|
+
/**
|
|
5
|
+
* Utility class for manipulating Quadratic Bézier 3D curves
|
|
6
|
+
*
|
|
7
|
+
* @exports
|
|
8
|
+
* @class QuadraticBezierCurve3
|
|
9
|
+
* @extends Curve
|
|
10
|
+
*/
|
|
11
|
+
export default class QuadraticBezierCurve3 extends Curve {
|
|
12
|
+
type = 'QuadraticBezierCurve3';
|
|
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 control point
|
|
27
|
+
*/
|
|
28
|
+
cpx;
|
|
29
|
+
/**
|
|
30
|
+
* Y-axis coordinate of the control point
|
|
31
|
+
*/
|
|
32
|
+
cpy;
|
|
33
|
+
/**
|
|
34
|
+
* Z-axis coordinate of the control point
|
|
35
|
+
*/
|
|
36
|
+
cpz;
|
|
37
|
+
/**
|
|
38
|
+
* X-axis coordinate of the end point
|
|
39
|
+
*/
|
|
40
|
+
x2;
|
|
41
|
+
/**
|
|
42
|
+
* Y-axis coordinate of the end point
|
|
43
|
+
*/
|
|
44
|
+
y2;
|
|
45
|
+
/**
|
|
46
|
+
* Z-axis coordinate of the end point
|
|
47
|
+
*/
|
|
48
|
+
z2;
|
|
49
|
+
/**
|
|
50
|
+
* @param {number} x1 X-axis coordinate of the start point
|
|
51
|
+
* @param {number} y1 Y-axis coordinate of the start point
|
|
52
|
+
* @param {number} z1 Z-axis coordinate of the start point
|
|
53
|
+
* @param {number} cpx X-axis coordinate of the control point
|
|
54
|
+
* @param {number} cpy Y-axis coordinate of the control point
|
|
55
|
+
* @param {number} cpz Z-axis coordinate of the control point
|
|
56
|
+
* @param {number} x2 X-axis coordinate of the end point
|
|
57
|
+
* @param {number} y2 Y-axis coordinate of the end point
|
|
58
|
+
* @param {number} z2 Z-axis coordinate of the end point
|
|
59
|
+
*/
|
|
60
|
+
constructor(x1, y1, z1, cpx, cpy, cpz, x2, y2, z2) {
|
|
61
|
+
super();
|
|
62
|
+
this.x1 = x1;
|
|
63
|
+
this.y1 = y1;
|
|
64
|
+
this.z1 = z1;
|
|
65
|
+
this.cpx = cpx;
|
|
66
|
+
this.cpy = cpy;
|
|
67
|
+
this.cpz = cpz;
|
|
68
|
+
this.x2 = x2;
|
|
69
|
+
this.y2 = y2;
|
|
70
|
+
this.z2 = z2;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Interpolate a point on this curve
|
|
74
|
+
*
|
|
75
|
+
* @param {number} t Normalized time value to interpolate
|
|
76
|
+
* @returns {Vector3} Interpolated coordinates on this curve
|
|
77
|
+
*/
|
|
78
|
+
getPoint(t) {
|
|
79
|
+
return new Vector3(...QuadraticBezierCurve3.interpolate(t, this.x1, this.y1, this.z1, this.cpx, this.cpy, this.cpz, this.x2, this.y2, this.z2));
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Interpolate a point on a Quadratic Bézier 3D curve
|
|
83
|
+
*
|
|
84
|
+
* @param {number} t Normalized time value to interpolate
|
|
85
|
+
* @param {number} x1 X-axis coordinate of the start point
|
|
86
|
+
* @param {number} y1 Y-axis coordinate of the start point
|
|
87
|
+
* @param {number} z1 Z-axis coordinate of the start point
|
|
88
|
+
* @param {number} cpx X-axis coordinate of the control point
|
|
89
|
+
* @param {number} cpy Y-axis coordinate of the control point
|
|
90
|
+
* @param {number} cpz Z-axis coordinate of the control point
|
|
91
|
+
* @param {number} x2 X-axis coordinate of the end point
|
|
92
|
+
* @param {number} y2 Y-axis coordinate of the end point
|
|
93
|
+
* @param {number} z2 Z-axis coordinate of the end point
|
|
94
|
+
* @returns {Point3} Interpolated coordinates on the curve
|
|
95
|
+
*/
|
|
96
|
+
static interpolate(t, x1, y1, z1, cpx, cpy, cpz, x2, y2, z2) {
|
|
97
|
+
const x = quadraticBezier(t, x1, cpx, x2);
|
|
98
|
+
const y = quadraticBezier(t, y1, cpy, y2);
|
|
99
|
+
const z = quadraticBezier(t, z1, cpz, z2);
|
|
100
|
+
return [x, y, z];
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
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 splines
|
|
@@ -7,18 +8,21 @@ import Curve from './Curve';
|
|
|
7
8
|
* @class SplineCurve
|
|
8
9
|
* @extends Curve
|
|
9
10
|
*/
|
|
10
|
-
export default class SplineCurve extends Curve {
|
|
11
|
+
export default class SplineCurve extends Curve<Vector2> {
|
|
11
12
|
readonly type: string;
|
|
12
|
-
points: Point[];
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* Array of points defining the curve
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
points: Point2[];
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
18
|
+
* @param {Point2[]} [points] Array of points defining the curve
|
|
19
|
+
*/
|
|
20
|
+
constructor(points?: Point2[]);
|
|
21
|
+
/**
|
|
22
|
+
* Interpolate a point on this curve
|
|
19
23
|
*
|
|
20
24
|
* @param {number} t Normalized time value to interpolate
|
|
21
|
-
* @returns {
|
|
25
|
+
* @returns {Vector2} Interpolated coordinates on this curve
|
|
22
26
|
*/
|
|
23
|
-
getPoint(t: number):
|
|
27
|
+
getPoint(t: number): Vector2;
|
|
24
28
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Vector2 } from '../geometry';
|
|
2
|
+
import CatmullRomCurve from './CatmullRomCurve';
|
|
2
3
|
import Curve from './Curve';
|
|
3
4
|
/**
|
|
4
5
|
* Utility class for manipulating splines
|
|
@@ -9,19 +10,22 @@ import Curve from './Curve';
|
|
|
9
10
|
*/
|
|
10
11
|
export default class SplineCurve extends Curve {
|
|
11
12
|
type = 'SplineCurve';
|
|
13
|
+
/**
|
|
14
|
+
* Array of points defining the curve
|
|
15
|
+
*/
|
|
12
16
|
points = [];
|
|
13
17
|
/**
|
|
14
|
-
* @param {
|
|
18
|
+
* @param {Point2[]} [points] Array of points defining the curve
|
|
15
19
|
*/
|
|
16
20
|
constructor(points = []) {
|
|
17
21
|
super();
|
|
18
22
|
this.points = points;
|
|
19
23
|
}
|
|
20
24
|
/**
|
|
21
|
-
* Interpolate a point on
|
|
25
|
+
* Interpolate a point on this curve
|
|
22
26
|
*
|
|
23
27
|
* @param {number} t Normalized time value to interpolate
|
|
24
|
-
* @returns {
|
|
28
|
+
* @returns {Vector2} Interpolated coordinates on this curve
|
|
25
29
|
*/
|
|
26
30
|
getPoint(t) {
|
|
27
31
|
const points = this.points;
|
|
@@ -32,7 +36,6 @@ export default class SplineCurve extends Curve {
|
|
|
32
36
|
const cp1 = points[index];
|
|
33
37
|
const cp2 = points[index > points.length - 2 ? points.length - 1 : index + 1];
|
|
34
38
|
const p2 = points[index > points.length - 3 ? points.length - 1 : index + 2];
|
|
35
|
-
|
|
36
|
-
return point;
|
|
39
|
+
return new Vector2(...CatmullRomCurve.interpolate(weight, ...p1, ...cp1, ...cp2, ...p2));
|
|
37
40
|
}
|
|
38
41
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Point3 } from '../../types';
|
|
2
|
+
import { Vector3 } from '../geometry';
|
|
3
|
+
import Curve from './Curve';
|
|
4
|
+
/**
|
|
5
|
+
* Utility class for manipulating 3D splines
|
|
6
|
+
*
|
|
7
|
+
* @exports
|
|
8
|
+
* @class SplineCurve3
|
|
9
|
+
* @extends Curve
|
|
10
|
+
*/
|
|
11
|
+
export default class SplineCurve3 extends Curve<Vector3> {
|
|
12
|
+
readonly type: string;
|
|
13
|
+
/**
|
|
14
|
+
* Array of points defining the curve
|
|
15
|
+
*/
|
|
16
|
+
points: Point3[];
|
|
17
|
+
/**
|
|
18
|
+
* @param {Point3[]} [points] Array of points defining the curve
|
|
19
|
+
*/
|
|
20
|
+
constructor(points?: Point3[]);
|
|
21
|
+
/**
|
|
22
|
+
* Interpolate a point on this curve
|
|
23
|
+
*
|
|
24
|
+
* @param {number} t Normalized time value to interpolate
|
|
25
|
+
* @returns {Vector3} Interpolated coordinates on this curve
|
|
26
|
+
*/
|
|
27
|
+
getPoint(t: number): Vector3;
|
|
28
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Vector3 } from '../geometry';
|
|
2
|
+
import CatmullRomCurve3 from './CatmullRomCurve3';
|
|
3
|
+
import Curve from './Curve';
|
|
4
|
+
/**
|
|
5
|
+
* Utility class for manipulating 3D splines
|
|
6
|
+
*
|
|
7
|
+
* @exports
|
|
8
|
+
* @class SplineCurve3
|
|
9
|
+
* @extends Curve
|
|
10
|
+
*/
|
|
11
|
+
export default class SplineCurve3 extends Curve {
|
|
12
|
+
type = 'SplineCurve3';
|
|
13
|
+
/**
|
|
14
|
+
* Array of points defining the curve
|
|
15
|
+
*/
|
|
16
|
+
points = [];
|
|
17
|
+
/**
|
|
18
|
+
* @param {Point3[]} [points] Array of points defining the curve
|
|
19
|
+
*/
|
|
20
|
+
constructor(points = []) {
|
|
21
|
+
super();
|
|
22
|
+
this.points = points;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Interpolate a point on this curve
|
|
26
|
+
*
|
|
27
|
+
* @param {number} t Normalized time value to interpolate
|
|
28
|
+
* @returns {Vector3} Interpolated coordinates on this curve
|
|
29
|
+
*/
|
|
30
|
+
getPoint(t) {
|
|
31
|
+
const points = this.points;
|
|
32
|
+
const p = (points.length - 1) * t;
|
|
33
|
+
const index = Math.floor(p);
|
|
34
|
+
const weight = p - index;
|
|
35
|
+
const p1 = points[index === 0 ? index : index - 1];
|
|
36
|
+
const cp1 = points[index];
|
|
37
|
+
const cp2 = points[index > points.length - 2 ? points.length - 1 : index + 1];
|
|
38
|
+
const p2 = points[index > points.length - 3 ? points.length - 1 : index + 2];
|
|
39
|
+
return new Vector3(...CatmullRomCurve3.interpolate(weight, ...p1, ...cp1, ...cp2, ...p2));
|
|
40
|
+
}
|
|
41
|
+
}
|