@thi.ng/geom-closest-point
Version:
2D / 3D closest point / proximity helpers
98 lines • 3.79 kB
TypeScript
import type { FnU3, Maybe } from "@thi.ng/api";
import type { ReadonlyVec, Vec } from "@thi.ng/vectors";
/**
* Computes the parametric distance `t` of point `p` projected onto line `a` ->
* `b`, relative to `a`. I.e. the projection of `p` can then be computed like
* so:
*
* @example
* ```ts
* import { closestT } from "@thi.ng/geom-closest-point";
* import { mixN } from "@thi.ng/vectors";
*
* mixN([], a, b, closestT(p, a, b))
* ```
*
* If the return value is outside the closed `[0,1]` interval, the
* projected point lies outside the line segment. Returns `undefined` if
* `a` and `b` are coincident.
*
* - {@link closestPointLine}
* - {@link closestPointSegment}
*
* @param p - query point
* @param a - line point A
* @param b - line point B
*/
export declare const closestT: FnU3<ReadonlyVec, Maybe<number>>;
/**
* Returns closest point to `p` on infinite line defined by points `a`
* and `b`. Use {@link closestPointSegment} to only consider the actual line
* segment between these two points.
*
* {@link closestPointSegment}
*
* @param p - query point
* @param a - line point A
* @param b - line point B
*/
export declare const closestPointLine: FnU3<ReadonlyVec, Vec>;
/**
* Returns distance from `p` to closest point to infinite line `a` ->
* `b`. Use {@link distToSegment} to only consider the actual line segment
* between these two points.
*
* {@link distToSegment}
*
* @param p - query point
* @param a - line point A
* @param b - line point B
*/
export declare const distToLine: FnU3<ReadonlyVec, number>;
/**
* Returns closest point to `p` on line segment `a` -> `b`. By default, if the
* result point lies outside the segment, returns a copy of the closest end
* point. The result is written to the optional `out` vector (or if omitted, a
* new one is created).
*
* If `insideOnly` is true, only returns the closest point iff it actually is
* inside the segment. The behavior of this configurable via the optional `eps`
* arg and by default includes both end points. This function uses
* {@link closestT} to compute the parametric position of the result point and
* determine if it lies within the line segment. If `eps > 0`, the end points
* `a` and `b` will be excluded from the match, effectively shortening the valid
* line segment from both ends, i.e. the valid interval of the parametric
* position will be `[eps,1-eps]`. If the result lies outside this interval, the
* function returns `undefined`. Likewise, if `a` and `b` are coincident.
*
* @param p - query point
* @param a - line point A
* @param b - line point B
* @param out - result
* @param eps - epsilon value
*/
export declare const closestPointSegment: (p: ReadonlyVec, a: ReadonlyVec, b: ReadonlyVec, out?: Vec, insideOnly?: boolean, eps?: number) => Vec<number> | undefined;
/**
* Returns distance from `p` to closest point on line segment `a` ->
* `b`.
*
* @param p - query point
* @param a - line point A
* @param b - line point B
*/
export declare const distToSegment: FnU3<ReadonlyVec, number>;
export declare const closestPointPolyline: (p: ReadonlyVec, pts: ReadonlyArray<Vec>, closed?: boolean, out?: Vec) => Vec<number> | undefined;
/**
* Returns the index of the start point containing the segment in the
* polyline array `points` farthest away from `p` with regards to the
* line segment `a` to `b`. `points` is only checked between indices
* `from` and `to` (not including the latter).
*
* @param a - line point A
* @param b - line point B
* @param points - points
* @param from - start search index
* @param to - end search index
*/
export declare const farthestPointSegment: (a: ReadonlyVec, b: ReadonlyVec, points: ReadonlyVec[], from?: number, to?: number) => number[];
//# sourceMappingURL=line.d.ts.map