@thi.ng/boids 1.1.1 → 1.1.3

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:48:10Z
3
+ - **Last updated**: 2025-05-09T10:26:34Z
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,18 @@ 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.3](https://github.com/thi-ng/umbrella/tree/@thi.ng/boids@1.1.3) (2025-05-09)
15
+
16
+ #### 🩹 Bug fixes
17
+
18
+ - off-by-one error in cohesion() ([e93b66c](https://github.com/thi-ng/umbrella/commit/e93b66c))
19
+
20
+ ### [1.1.2](https://github.com/thi-ng/umbrella/tree/@thi.ng/boids@1.1.2) (2025-05-08)
21
+
22
+ #### 🩹 Bug fixes
23
+
24
+ - update cohesion(), count used neighbors only ([9eef80c](https://github.com/thi-ng/umbrella/commit/9eef80c))
25
+
14
26
  ### [1.1.1](https://github.com/thi-ng/umbrella/tree/@thi.ng/boids@1.1.1) (2025-05-08)
15
27
 
16
28
  #### 🩹 Bug fixes
@@ -7,14 +7,17 @@ const cohesion = (maxDist, weight = 1, pred = () => true) => {
7
7
  update: (boid) => {
8
8
  const { add, mulN, setN } = boid.api;
9
9
  const neighbors = boid.neighbors($maxDist(boid), boid.pos.curr);
10
- const num = neighbors.length;
11
10
  setN(centroid, 0);
11
+ let used = 0;
12
+ const num = neighbors.length;
12
13
  for (let i = 0; i < num; i++) {
13
14
  const n = neighbors[i];
14
- if (n !== boid && pred(boid, n))
15
+ if (n !== boid && pred(boid, n)) {
15
16
  add(centroid, centroid, n.pos.curr);
17
+ used++;
18
+ }
16
19
  }
17
- return num > 1 ? boid.steerTowards(mulN(centroid, centroid, 1 / (num - 1))) : centroid;
20
+ return used > 0 ? boid.steerTowards(mulN(centroid, centroid, 1 / used)) : centroid;
18
21
  }
19
22
  };
20
23
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/boids",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
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": "a28559ffe7cc0157c84b3c33a29f6b1f681e8c13\n"
150
+ "gitHead": "131482d456dca3b0a1e839f4ecad1f83cb6ada8e\n"
151
151
  }