Skip to content

Commit

Permalink
feat(geom): add proximity()
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed May 3, 2024
1 parent 35ce854 commit 5d5951c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/geom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export * from "./plane.js";
export * from "./points.js";
export * from "./polygon.js";
export * from "./polyline.js";
export * from "./proximity.js";
export * from "./quad.js";
export * from "./quadratic.js";
export * from "./ray.js";
Expand Down
16 changes: 16 additions & 0 deletions packages/geom/src/proximity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { IShape } from "@thi.ng/geom-api";
import type { ReadonlyVec } from "@thi.ng/vectors";
import { dist } from "@thi.ng/vectors/dist";
import { closestPoint } from "./closest-point.js";

/**
* Computes {@link closestPoint} on `shape` to `p`, and if successful, returns
* eucledian distance between that point and `p`.
*
* @param shape
* @param p
*/
export const proximity = (shape: IShape, p: ReadonlyVec) => {
const q = closestPoint(shape, p);
return q ? dist(p, q) : undefined;
};

0 comments on commit 5d5951c

Please sign in to comment.