Class Rectangle
- java.lang.Object
-
- org.lwjgl.util.Rectangle
-
- All Implemented Interfaces:
Serializable,ReadableDimension,ReadablePoint,ReadableRectangle,WritableDimension,WritablePoint,WritableRectangle
public final class Rectangle extends Object implements ReadableRectangle, WritableRectangle, Serializable
A 2D integer Rectangle class which looks remarkably like an AWT one.- Version:
- $Revision$ $Id$
- Author:
- $Author$
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int newx, int newy)Adds a point, specified by the integer argumentsnewxandnewy, to thisRectangle.voidadd(ReadablePoint pt)Adds the specifiedPointto thisRectangle.voidadd(ReadableRectangle r)Adds 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).booleancontains(ReadablePoint p)Checks whether or not thisRectanglecontains the specifiedPoint.booleancontains(ReadableRectangle r)Checks whether or not thisRectangleentirely contains the specifiedRectangle.booleanequals(Object obj)Checks whether two rectangles are equal.voidgetBounds(WritableRectangle dest)Copy this readable rectangle's bounds into a destination RectangleintgetHeight()Gets 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.Rectangleintersection(ReadableRectangle r, Rectangle dest)Computes the intersection of thisRectanglewith the specifiedRectangle.booleanintersects(ReadableRectangle r)Determines 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 rectanglevoidsetBounds(ReadablePoint p, ReadableDimension d)Sets the bounds of the rectanglevoidsetBounds(ReadableRectangle r)Sets the bounds of the rectanglevoidsetHeight(int height)Sets the height.voidsetLocation(int x, int y)voidsetLocation(ReadablePoint p)voidsetSize(int w, int h)voidsetSize(ReadableDimension d)voidsetWidth(int width)Sets the width.voidsetX(int x)Sets the x.voidsetY(int y)Sets the y.StringtoString()Debuggingvoidtranslate(int x, int y)Translate the rectangle by an amount.voidtranslate(ReadablePoint point)Translate the rectangle by an amount.WritableRectangleunion(ReadableRectangle r, WritableRectangle dest)Computes the union of thisRectanglewith the specifiedRectangle.voiduntranslate(ReadablePoint point)Un-translate the rectangle by an amount.
-
-
-
Constructor Detail
-
Rectangle
public Rectangle()
Constructor for Rectangle.
-
Rectangle
public Rectangle(int x, int y, int w, int h)Constructor for Rectangle.
-
Rectangle
public Rectangle(ReadablePoint p, ReadableDimension d)
Constructor for Rectangle.
-
Rectangle
public Rectangle(ReadableRectangle r)
Constructor for Rectangle.
-
-
Method Detail
-
setLocation
public void setLocation(int x, int y)- Specified by:
setLocationin interfaceWritablePoint
-
setLocation
public void setLocation(ReadablePoint p)
- Specified by:
setLocationin interfaceWritablePoint
-
setSize
public void setSize(int w, int h)- Specified by:
setSizein interfaceWritableDimension
-
setSize
public void setSize(ReadableDimension d)
- 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
public void setBounds(ReadablePoint p, ReadableDimension d)
Description copied from interface:WritableRectangleSets the bounds of the rectangle- Specified by:
setBoundsin interfaceWritableRectangle
-
setBounds
public void setBounds(ReadableRectangle r)
Description copied from interface:WritableRectangleSets the bounds of the rectangle- Specified by:
setBoundsin interfaceWritableRectangle
-
getBounds
public void getBounds(WritableRectangle dest)
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
public void getLocation(WritablePoint dest)
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
public void getSize(WritableDimension dest)
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
public void translate(ReadablePoint point)
Translate the rectangle by an amount.- Parameters:
point- The translation amount
-
untranslate
public void untranslate(ReadablePoint point)
Un-translate the rectangle by an amount.- Parameters:
point- The translation amount
-
contains
public boolean contains(ReadablePoint p)
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
public boolean contains(ReadableRectangle r)
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
public boolean intersects(ReadableRectangle r)
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
public Rectangle intersection(ReadableRectangle r, Rectangle dest)
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
public WritableRectangle union(ReadableRectangle r, WritableRectangle dest)
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
public void add(ReadablePoint pt)
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
public void add(ReadableRectangle r)
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
public boolean equals(Object obj)
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.
-
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
-
-