@thi.ng/boids 0.1.2 → 0.1.5
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 +7 -1
- package/README.md +1 -1
- package/boid.d.ts +45 -0
- package/boid.js +55 -3
- package/package.json +12 -13
- package/region.js +5 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2023-
|
|
3
|
+
- **Last updated**: 2023-11-09T10:28:18Z
|
|
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.1.3](https://github.com/thi-ng/umbrella/tree/@thi.ng/boids@0.1.3) (2023-11-09)
|
|
13
|
+
|
|
14
|
+
#### ♻️ Refactoring
|
|
15
|
+
|
|
16
|
+
- update all tests (packages A-S) ([e3085e4](https://github.com/thi-ng/umbrella/commit/e3085e4))
|
|
17
|
+
|
|
12
18
|
## [0.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/boids@0.1.0) (2023-10-27)
|
|
13
19
|
|
|
14
20
|
#### 🚀 Features
|
package/README.md
CHANGED
package/boid.d.ts
CHANGED
|
@@ -17,8 +17,35 @@ export declare class Boid implements ITimeStep {
|
|
|
17
17
|
protected tmpAlign: Vec;
|
|
18
18
|
protected tmpCoh: Vec;
|
|
19
19
|
constructor(accel: AHashGrid<Boid>, api: VecAPI, distance: IDistance<ReadonlyVec>, pos: Vec, vel: Vec, opts: Partial<BoidOpts>);
|
|
20
|
+
/**
|
|
21
|
+
* Integration step of the thi.ng/timestep update cycle. See
|
|
22
|
+
* [`ITimeStep`](https://docs.thi.ng/umbrella/timestep/interfaces/ITimeStep.html)
|
|
23
|
+
*
|
|
24
|
+
* @param dt
|
|
25
|
+
* @param ctx
|
|
26
|
+
*/
|
|
20
27
|
integrate(dt: number, ctx: ReadonlyTimeStep): void;
|
|
28
|
+
/**
|
|
29
|
+
* Interplation step of the thi.ng/timestep update cycle. See
|
|
30
|
+
* [`ITimeStep`](https://docs.thi.ng/umbrella/timestep/interfaces/ITimeStep.html)
|
|
31
|
+
*
|
|
32
|
+
* @param dt
|
|
33
|
+
* @param ctx
|
|
34
|
+
*/
|
|
21
35
|
interpolate(alpha: number, ctx: ReadonlyTimeStep): void;
|
|
36
|
+
/**
|
|
37
|
+
* Queries the spatial index for other boids in the current region, or if
|
|
38
|
+
* `pos` is given also moves the search region to new position before
|
|
39
|
+
* querying.
|
|
40
|
+
*
|
|
41
|
+
* @remarks
|
|
42
|
+
* IMPORTANT: The returned array will always contain the current boid itself
|
|
43
|
+
* too. Filtering has been left out here for performance reasons and is left
|
|
44
|
+
* to downstream code.
|
|
45
|
+
*
|
|
46
|
+
* @param r
|
|
47
|
+
* @param pos
|
|
48
|
+
*/
|
|
22
49
|
neighbors(r: number, pos?: Vec): Boid[];
|
|
23
50
|
protected separate(): Vec;
|
|
24
51
|
protected align(): Vec;
|
|
@@ -27,6 +54,24 @@ export declare class Boid implements ITimeStep {
|
|
|
27
54
|
protected computeSteer(steer: Vec, num: number): Vec;
|
|
28
55
|
protected limitSteer(steer: Vec): Vec;
|
|
29
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Returns a new {@link Boid} instance configured to use optimized 2D vector
|
|
59
|
+
* operations.
|
|
60
|
+
*
|
|
61
|
+
* @param accel
|
|
62
|
+
* @param pos
|
|
63
|
+
* @param vel
|
|
64
|
+
* @param opts
|
|
65
|
+
*/
|
|
30
66
|
export declare const defBoid2: (accel: HashGrid2<Boid>, pos: Vec, vel: Vec, opts: Partial<BoidOpts>) => Boid;
|
|
67
|
+
/**
|
|
68
|
+
* Returns a new {@link Boid} instance configured to use optimized 3D vector
|
|
69
|
+
* operations.
|
|
70
|
+
*
|
|
71
|
+
* @param accel
|
|
72
|
+
* @param pos
|
|
73
|
+
* @param vel
|
|
74
|
+
* @param opts
|
|
75
|
+
*/
|
|
31
76
|
export declare const defBoid3: (accel: HashGrid3<Boid>, pos: Vec, vel: Vec, opts: Partial<BoidOpts>) => Boid;
|
|
32
77
|
//# sourceMappingURL=boid.d.ts.map
|
package/boid.js
CHANGED
|
@@ -7,12 +7,19 @@ import { VEC2 } from "@thi.ng/vectors/vec2-api";
|
|
|
7
7
|
import { VEC3 } from "@thi.ng/vectors/vec3-api";
|
|
8
8
|
import { Radial } from "./region.js";
|
|
9
9
|
export class Boid {
|
|
10
|
+
accel;
|
|
11
|
+
api;
|
|
12
|
+
pos;
|
|
13
|
+
vel;
|
|
14
|
+
opts;
|
|
15
|
+
region;
|
|
16
|
+
cachedNeighbors;
|
|
17
|
+
tmpSep = [];
|
|
18
|
+
tmpAlign = [];
|
|
19
|
+
tmpCoh = [];
|
|
10
20
|
constructor(accel, api, distance, pos, vel, opts) {
|
|
11
21
|
this.accel = accel;
|
|
12
22
|
this.api = api;
|
|
13
|
-
this.tmpSep = [];
|
|
14
|
-
this.tmpAlign = [];
|
|
15
|
-
this.tmpCoh = [];
|
|
16
23
|
this.opts = {
|
|
17
24
|
constrain: identity,
|
|
18
25
|
maxSpeed: 10,
|
|
@@ -28,13 +35,40 @@ export class Boid {
|
|
|
28
35
|
this.pos = defVector(api, pos, (pos, dt) => this.opts.constrain(api.maddN(pos, this.vel.curr, dt, pos)));
|
|
29
36
|
this.region = new Radial(distance, pos, 1);
|
|
30
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Integration step of the thi.ng/timestep update cycle. See
|
|
40
|
+
* [`ITimeStep`](https://docs.thi.ng/umbrella/timestep/interfaces/ITimeStep.html)
|
|
41
|
+
*
|
|
42
|
+
* @param dt
|
|
43
|
+
* @param ctx
|
|
44
|
+
*/
|
|
31
45
|
integrate(dt, ctx) {
|
|
32
46
|
this.cachedNeighbors = this.neighbors(this.opts.maxDist, this.pos.value);
|
|
33
47
|
integrateAll(dt, ctx, this.vel, this.pos);
|
|
34
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Interplation step of the thi.ng/timestep update cycle. See
|
|
51
|
+
* [`ITimeStep`](https://docs.thi.ng/umbrella/timestep/interfaces/ITimeStep.html)
|
|
52
|
+
*
|
|
53
|
+
* @param dt
|
|
54
|
+
* @param ctx
|
|
55
|
+
*/
|
|
35
56
|
interpolate(alpha, ctx) {
|
|
36
57
|
interpolateAll(alpha, ctx, this.vel, this.pos);
|
|
37
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Queries the spatial index for other boids in the current region, or if
|
|
61
|
+
* `pos` is given also moves the search region to new position before
|
|
62
|
+
* querying.
|
|
63
|
+
*
|
|
64
|
+
* @remarks
|
|
65
|
+
* IMPORTANT: The returned array will always contain the current boid itself
|
|
66
|
+
* too. Filtering has been left out here for performance reasons and is left
|
|
67
|
+
* to downstream code.
|
|
68
|
+
*
|
|
69
|
+
* @param r
|
|
70
|
+
* @param pos
|
|
71
|
+
*/
|
|
38
72
|
neighbors(r, pos) {
|
|
39
73
|
const region = this.region;
|
|
40
74
|
if (pos)
|
|
@@ -99,5 +133,23 @@ export class Boid {
|
|
|
99
133
|
: steer;
|
|
100
134
|
}
|
|
101
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Returns a new {@link Boid} instance configured to use optimized 2D vector
|
|
138
|
+
* operations.
|
|
139
|
+
*
|
|
140
|
+
* @param accel
|
|
141
|
+
* @param pos
|
|
142
|
+
* @param vel
|
|
143
|
+
* @param opts
|
|
144
|
+
*/
|
|
102
145
|
export const defBoid2 = (accel, pos, vel, opts) => new Boid(accel, VEC2, DIST_SQ2, pos, vel, opts);
|
|
146
|
+
/**
|
|
147
|
+
* Returns a new {@link Boid} instance configured to use optimized 3D vector
|
|
148
|
+
* operations.
|
|
149
|
+
*
|
|
150
|
+
* @param accel
|
|
151
|
+
* @param pos
|
|
152
|
+
* @param vel
|
|
153
|
+
* @param opts
|
|
154
|
+
*/
|
|
103
155
|
export const defBoid3 = (accel, pos, vel, opts) => new Boid(accel, VEC3, DIST_SQ3, pos, vel, opts);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/boids",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "n-dimensional boids simulation with highly configurable behaviors",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -28,24 +28,23 @@
|
|
|
28
28
|
"clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc",
|
|
29
29
|
"doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
|
|
30
30
|
"doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
|
|
31
|
-
"doc:readme": "
|
|
32
|
-
"doc:stats": "tools:module-stats",
|
|
31
|
+
"doc:readme": "bun ../../tools/src/module-stats.ts && bun ../../tools/src/readme.ts",
|
|
33
32
|
"pub": "yarn npm publish --access public",
|
|
34
|
-
"test": "
|
|
33
|
+
"test": "bun test"
|
|
35
34
|
},
|
|
36
35
|
"dependencies": {
|
|
37
|
-
"@thi.ng/api": "^8.9.
|
|
38
|
-
"@thi.ng/distance": "^2.4.
|
|
39
|
-
"@thi.ng/geom-accel": "^3.5.
|
|
40
|
-
"@thi.ng/timestep": "^0.5.
|
|
41
|
-
"@thi.ng/vectors": "^7.8.
|
|
36
|
+
"@thi.ng/api": "^8.9.8",
|
|
37
|
+
"@thi.ng/distance": "^2.4.30",
|
|
38
|
+
"@thi.ng/geom-accel": "^3.5.30",
|
|
39
|
+
"@thi.ng/timestep": "^0.5.5",
|
|
40
|
+
"@thi.ng/vectors": "^7.8.5"
|
|
42
41
|
},
|
|
43
42
|
"devDependencies": {
|
|
44
|
-
"@microsoft/api-extractor": "^7.38.
|
|
45
|
-
"@thi.ng/testament": "^0.
|
|
43
|
+
"@microsoft/api-extractor": "^7.38.2",
|
|
44
|
+
"@thi.ng/testament": "^0.4.1",
|
|
46
45
|
"rimraf": "^5.0.5",
|
|
47
46
|
"tools": "^0.0.1",
|
|
48
|
-
"typedoc": "^0.25.
|
|
47
|
+
"typedoc": "^0.25.3",
|
|
49
48
|
"typescript": "^5.2.2"
|
|
50
49
|
},
|
|
51
50
|
"keywords": [
|
|
@@ -91,5 +90,5 @@
|
|
|
91
90
|
"status": "alpha",
|
|
92
91
|
"year": 2023
|
|
93
92
|
},
|
|
94
|
-
"gitHead": "
|
|
93
|
+
"gitHead": "2be4c38c9680da929339bd164acfb69ebb1fd3d0\n"
|
|
95
94
|
}
|
package/region.js
CHANGED
|
@@ -7,11 +7,15 @@ import {} from "@thi.ng/api";
|
|
|
7
7
|
* @internal
|
|
8
8
|
*/
|
|
9
9
|
export class Radial {
|
|
10
|
+
dist;
|
|
11
|
+
target;
|
|
12
|
+
radius;
|
|
13
|
+
_r;
|
|
14
|
+
_items = [];
|
|
10
15
|
constructor(dist, target, radius = Infinity) {
|
|
11
16
|
this.dist = dist;
|
|
12
17
|
this.target = target;
|
|
13
18
|
this.radius = radius;
|
|
14
|
-
this._items = [];
|
|
15
19
|
this.setRadius(radius);
|
|
16
20
|
}
|
|
17
21
|
deref() {
|