FillRule

Delphi type TFillRule = (EvenOdd, NonZero, Positive, Negative);

C++ enum FillRule {EvenOdd, NonZero, Positive, Negative};

C#  public enum FillRule {EvenOdd, NonZero, Positive, Negative};


Complex polygons are defined by one or more closed paths that set both outer and inner polygon boundaries. But only portions of these paths (or 'contours') may be setting polygon boundaries, so crossing a path may or may not mean entering or exiting a 'filled' polygon region. For this reason complex polygons require filling rules that define which polygon sub-regions will be considered inside a given polygon, and which sub-regions will not.

The Clipper Library supports 4 filling rules: Even-Odd, Non-Zero, Positive and Negative. These rules are base on the winding numbers (see below) of each polygon sub-region, which in turn are based on the orientation of each path. Orientation is determined by the order in which vertices are declared during path construction, and whether these vertices progress roughly clockwise or counter-clockwise.

Winding numbers for polygon sub-regions can be derived using the following algorithm:

  1. From a point that's outside a given polygon, draw an imaginary line through the polygon.
  2. Starting with a winding number of zero, and beginning at the start of this imaginary line, follow the line as it crosses the polygon.
  3. For each polygon contour that you cross, increment the winding number if the line is heading right to left (relative to your imaginary line), otherwise decrement the winding number.
  4. And as you enter each polygon sub-region, allocate to it the current winding number.


Filling Rules:



By far the most widely used fill rules are Even-Odd and Non-Zero. Most graphics rendering libraries (AGG, Android Graphics, Cairo, GDI+, OpenGL, Quartz 2D etc) and vector graphics storage formats (SVG, Postscript, Photoshop etc) support both these rules. However some libraries (eg Java's Graphics2D) only support EvenOdd filling. Android Graphics and OpenGL are the only libraries that I'm aware of that support filling rules other than EvenOdd and NonZero.

Additional notes:

See Also

Difference, Intersect, Union, XOR