public final class Rectangle extends java.lang.Object implements ReadableRectangle, WritableRectangle, java.io.Serializable
Constructor and Description |
---|
Rectangle()
Constructor for Rectangle.
|
Rectangle(int x,
int y,
int w,
int h)
Constructor for Rectangle.
|
Rectangle(ReadablePoint p,
ReadableDimension d)
Constructor for Rectangle.
|
Rectangle(ReadableRectangle r)
Constructor for Rectangle.
|
Modifier and Type | Method and Description |
---|---|
void |
add(int newx,
int newy)
Adds a point, specified by the integer arguments
newx
and newy , to this Rectangle . |
void |
add(ReadablePoint pt)
Adds the specified
Point to this
Rectangle . |
void |
add(ReadableRectangle r)
Adds a
Rectangle to this Rectangle . |
boolean |
contains(int X,
int Y)
Checks whether or not this
Rectangle contains the
point at the specified location
(x, y). |
boolean |
contains(int X,
int Y,
int W,
int H)
Checks whether this
Rectangle entirely contains
the Rectangle
at the specified location (X, Y) with the
specified dimensions (W, H). |
boolean |
contains(ReadablePoint p)
Checks whether or not this
Rectangle contains the
specified Point . |
boolean |
contains(ReadableRectangle r)
Checks whether or not this
Rectangle entirely contains
the specified Rectangle . |
boolean |
equals(java.lang.Object obj)
Checks whether two rectangles are equal.
|
void |
getBounds(WritableRectangle dest)
Copy this readable rectangle's bounds into a destination Rectangle
|
int |
getHeight()
Gets the height.
|
void |
getLocation(WritablePoint dest)
Copy this ReadablePoint into a destination Point
|
void |
getSize(WritableDimension dest)
Copy this ReadableDimension into a destination Dimension
|
int |
getWidth()
Gets the width.
|
int |
getX()
Gets the x.
|
int |
getY()
Gets the y.
|
void |
grow(int h,
int v)
Resizes the
Rectangle both horizontally and vertically. |
Rectangle |
intersection(ReadableRectangle r,
Rectangle dest)
Computes the intersection of this
Rectangle with the
specified Rectangle . |
boolean |
intersects(ReadableRectangle r)
Determines whether or not this
Rectangle and the specified
Rectangle intersect. |
boolean |
isEmpty()
Determines whether or not this
Rectangle is empty. |
void |
setBounds(int x,
int y,
int w,
int h)
Sets the bounds of the rectangle
|
void |
setBounds(ReadablePoint p,
ReadableDimension d)
Sets the bounds of the rectangle
|
void |
setBounds(ReadableRectangle r)
Sets the bounds of the rectangle
|
void |
setHeight(int height)
Sets the height.
|
void |
setLocation(int x,
int y) |
void |
setLocation(ReadablePoint p) |
void |
setSize(int w,
int h) |
void |
setSize(ReadableDimension d) |
void |
setWidth(int width)
Sets the width.
|
void |
setX(int x)
Sets the x.
|
void |
setY(int y)
Sets the y.
|
java.lang.String |
toString()
Debugging
|
void |
translate(int x,
int y)
Translate the rectangle by an amount.
|
void |
translate(ReadablePoint point)
Translate the rectangle by an amount.
|
WritableRectangle |
union(ReadableRectangle r,
WritableRectangle dest)
Computes the union of this
Rectangle with the
specified Rectangle . |
void |
untranslate(ReadablePoint point)
Un-translate the rectangle by an amount.
|
public Rectangle()
public Rectangle(int x, int y, int w, int h)
public Rectangle(ReadablePoint p, ReadableDimension d)
public Rectangle(ReadableRectangle r)
public void setLocation(int x, int y)
setLocation
in interface WritablePoint
public void setLocation(ReadablePoint p)
setLocation
in interface WritablePoint
public void setSize(int w, int h)
setSize
in interface WritableDimension
public void setSize(ReadableDimension d)
setSize
in interface WritableDimension
public void setBounds(int x, int y, int w, int h)
WritableRectangle
setBounds
in interface WritableRectangle
x
- Position of rectangle on x axisy
- Position of rectangle on y axisw
- Width of rectangleh
- Height of rectanglepublic void setBounds(ReadablePoint p, ReadableDimension d)
WritableRectangle
setBounds
in interface WritableRectangle
public void setBounds(ReadableRectangle r)
WritableRectangle
setBounds
in interface WritableRectangle
public void getBounds(WritableRectangle dest)
ReadableRectangle
getBounds
in interface ReadableRectangle
dest
- The destination Rectangle, or null, to create a new Rectanglepublic void getLocation(WritablePoint dest)
ReadablePoint
getLocation
in interface ReadablePoint
dest
- The destination Point, or null, to create a new Pointpublic void getSize(WritableDimension dest)
ReadableDimension
getSize
in interface ReadableDimension
dest
- The destinationpublic void translate(int x, int y)
x
- The translation amount on the x axisy
- The translation amount on the y axispublic void translate(ReadablePoint point)
point
- The translation amountpublic void untranslate(ReadablePoint point)
point
- The translation amountpublic boolean contains(ReadablePoint p)
Rectangle
contains the
specified Point
.p
- the Point
to testtrue
if the Point
(x, y) is inside this
Rectangle
;
false
otherwise.public boolean contains(int X, int Y)
Rectangle
contains the
point at the specified location
(x, y).X
- the specified x coordinateY
- the specified y coordinatetrue
if the point
(x, y) is inside this
Rectangle
;
false
otherwise.public boolean contains(ReadableRectangle r)
Rectangle
entirely contains
the specified Rectangle
.r
- the specified Rectangle
true
if the Rectangle
is contained entirely inside this Rectangle
;
false
otherwise.public boolean contains(int X, int Y, int W, int H)
Rectangle
entirely contains
the Rectangle
at the specified location (X, Y) with the
specified dimensions (W, H).X
- the specified x coordinateY
- the specified y coordinateW
- the width of the Rectangle
H
- the height of the Rectangle
true
if the Rectangle
specified by
(X, Y, W, H)
is entirely enclosed inside this Rectangle
;
false
otherwise.public boolean intersects(ReadableRectangle r)
Rectangle
and the specified
Rectangle
intersect. Two rectangles intersect if
their intersection is nonempty.r
- the specified Rectangle
true
if the specified Rectangle
and this Rectangle
intersect;
false
otherwise.public Rectangle intersection(ReadableRectangle r, Rectangle dest)
Rectangle
with the
specified Rectangle
. Returns a new Rectangle
that represents the intersection of the two rectangles.
If the two rectangles do not intersect, the result will be
an empty rectangle.r
- the specified Rectangle
Rectangle
contained in both the
specified Rectangle
and in
this Rectangle
; or if the rectangles
do not intersect, an empty rectangle.public WritableRectangle union(ReadableRectangle r, WritableRectangle dest)
Rectangle
with the
specified Rectangle
. Returns a new
Rectangle
that
represents the union of the two rectanglesr
- the specified Rectangle
Rectangle
containing both
the specified Rectangle
and this
Rectangle
.public void add(int newx, int newy)
newx
and newy
, to this Rectangle
. The
resulting Rectangle
is
the smallest Rectangle
that contains both the
original Rectangle
and the specified point.
After adding a point, a call to contains
with the
added point as an argument does not necessarily return
true
. The contains
method does not
return true
for points on the right or bottom
edges of a Rectangle
. Therefore, if the added point
falls on the right or bottom edge of the enlarged
Rectangle
, contains
returns
false
for that point.
newx
- the x coordinates of the new pointnewy
- the y coordinates of the new pointpublic void add(ReadablePoint pt)
Point
to this
Rectangle
. The resulting Rectangle
is the smallest Rectangle
that contains both the
original Rectangle
and the specified
Point
.
After adding a Point
, a call to contains
with the added Point
as an argument does not
necessarily return true
. The contains
method does not return true
for points on the right
or bottom edges of a Rectangle
. Therefore if the added
Point
falls on the right or bottom edge of the
enlarged Rectangle
, contains
returns
false
for that Point
.
pt
- the new Point
to add to this
Rectangle
public void add(ReadableRectangle r)
Rectangle
to this Rectangle
.
The resulting Rectangle
is the union of the two
rectangles.r
- the specified Rectangle
public void grow(int h, int v)
Rectangle
both horizontally and vertically.
This method modifies the Rectangle
so that it is
h
units larger on both the left and right side,
and v
units larger at both the top and bottom.
The new Rectangle
has (x - h
,
y - v
) as its top-left corner, a
width of
width
+
2h
,
and a height of
height
+
2v
.
If negative values are supplied for h
and
v
, the size of the Rectangle
decreases accordingly.
The grow
method does not check whether the resulting
values of width
and height
are
non-negative.
h
- the horizontal expansionv
- the vertical expansionpublic boolean isEmpty()
Rectangle
is empty. A
Rectangle
is empty if its width or its height is less
than or equal to zero.true
if this Rectangle
is empty;
false
otherwise.public boolean equals(java.lang.Object obj)
The result is true
if and only if the argument is not
null
and is a Rectangle
object that has the
same top-left corner, width, and height as this Rectangle
.
equals
in class java.lang.Object
obj
- the Object
to compare with
this Rectangle
true
if the objects are equal;
false
otherwise.public java.lang.String toString()
toString
in class java.lang.Object
public int getHeight()
getHeight
in interface ReadableDimension
public void setHeight(int height)
setHeight
in interface WritableDimension
height
- The height to setpublic int getWidth()
getWidth
in interface ReadableDimension
public void setWidth(int width)
setWidth
in interface WritableDimension
width
- The width to setpublic int getX()
getX
in interface ReadablePoint
public void setX(int x)
setX
in interface WritablePoint
x
- The x to setpublic int getY()
getY
in interface ReadablePoint
public void setY(int y)
setY
in interface WritablePoint
y
- The y to setCopyright © 2002-2009 lwjgl.org. All Rights Reserved.