@thi.ng/boids 1.1.2 → 1.1.4

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-05-08T16:55:57Z
3
+ - **Last updated**: 2025-05-12T07:30:37Z
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,19 @@ 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.4](https://github.com/thi-ng/umbrella/tree/@thi.ng/boids@1.1.4) (2025-05-12)
15
+
16
+ #### ⏱ Performance improvements
17
+
18
+ - add Boid.force, update blendedBehaviorUpdate() ([dbb3178](https://github.com/thi-ng/umbrella/commit/dbb3178))
19
+ - pre-allocate force vector to avoid re-allocations for every frame
20
+
21
+ ### [1.1.3](https://github.com/thi-ng/umbrella/tree/@thi.ng/boids@1.1.3) (2025-05-09)
22
+
23
+ #### 🩹 Bug fixes
24
+
25
+ - off-by-one error in cohesion() ([e93b66c](https://github.com/thi-ng/umbrella/commit/e93b66c))
26
+
14
27
  ### [1.1.2](https://github.com/thi-ng/umbrella/tree/@thi.ng/boids@1.1.2) (2025-05-08)
15
28
 
16
29
  #### 🩹 Bug fixes
@@ -17,7 +17,7 @@ const cohesion = (maxDist, weight = 1, pred = () => true) => {
17
17
  used++;
18
18
  }
19
19
  }
20
- return used > 1 ? boid.steerTowards(mulN(centroid, centroid, 1 / (used - 1))) : centroid;
20
+ return used > 0 ? boid.steerTowards(mulN(centroid, centroid, 1 / used)) : centroid;
21
21
  }
22
22
  };
23
23
  };
@@ -1,4 +1,3 @@
1
- import type { Vec } from "@thi.ng/vectors";
2
1
  import type { Boid } from "../boid.js";
3
2
  /**
4
3
  * Behavior update function (the default implementation fro
@@ -10,5 +9,5 @@ import type { Boid } from "../boid.js";
10
9
  *
11
10
  * @param boid
12
11
  */
13
- export declare const blendedBehaviorUpdate: (boid: Boid) => Vec<number>;
12
+ export declare const blendedBehaviorUpdate: (boid: Boid) => import("@thi.ng/vectors").Vec<number>;
14
13
  //# sourceMappingURL=update.d.ts.map
@@ -1,7 +1,12 @@
1
1
  const blendedBehaviorUpdate = (boid) => {
2
- const { maddN, zeroes } = boid.api;
3
- const force = zeroes();
4
- for (let behavior of boid.behaviors) {
2
+ const {
3
+ api: { maddN, setN },
4
+ behaviors,
5
+ force
6
+ } = boid;
7
+ setN(force, 0);
8
+ for (let i = 0, n = behaviors.length; i < n; i++) {
9
+ const behavior = behaviors[i];
5
10
  const weight = behavior.weight(boid);
6
11
  if (weight !== 0) maddN(force, behavior.update(boid), weight, force);
7
12
  }
package/boid.d.ts CHANGED
@@ -12,6 +12,11 @@ export declare class Boid implements ITimeStep {
12
12
  behaviors: IBoidBehavior[];
13
13
  region: Radial<Boid>;
14
14
  opts: BoidOpts;
15
+ /**
16
+ * Pre-allocated vector for force accumulation, used by/for behavior
17
+ * updates.
18
+ */
19
+ force: Vec;
15
20
  constructor(opts: BoidOpts, api: VecAPI, distance: IDistance<ReadonlyVec>, pos: Vec, vel: Vec);
16
21
  /**
17
22
  * Integration step of the thi.ng/timestep update cycle. See
package/boid.js CHANGED
@@ -14,6 +14,11 @@ class Boid {
14
14
  behaviors;
15
15
  region;
16
16
  opts;
17
+ /**
18
+ * Pre-allocated vector for force accumulation, used by/for behavior
19
+ * updates.
20
+ */
21
+ force;
17
22
  constructor(opts, api, distance, pos, vel) {
18
23
  this.api = api;
19
24
  this.opts = { maxForce: 1, ...opts };
@@ -33,6 +38,7 @@ class Boid {
33
38
  (pos2, dt) => constrain(maddN(pos2, this.vel.curr, dt, pos2), this)
34
39
  );
35
40
  this.region = new Radial(distance, pos, 1);
41
+ this.force = api.zeroes();
36
42
  }
37
43
  /**
38
44
  * Integration step of the thi.ng/timestep update cycle. See
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/boids",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "n-dimensional boids simulation with modular behavior system",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -147,5 +147,5 @@
147
147
  "status": "alpha",
148
148
  "year": 2023
149
149
  },
150
- "gitHead": "9c77f9a75362561a47962e81b01366c0d3d09c8c\n"
150
+ "gitHead": "b730f03f5ff2a06cb2703c414ddacf8c46f66fb7\n"
151
151
  }