@thi.ng/boids 1.1.0 → 1.1.1

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-08T15:13:02Z
3
+ - **Last updated**: 2025-05-08T16:48:10Z
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,12 @@ 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.1](https://github.com/thi-ng/umbrella/tree/@thi.ng/boids@1.1.1) (2025-05-08)
15
+
16
+ #### 🩹 Bug fixes
17
+
18
+ - update cohesion(), use filter predicate ([66d219b](https://github.com/thi-ng/umbrella/commit/66d219b))
19
+
14
20
  ## [1.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/boids@1.1.0) (2025-05-08)
15
21
 
16
22
  #### 🚀 Features
@@ -1,5 +1,16 @@
1
- import type { FnU2 } from "@thi.ng/api";
1
+ import type { Predicate2 } from "@thi.ng/api";
2
2
  import type { IBoidBehavior, ScalarOrField } from "../api.js";
3
3
  import type { Boid } from "../boid.js";
4
- export declare const cohesion: (maxDist: ScalarOrField, weight?: ScalarOrField, amp?: FnU2<Boid, number>) => IBoidBehavior;
4
+ /**
5
+ * Cohesion behavior. Attempts to move boid towards centroid of neighboring
6
+ * boids within `maxDist`. The behavior itself can be weighted via `weight`.
7
+ * Neighbors can be filtered via optional `filter` predicate, which receives
8
+ * current boid as first arg and current neighbor as second. By default all
9
+ * neighbors are considered.
10
+ *
11
+ * @param maxDist
12
+ * @param weight
13
+ * @param pred
14
+ */
15
+ export declare const cohesion: (maxDist: ScalarOrField, weight?: ScalarOrField, pred?: Predicate2<Boid>) => IBoidBehavior;
5
16
  //# sourceMappingURL=cohesion.d.ts.map
@@ -1,19 +1,18 @@
1
1
  import { __ensureFn } from "../internal/ensure.js";
2
- const cohesion = (maxDist, weight = 1, amp) => {
2
+ const cohesion = (maxDist, weight = 1, pred = () => true) => {
3
3
  const $maxDist = __ensureFn(maxDist);
4
4
  const centroid = [];
5
5
  return {
6
6
  weight: __ensureFn(weight),
7
7
  update: (boid) => {
8
- const { add, maddN, mulN, setN } = boid.api;
8
+ const { add, mulN, setN } = boid.api;
9
9
  const neighbors = boid.neighbors($maxDist(boid), boid.pos.curr);
10
10
  const num = neighbors.length;
11
11
  setN(centroid, 0);
12
12
  for (let i = 0; i < num; i++) {
13
13
  const n = neighbors[i];
14
- if (n !== boid) {
15
- amp ? maddN(centroid, n.pos.curr, amp(boid, n), centroid) : add(centroid, centroid, n.pos.curr);
16
- }
14
+ if (n !== boid && pred(boid, n))
15
+ add(centroid, centroid, n.pos.curr);
17
16
  }
18
17
  return num > 1 ? boid.steerTowards(mulN(centroid, centroid, 1 / (num - 1))) : centroid;
19
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/boids",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
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": "8e61726779260744ea70bfe38438e755d6b53844\n"
150
+ "gitHead": "a28559ffe7cc0157c84b3c33a29f6b1f681e8c13\n"
151
151
  }