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.
- 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/ArcCurve.d.ts +3 -3
- package/lib/extras/curves/ArcCurve.js +5 -4
- 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 +25 -9
- package/lib/extras/curves/EllipseCurve.js +64 -15
- 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 +69 -56
- package/lib/extras/paths/index.d.ts +1 -1
- 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,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
|
+
}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
export { default as Curve } from './Curve';
|
|
2
2
|
export { default as LineCurve } from './LineCurve';
|
|
3
|
+
export { default as LineCurve3 } from './LineCurve3';
|
|
3
4
|
export { default as PolylineCurve } from './PolylineCurve';
|
|
5
|
+
export { default as PolylineCurve3 } from './PolylineCurve3';
|
|
4
6
|
export { default as QuadraticBezierCurve } from './QuadraticBezierCurve';
|
|
7
|
+
export { default as QuadraticBezierCurve3 } from './QuadraticBezierCurve3';
|
|
5
8
|
export { default as CubicBezierCurve } from './CubicBezierCurve';
|
|
9
|
+
export { default as CubicBezierCurve3 } from './CubicBezierCurve3';
|
|
6
10
|
export { default as CatmullRomCurve } from './CatmullRomCurve';
|
|
11
|
+
export { default as CatmullRomCurve3 } from './CatmullRomCurve3';
|
|
7
12
|
export { default as SplineCurve } from './SplineCurve';
|
|
13
|
+
export { default as SplineCurve3 } from './SplineCurve3';
|
|
8
14
|
export { default as EllipseCurve } from './EllipseCurve';
|
|
9
15
|
export { default as ArcCurve } from './ArcCurve';
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
export { default as Curve } from './Curve';
|
|
2
2
|
export { default as LineCurve } from './LineCurve';
|
|
3
|
+
export { default as LineCurve3 } from './LineCurve3';
|
|
3
4
|
export { default as PolylineCurve } from './PolylineCurve';
|
|
5
|
+
export { default as PolylineCurve3 } from './PolylineCurve3';
|
|
4
6
|
export { default as QuadraticBezierCurve } from './QuadraticBezierCurve';
|
|
7
|
+
export { default as QuadraticBezierCurve3 } from './QuadraticBezierCurve3';
|
|
5
8
|
export { default as CubicBezierCurve } from './CubicBezierCurve';
|
|
9
|
+
export { default as CubicBezierCurve3 } from './CubicBezierCurve3';
|
|
6
10
|
export { default as CatmullRomCurve } from './CatmullRomCurve';
|
|
11
|
+
export { default as CatmullRomCurve3 } from './CatmullRomCurve3';
|
|
7
12
|
export { default as SplineCurve } from './SplineCurve';
|
|
13
|
+
export { default as SplineCurve3 } from './SplineCurve3';
|
|
8
14
|
export { default as EllipseCurve } from './EllipseCurve';
|
|
9
15
|
export { default as ArcCurve } from './ArcCurve';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
// import { EPSILON } from '../../constants';
|
|
2
|
+
// import { dot } from '../../geometry';
|
|
3
|
+
// import type { Matrix2x2, Matrix2x3 } from '../../types';
|
|
4
|
+
export {};
|
|
5
|
+
// // prettier-ignore
|
|
6
|
+
// export const IDENTITY_MATRIX_2: Matrix2x3 = [
|
|
7
|
+
// 1, 0,
|
|
8
|
+
// 0, 1,
|
|
9
|
+
// 0, 0,
|
|
10
|
+
// ] as const;
|
|
11
|
+
// export default class Matrix2 {
|
|
12
|
+
// readonly isMatrix2 = true;
|
|
13
|
+
// readonly type: string = 'Matrix2';
|
|
14
|
+
// private _matrix: Matrix2x3 = [...IDENTITY_MATRIX_2];
|
|
15
|
+
// /**
|
|
16
|
+
// *
|
|
17
|
+
// * @param m11
|
|
18
|
+
// * @param m12
|
|
19
|
+
// * @param m21
|
|
20
|
+
// * @param m22
|
|
21
|
+
// * @param m31
|
|
22
|
+
// * @param m32
|
|
23
|
+
// */
|
|
24
|
+
// constructor(m11: number = 1, m12: number = 0, m21: number = 0, m22: number = 1, m31: number = 0, m32: number = 0) {
|
|
25
|
+
// this.set(m11, m12, m21, m22, m31, m32);
|
|
26
|
+
// }
|
|
27
|
+
// /**
|
|
28
|
+
// *
|
|
29
|
+
// * @param m11
|
|
30
|
+
// * @param m12
|
|
31
|
+
// * @param m21
|
|
32
|
+
// * @param m22
|
|
33
|
+
// * @param m31
|
|
34
|
+
// * @param m32
|
|
35
|
+
// */
|
|
36
|
+
// public set(m11: number, m12: number, m21: number, m22: number, m31: number, m32: number): this {
|
|
37
|
+
// this._matrix[0] = m11;
|
|
38
|
+
// this._matrix[1] = m12;
|
|
39
|
+
// this._matrix[2] = m21;
|
|
40
|
+
// this._matrix[3] = m22;
|
|
41
|
+
// this._matrix[4] = m31;
|
|
42
|
+
// this._matrix[5] = m32;
|
|
43
|
+
// return this;
|
|
44
|
+
// }
|
|
45
|
+
// /**
|
|
46
|
+
// *
|
|
47
|
+
// * @param array
|
|
48
|
+
// * @returns
|
|
49
|
+
// */
|
|
50
|
+
// public fromArray(array: number[]): this {
|
|
51
|
+
// for (let i = 0; i < 6; i++) {
|
|
52
|
+
// this._matrix[i] = array[i] ?? IDENTITY_MATRIX_2[i];
|
|
53
|
+
// }
|
|
54
|
+
// return this;
|
|
55
|
+
// }
|
|
56
|
+
// /**
|
|
57
|
+
// *
|
|
58
|
+
// * @returns {Matrix2x3}
|
|
59
|
+
// */
|
|
60
|
+
// public toArray(): Matrix2x3 {
|
|
61
|
+
// return [this.a, this.b, this.c, this.d, this.e, this.f];
|
|
62
|
+
// }
|
|
63
|
+
// public toMatrix2x2(): Matrix2x2 {
|
|
64
|
+
// return [this.a, this.b, this.c, this.d];
|
|
65
|
+
// }
|
|
66
|
+
// public toMatrix2x3(): Matrix2x3 {
|
|
67
|
+
// return [this.a, this.b, this.c, this.d, this.e, this.f];
|
|
68
|
+
// }
|
|
69
|
+
// public invert(): this {
|
|
70
|
+
// if (Math.abs(this.determinant) <= EPSILON) {
|
|
71
|
+
// this.set(NaN, NaN, NaN, NaN, NaN, NaN);
|
|
72
|
+
// return this;
|
|
73
|
+
// }
|
|
74
|
+
// const invDet = 1 / this.determinant;
|
|
75
|
+
// this.set(
|
|
76
|
+
// this.d * invDet,
|
|
77
|
+
// -this.b * invDet,
|
|
78
|
+
// -this.c * invDet,
|
|
79
|
+
// this.a * invDet,
|
|
80
|
+
// (this.c * this.f - this.d * this.e) * invDet,
|
|
81
|
+
// (this.b * this.e - this.a * this.f) * invDet
|
|
82
|
+
// );
|
|
83
|
+
// return this;
|
|
84
|
+
// }
|
|
85
|
+
// public multiply([a, b, c, d, e = 0, f = 0]: Matrix2 | Matrix2x2 | Matrix2x3): this {
|
|
86
|
+
// return this.set(
|
|
87
|
+
// this.a * a + this.c * b,
|
|
88
|
+
// this.b * a + this.d * b,
|
|
89
|
+
// this.a * c + this.c * d,
|
|
90
|
+
// this.b * c + this.d * d,
|
|
91
|
+
// this.a * e + this.c * f + this.e,
|
|
92
|
+
// this.b * e + this.d * f + this.f
|
|
93
|
+
// );
|
|
94
|
+
// }
|
|
95
|
+
// public translate(translateX: number, translateY: number): this {
|
|
96
|
+
// return this.multiply([1, 0, 0, 1, translateX, translateY]);
|
|
97
|
+
// }
|
|
98
|
+
// public scale(scaleX: number, scaleY: number): this {
|
|
99
|
+
// return this.multiply([scaleX, 0, 0, scaleY]);
|
|
100
|
+
// }
|
|
101
|
+
// /**
|
|
102
|
+
// *
|
|
103
|
+
// * @param angle (in radians)
|
|
104
|
+
// * @returns
|
|
105
|
+
// */
|
|
106
|
+
// public rotate(angle: number) {
|
|
107
|
+
// const cos = Math.cos(angle);
|
|
108
|
+
// const sin = Math.sin(angle);
|
|
109
|
+
// return this.multiply([cos, sin, -sin, cos]);
|
|
110
|
+
// }
|
|
111
|
+
// /**
|
|
112
|
+
// *
|
|
113
|
+
// * @param {Matrix2} matrix
|
|
114
|
+
// * @returns {boolean}
|
|
115
|
+
// */
|
|
116
|
+
// public equals([a, b, c, d, e = 0, f = 0]: Matrix2 | Matrix2x2 | Matrix2x3): boolean {
|
|
117
|
+
// return (
|
|
118
|
+
// Math.abs(this.a - a) <= EPSILON &&
|
|
119
|
+
// Math.abs(this.b - b) <= EPSILON &&
|
|
120
|
+
// Math.abs(this.c - c) <= EPSILON &&
|
|
121
|
+
// Math.abs(this.d - d) <= EPSILON &&
|
|
122
|
+
// Math.abs(this.e - e) <= EPSILON &&
|
|
123
|
+
// Math.abs(this.f - f) <= EPSILON
|
|
124
|
+
// );
|
|
125
|
+
// }
|
|
126
|
+
// /**
|
|
127
|
+
// *
|
|
128
|
+
// * @returns
|
|
129
|
+
// */
|
|
130
|
+
// public identity(): this {
|
|
131
|
+
// this.set(...IDENTITY_MATRIX_2);
|
|
132
|
+
// return this;
|
|
133
|
+
// }
|
|
134
|
+
// public reset(): this {
|
|
135
|
+
// return this.identity();
|
|
136
|
+
// }
|
|
137
|
+
// /**
|
|
138
|
+
// *
|
|
139
|
+
// * @returns
|
|
140
|
+
// */
|
|
141
|
+
// public isIdentity(): boolean {
|
|
142
|
+
// return this.equals(IDENTITY_MATRIX_2);
|
|
143
|
+
// }
|
|
144
|
+
// /**
|
|
145
|
+
// *
|
|
146
|
+
// * @returns {boolean}
|
|
147
|
+
// */
|
|
148
|
+
// public isOrthogonal(): boolean {
|
|
149
|
+
// return Math.abs(this.dot) <= EPSILON;
|
|
150
|
+
// }
|
|
151
|
+
// /**
|
|
152
|
+
// *
|
|
153
|
+
// * @returns {boolean}
|
|
154
|
+
// */
|
|
155
|
+
// public isUniform(): boolean {
|
|
156
|
+
// return Math.abs(this.scaleX - this.scaleY) <= EPSILON && this.isOrthogonal();
|
|
157
|
+
// }
|
|
158
|
+
// public copy(matrix: Matrix2): Matrix2 {
|
|
159
|
+
// this.set(...matrix.toArray());
|
|
160
|
+
// return this;
|
|
161
|
+
// }
|
|
162
|
+
// public clone(): Matrix2 {
|
|
163
|
+
// return new Matrix2(...this.toArray());
|
|
164
|
+
// }
|
|
165
|
+
// get dot(): number {
|
|
166
|
+
// return dot(this.a, this.b, this.c, this.d);
|
|
167
|
+
// }
|
|
168
|
+
// get determinant(): number {
|
|
169
|
+
// return this.a * this.d - this.b * this.c;
|
|
170
|
+
// }
|
|
171
|
+
// get translateX(): number {
|
|
172
|
+
// return this.e;
|
|
173
|
+
// }
|
|
174
|
+
// get translateY(): number {
|
|
175
|
+
// return this.f;
|
|
176
|
+
// }
|
|
177
|
+
// get scaleX(): number {
|
|
178
|
+
// return Math.hypot(this.a, this.b);
|
|
179
|
+
// }
|
|
180
|
+
// get scaleY(): number {
|
|
181
|
+
// return Math.hypot(this.c, this.d);
|
|
182
|
+
// }
|
|
183
|
+
// get rotation(): number {
|
|
184
|
+
// return Math.atan2(this.b, this.a);
|
|
185
|
+
// }
|
|
186
|
+
// get a() {
|
|
187
|
+
// return this._matrix[0];
|
|
188
|
+
// }
|
|
189
|
+
// get b() {
|
|
190
|
+
// return this._matrix[1];
|
|
191
|
+
// }
|
|
192
|
+
// get c() {
|
|
193
|
+
// return this._matrix[2];
|
|
194
|
+
// }
|
|
195
|
+
// get d() {
|
|
196
|
+
// return this._matrix[3];
|
|
197
|
+
// }
|
|
198
|
+
// get e() {
|
|
199
|
+
// return this._matrix[4];
|
|
200
|
+
// }
|
|
201
|
+
// get f() {
|
|
202
|
+
// return this._matrix[5];
|
|
203
|
+
// }
|
|
204
|
+
// get m11() {
|
|
205
|
+
// return this._matrix[0];
|
|
206
|
+
// }
|
|
207
|
+
// get m12() {
|
|
208
|
+
// return this._matrix[1];
|
|
209
|
+
// }
|
|
210
|
+
// get m21() {
|
|
211
|
+
// return this._matrix[2];
|
|
212
|
+
// }
|
|
213
|
+
// get m22() {
|
|
214
|
+
// return this._matrix[3];
|
|
215
|
+
// }
|
|
216
|
+
// get m31() {
|
|
217
|
+
// return this._matrix[4];
|
|
218
|
+
// }
|
|
219
|
+
// get m32() {
|
|
220
|
+
// return this._matrix[5];
|
|
221
|
+
// }
|
|
222
|
+
// *[Symbol.iterator](): Iterator<number> {
|
|
223
|
+
// yield this.a;
|
|
224
|
+
// yield this.b;
|
|
225
|
+
// yield this.c;
|
|
226
|
+
// yield this.d;
|
|
227
|
+
// yield this.e;
|
|
228
|
+
// yield this.f;
|
|
229
|
+
// }
|
|
230
|
+
// }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|