/** A place, `[x, y]`. */ export type Pt = readonly [number, number]; /** * The convex hull of some points: its corners in order, counter-clockwise with y up (clockwise on a page, where y is down), starting at the least x. A point on an edge of the hull is * not a corner. The same point twice is one. With no points the hull is empty, with one it is that point, and with two or with all on a line it is the two ends. * @example * ```ts * import { convexHull } from "@johnmorrisdotca/kyogijo-stadiums/layers"; * console.log(convexHull([[0, 0], [4, 0], [2, 0], [4, 3], [1, 1], [0, 3]])); * // [ [ 0, 0 ], [ 4, 0 ], [ 4, 3 ], [ 0, 3 ] ] * ``` */ export declare function convexHull(points: readonly Pt[]): Pt[]; /** The area of a polygon given by its corners (any orientation); 0 for fewer than three. */ export declare function polygonArea(polygon: readonly Pt[]): number; /** The centre of mass of a polygon's area, or the mean of its corners when it has none (a point, a line). `undefined` for no corners. */ export declare function polygonCentroid(polygon: readonly Pt[]): Pt | undefined; /** A triangulation: the distinct points, the triangles as triples of indices into them (counter-clockwise with y up), and where each input point went. */ export interface Triangulation { /** The distinct points, in the order they were first given. */ points: Pt[]; /** Three indices into `points` for each triangle, flat: `triangles[3 * k]`, `[3 * k + 1]`, `[3 * k + 2]`. Empty for fewer than three points and for points all on a line. */ triangles: number[]; /** For each input point, the index in `points` of the point it is (a repeated point is the first one). */ of: number[]; } /** * The Delaunay triangulation of some points: triangles whose circumcircle holds no other point, which cover the points' convex hull. Bowyer and * Watson's method: each point is added by removing the triangles whose circumcircle holds it and joining it to the edge of the hole. The hull is * kept by "ghost" triangles (an edge and a point at infinity) in place of a big triangle round everything, so that a point on or beyond the hull * is handled exactly and no sliver of the hull is lost. Points are added from the least x, so the answer does not depend on the order given * (up to which of four points on one circle are joined). Points that are not finite numbers are not allowed; a repeated point is one point. * @example * ```ts * import { delaunay } from "@johnmorrisdotca/kyogijo-stadiums/layers"; * const t = delaunay([[0, 0], [10, 0], [5, 8], [5, 3]]); * console.log(t.points.length, t.triangles.length / 3); * // 4 3 * ``` */ export declare function delaunay(input: readonly Pt[]): Triangulation; /** For each distinct point of a triangulation, the points it shares a triangle edge with, in increasing order. */ export declare function neighbours(t: Triangulation): number[][]; /** The edges of a triangulation, each once, as pairs of indices into its points with the smaller first, in order. */ export declare function triangulationEdges(t: Triangulation): [number, number][]; /** A convex polygon cut to the side of the line that is nearer `a` than `b` (Sutherland and Hodgman's clip against one half plane). */ export declare function clipNearer(polygon: readonly Pt[], a: Pt, b: Pt): Pt[]; /** * The Voronoi cells of some points inside a box: for each input point, the corners of the part of the box nearer to it than to any other point, * in order. The cells tile the box. A point given twice has the cell on its first appearance and an empty one on its second. With one point the * cell is the box; with points all on a line the cells are strips. The neighbours that cut a cell are the triangulation's, so a cell is made * from a handful of cuts and not from every other point. * @example * ```ts * import { voronoiCells } from "@johnmorrisdotca/kyogijo-stadiums/layers"; * const cells = voronoiCells([[2, 5], [8, 5]], { x: 0, y: 0, w: 10, h: 10 }); * console.log(cells[0].length, cells[1].map((p) => p.join(",")).join(" ")); * // 4 5,0 10,0 10,10 5,10 * ``` */ export declare function voronoiCells(points: readonly Pt[], box: { x: number; y: number; w: number; h: number; }): Pt[][];