@thi.ng/math 5.12.0 → 5.13.4

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/README.md CHANGED
@@ -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: 5.01 KB
80
+ Package sizes (brotli'd, pre-treeshake): ESM: 5.04 KB
81
81
 
82
82
  ## Dependencies
83
83
 
package/mix.d.ts CHANGED
@@ -460,6 +460,51 @@ export declare const schlick: FnN3;
460
460
  * @param num -
461
461
  */
462
462
  export declare const expFactor: FnN3;
463
+ /**
464
+ * Computes framerate-independent interpolation factor `t` for use with
465
+ * `mix(a,b, t)`, where `delta` is the time passed since last frame, `rate` is a
466
+ * user-defined interpolation rate and `fps` is the reference framerate (default
467
+ * = 60).
468
+ *
469
+ * @remarks
470
+ * Reference:
471
+ * https://blog.pkh.me/p/41-fixing-the-iterative-damping-interpolation-in-video-games.html
472
+ *
473
+ * @example
474
+ * ```ts tangle:../export/exp-rate.ts
475
+ * import { mix, expRate } from "@thi.ng/math";
476
+ *
477
+ * // fixed example framerate
478
+ * const FPS = 5;
479
+ * // arbitrary interpolation rate
480
+ * const RATE = 0.5;
481
+ *
482
+ * // start value
483
+ * let value = 0;
484
+ *
485
+ * // interpolate for 3 seconds at given FPS
486
+ * for(let i = 0; i < 3 * FPS; i++) {
487
+ * // compute current frame delta time (here static)
488
+ * const delta = 1 / FPS;
489
+ * // iteratively interpolate to target=100 in a framerate agnostic manner,
490
+ * // using RATE and 60 fps as reference frame rate
491
+ * value = mix(value, 100, expRate(delta, RATE, 60));
492
+ * console.log(i, value);
493
+ * }
494
+ * // 0 9.554162585016023
495
+ * // 1 18.195504943022847
496
+ * // 2 26.01123940261784
497
+ * // ...
498
+ * // 12 72.89486380583645
499
+ * // 13 75.48453258671687
500
+ * // 14 77.82678020185855
501
+ * ```
502
+ *
503
+ * @param delta
504
+ * @param rate
505
+ * @param fps
506
+ */
507
+ export declare const expRate: (delta: number, rate: number, fps?: number) => number;
463
508
  /**
464
509
  * Computes gaussian bell curve for given center `bias` and `sigma` (spread).
465
510
  *
package/mix.js CHANGED
@@ -113,6 +113,7 @@ const sigmoid01 = (k, t) => sigmoid(0.5, k, t);
113
113
  const sigmoid11 = (k, t) => sigmoid(0, k, t);
114
114
  const schlick = (a, b, t) => t <= b ? b * t / (t + a * (b - t) + EPS) : (1 - b) * (t - 1) / (1 - t - a * (b - t) + EPS) + 1;
115
115
  const expFactor = (a, b, num) => (b / a) ** (1 / num);
116
+ const expRate = (delta, rate, fps = 60) => 1 - Math.exp(-delta * -fps * Math.log(1 - rate / fps));
116
117
  const gaussian = (bias, sigma, t) => Math.exp(-((t - bias) ** 2) / (2 * sigma * sigma));
117
118
  export {
118
119
  bounce,
@@ -124,6 +125,7 @@ export {
124
125
  defMitchell,
125
126
  ease,
126
127
  expFactor,
128
+ expRate,
127
129
  gain,
128
130
  gaussian,
129
131
  impulse,
package/package.json CHANGED
@@ -1,148 +1,148 @@
1
1
  {
2
- "name": "@thi.ng/math",
3
- "version": "5.12.0",
4
- "description": "Assorted common math functions & utilities",
5
- "type": "module",
6
- "module": "./index.js",
7
- "typings": "./index.d.ts",
8
- "sideEffects": false,
9
- "repository": {
10
- "type": "git",
11
- "url": "https://github.com/thi-ng/umbrella.git"
12
- },
13
- "homepage": "https://thi.ng/math",
14
- "funding": [
15
- {
16
- "type": "github",
17
- "url": "https://github.com/sponsors/postspectacular"
18
- },
19
- {
20
- "type": "patreon",
21
- "url": "https://patreon.com/thing_umbrella"
22
- },
23
- {
24
- "type": "liberapay",
25
- "url": "https://liberapay.com/thi.ng"
26
- }
27
- ],
28
- "author": "Karsten Schmidt (https://thi.ng)",
29
- "contributors": [
30
- "@nkint (https://github.com/nkint)"
31
- ],
32
- "license": "Apache-2.0",
33
- "scripts": {
34
- "build": "yarn build:esbuild && yarn build:decl",
35
- "build:decl": "tsc --declaration --emitDeclarationOnly",
36
- "build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
37
- "clean": "bun ../../tools/src/clean-package.ts",
38
- "doc": "typedoc --options ../../typedoc.json --out doc src/index.ts",
39
- "doc:readme": "bun ../../tools/src/module-stats.ts && bun ../../tools/src/readme.ts",
40
- "pub": "yarn npm publish --access public",
41
- "test": "bun test",
42
- "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
43
- },
44
- "dependencies": {
45
- "@thi.ng/api": "^8.12.2"
46
- },
47
- "devDependencies": {
48
- "esbuild": "^0.25.9",
49
- "typedoc": "^0.28.12",
50
- "typescript": "^5.9.2"
51
- },
52
- "keywords": [
53
- "animation",
54
- "bezier",
55
- "cubic",
56
- "easing",
57
- "hermite",
58
- "interpolation",
59
- "interval",
60
- "math",
61
- "prime",
62
- "quadratic",
63
- "smoothmax",
64
- "smoothstep",
65
- "solver",
66
- "trigonometry",
67
- "typescript"
68
- ],
69
- "publishConfig": {
70
- "access": "public"
71
- },
72
- "engines": {
73
- "node": ">=18"
74
- },
75
- "files": [
76
- "./*.js",
77
- "./*.d.ts"
78
- ],
79
- "exports": {
80
- ".": {
81
- "default": "./index.js"
82
- },
83
- "./abs": {
84
- "default": "./abs.js"
85
- },
86
- "./angle": {
87
- "default": "./angle.js"
88
- },
89
- "./api": {
90
- "default": "./api.js"
91
- },
92
- "./crossing": {
93
- "default": "./crossing.js"
94
- },
95
- "./easing": {
96
- "default": "./easing.js"
97
- },
98
- "./eqdelta": {
99
- "default": "./eqdelta.js"
100
- },
101
- "./extrema": {
102
- "default": "./extrema.js"
103
- },
104
- "./fit": {
105
- "default": "./fit.js"
106
- },
107
- "./int": {
108
- "default": "./int.js"
109
- },
110
- "./interval": {
111
- "default": "./interval.js"
112
- },
113
- "./libc": {
114
- "default": "./libc.js"
115
- },
116
- "./min-error": {
117
- "default": "./min-error.js"
118
- },
119
- "./mix": {
120
- "default": "./mix.js"
121
- },
122
- "./permutations": {
123
- "default": "./permutations.js"
124
- },
125
- "./prec": {
126
- "default": "./prec.js"
127
- },
128
- "./prime": {
129
- "default": "./prime.js"
130
- },
131
- "./ratio": {
132
- "default": "./ratio.js"
133
- },
134
- "./safe-div": {
135
- "default": "./safe-div.js"
136
- },
137
- "./solve": {
138
- "default": "./solve.js"
139
- },
140
- "./step": {
141
- "default": "./step.js"
142
- }
143
- },
144
- "thi.ng": {
145
- "year": 2013
146
- },
147
- "gitHead": "e215a3e8de3809736ba0042c93bd8703a5a1a337\n"
148
- }
2
+ "name": "@thi.ng/math",
3
+ "version": "5.13.4",
4
+ "description": "Assorted common math functions & utilities",
5
+ "type": "module",
6
+ "module": "./index.js",
7
+ "typings": "./index.d.ts",
8
+ "sideEffects": false,
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/thi-ng/umbrella.git"
12
+ },
13
+ "homepage": "https://thi.ng/math",
14
+ "funding": [
15
+ {
16
+ "type": "github",
17
+ "url": "https://github.com/sponsors/postspectacular"
18
+ },
19
+ {
20
+ "type": "patreon",
21
+ "url": "https://patreon.com/thing_umbrella"
22
+ },
23
+ {
24
+ "type": "liberapay",
25
+ "url": "https://liberapay.com/thi.ng"
26
+ }
27
+ ],
28
+ "author": "Karsten Schmidt (https://thi.ng)",
29
+ "contributors": [
30
+ "@nkint (https://github.com/nkint)"
31
+ ],
32
+ "license": "Apache-2.0",
33
+ "scripts": {
34
+ "build": "yarn build:esbuild && yarn build:decl",
35
+ "build:decl": "tsc --declaration --emitDeclarationOnly",
36
+ "build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
37
+ "clean": "bun ../../tools/src/clean-package.ts",
38
+ "doc": "typedoc --options ../../typedoc.json --out doc src/index.ts",
39
+ "doc:readme": "bun ../../tools/src/module-stats.ts && bun ../../tools/src/readme.ts",
40
+ "pub": "npm publish --access public",
41
+ "test": "bun test",
42
+ "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
43
+ },
44
+ "dependencies": {
45
+ "@thi.ng/api": "^8.12.7"
46
+ },
47
+ "devDependencies": {
48
+ "esbuild": "^0.25.11",
49
+ "typedoc": "^0.28.14",
50
+ "typescript": "^5.9.3"
51
+ },
52
+ "keywords": [
53
+ "animation",
54
+ "bezier",
55
+ "cubic",
56
+ "easing",
57
+ "hermite",
58
+ "interpolation",
59
+ "interval",
60
+ "math",
61
+ "prime",
62
+ "quadratic",
63
+ "smoothmax",
64
+ "smoothstep",
65
+ "solver",
66
+ "trigonometry",
67
+ "typescript"
68
+ ],
69
+ "publishConfig": {
70
+ "access": "public"
71
+ },
72
+ "engines": {
73
+ "node": ">=18"
74
+ },
75
+ "files": [
76
+ "./*.js",
77
+ "./*.d.ts"
78
+ ],
79
+ "exports": {
80
+ ".": {
81
+ "default": "./index.js"
82
+ },
83
+ "./abs": {
84
+ "default": "./abs.js"
85
+ },
86
+ "./angle": {
87
+ "default": "./angle.js"
88
+ },
89
+ "./api": {
90
+ "default": "./api.js"
91
+ },
92
+ "./crossing": {
93
+ "default": "./crossing.js"
94
+ },
95
+ "./easing": {
96
+ "default": "./easing.js"
97
+ },
98
+ "./eqdelta": {
99
+ "default": "./eqdelta.js"
100
+ },
101
+ "./extrema": {
102
+ "default": "./extrema.js"
103
+ },
104
+ "./fit": {
105
+ "default": "./fit.js"
106
+ },
107
+ "./int": {
108
+ "default": "./int.js"
109
+ },
110
+ "./interval": {
111
+ "default": "./interval.js"
112
+ },
113
+ "./libc": {
114
+ "default": "./libc.js"
115
+ },
116
+ "./min-error": {
117
+ "default": "./min-error.js"
118
+ },
119
+ "./mix": {
120
+ "default": "./mix.js"
121
+ },
122
+ "./permutations": {
123
+ "default": "./permutations.js"
124
+ },
125
+ "./prec": {
126
+ "default": "./prec.js"
127
+ },
128
+ "./prime": {
129
+ "default": "./prime.js"
130
+ },
131
+ "./ratio": {
132
+ "default": "./ratio.js"
133
+ },
134
+ "./safe-div": {
135
+ "default": "./safe-div.js"
136
+ },
137
+ "./solve": {
138
+ "default": "./solve.js"
139
+ },
140
+ "./step": {
141
+ "default": "./step.js"
142
+ }
143
+ },
144
+ "thi.ng": {
145
+ "year": 2013
146
+ },
147
+ "gitHead": "d977f819bcafdcb2b24c45f8d01a167fe29fc85a\n"
148
+ }
package/CHANGELOG.md DELETED
@@ -1,94 +0,0 @@
1
- # Change Log
2
-
3
- - **Last updated**: 2025-09-01T16:38:35Z
4
- - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
-
6
- All notable changes to this project will be documented in this file.
7
- Only versions published since **2022-01-01** are listed here.
8
- Please consult the Git history for older version information.
9
- See [Conventional Commits](https://conventionalcommits.org/) for commit guidelines.
10
-
11
- **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
12
- and/or version bumps of transitive dependencies.
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
-
25
- ## [5.11.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/math@5.11.0) (2024-06-21)
26
-
27
- #### 🚀 Features
28
-
29
- - add solveTridiagonal() ([1277a0a](https://github.com/thi-ng/umbrella/commit/1277a0a))
30
-
31
- #### ♻️ Refactoring
32
-
33
- - enforce uniform naming convention of internal functions ([56992b2](https://github.com/thi-ng/umbrella/commit/56992b2))
34
-
35
- ## [5.10.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/math@5.10.0) (2024-02-16)
36
-
37
- #### 🚀 Features
38
-
39
- - add fromDMS()/toDMS() conversions ([1714067](https://github.com/thi-ng/umbrella/commit/1714067))
40
-
41
- ## [5.9.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/math@5.9.0) (2024-02-06)
42
-
43
- #### 🚀 Features
44
-
45
- - add easing functions ([e4966fd](https://github.com/thi-ng/umbrella/commit/e4966fd))
46
- - add easing functions, ported from [@thi.ng/shader-ast-std](https://github.com/thi-ng/umbrella/tree/main/packages/shader-ast-std) pkg
47
-
48
- ## [5.8.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/math@5.8.0) (2024-01-26)
49
-
50
- #### 🚀 Features
51
-
52
- - add signedPow(), add docs ([5207ba3](https://github.com/thi-ng/umbrella/commit/5207ba3))
53
-
54
- ### [5.7.2](https://github.com/thi-ng/umbrella/tree/@thi.ng/math@5.7.2) (2023-11-09)
55
-
56
- #### ♻️ Refactoring
57
-
58
- - update all tests (packages A-S) ([e3085e4](https://github.com/thi-ng/umbrella/commit/e3085e4))
59
-
60
- ## [5.7.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/math@5.7.0) (2023-10-27)
61
-
62
- #### 🚀 Features
63
-
64
- - add foldback01() ([1272647](https://github.com/thi-ng/umbrella/commit/1272647))
65
-
66
- ## [5.6.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/math@5.6.0) (2023-08-24)
67
-
68
- #### 🚀 Features
69
-
70
- - add minMax() ([76ca59d](https://github.com/thi-ng/umbrella/commit/76ca59d))
71
-
72
- ## [5.5.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/math@5.5.0) (2023-07-14)
73
-
74
- #### 🚀 Features
75
-
76
- - add smoothStep01/smootherStep01() ([152f93c](https://github.com/thi-ng/umbrella/commit/152f93c))
77
-
78
- ### [5.4.4](https://github.com/thi-ng/umbrella/tree/@thi.ng/math@5.4.4) (2023-03-02)
79
-
80
- #### ♻️ Refactoring
81
-
82
- - update sincos/cossin return types ([ae5cd82](https://github.com/thi-ng/umbrella/commit/ae5cd82))
83
-
84
- ## [5.4.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/math@5.4.0) (2023-01-10)
85
-
86
- #### 🚀 Features
87
-
88
- - add factorial. permutation/combination fns ([965af0d](https://github.com/thi-ng/umbrella/commit/965af0d))
89
-
90
- ## [5.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/math@5.3.0) (2022-03-11)
91
-
92
- #### 🚀 Features
93
-
94
- - add ldiv() ([35d1e97](https://github.com/thi-ng/umbrella/commit/35d1e97))