@thi.ng/math 5.11.34 → 5.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -1
- package/README.md +1 -1
- package/mix.d.ts +90 -2
- package/mix.js +33 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2025-
|
|
3
|
+
- **Last updated**: 2025-09-01T16:38:35Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -11,6 +11,17 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
11
11
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
12
12
|
and/or version bumps of transitive dependencies.
|
|
13
13
|
|
|
14
|
+
## [5.12.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/math@5.12.0) (2025-09-01)
|
|
15
|
+
|
|
16
|
+
#### 🚀 Features
|
|
17
|
+
|
|
18
|
+
- add `mixTrilinear()` ([5914ced](https://github.com/thi-ng/umbrella/commit/5914ced))
|
|
19
|
+
- add/update interpolation fns ([91e8fbd](https://github.com/thi-ng/umbrella/commit/91e8fbd))
|
|
20
|
+
- add defLanczos(), defMitchell()
|
|
21
|
+
- add mixKernel4()
|
|
22
|
+
- add interactive Desmos graphs
|
|
23
|
+
- update docs
|
|
24
|
+
|
|
14
25
|
## [5.11.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/math@5.11.0) (2024-06-21)
|
|
15
26
|
|
|
16
27
|
#### 🚀 Features
|
package/README.md
CHANGED
package/mix.d.ts
CHANGED
|
@@ -27,8 +27,43 @@ export declare const mix: FnN3;
|
|
|
27
27
|
* @param v - 2nd interpolation factor
|
|
28
28
|
*/
|
|
29
29
|
export declare const mixBilinear: FnN6;
|
|
30
|
+
/**
|
|
31
|
+
* Trilinear interpolation of given values (`a`..`h`) with interpolation factors
|
|
32
|
+
* `u`,`v`,`w` (in `[0,1]` range).
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```text
|
|
36
|
+
* c +-------+ d
|
|
37
|
+
* |\ :\
|
|
38
|
+
* | \ : \
|
|
39
|
+
* |g +-------+ h
|
|
40
|
+
* | | : |
|
|
41
|
+
* a +··|····+ b|
|
|
42
|
+
* \ | \ |
|
|
43
|
+
* \| \|
|
|
44
|
+
* e +-------+ f
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @param a
|
|
48
|
+
* @param b
|
|
49
|
+
* @param c
|
|
50
|
+
* @param d
|
|
51
|
+
* @param e
|
|
52
|
+
* @param f
|
|
53
|
+
* @param g
|
|
54
|
+
* @param h
|
|
55
|
+
* @param u
|
|
56
|
+
* @param v
|
|
57
|
+
* @param w
|
|
58
|
+
*/
|
|
59
|
+
export declare const mixTrilinear: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, u: number, v: number, w: number) => number;
|
|
30
60
|
/**
|
|
31
61
|
* Computes quadratic bezier interpolation for normalized value `t`.
|
|
62
|
+
* Interpolated result is between end points `a` and `c` with `b` a control
|
|
63
|
+
* point.
|
|
64
|
+
*
|
|
65
|
+
* @remarks
|
|
66
|
+
* [Interactive graph](https://www.desmos.com/calculator/s3cvphot1o)
|
|
32
67
|
*
|
|
33
68
|
* @param a
|
|
34
69
|
* @param b
|
|
@@ -37,7 +72,11 @@ export declare const mixBilinear: FnN6;
|
|
|
37
72
|
*/
|
|
38
73
|
export declare const mixQuadratic: FnN4;
|
|
39
74
|
/**
|
|
40
|
-
* Computes cubic bezier interpolation for normalized value `t`.
|
|
75
|
+
* Computes cubic bezier interpolation for normalized value `t`. Interpolated
|
|
76
|
+
* result is between end points `a` and `d` with `b` and `c` control points.
|
|
77
|
+
*
|
|
78
|
+
* @remarks
|
|
79
|
+
* [Interactive graph](https://www.desmos.com/calculator/dfc6twzlmk)
|
|
41
80
|
*
|
|
42
81
|
* @param a
|
|
43
82
|
* @param b
|
|
@@ -52,6 +91,7 @@ export declare const mixCubic: FnN5;
|
|
|
52
91
|
* inform the tangent of the interpolation curve. The interpolated result is
|
|
53
92
|
* that of `b` and `c`.
|
|
54
93
|
*
|
|
94
|
+
* @remarks
|
|
55
95
|
* Assumes all inputs are uniformly spaced. If that's not the case, use
|
|
56
96
|
* {@link mixCubicHermite} with one of the tangent generators supporting
|
|
57
97
|
* non-uniform spacing of points.
|
|
@@ -129,6 +169,27 @@ export declare const mixCubicHermiteFromPoints: FnN5;
|
|
|
129
169
|
* @param v -
|
|
130
170
|
*/
|
|
131
171
|
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;
|
|
172
|
+
/**
|
|
173
|
+
* Parametric interpolation function for 4 samples `a`...`d` and interpolation
|
|
174
|
+
* `kernel` and factor `t`. The interpolation is assumed to be between `b` and
|
|
175
|
+
* `c`, using `a` and `d` as neighbors. Interpolation factor `t` is in the [0,1]
|
|
176
|
+
* range.
|
|
177
|
+
*
|
|
178
|
+
* @remarks
|
|
179
|
+
* The `kernel` is avaluated for 4 different `t`s @ `t-1`, `t`, `t+1`, `t+2`
|
|
180
|
+
* (corresponding to samples `a`..`d`).
|
|
181
|
+
*
|
|
182
|
+
* This function can be used with e.g. {@link defLanczos} (filter radius=2) or
|
|
183
|
+
* {@link defMitchell}.
|
|
184
|
+
*
|
|
185
|
+
* @param kernel
|
|
186
|
+
* @param a
|
|
187
|
+
* @param b
|
|
188
|
+
* @param c
|
|
189
|
+
* @param d
|
|
190
|
+
* @param t
|
|
191
|
+
*/
|
|
192
|
+
export declare const mixKernel4: (kernel: FnN, a: number, b: number, c: number, d: number, t: number) => number;
|
|
132
193
|
/**
|
|
133
194
|
* Helper function for {@link mixCubicHermite}. Computes cardinal tangents based
|
|
134
195
|
* on point neighbors of a point B (not given), i.e. `a` (predecessor) and `c`
|
|
@@ -318,12 +379,39 @@ export declare const sincNormalized: FnN2;
|
|
|
318
379
|
* returns 0.
|
|
319
380
|
*
|
|
320
381
|
* @remarks
|
|
321
|
-
*
|
|
382
|
+
* References:
|
|
383
|
+
*
|
|
384
|
+
* - [Interactive graph](https://www.desmos.com/calculator/ccpog9yol8)
|
|
385
|
+
* - https://en.wikipedia.org/wiki/Lanczos_resampling
|
|
322
386
|
*
|
|
323
387
|
* @param a -
|
|
324
388
|
* @param t -
|
|
325
389
|
*/
|
|
326
390
|
export declare const lanczos: FnN2;
|
|
391
|
+
/**
|
|
392
|
+
* Higher-order version of {@link lanczos} for filter size `a` (should be 1, 2
|
|
393
|
+
* or 3). Returns function which takes single param `t` and computes its Lanczos
|
|
394
|
+
* filter coefficient.
|
|
395
|
+
*
|
|
396
|
+
* @param a
|
|
397
|
+
*/
|
|
398
|
+
export declare const defLanczos: (a: number) => FnN;
|
|
399
|
+
/**
|
|
400
|
+
* Higher-order Mitchell-Netravali filter kernel for params `b` and `c`. Returns
|
|
401
|
+
* function which takes single param `t` and computes its filter coefficient.
|
|
402
|
+
*
|
|
403
|
+
* @remarks
|
|
404
|
+
* Default `b` and `c` values are: b=1/3, c=1/3. The returned function can be
|
|
405
|
+
* used with {@link mixKernel4}.
|
|
406
|
+
*
|
|
407
|
+
* References:
|
|
408
|
+
*
|
|
409
|
+
* - https://en.wikipedia.org/wiki/Mitchell%E2%80%93Netravali_filters
|
|
410
|
+
*
|
|
411
|
+
* @param b
|
|
412
|
+
* @param c
|
|
413
|
+
*/
|
|
414
|
+
export declare const defMitchell: (b?: number, c?: number) => (t: number) => number;
|
|
327
415
|
/**
|
|
328
416
|
* Sigmoid function for inputs arounds center bias.
|
|
329
417
|
*
|
package/mix.js
CHANGED
|
@@ -5,6 +5,16 @@ const mixBilinear = (a, b, c, d, u, v) => {
|
|
|
5
5
|
const iv = 1 - v;
|
|
6
6
|
return a * iu * iv + b * u * iv + c * iu * v + d * u * v;
|
|
7
7
|
};
|
|
8
|
+
const mixTrilinear = (a, b, c, d, e, f, g, h, u, v, w) => {
|
|
9
|
+
const iu = 1 - u;
|
|
10
|
+
const iv = 1 - v;
|
|
11
|
+
const iw = 1 - w;
|
|
12
|
+
const uv = u * v;
|
|
13
|
+
const u_iv = u * iv;
|
|
14
|
+
const iu_v = iu * v;
|
|
15
|
+
const iuv = iu * iv;
|
|
16
|
+
return a * iuv * iw + b * u_iv * iw + c * iu_v * iw + d * uv * iw + e * iuv * w + f * u_iv * w + g * iu_v * w + h * uv * w;
|
|
17
|
+
};
|
|
8
18
|
const mixQuadratic = (a, b, c, t) => {
|
|
9
19
|
const s = 1 - t;
|
|
10
20
|
return a * s * s + b * 2 * s * t + c * t * t;
|
|
@@ -46,6 +56,7 @@ const mixBicubic = (s00, s01, s02, s03, s10, s11, s12, s13, s20, s21, s22, s23,
|
|
|
46
56
|
mixCubicHermiteFromPoints(s30, s31, s32, s33, u),
|
|
47
57
|
v
|
|
48
58
|
);
|
|
59
|
+
const mixKernel4 = (kernel, a, b, c, d, t) => a * kernel(t + 1) + b * kernel(t) + c * kernel(t - 1) + d * kernel(t - 2);
|
|
49
60
|
const tangentCardinal = (prev, next, scale = 0.5, ta = 0, tc = 2) => scale * ((next - prev) / (tc - ta));
|
|
50
61
|
const tangentDiff3 = (prev, curr, next, ta = 0, tb = 1, tc = 2) => 0.5 * ((next - curr) / (tc - tb) + (curr - prev) / (tb - ta));
|
|
51
62
|
const tween = (f, from, to) => (t) => mix(from, to, f(t));
|
|
@@ -79,7 +90,24 @@ const cubicPulse = (w, c, t) => {
|
|
|
79
90
|
};
|
|
80
91
|
const sinc = (t) => t !== 0 ? Math.sin(t) / t : 1;
|
|
81
92
|
const sincNormalized = (k, t) => sinc(PI * k * t);
|
|
82
|
-
const lanczos = (a, t) => t !== 0 ? -a < t && t < a ?
|
|
93
|
+
const lanczos = (a, t) => t !== 0 ? -a < t && t < a ? (t *= PI, a * Math.sin(t) * Math.sin(t / a) / (t * t)) : 0 : 1;
|
|
94
|
+
const defLanczos = (a) => (t) => lanczos(a, t);
|
|
95
|
+
const defMitchell = (b = 1 / 3, c = 1 / 3) => {
|
|
96
|
+
const b12 = 12 * b;
|
|
97
|
+
const c6 = 6 * c;
|
|
98
|
+
const k1 = 12 - 9 * b - c6;
|
|
99
|
+
const k2 = -18 + b12 + c6;
|
|
100
|
+
const k3 = 6 - 2 * b;
|
|
101
|
+
const k4 = -b - c6;
|
|
102
|
+
const k5 = 6 * b + 30 * c;
|
|
103
|
+
const k6 = -b12 - 48 * c;
|
|
104
|
+
const k7 = 8 * b + 24 * c;
|
|
105
|
+
return (t) => {
|
|
106
|
+
if (t < 0) t = -t;
|
|
107
|
+
const t2 = t * t;
|
|
108
|
+
return t < 1 ? (k1 * t2 * t + k2 * t2 + k3) / 6 : t < 2 ? (k4 * t2 * t + k5 * t2 + k6 * t + k7) / 6 : 0;
|
|
109
|
+
};
|
|
110
|
+
};
|
|
83
111
|
const sigmoid = (bias, k, t) => t != bias ? 1 / (1 + Math.exp(-k * (t - bias))) : 0.5;
|
|
84
112
|
const sigmoid01 = (k, t) => sigmoid(0.5, k, t);
|
|
85
113
|
const sigmoid11 = (k, t) => sigmoid(0, k, t);
|
|
@@ -92,6 +120,8 @@ export {
|
|
|
92
120
|
cosine,
|
|
93
121
|
cubicPulse,
|
|
94
122
|
decimated,
|
|
123
|
+
defLanczos,
|
|
124
|
+
defMitchell,
|
|
95
125
|
ease,
|
|
96
126
|
expFactor,
|
|
97
127
|
gain,
|
|
@@ -107,7 +137,9 @@ export {
|
|
|
107
137
|
mixCubicHermite,
|
|
108
138
|
mixCubicHermiteFromPoints,
|
|
109
139
|
mixHermite,
|
|
140
|
+
mixKernel4,
|
|
110
141
|
mixQuadratic,
|
|
142
|
+
mixTrilinear,
|
|
111
143
|
parabola,
|
|
112
144
|
schlick,
|
|
113
145
|
sigmoid,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/math",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.12.0",
|
|
4
4
|
"description": "Assorted common math functions & utilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -42,11 +42,11 @@
|
|
|
42
42
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@thi.ng/api": "^8.12.
|
|
45
|
+
"@thi.ng/api": "^8.12.2"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"esbuild": "^0.25.
|
|
49
|
-
"typedoc": "^0.28.
|
|
48
|
+
"esbuild": "^0.25.9",
|
|
49
|
+
"typedoc": "^0.28.12",
|
|
50
50
|
"typescript": "^5.9.2"
|
|
51
51
|
},
|
|
52
52
|
"keywords": [
|
|
@@ -144,5 +144,5 @@
|
|
|
144
144
|
"thi.ng": {
|
|
145
145
|
"year": 2013
|
|
146
146
|
},
|
|
147
|
-
"gitHead": "
|
|
147
|
+
"gitHead": "e215a3e8de3809736ba0042c93bd8703a5a1a337\n"
|
|
148
148
|
}
|