@thi.ng/math 5.10.13 ā 5.11.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 +11 -1
- package/README.md +2 -2
- package/extrema.js +3 -3
- package/mix.d.ts +18 -7
- package/package.json +7 -7
- package/solve.d.ts +16 -1
- package/solve.js +19 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2024-
|
|
3
|
+
- **Last updated**: 2024-06-21T19:34:38Z
|
|
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.
|
|
@@ -9,6 +9,16 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
## [5.11.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/math@5.11.0) (2024-06-21)
|
|
13
|
+
|
|
14
|
+
#### š Features
|
|
15
|
+
|
|
16
|
+
- add solveTridiagonal() ([1277a0a](https://github.com/thi-ng/umbrella/commit/1277a0a))
|
|
17
|
+
|
|
18
|
+
#### ā»ļø Refactoring
|
|
19
|
+
|
|
20
|
+
- enforce uniform naming convention of internal functions ([56992b2](https://github.com/thi-ng/umbrella/commit/56992b2))
|
|
21
|
+
|
|
12
22
|
## [5.10.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/math@5.10.0) (2024-02-16)
|
|
13
23
|
|
|
14
24
|
#### š Features
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://mastodon.thi.ng/@toxi)
|
|
8
8
|
|
|
9
9
|
> [!NOTE]
|
|
10
|
-
> This is one of
|
|
10
|
+
> This is one of 193 standalone projects, maintained as part
|
|
11
11
|
> of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
|
|
12
12
|
> and anti-framework.
|
|
13
13
|
>
|
|
@@ -77,7 +77,7 @@ For Node.js REPL:
|
|
|
77
77
|
const math = await import("@thi.ng/math");
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
-
Package sizes (brotli'd, pre-treeshake): ESM: 4.
|
|
80
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 4.80 KB
|
|
81
81
|
|
|
82
82
|
## Dependencies
|
|
83
83
|
|
package/extrema.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const isMinima = (a, b, c) => a > b && b < c;
|
|
2
2
|
const isMaxima = (a, b, c) => a < b && b > c;
|
|
3
|
-
const
|
|
3
|
+
const __index = (pred, values, from = 0, to = values.length) => {
|
|
4
4
|
to--;
|
|
5
5
|
for (let i = from + 1; i < to; i++) {
|
|
6
6
|
if (pred(values[i - 1], values[i], values[i + 1])) {
|
|
@@ -9,8 +9,8 @@ const index = (pred, values, from = 0, to = values.length) => {
|
|
|
9
9
|
}
|
|
10
10
|
return -1;
|
|
11
11
|
};
|
|
12
|
-
const minimaIndex = (values, from = 0, to = values.length) =>
|
|
13
|
-
const maximaIndex = (values, from = 0, to = values.length) =>
|
|
12
|
+
const minimaIndex = (values, from = 0, to = values.length) => __index(isMinima, values, from, to);
|
|
13
|
+
const maximaIndex = (values, from = 0, to = values.length) => __index(isMaxima, values, from, to);
|
|
14
14
|
function* indices(fn, vals, from = 0, to = vals.length) {
|
|
15
15
|
while (from < to) {
|
|
16
16
|
const i = fn(vals, from, to);
|
package/mix.d.ts
CHANGED
|
@@ -172,13 +172,13 @@ export declare const tangentDiff3: (prev: number, curr: number, next: number, ta
|
|
|
172
172
|
* and returns interpolated value.
|
|
173
173
|
*
|
|
174
174
|
* @example
|
|
175
|
-
* ```ts
|
|
175
|
+
* ```ts tangle:../export/tween.ts
|
|
176
176
|
* import { easeInOut2, tween } from "@thi.ng/math";
|
|
177
177
|
*
|
|
178
178
|
* // create tweening function
|
|
179
179
|
* const anim = tween(easeInOut2, 100, 200);
|
|
180
180
|
*
|
|
181
|
-
* for(let i=0; i<=10; i++) console.log(anim(i/10));
|
|
181
|
+
* for(let i=0; i<=10; i++) console.log(anim(i / 10));
|
|
182
182
|
* // 100
|
|
183
183
|
* // 102
|
|
184
184
|
* // 108
|
|
@@ -229,17 +229,28 @@ export declare const invCircular: FnN;
|
|
|
229
229
|
* reference to below example.
|
|
230
230
|
*
|
|
231
231
|
* @example
|
|
232
|
-
* ```ts
|
|
232
|
+
* ```ts tangle:../export/lens.ts
|
|
233
233
|
* import { mix, lens, tween } from "@thi.ng/math";
|
|
234
234
|
* import { partial } from "@thi.ng/compose";
|
|
235
235
|
*
|
|
236
236
|
* // interpolated position in [100..400] interval for given `t`
|
|
237
|
-
* y = mix(100, 400, lens(0.5, 1, t));
|
|
237
|
+
* // const y = mix(100, 400, lens(0.5, 1, t));
|
|
238
238
|
*
|
|
239
239
|
* // or compose tween function via `tween()` & `partial()`
|
|
240
|
-
* f = tween(partial(lens, 0.
|
|
241
|
-
*
|
|
242
|
-
* f(
|
|
240
|
+
* const f = tween(partial(lens, 0.75, 1), 100, 400);
|
|
241
|
+
*
|
|
242
|
+
* for(let i=0; i<=10; i++) console.log(f(i / 10));
|
|
243
|
+
* // 100.0
|
|
244
|
+
* // 102.0
|
|
245
|
+
* // 108.1
|
|
246
|
+
* // 118.7
|
|
247
|
+
* // 134.6
|
|
248
|
+
* // 157.2
|
|
249
|
+
* // 190.0
|
|
250
|
+
* // 244.2
|
|
251
|
+
* // 370.0
|
|
252
|
+
* // 393.7
|
|
253
|
+
* // 400.0
|
|
243
254
|
* ```
|
|
244
255
|
*
|
|
245
256
|
* @param pos - lens pos
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/math",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.11.0",
|
|
4
4
|
"description": "Assorted common math functions & utilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "https://github.com/thi-ng/umbrella.git"
|
|
12
12
|
},
|
|
13
|
-
"homepage": "https://
|
|
13
|
+
"homepage": "https://thi.ng/math",
|
|
14
14
|
"funding": [
|
|
15
15
|
{
|
|
16
16
|
"type": "github",
|
|
@@ -39,13 +39,13 @@
|
|
|
39
39
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@thi.ng/api": "^8.11.
|
|
42
|
+
"@thi.ng/api": "^8.11.3"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@microsoft/api-extractor": "^7.
|
|
46
|
-
"esbuild": "^0.21.
|
|
45
|
+
"@microsoft/api-extractor": "^7.47.0",
|
|
46
|
+
"esbuild": "^0.21.5",
|
|
47
47
|
"typedoc": "^0.25.13",
|
|
48
|
-
"typescript": "^5.
|
|
48
|
+
"typescript": "^5.5.2"
|
|
49
49
|
},
|
|
50
50
|
"keywords": [
|
|
51
51
|
"animation",
|
|
@@ -142,5 +142,5 @@
|
|
|
142
142
|
"thi.ng": {
|
|
143
143
|
"year": 2013
|
|
144
144
|
},
|
|
145
|
-
"gitHead": "
|
|
145
|
+
"gitHead": "154c95cf9d6bab32174498ec3b5b5d87e42be7f9\n"
|
|
146
146
|
}
|
package/solve.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FnN2 } from "@thi.ng/api";
|
|
1
|
+
import type { FnN2, NumericArray } from "@thi.ng/api";
|
|
2
2
|
/**
|
|
3
3
|
* Produces a new function which computes derivative of the given single-arg
|
|
4
4
|
* function. The extra optional arg `eps` is used to define the step width for
|
|
@@ -54,4 +54,19 @@ export declare const solveQuadratic: (a: number, b: number, c: number, eps?: num
|
|
|
54
54
|
* @param eps - tolerance to determine multiple roots
|
|
55
55
|
*/
|
|
56
56
|
export declare const solveCubic: (a: number, b: number, c: number, d: number, eps?: number) => number[];
|
|
57
|
+
/**
|
|
58
|
+
* Solves a system of linear equations for N unknowns: `a[i]*x[iā1] + b[i]*x[i]
|
|
59
|
+
* + c[i]*x[i+1] = d[i]`, where a[0]=0 and c[N-1]=0. Writes solutions `x[i]` back into
|
|
60
|
+
* array of input coefficients `d` and returns it. The other arrays are not modified.
|
|
61
|
+
*
|
|
62
|
+
* @remarks
|
|
63
|
+
* Reference:
|
|
64
|
+
* https://en.wikipedia.org/wiki/Tridiagonal_matrix_algorithm
|
|
65
|
+
*
|
|
66
|
+
* @param a - subdiagonal [1,N-1], a[0] is lower left corner
|
|
67
|
+
* @param b - main diagonal [0,N-1]
|
|
68
|
+
* @param c - superdiagonal [0,N-2], c[N-1] is upper right corner
|
|
69
|
+
* @param d - input coefficients & output solutions [0,N-1]
|
|
70
|
+
*/
|
|
71
|
+
export declare const solveTridiagonal: (a: NumericArray, b: NumericArray, c: NumericArray, d: NumericArray) => NumericArray;
|
|
57
72
|
//# sourceMappingURL=solve.d.ts.map
|
package/solve.js
CHANGED
|
@@ -34,9 +34,27 @@ const solveCubic = (a, b, c, d, eps = 1e-9) => {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
+
const solveTridiagonal = (a, b, c, d) => {
|
|
38
|
+
const n = d.length - 1;
|
|
39
|
+
const tmp = new Array(n + 1);
|
|
40
|
+
tmp[0] = c[0] / b[0];
|
|
41
|
+
d[0] = d[0] / b[0];
|
|
42
|
+
for (let i = 1; i <= n; i++) {
|
|
43
|
+
const ai = a[i];
|
|
44
|
+
const bi = b[i];
|
|
45
|
+
const denom = 1 / (bi - ai * tmp[i - 1]);
|
|
46
|
+
tmp[i] = c[i] * denom;
|
|
47
|
+
d[i] = (d[i] - ai * d[i - 1]) * denom;
|
|
48
|
+
}
|
|
49
|
+
for (let i = n; i-- > 0; ) {
|
|
50
|
+
d[i] -= tmp[i] * d[i + 1];
|
|
51
|
+
}
|
|
52
|
+
return d;
|
|
53
|
+
};
|
|
37
54
|
export {
|
|
38
55
|
derivative,
|
|
39
56
|
solveCubic,
|
|
40
57
|
solveLinear,
|
|
41
|
-
solveQuadratic
|
|
58
|
+
solveQuadratic,
|
|
59
|
+
solveTridiagonal
|
|
42
60
|
};
|