Constructor and Description |
---|
Rectangle()
Creates a new instance of Rectangle
|
Rectangle(int x,
int y,
Dimension size)
Creates a new instance of Rectangle at position (x, y) and with
predefine dimension
|
Rectangle(int x,
int y,
int w,
int h)
Creates a new instance of Rectangle at position (x, y) and with
predefine width and height
|
Rectangle(Rectangle rect)
A copy Constructor
|
Modifier and Type | Method and Description |
---|---|
boolean |
contains(int rX,
int rY)
Checks whether or not this Rectangle contains the point at the specified
location (rX, rY).
|
boolean |
contains(int rX,
int rY,
int rWidth,
int rHeight)
Checks whether this Rectangle entirely contains the Rectangle
at the specified location (rX, rY) with the specified
dimensions (rWidth, rHeight).
|
static boolean |
contains(int x1,
int y1,
int w1,
int h1,
int x2,
int y2,
int w2,
int h2)
Checks wheather the 2nd rectangle is contained in the first rectangle
|
boolean |
contains(Rectangle rect)
Checks whether or not this Rectangle entirely contains the specified
Rectangle.
|
Dimension |
getSize()
Return the dimension of the rectangle
|
int |
getX()
Return the x coordinate of the rectangle
|
int |
getY()
Return the y coordinate of the rectangle
|
Rectangle |
intersection(int rX,
int rY,
int rW,
int rH)
Returns a rectangle that intersects the given rectangle with this rectangle
|
Rectangle |
intersection(Rectangle r)
Returns a rectangle that intersects the given rectangle with this rectangle
|
boolean |
intersects(int x,
int y,
int width,
int height)
Determines whether or not this Rectangle and the specified Rectangle
location (x, y) with the specified dimensions (width, height),
intersect.
|
static boolean |
intersects(int tx,
int ty,
int tw,
int th,
int x,
int y,
int width,
int height)
Helper method allowing us to determine if two coordinate sets intersect.
|
boolean |
intersects(Rectangle rect)
Determines whether or not this Rectangle and the specified Rectangle
location (x, y) with the specified dimensions (width, height),
intersect.
|
void |
setX(int x)
Sets the x position of the rectangle
|
void |
setY(int y)
Sets the y position of the rectangle
|
String |
toString()
Returns a string representation of the object.
|
public Rectangle()
public Rectangle(int x, int y, Dimension size)
x
- the x coordinate of the rectangley
- the y coordinate of the rectanglesize
- the Dimension
of the rectanglepublic Rectangle(int x, int y, int w, int h)
x
- the x coordinate of the rectangley
- the y coordinate of the rectanglew
- the width of the rectangleh
- the height of the rectanglepublic Rectangle(Rectangle rect)
rect
- the Rectangle to copypublic Dimension getSize()
public int getX()
public int getY()
public String toString()
Object
toString
method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read.
It is recommended that all subclasses override this method.
The toString
method for class Object
returns a string consisting of the name of the class of which the
object is an instance, the at-sign character `@
', and
the unsigned hexadecimal representation of the hash code of the
object. In other words, this method returns a string equal to the
value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
public void setX(int x)
x
- the x coordinate of the rectanglepublic void setY(int y)
y
- the y coordinate of the rectanglepublic boolean contains(Rectangle rect)
rect
- the specified Rectanglepublic boolean contains(int rX, int rY, int rWidth, int rHeight)
rX
- the specified x coordinaterY
- the specified y coordinaterWidth
- the width of the RectanglerHeight
- the height of the Rectanglepublic static boolean contains(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2)
x1
- first rect xy1
- first rect yw1
- first rect wh1
- first rect hx2
- second rect xy2
- second rect yw2
- second rect wh2
- second rect hpublic boolean contains(int rX, int rY)
rX
- the specified x coordinaterY
- the specified y coordinatepublic Rectangle intersection(int rX, int rY, int rW, int rH)
rX
- rectangle to intersect with this rectanglerY
- rectangle to intersect with this rectanglerW
- rectangle to intersect with this rectanglerH
- rectangle to intersect with this rectanglepublic Rectangle intersection(Rectangle r)
r
- rectangle to intersect with this rectanglepublic boolean intersects(int x, int y, int width, int height)
x
- the specified x coordinatey
- the specified y coordinatewidth
- the width of the Rectangleheight
- the height of the Rectanglepublic boolean intersects(Rectangle rect)
rect
- the Rectangle to check intersection withpublic static boolean intersects(int tx, int ty, int tw, int th, int x, int y, int width, int height)
tx
- x of first rectanglety
- y of first rectangletw
- width of first rectangleth
- height of first rectanglex
- x of second rectangley
- y of second rectanglewidth
- width of second rectangleheight
- height of second rectangle