Class Rectangle
- All Implemented Interfaces:
Serializable,ReadableDimension,ReadablePoint,ReadableRectangle,WritableDimension,WritablePoint,WritableRectangle
- Version:
- $Revision$ $Id$
- Author:
- $Author$
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor for Rectangle.Rectangle(int x, int y, int w, int h) Constructor for Rectangle.Constructor for Rectangle.Constructor for Rectangle. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(int newx, int newy) Adds a point, specified by the integer argumentsnewxandnewy, to thisRectangle.voidadd(ReadablePoint pt) Adds the specifiedPointto thisRectangle.voidAdds aRectangleto thisRectangle.booleancontains(int X, int Y) Checks whether or not thisRectanglecontains the point at the specified location (x, y).booleancontains(int X, int Y, int W, int H) Checks whether thisRectangleentirely contains theRectangleat the specified location (X, Y) with the specified dimensions (W, H).booleanChecks whether or not thisRectanglecontains the specifiedPoint.booleanChecks whether or not thisRectangleentirely contains the specifiedRectangle.booleanChecks whether two rectangles are equal.voidgetBounds(WritableRectangle dest) Copy this readable rectangle's bounds into a destination RectangleintGets the height.voidgetLocation(WritablePoint dest) Copy this ReadablePoint into a destination PointvoidgetSize(WritableDimension dest) Copy this ReadableDimension into a destination DimensionintgetWidth()Gets the width.intgetX()Gets the x.intgetY()Gets the y.voidgrow(int h, int v) Resizes theRectangleboth horizontally and vertically.intersection(ReadableRectangle r, Rectangle dest) Computes the intersection of thisRectanglewith the specifiedRectangle.booleanDetermines whether or not thisRectangleand the specifiedRectangleintersect.booleanisEmpty()Determines whether or not thisRectangleis empty.voidsetBounds(int x, int y, int w, int h) Sets the bounds of the rectanglevoidSets the bounds of the rectanglevoidSets the bounds of the rectanglevoidsetHeight(int height) Sets the height.voidsetLocation(int x, int y) voidvoidsetSize(int w, int h) voidvoidsetWidth(int width) Sets the width.voidsetX(int x) Sets the x.voidsetY(int y) Sets the y.toString()Debuggingvoidtranslate(int x, int y) Translate the rectangle by an amount.voidtranslate(ReadablePoint point) Translate the rectangle by an amount.union(ReadableRectangle r, WritableRectangle dest) Computes the union of thisRectanglewith the specifiedRectangle.voiduntranslate(ReadablePoint point) Un-translate the rectangle by an amount.
-
Constructor Details
-
Rectangle
public Rectangle()Constructor for Rectangle. -
Rectangle
public Rectangle(int x, int y, int w, int h) Constructor for Rectangle. -
Rectangle
Constructor for Rectangle. -
Rectangle
Constructor for Rectangle.
-
-
Method Details
-
setLocation
public void setLocation(int x, int y) - Specified by:
setLocationin interfaceWritablePoint
-
setLocation
- Specified by:
setLocationin interfaceWritablePoint
-
setSize
public void setSize(int w, int h) - Specified by:
setSizein interfaceWritableDimension
-
setSize
- Specified by:
setSizein interfaceWritableDimension
-
setBounds
public void setBounds(int x, int y, int w, int h) Description copied from interface:WritableRectangleSets the bounds of the rectangle- Specified by:
setBoundsin interfaceWritableRectangle- Parameters:
x- Position of rectangle on x axisy- Position of rectangle on y axisw- Width of rectangleh- Height of rectangle
-
setBounds
Description copied from interface:WritableRectangleSets the bounds of the rectangle- Specified by:
setBoundsin interfaceWritableRectangle- Parameters:
p-d-
-
setBounds
Description copied from interface:WritableRectangleSets the bounds of the rectangle- Specified by:
setBoundsin interfaceWritableRectangle- Parameters:
r-
-
getBounds
Description copied from interface:ReadableRectangleCopy this readable rectangle's bounds into a destination Rectangle- Specified by:
getBoundsin interfaceReadableRectangle- Parameters:
dest- The destination Rectangle, or null, to create a new Rectangle
-
getLocation
Description copied from interface:ReadablePointCopy this ReadablePoint into a destination Point- Specified by:
getLocationin interfaceReadablePoint- Parameters:
dest- The destination Point, or null, to create a new Point
-
getSize
Description copied from interface:ReadableDimensionCopy this ReadableDimension into a destination Dimension- Specified by:
getSizein interfaceReadableDimension- Parameters:
dest- The destination
-
translate
public void translate(int x, int y) Translate the rectangle by an amount.- Parameters:
x- The translation amount on the x axisy- The translation amount on the y axis
-
translate
Translate the rectangle by an amount.- Parameters:
point- The translation amount
-
untranslate
Un-translate the rectangle by an amount.- Parameters:
point- The translation amount
-
contains
Checks whether or not thisRectanglecontains the specifiedPoint.- Parameters:
p- thePointto test- Returns:
trueif thePoint(x, y) is inside thisRectangle;falseotherwise.
-
contains
public boolean contains(int X, int Y) Checks whether or not thisRectanglecontains the point at the specified location (x, y).- Parameters:
X- the specified x coordinateY- the specified y coordinate- Returns:
trueif the point (x, y) is inside thisRectangle;falseotherwise.
-
contains
Checks whether or not thisRectangleentirely contains the specifiedRectangle.- Parameters:
r- the specifiedRectangle- Returns:
trueif theRectangleis contained entirely inside thisRectangle;falseotherwise.
-
contains
public boolean contains(int X, int Y, int W, int H) Checks whether thisRectangleentirely contains theRectangleat the specified location (X, Y) with the specified dimensions (W, H).- Parameters:
X- the specified x coordinateY- the specified y coordinateW- the width of theRectangleH- the height of theRectangle- Returns:
trueif theRectanglespecified by (X, Y, W, H) is entirely enclosed inside thisRectangle;falseotherwise.
-
intersects
Determines whether or not thisRectangleand the specifiedRectangleintersect. Two rectangles intersect if their intersection is nonempty.- Parameters:
r- the specifiedRectangle- Returns:
trueif the specifiedRectangleand thisRectangleintersect;falseotherwise.
-
intersection
Computes the intersection of thisRectanglewith the specifiedRectangle. Returns a newRectanglethat represents the intersection of the two rectangles. If the two rectangles do not intersect, the result will be an empty rectangle.- Parameters:
r- the specifiedRectangle- Returns:
- the largest
Rectanglecontained in both the specifiedRectangleand in thisRectangle; or if the rectangles do not intersect, an empty rectangle.
-
union
Computes the union of thisRectanglewith the specifiedRectangle. Returns a newRectanglethat represents the union of the two rectangles- Parameters:
r- the specifiedRectangle- Returns:
- the smallest
Rectanglecontaining both the specifiedRectangleand thisRectangle.
-
add
public void add(int newx, int newy) Adds a point, specified by the integer argumentsnewxandnewy, to thisRectangle. The resultingRectangleis the smallestRectanglethat contains both the originalRectangleand the specified point.After adding a point, a call to
containswith the added point as an argument does not necessarily returntrue. Thecontainsmethod does not returntruefor points on the right or bottom edges of aRectangle. Therefore, if the added point falls on the right or bottom edge of the enlargedRectangle,containsreturnsfalsefor that point.- Parameters:
newx- the x coordinates of the new pointnewy- the y coordinates of the new point
-
add
Adds the specifiedPointto thisRectangle. The resultingRectangleis the smallestRectanglethat contains both the originalRectangleand the specifiedPoint.After adding a
Point, a call tocontainswith the addedPointas an argument does not necessarily returntrue. Thecontainsmethod does not returntruefor points on the right or bottom edges of aRectangle. Therefore if the addedPointfalls on the right or bottom edge of the enlargedRectangle,containsreturnsfalsefor thatPoint.- Parameters:
pt- the newPointto add to thisRectangle
-
add
Adds aRectangleto thisRectangle. The resultingRectangleis the union of the two rectangles.- Parameters:
r- the specifiedRectangle
-
grow
public void grow(int h, int v) Resizes theRectangleboth horizontally and vertically.This method modifies the
Rectangleso that it ishunits larger on both the left and right side, andvunits larger at both the top and bottom.The new
Rectanglehas (x - h,y - v) as its top-left corner, a width ofwidth+2h, and a height ofheight+2v.If negative values are supplied for
handv, the size of theRectangledecreases accordingly. Thegrowmethod does not check whether the resulting values ofwidthandheightare non-negative.- Parameters:
h- the horizontal expansionv- the vertical expansion
-
isEmpty
public boolean isEmpty()Determines whether or not thisRectangleis empty. ARectangleis empty if its width or its height is less than or equal to zero.- Returns:
trueif thisRectangleis empty;falseotherwise.
-
equals
Checks whether two rectangles are equal.The result is
trueif and only if the argument is notnulland is aRectangleobject that has the same top-left corner, width, and height as thisRectangle. -
toString
Debugging -
getHeight
public int getHeight()Gets the height.- Specified by:
getHeightin interfaceReadableDimension- Returns:
- Returns a int
-
setHeight
public void setHeight(int height) Sets the height.- Specified by:
setHeightin interfaceWritableDimension- Parameters:
height- The height to set
-
getWidth
public int getWidth()Gets the width.- Specified by:
getWidthin interfaceReadableDimension- Returns:
- Returns a int
-
setWidth
public void setWidth(int width) Sets the width.- Specified by:
setWidthin interfaceWritableDimension- Parameters:
width- The width to set
-
getX
public int getX()Gets the x.- Specified by:
getXin interfaceReadablePoint- Returns:
- Returns a int
-
setX
public void setX(int x) Sets the x.- Specified by:
setXin interfaceWritablePoint- Parameters:
x- The x to set
-
getY
public int getY()Gets the y.- Specified by:
getYin interfaceReadablePoint- Returns:
- Returns a int
-
setY
public void setY(int y) Sets the y.- Specified by:
setYin interfaceWritablePoint- Parameters:
y- The y to set
-