@technobuddha/library
Version:
A large library of useful functions
24 lines (23 loc) • 950 B
TypeScript
import { type Cartesian, type Polygon } from './@types/geometry.ts';
/**
* Computes the convex hull of a set of 2D points using the Monotone Chain algorithm.
* @see {@link https://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain#JavaScript| Monotone Chain}
* @param vertices - An array of points.
* @returns The convex hull as an array of points in counterclockwise order, or `undefined` if there are fewer than 3 vertices.
* @example
* ```typescript
* convexHull([
* { x: 0, y: 0 },
* { x: 1, y: 1 },
* { x: 2, y: 0 },
* { x: 1, y: -1 }
* ]);
* // hull is now the convex hull of the points
* ```
* @remarks
* - The returned array does not repeat the starting point at the end.
* - Points on the edge of the hull may be included or excluded depending on their order.
* @group Geometry
* @category Polygon
*/
export declare function convexHull(vertices: Cartesian[]): Polygon | undefined;