@thi.ng/timestep 0.4.22 → 0.5.1
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 +17 -1
- package/package.json +7 -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-30T14:31:56Z
|
|
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
|
@@ -13,8 +13,10 @@ This project is part of the
|
|
|
13
13
|
- [About](#about)
|
|
14
14
|
- [Managing fixed timestep updates](#managing-fixed-timestep-updates)
|
|
15
15
|
- [Status](#status)
|
|
16
|
+
- [Related packages](#related-packages)
|
|
16
17
|
- [Installation](#installation)
|
|
17
18
|
- [Dependencies](#dependencies)
|
|
19
|
+
- [Usage examples](#usage-examples)
|
|
18
20
|
- [API](#api)
|
|
19
21
|
- [Authors](#authors)
|
|
20
22
|
- [License](#license)
|
|
@@ -132,6 +134,10 @@ after 1 second (25 frames)...
|
|
|
132
134
|
|
|
133
135
|
[Search or submit any issues for this package](https://github.com/thi-ng/umbrella/issues?q=%5Btimestep%5D+in%3Atitle)
|
|
134
136
|
|
|
137
|
+
## Related packages
|
|
138
|
+
|
|
139
|
+
- [@thi.ng/boids](https://github.com/thi-ng/umbrella/tree/develop/packages/boids) - n-dimensional boids simulation with highly configurable behaviors
|
|
140
|
+
|
|
135
141
|
## Installation
|
|
136
142
|
|
|
137
143
|
```bash
|
|
@@ -152,7 +158,7 @@ For Node.js REPL:
|
|
|
152
158
|
const timestep = await import("@thi.ng/timestep");
|
|
153
159
|
```
|
|
154
160
|
|
|
155
|
-
Package sizes (brotli'd, pre-treeshake): ESM:
|
|
161
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 821 bytes
|
|
156
162
|
|
|
157
163
|
## Dependencies
|
|
158
164
|
|
|
@@ -160,6 +166,16 @@ Package sizes (brotli'd, pre-treeshake): ESM: 816 bytes
|
|
|
160
166
|
- [@thi.ng/math](https://github.com/thi-ng/umbrella/tree/develop/packages/math)
|
|
161
167
|
- [@thi.ng/vectors](https://github.com/thi-ng/umbrella/tree/develop/packages/vectors)
|
|
162
168
|
|
|
169
|
+
## Usage examples
|
|
170
|
+
|
|
171
|
+
One project in this repo's
|
|
172
|
+
[/examples](https://github.com/thi-ng/umbrella/tree/develop/examples)
|
|
173
|
+
directory is using this package:
|
|
174
|
+
|
|
175
|
+
| Screenshot | Description | Live demo | Source |
|
|
176
|
+
|:-------------------------------------------------------------------------------------------------------------------|:---------------------------------------------------------------|:--------------------------------------------------|:-------------------------------------------------------------------------------|
|
|
177
|
+
| <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) |
|
|
178
|
+
|
|
163
179
|
## API
|
|
164
180
|
|
|
165
181
|
[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.1",
|
|
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.1",
|
|
39
|
+
"@thi.ng/vectors": "^7.8.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@microsoft/api-extractor": "^7.38.0",
|
|
@@ -85,8 +85,11 @@
|
|
|
85
85
|
}
|
|
86
86
|
},
|
|
87
87
|
"thi.ng": {
|
|
88
|
+
"related": [
|
|
89
|
+
"boids"
|
|
90
|
+
],
|
|
88
91
|
"status": "alpha",
|
|
89
92
|
"year": 2023
|
|
90
93
|
},
|
|
91
|
-
"gitHead": "
|
|
94
|
+
"gitHead": "bfa16829786146bd24df3cdbd44649a45a603e44\n"
|
|
92
95
|
}
|
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);
|