polygon2.repaired
The region a self-intersecting or mis-wound ring encloses under a fill rule, as clean polygons with holes.
Usage
polygon.repaired(fillRule?: FillRule): Result<Region2>Parameters
fillRuleFillRuleWhich points a ring encloses: winding number ≠ 0, or an odd number of crossings. Default
'evenOdd'. One ofnonZero,evenOdd.
Returns
Ok with the enclosed region: counter-clockwise outlines, clockwise holes; Region2.empty when the ring encloses nothing (a collinear ring, or a doubly wound ring under evenOdd).
Errors
Guarantees
- a simple ring repairs to a region of the same area (Region2.area)
- a bow-tie repairs into two triangles (parts.length === 2)
- outlines wind counter-clockwise and holes clockwise (part.outer.isCounterClockwise(), !hole.isCounterClockwise())
- The same result on every machine.
Example
const bowTie = Polygon2.fromFlat([0, 0, 2, 2, 2, 0, 0, 2]).value
const r = bowTie.repaired() // → two triangles, area 2, once loadGeometryKernel() has run