@thi.ng/timestep 0.4.21 → 0.5.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 +8 -1
- package/README.md +14 -1
- package/package.json +4 -4
- package/state.d.ts +13 -10
- package/state.js +19 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2023-10-
|
|
3
|
+
- **Last updated**: 2023-10-27T16:56:24Z
|
|
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,13 @@ 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.5.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/timestep@0.5.0) (2023-10-27)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- update VectorState, add VecAPI support ([f0aeb7e](https://github.com/thi-ng/umbrella/commit/f0aeb7e))
|
|
17
|
+
- update VectorState ctor & defVector() args
|
|
18
|
+
|
|
12
19
|
### [0.4.2](https://github.com/thi-ng/umbrella/tree/@thi.ng/timestep@0.4.2) (2023-08-04)
|
|
13
20
|
|
|
14
21
|
#### ♻️ Refactoring
|
package/README.md
CHANGED
|
@@ -15,6 +15,7 @@ This project is part of the
|
|
|
15
15
|
- [Status](#status)
|
|
16
16
|
- [Installation](#installation)
|
|
17
17
|
- [Dependencies](#dependencies)
|
|
18
|
+
- [Usage examples](#usage-examples)
|
|
18
19
|
- [API](#api)
|
|
19
20
|
- [Authors](#authors)
|
|
20
21
|
- [License](#license)
|
|
@@ -152,7 +153,7 @@ For Node.js REPL:
|
|
|
152
153
|
const timestep = await import("@thi.ng/timestep");
|
|
153
154
|
```
|
|
154
155
|
|
|
155
|
-
Package sizes (brotli'd, pre-treeshake): ESM:
|
|
156
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 821 bytes
|
|
156
157
|
|
|
157
158
|
## Dependencies
|
|
158
159
|
|
|
@@ -160,6 +161,18 @@ Package sizes (brotli'd, pre-treeshake): ESM: 816 bytes
|
|
|
160
161
|
- [@thi.ng/math](https://github.com/thi-ng/umbrella/tree/develop/packages/math)
|
|
161
162
|
- [@thi.ng/vectors](https://github.com/thi-ng/umbrella/tree/develop/packages/vectors)
|
|
162
163
|
|
|
164
|
+
## Usage examples
|
|
165
|
+
|
|
166
|
+
Several demos in this repo's
|
|
167
|
+
[/examples](https://github.com/thi-ng/umbrella/tree/develop/examples)
|
|
168
|
+
directory are using this package.
|
|
169
|
+
|
|
170
|
+
A selection:
|
|
171
|
+
|
|
172
|
+
| Screenshot | Description | Live demo | Source |
|
|
173
|
+
|:-------------------------------------------------------------------------------------------------------------------|:---------------------------------------------------------------|:--------------------------------------------------|:-------------------------------------------------------------------------------|
|
|
174
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/boid-basics.png" width="240"/> | Basic 2D boid simulation and spatial indexing neighbor lookups | [Demo](https://demo.thi.ng/umbrella/boid-basics/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/boid-basics) |
|
|
175
|
+
|
|
163
176
|
## API
|
|
164
177
|
|
|
165
178
|
[Generated API docs](https://docs.thi.ng/umbrella/timestep/)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/timestep",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Deterministic fixed timestep simulation updates with state interpolation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@thi.ng/api": "^8.9.6",
|
|
38
|
-
"@thi.ng/math": "^5.
|
|
39
|
-
"@thi.ng/vectors": "^7.
|
|
38
|
+
"@thi.ng/math": "^5.7.0",
|
|
39
|
+
"@thi.ng/vectors": "^7.8.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@microsoft/api-extractor": "^7.38.0",
|
|
@@ -88,5 +88,5 @@
|
|
|
88
88
|
"status": "alpha",
|
|
89
89
|
"year": 2023
|
|
90
90
|
},
|
|
91
|
-
"gitHead": "
|
|
91
|
+
"gitHead": "502e8fa937677ff7bc4fbd0906d8c8b4b0b471e5\n"
|
|
92
92
|
}
|
package/state.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IDeref } from "@thi.ng/api";
|
|
2
|
-
import type { ReadonlyVec, Vec, VecOpV, VecOpVVN } from "@thi.ng/vectors";
|
|
2
|
+
import type { ReadonlyVec, Vec, VecAPI, VecOpV, VecOpVVN } from "@thi.ng/vectors";
|
|
3
3
|
import type { ITimeStep, ReadonlyTimeStep, StateUpdate } from "./api.js";
|
|
4
4
|
export declare class NumericState implements IDeref<number>, ITimeStep {
|
|
5
5
|
value: number;
|
|
@@ -20,12 +20,12 @@ export declare class NumericState implements IDeref<number>, ITimeStep {
|
|
|
20
20
|
}
|
|
21
21
|
export declare class VectorState implements IDeref<ReadonlyVec>, ITimeStep {
|
|
22
22
|
value: Vec;
|
|
23
|
-
setFn: VecOpV;
|
|
24
|
-
mixFn: VecOpVVN;
|
|
25
23
|
update: StateUpdate<ReadonlyVec>;
|
|
26
24
|
prev: Vec;
|
|
27
25
|
curr: Vec;
|
|
28
|
-
|
|
26
|
+
setFn: VecOpV;
|
|
27
|
+
mixFn: VecOpVVN;
|
|
28
|
+
constructor(api: Pick<VecAPI, "set" | "mixN">, value: Vec, update: StateUpdate<ReadonlyVec>);
|
|
29
29
|
deref(): ReadonlyVec;
|
|
30
30
|
/**
|
|
31
31
|
* Copies given vector to {@link VectorState.prev}, {@link VectorState.curr}
|
|
@@ -47,18 +47,21 @@ export declare class VectorState implements IDeref<ReadonlyVec>, ITimeStep {
|
|
|
47
47
|
export declare const defNumeric: (x: number, update: StateUpdate<number>) => NumericState;
|
|
48
48
|
/**
|
|
49
49
|
* Returns a new {@link VectorState} wrapper for given vector `v` (arbitrary
|
|
50
|
-
* length) and its update function for use with {@link TimeStep.update}.
|
|
50
|
+
* length) and its update function for use with {@link TimeStep.update}. The
|
|
51
|
+
* `api` object is used to provide dedicated vector ops used internally.
|
|
51
52
|
*
|
|
52
53
|
* @remarks
|
|
53
|
-
* **IMPORTANT:** The `update` function MUST
|
|
54
|
-
*
|
|
54
|
+
* **IMPORTANT:** The `update` function MUST update the vector received as 1st
|
|
55
|
+
* arg (which is {@link VectorState.curr}).
|
|
55
56
|
*
|
|
56
|
-
* Also see {@link defVector2}, {@link defVector3}, {@link defVector4}
|
|
57
|
+
* Also see {@link defVector2}, {@link defVector3}, {@link defVector4} for
|
|
58
|
+
* pre-configured versions.
|
|
57
59
|
*
|
|
58
|
-
* @param
|
|
60
|
+
* @param api
|
|
61
|
+
* @param v
|
|
59
62
|
* @param update
|
|
60
63
|
*/
|
|
61
|
-
export declare const defVector: (v: ReadonlyVec, update: StateUpdate<ReadonlyVec>) => VectorState;
|
|
64
|
+
export declare const defVector: (api: Pick<VecAPI, "set" | "mixN">, v: ReadonlyVec, update: StateUpdate<ReadonlyVec>) => VectorState;
|
|
62
65
|
/**
|
|
63
66
|
* 2D optimized version of {@link defVector}.
|
|
64
67
|
*
|
package/state.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { mix } from "@thi.ng/math/mix";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { mixN2, mixN3, mixN4 } from "@thi.ng/vectors/mixn";
|
|
3
|
+
import { set2, set3, set4 } from "@thi.ng/vectors/set";
|
|
4
4
|
export class NumericState {
|
|
5
5
|
constructor(value, update) {
|
|
6
6
|
this.value = value;
|
|
@@ -28,13 +28,13 @@ export class NumericState {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
export class VectorState {
|
|
31
|
-
constructor(
|
|
31
|
+
constructor(api, value, update) {
|
|
32
32
|
this.value = value;
|
|
33
|
-
this.setFn = setFn;
|
|
34
|
-
this.mixFn = mixFn;
|
|
35
33
|
this.update = update;
|
|
36
|
-
this.
|
|
37
|
-
this.
|
|
34
|
+
this.setFn = api.set;
|
|
35
|
+
this.mixFn = api.mixN;
|
|
36
|
+
this.prev = this.setFn([], value);
|
|
37
|
+
this.curr = this.setFn([], value);
|
|
38
38
|
}
|
|
39
39
|
deref() {
|
|
40
40
|
return this.value;
|
|
@@ -69,36 +69,39 @@ export class VectorState {
|
|
|
69
69
|
export const defNumeric = (x, update) => new NumericState(x, update);
|
|
70
70
|
/**
|
|
71
71
|
* Returns a new {@link VectorState} wrapper for given vector `v` (arbitrary
|
|
72
|
-
* length) and its update function for use with {@link TimeStep.update}.
|
|
72
|
+
* length) and its update function for use with {@link TimeStep.update}. The
|
|
73
|
+
* `api` object is used to provide dedicated vector ops used internally.
|
|
73
74
|
*
|
|
74
75
|
* @remarks
|
|
75
|
-
* **IMPORTANT:** The `update` function MUST
|
|
76
|
-
*
|
|
76
|
+
* **IMPORTANT:** The `update` function MUST update the vector received as 1st
|
|
77
|
+
* arg (which is {@link VectorState.curr}).
|
|
77
78
|
*
|
|
78
|
-
* Also see {@link defVector2}, {@link defVector3}, {@link defVector4}
|
|
79
|
+
* Also see {@link defVector2}, {@link defVector3}, {@link defVector4} for
|
|
80
|
+
* pre-configured versions.
|
|
79
81
|
*
|
|
80
|
-
* @param
|
|
82
|
+
* @param api
|
|
83
|
+
* @param v
|
|
81
84
|
* @param update
|
|
82
85
|
*/
|
|
83
|
-
export const defVector = (v, update) => new VectorState(
|
|
86
|
+
export const defVector = (api, v, update) => new VectorState(api, v, update);
|
|
84
87
|
/**
|
|
85
88
|
* 2D optimized version of {@link defVector}.
|
|
86
89
|
*
|
|
87
90
|
* @param v
|
|
88
91
|
* @param update
|
|
89
92
|
*/
|
|
90
|
-
export const defVector2 = (v, update) => new VectorState(
|
|
93
|
+
export const defVector2 = (v, update) => new VectorState({ set: set2, mixN: mixN2 }, v, update);
|
|
91
94
|
/**
|
|
92
95
|
* 3D optimized version of {@link defVector}.
|
|
93
96
|
*
|
|
94
97
|
* @param v
|
|
95
98
|
* @param update
|
|
96
99
|
*/
|
|
97
|
-
export const defVector3 = (v, update) => new VectorState(
|
|
100
|
+
export const defVector3 = (v, update) => new VectorState({ set: set3, mixN: mixN3 }, v, update);
|
|
98
101
|
/**
|
|
99
102
|
* 4D optimized version of {@link defVector}.
|
|
100
103
|
*
|
|
101
104
|
* @param v
|
|
102
105
|
* @param update
|
|
103
106
|
*/
|
|
104
|
-
export const defVector4 = (v, update) => new VectorState(
|
|
107
|
+
export const defVector4 = (v, update) => new VectorState({ set: set4, mixN: mixN4 }, v, update);
|