curvy 0.3.3 → 1.0.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/LICENSE.md +21 -0
- package/dist/curve/cubic2d.d.mts +31 -0
- package/dist/curve/cubic2d.d.ts +31 -0
- package/dist/curve/cubic2d.mjs +96 -0
- package/dist/curve/linear2d.d.mts +28 -0
- package/dist/curve/linear2d.d.ts +28 -0
- package/dist/curve/linear2d.mjs +48 -0
- package/dist/curve/quadratic2d.d.mts +33 -0
- package/dist/curve/quadratic2d.d.ts +33 -0
- package/dist/curve/quadratic2d.mjs +86 -0
- package/dist/interval.d.mts +58 -0
- package/dist/interval.d.ts +58 -0
- package/dist/interval.mjs +88 -0
- package/dist/matrix/matrix2x2.d.mts +49 -0
- package/dist/matrix/matrix2x2.d.ts +49 -0
- package/dist/matrix/matrix2x2.mjs +23 -0
- package/dist/matrix/matrix3x3.d.mts +63 -0
- package/dist/matrix/matrix3x3.d.ts +63 -0
- package/dist/matrix/matrix3x3.mjs +26 -0
- package/dist/matrix/matrix4x4.d.mts +72 -0
- package/dist/matrix/matrix4x4.d.ts +72 -0
- package/dist/matrix/matrix4x4.mjs +214 -0
- package/dist/path/cubic2d.d.mts +29 -0
- package/dist/path/cubic2d.d.ts +29 -0
- package/dist/path/cubic2d.mjs +60 -0
- package/dist/path/linear2d.d.mts +29 -0
- package/dist/path/linear2d.d.ts +29 -0
- package/dist/path/linear2d.mjs +54 -0
- package/dist/path/quadratic2d.d.mts +30 -0
- package/dist/path/quadratic2d.d.ts +30 -0
- package/dist/path/quadratic2d.mjs +60 -0
- package/dist/polynomial/cubic.d.mts +7 -0
- package/dist/polynomial/cubic.d.ts +7 -0
- package/dist/polynomial/cubic.mjs +147 -0
- package/dist/polynomial/linear.d.mts +7 -0
- package/dist/polynomial/linear.d.ts +7 -0
- package/dist/polynomial/linear.mjs +22 -0
- package/dist/polynomial/quadratic.d.mts +7 -0
- package/dist/polynomial/quadratic.d.ts +7 -0
- package/dist/polynomial/quadratic.mjs +23 -0
- package/dist/shared/curvy.BN-oFBsc.d.mts +26 -0
- package/dist/shared/curvy.BN-oFBsc.d.ts +26 -0
- package/dist/shared/curvy.CT38g_II.d.mts +22 -0
- package/dist/shared/curvy.CT38g_II.d.ts +22 -0
- package/dist/shared/curvy.ChkqgKuv.mjs +119 -0
- package/dist/shared/curvy.CkJRVnqj.d.ts +155 -0
- package/dist/shared/curvy.Cty3LrOR.mjs +70 -0
- package/dist/shared/curvy.D7MEXd5g.mjs +130 -0
- package/dist/shared/curvy.D7bhnwZy.mjs +52 -0
- package/dist/shared/curvy.DB7nQmVs.mjs +79 -0
- package/dist/shared/curvy.DM6AiKbn.mjs +119 -0
- package/dist/shared/curvy.DOSsf40r.mjs +49 -0
- package/dist/shared/curvy.DmVFTi0N.mjs +34 -0
- package/dist/shared/curvy.DwHW5Fqt.d.mts +155 -0
- package/dist/shared/curvy.bvP77ZZm.mjs +123 -0
- package/dist/splines/bezier2d.d.mts +43 -0
- package/dist/splines/bezier2d.d.ts +43 -0
- package/dist/splines/bezier2d.mjs +148 -0
- package/dist/vector/vector2.d.mts +41 -0
- package/dist/vector/vector2.d.ts +41 -0
- package/dist/vector/vector2.mjs +17 -0
- package/dist/vector/vector3.d.mts +38 -0
- package/dist/vector/vector3.d.ts +38 -0
- package/dist/vector/vector3.mjs +16 -0
- package/dist/vector/vector4.d.mts +39 -0
- package/dist/vector/vector4.d.ts +39 -0
- package/dist/vector/vector4.mjs +16 -0
- package/package.json +78 -37
- package/dist/axis.cjs +0 -14
- package/dist/axis.d.cts +0 -20
- package/dist/axis.d.mts +0 -20
- package/dist/axis.d.ts +0 -20
- package/dist/axis.mjs +0 -3
- package/dist/convert.cjs +0 -74
- package/dist/convert.d.cts +0 -6
- package/dist/convert.d.mts +0 -6
- package/dist/convert.d.ts +0 -6
- package/dist/convert.mjs +0 -68
- package/dist/curve.cjs +0 -365
- package/dist/curve.d.cts +0 -20
- package/dist/curve.d.mts +0 -20
- package/dist/curve.d.ts +0 -20
- package/dist/curve.mjs +0 -354
- package/dist/shared/curvy.262f6070.cjs +0 -16
- package/dist/shared/curvy.7876e09e.mjs +0 -323
- package/dist/shared/curvy.9cd8b44c.mjs +0 -13
- package/dist/shared/curvy.db103082.cjs +0 -335
- package/dist/shared/curvy.df73166c.d.cts +0 -38
- package/dist/shared/curvy.df73166c.d.mts +0 -38
- package/dist/shared/curvy.df73166c.d.ts +0 -38
- package/dist/splines.cjs +0 -150
- package/dist/splines.d.cts +0 -27
- package/dist/splines.d.mts +0 -27
- package/dist/splines.d.ts +0 -27
- package/dist/splines.mjs +0 -138
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Tim Morris
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { e as TwoDimensional } from '../shared/curvy.CT38g_II.mjs';
|
|
2
|
+
import { P as Pipeable } from '../shared/curvy.BN-oFBsc.mjs';
|
|
3
|
+
import { Interval } from '../interval.mjs';
|
|
4
|
+
import { C as CubicPolynomial } from '../shared/curvy.DwHW5Fqt.mjs';
|
|
5
|
+
import { Vector2 } from '../vector/vector2.mjs';
|
|
6
|
+
import '../vector/vector3.mjs';
|
|
7
|
+
import '../vector/vector4.mjs';
|
|
8
|
+
|
|
9
|
+
declare const CubicCurve2dTypeId: unique symbol;
|
|
10
|
+
type CubicCurve2dTypeId = typeof CubicCurve2dTypeId;
|
|
11
|
+
|
|
12
|
+
interface CubicCurve2d extends Pipeable, TwoDimensional<CubicPolynomial> {
|
|
13
|
+
readonly [CubicCurve2dTypeId]: CubicCurve2dTypeId;
|
|
14
|
+
}
|
|
15
|
+
declare const fromPolynomials: (x: CubicPolynomial, y: CubicPolynomial) => CubicCurve2d;
|
|
16
|
+
declare const fromPoints: (p0: Vector2, p1: Vector2, p2: Vector2, p3: Vector2) => CubicCurve2d;
|
|
17
|
+
declare const isCubicCurve2d: (c: unknown) => c is CubicCurve2d;
|
|
18
|
+
declare const solve: {
|
|
19
|
+
(t: number): (c: CubicCurve2d) => Vector2;
|
|
20
|
+
(c: CubicCurve2d, t: number): Vector2;
|
|
21
|
+
};
|
|
22
|
+
declare const length: {
|
|
23
|
+
(c: CubicCurve2d, i: Interval): number;
|
|
24
|
+
(i: Interval): (c: CubicCurve2d) => number;
|
|
25
|
+
};
|
|
26
|
+
declare const curvature: {
|
|
27
|
+
(c: CubicCurve2d, t: number): number;
|
|
28
|
+
(t: number): (c: CubicCurve2d) => number;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export { type CubicCurve2d, curvature, fromPoints, fromPolynomials, isCubicCurve2d, length, solve };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { e as TwoDimensional } from '../shared/curvy.CT38g_II.js';
|
|
2
|
+
import { P as Pipeable } from '../shared/curvy.BN-oFBsc.js';
|
|
3
|
+
import { Interval } from '../interval.js';
|
|
4
|
+
import { C as CubicPolynomial } from '../shared/curvy.CkJRVnqj.js';
|
|
5
|
+
import { Vector2 } from '../vector/vector2.js';
|
|
6
|
+
import '../vector/vector3.js';
|
|
7
|
+
import '../vector/vector4.js';
|
|
8
|
+
|
|
9
|
+
declare const CubicCurve2dTypeId: unique symbol;
|
|
10
|
+
type CubicCurve2dTypeId = typeof CubicCurve2dTypeId;
|
|
11
|
+
|
|
12
|
+
interface CubicCurve2d extends Pipeable, TwoDimensional<CubicPolynomial> {
|
|
13
|
+
readonly [CubicCurve2dTypeId]: CubicCurve2dTypeId;
|
|
14
|
+
}
|
|
15
|
+
declare const fromPolynomials: (x: CubicPolynomial, y: CubicPolynomial) => CubicCurve2d;
|
|
16
|
+
declare const fromPoints: (p0: Vector2, p1: Vector2, p2: Vector2, p3: Vector2) => CubicCurve2d;
|
|
17
|
+
declare const isCubicCurve2d: (c: unknown) => c is CubicCurve2d;
|
|
18
|
+
declare const solve: {
|
|
19
|
+
(t: number): (c: CubicCurve2d) => Vector2;
|
|
20
|
+
(c: CubicCurve2d, t: number): Vector2;
|
|
21
|
+
};
|
|
22
|
+
declare const length: {
|
|
23
|
+
(c: CubicCurve2d, i: Interval): number;
|
|
24
|
+
(i: Interval): (c: CubicCurve2d) => number;
|
|
25
|
+
};
|
|
26
|
+
declare const curvature: {
|
|
27
|
+
(c: CubicCurve2d, t: number): number;
|
|
28
|
+
(t: number): (c: CubicCurve2d) => number;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export { type CubicCurve2d, curvature, fromPoints, fromPolynomials, isCubicCurve2d, length, solve };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { d as dual, r as round, P as Pipeable } from '../shared/curvy.ChkqgKuv.mjs';
|
|
2
|
+
import { size, scaleShift, biunit } from '../interval.mjs';
|
|
3
|
+
import { G as GL32_W0, a as GL32_X0, b as GL32_W1, c as GL32_X1, d as GL32_W2, e as GL32_X2, f as GL32_W3, g as GL32_X3, h as GL32_W4, i as GL32_X4, j as GL32_W5, k as GL32_X5, l as GL32_W6, m as GL32_X6, n as GL32_W7, o as GL32_X7, p as GL32_W8, q as GL32_X8, r as GL32_W9, s as GL32_X9, t as GL32_W10, u as GL32_X10, v as GL32_W11, w as GL32_X11, x as GL32_W12, y as GL32_X12, z as GL32_W13, A as GL32_X13, B as GL32_W14, C as GL32_X14, D as GL32_W15, E as GL32_X15 } from '../shared/curvy.DmVFTi0N.mjs';
|
|
4
|
+
import { make, solve as solve$2, derivative as derivative$2 } from '../polynomial/cubic.mjs';
|
|
5
|
+
import { make as make$2 } from '../polynomial/quadratic.mjs';
|
|
6
|
+
import { make as make$1, magnitude, cross } from '../vector/vector2.mjs';
|
|
7
|
+
import { solve as solve$4 } from './linear2d.mjs';
|
|
8
|
+
import { length as length$2, fromPolynomials as fromPolynomials$2, solve as solve$3, derivative as derivative$1 } from './quadratic2d.mjs';
|
|
9
|
+
import '../shared/curvy.D7MEXd5g.mjs';
|
|
10
|
+
import '../shared/curvy.DB7nQmVs.mjs';
|
|
11
|
+
import '../shared/curvy.DOSsf40r.mjs';
|
|
12
|
+
import '../polynomial/linear.mjs';
|
|
13
|
+
|
|
14
|
+
const CubicCurve2dTypeId = Symbol("curvy/curve/cubic2d");
|
|
15
|
+
class CubicCurve2dImpl extends Pipeable {
|
|
16
|
+
[CubicCurve2dTypeId] = CubicCurve2dTypeId;
|
|
17
|
+
x;
|
|
18
|
+
y;
|
|
19
|
+
constructor(c0, c1) {
|
|
20
|
+
super();
|
|
21
|
+
this.x = c0;
|
|
22
|
+
this.y = c1;
|
|
23
|
+
}
|
|
24
|
+
get [0]() {
|
|
25
|
+
return this.x;
|
|
26
|
+
}
|
|
27
|
+
get [1]() {
|
|
28
|
+
return this.y;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const fromPolynomials$1 = (c0, c1) => new CubicCurve2dImpl(c0, c1);
|
|
32
|
+
const fromPoints$1 = (p0, p1, p2, p3) => new CubicCurve2dImpl(
|
|
33
|
+
make(p0.x, p1.x, p2.x, p3.x),
|
|
34
|
+
make(p0.y, p1.y, p2.y, p3.y)
|
|
35
|
+
);
|
|
36
|
+
const isCubicCurve2d$1 = (c) => typeof c === "object" && c !== null && CubicCurve2dTypeId in c;
|
|
37
|
+
const solve$1 = dual(
|
|
38
|
+
2,
|
|
39
|
+
(c, t) => make$1(solve$2(c.x, t), solve$2(c.y, t))
|
|
40
|
+
);
|
|
41
|
+
const derivative = (c) => fromPolynomials$2(
|
|
42
|
+
derivative$2(c.x),
|
|
43
|
+
derivative$2(c.y)
|
|
44
|
+
);
|
|
45
|
+
const length$1 = dual(2, (c, i) => {
|
|
46
|
+
if (size(i) === 0) {
|
|
47
|
+
return 0;
|
|
48
|
+
}
|
|
49
|
+
if (c.x.c3 === 0 && c.y.c3 === 0) {
|
|
50
|
+
return length$2(
|
|
51
|
+
fromPolynomials$2(
|
|
52
|
+
make$2(c.x.c0, c.x.c1, c.x.c2),
|
|
53
|
+
make$2(c.y.c0, c.y.c1, c.y.c2)
|
|
54
|
+
),
|
|
55
|
+
i
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
const d = derivative(c);
|
|
59
|
+
const { scale, shift } = scaleShift(biunit, i);
|
|
60
|
+
return round(
|
|
61
|
+
(GL32_W0 * magnitude(solve$3(d, shift + scale * -GL32_X0)) + GL32_W0 * magnitude(solve$3(d, shift + scale * GL32_X0)) + GL32_W1 * magnitude(solve$3(d, shift + scale * -GL32_X1)) + GL32_W1 * magnitude(solve$3(d, shift + scale * GL32_X1)) + GL32_W2 * magnitude(solve$3(d, shift + scale * -GL32_X2)) + GL32_W2 * magnitude(solve$3(d, shift + scale * GL32_X2)) + GL32_W3 * magnitude(solve$3(d, shift + scale * -GL32_X3)) + GL32_W3 * magnitude(solve$3(d, shift + scale * GL32_X3)) + GL32_W4 * magnitude(solve$3(d, shift + scale * -GL32_X4)) + GL32_W4 * magnitude(solve$3(d, shift + scale * GL32_X4)) + GL32_W5 * magnitude(solve$3(d, shift + scale * -GL32_X5)) + GL32_W5 * magnitude(solve$3(d, shift + scale * GL32_X5)) + GL32_W6 * magnitude(solve$3(d, shift + scale * -GL32_X6)) + GL32_W6 * magnitude(solve$3(d, shift + scale * GL32_X6)) + GL32_W7 * magnitude(solve$3(d, shift + scale * -GL32_X7)) + GL32_W7 * magnitude(solve$3(d, shift + scale * GL32_X7)) + GL32_W8 * magnitude(solve$3(d, shift + scale * -GL32_X8)) + GL32_W8 * magnitude(solve$3(d, shift + scale * GL32_X8)) + GL32_W9 * magnitude(solve$3(d, shift + scale * -GL32_X9)) + GL32_W9 * magnitude(solve$3(d, shift + scale * GL32_X9)) + GL32_W10 * magnitude(
|
|
62
|
+
solve$3(d, shift + scale * -GL32_X10)
|
|
63
|
+
) + GL32_W10 * magnitude(solve$3(d, shift + scale * GL32_X10)) + GL32_W11 * magnitude(
|
|
64
|
+
solve$3(d, shift + scale * -GL32_X11)
|
|
65
|
+
) + GL32_W11 * magnitude(solve$3(d, shift + scale * GL32_X11)) + GL32_W12 * magnitude(
|
|
66
|
+
solve$3(d, shift + scale * -GL32_X12)
|
|
67
|
+
) + GL32_W12 * magnitude(solve$3(d, shift + scale * GL32_X12)) + GL32_W13 * magnitude(
|
|
68
|
+
solve$3(d, shift + scale * -GL32_X13)
|
|
69
|
+
) + GL32_W13 * magnitude(solve$3(d, shift + scale * GL32_X13)) + GL32_W14 * magnitude(
|
|
70
|
+
solve$3(d, shift + scale * -GL32_X14)
|
|
71
|
+
) + GL32_W14 * magnitude(solve$3(d, shift + scale * GL32_X14)) + GL32_W15 * magnitude(
|
|
72
|
+
solve$3(d, shift + scale * -GL32_X15)
|
|
73
|
+
) + GL32_W15 * magnitude(
|
|
74
|
+
solve$3(d, shift + scale * GL32_X15)
|
|
75
|
+
)) * scale
|
|
76
|
+
);
|
|
77
|
+
});
|
|
78
|
+
const curvature$1 = dual(2, (c, t) => {
|
|
79
|
+
const d = derivative(c);
|
|
80
|
+
const v = solve$3(d, t);
|
|
81
|
+
const a = solve$4(derivative$1(d), t);
|
|
82
|
+
const vMag = magnitude(v);
|
|
83
|
+
if (vMag === 0) {
|
|
84
|
+
return 0;
|
|
85
|
+
}
|
|
86
|
+
return round(Math.abs(cross(v, a)) / vMag ** 3);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const fromPolynomials = fromPolynomials$1;
|
|
90
|
+
const fromPoints = fromPoints$1;
|
|
91
|
+
const isCubicCurve2d = isCubicCurve2d$1;
|
|
92
|
+
const solve = solve$1;
|
|
93
|
+
const length = length$1;
|
|
94
|
+
const curvature = curvature$1;
|
|
95
|
+
|
|
96
|
+
export { curvature, fromPoints, fromPolynomials, isCubicCurve2d, length, solve };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { e as TwoDimensional } from '../shared/curvy.CT38g_II.mjs';
|
|
2
|
+
import { P as Pipeable } from '../shared/curvy.BN-oFBsc.mjs';
|
|
3
|
+
import { Interval } from '../interval.mjs';
|
|
4
|
+
import { L as LinearPolynomial } from '../shared/curvy.DwHW5Fqt.mjs';
|
|
5
|
+
import { Vector2 } from '../vector/vector2.mjs';
|
|
6
|
+
import '../vector/vector3.mjs';
|
|
7
|
+
import '../vector/vector4.mjs';
|
|
8
|
+
|
|
9
|
+
declare const LinearCurve2dTypeId: unique symbol;
|
|
10
|
+
type LinearCurve2dTypeId = typeof LinearCurve2dTypeId;
|
|
11
|
+
|
|
12
|
+
interface LinearCurve2d extends Pipeable, TwoDimensional<LinearPolynomial> {
|
|
13
|
+
readonly [LinearCurve2dTypeId]: LinearCurve2dTypeId;
|
|
14
|
+
}
|
|
15
|
+
declare const fromPolynomials: (x: LinearPolynomial, y: LinearPolynomial) => LinearCurve2d;
|
|
16
|
+
declare const fromPoints: (p0: Vector2, p1: Vector2) => LinearCurve2d;
|
|
17
|
+
declare const isLinearCurve2d: (c: unknown) => c is LinearCurve2d;
|
|
18
|
+
declare const derivative: (c: LinearCurve2d) => Vector2;
|
|
19
|
+
declare const solve: {
|
|
20
|
+
(t: number): (c: LinearCurve2d) => Vector2;
|
|
21
|
+
(c: LinearCurve2d, t: number): Vector2;
|
|
22
|
+
};
|
|
23
|
+
declare const length: {
|
|
24
|
+
(c: LinearCurve2d, i: Interval): number;
|
|
25
|
+
(i: Interval): (c: LinearCurve2d) => number;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export { type LinearCurve2d, derivative, fromPoints, fromPolynomials, isLinearCurve2d, length, solve };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { e as TwoDimensional } from '../shared/curvy.CT38g_II.js';
|
|
2
|
+
import { P as Pipeable } from '../shared/curvy.BN-oFBsc.js';
|
|
3
|
+
import { Interval } from '../interval.js';
|
|
4
|
+
import { L as LinearPolynomial } from '../shared/curvy.CkJRVnqj.js';
|
|
5
|
+
import { Vector2 } from '../vector/vector2.js';
|
|
6
|
+
import '../vector/vector3.js';
|
|
7
|
+
import '../vector/vector4.js';
|
|
8
|
+
|
|
9
|
+
declare const LinearCurve2dTypeId: unique symbol;
|
|
10
|
+
type LinearCurve2dTypeId = typeof LinearCurve2dTypeId;
|
|
11
|
+
|
|
12
|
+
interface LinearCurve2d extends Pipeable, TwoDimensional<LinearPolynomial> {
|
|
13
|
+
readonly [LinearCurve2dTypeId]: LinearCurve2dTypeId;
|
|
14
|
+
}
|
|
15
|
+
declare const fromPolynomials: (x: LinearPolynomial, y: LinearPolynomial) => LinearCurve2d;
|
|
16
|
+
declare const fromPoints: (p0: Vector2, p1: Vector2) => LinearCurve2d;
|
|
17
|
+
declare const isLinearCurve2d: (c: unknown) => c is LinearCurve2d;
|
|
18
|
+
declare const derivative: (c: LinearCurve2d) => Vector2;
|
|
19
|
+
declare const solve: {
|
|
20
|
+
(t: number): (c: LinearCurve2d) => Vector2;
|
|
21
|
+
(c: LinearCurve2d, t: number): Vector2;
|
|
22
|
+
};
|
|
23
|
+
declare const length: {
|
|
24
|
+
(c: LinearCurve2d, i: Interval): number;
|
|
25
|
+
(i: Interval): (c: LinearCurve2d) => number;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export { type LinearCurve2d, derivative, fromPoints, fromPolynomials, isLinearCurve2d, length, solve };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { d as dual, r as round, P as Pipeable } from '../shared/curvy.ChkqgKuv.mjs';
|
|
2
|
+
import { make, solve as solve$2 } from '../polynomial/linear.mjs';
|
|
3
|
+
import { make as make$1 } from '../vector/vector2.mjs';
|
|
4
|
+
import '../shared/curvy.DB7nQmVs.mjs';
|
|
5
|
+
import '../interval.mjs';
|
|
6
|
+
import '../shared/curvy.DOSsf40r.mjs';
|
|
7
|
+
|
|
8
|
+
const LinearCurve2dTypeId = Symbol("curvy/curve/linear2d");
|
|
9
|
+
class LinearCurve2dImpl extends Pipeable {
|
|
10
|
+
[LinearCurve2dTypeId] = LinearCurve2dTypeId;
|
|
11
|
+
x;
|
|
12
|
+
y;
|
|
13
|
+
constructor(c0, c1) {
|
|
14
|
+
super();
|
|
15
|
+
this.x = c0;
|
|
16
|
+
this.y = c1;
|
|
17
|
+
}
|
|
18
|
+
get [0]() {
|
|
19
|
+
return this.x;
|
|
20
|
+
}
|
|
21
|
+
get [1]() {
|
|
22
|
+
return this.y;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const fromPolynomials$1 = (c0, c1) => new LinearCurve2dImpl(c0, c1);
|
|
26
|
+
const fromPoints$1 = (p0, p1) => new LinearCurve2dImpl(
|
|
27
|
+
make(p0.x, p1.x),
|
|
28
|
+
make(p0.y, p1.y)
|
|
29
|
+
);
|
|
30
|
+
const isLinearCurve2d$1 = (c) => typeof c === "object" && c !== null && LinearCurve2dTypeId in c;
|
|
31
|
+
const derivative$1 = (c) => make$1(c.x.c1, c.y.c1);
|
|
32
|
+
const solve$1 = dual(
|
|
33
|
+
2,
|
|
34
|
+
(c, t) => make$1(solve$2(c.x, t), solve$2(c.y, t))
|
|
35
|
+
);
|
|
36
|
+
const length$1 = dual(
|
|
37
|
+
2,
|
|
38
|
+
(c, i) => round(Math.sqrt(c.x.c1 ** 2 + c.y.c1 ** 2) * Math.abs(i.end - i.start))
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const fromPolynomials = fromPolynomials$1;
|
|
42
|
+
const fromPoints = fromPoints$1;
|
|
43
|
+
const isLinearCurve2d = isLinearCurve2d$1;
|
|
44
|
+
const derivative = derivative$1;
|
|
45
|
+
const solve = solve$1;
|
|
46
|
+
const length = length$1;
|
|
47
|
+
|
|
48
|
+
export { derivative, fromPoints, fromPolynomials, isLinearCurve2d, length, solve };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { e as TwoDimensional } from '../shared/curvy.CT38g_II.mjs';
|
|
2
|
+
import { P as Pipeable } from '../shared/curvy.BN-oFBsc.mjs';
|
|
3
|
+
import { Interval } from '../interval.mjs';
|
|
4
|
+
import { Q as QuadraticPolynomial } from '../shared/curvy.DwHW5Fqt.mjs';
|
|
5
|
+
import { Vector2 } from '../vector/vector2.mjs';
|
|
6
|
+
import { LinearCurve2d } from './linear2d.mjs';
|
|
7
|
+
import '../vector/vector3.mjs';
|
|
8
|
+
import '../vector/vector4.mjs';
|
|
9
|
+
|
|
10
|
+
declare const QuadraticCurve2dTypeId: unique symbol;
|
|
11
|
+
type QuadraticCurve2dTypeId = typeof QuadraticCurve2dTypeId;
|
|
12
|
+
|
|
13
|
+
interface QuadraticCurve2d extends Pipeable, TwoDimensional<QuadraticPolynomial> {
|
|
14
|
+
readonly [QuadraticCurve2dTypeId]: QuadraticCurve2dTypeId;
|
|
15
|
+
}
|
|
16
|
+
declare const fromPolynomials: (c0: QuadraticPolynomial, c1: QuadraticPolynomial) => QuadraticCurve2d;
|
|
17
|
+
declare const fromPoints: (p0: Vector2, p1: Vector2, p2: Vector2) => QuadraticCurve2d;
|
|
18
|
+
declare const isQuadraticCurve2d: (c: unknown) => c is QuadraticCurve2d;
|
|
19
|
+
declare const solve: {
|
|
20
|
+
(t: number): (c: QuadraticCurve2d) => Vector2;
|
|
21
|
+
(c: QuadraticCurve2d, t: number): Vector2;
|
|
22
|
+
};
|
|
23
|
+
declare const length: {
|
|
24
|
+
(c: QuadraticCurve2d, i: Interval): number;
|
|
25
|
+
(i: Interval): (c: QuadraticCurve2d) => number;
|
|
26
|
+
};
|
|
27
|
+
declare const derivative: (c: QuadraticCurve2d) => LinearCurve2d;
|
|
28
|
+
declare const curvature: {
|
|
29
|
+
(c: QuadraticCurve2d, t: number): number;
|
|
30
|
+
(t: number): (c: QuadraticCurve2d) => number;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export { type QuadraticCurve2d, curvature, derivative, fromPoints, fromPolynomials, isQuadraticCurve2d, length, solve };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { e as TwoDimensional } from '../shared/curvy.CT38g_II.js';
|
|
2
|
+
import { P as Pipeable } from '../shared/curvy.BN-oFBsc.js';
|
|
3
|
+
import { Interval } from '../interval.js';
|
|
4
|
+
import { Q as QuadraticPolynomial } from '../shared/curvy.CkJRVnqj.js';
|
|
5
|
+
import { Vector2 } from '../vector/vector2.js';
|
|
6
|
+
import { LinearCurve2d } from './linear2d.js';
|
|
7
|
+
import '../vector/vector3.js';
|
|
8
|
+
import '../vector/vector4.js';
|
|
9
|
+
|
|
10
|
+
declare const QuadraticCurve2dTypeId: unique symbol;
|
|
11
|
+
type QuadraticCurve2dTypeId = typeof QuadraticCurve2dTypeId;
|
|
12
|
+
|
|
13
|
+
interface QuadraticCurve2d extends Pipeable, TwoDimensional<QuadraticPolynomial> {
|
|
14
|
+
readonly [QuadraticCurve2dTypeId]: QuadraticCurve2dTypeId;
|
|
15
|
+
}
|
|
16
|
+
declare const fromPolynomials: (c0: QuadraticPolynomial, c1: QuadraticPolynomial) => QuadraticCurve2d;
|
|
17
|
+
declare const fromPoints: (p0: Vector2, p1: Vector2, p2: Vector2) => QuadraticCurve2d;
|
|
18
|
+
declare const isQuadraticCurve2d: (c: unknown) => c is QuadraticCurve2d;
|
|
19
|
+
declare const solve: {
|
|
20
|
+
(t: number): (c: QuadraticCurve2d) => Vector2;
|
|
21
|
+
(c: QuadraticCurve2d, t: number): Vector2;
|
|
22
|
+
};
|
|
23
|
+
declare const length: {
|
|
24
|
+
(c: QuadraticCurve2d, i: Interval): number;
|
|
25
|
+
(i: Interval): (c: QuadraticCurve2d) => number;
|
|
26
|
+
};
|
|
27
|
+
declare const derivative: (c: QuadraticCurve2d) => LinearCurve2d;
|
|
28
|
+
declare const curvature: {
|
|
29
|
+
(c: QuadraticCurve2d, t: number): number;
|
|
30
|
+
(t: number): (c: QuadraticCurve2d) => number;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export { type QuadraticCurve2d, curvature, derivative, fromPoints, fromPolynomials, isQuadraticCurve2d, length, solve };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { d as dual, r as round, P as Pipeable } from '../shared/curvy.ChkqgKuv.mjs';
|
|
2
|
+
import { size, scaleShift, biunit } from '../interval.mjs';
|
|
3
|
+
import { G as GL32_W0, a as GL32_X0, b as GL32_W1, c as GL32_X1, d as GL32_W2, e as GL32_X2, f as GL32_W3, g as GL32_X3, h as GL32_W4, i as GL32_X4, j as GL32_W5, k as GL32_X5, l as GL32_W6, m as GL32_X6, n as GL32_W7, o as GL32_X7, p as GL32_W8, q as GL32_X8, r as GL32_W9, s as GL32_X9, t as GL32_W10, u as GL32_X10, v as GL32_W11, w as GL32_X11, x as GL32_W12, y as GL32_X12, z as GL32_W13, A as GL32_X13, B as GL32_W14, C as GL32_X14, D as GL32_W15, E as GL32_X15 } from '../shared/curvy.DmVFTi0N.mjs';
|
|
4
|
+
import { make as make$2 } from '../polynomial/linear.mjs';
|
|
5
|
+
import { make, solve as solve$2, derivative as derivative$2 } from '../polynomial/quadratic.mjs';
|
|
6
|
+
import { make as make$1, magnitude, cross } from '../vector/vector2.mjs';
|
|
7
|
+
import { fromPolynomials as fromPolynomials$2, length as length$2, solve as solve$3, derivative as derivative$3 } from './linear2d.mjs';
|
|
8
|
+
import '../shared/curvy.DB7nQmVs.mjs';
|
|
9
|
+
import '../shared/curvy.D7MEXd5g.mjs';
|
|
10
|
+
import '../shared/curvy.DOSsf40r.mjs';
|
|
11
|
+
|
|
12
|
+
const QuadraticCurve2dTypeId = Symbol(
|
|
13
|
+
"curvy/curve/quadratic2d"
|
|
14
|
+
);
|
|
15
|
+
class QuadraticCurve2dImpl extends Pipeable {
|
|
16
|
+
[QuadraticCurve2dTypeId] = QuadraticCurve2dTypeId;
|
|
17
|
+
x;
|
|
18
|
+
y;
|
|
19
|
+
constructor(c0, c1) {
|
|
20
|
+
super();
|
|
21
|
+
this.x = c0;
|
|
22
|
+
this.y = c1;
|
|
23
|
+
}
|
|
24
|
+
get [0]() {
|
|
25
|
+
return this.x;
|
|
26
|
+
}
|
|
27
|
+
get [1]() {
|
|
28
|
+
return this.y;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const fromPolynomials$1 = (c0, c1) => new QuadraticCurve2dImpl(c0, c1);
|
|
32
|
+
const fromPoints$1 = (p0, p1, p2) => new QuadraticCurve2dImpl(
|
|
33
|
+
make(p0.x, p1.x, p2.x),
|
|
34
|
+
make(p0.y, p1.y, p2.y)
|
|
35
|
+
);
|
|
36
|
+
const isQuadraticCurve2d$1 = (c) => typeof c === "object" && c !== null && QuadraticCurve2dTypeId in c;
|
|
37
|
+
const solve$1 = dual(
|
|
38
|
+
2,
|
|
39
|
+
(c, t) => make$1(
|
|
40
|
+
solve$2(c.x, t),
|
|
41
|
+
solve$2(c.y, t)
|
|
42
|
+
)
|
|
43
|
+
);
|
|
44
|
+
const derivative$1 = (c) => fromPolynomials$2(
|
|
45
|
+
derivative$2(c.x),
|
|
46
|
+
derivative$2(c.y)
|
|
47
|
+
);
|
|
48
|
+
const length$1 = dual(2, (c, i) => {
|
|
49
|
+
if (size(i) === 0) {
|
|
50
|
+
return 0;
|
|
51
|
+
}
|
|
52
|
+
if (c.x.c2 === 0 && c.y.c2 === 0) {
|
|
53
|
+
return length$2(
|
|
54
|
+
fromPolynomials$2(
|
|
55
|
+
make$2(c.x.c0, c.x.c1),
|
|
56
|
+
make$2(c.y.c0, c.y.c1)
|
|
57
|
+
),
|
|
58
|
+
i
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
const d = derivative$1(c);
|
|
62
|
+
const { scale, shift } = scaleShift(biunit, i);
|
|
63
|
+
return round(
|
|
64
|
+
(GL32_W0 * magnitude(solve$3(d, shift + scale * -GL32_X0)) + GL32_W0 * magnitude(solve$3(d, shift + scale * GL32_X0)) + GL32_W1 * magnitude(solve$3(d, shift + scale * -GL32_X1)) + GL32_W1 * magnitude(solve$3(d, shift + scale * GL32_X1)) + GL32_W2 * magnitude(solve$3(d, shift + scale * -GL32_X2)) + GL32_W2 * magnitude(solve$3(d, shift + scale * GL32_X2)) + GL32_W3 * magnitude(solve$3(d, shift + scale * -GL32_X3)) + GL32_W3 * magnitude(solve$3(d, shift + scale * GL32_X3)) + GL32_W4 * magnitude(solve$3(d, shift + scale * -GL32_X4)) + GL32_W4 * magnitude(solve$3(d, shift + scale * GL32_X4)) + GL32_W5 * magnitude(solve$3(d, shift + scale * -GL32_X5)) + GL32_W5 * magnitude(solve$3(d, shift + scale * GL32_X5)) + GL32_W6 * magnitude(solve$3(d, shift + scale * -GL32_X6)) + GL32_W6 * magnitude(solve$3(d, shift + scale * GL32_X6)) + GL32_W7 * magnitude(solve$3(d, shift + scale * -GL32_X7)) + GL32_W7 * magnitude(solve$3(d, shift + scale * GL32_X7)) + GL32_W8 * magnitude(solve$3(d, shift + scale * -GL32_X8)) + GL32_W8 * magnitude(solve$3(d, shift + scale * GL32_X8)) + GL32_W9 * magnitude(solve$3(d, shift + scale * -GL32_X9)) + GL32_W9 * magnitude(solve$3(d, shift + scale * GL32_X9)) + GL32_W10 * magnitude(solve$3(d, shift + scale * -GL32_X10)) + GL32_W10 * magnitude(solve$3(d, shift + scale * GL32_X10)) + GL32_W11 * magnitude(solve$3(d, shift + scale * -GL32_X11)) + GL32_W11 * magnitude(solve$3(d, shift + scale * GL32_X11)) + GL32_W12 * magnitude(solve$3(d, shift + scale * -GL32_X12)) + GL32_W12 * magnitude(solve$3(d, shift + scale * GL32_X12)) + GL32_W13 * magnitude(solve$3(d, shift + scale * -GL32_X13)) + GL32_W13 * magnitude(solve$3(d, shift + scale * GL32_X13)) + GL32_W14 * magnitude(solve$3(d, shift + scale * -GL32_X14)) + GL32_W14 * magnitude(solve$3(d, shift + scale * GL32_X14)) + GL32_W15 * magnitude(solve$3(d, shift + scale * -GL32_X15)) + GL32_W15 * magnitude(solve$3(d, shift + scale * GL32_X15))) * scale
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
const curvature$1 = dual(2, (c, t) => {
|
|
68
|
+
const d = derivative$1(c);
|
|
69
|
+
const v = solve$3(d, t);
|
|
70
|
+
const a = derivative$3(d);
|
|
71
|
+
const vMag = magnitude(v);
|
|
72
|
+
if (vMag === 0) {
|
|
73
|
+
return 0;
|
|
74
|
+
}
|
|
75
|
+
return round(Math.abs(cross(v, a)) / vMag ** 3);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const fromPolynomials = fromPolynomials$1;
|
|
79
|
+
const fromPoints = fromPoints$1;
|
|
80
|
+
const isQuadraticCurve2d = isQuadraticCurve2d$1;
|
|
81
|
+
const solve = solve$1;
|
|
82
|
+
const length = length$1;
|
|
83
|
+
const derivative = derivative$1;
|
|
84
|
+
const curvature = curvature$1;
|
|
85
|
+
|
|
86
|
+
export { curvature, derivative, fromPoints, fromPolynomials, isQuadraticCurve2d, length, solve };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { P as Pipeable } from './shared/curvy.BN-oFBsc.mjs';
|
|
2
|
+
|
|
3
|
+
interface Interval extends Pipeable {
|
|
4
|
+
readonly start: number;
|
|
5
|
+
readonly end: number;
|
|
6
|
+
}
|
|
7
|
+
declare const isInterval: (v: unknown) => v is Interval;
|
|
8
|
+
declare const make: {
|
|
9
|
+
(point: number): Interval;
|
|
10
|
+
(start: number, end: number): Interval;
|
|
11
|
+
};
|
|
12
|
+
declare const fromSize: {
|
|
13
|
+
(size: number): Interval;
|
|
14
|
+
(start: number, size: number): Interval;
|
|
15
|
+
};
|
|
16
|
+
declare const fromMinMax: (...values: ReadonlyArray<number>) => Interval;
|
|
17
|
+
declare const size: (i: Interval) => number;
|
|
18
|
+
declare const contains: {
|
|
19
|
+
(interval: Interval, value: number, options?: {
|
|
20
|
+
includeStart?: boolean;
|
|
21
|
+
includeEnd?: boolean;
|
|
22
|
+
}): boolean;
|
|
23
|
+
(value: number, options?: {
|
|
24
|
+
includeStart?: boolean;
|
|
25
|
+
includeEnd?: boolean;
|
|
26
|
+
}): (interval: Interval) => boolean;
|
|
27
|
+
};
|
|
28
|
+
declare const filter: {
|
|
29
|
+
<V extends ReadonlyArray<number>>(interval: Interval, value: V, options?: {
|
|
30
|
+
includeStart?: boolean;
|
|
31
|
+
includeEnd?: boolean;
|
|
32
|
+
}): V;
|
|
33
|
+
<V extends ReadonlyArray<number>>(value: V, options?: {
|
|
34
|
+
includeStart?: boolean;
|
|
35
|
+
includeEnd?: boolean;
|
|
36
|
+
}): (interval: Interval) => V;
|
|
37
|
+
};
|
|
38
|
+
declare const clamp: {
|
|
39
|
+
(interval: Interval, value: number): number;
|
|
40
|
+
(value: number): (interval: Interval) => number;
|
|
41
|
+
(interval: Interval, value: ReadonlyArray<number>): ReadonlyArray<number>;
|
|
42
|
+
(value: ReadonlyArray<number>): (interval: Interval) => ReadonlyArray<number>;
|
|
43
|
+
};
|
|
44
|
+
declare const unit: Interval;
|
|
45
|
+
declare const biunit: Interval;
|
|
46
|
+
declare const lerp: (interval: Interval, t: number) => number;
|
|
47
|
+
declare const toLerpFn: (interval: Interval) => (t: number) => number;
|
|
48
|
+
declare const normalize: (interval: Interval, x: number) => number;
|
|
49
|
+
declare const toNormalizeFn: (interval: Interval) => (x: number) => number;
|
|
50
|
+
declare const remap: (source: Interval, target: Interval, x: number) => number;
|
|
51
|
+
declare const toRemapFn: (source: Interval, target: Interval) => (x: number) => number;
|
|
52
|
+
interface ScaleShift {
|
|
53
|
+
readonly scale: number;
|
|
54
|
+
readonly shift: number;
|
|
55
|
+
}
|
|
56
|
+
declare const scaleShift: (source: Interval, target: Interval) => ScaleShift;
|
|
57
|
+
|
|
58
|
+
export { type Interval, type ScaleShift, biunit, clamp, contains, filter, fromMinMax, fromSize, isInterval, lerp, make, normalize, remap, scaleShift, size, toLerpFn, toNormalizeFn, toRemapFn, unit };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { P as Pipeable } from './shared/curvy.BN-oFBsc.js';
|
|
2
|
+
|
|
3
|
+
interface Interval extends Pipeable {
|
|
4
|
+
readonly start: number;
|
|
5
|
+
readonly end: number;
|
|
6
|
+
}
|
|
7
|
+
declare const isInterval: (v: unknown) => v is Interval;
|
|
8
|
+
declare const make: {
|
|
9
|
+
(point: number): Interval;
|
|
10
|
+
(start: number, end: number): Interval;
|
|
11
|
+
};
|
|
12
|
+
declare const fromSize: {
|
|
13
|
+
(size: number): Interval;
|
|
14
|
+
(start: number, size: number): Interval;
|
|
15
|
+
};
|
|
16
|
+
declare const fromMinMax: (...values: ReadonlyArray<number>) => Interval;
|
|
17
|
+
declare const size: (i: Interval) => number;
|
|
18
|
+
declare const contains: {
|
|
19
|
+
(interval: Interval, value: number, options?: {
|
|
20
|
+
includeStart?: boolean;
|
|
21
|
+
includeEnd?: boolean;
|
|
22
|
+
}): boolean;
|
|
23
|
+
(value: number, options?: {
|
|
24
|
+
includeStart?: boolean;
|
|
25
|
+
includeEnd?: boolean;
|
|
26
|
+
}): (interval: Interval) => boolean;
|
|
27
|
+
};
|
|
28
|
+
declare const filter: {
|
|
29
|
+
<V extends ReadonlyArray<number>>(interval: Interval, value: V, options?: {
|
|
30
|
+
includeStart?: boolean;
|
|
31
|
+
includeEnd?: boolean;
|
|
32
|
+
}): V;
|
|
33
|
+
<V extends ReadonlyArray<number>>(value: V, options?: {
|
|
34
|
+
includeStart?: boolean;
|
|
35
|
+
includeEnd?: boolean;
|
|
36
|
+
}): (interval: Interval) => V;
|
|
37
|
+
};
|
|
38
|
+
declare const clamp: {
|
|
39
|
+
(interval: Interval, value: number): number;
|
|
40
|
+
(value: number): (interval: Interval) => number;
|
|
41
|
+
(interval: Interval, value: ReadonlyArray<number>): ReadonlyArray<number>;
|
|
42
|
+
(value: ReadonlyArray<number>): (interval: Interval) => ReadonlyArray<number>;
|
|
43
|
+
};
|
|
44
|
+
declare const unit: Interval;
|
|
45
|
+
declare const biunit: Interval;
|
|
46
|
+
declare const lerp: (interval: Interval, t: number) => number;
|
|
47
|
+
declare const toLerpFn: (interval: Interval) => (t: number) => number;
|
|
48
|
+
declare const normalize: (interval: Interval, x: number) => number;
|
|
49
|
+
declare const toNormalizeFn: (interval: Interval) => (x: number) => number;
|
|
50
|
+
declare const remap: (source: Interval, target: Interval, x: number) => number;
|
|
51
|
+
declare const toRemapFn: (source: Interval, target: Interval) => (x: number) => number;
|
|
52
|
+
interface ScaleShift {
|
|
53
|
+
readonly scale: number;
|
|
54
|
+
readonly shift: number;
|
|
55
|
+
}
|
|
56
|
+
declare const scaleShift: (source: Interval, target: Interval) => ScaleShift;
|
|
57
|
+
|
|
58
|
+
export { type Interval, type ScaleShift, biunit, clamp, contains, filter, fromMinMax, fromSize, isInterval, lerp, make, normalize, remap, scaleShift, size, toLerpFn, toNormalizeFn, toRemapFn, unit };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { d as dual, P as Pipeable, r as round } from './shared/curvy.ChkqgKuv.mjs';
|
|
2
|
+
|
|
3
|
+
const TypeId = Symbol.for("curvy/interval");
|
|
4
|
+
class IntervalImpl extends Pipeable {
|
|
5
|
+
[TypeId] = TypeId;
|
|
6
|
+
start;
|
|
7
|
+
end;
|
|
8
|
+
constructor(start = 0, end = start) {
|
|
9
|
+
super();
|
|
10
|
+
if (end < start) {
|
|
11
|
+
throw new Error("Interval end must be greater than or equal to start");
|
|
12
|
+
}
|
|
13
|
+
this.start = round(start);
|
|
14
|
+
this.end = round(end);
|
|
15
|
+
}
|
|
16
|
+
get [Symbol.toStringTag]() {
|
|
17
|
+
return `Interval [${this.start}, ${this.end}]`;
|
|
18
|
+
}
|
|
19
|
+
get [Symbol.for("nodejs.util.inspect.custom")]() {
|
|
20
|
+
return this[Symbol.toStringTag];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const isInterval$1 = (v) => typeof v === "object" && v !== null && TypeId in v;
|
|
24
|
+
const make$1 = (start, end) => new IntervalImpl(start, end ?? start);
|
|
25
|
+
const fromSize$1 = (a, b) => {
|
|
26
|
+
if (b === void 0) {
|
|
27
|
+
return new IntervalImpl(0, a);
|
|
28
|
+
}
|
|
29
|
+
return new IntervalImpl(a, a + b);
|
|
30
|
+
};
|
|
31
|
+
const fromMinMax$1 = (...values) => new IntervalImpl(Math.min(...values), Math.max(...values));
|
|
32
|
+
const size$1 = (i) => Math.abs(i.end - i.start);
|
|
33
|
+
const contains$1 = dual(
|
|
34
|
+
(args) => isInterval$1(args[0]),
|
|
35
|
+
(interval, value, { includeStart = true, includeEnd = true } = {}) => value > interval.start && value < interval.end || includeStart && value === interval.start || includeEnd && value === interval.end
|
|
36
|
+
);
|
|
37
|
+
const filter$1 = dual(
|
|
38
|
+
(args) => isInterval$1(args[0]),
|
|
39
|
+
(interval, value, options) => {
|
|
40
|
+
return value.filter((v) => contains$1(interval, v, options));
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
const clamp$1 = dual(
|
|
44
|
+
2,
|
|
45
|
+
(interval, value) => {
|
|
46
|
+
if (Array.isArray(value)) {
|
|
47
|
+
return value.map((v) => clamp$1(interval, v));
|
|
48
|
+
}
|
|
49
|
+
return contains$1(interval, value) ? value : value < interval.start ? interval.start : interval.end;
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
const unit$1 = make$1(0, 1);
|
|
53
|
+
const biunit$1 = make$1(-1, 1);
|
|
54
|
+
const lerp$1 = (interval, t) => (1 - t) * interval.start + t * interval.end;
|
|
55
|
+
const toLerpFn$1 = (interval) => (t) => lerp$1(interval, t);
|
|
56
|
+
const normalize$1 = (interval, x) => (x - interval.start) / size$1(interval);
|
|
57
|
+
const toNormalizeFn$1 = (interval) => (x) => normalize$1(interval, x);
|
|
58
|
+
const remap$1 = (source, target, x) => {
|
|
59
|
+
return target.start + (x - source.start) * size$1(target) / size$1(source);
|
|
60
|
+
};
|
|
61
|
+
const toRemapFn$1 = (source, target) => (x) => remap$1(source, target, x);
|
|
62
|
+
const scaleShift$1 = (source, target) => {
|
|
63
|
+
const scale = size$1(target) / size$1(source);
|
|
64
|
+
return {
|
|
65
|
+
scale,
|
|
66
|
+
shift: target.start - source.start * scale
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const isInterval = isInterval$1;
|
|
71
|
+
const make = make$1;
|
|
72
|
+
const fromSize = fromSize$1;
|
|
73
|
+
const fromMinMax = fromMinMax$1;
|
|
74
|
+
const size = size$1;
|
|
75
|
+
const contains = contains$1;
|
|
76
|
+
const filter = filter$1;
|
|
77
|
+
const clamp = clamp$1;
|
|
78
|
+
const unit = unit$1;
|
|
79
|
+
const biunit = biunit$1;
|
|
80
|
+
const lerp = lerp$1;
|
|
81
|
+
const toLerpFn = toLerpFn$1;
|
|
82
|
+
const normalize = normalize$1;
|
|
83
|
+
const toNormalizeFn = toNormalizeFn$1;
|
|
84
|
+
const remap = remap$1;
|
|
85
|
+
const toRemapFn = toRemapFn$1;
|
|
86
|
+
const scaleShift = scaleShift$1;
|
|
87
|
+
|
|
88
|
+
export { biunit, clamp, contains, filter, fromMinMax, fromSize, isInterval, lerp, make, normalize, remap, scaleShift, size, toLerpFn, toNormalizeFn, toRemapFn, unit };
|