@thi.ng/distance 2.1.38 → 2.2.0
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 +7 -1
- package/README.md +1 -1
- package/knearest.d.ts +21 -3
- package/knearest.js +29 -2
- package/package.json +13 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**:
|
|
3
|
+
- **Last updated**: 2023-02-05T14:42:21Z
|
|
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
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
|
-
|
|
23
|
-
|
|
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.
|
|
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.
|
|
3
|
+
"version": "2.2.0",
|
|
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.
|
|
38
|
-
"@thi.ng/checks": "^3.3.
|
|
39
|
-
"@thi.ng/errors": "^2.2.
|
|
40
|
-
"@thi.ng/heaps": "^2.1.
|
|
41
|
-
"@thi.ng/math": "^5.
|
|
42
|
-
"@thi.ng/vectors": "^7.
|
|
37
|
+
"@thi.ng/api": "^8.7.0",
|
|
38
|
+
"@thi.ng/checks": "^3.3.8",
|
|
39
|
+
"@thi.ng/errors": "^2.2.9",
|
|
40
|
+
"@thi.ng/heaps": "^2.1.23",
|
|
41
|
+
"@thi.ng/math": "^5.4.1",
|
|
42
|
+
"@thi.ng/vectors": "^7.6.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@microsoft/api-extractor": "^7.
|
|
46
|
-
"@thi.ng/testament": "^0.3.
|
|
47
|
-
"rimraf": "^
|
|
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.
|
|
50
|
-
"typescript": "^4.9.
|
|
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": "
|
|
112
|
+
"gitHead": "50ba9c87676fac60c46d2bc0e4d2c7711a374a68\n"
|
|
113
113
|
}
|