Repository navigation
FillRule
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:
- From a point that's outside a given polygon, draw an imaginary line through the polygon.
- Starting with a winding number of zero, and beginning at the start of this imaginary line, follow the line as it crosses the polygon.
- 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.
- And as you enter each polygon sub-region, allocate to it the current winding number.
Filling Rules:
- Even-Odd: Only odd numbered sub-regions are filled
- Non-Zero: Only non-zero sub-regions are filled
- Positive: Only sub-regions with winding counts > 0 are filled
- Negative: Only sub-regions with winding counts < 0 are filled
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:
- Reversing a polygon's path will reverse its orientation, as will inverting the Y-axis in which it's displayed. Yet reversing orientation won't affect winding number odd-ness or even-ness, or whether it's zero. It will only change the winding number's sign (ie from positive to negative and vice-versa).
- Only clipping functions require filling rules together with path definitions. Polygon filling has no bearing on polygon offsetting.
Copyright © 2010-2025 Angus Johnson. Clipper2 is distributed under the Boost Software License.
Headers
- clipper.h
- clipper.core.h
- clipper.engine.h
- clipper.export.h
- clipper.minkowski.h
- clipper.offset.h
- clipper.rectclip.h
- clipper.triangulation.h
Classes
Data types and structure definitions
- ClipType
- EndType
- FillRule
- JoinType
- Path64
- PathD
- Paths64
- PathsD
- Point64
- PointD
- PointInPolygonResult
- Rect64
- RectD
- TriangulateResult
- ZCallback64
- ZCallbackD
Static Functions
- Area
- BooleanOp
- Difference
- InflatePaths
- Intersect
- IsPositive
- MakePath
- MinkowskiDiff
- MinkowskiSum
- PointInPolygon
- PolyTreeToPaths64
- PolyTreeToPathsD
- RectClip
- RectClipLines
- ReversePath
- SimplifyPaths
- TranslatePath
- Triangulate
- TrimCollinear
- Union
- XOR
Topics