polygon2.contains

Whether the ring encloses a point under a fill rule.

GeometricSince 0.4.0

Usage

TypeScript
polygon.contains(p: Point2, fillRule?: FillRule): boolean

Parameters

  • pPoint2

    The point to test. Required. In model.

  • fillRuleFillRule

    Which points a ring encloses: winding number ≠ 0, or an odd number of crossings. Default 'nonZero'. One of nonZero, evenOdd.

Returns

true when the winding number is non-zero (nonZero) or odd (evenOdd); false outside and for a non-finite point.

Guarantees

  • agrees with windingNumber(p): w !== 0 for nonZero, w % 2 !== 0 for evenOdd
  • The same result on every machine.

Example

TypeScript
Polygon2.rectangle(2, 2).value.contains(Point2.of(0.5, 0.5)) // → true

See also