region2.intersection

The intersection of two single-outline regions, by kernel2d’s exact arrangement boolean.

GeometricSince 0.4.0

Usage

TypeScript
Region2.intersection(a: Region2, b: Region2): Result<Region2>

Parameters

  • aRegion2

    First operand: empty, or one outline without holes. Required. In model.

  • bRegion2

    Second 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 Region2.empty without kernel2d.

Errors

Guarantees

  • area(a ∩ b) ≤ min(area(a), area(b)) (Region2.area)
  • outlines wind counter-clockwise and holes clockwise (part.outer.isCounterClockwise(), !hole.isCounterClockwise())
  • The same result on every machine.

Use instead

Example

TypeScript
const a = Polygon2.rectangle(2, 2).value, b = Polygon2.rectangle(2, 2, Point2.of(1, 0)).value
const r = Region2.intersection(Region2.of(a), Region2.of(b)) // → area 2 once loadGeometryKernel() has run