closes interior “holes," and the “holes" may also enclose further interior paths. Therefore, it is not necessar-
ily obvious whether a given point is inside or outside a complex shape. In these situations, the determination
of whether a point is inside or outside a shape is made by applying a winding rule . When you create a Gen-
eralPath object, you have the option of defining one of two winding rules that are then used to determine
whether a given point is inside or outside the shape. The winding rules that you can specify are defined by
static constants that are inherited in the GeneralPath class from Path2D :
• WIND_EVEN_ODD : A point is interior to a GeneralPath object if the boundary is crossed an odd
number of times by a line from a point exterior to the GeneralPath to the point in question. When
you use this winding rule for shapes with holes, a point is determined to be interior to the shape if
it is enclosed by an odd number of boundaries.
• WIND_NON_ZERO : Whether a point is inside or outside a path is determined by considering how the
path boundaries cross a line drawn from the point in question to infinity, taking account of the dir-
ection in which the path boundaries are drawn.
Looking along the line from the point, the point is interior to the GeneralPath object if the difference
between the number of times the line is crossed by a boundary from left to right, and the number of times
the line is crossed from right to left, is non-zero. When you use this rule for shapes bounded by more than
one contiguous path — with holes, in other words — the result varies depending on the direction in which
each path is drawn. If an interior path is drawn in the opposite direction to the outer path, the interior of
the inner path is determined as not being interior to the shape.
The region of the shape that is determined as being inside the shape is shown shaded in Figure 19-16 .
The directions in which the boundaries are drawn are indicated by the arrows on the boundaries. As you can
see, the region where P3 lies is determined as being outside the shape by the WIND_EVEN_ODD rule, and as
being inside the shape by the WIND_NON_ZERO rule.
You have four constructors available for creating GeneralPath objects:
• GeneralPath() : Defines a general path with a default winding rule of WIND_NON_ZERO .