animouse
Version:
lightweight animation state machine for three js
88 lines (87 loc) • 3.84 kB
TypeScript
import type { TriangleCache, Vector2Like } from "./math";
/**
* A triangle in 2D space with precomputed geometric properties.
*
* @template T - Type of vertices that must be Vector2Like objects
*/
export interface Triangle<T extends Vector2Like> extends TriangleCache {
/** First vertex of the triangle */
readonly a: T;
/** Second vertex of the triangle */
readonly b: T;
/** Third vertex of the triangle */
readonly c: T;
}
/**
* Result of Delaunay triangulation.
*
* @template T - Type of vertices that must be Vector2Like objects
*/
export interface TriangulationResult<T extends Vector2Like> {
/** Array of triangles forming the Delaunay triangulation */
readonly triangles: Triangle<T>[];
/** Map from boundary vertices to their adjacent boundary vertices [prev, next] */
readonly boundaryEdgeMap: Map<T, [T, T]>;
}
/**
* Implements Bowyer-Watson algorithm for Delaunay triangulation.
*/
export declare class DelaunayTriangulator {
/**
* Performs Delaunay triangulation on a set of 2D points.
*
* @template T - Type of vertices that must be Vector2Like objects
* @param points - Array of points to triangulate (minimum 3 points required)
* @returns Triangulation result containing triangles and boundary edge information
* @throws {Error} When fewer than 3 points provided, points contain invalid coordinates,
* duplicate points exist, or all points are collinear
*/
static triangulate<T extends Vector2Like>(points: T[]): TriangulationResult<T>;
/**
* Identifies and removes triangles whose circumcircles contain the given point.
* Modifies the input triangles array in-place for efficiency.
*
* @template T - Type of vertices that must be Vector2Like objects
* @param triangles - Array of triangles to filter (modified in-place)
* @param point - Point to test against triangle circumcircles
* @returns Array of triangles that contain the point in their circumcircles
*/
private static filterBadTriangles;
/**
* Constructs the polygon boundary formed by removing bad triangles.
* Finds edges that belong to only one triangle.
*
* @template T - Type of vertices that must be Vector2Like objects
* @param triangles - Array of triangles forming the cavity
* @returns Array of edges [vertex1, vertex2] that form the polygon boundary
*/
private static buildPolygon;
/**
* Removes triangles containing super triangle vertices and builds boundary edge map.
* Filters out triangles that include any vertex from the initial super triangle.
*
* @template T - Type of vertices that must be Vector2Like objects
* @param triangles - Array of triangles to filter (modified in-place)
* @param superTriangle - The super triangle used to initialize triangulation
* @returns Map from boundary vertices to arrays of their adjacent boundary vertices
*/
private static filterSuperTriangleVertices;
/**
* Constructs a large triangle that encompasses all input points.
* Vertices are positioned outside the bounding box of input points.
*
* @template T - Type of vertices that must be Vector2Like objects
* @param points - Array of input points to encompass
* @returns Triangle that contains all input points with precomputed properties
*/
private static buildSuperTriangle;
/**
* Tests whether a vertex belongs to a specific triangle.
*
* @template T - Type of vertices that must be Vector2Like objects
* @param vertex - Vertex to test for membership
* @param triangle - Triangle to test against
* @returns True if the vertex is one of the triangle's vertices, false otherwise
*/
private static isVertexFromTriangle;
}