polygon2.union
The region covered by either polygon, by kernel2d’s exact arrangement boolean.
Usage
Polygon2.union(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(b) − 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.
Use instead
region2.union: the operands are already single-outline regions
Example
const a = Polygon2.rectangle(2, 2).value, b = Polygon2.rectangle(2, 2, Point2.of(1, 0)).value
const r = Polygon2.union(a, b) // → area 6 once loadGeometryKernel() has run