@thi.ng/geom-poly-utils
Version:
2D polygon/polyline analysis & processing utilities
60 lines • 2.03 kB
TypeScript
import { type ReadonlyVec, type Vec, type VecPair } from "@thi.ng/vectors/api";
/**
* Computes the nD bounds of given vectors. `vmin` should be initialized
* to `+∞` and `vmax` to `-∞` (e.g. use copies of `MIN*` / `MAX*`
* constants defined in thi.ng/vectors).
*
* @remarks
* Also see {@link bounds2}, {@link bounds3}.
*
* @example
* ```ts tangle:../export/bounds.ts
* import { bounds } from "@thi.ng/geom-poly-utils";
* import { MAX2, MIN2 } from "@thi.ng/vectors";
*
* const points = [[-1,-2], [5,-3], [0,4]];
*
* console.log(
* bounds(points, [...MAX2], [...MIN2])
* );
* // [[-1, -3], [5, 4]]
* ```
*
* Returns 2-tuple of modified `[vmin, vmax]`.
*
* @param points - points
* @param vmin - min result (pre-initialized to `+∞`)
* @param vmax - max result (pre-initialized to `-∞`)
*/
export declare const bounds: (points: ReadonlyArray<Vec>, vmin: Vec, vmax: Vec, start?: number, end?: number) => VecPair;
export declare const bounds2: (points: ReadonlyArray<Vec>, start?: number, end?: number) => VecPair;
export declare const bounds3: (points: ReadonlyArray<Vec>, start?: number, end?: number) => VecPair;
/**
* Calculates a near-optimal bounding circle for a set of points in 2D. Returns
* tuple of `[centroid, radius]`.
*
* @remarks
* Based on "An Efficient Bounding Sphere" by Jack Ritter "Graphics Gems",
* Academic Press, 1990
*
* Ported from:
* https://github.com/erich666/GraphicsGems/blob/master/gems/BoundSphere.c
*
* @param pts
*/
export declare const boundingCircle: (pts: ReadonlyVec[]) => [Vec, number];
/**
* Calculates a near-optimal bounding circle for a set of points in 3D. Returns
* tuple of `[centroid, radius]`.
*
* @remarks
* Based on "An Efficient Bounding Sphere" by Jack Ritter "Graphics Gems",
* Academic Press, 1990
*
* Ported from:
* https://github.com/erich666/GraphicsGems/blob/master/gems/BoundSphere.c
*
* @param pts
*/
export declare const boundingSphere: (pts: ReadonlyVec[]) => [Vec, number];
//# sourceMappingURL=bounds.d.ts.map