region2.union
The union of two single-outline regions, by kernel2d’s exact arrangement boolean.
Usage
Region2.union(a: Region2, b: Region2): Result<Region2>Parameters
aRegion2First operand: empty, or one outline without holes. Required. In model.
bRegion2Second operand: empty, or one outline without holes. Required. In model.
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). An empty operand returns the other region without kernel2d.
Errors
Guarantees
- area(a ∪ b) = area(a) + area(b) − area(a ∩ b) (Region2.area)
- outlines wind counter-clockwise and holes clockwise (part.outer.isCounterClockwise(), !hole.isCounterClockwise())
- The same result on every machine.
Use instead
polygon2.union: the operands are rings, or a fill rule other than nonZero is needed
Example
const a = Polygon2.rectangle(2, 2).value, b = Polygon2.rectangle(2, 2, Point2.of(1, 0)).value
const r = Region2.union(Region2.of(a), Region2.of(b)) // → area 6 once loadGeometryKernel() has run