polygon2.intersection
The region covered by both polygons, by kernel2d’s exact arrangement boolean.
Usage
Polygon2.intersection(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) ≤ min(area(a), area(b)), and Region2.empty for disjoint rings
- 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.intersection(a, b) // → area 2 once loadGeometryKernel() has run