@thi.ng/geom-clip-line
Version:
2D line clipping (Liang-Barsky)
36 lines • 1.41 kB
TypeScript
import type { FnU8, Maybe, Tuple } from "@thi.ng/api";
import type { ReadonlyVec, Vec } from "@thi.ng/vectors";
/**
* Performs Liang-Barsky clipping of the line segment with endpoints `a`, `b`
* against the clipping rect defined by `min` and `max`. The optional `ca` and
* `cb` vectors can be given to store the result (clipped points). If omitted
* creates new vectors. Returns a tuple of `[ca, cb, a, b]`, where the latter
* two values represent the normalized distances of the clipped points relative
* to original given line segment. Returns `undefined` iff the line lies
* completely outside the rect.
*
* - https://en.wikipedia.org/wiki/Liang%E2%80%93Barsky_algorithm
* - https://github.com/thi-ng/c-thing/blob/develop/src/geom/clip/liangbarsky.c
*
* @param a - line endpoint
* @param b - line endpoint
* @param min - bbox min
* @param max - bbox max
* @param ca - result A
* @param cb - result B
*/
export declare const liangBarsky2: (a: ReadonlyVec, b: ReadonlyVec, min: ReadonlyVec, max: ReadonlyVec, ca?: Vec, cb?: Vec) => Maybe<[Vec, Vec, number, number]>;
/**
* Same as {@link liangBarsky2} but for non-vector arguments.
*
* @param ax -
* @param ay -
* @param bx -
* @param by -
* @param minx -
* @param miny -
* @param maxx -
* @param maxy -
*/
export declare const liangBarsky2Raw: FnU8<number, Maybe<Tuple<number, 6>>>;
//# sourceMappingURL=liang-barsky.d.ts.map