polygon2.windingNumber

How many times the ring winds around a point, counter-clockwise turns counting +1.

GeometricSince 0.4.0

Usage

TypeScript
polygon.windingNumber(p: Point2): number

Parameters

  • pPoint2

    The point to test. Required. In model.

Returns

An integer: 0 outside, +1 inside a counter-clockwise simple ring, −1 inside a clockwise one, more for multiply wound rings; 0 for a non-finite point.

Guarantees

  • for a simple ring, the result is 0 or ±1 with the sign of signedArea()
  • reversed() negates it
  • The same result on every machine.

Example

TypeScript
const sq = Polygon2.rectangle(2, 2).value.xy
Polygon2.fromFlat([...sq, ...sq]).value.windingNumber(Point2.origin) // → 2

See also