region2.difference
The part of region a outside region b, by kernel2d’s exact arrangement boolean.
Usage
Region2.difference(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 a returns Region2.empty and an empty b returns a, without kernel2d.
Errors
Guarantees
- area(a − b) = area(a) − 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.difference: 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.difference(Region2.of(a), Region2.of(b)) // → area 2 once loadGeometryKernel() has run