API reference
API reference
Select your platform
No SDKs available
No versions available

Triangulator Object

Polygon triangulation with hole support using the earcut algorithm.
Clean Kotlin implementation of the Mapbox earcut algorithm with extended robustness for bad input data (collinear vertices, self-touching contours, touching holes, degenerate geometry from font curve approximation).
Features:
  • Circular doubly-linked list with z-order spatial hashing for efficient point-in-triangle queries
  • David Eberly's algorithm for finding bridge vertices between holes and outer polygon
  • Multi-pass recovery: filter collinear → cure local intersections → split polygon
  • Automatic winding correction (outer → CCW, holes → CW in output)
Reference: https://github.com/mapbox/earcut

Signature

object Triangulator

Methods

signedArea ( points )
Computes the signed area of a polygon using the shoelace formula. Positive = CCW.
Signature
fun signedArea(points: List<Point2D>): Float
Parameters
points: List
Returns
Float
triangulate ( outer , holes )
Triangulates a polygon that may contain holes.
The outer boundary and holes are pre-classified by the caller (typically using the even-odd fill rule). Winding is auto-corrected internally.
Signature
fun triangulate(outer: List<Point2D>, holes: List<List<Point2D>> = emptyList()): TriangulationResult
Parameters
outer: List  Vertices of the outer boundary
holes: List  List of hole boundaries (inner contours)
Returns
TriangulationResult  Merged vertex list and triangle index triplets. Indices reference positions in the merged list (outer vertices first, then hole vertices in order).