@thi.ng/distance 2.4.120 → 3.0.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 +15 -1
- package/README.md +2 -2
- package/api.d.ts +9 -7
- package/eucledian.d.ts +5 -11
- package/eucledian.js +6 -17
- package/haversine.d.ts +3 -3
- package/haversine.js +7 -3
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/jaccard.d.ts +10 -0
- package/jaccard.js +6 -0
- package/package.json +21 -8
- package/untransformed.d.ts +8 -0
- package/untransformed.js +14 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2025-
|
|
3
|
+
- **Last updated**: 2025-06-14T20:56:27Z
|
|
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,20 @@ 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
|
+
# [3.0.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/distance@3.0.0) (2025-06-14)
|
|
15
|
+
|
|
16
|
+
#### 🛑 Breaking changes
|
|
17
|
+
|
|
18
|
+
- rename class Eucledian => Untransformed ([5ace461](https://github.com/thi-ng/umbrella/commit/5ace461))
|
|
19
|
+
- BREAKING CHANGE: rename class `Eucledian` => `Untransformed`
|
|
20
|
+
- migrate to own src file
|
|
21
|
+
- update references
|
|
22
|
+
- update doc strings
|
|
23
|
+
|
|
24
|
+
#### 🚀 Features
|
|
25
|
+
|
|
26
|
+
- add JACCARD n-D distance metric ([ea48648](https://github.com/thi-ng/umbrella/commit/ea48648))
|
|
27
|
+
|
|
14
28
|
### [2.4.70](https://github.com/thi-ng/umbrella/tree/@thi.ng/distance@2.4.70) (2024-04-20)
|
|
15
29
|
|
|
16
30
|
#### ♻️ Refactoring
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://mastodon.thi.ng/@toxi)
|
|
8
8
|
|
|
9
9
|
> [!NOTE]
|
|
10
|
-
> This is one of
|
|
10
|
+
> This is one of 209 standalone projects, maintained as part
|
|
11
11
|
> of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
|
|
12
12
|
> and anti-framework.
|
|
13
13
|
>
|
|
@@ -140,7 +140,7 @@ For Node.js REPL:
|
|
|
140
140
|
const dist = await import("@thi.ng/distance");
|
|
141
141
|
```
|
|
142
142
|
|
|
143
|
-
Package sizes (brotli'd, pre-treeshake): ESM: 1.
|
|
143
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 1.41 KB
|
|
144
144
|
|
|
145
145
|
## Dependencies
|
|
146
146
|
|
package/api.d.ts
CHANGED
|
@@ -16,13 +16,14 @@ export interface IDistance<T> {
|
|
|
16
16
|
*/
|
|
17
17
|
readonly metric: Metric<T>;
|
|
18
18
|
/**
|
|
19
|
-
* Converts
|
|
19
|
+
* Converts "untransformed" raw distance `x` into the metric of this instance.
|
|
20
20
|
*
|
|
21
21
|
* @param x -
|
|
22
22
|
*/
|
|
23
23
|
to(x: number): number;
|
|
24
24
|
/**
|
|
25
|
-
* Converts `x` from the metric of this instance into an
|
|
25
|
+
* Converts `x` from the metric of this instance into an "untransformed" raw
|
|
26
|
+
* value.
|
|
26
27
|
*
|
|
27
28
|
* @param x -
|
|
28
29
|
*/
|
|
@@ -43,14 +44,15 @@ export interface INeighborhood<P, T> extends IReset {
|
|
|
43
44
|
readonly radius: number;
|
|
44
45
|
/**
|
|
45
46
|
* Returns true, if distance `d` is <= current radius of this neighborhood.
|
|
46
|
-
* If `
|
|
47
|
-
* into the metric used by this neighborhood using
|
|
48
|
-
* otherwise it is expected to be already in that
|
|
47
|
+
* If `untransformed` is true (default: true), then `d` will first be
|
|
48
|
+
* converted into the metric used by this neighborhood using
|
|
49
|
+
* {@link IDistance.to}, otherwise it is expected to be already in that
|
|
50
|
+
* metric's space.
|
|
49
51
|
*
|
|
50
52
|
* @param d -
|
|
51
|
-
* @param
|
|
53
|
+
* @param untransformed -
|
|
52
54
|
*/
|
|
53
|
-
includesDistance(d: number,
|
|
55
|
+
includesDistance(d: number, untransformed?: boolean): boolean;
|
|
54
56
|
/**
|
|
55
57
|
* Computes distance metric between `pos` and this neighborhood's target
|
|
56
58
|
* pos. Returns true if result is <= current radius.
|
package/eucledian.d.ts
CHANGED
|
@@ -1,25 +1,19 @@
|
|
|
1
1
|
import type { ReadonlyVec } from "@thi.ng/vectors";
|
|
2
|
-
import
|
|
3
|
-
export declare class Eucledian<T> implements IDistance<T> {
|
|
4
|
-
readonly metric: Metric<T>;
|
|
5
|
-
constructor(metric: Metric<T>);
|
|
6
|
-
to(x: number): number;
|
|
7
|
-
from(x: number): number;
|
|
8
|
-
}
|
|
2
|
+
import { Untransformed } from "./untransformed.js";
|
|
9
3
|
/**
|
|
10
4
|
* Eucledian distance metric for n-D vectors.
|
|
11
5
|
*/
|
|
12
|
-
export declare const EUCLEDIAN:
|
|
6
|
+
export declare const EUCLEDIAN: Untransformed<ReadonlyVec>;
|
|
13
7
|
/**
|
|
14
8
|
* Eucledian distance metric for numbers.
|
|
15
9
|
*/
|
|
16
|
-
export declare const EUCLEDIAN1:
|
|
10
|
+
export declare const EUCLEDIAN1: Untransformed<number>;
|
|
17
11
|
/**
|
|
18
12
|
* Eucledian distance metric for 2d vectors.
|
|
19
13
|
*/
|
|
20
|
-
export declare const EUCLEDIAN2:
|
|
14
|
+
export declare const EUCLEDIAN2: Untransformed<ReadonlyVec>;
|
|
21
15
|
/**
|
|
22
16
|
* Eucledian distance metric for 3d vectors.
|
|
23
17
|
*/
|
|
24
|
-
export declare const EUCLEDIAN3:
|
|
18
|
+
export declare const EUCLEDIAN3: Untransformed<ReadonlyVec>;
|
|
25
19
|
//# sourceMappingURL=eucledian.d.ts.map
|
package/eucledian.js
CHANGED
|
@@ -1,23 +1,12 @@
|
|
|
1
1
|
import { dist, dist2, dist3 } from "@thi.ng/vectors/dist";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return x;
|
|
8
|
-
}
|
|
9
|
-
from(x) {
|
|
10
|
-
return x;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
const EUCLEDIAN = new Eucledian(dist);
|
|
14
|
-
const EUCLEDIAN1 = new Eucledian((a, b) => Math.abs(a - b));
|
|
15
|
-
const EUCLEDIAN2 = new Eucledian(dist2);
|
|
16
|
-
const EUCLEDIAN3 = new Eucledian(dist3);
|
|
2
|
+
import { Untransformed } from "./untransformed.js";
|
|
3
|
+
const EUCLEDIAN = new Untransformed(dist);
|
|
4
|
+
const EUCLEDIAN1 = new Untransformed((a, b) => Math.abs(a - b));
|
|
5
|
+
const EUCLEDIAN2 = new Untransformed(dist2);
|
|
6
|
+
const EUCLEDIAN3 = new Untransformed(dist3);
|
|
17
7
|
export {
|
|
18
8
|
EUCLEDIAN,
|
|
19
9
|
EUCLEDIAN1,
|
|
20
10
|
EUCLEDIAN2,
|
|
21
|
-
EUCLEDIAN3
|
|
22
|
-
Eucledian
|
|
11
|
+
EUCLEDIAN3
|
|
23
12
|
};
|
package/haversine.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { ReadonlyVec } from "@thi.ng/vectors";
|
|
2
|
-
import {
|
|
2
|
+
import { Untransformed } from "./untransformed.js";
|
|
3
3
|
/**
|
|
4
4
|
* Distance metric for geo locations given as `[lat,lon]` vectors.
|
|
5
5
|
*/
|
|
6
|
-
export declare const HAVERSINE_LATLON:
|
|
6
|
+
export declare const HAVERSINE_LATLON: Untransformed<ReadonlyVec>;
|
|
7
7
|
/**
|
|
8
8
|
* Distance metric for geo locations given as `[lon,lat]` vectors.
|
|
9
9
|
*/
|
|
10
|
-
export declare const HAVERSINE_LONLAT:
|
|
10
|
+
export declare const HAVERSINE_LONLAT: Untransformed<ReadonlyVec>;
|
|
11
11
|
//# sourceMappingURL=haversine.d.ts.map
|
package/haversine.js
CHANGED
|
@@ -2,9 +2,13 @@ import {
|
|
|
2
2
|
distHaversineLatLon,
|
|
3
3
|
distHaversineLonLat
|
|
4
4
|
} from "@thi.ng/vectors/dist-haversine";
|
|
5
|
-
import {
|
|
6
|
-
const HAVERSINE_LATLON = new
|
|
7
|
-
|
|
5
|
+
import { Untransformed } from "./untransformed.js";
|
|
6
|
+
const HAVERSINE_LATLON = new Untransformed(
|
|
7
|
+
distHaversineLatLon
|
|
8
|
+
);
|
|
9
|
+
const HAVERSINE_LONLAT = new Untransformed(
|
|
10
|
+
distHaversineLonLat
|
|
11
|
+
);
|
|
8
12
|
export {
|
|
9
13
|
HAVERSINE_LATLON,
|
|
10
14
|
HAVERSINE_LONLAT
|
package/index.d.ts
CHANGED
|
@@ -2,9 +2,11 @@ export * from "./api.js";
|
|
|
2
2
|
export * from "./argmin.js";
|
|
3
3
|
export * from "./eucledian.js";
|
|
4
4
|
export * from "./haversine.js";
|
|
5
|
+
export * from "./jaccard.js";
|
|
5
6
|
export * from "./knearest.js";
|
|
6
7
|
export * from "./manhattan.js";
|
|
7
8
|
export * from "./nearest.js";
|
|
8
9
|
export * from "./radial.js";
|
|
9
10
|
export * from "./squared.js";
|
|
11
|
+
export * from "./untransformed.js";
|
|
10
12
|
//# sourceMappingURL=index.d.ts.map
|
package/index.js
CHANGED
|
@@ -2,8 +2,10 @@ export * from "./api.js";
|
|
|
2
2
|
export * from "./argmin.js";
|
|
3
3
|
export * from "./eucledian.js";
|
|
4
4
|
export * from "./haversine.js";
|
|
5
|
+
export * from "./jaccard.js";
|
|
5
6
|
export * from "./knearest.js";
|
|
6
7
|
export * from "./manhattan.js";
|
|
7
8
|
export * from "./nearest.js";
|
|
8
9
|
export * from "./radial.js";
|
|
9
10
|
export * from "./squared.js";
|
|
11
|
+
export * from "./untransformed.js";
|
package/jaccard.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ReadonlyVec } from "@thi.ng/vectors";
|
|
2
|
+
import { Untransformed } from "./untransformed.js";
|
|
3
|
+
/**
|
|
4
|
+
* Jaccard distance metric for n-D vectors. Returns the inverse Jaccard
|
|
5
|
+
* similarity, i.e. as distance metric rather than similarity. Returns a value
|
|
6
|
+
* in `[0,1]` interval: 0.0 if `a` and `b` are equal, or 1.0 if none of the
|
|
7
|
+
* components match.
|
|
8
|
+
*/
|
|
9
|
+
export declare const JACCARD: Untransformed<ReadonlyVec>;
|
|
10
|
+
//# sourceMappingURL=jaccard.d.ts.map
|
package/jaccard.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/distance",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "N-dimensional distance metrics & K-nearest neighborhoods for point queries",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -39,12 +39,12 @@
|
|
|
39
39
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@thi.ng/api": "^8.11.
|
|
43
|
-
"@thi.ng/checks": "^3.7.
|
|
44
|
-
"@thi.ng/errors": "^2.5.
|
|
45
|
-
"@thi.ng/heaps": "^2.1.
|
|
46
|
-
"@thi.ng/math": "^5.11.
|
|
47
|
-
"@thi.ng/vectors": "^8.
|
|
42
|
+
"@thi.ng/api": "^8.11.29",
|
|
43
|
+
"@thi.ng/checks": "^3.7.9",
|
|
44
|
+
"@thi.ng/errors": "^2.5.35",
|
|
45
|
+
"@thi.ng/heaps": "^2.1.101",
|
|
46
|
+
"@thi.ng/math": "^5.11.29",
|
|
47
|
+
"@thi.ng/vectors": "^8.3.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"esbuild": "^0.25.5",
|
|
@@ -52,8 +52,15 @@
|
|
|
52
52
|
"typescript": "^5.8.3"
|
|
53
53
|
},
|
|
54
54
|
"keywords": [
|
|
55
|
+
"2d",
|
|
56
|
+
"3d",
|
|
57
|
+
"4d",
|
|
55
58
|
"distance",
|
|
59
|
+
"eucledian",
|
|
60
|
+
"haversine",
|
|
61
|
+
"jaccard",
|
|
56
62
|
"k-nearest",
|
|
63
|
+
"manhattan",
|
|
57
64
|
"metric",
|
|
58
65
|
"nd",
|
|
59
66
|
"neighborhood",
|
|
@@ -90,6 +97,9 @@
|
|
|
90
97
|
"./haversine": {
|
|
91
98
|
"default": "./haversine.js"
|
|
92
99
|
},
|
|
100
|
+
"./jaccard": {
|
|
101
|
+
"default": "./jaccard.js"
|
|
102
|
+
},
|
|
93
103
|
"./knearest": {
|
|
94
104
|
"default": "./knearest.js"
|
|
95
105
|
},
|
|
@@ -104,6 +114,9 @@
|
|
|
104
114
|
},
|
|
105
115
|
"./squared": {
|
|
106
116
|
"default": "./squared.js"
|
|
117
|
+
},
|
|
118
|
+
"./untransformed": {
|
|
119
|
+
"default": "./untransformed.js"
|
|
107
120
|
}
|
|
108
121
|
},
|
|
109
122
|
"thi.ng": {
|
|
@@ -115,5 +128,5 @@
|
|
|
115
128
|
],
|
|
116
129
|
"year": 2021
|
|
117
130
|
},
|
|
118
|
-
"gitHead": "
|
|
131
|
+
"gitHead": "14e994e531d32053e948768998324d443436a542\n"
|
|
119
132
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IDistance, Metric } from "./api.js";
|
|
2
|
+
export declare class Untransformed<T> implements IDistance<T> {
|
|
3
|
+
readonly metric: Metric<T>;
|
|
4
|
+
constructor(metric: Metric<T>);
|
|
5
|
+
to(x: number): number;
|
|
6
|
+
from(x: number): number;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=untransformed.d.ts.map
|