polygon2.difference
The region of a not covered by b, by kernel2d’s exact arrangement boolean; a hole appears when b lies inside a.
Usage
Polygon2.difference(a: Polygon2, b: Polygon2, fillRule?: FillRule): Result<Region2>Parameters
aPolygon2First operand, one ring of either orientation. Required. In model.
bPolygon2Second operand, one ring of either orientation. Required. In model.
fillRuleFillRuleWhich points a ring encloses: winding number ≠ 0, or an odd number of crossings. Default
'nonZero'. One ofnonZero,evenOdd.
Returns
Ok with a region of zero or more parts, each an outline with its holes; Region2.empty when nothing remains (e.g. the intersection of disjoint rings), and also when a coordinate is outside kernel2d’s magnitude contract (see limits).
Errors
Guarantees
- area(a − b) = area(a) − area(a ∩ b), to about 1e-12 relative (Region2.area)
- outlines wind counter-clockwise and holes clockwise (part.outer.isCounterClockwise(), !hole.isCounterClockwise())
- The same result on every machine.
Example
const a = Polygon2.rectangle(2, 2).value, b = Polygon2.rectangle(2, 2, Point2.of(1, 0)).value
const r = Polygon2.difference(a, b) // → area 2 once loadGeometryKernel() has run