Nonzero-rule

In two-dimensional computer graphics, the non-zero winding rule is a means of determining whether a given point falls within an enclosed curve.

Unlike the similar even-odd rule, it relies on knowing the direction of stroke for each part of the curve.

The winding number is effectively a count of how many full counter-clockwise revolutions ('windings') the curve makes around P without doubling back on itself.

One formal definition of the winding number of point P with respect to curve C (where P does not lie on the curve) is as follows: Consider a point Q that travels once around C. The endpoint of a vector from P to Q, after normalization, travels along the unit circle centered at P. If we imagine the track of this endpoint as a rubber band, and let the band contract, it will end up wrapped about the circle some number of times.

[1]The SVG computer graphics vector standard uses the non-zero rule by default when drawing polygons.

A curve (top) is filled according to two rules: the even-odd rule (left), and the non-zero winding rule (right). In each case an arrow shows a ray from a point P heading out of the curve. In the even-odd case, the ray is intersected by two lines, an even number; therefore P is concluded to be 'outside' the curve. By the non-zero winding rule, the ray is intersected in a clockwise direction twice, each contributing -1 to the winding score: because the total, -2, is not zero, P is concluded to be 'inside' the curve.