UNPKG

@maplat/edgeruler

Version:

A small library for dual-constraining a Delaunator triangulation

154 lines (148 loc) 4.73 kB
declare class Base { /** * @member del The triangulation object from Delaunator */ del: DelaunatorLike; constructor(del: DelaunatorLike); } /** * A set of numbers, stored as bits in a typed array. The amount of numbers / * the maximum number that can be stored is limited by the length, which is * fixed at construction time. */ declare abstract class BitSet { protected readonly bs: Uint8Array | Uint16Array | Uint32Array; protected readonly W: 8 | 16 | 32; protected constructor(W: typeof BitSet.prototype.W, bs: typeof BitSet.prototype.bs); /** * Add a number to the set. * * @param idx The number to add. Must be 0 <= idx < len. * @return this. */ add(idx: number): this; /** * Delete a number from the set. * * @param idx The number to delete. Must be 0 <= idx < len. * @return this. */ delete(idx: number): this; /** * Add or delete a number in the set, depending on the second argument. * * @param idx The number to add or delete. Must be 0 <= idx < len. * @param val If true, add the number, otherwise delete. * @return val. */ set(idx: number, val: boolean): boolean; /** * Whether the number is in the set. * * @param idx The number to test. Must be 0 <= idx < len. * @return True if the number is in the set. */ has(idx: number): boolean; /** * Iterate over the numbers that are in the set. The callback is invoked * with each number that is set. It is allowed to change the BitSet during * iteration. If it deletes a number that has not been iterated over, that * number will not show up in a later call. If it adds a number during * iteration, that number may or may not show up in a later call. * * @param fn The function to call for each number. * @return this. */ forEach(fn: (idx: number) => void): this; } declare class Constrain extends Base { vertMap: Uint32Array; flips: BitSet; consd: BitSet; /** * Make a Constrain. * * @param del The triangulation output from Delaunator. * @param edges If provided, constrain these edges as by constrainAll. */ constructor(del: DelaunatorLike, edges?: readonly [number, number][]); /** * Constrain the triangulation such that there is an edge between p1 and p2. */ constrainOne(segP1: number, segP2: number): number; /** * Fix the Delaunay condition. */ delaunify(deep?: boolean): this; /** * Call constrainOne on each edge */ constrainAll(edges: readonly [number, number][]): this; /** * Whether an edge is constrained */ isConstrained(edg: number): boolean; /** * Find the edge that points from p1 -> p2. If there is only an edge from * p2 -> p1 (i.e. it is on the hull), returns the negative id of it. */ findEdge(p1: number, p2: number): number; /** * Mark an edge as constrained, i.e. should not be touched by `delaunify`. */ private protect; /** * Mark an edge as flipped unless constrained. */ private markFlip; /** * Flip the edge shared by two triangles. */ private flipDiagonal; /** * Whether point p1, p2, and p are collinear */ private isCollinear; /** * Whether px is in the circumcircle of the triangle formed by p1, p2, p3 */ private inCircle; /** * Whether the triangles sharing edg conform to the Delaunay condition */ private isDelaunay; /** * Update the vertex -> incoming edge map */ private updateVert; /** * Whether the segments between vertices intersect */ protected intersectSegments(p1: number, p2: number, p3: number, p4: number): boolean; static intersectSegments: typeof intersectSegments; } export { Constrain } export default Constrain; export declare interface DelaunatorLike { coords: { readonly length: number; readonly [n: number]: number; }; triangles: { readonly length: number; [n: number]: number; }; halfedges: { readonly length: number; [n: number]: number; }; hull: { readonly length: number; readonly [n: number]: number; }; } /** * Compute if two line segments [p1, p2] and [p3, p4] intersect */ declare function intersectSegments(p1x: number, p1y: number, p2x: number, p2y: number, p3x: number, p3y: number, p4x: number, p4y: number): boolean; export { }