Top Description Fields Constructors Methods
org.lwjgl.util

public final Class Rectangle

extends Object
implements ReadableRectangle, WritableRectangle, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.lwjgl.util.WritableRectangle, org.lwjgl.util.WritableDimension, org.lwjgl.util.WritablePoint, org.lwjgl.util.ReadableRectangle, org.lwjgl.util.ReadablePoint, org.lwjgl.util.ReadableDimension
Imports
java.io.Serializable

A 2D integer Rectangle class which looks remarkably like an AWT one.
Author
$Author$
Version
$Revision$ $Id$

Field Summary

Modifier and TypeField and Description
private int
height

Rectangle's bounds

pack-priv static final long
private int
width

Rectangle's bounds

private int
x

Rectangle's bounds

private int
y

Rectangle's bounds

Constructor Summary

AccessConstructor and Description
public
Rectangle()

Constructor for Rectangle.

public
Rectangle(int x, int y, int w, int h)

Constructor for Rectangle.

public
Rectangle(ReadablePoint p, ReadableDimension d)

Constructor for Rectangle.

public
Rectangle(ReadableRectangle r)

Constructor for Rectangle.

Method Summary

Modifier and TypeMethod and Description
public void
add(int
the x coordinates of the new point
newx
,
int
the y coordinates of the new point
newy
)

Adds a point, specified by the integer arguments newx and newy, to this Rectangle.

public void
add(ReadablePoint
the new Point to add to this Rectangle
pt
)

Adds the specified Point to this Rectangle.

public void
add(ReadableRectangle
the specified Rectangle
r
)

Adds a Rectangle to this Rectangle.

public boolean

Returns:

true if the Point (x, y) is inside this Rectangle; false otherwise.
contains
(ReadablePoint
the Point to test
p
)

Checks whether or not this Rectangle contains the specified Point.

public boolean

Returns:

true if the point (x, y) is inside this Rectangle; false otherwise.
contains
(int
the specified x coordinate
X
,
int
the specified y coordinate
Y
)

Checks whether or not this Rectangle contains the point at the specified location (x, y).

public boolean

Returns:

true if the Rectangle is contained entirely inside this Rectangle; false otherwise.
contains
(ReadableRectangle
the specified Rectangle
r
)

Checks whether or not this Rectangle entirely contains the specified Rectangle.

public boolean

Returns:

true if the Rectangle specified by (X, Y, W, H) is entirely enclosed inside this Rectangle; false otherwise.
contains
(int
the specified x coordinate
X
,
int
the specified y coordinate
Y
,
int
the width of the Rectangle
W
,
int
the height of the Rectangle
H
)

Checks whether this Rectangle entirely contains the Rectangle at the specified location (X, Y) with the specified dimensions (W, H).

public boolean

Returns:

true if the objects are equal; false otherwise.
equals
(Object
the Object to compare with this Rectangle
obj
)

Overrides java.lang.Object.equals.

Checks whether two rectangles are equal.
public void
getBounds(WritableRectangle
The destination Rectangle, or null, to create a new Rectangle
dest
)

Implements org.lwjgl.util.ReadableRectangle.getBounds.

Copy this readable rectangle's bounds into a destination Rectangle
public int

Returns:

Returns a int
getHeight
()

Implements org.lwjgl.util.ReadableDimension.getHeight.

Gets the height.
public void
getLocation(WritablePoint
The destination Point, or null, to create a new Point
dest
)

Implements org.lwjgl.util.ReadablePoint.getLocation.

Copy this ReadablePoint into a destination Point
public void
getSize(WritableDimension
The destination
dest
)

Implements org.lwjgl.util.ReadableDimension.getSize.

Copy this ReadableDimension into a destination Dimension
public int

Returns:

Returns a int
getWidth
()

Implements org.lwjgl.util.ReadableDimension.getWidth.

Gets the width.
public int

Returns:

Returns a int
getX
()

Implements org.lwjgl.util.ReadablePoint.getX.

Gets the x.
public int

Returns:

Returns a int
getY
()

Implements org.lwjgl.util.ReadablePoint.getY.

Gets the y.
public void
grow(int
the horizontal expansion
h
,
int
the vertical expansion
v
)

Resizes the Rectangle both horizontally and vertically.

public Rectangle

Returns:

the largest Rectangle contained in both the specified Rectangle and in this Rectangle; or if the rectangles do not intersect, an empty rectangle.
intersection
(ReadableRectangle
the specified Rectangle
r
,
Rectangle dest)

Computes the intersection of this Rectangle with the specified Rectangle.

public boolean

Returns:

true if the specified Rectangle and this Rectangle intersect; false otherwise.
intersects
(ReadableRectangle
the specified Rectangle
r
)

Determines whether or not this Rectangle and the specified Rectangle intersect.

public boolean

Returns:

true if this Rectangle is empty; false otherwise.
isEmpty
()

Determines whether or not this Rectangle is empty.

public void
setBounds(int
Position of rectangle on x axis
x
,
int
Position of rectangle on y axis
y
,
int
Width of rectangle
w
,
int
Height of rectangle
h
)

Implements org.lwjgl.util.WritableRectangle.setBounds.

Sets the bounds of the rectangle
public void
setBounds(ReadablePoint p, ReadableDimension d)

Implements org.lwjgl.util.WritableRectangle.setBounds.

Sets the bounds of the rectangle
public void
setBounds(ReadableRectangle r)

Implements org.lwjgl.util.WritableRectangle.setBounds.

Sets the bounds of the rectangle
public void
setHeight(int
The height to set
height
)

Implements org.lwjgl.util.WritableDimension.setHeight.

Sets the height.
public void
public void
public void
public void
public void
setWidth(int
The width to set
width
)

Implements org.lwjgl.util.WritableDimension.setWidth.

Sets the width.
public void
setX(int
The x to set
x
)

Implements org.lwjgl.util.WritablePoint.setX.

Sets the x.
public void
setY(int
The y to set
y
)

Implements org.lwjgl.util.WritablePoint.setY.

Sets the y.
public String

Returns:

a String
toString
()

Overrides java.lang.Object.toString.

Debugging
public void
translate(int
The translation amount on the x axis
x
,
int
The translation amount on the y axis
y
)

Translate the rectangle by an amount.

public void
translate(ReadablePoint
The translation amount
point
)

Translate the rectangle by an amount.

public WritableRectangle

Returns:

the smallest Rectangle containing both the specified Rectangle and this Rectangle.
union
(ReadableRectangle
the specified Rectangle
r
,
WritableRectangle dest)

Computes the union of this Rectangle with the specified Rectangle.

public void
untranslate(ReadablePoint
The translation amount
point
)

Un-translate the rectangle by an amount.

Inherited from java.lang.Object:
clonefinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

heightback to summary
private int height

Rectangle's bounds

serialVersionUIDback to summary
pack-priv static final long serialVersionUID
widthback to summary
private int width

Rectangle's bounds

xback to summary
private int x

Rectangle's bounds

yback to summary
private int y

Rectangle's bounds

Constructor Detail

Rectangleback to summary
public Rectangle()

Constructor for Rectangle.

Rectangleback to summary
public Rectangle(int x, int y, int w, int h)

Constructor for Rectangle.

Rectangleback to summary
public Rectangle(ReadablePoint p, ReadableDimension d)

Constructor for Rectangle.

Rectangleback to summary
public Rectangle(ReadableRectangle r)

Constructor for Rectangle.

Method Detail

addback to summary
public void add(int newx, int newy)

Adds a point, specified by the integer arguments 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.

Parameters
newx:int

the x coordinates of the new point

newy:int

the y coordinates of the new point

addback to summary
public void add(ReadablePoint pt)

Adds the specified 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.

Parameters
pt:ReadablePoint

the new Point to add to this Rectangle

addback to summary
public void add(ReadableRectangle r)

Adds a Rectangle to this Rectangle. The resulting Rectangle is the union of the two rectangles.

Parameters
r:ReadableRectangle

the specified Rectangle

containsback to summary
public boolean contains(ReadablePoint p)

Checks whether or not this Rectangle contains the specified Point.

Parameters
p:ReadablePoint

the Point to test

Returns:boolean

true if the Point (x, y) is inside this Rectangle; false otherwise.

containsback to summary
public boolean contains(int X, int Y)

Checks whether or not this Rectangle contains the point at the specified location (x, y).

Parameters
X:int

the specified x coordinate

Y:int

the specified y coordinate

Returns:boolean

true if the point (x, y) is inside this Rectangle; false otherwise.

containsback to summary
public boolean contains(ReadableRectangle r)

Checks whether or not this Rectangle entirely contains the specified Rectangle.

Parameters
r:ReadableRectangle

the specified Rectangle

Returns:boolean

true if the Rectangle is contained entirely inside this Rectangle; false otherwise.

containsback to summary
public 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).

Parameters
X:int

the specified x coordinate

Y:int

the specified y coordinate

W:int

the width of the Rectangle

H:int

the height of the Rectangle

Returns:boolean

true if the Rectangle specified by (X, Y, W, H) is entirely enclosed inside this Rectangle; false otherwise.

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Checks whether two rectangles are equal.

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.

Parameters
obj:Object

the Object to compare with this Rectangle

Returns:boolean

true if the objects are equal; false otherwise.

getBoundsback to summary
public void getBounds(WritableRectangle dest)

Implements org.lwjgl.util.ReadableRectangle.getBounds.

Doc from org.lwjgl.util.ReadableRectangle.getBounds.

Copy this readable rectangle's bounds into a destination Rectangle

Parameters
dest:WritableRectangle

The destination Rectangle, or null, to create a new Rectangle

getHeightback to summary
public int getHeight()

Implements org.lwjgl.util.ReadableDimension.getHeight.

Gets the height.

Returns:int

Returns a int

getLocationback to summary
public void getLocation(WritablePoint dest)

Implements org.lwjgl.util.ReadablePoint.getLocation.

Doc from org.lwjgl.util.ReadablePoint.getLocation.

Copy this ReadablePoint into a destination Point

Parameters
dest:WritablePoint

The destination Point, or null, to create a new Point

getSizeback to summary
public void getSize(WritableDimension dest)

Implements org.lwjgl.util.ReadableDimension.getSize.

Doc from org.lwjgl.util.ReadableDimension.getSize.

Copy this ReadableDimension into a destination Dimension

Parameters
dest:WritableDimension

The destination

getWidthback to summary
public int getWidth()

Implements org.lwjgl.util.ReadableDimension.getWidth.

Gets the width.

Returns:int

Returns a int

getXback to summary
public int getX()

Implements org.lwjgl.util.ReadablePoint.getX.

Gets the x.

Returns:int

Returns a int

getYback to summary
public int getY()

Implements org.lwjgl.util.ReadablePoint.getY.

Gets the y.

Returns:int

Returns a int

growback to summary
public void grow(int h, int v)

Resizes the 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.

Parameters
h:int

the horizontal expansion

v:int

the vertical expansion

intersectionback to summary
public Rectangle intersection(ReadableRectangle r, Rectangle dest)

Computes the intersection of this 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.

Parameters
r:ReadableRectangle

the specified Rectangle

Returns:Rectangle

the largest Rectangle contained in both the specified Rectangle and in this Rectangle; or if the rectangles do not intersect, an empty rectangle.

intersectsback to summary
public boolean intersects(ReadableRectangle r)

Determines whether or not this Rectangle and the specified Rectangle intersect. Two rectangles intersect if their intersection is nonempty.

Parameters
r:ReadableRectangle

the specified Rectangle

Returns:boolean

true if the specified Rectangle and this Rectangle intersect; false otherwise.

isEmptyback to summary
public boolean isEmpty()

Determines whether or not this Rectangle is empty. A Rectangle is empty if its width or its height is less than or equal to zero.

Returns:boolean

true if this Rectangle is empty; false otherwise.

setBoundsback to summary
public void setBounds(int x, int y, int w, int h)

Implements org.lwjgl.util.WritableRectangle.setBounds.

Doc from org.lwjgl.util.WritableRectangle.setBounds.

Sets the bounds of the rectangle

Parameters
x:int

Position of rectangle on x axis

y:int

Position of rectangle on y axis

w:int

Width of rectangle

h:int

Height of rectangle

setBoundsback to summary
public void setBounds(ReadablePoint p, ReadableDimension d)

Implements org.lwjgl.util.WritableRectangle.setBounds.

Doc from org.lwjgl.util.WritableRectangle.setBounds.

Sets the bounds of the rectangle

setBoundsback to summary
public void setBounds(ReadableRectangle r)

Implements org.lwjgl.util.WritableRectangle.setBounds.

Doc from org.lwjgl.util.WritableRectangle.setBounds.

Sets the bounds of the rectangle

setHeightback to summary
public void setHeight(int height)

Implements org.lwjgl.util.WritableDimension.setHeight.

Sets the height.

Parameters
height:int

The height to set

setLocationback to summary
public void setLocation(int x, int y)

Implements org.lwjgl.util.WritablePoint.setLocation.

setLocationback to summary
public void setLocation(ReadablePoint p)

Implements org.lwjgl.util.WritablePoint.setLocation.

setSizeback to summary
public void setSize(int w, int h)

Implements org.lwjgl.util.WritableDimension.setSize.

setSizeback to summary
public void setSize(ReadableDimension d)

Implements org.lwjgl.util.WritableDimension.setSize.

setWidthback to summary
public void setWidth(int width)

Implements org.lwjgl.util.WritableDimension.setWidth.

Sets the width.

Parameters
width:int

The width to set

setXback to summary
public void setX(int x)

Implements org.lwjgl.util.WritablePoint.setX.

Sets the x.

Parameters
x:int

The x to set

setYback to summary
public void setY(int y)

Implements org.lwjgl.util.WritablePoint.setY.

Sets the y.

Parameters
y:int

The y to set

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Debugging

Returns:String

a String

translateback to summary
public void translate(int x, int y)

Translate the rectangle by an amount.

Parameters
x:int

The translation amount on the x axis

y:int

The translation amount on the y axis

translateback to summary
public void translate(ReadablePoint point)

Translate the rectangle by an amount.

Parameters
point:ReadablePoint

The translation amount

unionback to summary
public WritableRectangle union(ReadableRectangle r, WritableRectangle dest)

Computes the union of this Rectangle with the specified Rectangle. Returns a new Rectangle that represents the union of the two rectangles

Parameters
r:ReadableRectangle

the specified Rectangle

Returns:WritableRectangle

the smallest Rectangle containing both the specified Rectangle and this Rectangle.

untranslateback to summary
public void untranslate(ReadablePoint point)

Un-translate the rectangle by an amount.

Parameters
point:ReadablePoint

The translation amount