@thi.ng/geom-voronoi
Version:
Fast, incremental 2D Delaunay & Voronoi mesh implementation
73 lines • 2.98 kB
TypeScript
import type { Pair } from "@thi.ng/api";
import { type BitField } from "@thi.ng/bitfield/bitfield";
import { type Edge } from "@thi.ng/quad-edge";
import { type ReadonlyVec, type Vec, type VecPair } from "@thi.ng/vectors/api";
export type Visitor<T> = (e: Edge<Vertex<T>>, vistedEdges: BitField, visitedVerts: BitField) => void;
export interface Vertex<T> {
pos: ReadonlyVec;
id: number;
val?: T;
}
export declare class DVMesh<T> {
first: Edge<Vertex<T>>;
nextEID: number;
nextVID: number;
constructor(pts?: ReadonlyVec[] | Pair<ReadonlyVec, T>[], size?: number);
/**
* Adds a single new point `p` w/ optional value `val` to the mesh, unless
* there already is another point existing within radius `eps`. If `update`
* is true (default), the mesh dual will be automatically updated using
* {@link DVMesh.computeDual}.
*
* @remarks
* If adding multiple points, ensure `computeDual` will only be called
* for/after the last point insertion to avoid computational overhead.
*
* @param p -
* @param val -
* @param eps -
* @param update -
*/
add(p: ReadonlyVec, val?: T, eps?: number, update?: boolean): boolean;
addKeys(pts: Iterable<ReadonlyVec>, eps?: number): void;
addAll(pairs: Iterable<Pair<ReadonlyVec, T>>, eps?: number): void;
/**
* Returns tuple of the edge related to `p` and a boolean to indicate if
* `p` already exists in this triangulation (true if already present).
*
* @param p - query point
*/
locate(p: ReadonlyVec, eps?: number): [Edge<Vertex<T>>, boolean];
/**
* Syncronize / update / add dual faces (i.e. Voronoi) for current
* primary mesh (i.e. Delaunay).
*/
computeDual(): void;
delaunay(bounds?: ReadonlyVec[]): Vec<number>[][];
/**
* Advanced use only. Returns Delaunay triangles as arrays of raw
* [thi.ng/quad-edge
* Edges](https://docs.thi.ng/umbrella/quad-edge/classes/Edge.html).
*
* @remarks
* The actual vertex position associated with each edge can be obtained via
* `e.origin.pos`. Each edge (and each associated {@link Vertex}) also has a
* unique ID, accessible via `e.id` and `e.origin.id`.
*/
delaunayQE(): Edge<Vertex<T>>[][];
voronoi(bounds?: ReadonlyVec[]): Vec<number>[][];
/**
* Advanced use only. Returns Voronoi cells as arrays of raw
* [thi.ng/quad-edge
* Edges](https://docs.thi.ng/umbrella/quad-edge/classes/Edge.html).
*
* @remarks
* The actual vertex position associated with each edge can be obtained via
* `e.origin.pos`. Each edge (and each associated {@link Vertex}) also has a
* unique ID, accessible via `e.id` and `e.origin.id`.
*/
voronoiQE(): Edge<Vertex<T>>[][];
edges(voronoi?: boolean, boundsMinMax?: VecPair): VecPair[];
traverse(proc: Visitor<T>, edges?: boolean, e?: Edge<Vertex<T>>): void;
}
//# sourceMappingURL=index.d.ts.map