/** * Typed Geometry Functions * * Pure TypeScript implementations of geometric operations including * angles, products, areas, spatial queries, transforms, distances, * and intersections. Includes optional WASM acceleration for * Delaunay triangulation, Voronoi diagrams, and k-d tree operations. * * @packageDocumentation */ type f64 = number; type i32 = number; /** * Compute the angle (in radians) between two 2D vectors. * * @param v1 - First 2D vector * @param v2 - Second 2D vector * @returns Angle in radians [0, pi] */ export declare function angle2D(v1: number[], v2: number[]): f64; /** * Compute the angle (in radians) between two 3D vectors. * * @param v1 - First 3D vector * @param v2 - Second 3D vector * @returns Angle in radians [0, pi] */ export declare function angle3D(v1: number[], v2: number[]): f64; /** * Compute the cross product of two 3D vectors. * * @param a - First 3D vector * @param b - Second 3D vector * @returns Cross product vector */ export declare function cross3D(a: number[], b: number[]): number[]; /** * Compute the dot product of two 3D vectors. * * @param a - First 3D vector * @param b - Second 3D vector * @returns Dot product scalar */ export declare function dot3D(a: number[], b: number[]): f64; /** * Compute the area of a triangle given three 2D vertices using the shoelace formula. * * @param a - First vertex [x, y] * @param b - Second vertex [x, y] * @param c - Third vertex [x, y] * @returns Unsigned area of the triangle */ export declare function triangleArea(a: number[], b: number[], c: number[]): f64; /** * Compute the area of a simple polygon given its vertices (2D) using the shoelace formula. * Vertices should be ordered (clockwise or counter-clockwise). * * @param vertices - Array of [x, y] vertices * @returns Unsigned area of the polygon */ export declare function polygonArea(vertices: number[][]): f64; /** * Compute the convex hull of a set of 2D points using Andrew's monotone chain algorithm. * Returns vertices (as coordinates) in counter-clockwise order. * * Internal, WASM-sort-accelerated 2-D hull. The public, structured hull API * (indices + area/volume, 2-D and 3-D) is `convexHull` in * `../geometry/hull.ts`. * * @param points - Array of [x, y] points * @returns Convex hull vertices (coordinates) in CCW order */ export declare function convexHull2D(points: number[][]): number[][]; /** * Determine if a 2D point lies inside a polygon using the ray casting algorithm. * * @param point - The test point [x, y] * @param polygon - Array of polygon vertices [x, y] * @returns true if point is inside the polygon */ export declare function pointInPolygon(point: number[], polygon: number[][]): boolean; /** * Rotate a 2D vector by a given angle (radians). * * @param v - The 2D vector [x, y] * @param angle - Rotation angle in radians * @returns Rotated vector */ export declare function rotateVector2D(v: number[], angle: f64): number[]; /** * Rotate a 3D vector around an arbitrary axis by a given angle (Rodrigues' formula). * * @param v - The 3D vector * @param axis - The rotation axis (will be normalized) * @param angle - Rotation angle in radians * @returns Rotated vector */ export declare function rotateVector3D(v: number[], axis: number[], angle: f64): number[]; /** * Reflect a vector across a plane defined by its normal. * * @param v - The vector to reflect * @param normal - The normal of the reflection plane (will be normalized) * @returns Reflected vector */ export declare function reflectVector(v: number[], normal: number[]): number[]; /** * Project vector v onto vector onto. * * @param v - The vector to project * @param onto - The vector to project onto * @returns Projected vector */ export declare function projectVector(v: number[], onto: number[]): number[]; /** * Euclidean distance between two 2D points. */ export declare function distance2D(a: number[], b: number[]): f64; /** * Euclidean distance between two 3D points. */ export declare function distance3D(a: number[], b: number[]): f64; /** * Euclidean distance between two N-dimensional points. */ export declare function distanceND(a: number[], b: number[]): f64; /** * Shortest distance from a point to a line segment in 2D. * * @param point - The point [x, y] * @param lineStart - Start of the line segment [x, y] * @param lineEnd - End of the line segment [x, y] * @returns Distance from point to the line segment */ export declare function distancePointToLine2D(point: number[], lineStart: number[], lineEnd: number[]): f64; /** * Find the intersection point of two infinite 2D lines. * Each line is defined by a point and a direction vector. * * @param p1 - Point on line 1 * @param d1 - Direction of line 1 * @param p2 - Point on line 2 * @param d2 - Direction of line 2 * @returns Intersection point [x, y] or null if parallel */ export declare function intersectLines2D(p1: number[], d1: number[], p2: number[], d2: number[]): number[] | null; /** * Find the intersection point of two 2D line segments. * * @param a1 - Start of segment A * @param a2 - End of segment A * @param b1 - Start of segment B * @param b2 - End of segment B * @returns Intersection point [x, y] or null if segments do not intersect */ export declare function intersectSegments2D(a1: number[], a2: number[], b1: number[], b2: number[]): number[] | null; /** * Shape type for area calculation. */ export type Shape = { type: 'circle'; radius: f64; } | { type: 'triangle'; vertices: [number[], number[], number[]]; } | { type: 'polygon'; vertices: number[][]; } | { type: 'rectangle'; width: f64; height: f64; }; /** * Compute the area of a shape. * * @param shape - Shape descriptor * @returns Area * * @example * area({ type: 'circle', radius: 1 }) // => pi * area({ type: 'rectangle', width: 3, height: 4 }) // => 12 */ export declare function area(shape: Shape): f64; /** * Compute the centroid of a polygon. * * @param vertices - Array of [x, y] vertices in order * @returns Centroid [x, y] * * @example * centroid([[0,0], [4,0], [4,3], [0,3]]) // => [2, 1.5] */ export declare function centroid(vertices: number[][]): number[]; /** * Convert between coordinate systems. * * @param point - Input coordinates * @param from - Source system: 'cartesian' | 'polar' | 'spherical' | 'cylindrical' * @param to - Target system * @returns Converted coordinates */ export declare function coordinateTransform(point: number[], from: 'cartesian' | 'polar' | 'spherical' | 'cylindrical', to: 'cartesian' | 'polar' | 'spherical' | 'cylindrical'): number[]; /** * Perimeter of a polygon. * * @param vertices - Array of [x, y] vertices in order * @returns Perimeter length */ export declare function polygonPerimeter(vertices: number[][]): f64; /** * Manhattan (L1) distance between two points. * * @param a - First point * @param b - Second point * @returns L1 distance */ export declare function manhattanDistance(a: number[], b: number[]): f64; /** * Chebyshev (L-infinity) distance between two points. * * @param a - First point * @param b - Second point * @returns L-infinity distance */ export declare function chebyshevDistance(a: number[], b: number[]): f64; /** * Minkowski (Lp) distance between two points. * * @param a - First point * @param b - Second point * @param p - Distance order (p >= 1) * @returns Lp distance */ export declare function minkowskiDistance(a: number[], b: number[], p: f64): f64; /** * Delaunay triangulation using Bowyer-Watson algorithm. * * @param points - Array of [x, y] points * @returns Array of triangles, each an array of 3 point indices */ export declare function delaunayTriangulation(points: number[][]): number[][]; /** * Voronoi diagram from Delaunay triangulation (dual graph). * Returns Voronoi vertices and regions. * * @param points - Array of [x, y] points * @param bounds - Clipping bounds [minX, minY, maxX, maxY] * @returns `{ vertices: number[][], regions: number[][] }` */ export declare function voronoiDiagram(points: number[][], bounds: [f64, f64, f64, f64]): { vertices: number[][]; regions: number[][]; }; /** * K-d tree node. */ export interface KDTreeNode { point: number[]; index: i32; left: KDTreeNode | null; right: KDTreeNode | null; axis: i32; } /** * Build a k-d tree for spatial queries. * * @param points - Array of points (each same dimensionality) * @returns Root node of the k-d tree */ export declare function kdTree(points: number[][]): KDTreeNode | null; /** * Find the nearest neighbor in a k-d tree. * * @param root - K-d tree root * @param target - Query point * @returns `{ point, index, distance }` */ export declare function kdTreeNearest(root: KDTreeNode | null, target: number[]): { point: number[]; index: i32; distance: f64; } | null; /** * One-shot nearest-neighbor search: builds a k-d tree and queries it. * Uses WASM acceleration for large point sets. * * @param points - Array of points (each same dimensionality) * @param query - Query point * @returns `{ point, index, distance }` of the nearest neighbor, or null */ export declare function nearestNeighbor(points: number[][], query: number[]): { point: number[]; index: i32; distance: f64; } | null; /** * Represents a triangular face of a 3-D convex hull as three vertex indices * into the input point array. The vertices are in counter-clockwise order * when viewed from outside the hull. */ export type HullFace3D = [i32, i32, i32]; /** * Compute the 3-D convex hull of a set of points using QuickHull (incremental * variant — Barber, Dobkin, Huhdanpaa 1996). * * Point sets with ≥ 1024 points are dispatched to the WASM kernel; * smaller sets use a pure-TypeScript fallback with the same algorithm. * * @param points - Array of 3-D points, each `[x, y, z]`. * @returns Array of triangular faces. Each face is `[i, j, k]` where i/j/k * are indices into `points`, oriented CCW from outside. * @throws Error when the input is degenerate (fewer than 4 non-coplanar points). */ export declare function convexHull3D(points: number[][]): HullFace3D[]; /** * Compute the all-pairs Euclidean distance matrix for a set of points. * * Returns the symmetric `n x n` matrix whose entry `(i, j)` is the Euclidean * distance between point `i` and point `j`. Every output row is independent, so * large point sets are computed across the worker pool; small sets — or an * uninitialized pool — fall back to a sequential computation. * * @param points - Array of `n` points, each a coordinate array of equal length * @returns `n x n` distance matrix * * @example * await distanceMatrix([[0, 0], [3, 0], [0, 4]]) * // [[0, 3, 4], [3, 0, 5], [4, 5, 0]] */ export declare function distanceMatrix(points: number[][]): Promise; export {}; //# sourceMappingURL=geometry.d.ts.map