Constructive area geometry is a fancy name for combining shapes. Two or more shapes can be combined using different rules or operations, much the way numbers can be combined in an equation. The 2D API supports four different operations for combining the areas of two shapes:
The addition of two shapes is the area covered by one or both of the shapes.
The intersection of two shapes is the area that is covered by both shapes simultaneously.
The result of subtracting one shape from another is the area covered by one that is not covered by the other.
The exclusive or operator is the inverse of the intersection operator. In other words, the exclusive or of two shapes is the area that is covered by one or the other of the shapes. But it does not include the area covered by both.
It's hard to visualize these operators just by reading about them. Figure 3.21 shows the result of applying these operators to two overlapping shapes.
In Java 2D, the java.awt.geom.Area class supports constructive area geometry. This class offers two constructors:
This constructor creates an empty Area. You can accumulate area using the add() method, described below.
public Area(Shape g)
This constructor creates an Area using the interior of the supplied Shape.
The four area operators are implemented as Area's methods:
public void add(Area rhs)
Use this ...