◄ WORLD V · SONNY 5DART 497 · a helldive at the net

THE WINDING NUMBER how many times the boundary wraps the point — a topological count

The winding number counts how many times a closed curve travels around a point — a signed integer, positive for counter-clockwise loops. For point-in-polygon it is the robust cousin of ray casting: it is 1 inside a simple polygon and 0 outside, and unlike the even-odd rule it stays correct for self-overlapping paths and non-zero fill rules (the ones every vector renderer offers). You compute it by summing signed edge crossings — up-and-left adds one, down-and-right subtracts one. A topological quantity from local arithmetic, edge by edge.

THE TECHNIQUE sum signed crossings — +1 up-left, −1 down-right; inside ⇒ 1

The demo computes the winding number of a square around two points — 1 inside, 0 outside: live demo


HISTORY & CREDIT winding number · nonzero-fill rule

“Inside is just odd crossings.” — the winding number is signed, so it fills self-overlapping paths correctly where parity fails. cited

the count · sum signed edge crossings of a ray — up-left +1, down-right −1.
the verdict · nonzero ⇒ inside; for a simple polygon it is 1 in, 0 out.
the difference · robust to self-overlap where even-odd (dart 491) is not — the nonzero-fill rule.

A topological wrap-count assembled from signed local crossings — how many times the boundary circles the point. recognizer

RECOMMEND FOR I-13 the wrap count, on the compiler

On the canonical compiler, the square winds once around (2,2) (inside) and zero times around (6,2) (outside):

$ i13 run cg_windingnumber.i13 # signed crossings RUN OK · 669 step(s) · peak stack 16 · call depth 6 w_in = 1 -- (2,2): winds once w_out = 0 -- (6,2): winds zero times test = 1
Recommend as a NULL — a recognizer, topological flavor. The winding number tests containment (B41), computing a signed integer forall-pinned by the polygon (B39). It is a lovely topological quantity — the robust twin of ray casting — but a checked count, not an enacted channel. NULL.