@thi.ng/shader-ast-stdlib 0.14.18 → 0.14.20

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-08-27T11:20:59Z
3
+ - **Last updated**: 2023-10-24T08:38:23Z
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,12 @@ 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
+ ### [0.14.20](https://github.com/thi-ng/umbrella/tree/@thi.ng/shader-ast-stdlib@0.14.20) (2023-10-24)
13
+
14
+ #### ♻️ Refactoring
15
+
16
+ - use hoc function to define easing functions ([2b2c451](https://github.com/thi-ng/umbrella/commit/2b2c451))
17
+
12
18
  ## [0.14.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/shader-ast-stdlib@0.14.0) (2023-07-14)
13
19
 
14
20
  #### 🚀 Features
package/README.md CHANGED
@@ -27,6 +27,7 @@ This project is part of the
27
27
  - [Fog](#fog)
28
28
  - [Lighting](#lighting)
29
29
  - [Math](#math)
30
+ - [Easing functions](#easing-functions)
30
31
  - [Oscillators](#oscillators)
31
32
  - [Matrix operations](#matrix-operations)
32
33
  - [Noise / randomness](#noise--randomness)
@@ -102,7 +103,7 @@ For Node.js REPL:
102
103
  const shaderAstStdlib = await import("@thi.ng/shader-ast-stdlib");
103
104
  ```
104
105
 
105
- Package sizes (brotli'd, pre-treeshake): ESM: 11.82 KB
106
+ Package sizes (brotli'd, pre-treeshake): ESM: 12.62 KB
106
107
 
107
108
  ## Dependencies
108
109
 
@@ -391,6 +392,21 @@ for reference.
391
392
  - `smootherStep` / `smootherStep2` / `smootherStep3` / `smootherStep4`
392
393
  - `smootherStep01` / `smootherStep01_2` / `smootherStep01_3` / `smootherStep01_4`
393
394
 
395
+ ### Easing functions
396
+
397
+ [/src/math/easing.ts](https://github.com/thi-ng/umbrella/tree/develop/packages/shader-ast-stdlib/src/math/easing.ts)
398
+
399
+ - `easeInBack` / `easeOutBack` / `easeInOutBack`
400
+ - `easeInBounce` / `easeOutBounce` / `easeInOutBounce`
401
+ - `easeInCirc` / `easeOutCirc` / `easeInOutCirc`
402
+ - `easeInCubic` / `easeOutCubic` / `easeInOutCubic`
403
+ - `easeInElastic` / `easeOutElastic` / `easeInOutElastic`
404
+ - `easeInExpo` / `easeOutExpo` / `easeInOutExpo`
405
+ - `easeInQuad` / `easeOutQuad` / `easeInOutQuad`
406
+ - `easeInQuart` / `easeOutQuart` / `easeInOutQuart`
407
+ - `easeInQuint` / `easeOutQuint` / `easeInOutQuint`
408
+ - `easeInSine` / `easeOutSine` / `easeInOutSine`
409
+
394
410
  ### Oscillators
395
411
 
396
412
  [/src/math](https://github.com/thi-ng/umbrella/tree/develop/packages/shader-ast-stdlib/src/math/osc.ts)
@@ -491,14 +507,15 @@ for reference.
491
507
 
492
508
  ## Authors
493
509
 
494
- - [Karsten Schmidt](https://thi.ng)
510
+ - [Karsten Schmidt](https://thi.ng) (Main author)
511
+ - [Yury Hantsouski](https://github.com/Hantsouski)
495
512
 
496
513
  If this project contributes to an academic publication, please cite it as:
497
514
 
498
515
  ```bibtex
499
516
  @misc{thing-shader-ast-stdlib,
500
517
  title = "@thi.ng/shader-ast-stdlib",
501
- author = "Karsten Schmidt",
518
+ author = "Karsten Schmidt and others",
502
519
  note = "https://thi.ng/shader-ast-stdlib",
503
520
  year = 2019
504
521
  }
package/index.d.ts CHANGED
@@ -27,6 +27,7 @@ export * from "./math/osc.js";
27
27
  export * from "./math/polar.js";
28
28
  export * from "./math/sincos.js";
29
29
  export * from "./math/smoother-step.js";
30
+ export * from "./math/easing.js";
30
31
  export * from "./matrix/lookat.js";
31
32
  export * from "./matrix/mvp.js";
32
33
  export * from "./matrix/normal.js";
package/index.js CHANGED
@@ -27,6 +27,7 @@ export * from "./math/osc.js";
27
27
  export * from "./math/polar.js";
28
28
  export * from "./math/sincos.js";
29
29
  export * from "./math/smoother-step.js";
30
+ export * from "./math/easing.js";
30
31
  export * from "./matrix/lookat.js";
31
32
  export * from "./matrix/mvp.js";
32
33
  export * from "./matrix/normal.js";
@@ -0,0 +1,39 @@
1
+ import type { FnBody1 } from "@thi.ng/shader-ast";
2
+ /**
3
+ * Higher order helper function to wrap a given easing function body as proper
4
+ * shader-ast function.
5
+ *
6
+ * @param body
7
+ */
8
+ export declare const defEasing: (body: FnBody1<"float">) => import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
9
+ export declare const easeInSine: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
10
+ export declare const easeOutSine: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
11
+ export declare const easeInOutSine: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
12
+ export declare const easeInQuad: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
13
+ export declare const easeOutQuad: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
14
+ export declare const easeInOutQuad: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
15
+ export declare const easeInCubic: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
16
+ export declare const easeOutCubic: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
17
+ export declare const easeInOutCubic: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
18
+ export declare const easeInQuart: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
19
+ export declare const easeOutQuart: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
20
+ export declare const easeInOutQuart: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
21
+ export declare const easeInQuint: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
22
+ export declare const easeOutQuint: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
23
+ export declare const easeInOutQuint: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
24
+ export declare const easeInExpo: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
25
+ export declare const easeOutExpo: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
26
+ export declare const easeInOutExpo: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
27
+ export declare const easeInCirc: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
28
+ export declare const easeOutCirc: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
29
+ export declare const easeInOutCirc: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
30
+ export declare const easeInBack: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
31
+ export declare const easeOutBack: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
32
+ export declare const easeInOutBack: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
33
+ export declare const easeInElastic: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
34
+ export declare const easeOutElastic: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
35
+ export declare const easeInOutElastic: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
36
+ export declare const easeOutBounce: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
37
+ export declare const easeInBounce: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
38
+ export declare const easeInOutBounce: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
39
+ //# sourceMappingURL=easing.d.ts.map
package/math/easing.js ADDED
@@ -0,0 +1,117 @@
1
+ import { F } from "@thi.ng/shader-ast/api/types";
2
+ import { ifThen, ternary } from "@thi.ng/shader-ast/ast/controlflow";
3
+ import { defn, ret } from "@thi.ng/shader-ast/ast/function";
4
+ import { FLOAT0, FLOAT05, FLOAT1, FLOAT2, HALF_PI, PI, TAU, float, } from "@thi.ng/shader-ast/ast/lit";
5
+ import { add, div, eq, gte, lt, lte, madd, mul, neg, reciprocal, sub, } from "@thi.ng/shader-ast/ast/ops";
6
+ import { cos, exp2, pow, sin, sqrt } from "@thi.ng/shader-ast/builtin/math";
7
+ /**
8
+ * Higher order helper function to wrap a given easing function body as proper
9
+ * shader-ast function.
10
+ *
11
+ * @param body
12
+ */
13
+ export const defEasing = (body) => defn(F, null, [F], body);
14
+ export const easeInSine = defEasing((x) => [
15
+ ret(sub(FLOAT1, cos(mul(x, HALF_PI)))),
16
+ ]);
17
+ export const easeOutSine = defEasing((x) => [ret(sin(mul(x, HALF_PI)))]);
18
+ export const easeInOutSine = defEasing((x) => [
19
+ ret(div(neg(sub(cos(mul(PI, x)), FLOAT1)), FLOAT2)),
20
+ ]);
21
+ export const easeInQuad = defEasing((x) => [ret(pow(x, FLOAT2))]);
22
+ export const easeOutQuad = defEasing((x) => [
23
+ ret(sub(FLOAT1, pow(sub(FLOAT1, x), FLOAT2))),
24
+ ]);
25
+ export const easeInOutQuad = defEasing((x) => [
26
+ ret(ternary(lt(x, FLOAT05), mul(FLOAT2, pow(x, FLOAT2)), sub(FLOAT1, div(pow(madd(neg(FLOAT2), x, FLOAT2), FLOAT2), FLOAT2)))),
27
+ ]);
28
+ export const easeInCubic = defEasing((x) => [ret(pow(x, float(3)))]);
29
+ export const easeOutCubic = defEasing((x) => [
30
+ ret(sub(FLOAT1, pow(sub(FLOAT1, x), float(3)))),
31
+ ]);
32
+ export const easeInOutCubic = defEasing((x) => [
33
+ ret(ternary(lt(x, FLOAT05), mul(float(4), pow(x, float(3))), sub(FLOAT1, div(pow(madd(neg(FLOAT2), x, FLOAT2), float(3)), FLOAT2)))),
34
+ ]);
35
+ export const easeInQuart = defEasing((x) => [ret(pow(x, float(4)))]);
36
+ export const easeOutQuart = defEasing((x) => [
37
+ ret(sub(FLOAT1, pow(sub(FLOAT1, x), float(4)))),
38
+ ]);
39
+ export const easeInOutQuart = defEasing((x) => [
40
+ ret(ternary(lt(x, FLOAT05), mul(float(8), pow(x, float(4))), sub(FLOAT1, div(pow(madd(neg(FLOAT2), x, FLOAT2), float(4)), FLOAT2)))),
41
+ ]);
42
+ export const easeInQuint = defEasing((x) => [ret(pow(x, float(5)))]);
43
+ export const easeOutQuint = defEasing((x) => [
44
+ ret(sub(FLOAT1, pow(sub(FLOAT1, x), float(5)))),
45
+ ]);
46
+ export const easeInOutQuint = defEasing((x) => [
47
+ ret(ternary(lt(x, FLOAT05), mul(float(16), pow(x, float(5))), sub(FLOAT1, div(pow(madd(neg(FLOAT2), x, FLOAT2), float(5)), FLOAT2)))),
48
+ ]);
49
+ export const easeInExpo = defEasing((x) => [
50
+ ret(ternary(eq(x, FLOAT0), FLOAT0, exp2(sub(mul(float(10), x), float(10))))),
51
+ ]);
52
+ export const easeOutExpo = defEasing((x) => [
53
+ ret(ternary(eq(x, FLOAT1), FLOAT1, sub(FLOAT1, exp2(mul(neg(float(10)), x))))),
54
+ ]);
55
+ export const easeInOutExpo = defEasing((x) => [
56
+ ret(ternary(eq(x, FLOAT0), FLOAT0, ternary(eq(x, FLOAT1), FLOAT1, ternary(lt(x, FLOAT05), div(exp2(sub(mul(float(20), x), float(10))), FLOAT2), div(sub(FLOAT2, exp2(madd(neg(float(20)), x, float(10)))), FLOAT2))))),
57
+ ]);
58
+ export const easeInCirc = defEasing((x) => [
59
+ ret(sub(FLOAT1, sqrt(sub(FLOAT1, pow(x, FLOAT2))))),
60
+ ]);
61
+ export const easeOutCirc = defEasing((x) => [
62
+ ret(sqrt(sub(FLOAT1, pow(sub(x, FLOAT1), FLOAT2)))),
63
+ ]);
64
+ export const easeInOutCirc = defEasing((x) => [
65
+ ret(ternary(lt(x, FLOAT05), div(sub(FLOAT1, sqrt(sub(FLOAT1, pow(mul(FLOAT2, x), FLOAT2)))), FLOAT2), div(add(sqrt(sub(FLOAT1, pow(madd(neg(FLOAT2), x, FLOAT2), FLOAT2))), FLOAT1), FLOAT2))),
66
+ ]);
67
+ export const easeInBack = defEasing((x) => {
68
+ const c1 = 1.70158;
69
+ const c3 = c1 + 1;
70
+ return [ret(sub(mul(c3, pow(x, float(3))), mul(c1, pow(x, FLOAT2))))];
71
+ });
72
+ export const easeOutBack = defEasing((x) => {
73
+ const c1 = 1.70158;
74
+ const c3 = c1 + 1;
75
+ return [
76
+ ret(add(madd(float(c3), pow(sub(x, FLOAT1), float(3)), FLOAT1), mul(c1, pow(sub(x, FLOAT1), FLOAT2)))),
77
+ ];
78
+ });
79
+ export const easeInOutBack = defEasing((x) => {
80
+ const c1 = 1.70158;
81
+ const c2 = c1 * 1.525;
82
+ return [
83
+ ret(ternary(lt(x, FLOAT05), div(mul(pow(mul(FLOAT2, x), FLOAT2), sub(mul(mul(add(c2, FLOAT1), FLOAT2), x), c2)), FLOAT2), div(add(mul(pow(sub(mul(FLOAT2, x), FLOAT2), FLOAT2), add(mul(add(c2, FLOAT1), sub(mul(x, FLOAT2), FLOAT2)), c2)), FLOAT2), FLOAT2))),
84
+ ];
85
+ });
86
+ export const easeInElastic = defEasing((x) => [
87
+ ret(ternary(eq(x, FLOAT0), FLOAT0, ternary(eq(x, FLOAT1), FLOAT1, mul(neg(exp2(sub(mul(10, x), 10))), sin(mul(sub(mul(x, 10), 10.75), div(TAU, 3))))))),
88
+ ]);
89
+ export const easeOutElastic = defEasing((x) => [
90
+ ret(ternary(lte(x, FLOAT0), FLOAT0, ternary(gte(x, FLOAT1), FLOAT1, madd(exp2(mul(-10, x)), sin(mul(sub(mul(x, 10), 0.75), div(TAU, 3))), FLOAT1)))),
91
+ ]);
92
+ export const easeInOutElastic = defEasing((x) => {
93
+ const c5 = div(TAU, 4.5);
94
+ return [
95
+ ret(ternary(eq(x, FLOAT0), FLOAT0, ternary(eq(x, FLOAT1), FLOAT1, ternary(lt(x, FLOAT05), div(neg(mul(exp2(sub(mul(20, x), 10)), sin(mul(sub(mul(20, x), 11.125), c5)))), FLOAT2), add(div(mul(exp2(madd(neg(float(20)), x, float(10))), sin(mul(sub(mul(20, x), 11.125), c5))), FLOAT2), FLOAT1))))),
96
+ ];
97
+ });
98
+ export const easeOutBounce = defEasing((x) => {
99
+ const n1 = 7.5625;
100
+ const d1 = float(2.75);
101
+ return [
102
+ ifThen(lt(x, reciprocal(d1)), [ret(mul(n1, pow(x, FLOAT2)))]),
103
+ ifThen(lt(x, div(FLOAT2, d1)), [
104
+ ret(add(mul(mul(n1, sub(x, div(1.5, d1))), sub(x, div(1.5, d1))), 0.75)),
105
+ ]),
106
+ ifThen(lt(x, div(2.5, d1)), [
107
+ ret(add(mul(mul(n1, sub(x, div(2.25, d1))), sub(x, div(2.25, d1))), 0.9375)),
108
+ ]),
109
+ ret(add(mul(mul(n1, sub(x, div(2.625, d1))), sub(x, div(2.625, d1))), 0.984375)),
110
+ ];
111
+ });
112
+ export const easeInBounce = defEasing((x) => [
113
+ ret(sub(FLOAT1, easeOutBounce(sub(FLOAT1, x)))),
114
+ ]);
115
+ export const easeInOutBounce = defEasing((x) => [
116
+ ret(ternary(lt(x, FLOAT05), div(sub(FLOAT1, easeOutBounce(sub(FLOAT1, mul(FLOAT2, x)))), FLOAT2), div(add(FLOAT1, easeOutBounce(sub(mul(FLOAT2, x), FLOAT1))), FLOAT2))),
117
+ ]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/shader-ast-stdlib",
3
- "version": "0.14.18",
3
+ "version": "0.14.20",
4
4
  "description": "Function collection for modular GPGPU / shader programming with @thi.ng/shader-ast",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -22,6 +22,9 @@
22
22
  }
23
23
  ],
24
24
  "author": "Karsten Schmidt (https://thi.ng)",
25
+ "contributors": [
26
+ "Yury Hantsouski (https://github.com/Hantsouski)"
27
+ ],
25
28
  "license": "Apache-2.0",
26
29
  "scripts": {
27
30
  "build": "yarn clean && tsc --declaration",
@@ -34,15 +37,15 @@
34
37
  "test": "testament test"
35
38
  },
36
39
  "dependencies": {
37
- "@thi.ng/api": "^8.9.5",
38
- "@thi.ng/shader-ast": "^0.12.72"
40
+ "@thi.ng/api": "^8.9.6",
41
+ "@thi.ng/shader-ast": "^0.12.74"
39
42
  },
40
43
  "devDependencies": {
41
- "@microsoft/api-extractor": "^7.36.4",
42
- "@thi.ng/testament": "^0.3.23",
43
- "rimraf": "^5.0.1",
44
+ "@microsoft/api-extractor": "^7.38.0",
45
+ "@thi.ng/testament": "^0.3.24",
46
+ "rimraf": "^5.0.5",
44
47
  "tools": "^0.0.1",
45
- "typedoc": "^0.25.0",
48
+ "typedoc": "^0.25.2",
46
49
  "typescript": "^5.2.2"
47
50
  },
48
51
  "keywords": [
@@ -51,6 +54,7 @@
51
54
  "canvas",
52
55
  "codegen",
53
56
  "dsl",
57
+ "easing",
54
58
  "fog",
55
59
  "functional",
56
60
  "glsl",
@@ -149,6 +153,9 @@
149
153
  "./math/dist-manhattan": {
150
154
  "default": "./math/dist-manhattan.js"
151
155
  },
156
+ "./math/easing": {
157
+ "default": "./math/easing.js"
158
+ },
152
159
  "./math/fit": {
153
160
  "default": "./math/fit.js"
154
161
  },
@@ -333,5 +340,5 @@
333
340
  ],
334
341
  "year": 2019
335
342
  },
336
- "gitHead": "46e445c09f2909d1aeaa9fdc8d8b3aa61c114db2\n"
343
+ "gitHead": "dc7eeaba72f3c3977f2d6cc201e595ed6d68e2ad\n"
337
344
  }