Skip to content

Commit

Permalink
refactor(distance): use clamp0()
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jan 24, 2021
1 parent d18c869 commit 8987946
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/distance/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"dependencies": {
"@thi.ng/api": "^6.13.6",
"@thi.ng/heaps": "^1.2.31",
"@thi.ng/math": "^3.1.0",
"@thi.ng/vectors": "^4.9.1"
},
"files": [
Expand Down
3 changes: 2 additions & 1 deletion packages/distance/src/knearest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { IDeref } from "@thi.ng/api";
import { Heap } from "@thi.ng/heaps";
import { clamp0 } from "@thi.ng/math";
import type { ReadonlyVec } from "@thi.ng/vectors";
import type { IDistance, INeighborhood, Neighbor } from "./api";
import { DIST_SQ, DIST_SQ1, DIST_SQ2, DIST_SQ3 } from "./squared";
Expand Down Expand Up @@ -31,7 +32,7 @@ export class KNearest<D, T>
radius = Infinity,
public sorted = false
) {
this.radius = Math.max(0, radius);
this.radius = clamp0(radius);
this.reset();
}

Expand Down
5 changes: 3 additions & 2 deletions packages/distance/src/nearest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { IDeref } from "@thi.ng/api";
import { clamp0 } from "@thi.ng/math";
import type { ReadonlyVec } from "@thi.ng/vectors";
import type { IDistance, Neighbor, INeighborhood } from "./api";
import type { IDistance, INeighborhood, Neighbor } from "./api";
import { DIST_SQ, DIST_SQ1, DIST_SQ2, DIST_SQ3 } from "./squared";

/**
Expand All @@ -19,7 +20,7 @@ export class Nearest<D, T>
public readonly target: D,
radius = Infinity
) {
this.radius = Math.max(0, radius);
this.radius = clamp0(radius);
this.reset();
}

Expand Down

0 comments on commit 8987946

Please sign in to comment.