@thi.ng/distance 2.1.39 → 2.2.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**: 2023-01-10T15:20:18Z
3
+ - **Last updated**: 2023-02-10T13:55:29Z
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.
@@ -9,6 +9,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ## [2.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/distance@2.2.0) (2023-02-05)
13
+
14
+ #### 🚀 Features
15
+
16
+ - update KNearest, add setters ([6b185f4](https://github.com/thi-ng/umbrella/commit/6b185f4))
17
+
12
18
  ## [2.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/distance@2.1.0) (2021-11-17)
13
19
 
14
20
  #### 🚀 Features
package/README.md CHANGED
@@ -19,6 +19,7 @@ This project is part of the
19
19
  - [Related packages](#related-packages)
20
20
  - [Installation](#installation)
21
21
  - [Dependencies](#dependencies)
22
+ - [Usage examples](#usage-examples)
22
23
  - [API](#api)
23
24
  - [Authors](#authors)
24
25
  - [License](#license)
@@ -121,7 +122,7 @@ For Node.js REPL:
121
122
  const distance = await import("@thi.ng/distance");
122
123
  ```
123
124
 
124
- Package sizes (brotli'd, pre-treeshake): ESM: 1.11 KB
125
+ Package sizes (brotli'd, pre-treeshake): ESM: 1.15 KB
125
126
 
126
127
  ## Dependencies
127
128
 
@@ -132,6 +133,18 @@ Package sizes (brotli'd, pre-treeshake): ESM: 1.11 KB
132
133
  - [@thi.ng/math](https://github.com/thi-ng/umbrella/tree/develop/packages/math)
133
134
  - [@thi.ng/vectors](https://github.com/thi-ng/umbrella/tree/develop/packages/vectors)
134
135
 
136
+ ## Usage examples
137
+
138
+ Several demos in this repo's
139
+ [/examples](https://github.com/thi-ng/umbrella/tree/develop/examples)
140
+ directory are using this package.
141
+
142
+ A selection:
143
+
144
+ | Screenshot | Description | Live demo | Source |
145
+ |:---------------------------------------------------------------------------------------------------------------------|:------------------------------------------|:----------------------------------------------------|:---------------------------------------------------------------------------------|
146
+ | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/geom-knn-hash.jpg" width="240"/> | K-nearest neighbor search in an hash grid | [Demo](https://demo.thi.ng/umbrella/geom-knn-hash/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/geom-knn-hash) |
147
+
135
148
  ## API
136
149
 
137
150
  [Generated API docs](https://docs.thi.ng/umbrella/distance/)
package/knearest.d.ts CHANGED
@@ -19,14 +19,32 @@ import type { IDistance, INeighborhood, Neighbor } from "./api.js";
19
19
  */
20
20
  export declare class KNearest<D, T> implements INeighborhood<D, T>, IDeref<Neighbor<T>[]> {
21
21
  readonly dist: IDistance<D>;
22
- readonly target: D;
23
- readonly k: number;
22
+ target: D;
23
+ k: number;
24
+ radius: number;
24
25
  sorted: boolean;
25
- readonly radius: number;
26
26
  protected _currR: number;
27
27
  protected _heap: Heap<Neighbor<T>>;
28
28
  constructor(dist: IDistance<D>, target: D, k: number, radius?: number, sorted?: boolean);
29
29
  reset(): this;
30
+ /**
31
+ * Resets search/reference position.
32
+ *
33
+ * @param target
34
+ */
35
+ setTarget(target: D): void;
36
+ /**
37
+ * Resets max. search/query radius and clears current results.
38
+ *
39
+ * @param r
40
+ */
41
+ setRadius(r: number): void;
42
+ /**
43
+ * Resets `k-nearest` limit and clears current results.
44
+ *
45
+ * @param r
46
+ */
47
+ setK(k: number): void;
30
48
  /**
31
49
  * Returns an array of current nearest neighbor result tuples (each `[dist,
32
50
  * val]`). The array will contain at most `k` items and if the `sorted` ctor
package/knearest.js CHANGED
@@ -22,19 +22,46 @@ export class KNearest {
22
22
  this.dist = dist;
23
23
  this.target = target;
24
24
  this.k = k;
25
+ this.radius = radius;
25
26
  this.sorted = sorted;
26
27
  this._heap = new Heap(null, {
27
28
  compare: (a, b) => b[0] - a[0],
28
29
  });
29
- assert(k > 0, `invalid k (must be > 0)`);
30
30
  this.radius = clamp0(radius);
31
- this.reset();
31
+ this.setK(k);
32
32
  }
33
33
  reset() {
34
34
  this._currR = this.dist.to(this.radius);
35
35
  this._heap.clear();
36
36
  return this;
37
37
  }
38
+ /**
39
+ * Resets search/reference position.
40
+ *
41
+ * @param target
42
+ */
43
+ setTarget(target) {
44
+ this.target = target;
45
+ }
46
+ /**
47
+ * Resets max. search/query radius and clears current results.
48
+ *
49
+ * @param r
50
+ */
51
+ setRadius(r) {
52
+ this.radius = clamp0(r);
53
+ this.reset();
54
+ }
55
+ /**
56
+ * Resets `k-nearest` limit and clears current results.
57
+ *
58
+ * @param r
59
+ */
60
+ setK(k) {
61
+ assert(k > 0, `invalid k (must be > 0)`);
62
+ this.k = k;
63
+ this.reset();
64
+ }
38
65
  /**
39
66
  * Returns an array of current nearest neighbor result tuples (each `[dist,
40
67
  * val]`). The array will contain at most `k` items and if the `sorted` ctor
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/distance",
3
- "version": "2.1.39",
3
+ "version": "2.2.1",
4
4
  "description": "N-dimensional distance metrics & K-nearest neighborhoods for point queries",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -34,20 +34,20 @@
34
34
  "test": "testament test"
35
35
  },
36
36
  "dependencies": {
37
- "@thi.ng/api": "^8.6.3",
38
- "@thi.ng/checks": "^3.3.7",
39
- "@thi.ng/errors": "^2.2.8",
40
- "@thi.ng/heaps": "^2.1.22",
41
- "@thi.ng/math": "^5.4.0",
42
- "@thi.ng/vectors": "^7.5.31"
37
+ "@thi.ng/api": "^8.7.1",
38
+ "@thi.ng/checks": "^3.3.8",
39
+ "@thi.ng/errors": "^2.2.10",
40
+ "@thi.ng/heaps": "^2.1.24",
41
+ "@thi.ng/math": "^5.4.2",
42
+ "@thi.ng/vectors": "^7.6.1"
43
43
  },
44
44
  "devDependencies": {
45
- "@microsoft/api-extractor": "^7.33.7",
46
- "@thi.ng/testament": "^0.3.9",
47
- "rimraf": "^3.0.2",
45
+ "@microsoft/api-extractor": "^7.34.2",
46
+ "@thi.ng/testament": "^0.3.10",
47
+ "rimraf": "^4.1.2",
48
48
  "tools": "^0.0.1",
49
- "typedoc": "^0.23.22",
50
- "typescript": "^4.9.4"
49
+ "typedoc": "^0.23.24",
50
+ "typescript": "^4.9.5"
51
51
  },
52
52
  "keywords": [
53
53
  "distance",
@@ -109,5 +109,5 @@
109
109
  ],
110
110
  "year": 2021
111
111
  },
112
- "gitHead": "3f0b3e2a7c82aefc7e46fb4338369836b5e1b8cf\n"
112
+ "gitHead": "2b5a99a8af71670780875637299be9118b01084d\n"
113
113
  }