@thi.ng/math 5.3.16 → 5.3.17
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/CHANGELOG.md +1 -1
- package/interval.d.ts +4 -4
- package/interval.js +4 -4
- package/mix.d.ts +20 -20
- package/mix.js +20 -20
- package/package.json +3 -3
- package/solve.d.ts +16 -17
- package/solve.js +16 -17
package/CHANGELOG.md
CHANGED
package/interval.d.ts
CHANGED
|
@@ -92,11 +92,11 @@ export declare const minNonZero3: FnN3;
|
|
|
92
92
|
*/
|
|
93
93
|
export declare const smin: FnN3;
|
|
94
94
|
/**
|
|
95
|
-
* Smooth maximum. Note: Result values will be slightly larger than max
|
|
96
|
-
*
|
|
97
|
-
*
|
|
95
|
+
* Smooth maximum. Note: Result values will be slightly larger than max value
|
|
96
|
+
* near max(a,b) + eps due to exponential decay. Higher `k` values reduce the
|
|
97
|
+
* error, but also reduce the smoothing. Recommended k=16.
|
|
98
98
|
*
|
|
99
|
-
*
|
|
99
|
+
* https://en.wikipedia.org/wiki/Smooth_maximum
|
|
100
100
|
*
|
|
101
101
|
* @param a -
|
|
102
102
|
* @param b -
|
package/interval.js
CHANGED
|
@@ -135,11 +135,11 @@ export const minNonZero3 = (a, b, c) => minNonZero2(minNonZero2(a, b), c);
|
|
|
135
135
|
*/
|
|
136
136
|
export const smin = (a, b, k) => smax(a, b, -k);
|
|
137
137
|
/**
|
|
138
|
-
* Smooth maximum. Note: Result values will be slightly larger than max
|
|
139
|
-
*
|
|
140
|
-
*
|
|
138
|
+
* Smooth maximum. Note: Result values will be slightly larger than max value
|
|
139
|
+
* near max(a,b) + eps due to exponential decay. Higher `k` values reduce the
|
|
140
|
+
* error, but also reduce the smoothing. Recommended k=16.
|
|
141
141
|
*
|
|
142
|
-
*
|
|
142
|
+
* https://en.wikipedia.org/wiki/Smooth_maximum
|
|
143
143
|
*
|
|
144
144
|
* @param a -
|
|
145
145
|
* @param b -
|
package/mix.d.ts
CHANGED
|
@@ -47,19 +47,19 @@ export declare const mixQuadratic: FnN4;
|
|
|
47
47
|
*/
|
|
48
48
|
export declare const mixCubic: FnN5;
|
|
49
49
|
/**
|
|
50
|
-
* Returns hermite interpolation of `a, b, c, d` at normalized position
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
50
|
+
* Returns hermite interpolation of `a, b, c, d` at normalized position `t`,
|
|
51
|
+
* where `a` and `d` are used as predecessor/successor of `b` / `c` and only
|
|
52
|
+
* inform the tangent of the interpolation curve. The interpolated result is
|
|
53
|
+
* that of `b` and `c`.
|
|
54
54
|
*
|
|
55
55
|
* Assumes all inputs are uniformly spaced. If that's not the case, use
|
|
56
56
|
* {@link mixCubicHermite} with one of the tangent generators supporting
|
|
57
57
|
* non-uniform spacing of points.
|
|
58
58
|
*
|
|
59
|
-
* See:
|
|
59
|
+
* See: https://www.desmos.com/calculator/j4gf8g9vkr
|
|
60
60
|
*
|
|
61
61
|
* Source:
|
|
62
|
-
*
|
|
62
|
+
* https://www.musicdsp.org/en/latest/Other/93-hermite-interpollation.html
|
|
63
63
|
*
|
|
64
64
|
* - {@link mixCubicHermite}
|
|
65
65
|
* - {@link tangentCardinal}
|
|
@@ -76,7 +76,7 @@ export declare const mixHermite: FnN5;
|
|
|
76
76
|
* Computes cubic-hermite interpolation between `a` / `b` at normalized
|
|
77
77
|
* time `t` and using respective tangents `ta` / `tb`.
|
|
78
78
|
*
|
|
79
|
-
*
|
|
79
|
+
* https://en.wikipedia.org/wiki/Cubic_Hermite_spline
|
|
80
80
|
*
|
|
81
81
|
* - {@link mixHermite}
|
|
82
82
|
* - {@link tangentCardinal}
|
|
@@ -130,14 +130,14 @@ export declare const mixCubicHermiteFromPoints: FnN5;
|
|
|
130
130
|
*/
|
|
131
131
|
export declare const mixBicubic: (s00: number, s01: number, s02: number, s03: number, s10: number, s11: number, s12: number, s13: number, s20: number, s21: number, s22: number, s23: number, s30: number, s31: number, s32: number, s33: number, u: number, v: number) => number;
|
|
132
132
|
/**
|
|
133
|
-
* Helper function for {@link mixCubicHermite}. Computes cardinal tangents
|
|
134
|
-
*
|
|
135
|
-
* (
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
133
|
+
* Helper function for {@link mixCubicHermite}. Computes cardinal tangents based
|
|
134
|
+
* on point neighbors of a point B (not given), i.e. `a` (predecessor) and `c`
|
|
135
|
+
* (successor) and their times (defaults to uniformly spaced). The optional
|
|
136
|
+
* `tension` parameter can be used to scale the tangent where 0.0 produces a
|
|
137
|
+
* Cardinal spline tangent and 1.0 a Catmull-Rom (opposite to the Wikipedia
|
|
138
|
+
* ref).
|
|
139
139
|
*
|
|
140
|
-
*
|
|
140
|
+
* https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Cardinal_spline
|
|
141
141
|
*
|
|
142
142
|
* @param prev -
|
|
143
143
|
* @param next -
|
|
@@ -148,15 +148,15 @@ export declare const mixBicubic: (s00: number, s01: number, s02: number, s03: nu
|
|
|
148
148
|
export declare const tangentCardinal: (prev: number, next: number, scale?: number, ta?: number, tc?: number) => number;
|
|
149
149
|
/**
|
|
150
150
|
* Helper function for {@link mixCubicHermite}. Computes tangent for `curr`,
|
|
151
|
-
* based on 3-point finite difference, where `prev` & `next` are
|
|
152
|
-
*
|
|
153
|
-
*
|
|
151
|
+
* based on 3-point finite difference, where `prev` & `next` are `curr`'s
|
|
152
|
+
* neighbors and the `tX` the three points' respective time values. The latter
|
|
153
|
+
* are equally spaced by default (each 1.0 apart).
|
|
154
154
|
*
|
|
155
155
|
* Using this function with equal spacing of 1.0 and together with
|
|
156
|
-
* {@link mixCubicHermite} will produce same results as the somewhat
|
|
157
|
-
*
|
|
156
|
+
* {@link mixCubicHermite} will produce same results as the somewhat optimized
|
|
157
|
+
* variant {@link mixHermite}.
|
|
158
158
|
*
|
|
159
|
-
*
|
|
159
|
+
* https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Finite_difference
|
|
160
160
|
*
|
|
161
161
|
* @param prev -
|
|
162
162
|
* @param curr -
|
package/mix.js
CHANGED
|
@@ -59,19 +59,19 @@ export const mixCubic = (a, b, c, d, t) => {
|
|
|
59
59
|
return a * s2 * s + b * 3 * s2 * t + c * 3 * t2 * s + d * t2 * t;
|
|
60
60
|
};
|
|
61
61
|
/**
|
|
62
|
-
* Returns hermite interpolation of `a, b, c, d` at normalized position
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
62
|
+
* Returns hermite interpolation of `a, b, c, d` at normalized position `t`,
|
|
63
|
+
* where `a` and `d` are used as predecessor/successor of `b` / `c` and only
|
|
64
|
+
* inform the tangent of the interpolation curve. The interpolated result is
|
|
65
|
+
* that of `b` and `c`.
|
|
66
66
|
*
|
|
67
67
|
* Assumes all inputs are uniformly spaced. If that's not the case, use
|
|
68
68
|
* {@link mixCubicHermite} with one of the tangent generators supporting
|
|
69
69
|
* non-uniform spacing of points.
|
|
70
70
|
*
|
|
71
|
-
* See:
|
|
71
|
+
* See: https://www.desmos.com/calculator/j4gf8g9vkr
|
|
72
72
|
*
|
|
73
73
|
* Source:
|
|
74
|
-
*
|
|
74
|
+
* https://www.musicdsp.org/en/latest/Other/93-hermite-interpollation.html
|
|
75
75
|
*
|
|
76
76
|
* - {@link mixCubicHermite}
|
|
77
77
|
* - {@link tangentCardinal}
|
|
@@ -92,7 +92,7 @@ export const mixHermite = (a, b, c, d, t) => {
|
|
|
92
92
|
* Computes cubic-hermite interpolation between `a` / `b` at normalized
|
|
93
93
|
* time `t` and using respective tangents `ta` / `tb`.
|
|
94
94
|
*
|
|
95
|
-
*
|
|
95
|
+
* https://en.wikipedia.org/wiki/Cubic_Hermite_spline
|
|
96
96
|
*
|
|
97
97
|
* - {@link mixHermite}
|
|
98
98
|
* - {@link tangentCardinal}
|
|
@@ -163,14 +163,14 @@ export const mixCubicHermiteFromPoints = (a, b, c, d, t) => {
|
|
|
163
163
|
*/
|
|
164
164
|
export const mixBicubic = (s00, s01, s02, s03, s10, s11, s12, s13, s20, s21, s22, s23, s30, s31, s32, s33, u, v) => mixCubicHermiteFromPoints(mixCubicHermiteFromPoints(s00, s01, s02, s03, u), mixCubicHermiteFromPoints(s10, s11, s12, s13, u), mixCubicHermiteFromPoints(s20, s21, s22, s23, u), mixCubicHermiteFromPoints(s30, s31, s32, s33, u), v);
|
|
165
165
|
/**
|
|
166
|
-
* Helper function for {@link mixCubicHermite}. Computes cardinal tangents
|
|
167
|
-
*
|
|
168
|
-
* (
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
166
|
+
* Helper function for {@link mixCubicHermite}. Computes cardinal tangents based
|
|
167
|
+
* on point neighbors of a point B (not given), i.e. `a` (predecessor) and `c`
|
|
168
|
+
* (successor) and their times (defaults to uniformly spaced). The optional
|
|
169
|
+
* `tension` parameter can be used to scale the tangent where 0.0 produces a
|
|
170
|
+
* Cardinal spline tangent and 1.0 a Catmull-Rom (opposite to the Wikipedia
|
|
171
|
+
* ref).
|
|
172
172
|
*
|
|
173
|
-
*
|
|
173
|
+
* https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Cardinal_spline
|
|
174
174
|
*
|
|
175
175
|
* @param prev -
|
|
176
176
|
* @param next -
|
|
@@ -181,15 +181,15 @@ export const mixBicubic = (s00, s01, s02, s03, s10, s11, s12, s13, s20, s21, s22
|
|
|
181
181
|
export const tangentCardinal = (prev, next, scale = 0.5, ta = 0, tc = 2) => scale * ((next - prev) / (tc - ta));
|
|
182
182
|
/**
|
|
183
183
|
* Helper function for {@link mixCubicHermite}. Computes tangent for `curr`,
|
|
184
|
-
* based on 3-point finite difference, where `prev` & `next` are
|
|
185
|
-
*
|
|
186
|
-
*
|
|
184
|
+
* based on 3-point finite difference, where `prev` & `next` are `curr`'s
|
|
185
|
+
* neighbors and the `tX` the three points' respective time values. The latter
|
|
186
|
+
* are equally spaced by default (each 1.0 apart).
|
|
187
187
|
*
|
|
188
188
|
* Using this function with equal spacing of 1.0 and together with
|
|
189
|
-
* {@link mixCubicHermite} will produce same results as the somewhat
|
|
190
|
-
*
|
|
189
|
+
* {@link mixCubicHermite} will produce same results as the somewhat optimized
|
|
190
|
+
* variant {@link mixHermite}.
|
|
191
191
|
*
|
|
192
|
-
*
|
|
192
|
+
* https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Finite_difference
|
|
193
193
|
*
|
|
194
194
|
* @param prev -
|
|
195
195
|
* @param curr -
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/math",
|
|
3
|
-
"version": "5.3.
|
|
3
|
+
"version": "5.3.17",
|
|
4
4
|
"description": "Assorted common math functions & utilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"test": "testament test"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@thi.ng/api": "^8.6.
|
|
40
|
+
"@thi.ng/api": "^8.6.1"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@microsoft/api-extractor": "^7.33.7",
|
|
@@ -135,5 +135,5 @@
|
|
|
135
135
|
"thi.ng": {
|
|
136
136
|
"year": 2013
|
|
137
137
|
},
|
|
138
|
-
"gitHead": "
|
|
138
|
+
"gitHead": "7b2af448da8a63fb21704a79cc4cdf1f3d7d7a64\n"
|
|
139
139
|
}
|
package/solve.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type { FnN2 } from "@thi.ng/api";
|
|
2
2
|
/**
|
|
3
|
-
* Produces a new function which computes derivative of the given
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* Produces a new function which computes derivative of the given single-arg
|
|
4
|
+
* function. The extra optional arg `eps` is used to define the step width for
|
|
5
|
+
* computing derived values:
|
|
6
6
|
*
|
|
7
7
|
* `f'(x) = (f(x + eps) - f(x)) / eps`
|
|
8
8
|
*
|
|
9
|
-
* The original function is assumed to be fully differentiable
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* The original function is assumed to be fully differentiable in the interval
|
|
10
|
+
* the returned function is going to be used. No validity checks of any form are
|
|
11
|
+
* done.
|
|
12
12
|
*
|
|
13
|
-
*
|
|
13
|
+
* https://en.wikipedia.org/wiki/Derivative#Continuity_and_differentiability
|
|
14
14
|
*
|
|
15
15
|
* @param fn -
|
|
16
16
|
* @param eps -
|
|
@@ -26,13 +26,12 @@ export declare const derivative: (f: (x: number) => number, eps?: number) => (x:
|
|
|
26
26
|
*/
|
|
27
27
|
export declare const solveLinear: FnN2;
|
|
28
28
|
/**
|
|
29
|
-
* Computes solutions for quadratic equation: `ax^2 + bx + c = 0`.
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* use {@link solveLinear} instead.
|
|
29
|
+
* Computes solutions for quadratic equation: `ax^2 + bx + c = 0`. Returns array
|
|
30
|
+
* of real solutions. Note: `a` MUST NOT be zero. If the quadratic term is
|
|
31
|
+
* missing, use {@link solveLinear} instead.
|
|
33
32
|
*
|
|
34
|
-
* -
|
|
35
|
-
* -
|
|
33
|
+
* - https://en.wikipedia.org/wiki/Quadratic_function
|
|
34
|
+
* - https://en.wikipedia.org/wiki/Quadratic_equation
|
|
36
35
|
*
|
|
37
36
|
* @param a - quadratic coefficient
|
|
38
37
|
* @param b - linear coefficient
|
|
@@ -42,11 +41,11 @@ export declare const solveLinear: FnN2;
|
|
|
42
41
|
export declare const solveQuadratic: (a: number, b: number, c: number, eps?: number) => number[];
|
|
43
42
|
/**
|
|
44
43
|
* Computes solutions for quadratic equation: `ax^3 + bx^2 + c*x + d = 0`.
|
|
45
|
-
* Returns array of solutions, both real & imaginary.
|
|
46
|
-
*
|
|
47
|
-
*
|
|
44
|
+
* Returns array of solutions, both real & imaginary. Note: `a` MUST NOT be
|
|
45
|
+
* zero. If the cubic term is missing (i.e. zero), use {@link solveQuadratic} or
|
|
46
|
+
* {@link solveLinear} instead.
|
|
48
47
|
*
|
|
49
|
-
*
|
|
48
|
+
* https://en.wikipedia.org/wiki/Cubic_function
|
|
50
49
|
*
|
|
51
50
|
* @param a - cubic coefficient
|
|
52
51
|
* @param b - quadratic coefficient
|
package/solve.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { EPS } from "./api.js";
|
|
2
2
|
import { safeDiv } from "./safe-div.js";
|
|
3
3
|
/**
|
|
4
|
-
* Produces a new function which computes derivative of the given
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Produces a new function which computes derivative of the given single-arg
|
|
5
|
+
* function. The extra optional arg `eps` is used to define the step width for
|
|
6
|
+
* computing derived values:
|
|
7
7
|
*
|
|
8
8
|
* `f'(x) = (f(x + eps) - f(x)) / eps`
|
|
9
9
|
*
|
|
10
|
-
* The original function is assumed to be fully differentiable
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* The original function is assumed to be fully differentiable in the interval
|
|
11
|
+
* the returned function is going to be used. No validity checks of any form are
|
|
12
|
+
* done.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
14
|
+
* https://en.wikipedia.org/wiki/Derivative#Continuity_and_differentiability
|
|
15
15
|
*
|
|
16
16
|
* @param fn -
|
|
17
17
|
* @param eps -
|
|
@@ -27,13 +27,12 @@ export const derivative = (f, eps = EPS) => (x) => (f(x + eps) - f(x)) / eps;
|
|
|
27
27
|
*/
|
|
28
28
|
export const solveLinear = (a, b) => safeDiv(-b, a);
|
|
29
29
|
/**
|
|
30
|
-
* Computes solutions for quadratic equation: `ax^2 + bx + c = 0`.
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* use {@link solveLinear} instead.
|
|
30
|
+
* Computes solutions for quadratic equation: `ax^2 + bx + c = 0`. Returns array
|
|
31
|
+
* of real solutions. Note: `a` MUST NOT be zero. If the quadratic term is
|
|
32
|
+
* missing, use {@link solveLinear} instead.
|
|
34
33
|
*
|
|
35
|
-
* -
|
|
36
|
-
* -
|
|
34
|
+
* - https://en.wikipedia.org/wiki/Quadratic_function
|
|
35
|
+
* - https://en.wikipedia.org/wiki/Quadratic_equation
|
|
37
36
|
*
|
|
38
37
|
* @param a - quadratic coefficient
|
|
39
38
|
* @param b - linear coefficient
|
|
@@ -51,11 +50,11 @@ export const solveQuadratic = (a, b, c, eps = 1e-9) => {
|
|
|
51
50
|
};
|
|
52
51
|
/**
|
|
53
52
|
* Computes solutions for quadratic equation: `ax^3 + bx^2 + c*x + d = 0`.
|
|
54
|
-
* Returns array of solutions, both real & imaginary.
|
|
55
|
-
*
|
|
56
|
-
*
|
|
53
|
+
* Returns array of solutions, both real & imaginary. Note: `a` MUST NOT be
|
|
54
|
+
* zero. If the cubic term is missing (i.e. zero), use {@link solveQuadratic} or
|
|
55
|
+
* {@link solveLinear} instead.
|
|
57
56
|
*
|
|
58
|
-
*
|
|
57
|
+
* https://en.wikipedia.org/wiki/Cubic_function
|
|
59
58
|
*
|
|
60
59
|
* @param a - cubic coefficient
|
|
61
60
|
* @param b - quadratic coefficient
|