polygon2.triangulate
A constrained Delaunay triangulation of the ring under a fill rule, optionally refined to a minimum angle.
Usage
polygon.triangulate(options?: { minAngleDeg?: number; maxSteiner?: number; fillRule?: FillRule }): Result<Triangulation2>Parameters
options.minAngleDegnumberRefine with Steiner points until no triangle angle is below this, in degrees; 0 is a plain constrained Delaunay triangulation. Default
0. Range [0, 34].options.maxSteinernumberBudget of added points for ring crossings and refinement; a non-negative integer (kernel2d clamps it to 2^20). Default
10000. In count.options.fillRuleFillRuleWhich points a ring encloses: winding number ≠ 0, or an odd number of crossings. Default
'nonZero'. One ofnonZero,evenOdd.
Returns
Ok with the triangulation: the ring’s corners, then any Steiner points, and counter-clockwise triangles. It has no triangles when the ring encloses nothing under the fill rule (collinear, or doubly wound under evenOdd).
Errors
Guarantees
- with minAngleDeg θ, Triangulation2.minAngleDeg(t) ≥ θ, except triangles at ring corners, crossings or T-junctions sharper than 60°, at ring pieces too short to split in f64, and a few unreachable circumcentres
- the first points are the input corners, unchanged and in order; t.steinerCount === t.points.length − the number of input corners
- every triangle is counter-clockwise, and their total area equals the enclosed area (Triangulation2.toMesh(t).value.area())
- The same result on every machine.
Use instead
region2.triangulate: the shape has holes
Example
const r = Polygon2.rectangle(2, 2).value.triangulate() // → 2 triangles, no Steiner points, once loadGeometryKernel() has run