@thi.ng/boids 1.1.9 → 1.1.11
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 +9 -1
- package/README.md +1 -1
- package/accel.js +4 -1
- package/behaviors/alignment.js +3 -2
- package/behaviors/cohesion.js +3 -3
- package/behaviors/separation.js +2 -2
- package/behaviors/update.js +4 -3
- package/constrain.js +1 -2
- package/package.json +3 -3
- package/region.d.ts +1 -1
- package/region.js +7 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2025-06-
|
|
3
|
+
- **Last updated**: 2025-06-24T21:39:38Z
|
|
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.
|
|
@@ -11,6 +11,14 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
11
11
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
12
12
|
and/or version bumps of transitive dependencies.
|
|
13
13
|
|
|
14
|
+
### [1.1.10](https://github.com/thi-ng/umbrella/tree/@thi.ng/boids@1.1.10) (2025-06-19)
|
|
15
|
+
|
|
16
|
+
#### ⏱ Performance improvements
|
|
17
|
+
|
|
18
|
+
- various minor optimizations ([f47c986](https://github.com/thi-ng/umbrella/commit/f47c986))
|
|
19
|
+
- hoist local vars in hotspots
|
|
20
|
+
- update Radial.setRadius() to avoid distance calc if possible
|
|
21
|
+
|
|
14
22
|
### [1.1.4](https://github.com/thi-ng/umbrella/tree/@thi.ng/boids@1.1.4) (2025-05-12)
|
|
15
23
|
|
|
16
24
|
#### ⏱ Performance improvements
|
package/README.md
CHANGED
package/accel.js
CHANGED
|
@@ -5,7 +5,10 @@ const noAccel = () => {
|
|
|
5
5
|
boids = $boids;
|
|
6
6
|
},
|
|
7
7
|
queryNeighborhood(neighborhood) {
|
|
8
|
-
for (let
|
|
8
|
+
for (let i = 0, n = boids.length; i < n; i++) {
|
|
9
|
+
const b = boids[i];
|
|
10
|
+
neighborhood.consider(b.pos.curr, b);
|
|
11
|
+
}
|
|
9
12
|
return neighborhood;
|
|
10
13
|
}
|
|
11
14
|
};
|
package/behaviors/alignment.js
CHANGED
|
@@ -8,9 +8,10 @@ const alignment = (maxDist, weight = 1, amp) => {
|
|
|
8
8
|
const { add, maddN, setN } = boid.api;
|
|
9
9
|
const neighbors = boid.neighbors($maxDist(boid), boid.pos.curr);
|
|
10
10
|
const num = neighbors.length;
|
|
11
|
+
let i, n;
|
|
11
12
|
setN(force, 0);
|
|
12
|
-
for (
|
|
13
|
-
|
|
13
|
+
for (i = 0; i < num; i++) {
|
|
14
|
+
n = neighbors[i];
|
|
14
15
|
if (n !== boid) {
|
|
15
16
|
amp ? maddN(force, n.vel.curr, amp(boid, n), force) : add(force, force, n.vel.curr);
|
|
16
17
|
}
|
package/behaviors/cohesion.js
CHANGED
|
@@ -8,10 +8,10 @@ const cohesion = (maxDist, weight = 1, pred = () => true) => {
|
|
|
8
8
|
const { add, mulN, setN } = boid.api;
|
|
9
9
|
const neighbors = boid.neighbors($maxDist(boid), boid.pos.curr);
|
|
10
10
|
setN(centroid, 0);
|
|
11
|
-
let used = 0;
|
|
12
11
|
const num = neighbors.length;
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
let used = 0, i, n;
|
|
13
|
+
for (i = 0; i < num; i++) {
|
|
14
|
+
n = neighbors[i];
|
|
15
15
|
if (n !== boid && pred(boid, n)) {
|
|
16
16
|
add(centroid, centroid, n.pos.curr);
|
|
17
17
|
used++;
|
package/behaviors/separation.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __ensureFn } from "../internal/ensure.js";
|
|
2
|
-
const separation = (minDist, weight = 1, amp) => {
|
|
2
|
+
const separation = (minDist, weight = 1, amp = () => 1) => {
|
|
3
3
|
const $minDist = __ensureFn(minDist);
|
|
4
4
|
const force = [];
|
|
5
5
|
const delta = [];
|
|
@@ -19,7 +19,7 @@ const separation = (minDist, weight = 1, amp) => {
|
|
|
19
19
|
maddN(
|
|
20
20
|
force,
|
|
21
21
|
delta,
|
|
22
|
-
|
|
22
|
+
amp(boid, n) / (magSq(delta) + 1e-6),
|
|
23
23
|
force
|
|
24
24
|
);
|
|
25
25
|
}
|
package/behaviors/update.js
CHANGED
|
@@ -5,9 +5,10 @@ const blendedBehaviorUpdate = (boid) => {
|
|
|
5
5
|
force
|
|
6
6
|
} = boid;
|
|
7
7
|
setN(force, 0);
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
let i, n, weight, behavior;
|
|
9
|
+
for (i = 0, n = behaviors.length; i < n; i++) {
|
|
10
|
+
behavior = behaviors[i];
|
|
11
|
+
weight = behavior.weight(boid);
|
|
11
12
|
if (weight !== 0) maddN(force, behavior.update(boid), weight, force);
|
|
12
13
|
}
|
|
13
14
|
return force;
|
package/constrain.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { wrapOnce } from "@thi.ng/math/interval";
|
|
2
1
|
import { clamp2 as $clamp2, clamp3 as $clamp3 } from "@thi.ng/vectors/clamp";
|
|
3
2
|
const clamp2 = (min, max) => (p) => $clamp2(p, p, min, max);
|
|
4
3
|
const clamp3 = (min, max) => (p) => $clamp3(p, p, min, max);
|
|
5
4
|
const __wrap = (p, i, x, min, max) => {
|
|
6
5
|
if (x < min || x > max) {
|
|
7
|
-
p[i] =
|
|
6
|
+
p[i] = x < min ? x - min + max : x > max ? x - max + min : x;
|
|
8
7
|
return true;
|
|
9
8
|
}
|
|
10
9
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/boids",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.11",
|
|
4
4
|
"description": "n-dimensional boids simulation with modular behavior system",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@thi.ng/api": "^8.11.29",
|
|
43
43
|
"@thi.ng/checks": "^3.7.9",
|
|
44
|
-
"@thi.ng/distance": "^3.0.
|
|
44
|
+
"@thi.ng/distance": "^3.0.2",
|
|
45
45
|
"@thi.ng/geom-closest-point": "^2.1.176",
|
|
46
46
|
"@thi.ng/geom-resample": "^3.0.48",
|
|
47
47
|
"@thi.ng/math": "^5.11.29",
|
|
@@ -147,5 +147,5 @@
|
|
|
147
147
|
"status": "alpha",
|
|
148
148
|
"year": 2023
|
|
149
149
|
},
|
|
150
|
-
"gitHead": "
|
|
150
|
+
"gitHead": "45e91ee75236e39fc87ea10fbabac1272bef62e3\n"
|
|
151
151
|
}
|
package/region.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export declare class Radial<T> implements INeighborhood<ReadonlyVec, T>, IDeref<
|
|
|
16
16
|
constructor(dist: IDistance<ReadonlyVec>, target: ReadonlyVec, radius?: number);
|
|
17
17
|
deref(): T[];
|
|
18
18
|
reset(): this;
|
|
19
|
-
setRadius(r: number):
|
|
19
|
+
setRadius(r: number): this;
|
|
20
20
|
includesDistance(d: number, eucledian?: boolean): boolean;
|
|
21
21
|
includesPosition(pos: ReadonlyVec): boolean;
|
|
22
22
|
consider(pos: ReadonlyVec, val: T): number;
|
package/region.js
CHANGED
|
@@ -3,9 +3,9 @@ class Radial {
|
|
|
3
3
|
constructor(dist, target, radius = Infinity) {
|
|
4
4
|
this.dist = dist;
|
|
5
5
|
this.target = target;
|
|
6
|
-
this.radius = radius;
|
|
7
6
|
this.setRadius(radius);
|
|
8
7
|
}
|
|
8
|
+
radius;
|
|
9
9
|
_r;
|
|
10
10
|
_items = [];
|
|
11
11
|
deref() {
|
|
@@ -16,9 +16,12 @@ class Radial {
|
|
|
16
16
|
return this;
|
|
17
17
|
}
|
|
18
18
|
setRadius(r) {
|
|
19
|
-
this.radius
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
if (this.radius !== r) {
|
|
20
|
+
this.radius = Math.max(0, r);
|
|
21
|
+
this._r = this.dist.to(this.radius);
|
|
22
|
+
}
|
|
23
|
+
this._items.length = 0;
|
|
24
|
+
return this;
|
|
22
25
|
}
|
|
23
26
|
includesDistance(d, eucledian = true) {
|
|
24
27
|
return (eucledian ? this.dist.to(d) : d) <= this._r;
|