curvy 1.0.7 → 1.0.9
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/dist/curve/cubic2d.d.mts +80 -2
- package/dist/curve/cubic2d.d.ts +80 -2
- package/dist/curve/cubic2d.mjs +9 -26
- package/dist/curve/cubic2d.mjs.map +1 -0
- package/dist/curve/linear2d.d.mts +68 -2
- package/dist/curve/linear2d.d.ts +68 -2
- package/dist/curve/linear2d.mjs +11 -14
- package/dist/curve/linear2d.mjs.map +1 -0
- package/dist/curve/quadratic2d.d.mts +86 -2
- package/dist/curve/quadratic2d.d.ts +86 -2
- package/dist/curve/quadratic2d.mjs +10 -15
- package/dist/curve/quadratic2d.mjs.map +1 -0
- package/dist/interval.d.mts +195 -2
- package/dist/interval.d.ts +195 -2
- package/dist/interval.mjs +9 -12
- package/dist/interval.mjs.map +1 -0
- package/dist/matrix/matrix2x2.d.mts +273 -2
- package/dist/matrix/matrix2x2.d.ts +273 -2
- package/dist/matrix/matrix2x2.mjs +5 -4
- package/dist/matrix/matrix2x2.mjs.map +1 -0
- package/dist/matrix/matrix3x3.d.mts +308 -1
- package/dist/matrix/matrix3x3.d.ts +308 -1
- package/dist/matrix/matrix3x3.mjs +5 -4
- package/dist/matrix/matrix3x3.mjs.map +1 -0
- package/dist/matrix/matrix4x4.d.mts +310 -1
- package/dist/matrix/matrix4x4.d.ts +310 -1
- package/dist/matrix/matrix4x4.mjs +24 -61
- package/dist/matrix/matrix4x4.mjs.map +1 -0
- package/dist/path/cubic2d.d.mts +68 -2
- package/dist/path/cubic2d.d.ts +68 -2
- package/dist/path/cubic2d.mjs +10 -12
- package/dist/path/cubic2d.mjs.map +1 -0
- package/dist/path/linear2d.d.mts +68 -2
- package/dist/path/linear2d.d.ts +68 -2
- package/dist/path/linear2d.mjs +7 -9
- package/dist/path/linear2d.mjs.map +1 -0
- package/dist/path/quadratic2d.d.mts +67 -2
- package/dist/path/quadratic2d.d.ts +67 -2
- package/dist/path/quadratic2d.mjs +9 -13
- package/dist/path/quadratic2d.mjs.map +1 -0
- package/dist/pipe.mjs +1 -0
- package/dist/pipe.mjs.map +1 -0
- package/dist/polynomial/cubic.d.mts +1 -1
- package/dist/polynomial/cubic.d.ts +1 -1
- package/dist/polynomial/cubic.mjs +13 -28
- package/dist/polynomial/cubic.mjs.map +1 -0
- package/dist/polynomial/linear.d.mts +1 -1
- package/dist/polynomial/linear.d.ts +1 -1
- package/dist/polynomial/linear.mjs +2 -1
- package/dist/polynomial/linear.mjs.map +1 -0
- package/dist/polynomial/quadratic.d.mts +2 -2
- package/dist/polynomial/quadratic.d.ts +2 -2
- package/dist/polynomial/quadratic.mjs +5 -2
- package/dist/polynomial/quadratic.mjs.map +1 -0
- package/dist/shared/{curvy.Cps2R_RU.mjs → curvy.BkkW8Tx9.mjs} +11 -29
- package/dist/shared/curvy.BkkW8Tx9.mjs.map +1 -0
- package/dist/shared/{curvy.BzVmUIKm.mjs → curvy.BxdGW9he.mjs} +17 -32
- package/dist/shared/curvy.BxdGW9he.mjs.map +1 -0
- package/dist/shared/{curvy.C2XGH0R0.mjs → curvy.C_sCeg9J.mjs} +15 -24
- package/dist/shared/curvy.C_sCeg9J.mjs.map +1 -0
- package/dist/shared/curvy.Cg8lZVUz.d.ts +688 -0
- package/dist/shared/{curvy.CE4X6_Is.mjs → curvy.DCt1gGII.mjs} +11 -45
- package/dist/shared/curvy.DCt1gGII.mjs.map +1 -0
- package/dist/shared/{curvy.BZ_mTkJe.mjs → curvy.DJ4xO0al.mjs} +9 -6
- package/dist/shared/curvy.DJ4xO0al.mjs.map +1 -0
- package/dist/shared/curvy.DmVFTi0N.mjs +1 -0
- package/dist/shared/curvy.DmVFTi0N.mjs.map +1 -0
- package/dist/shared/curvy.FDaj5rlj.d.mts +688 -0
- package/dist/shared/{curvy.NLeFCr-9.mjs → curvy.lktriTpx.mjs} +19 -42
- package/dist/shared/curvy.lktriTpx.mjs.map +1 -0
- package/dist/shared/{curvy.Ck0of1PI.mjs → curvy.mLFprrGm.mjs} +26 -22
- package/dist/shared/curvy.mLFprrGm.mjs.map +1 -0
- package/dist/shared/{curvy.BDhiZ7He.mjs → curvy.r6f1j287.mjs} +8 -12
- package/dist/shared/curvy.r6f1j287.mjs.map +1 -0
- package/dist/splines/basis2d.d.mts +94 -2
- package/dist/splines/basis2d.d.ts +94 -2
- package/dist/splines/basis2d.mjs +13 -12
- package/dist/splines/basis2d.mjs.map +1 -0
- package/dist/splines/bezier2d.d.mts +136 -2
- package/dist/splines/bezier2d.d.ts +136 -2
- package/dist/splines/bezier2d.mjs +10 -9
- package/dist/splines/bezier2d.mjs.map +1 -0
- package/dist/splines/cardinal2d.d.mts +131 -2
- package/dist/splines/cardinal2d.d.ts +131 -2
- package/dist/splines/cardinal2d.mjs +15 -24
- package/dist/splines/cardinal2d.mjs.map +1 -0
- package/dist/splines/hermite2d.d.mts +94 -3
- package/dist/splines/hermite2d.d.ts +94 -3
- package/dist/splines/hermite2d.mjs +22 -36
- package/dist/splines/hermite2d.mjs.map +1 -0
- package/dist/utils.d.mts +179 -1
- package/dist/utils.d.ts +179 -1
- package/dist/utils.mjs +16 -7
- package/dist/utils.mjs.map +1 -0
- package/dist/vector/vector2.d.mts +259 -1
- package/dist/vector/vector2.d.ts +259 -1
- package/dist/vector/vector2.mjs +4 -2
- package/dist/vector/vector2.mjs.map +1 -0
- package/dist/vector/vector3.d.mts +345 -1
- package/dist/vector/vector3.d.ts +345 -1
- package/dist/vector/vector3.mjs +9 -2
- package/dist/vector/vector3.mjs.map +1 -0
- package/dist/vector/vector4.d.mts +163 -1
- package/dist/vector/vector4.d.ts +163 -1
- package/dist/vector/vector4.mjs +4 -2
- package/dist/vector/vector4.mjs.map +1 -0
- package/package.json +4 -4
- package/dist/shared/curvy.BsHoYJNv.d.ts +0 -155
- package/dist/shared/curvy.NsmY7zcr.d.mts +0 -155
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { T as TwoDimensional } from '../shared/curvy.Bf5TIk31.mjs';
|
|
2
2
|
import { Interval } from '../interval.mjs';
|
|
3
3
|
import { Pipeable } from '../pipe.mjs';
|
|
4
|
-
import { Q as QuadraticPolynomial } from '../shared/curvy.
|
|
4
|
+
import { Q as QuadraticPolynomial } from '../shared/curvy.FDaj5rlj.mjs';
|
|
5
5
|
import { Vector2 } from '../vector/vector2.mjs';
|
|
6
6
|
import { LinearCurve2d } from './linear2d.mjs';
|
|
7
7
|
import '../vector/vector3.mjs';
|
|
@@ -10,24 +10,108 @@ import '../vector/vector4.mjs';
|
|
|
10
10
|
declare const QuadraticCurve2dTypeId: unique symbol;
|
|
11
11
|
type QuadraticCurve2dTypeId = typeof QuadraticCurve2dTypeId;
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* A quadratic curve in 2D space.
|
|
15
|
+
*
|
|
16
|
+
* All fields are readonly and immutable, and all operations create new instances.
|
|
17
|
+
*
|
|
18
|
+
* @since 1.0.0
|
|
19
|
+
*/
|
|
13
20
|
interface QuadraticCurve2d extends Pipeable, TwoDimensional<QuadraticPolynomial> {
|
|
14
21
|
readonly [QuadraticCurve2dTypeId]: QuadraticCurve2dTypeId;
|
|
15
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new `QuadraticCurve2d` instance from polynomial parameters.
|
|
25
|
+
*
|
|
26
|
+
* @param c0 - The x polynomial.
|
|
27
|
+
* @param c1 - The y polynomial.
|
|
28
|
+
* @returns A new `QuadraticCurve2d` instance.
|
|
29
|
+
* @since 1.0.0
|
|
30
|
+
*/
|
|
16
31
|
declare const fromPolynomials: (c0: QuadraticPolynomial, c1: QuadraticPolynomial) => QuadraticCurve2d;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a new `QuadraticCurve2d` instance from pairs of coefficients.
|
|
34
|
+
*
|
|
35
|
+
* @param p0 - The x^0 coefficients for the x and y polynomials.
|
|
36
|
+
* @param p1 - The x^1 coefficients for the x and y polynomials.
|
|
37
|
+
* @param p2 - The x^2 coefficients for the x and y polynomials.
|
|
38
|
+
* @returns A new `QuadraticCurve2d` instance.
|
|
39
|
+
* @since 1.0.0
|
|
40
|
+
*/
|
|
17
41
|
declare const fromPoints: (p0: Vector2, p1: Vector2, p2: Vector2) => QuadraticCurve2d;
|
|
42
|
+
/**
|
|
43
|
+
* Checks if a value is a `QuadraticCurve2d`.
|
|
44
|
+
*
|
|
45
|
+
* @param c - The value to check.
|
|
46
|
+
* @returns `true` if the value is a `QuadraticCurve2d`, `false` otherwise.
|
|
47
|
+
* @since 1.0.0
|
|
48
|
+
*/
|
|
18
49
|
declare const isQuadraticCurve2d: (c: unknown) => c is QuadraticCurve2d;
|
|
19
50
|
declare const solve: {
|
|
51
|
+
/**
|
|
52
|
+
* Solves the quadratic curve for a given parameter t.
|
|
53
|
+
*
|
|
54
|
+
* @param t - The parameter value.
|
|
55
|
+
* @returns A function that takes a quadratic curve and returns the point on the curve at parameter t.
|
|
56
|
+
* @since 1.0.0
|
|
57
|
+
*/
|
|
20
58
|
(t: number): (c: QuadraticCurve2d) => Vector2;
|
|
59
|
+
/**
|
|
60
|
+
* Solves the quadratic curve for a given parameter t.
|
|
61
|
+
*
|
|
62
|
+
* @param c - The quadratic curve to solve.
|
|
63
|
+
* @param t - The parameter value.
|
|
64
|
+
* @returns The point on the curve at parameter t.
|
|
65
|
+
* @since 1.0.0
|
|
66
|
+
*/
|
|
21
67
|
(c: QuadraticCurve2d, t: number): Vector2;
|
|
22
68
|
};
|
|
23
69
|
declare const length: {
|
|
70
|
+
/**
|
|
71
|
+
* Computes the length of the quadratic curve over a given interval.
|
|
72
|
+
*
|
|
73
|
+
* @param c - The quadratic curve to compute the length of.
|
|
74
|
+
* @param i - The interval over which to compute the length.
|
|
75
|
+
* @returns The length of the quadratic curve over the interval.
|
|
76
|
+
* @since 1.0.0
|
|
77
|
+
*/
|
|
24
78
|
(c: QuadraticCurve2d, i: Interval): number;
|
|
79
|
+
/**
|
|
80
|
+
* Computes the length of the quadratic curve over a given interval.
|
|
81
|
+
*
|
|
82
|
+
* @param i - The interval over which to compute the length.
|
|
83
|
+
* @returns A function that takes a quadratic curve and returns the length of the curve over the interval.
|
|
84
|
+
* @since 1.0.0
|
|
85
|
+
*/
|
|
25
86
|
(i: Interval): (c: QuadraticCurve2d) => number;
|
|
26
87
|
};
|
|
88
|
+
/**
|
|
89
|
+
* Computes the derivative of a quadratic curve.
|
|
90
|
+
*
|
|
91
|
+
* @param c - The quadratic curve to compute the derivative of.
|
|
92
|
+
* @returns The derivative of the quadratic curve as a linear curve.
|
|
93
|
+
* @since 1.0.0
|
|
94
|
+
*/
|
|
27
95
|
declare const derivative: (c: QuadraticCurve2d) => LinearCurve2d;
|
|
28
96
|
declare const curvature: {
|
|
97
|
+
/**
|
|
98
|
+
* Computes the curvature of the quadratic curve at a given parameter t.
|
|
99
|
+
*
|
|
100
|
+
* @param c - The quadratic curve to compute the curvature for.
|
|
101
|
+
* @param t - The parameter value.
|
|
102
|
+
* @returns The curvature of the quadratic curve at parameter t.
|
|
103
|
+
* @since 1.0.0
|
|
104
|
+
*/
|
|
29
105
|
(c: QuadraticCurve2d, t: number): number;
|
|
106
|
+
/**
|
|
107
|
+
* Computes the curvature of the quadratic curve at a given parameter t.
|
|
108
|
+
*
|
|
109
|
+
* @param t - The parameter value.
|
|
110
|
+
* @returns A function that takes a quadratic curve and returns the curvature of the curve at parameter t.
|
|
111
|
+
* @since 1.0.0
|
|
112
|
+
*/
|
|
30
113
|
(t: number): (c: QuadraticCurve2d) => number;
|
|
31
114
|
};
|
|
32
115
|
|
|
33
|
-
export {
|
|
116
|
+
export { curvature, derivative, fromPoints, fromPolynomials, isQuadraticCurve2d, length, solve };
|
|
117
|
+
export type { QuadraticCurve2d };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { T as TwoDimensional } from '../shared/curvy.Bf5TIk31.js';
|
|
2
2
|
import { Interval } from '../interval.js';
|
|
3
3
|
import { Pipeable } from '../pipe.js';
|
|
4
|
-
import { Q as QuadraticPolynomial } from '../shared/curvy.
|
|
4
|
+
import { Q as QuadraticPolynomial } from '../shared/curvy.Cg8lZVUz.js';
|
|
5
5
|
import { Vector2 } from '../vector/vector2.js';
|
|
6
6
|
import { LinearCurve2d } from './linear2d.js';
|
|
7
7
|
import '../vector/vector3.js';
|
|
@@ -10,24 +10,108 @@ import '../vector/vector4.js';
|
|
|
10
10
|
declare const QuadraticCurve2dTypeId: unique symbol;
|
|
11
11
|
type QuadraticCurve2dTypeId = typeof QuadraticCurve2dTypeId;
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* A quadratic curve in 2D space.
|
|
15
|
+
*
|
|
16
|
+
* All fields are readonly and immutable, and all operations create new instances.
|
|
17
|
+
*
|
|
18
|
+
* @since 1.0.0
|
|
19
|
+
*/
|
|
13
20
|
interface QuadraticCurve2d extends Pipeable, TwoDimensional<QuadraticPolynomial> {
|
|
14
21
|
readonly [QuadraticCurve2dTypeId]: QuadraticCurve2dTypeId;
|
|
15
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new `QuadraticCurve2d` instance from polynomial parameters.
|
|
25
|
+
*
|
|
26
|
+
* @param c0 - The x polynomial.
|
|
27
|
+
* @param c1 - The y polynomial.
|
|
28
|
+
* @returns A new `QuadraticCurve2d` instance.
|
|
29
|
+
* @since 1.0.0
|
|
30
|
+
*/
|
|
16
31
|
declare const fromPolynomials: (c0: QuadraticPolynomial, c1: QuadraticPolynomial) => QuadraticCurve2d;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a new `QuadraticCurve2d` instance from pairs of coefficients.
|
|
34
|
+
*
|
|
35
|
+
* @param p0 - The x^0 coefficients for the x and y polynomials.
|
|
36
|
+
* @param p1 - The x^1 coefficients for the x and y polynomials.
|
|
37
|
+
* @param p2 - The x^2 coefficients for the x and y polynomials.
|
|
38
|
+
* @returns A new `QuadraticCurve2d` instance.
|
|
39
|
+
* @since 1.0.0
|
|
40
|
+
*/
|
|
17
41
|
declare const fromPoints: (p0: Vector2, p1: Vector2, p2: Vector2) => QuadraticCurve2d;
|
|
42
|
+
/**
|
|
43
|
+
* Checks if a value is a `QuadraticCurve2d`.
|
|
44
|
+
*
|
|
45
|
+
* @param c - The value to check.
|
|
46
|
+
* @returns `true` if the value is a `QuadraticCurve2d`, `false` otherwise.
|
|
47
|
+
* @since 1.0.0
|
|
48
|
+
*/
|
|
18
49
|
declare const isQuadraticCurve2d: (c: unknown) => c is QuadraticCurve2d;
|
|
19
50
|
declare const solve: {
|
|
51
|
+
/**
|
|
52
|
+
* Solves the quadratic curve for a given parameter t.
|
|
53
|
+
*
|
|
54
|
+
* @param t - The parameter value.
|
|
55
|
+
* @returns A function that takes a quadratic curve and returns the point on the curve at parameter t.
|
|
56
|
+
* @since 1.0.0
|
|
57
|
+
*/
|
|
20
58
|
(t: number): (c: QuadraticCurve2d) => Vector2;
|
|
59
|
+
/**
|
|
60
|
+
* Solves the quadratic curve for a given parameter t.
|
|
61
|
+
*
|
|
62
|
+
* @param c - The quadratic curve to solve.
|
|
63
|
+
* @param t - The parameter value.
|
|
64
|
+
* @returns The point on the curve at parameter t.
|
|
65
|
+
* @since 1.0.0
|
|
66
|
+
*/
|
|
21
67
|
(c: QuadraticCurve2d, t: number): Vector2;
|
|
22
68
|
};
|
|
23
69
|
declare const length: {
|
|
70
|
+
/**
|
|
71
|
+
* Computes the length of the quadratic curve over a given interval.
|
|
72
|
+
*
|
|
73
|
+
* @param c - The quadratic curve to compute the length of.
|
|
74
|
+
* @param i - The interval over which to compute the length.
|
|
75
|
+
* @returns The length of the quadratic curve over the interval.
|
|
76
|
+
* @since 1.0.0
|
|
77
|
+
*/
|
|
24
78
|
(c: QuadraticCurve2d, i: Interval): number;
|
|
79
|
+
/**
|
|
80
|
+
* Computes the length of the quadratic curve over a given interval.
|
|
81
|
+
*
|
|
82
|
+
* @param i - The interval over which to compute the length.
|
|
83
|
+
* @returns A function that takes a quadratic curve and returns the length of the curve over the interval.
|
|
84
|
+
* @since 1.0.0
|
|
85
|
+
*/
|
|
25
86
|
(i: Interval): (c: QuadraticCurve2d) => number;
|
|
26
87
|
};
|
|
88
|
+
/**
|
|
89
|
+
* Computes the derivative of a quadratic curve.
|
|
90
|
+
*
|
|
91
|
+
* @param c - The quadratic curve to compute the derivative of.
|
|
92
|
+
* @returns The derivative of the quadratic curve as a linear curve.
|
|
93
|
+
* @since 1.0.0
|
|
94
|
+
*/
|
|
27
95
|
declare const derivative: (c: QuadraticCurve2d) => LinearCurve2d;
|
|
28
96
|
declare const curvature: {
|
|
97
|
+
/**
|
|
98
|
+
* Computes the curvature of the quadratic curve at a given parameter t.
|
|
99
|
+
*
|
|
100
|
+
* @param c - The quadratic curve to compute the curvature for.
|
|
101
|
+
* @param t - The parameter value.
|
|
102
|
+
* @returns The curvature of the quadratic curve at parameter t.
|
|
103
|
+
* @since 1.0.0
|
|
104
|
+
*/
|
|
29
105
|
(c: QuadraticCurve2d, t: number): number;
|
|
106
|
+
/**
|
|
107
|
+
* Computes the curvature of the quadratic curve at a given parameter t.
|
|
108
|
+
*
|
|
109
|
+
* @param t - The parameter value.
|
|
110
|
+
* @returns A function that takes a quadratic curve and returns the curvature of the curve at parameter t.
|
|
111
|
+
* @since 1.0.0
|
|
112
|
+
*/
|
|
30
113
|
(t: number): (c: QuadraticCurve2d) => number;
|
|
31
114
|
};
|
|
32
115
|
|
|
33
|
-
export {
|
|
116
|
+
export { curvature, derivative, fromPoints, fromPolynomials, isQuadraticCurve2d, length, solve };
|
|
117
|
+
export type { QuadraticCurve2d };
|
|
@@ -6,19 +6,16 @@ import { make, solve as solve$2, derivative as derivative$2 } from '../polynomia
|
|
|
6
6
|
import { round } from '../utils.mjs';
|
|
7
7
|
import { make as make$1, magnitude, cross } from '../vector/vector2.mjs';
|
|
8
8
|
import { fromPolynomials as fromPolynomials$2, length as length$2, solve as solve$3, derivative as derivative$3 } from './linear2d.mjs';
|
|
9
|
-
import '../shared/curvy.
|
|
10
|
-
import '../shared/curvy.
|
|
11
|
-
import '../shared/curvy.
|
|
9
|
+
import '../shared/curvy.r6f1j287.mjs';
|
|
10
|
+
import '../shared/curvy.BxdGW9he.mjs';
|
|
11
|
+
import '../shared/curvy.DJ4xO0al.mjs';
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
)
|
|
16
|
-
class QuadraticCurve2dImpl extends Pipeable {
|
|
17
|
-
[QuadraticCurve2dTypeId] = QuadraticCurve2dTypeId;
|
|
18
|
-
x;
|
|
19
|
-
y;
|
|
13
|
+
var _a, _b;
|
|
14
|
+
const QuadraticCurve2dTypeId = Symbol("curvy/curve/quadratic2d");
|
|
15
|
+
class QuadraticCurve2dImpl extends (_b = Pipeable, _a = QuadraticCurve2dTypeId, _b) {
|
|
20
16
|
constructor(c0, c1) {
|
|
21
17
|
super();
|
|
18
|
+
this[_a] = QuadraticCurve2dTypeId;
|
|
22
19
|
this.x = c0;
|
|
23
20
|
this.y = c1;
|
|
24
21
|
}
|
|
@@ -37,10 +34,7 @@ const fromPoints$1 = (p0, p1, p2) => new QuadraticCurve2dImpl(
|
|
|
37
34
|
const isQuadraticCurve2d$1 = (c) => typeof c === "object" && c !== null && QuadraticCurve2dTypeId in c;
|
|
38
35
|
const solve$1 = dual(
|
|
39
36
|
2,
|
|
40
|
-
(c, t) => make$1(
|
|
41
|
-
solve$2(c.x, t),
|
|
42
|
-
solve$2(c.y, t)
|
|
43
|
-
)
|
|
37
|
+
(c, t) => make$1(solve$2(c.x, t), solve$2(c.y, t))
|
|
44
38
|
);
|
|
45
39
|
const derivative$1 = (c) => fromPolynomials$2(
|
|
46
40
|
derivative$2(c.x),
|
|
@@ -62,7 +56,7 @@ const length$1 = dual(2, (c, i) => {
|
|
|
62
56
|
const d = derivative$1(c);
|
|
63
57
|
const { scale, shift } = scaleShift(biunit, i);
|
|
64
58
|
return round(
|
|
65
|
-
(GL32_W0 * magnitude(solve$3(d, shift + scale * -
|
|
59
|
+
(GL32_W0 * magnitude(solve$3(d, shift + scale * -0.9972638618494816)) + GL32_W0 * magnitude(solve$3(d, shift + scale * GL32_X0)) + GL32_W1 * magnitude(solve$3(d, shift + scale * -0.9856115115452684)) + GL32_W1 * magnitude(solve$3(d, shift + scale * GL32_X1)) + GL32_W2 * magnitude(solve$3(d, shift + scale * -0.9647622555875064)) + GL32_W2 * magnitude(solve$3(d, shift + scale * GL32_X2)) + GL32_W3 * magnitude(solve$3(d, shift + scale * -0.9349060759377397)) + GL32_W3 * magnitude(solve$3(d, shift + scale * GL32_X3)) + GL32_W4 * magnitude(solve$3(d, shift + scale * -0.8963211557660521)) + GL32_W4 * magnitude(solve$3(d, shift + scale * GL32_X4)) + GL32_W5 * magnitude(solve$3(d, shift + scale * -0.84936761373257)) + GL32_W5 * magnitude(solve$3(d, shift + scale * GL32_X5)) + GL32_W6 * magnitude(solve$3(d, shift + scale * -0.7944837959679424)) + GL32_W6 * magnitude(solve$3(d, shift + scale * GL32_X6)) + GL32_W7 * magnitude(solve$3(d, shift + scale * -0.7321821187402897)) + GL32_W7 * magnitude(solve$3(d, shift + scale * GL32_X7)) + GL32_W8 * magnitude(solve$3(d, shift + scale * -0.6630442669302152)) + GL32_W8 * magnitude(solve$3(d, shift + scale * GL32_X8)) + GL32_W9 * magnitude(solve$3(d, shift + scale * -0.5877157572407623)) + GL32_W9 * magnitude(solve$3(d, shift + scale * GL32_X9)) + GL32_W10 * magnitude(solve$3(d, shift + scale * -0.5068999089322294)) + GL32_W10 * magnitude(solve$3(d, shift + scale * GL32_X10)) + GL32_W11 * magnitude(solve$3(d, shift + scale * -0.42135127613063533)) + GL32_W11 * magnitude(solve$3(d, shift + scale * GL32_X11)) + GL32_W12 * magnitude(solve$3(d, shift + scale * -0.33186860228212767)) + GL32_W12 * magnitude(solve$3(d, shift + scale * GL32_X12)) + GL32_W13 * magnitude(solve$3(d, shift + scale * -0.23928736225213706)) + GL32_W13 * magnitude(solve$3(d, shift + scale * GL32_X13)) + GL32_W14 * magnitude(solve$3(d, shift + scale * -0.1444719615827965)) + GL32_W14 * magnitude(solve$3(d, shift + scale * GL32_X14)) + GL32_W15 * magnitude(solve$3(d, shift + scale * -0.04830766568773831)) + GL32_W15 * magnitude(solve$3(d, shift + scale * GL32_X15))) * scale
|
|
66
60
|
);
|
|
67
61
|
});
|
|
68
62
|
const curvature$1 = dual(2, (c, t) => {
|
|
@@ -85,3 +79,4 @@ const derivative = derivative$1;
|
|
|
85
79
|
const curvature = curvature$1;
|
|
86
80
|
|
|
87
81
|
export { curvature, derivative, fromPoints, fromPolynomials, isQuadraticCurve2d, length, solve };
|
|
82
|
+
//# sourceMappingURL=quadratic2d.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quadratic2d.mjs","sources":["../../src/curve/quadratic2d.internal.ts","../../src/curve/quadratic2d.ts"],"sourcesContent":["import * as Interval from '../interval'\nimport {\n GL32_W0,\n GL32_W1,\n GL32_W2,\n GL32_W3,\n GL32_W4,\n GL32_W5,\n GL32_W6,\n GL32_W7,\n GL32_W8,\n GL32_W9,\n GL32_W10,\n GL32_W11,\n GL32_W12,\n GL32_W13,\n GL32_W14,\n GL32_W15,\n GL32_X0,\n GL32_X1,\n GL32_X2,\n GL32_X3,\n GL32_X4,\n GL32_X5,\n GL32_X6,\n GL32_X7,\n GL32_X8,\n GL32_X9,\n GL32_X10,\n GL32_X11,\n GL32_X12,\n GL32_X13,\n GL32_X14,\n GL32_X15,\n} from '../length'\nimport { Pipeable } from '../pipe'\nimport { dual } from '../pipe'\nimport * as LinearPolynomial from '../polynomial/linear'\nimport * as QuadraticPolynomial from '../polynomial/quadratic'\nimport { round } from '../utils'\nimport * as Vector2 from '../vector/vector2'\nimport * as LinearCurve2d from './linear2d'\nimport type { QuadraticCurve2d } from './quadratic2d'\n\nexport const QuadraticCurve2dTypeId: unique symbol = Symbol('curvy/curve/quadratic2d')\nexport type QuadraticCurve2dTypeId = typeof QuadraticCurve2dTypeId\n\nexport class QuadraticCurve2dImpl extends Pipeable implements QuadraticCurve2d {\n readonly [QuadraticCurve2dTypeId]: QuadraticCurve2dTypeId = QuadraticCurve2dTypeId\n\n readonly x: QuadraticPolynomial.QuadraticPolynomial\n readonly y: QuadraticPolynomial.QuadraticPolynomial\n\n constructor(\n c0: QuadraticPolynomial.QuadraticPolynomial,\n c1: QuadraticPolynomial.QuadraticPolynomial,\n ) {\n super()\n this.x = c0\n this.y = c1\n }\n\n get [0]() {\n return this.x\n }\n\n get [1]() {\n return this.y\n }\n}\n\nexport const fromPolynomials: (\n c0: QuadraticPolynomial.QuadraticPolynomial,\n c1: QuadraticPolynomial.QuadraticPolynomial,\n) => QuadraticCurve2d = (c0, c1) => new QuadraticCurve2dImpl(c0, c1)\n\nexport const fromPoints: (\n p0: Vector2.Vector2,\n p1: Vector2.Vector2,\n p2: Vector2.Vector2,\n) => QuadraticCurve2d = (p0, p1, p2) =>\n new QuadraticCurve2dImpl(\n QuadraticPolynomial.make(p0.x, p1.x, p2.x),\n QuadraticPolynomial.make(p0.y, p1.y, p2.y),\n )\n\nexport const isQuadraticCurve2d = (c: unknown): c is QuadraticCurve2d =>\n typeof c === 'object' && c !== null && QuadraticCurve2dTypeId in c\n\nexport const solve = dual<\n (t: number) => (c: QuadraticCurve2d) => Vector2.Vector2,\n (c: QuadraticCurve2d, t: number) => Vector2.Vector2\n>(2, (c: QuadraticCurve2d, t: number) =>\n Vector2.make(QuadraticPolynomial.solve(c.x, t), QuadraticPolynomial.solve(c.y, t)),\n)\n\nexport const derivative = (c: QuadraticCurve2d) =>\n LinearCurve2d.fromPolynomials(\n QuadraticPolynomial.derivative(c.x),\n QuadraticPolynomial.derivative(c.y),\n )\n\nexport const length = dual(2, (c: QuadraticCurve2d, i: Interval.Interval) => {\n if (Interval.size(i) === 0) {\n return 0\n }\n\n if (c.x.c2 === 0 && c.y.c2 === 0) {\n return LinearCurve2d.length(\n LinearCurve2d.fromPolynomials(\n LinearPolynomial.make(c.x.c0, c.x.c1),\n LinearPolynomial.make(c.y.c0, c.y.c1),\n ),\n i,\n )\n }\n\n const d = derivative(c)\n\n const { scale, shift } = Interval.scaleShift(Interval.biunit, i)\n\n return round(\n (GL32_W0 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * -GL32_X0)) +\n GL32_W0 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * GL32_X0)) +\n GL32_W1 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * -GL32_X1)) +\n GL32_W1 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * GL32_X1)) +\n GL32_W2 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * -GL32_X2)) +\n GL32_W2 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * GL32_X2)) +\n GL32_W3 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * -GL32_X3)) +\n GL32_W3 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * GL32_X3)) +\n GL32_W4 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * -GL32_X4)) +\n GL32_W4 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * GL32_X4)) +\n GL32_W5 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * -GL32_X5)) +\n GL32_W5 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * GL32_X5)) +\n GL32_W6 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * -GL32_X6)) +\n GL32_W6 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * GL32_X6)) +\n GL32_W7 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * -GL32_X7)) +\n GL32_W7 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * GL32_X7)) +\n GL32_W8 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * -GL32_X8)) +\n GL32_W8 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * GL32_X8)) +\n GL32_W9 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * -GL32_X9)) +\n GL32_W9 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * GL32_X9)) +\n GL32_W10 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * -GL32_X10)) +\n GL32_W10 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * GL32_X10)) +\n GL32_W11 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * -GL32_X11)) +\n GL32_W11 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * GL32_X11)) +\n GL32_W12 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * -GL32_X12)) +\n GL32_W12 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * GL32_X12)) +\n GL32_W13 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * -GL32_X13)) +\n GL32_W13 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * GL32_X13)) +\n GL32_W14 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * -GL32_X14)) +\n GL32_W14 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * GL32_X14)) +\n GL32_W15 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * -GL32_X15)) +\n GL32_W15 * Vector2.magnitude(LinearCurve2d.solve(d, shift + scale * GL32_X15))) *\n scale,\n )\n})\n\nexport const curvature = dual(2, (c: QuadraticCurve2d, t: number) => {\n const d = derivative(c)\n const v = LinearCurve2d.solve(d, t)\n const a = LinearCurve2d.derivative(d)\n\n const vMag = Vector2.magnitude(v)\n\n if (vMag === 0) {\n return 0\n }\n\n return round(Math.abs(Vector2.cross(v, a)) / vMag ** 3)\n})\n","import type { TwoDimensional } from '../dimensions'\nimport type { Interval } from '../interval'\nimport type { Pipeable } from '../pipe'\nimport type { QuadraticPolynomial } from '../polynomial/quadratic'\nimport type { Vector2 } from '../vector/vector2'\nimport type { LinearCurve2d } from './linear2d'\nimport type { QuadraticCurve2dTypeId } from './quadratic2d.internal'\nimport * as internal from './quadratic2d.internal'\n\n/**\n * A quadratic curve in 2D space.\n *\n * All fields are readonly and immutable, and all operations create new instances.\n *\n * @since 1.0.0\n */\nexport interface QuadraticCurve2d extends Pipeable, TwoDimensional<QuadraticPolynomial> {\n readonly [QuadraticCurve2dTypeId]: QuadraticCurve2dTypeId\n}\n\n/**\n * Creates a new `QuadraticCurve2d` instance from polynomial parameters.\n *\n * @param c0 - The x polynomial.\n * @param c1 - The y polynomial.\n * @returns A new `QuadraticCurve2d` instance.\n * @since 1.0.0\n */\nexport const fromPolynomials: (\n c0: QuadraticPolynomial,\n c1: QuadraticPolynomial,\n) => QuadraticCurve2d = internal.fromPolynomials\n\n/**\n * Creates a new `QuadraticCurve2d` instance from pairs of coefficients.\n *\n * @param p0 - The x^0 coefficients for the x and y polynomials.\n * @param p1 - The x^1 coefficients for the x and y polynomials.\n * @param p2 - The x^2 coefficients for the x and y polynomials.\n * @returns A new `QuadraticCurve2d` instance.\n * @since 1.0.0\n */\nexport const fromPoints: (p0: Vector2, p1: Vector2, p2: Vector2) => QuadraticCurve2d =\n internal.fromPoints\n\n/**\n * Checks if a value is a `QuadraticCurve2d`.\n *\n * @param c - The value to check.\n * @returns `true` if the value is a `QuadraticCurve2d`, `false` otherwise.\n * @since 1.0.0\n */\nexport const isQuadraticCurve2d: (c: unknown) => c is QuadraticCurve2d = internal.isQuadraticCurve2d\n\nexport const solve: {\n /**\n * Solves the quadratic curve for a given parameter t.\n *\n * @param t - The parameter value.\n * @returns A function that takes a quadratic curve and returns the point on the curve at parameter t.\n * @since 1.0.0\n */\n (t: number): (c: QuadraticCurve2d) => Vector2\n /**\n * Solves the quadratic curve for a given parameter t.\n *\n * @param c - The quadratic curve to solve.\n * @param t - The parameter value.\n * @returns The point on the curve at parameter t.\n * @since 1.0.0\n */\n (c: QuadraticCurve2d, t: number): Vector2\n} = internal.solve\n\nexport const length: {\n /**\n * Computes the length of the quadratic curve over a given interval.\n *\n * @param c - The quadratic curve to compute the length of.\n * @param i - The interval over which to compute the length.\n * @returns The length of the quadratic curve over the interval.\n * @since 1.0.0\n */\n (c: QuadraticCurve2d, i: Interval): number\n /**\n * Computes the length of the quadratic curve over a given interval.\n *\n * @param i - The interval over which to compute the length.\n * @returns A function that takes a quadratic curve and returns the length of the curve over the interval.\n * @since 1.0.0\n */\n (i: Interval): (c: QuadraticCurve2d) => number\n} = internal.length\n\n/**\n * Computes the derivative of a quadratic curve.\n *\n * @param c - The quadratic curve to compute the derivative of.\n * @returns The derivative of the quadratic curve as a linear curve.\n * @since 1.0.0\n */\nexport const derivative: (c: QuadraticCurve2d) => LinearCurve2d = internal.derivative\n\nexport const curvature: {\n /**\n * Computes the curvature of the quadratic curve at a given parameter t.\n *\n * @param c - The quadratic curve to compute the curvature for.\n * @param t - The parameter value.\n * @returns The curvature of the quadratic curve at parameter t.\n * @since 1.0.0\n */\n (c: QuadraticCurve2d, t: number): number\n /**\n * Computes the curvature of the quadratic curve at a given parameter t.\n *\n * @param t - The parameter value.\n * @returns A function that takes a quadratic curve and returns the curvature of the curve at parameter t.\n * @since 1.0.0\n */\n (t: number): (c: QuadraticCurve2d) => number\n} = internal.curvature\n"],"names":["fromPolynomials","fromPoints","QuadraticPolynomial.make","isQuadraticCurve2d","solve","Vector2.make","QuadraticPolynomial.solve","derivative","LinearCurve2d.fromPolynomials","QuadraticPolynomial.derivative","length","Interval.size","LinearCurve2d.length","LinearPolynomial.make","Interval.scaleShift","Interval.biunit","Vector2.magnitude","LinearCurve2d.solve","curvature","LinearCurve2d.derivative","Vector2.cross","internal.fromPolynomials","internal.fromPoints","internal.isQuadraticCurve2d","internal.solve","internal.length","internal.derivative","internal.curvature"],"mappings":";;;;;;;;;;;;AAAA,IAAA,EAAA,EAAA,EAAA;AA4Ca,MAAA,sBAAA,GAAwC,OAAO,yBAAyB,CAAA;AAGxE,MAAA,oBAAA,UAA6B,EAC9B,GAAA,QAAA,EAAA,EAAA,GAAA,sBAAA,EAD8B,EAAqC,EAAA;AAAA,EAM7E,WAAA,CACE,IACA,EACA,EAAA;AACA,IAAM,KAAA,EAAA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,CAAC,CAAA;AACtB,EAAA,MAAM,CAAI,GAAAU,OAAoB,CAAA,CAAA,EAAG,CAAC,CAAA;AAClC,EAAM,MAAA,CAAA,GAAIE,YAAc,CAAW,CAAC,CAAA;AAEpC,EAAM,MAAA,IAAA,GAAOH,SAAQ,CAAU,CAAC,CAAA;AAEhC,EAAA,IAAI,SAAS,CAAG,EAAA;AACd,IAAO,OAAA,CAAA;AAAA;AAGT,EAAO,OAAA,KAAA,CAAM,IAAK,CAAA,GAAA,CAAII,KAAQ,CAAM,GAAG,CAAC,CAAC,CAAI,GAAA,IAAA,IAAQ,CAAC,CAAA;AACxD,CAAC,CAAA;;AC9IM,MAAM,kBAGWC;AAWjB,MAAM,aACXC;AASK,MAAM,qBAA4DC;AAElE,MAAM,QAkBTC;AAEG,MAAM,SAkBTC;AASG,MAAM,aAAqDC;AAE3D,MAAM,YAkBTC;;;;"}
|
package/dist/interval.d.mts
CHANGED
|
@@ -1,58 +1,251 @@
|
|
|
1
1
|
import { Pipeable } from './pipe.mjs';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* A mathematical interval.
|
|
5
|
+
*
|
|
6
|
+
* All fields are readonly and immutable, and all operations create new instances.
|
|
7
|
+
*
|
|
8
|
+
* @since 1.0.0
|
|
9
|
+
*/
|
|
3
10
|
interface Interval extends Pipeable {
|
|
4
11
|
readonly start: number;
|
|
5
12
|
readonly end: number;
|
|
6
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Checks if a value is an `Interval`.
|
|
16
|
+
*
|
|
17
|
+
* @param v - The value to check.
|
|
18
|
+
* @returns `true` if the value is an `Interval`, `false` otherwise.
|
|
19
|
+
* @since 1.0.0
|
|
20
|
+
*/
|
|
7
21
|
declare const isInterval: (v: unknown) => v is Interval;
|
|
8
22
|
declare const make: {
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new `Interval` instance.
|
|
25
|
+
*
|
|
26
|
+
* @param point - The point of the interval.
|
|
27
|
+
* @returns A new `Interval` instance.
|
|
28
|
+
* @since 1.0.0
|
|
29
|
+
*/
|
|
9
30
|
(point: number): Interval;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a new `Interval` instance.
|
|
33
|
+
*
|
|
34
|
+
* @param start - The start of the interval.
|
|
35
|
+
* @param end - The end of the interval.
|
|
36
|
+
* @returns A new `Interval` instance.
|
|
37
|
+
* @since 1.0.0
|
|
38
|
+
*/
|
|
10
39
|
(start: number, end: number): Interval;
|
|
11
40
|
};
|
|
12
41
|
declare const fromSize: {
|
|
42
|
+
/**
|
|
43
|
+
* Creates a new `Interval` instance from a size.
|
|
44
|
+
*
|
|
45
|
+
* @param size - The size of the interval.
|
|
46
|
+
* @returns A new `Interval` instance.
|
|
47
|
+
* @since 1.0.0
|
|
48
|
+
*/
|
|
13
49
|
(size: number): Interval;
|
|
50
|
+
/**
|
|
51
|
+
* Creates a new `Interval` instance from a size.
|
|
52
|
+
*
|
|
53
|
+
* @param size - The size of the interval.
|
|
54
|
+
* @param start - The start of the interval.
|
|
55
|
+
* @returns A new `Interval` instance.
|
|
56
|
+
* @since 1.0.0
|
|
57
|
+
*/
|
|
14
58
|
(start: number, size: number): Interval;
|
|
15
59
|
};
|
|
60
|
+
/**
|
|
61
|
+
* Creates a new `Interval` instance from a minimum and maximum value.
|
|
62
|
+
*
|
|
63
|
+
* @param values - The minimum and maximum values of the interval.
|
|
64
|
+
* @returns A new `Interval` instance.
|
|
65
|
+
* @since 1.0.0
|
|
66
|
+
*/
|
|
16
67
|
declare const fromMinMax: (...values: ReadonlyArray<number>) => Interval;
|
|
68
|
+
/**
|
|
69
|
+
* Calculates the size of an interval.
|
|
70
|
+
*
|
|
71
|
+
* @param interval - The interval to calculate the size of.
|
|
72
|
+
* @returns The size of the interval.
|
|
73
|
+
* @since 1.0.0
|
|
74
|
+
*/
|
|
17
75
|
declare const size: (i: Interval) => number;
|
|
18
76
|
declare const contains: {
|
|
77
|
+
/**
|
|
78
|
+
* Checks if a value is contained within an interval.
|
|
79
|
+
*
|
|
80
|
+
* @param interval - The interval to check.
|
|
81
|
+
* @param value - The value to check.
|
|
82
|
+
* @param options - Options for the check.
|
|
83
|
+
* @returns `true` if the value is contained within the interval, `false` otherwise.
|
|
84
|
+
* @since 1.0.0
|
|
85
|
+
*/
|
|
19
86
|
(interval: Interval, value: number, options?: {
|
|
20
87
|
includeStart?: boolean;
|
|
21
88
|
includeEnd?: boolean;
|
|
22
89
|
}): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Checks if a value is contained within an interval.
|
|
92
|
+
*
|
|
93
|
+
* @param value - The value to check.
|
|
94
|
+
* @param options - Options for the check.
|
|
95
|
+
* @returns A function that takes an interval and returns `true` if the value is contained within the interval, `false` otherwise.
|
|
96
|
+
* @since 1.0.0
|
|
97
|
+
*/
|
|
23
98
|
(value: number, options?: {
|
|
24
99
|
includeStart?: boolean;
|
|
25
100
|
includeEnd?: boolean;
|
|
26
101
|
}): (interval: Interval) => boolean;
|
|
27
102
|
};
|
|
28
103
|
declare const filter: {
|
|
104
|
+
/**
|
|
105
|
+
* Filters a value to be within an interval.
|
|
106
|
+
*
|
|
107
|
+
* @param interval - The interval to filter the value to.
|
|
108
|
+
* @param value - The value to filter.
|
|
109
|
+
* @param options - Options for the filter.
|
|
110
|
+
* @returns The filtered value.
|
|
111
|
+
* @since 1.0.0
|
|
112
|
+
*/
|
|
29
113
|
<V extends ReadonlyArray<number>>(interval: Interval, value: V, options?: {
|
|
30
114
|
includeStart?: boolean;
|
|
31
115
|
includeEnd?: boolean;
|
|
32
116
|
}): V;
|
|
117
|
+
/**
|
|
118
|
+
* Filters a value to be within an interval.
|
|
119
|
+
*
|
|
120
|
+
* @param value - The value to filter.
|
|
121
|
+
* @param options - Options for the filter.
|
|
122
|
+
* @returns A function that takes an interval and returns the filtered value.
|
|
123
|
+
* @since 1.0.0
|
|
124
|
+
*/
|
|
33
125
|
<V extends ReadonlyArray<number>>(value: V, options?: {
|
|
34
126
|
includeStart?: boolean;
|
|
35
127
|
includeEnd?: boolean;
|
|
36
128
|
}): (interval: Interval) => V;
|
|
37
129
|
};
|
|
38
130
|
declare const clamp: {
|
|
131
|
+
/**
|
|
132
|
+
* Clamps a value to be within an interval.
|
|
133
|
+
*
|
|
134
|
+
* @param interval - The interval to clamp the value to.
|
|
135
|
+
* @param value - The value to clamp.
|
|
136
|
+
* @returns The clamped value.
|
|
137
|
+
* @since 1.0.0
|
|
138
|
+
*/
|
|
39
139
|
(interval: Interval, value: number): number;
|
|
140
|
+
/**
|
|
141
|
+
* Clamps a value to be within an interval.
|
|
142
|
+
*
|
|
143
|
+
* @param value - The value to clamp.
|
|
144
|
+
* @returns A function that takes an interval and returns the clamped value.
|
|
145
|
+
* @since 1.0.0
|
|
146
|
+
*/
|
|
40
147
|
(value: number): (interval: Interval) => number;
|
|
148
|
+
/**
|
|
149
|
+
* Clamps an array of values to be within an interval.
|
|
150
|
+
*
|
|
151
|
+
* @param interval - The interval to clamp the values to.
|
|
152
|
+
* @param value - The values to clamp.
|
|
153
|
+
* @returns The clamped values.
|
|
154
|
+
* @since 1.0.0
|
|
155
|
+
*/
|
|
41
156
|
(interval: Interval, value: ReadonlyArray<number>): ReadonlyArray<number>;
|
|
157
|
+
/**
|
|
158
|
+
* Clamps an array of values to be within an interval.
|
|
159
|
+
*
|
|
160
|
+
* @param value - The values to clamp.
|
|
161
|
+
* @returns A function that takes an interval and returns the clamped values.
|
|
162
|
+
* @since 1.0.0
|
|
163
|
+
*/
|
|
42
164
|
(value: ReadonlyArray<number>): (interval: Interval) => ReadonlyArray<number>;
|
|
43
165
|
};
|
|
166
|
+
/**
|
|
167
|
+
* The unit interval, which is the interval [0, 1].
|
|
168
|
+
*
|
|
169
|
+
* @since 1.0.0
|
|
170
|
+
*/
|
|
44
171
|
declare const unit: Interval;
|
|
172
|
+
/**
|
|
173
|
+
* The biunit interval, which is the interval [-1, 1].
|
|
174
|
+
*
|
|
175
|
+
* @since 1.0.0
|
|
176
|
+
*/
|
|
45
177
|
declare const biunit: Interval;
|
|
178
|
+
/**
|
|
179
|
+
* Linearly interpolates a value within an interval.
|
|
180
|
+
*
|
|
181
|
+
* @param interval - The interval to interpolate within.
|
|
182
|
+
* @param t - The interpolation factor, typically between 0 and 1.
|
|
183
|
+
* @returns The interpolated value.
|
|
184
|
+
* @since 1.0.0
|
|
185
|
+
*/
|
|
46
186
|
declare const lerp: (interval: Interval, t: number) => number;
|
|
187
|
+
/**
|
|
188
|
+
* Creates a linear interpolation function for an interval.
|
|
189
|
+
*
|
|
190
|
+
* @param interval - The interval to create the interpolation function for.
|
|
191
|
+
* @returns A function that takes a factor `t` and returns the interpolated value.
|
|
192
|
+
* @since 1.0.0
|
|
193
|
+
*/
|
|
47
194
|
declare const toLerpFn: (interval: Interval) => (t: number) => number;
|
|
195
|
+
/**
|
|
196
|
+
* Normalizes a value within an interval.
|
|
197
|
+
*
|
|
198
|
+
* @param interval - The interval to normalize within.
|
|
199
|
+
* @param x - The value to normalize.
|
|
200
|
+
* @returns The normalized value.
|
|
201
|
+
* @since 1.0.0
|
|
202
|
+
*/
|
|
48
203
|
declare const normalize: (interval: Interval, x: number) => number;
|
|
204
|
+
/**
|
|
205
|
+
* Creates a normalization function for an interval.
|
|
206
|
+
*
|
|
207
|
+
* @param interval - The interval to create the normalization function for.
|
|
208
|
+
* @returns A function that takes a value `x` and returns the normalized value.
|
|
209
|
+
* @since 1.0.0
|
|
210
|
+
*/
|
|
49
211
|
declare const toNormalizeFn: (interval: Interval) => (x: number) => number;
|
|
212
|
+
/**
|
|
213
|
+
* Remaps a value from one interval to another.
|
|
214
|
+
*
|
|
215
|
+
* @param source - The source interval.
|
|
216
|
+
* @param target - The target interval.
|
|
217
|
+
* @param x - The value to remap.
|
|
218
|
+
* @returns The remapped value.
|
|
219
|
+
* @since 1.0.0
|
|
220
|
+
*/
|
|
50
221
|
declare const remap: (source: Interval, target: Interval, x: number) => number;
|
|
222
|
+
/**
|
|
223
|
+
* Creates a remapping function for an interval.
|
|
224
|
+
*
|
|
225
|
+
* @param source - The source interval.
|
|
226
|
+
* @param target - The target interval.
|
|
227
|
+
* @returns A function that takes a value `x` and returns the remapped value.
|
|
228
|
+
* @since 1.0.0
|
|
229
|
+
*/
|
|
51
230
|
declare const toRemapFn: (source: Interval, target: Interval) => (x: number) => number;
|
|
231
|
+
/**
|
|
232
|
+
* Calculates the scale and shift needed to map a source interval to a target interval.
|
|
233
|
+
*
|
|
234
|
+
* @param source - The source interval.
|
|
235
|
+
* @param target - The target interval.
|
|
236
|
+
* @returns An object containing the scale and shift values.
|
|
237
|
+
* @since 1.0.0
|
|
238
|
+
*/
|
|
239
|
+
declare const scaleShift: (source: Interval, target: Interval) => ScaleShift;
|
|
240
|
+
/**
|
|
241
|
+
* The scale and shift needed to map a source interval to a target interval.
|
|
242
|
+
*
|
|
243
|
+
* @since 1.0.0
|
|
244
|
+
*/
|
|
52
245
|
interface ScaleShift {
|
|
53
246
|
readonly scale: number;
|
|
54
247
|
readonly shift: number;
|
|
55
248
|
}
|
|
56
|
-
declare const scaleShift: (source: Interval, target: Interval) => ScaleShift;
|
|
57
249
|
|
|
58
|
-
export {
|
|
250
|
+
export { biunit, clamp, contains, filter, fromMinMax, fromSize, isInterval, lerp, make, normalize, remap, scaleShift, size, toLerpFn, toNormalizeFn, toRemapFn, unit };
|
|
251
|
+
export type { Interval, ScaleShift };
|