Java Reference
In-Depth Information
There are also several methods that
you can use to combine
Rectangle
objects, and also to extend a
Rectangle
object to enclose a point.
The effects of each of these methods
are shown in the following diagram.
The rectangle that results from each operation is shown dashed. The methods illustrated in the diagram are:
Method
Description
Rectangle
intersection(
Rectangle
r)
Returns a
Rectangle
object that is the intersection of
the current object and the argument. If the two rectangles
do not intersect, the
Rectangle
object returned is at
position (0, 0) and the
width
and
height
members are
zero so the rectangle is empty.
Rectangle
union(
Rectangle
r)
Returns the smallest
Rectangle
object enclosing both
the current
Rectangle
object and the
Rectangle
object
r
, passed as an argument.
void
add(Rectangle
r)
Expands the current
Rectangle
object to enclose the
argument
Rectangle
.
void
add(Point
p)
Expands the current
Rectangle
object to enclose the
Point
object
p
. The result will be the smallest rectangle
that encloses the original rectangle and the point.
void
add(int
x,
int
y)
Expands the current
Rectangle
object to enclose the
point at (
x
,
y
).
void
grow(int
h,
int
v)
Enlarges the current
Rectangle
object by moving the
boundary out from the center by
h
horizontally and
v
vertically.