@thi.ng/boids 1.1.8 → 1.1.10

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**: 2025-06-09T17:24:08Z
3
+ - **Last updated**: 2025-06-19T13:15:11Z
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/accel.js CHANGED
@@ -5,7 +5,10 @@ const noAccel = () => {
5
5
  boids = $boids;
6
6
  },
7
7
  queryNeighborhood(neighborhood) {
8
- for (let b of boids) neighborhood.consider(b.pos.curr, b);
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
  };
@@ -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 (let i = 0; i < num; i++) {
13
- const n = neighbors[i];
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
  }
@@ -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
- for (let i = 0; i < num; i++) {
14
- const n = neighbors[i];
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++;
@@ -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
- (amp?.(boid, n) ?? 1) / (magSq(delta) + 1e-6),
22
+ amp(boid, n) / (magSq(delta) + 1e-6),
23
23
  force
24
24
  );
25
25
  }
@@ -5,9 +5,10 @@ const blendedBehaviorUpdate = (boid) => {
5
5
  force
6
6
  } = boid;
7
7
  setN(force, 0);
8
- for (let i = 0, n = behaviors.length; i < n; i++) {
9
- const behavior = behaviors[i];
10
- const weight = behavior.weight(boid);
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] = wrapOnce(x, min, max);
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.8",
3
+ "version": "1.1.10",
4
4
  "description": "n-dimensional boids simulation with modular behavior system",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -41,12 +41,12 @@
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.0",
45
- "@thi.ng/geom-closest-point": "^2.1.175",
46
- "@thi.ng/geom-resample": "^3.0.47",
44
+ "@thi.ng/distance": "^3.0.1",
45
+ "@thi.ng/geom-closest-point": "^2.1.176",
46
+ "@thi.ng/geom-resample": "^3.0.48",
47
47
  "@thi.ng/math": "^5.11.29",
48
- "@thi.ng/timestep": "^1.0.23",
49
- "@thi.ng/vectors": "^8.3.0"
48
+ "@thi.ng/timestep": "^1.0.24",
49
+ "@thi.ng/vectors": "^8.3.1"
50
50
  },
51
51
  "devDependencies": {
52
52
  "esbuild": "^0.25.5",
@@ -147,5 +147,5 @@
147
147
  "status": "alpha",
148
148
  "year": 2023
149
149
  },
150
- "gitHead": "14e994e531d32053e948768998324d443436a542\n"
150
+ "gitHead": "091008063a5999d05b8f54bb22cfbd6d9b66f7f6\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): void;
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 = Math.max(0, r);
20
- this._r = this.dist.to(this.radius);
21
- this.reset();
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;