@thi.ng/geom-tessellate
Version:
2D/3D convex polygon tessellators
74 lines • 2.81 kB
TypeScript
import type { ReadonlyVec } from "@thi.ng/vectors";
import type { Tessellator } from "./api.js";
/**
* Higher-order tessellator, implementing an ear slicing triangulation
* algorithm, optionally optimized by Morton/Z-curve hashing/sorting and able to
* handle complex polygons with holes, twists, degeneracies and
* self-intersections.
*
* @remarks
* This is an adapted version of https://github.com/mapbox/earcut with the
* following changes to the original implementation:
*
* - Input points given as array of points (not flattened, only 2D supported)
* - Appends results to given tessellation instance as per contract of all
* tessellators in this package
* - Configurable Z-curve hashing threshold (default: 80)
* - If Z-curve hashing is used, points are pre-scaled once internally for
* various simplifications and to avoid passing extraneous args around
* - Use unsigned 16 bits (per coord) hashing (instead of 15 bits)
* - Re-use existing thi.ng/umbrella fns for some processing steps
* - Add small tolerance for colinear check
* - Rename `Node` => `Vertex`
* - Minor other refactoring (use of destructuring, add types, renames etc.)
*
* Original implementation Copyright (c) 2016, Mapbox, ISC License. Original
* author: Volodymyr Agafonkin
*
* References:
*
* - https://www.cosy.sbg.ac.at/~held/projects/triang/triang.html
* - https://www.geometrictools.com/Documentation/TriangulationByEarClipping.pdf
* - https://docs.thi.ng/umbrella/morton/
*
* @param holeIDs
* @param hashThreshold
*/
export declare const earCutComplex: (holeIDs?: number[], hashThreshold?: number) => Tessellator;
/**
* Takes an array of `boundary` points and another array of `holes` containing
* point arrays of individual holes. Concatenates all points (both boundary &
* holes) and returns a tuple of `[points, holeIDs]`, suitable for
* {@link earCutComplex}.
*
* @example
* ```ts tangle:../export/earcut-complex.ts
* import {
* earCutComplex, earCutComplexPrepare, tessellate
* } from "@thi.ng/geom-tessellate";
*
* const boundary = [[0,0], [100,0], [100,100], [0,100]];
* const hole = [[20,20],[50,80],[80,20]];
*
* const [points, holeIDs] = earCutComplexPrepare(boundary, [hole]);
*
* const tess = tessellate(points, earCutComplex(holeIDs));
*
* console.log(tess);
* // {
* // points: [
* // [ 0, 0 ], [ 100, 0 ], [ 100, 100 ], [ 0, 100 ],
* // [ 20, 20 ], [ 50, 80 ], [ 80, 20 ]
* // ],
* // indices: [
* // [ 0, 4, 5 ], [ 6, 4, 0 ], [ 3, 0, 5 ], [ 6, 0, 1 ],
* // [ 2, 3, 5 ], [ 5, 6, 1 ], [ 1, 2, 5 ]
* // ],
* // }
* ```
*
* @param boundary
* @param holes
*/
export declare const earCutComplexPrepare: (boundary: ReadonlyVec[], holes: ReadonlyVec[][]) => [ReadonlyVec[], number[]];
//# sourceMappingURL=earcut-complex.d.ts.map