region2.contains

Whether a point lies inside an outline of the region and in none of that outline’s holes.

GeometricSince 0.4.0

Usage

TypeScript
region.contains(p: Point2): boolean

Parameters

  • pPoint2

    The point to test. Required. In model.

Returns

true inside the region; false outside, in a hole, for Region2.empty and for a non-finite point.

Guarantees

  • true exactly when some part’s outer.contains(p) and none of its holes contains p (nonZero per ring)
  • The same result on every machine.

Example

TypeScript
const r = Region2.of(Polygon2.rectangle(4, 4).value, [Polygon2.rectangle(2, 2).value])
r.contains(Point2.of(1.5, 0)) && !r.contains(Point2.origin) // → true (in the ring, not in the hole)

See also