Previous Next


                                        232
CHAPTER 4                                                                   Graphics



in a dash pattern. In the latter case, the line caps are always painted, since their
orientation is determined by the direction of the underlying path.) A single-
point open subpath (specified by a trailing m operator) produces no output.


Filling

The f operator uses the current nonstroking color to paint the entire region en-
closed by the current path. If the path consists of several disconnected subpaths, f
paints the insides of all subpaths, considered together. Any subpaths that are open
are implicitly closed before being filled.

If a subpath is degenerate (consists of a single-point closed path or of two or more
points at the same coordinates), f paints the single device pixel lying under that
point; the result is device-dependent and not generally useful. A single-point
open subpath (specified by a trailing m operator) produces no output.

For a simple path, it is intuitively clear what region lies inside. However, for a
more complex path—for example, a path that intersects itself or has one subpath
that encloses another—it is not always obvious which points lie inside the path.
The path machinery uses one of two rules for determining which points lie inside
a path: the nonzero winding number rule and the even-odd rule, both discussed in
detail below.

The nonzero winding number rule is more versatile than the even-odd rule and is
the standard rule the f operator uses. Similarly, the W operator uses this rule to
determine the inside of the current clipping path. The even-odd rule is occasion-
ally useful for special effects or for compatibility with other graphics systems; the
f* and W* operators invoke this rule.


Nonzero Winding Number Rule

The nonzero winding number rule determines whether a given point is inside a
path by conceptually drawing a ray from that point to infinity in any direction
and then examining the places where a segment of the path crosses the ray. Start-
ing with a count of 0, the rule adds 1 each time a path segment crosses the ray
from left to right and subtracts 1 each time a segment crosses from right to left.
After counting all the crossings, if the result is 0, the point is outside the path;
otherwise, it is inside.

Previous Next