org.newdawn.slick.geom
Class Rectangle

java.lang.Object
  extended by org.newdawn.slick.geom.Shape
      extended by org.newdawn.slick.geom.Rectangle
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
RoundedRectangle

public class Rectangle
extends Shape

An axis oriented used for shape bounds

Author:
Kevin Glass
See Also:
Serialized Form

Field Summary
protected  float height
          The height of the box
protected  float width
          The width of the box
 
Fields inherited from class org.newdawn.slick.geom.Shape
boundingCircleRadius, center, maxX, maxY, minX, minY, points, pointsDirty, trianglesDirty, tris, x, y
 
Constructor Summary
Rectangle(float x, float y, float width, float height)
          Create a new bounding box
 
Method Summary
 boolean contains(float xp, float yp)
          Check if this rectangle contains a point
static boolean contains(float xp, float yp, float xr, float yr, float widthr, float heightr)
          Check if a rectangle contains a point (static to use it everywhere)
protected  void createPoints()
          Subclasses implement this to create the points of the shape.
 float getHeight()
          Get the height of the box
 float getWidth()
          Get the width of the box
 void grow(float h, float v)
          Grow the rectangle at all edges by the given amounts.
 boolean intersects(Shape shape)
          Check if this box touches another
 void scaleGrow(float h, float v)
          Grow the rectangle based on scaling it's size
 void setBounds(float x, float y, float width, float height)
          Set the bounds of this rectangle
 void setBounds(Rectangle other)
          Set the bounds of this rectangle based on the given rectangle
 void setHeight(float height)
          Set the heightof this box
 void setSize(float width, float height)
          Set the size (widtha and height) of this rectangle
 void setWidth(float width)
          Set the width of this box
 java.lang.String toString()
           
 Shape transform(Transform transform)
          Apply a transformation and return a new shape.
 
Methods inherited from class org.newdawn.slick.geom.Shape
calculateRadius, calculateTriangles, checkPoints, closed, contains, findCenter, getBoundingCircleRadius, getCenter, getCenterX, getCenterY, getLocation, getMaxX, getMaxY, getMinX, getMinY, getNormal, getPoint, getPointCount, getPoints, getTriangles, getX, getY, hasVertex, includes, increaseTriangulation, indexOf, preCache, prune, setCenterX, setCenterY, setLocation, setLocation, setX, setY, subtract, union
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

width

protected float width
The width of the box


height

protected float height
The height of the box

Constructor Detail

Rectangle

public Rectangle(float x,
                 float y,
                 float width,
                 float height)
Create a new bounding box

Parameters:
x - The x position of the box
y - The y position of the box
width - The width of the box
height - The hieght of the box
Method Detail

contains

public boolean contains(float xp,
                        float yp)
Check if this rectangle contains a point

Overrides:
contains in class Shape
Parameters:
xp - The x coordinate of the point to check
yp - The y coordinate of the point to check
Returns:
True if the point is within the rectangle

setBounds

public void setBounds(Rectangle other)
Set the bounds of this rectangle based on the given rectangle

Parameters:
other - The other rectangle whose bounds should be applied

setBounds

public void setBounds(float x,
                      float y,
                      float width,
                      float height)
Set the bounds of this rectangle

Parameters:
x - The x coordinate of this rectangle
y - The y coordinate of this rectangle
width - The width to set in this rectangle
height - The height to set in this rectangle

setSize

public void setSize(float width,
                    float height)
Set the size (widtha and height) of this rectangle

Parameters:
width - The width to set in this rectangle
height - The height to set in this rectangle

getWidth

public float getWidth()
Get the width of the box

Overrides:
getWidth in class Shape
Returns:
The width of the box

getHeight

public float getHeight()
Get the height of the box

Overrides:
getHeight in class Shape
Returns:
The height of the box

grow

public void grow(float h,
                 float v)
Grow the rectangle at all edges by the given amounts. This will result in the rectangle getting larger around it's centre.

Parameters:
h - The amount to adjust horizontally
v - The amount to ajust vertically

scaleGrow

public void scaleGrow(float h,
                      float v)
Grow the rectangle based on scaling it's size

Parameters:
h - The scale to apply to the horizontal
v - The scale to appy to the vertical

setWidth

public void setWidth(float width)
Set the width of this box

Parameters:
width - The new width of this box

setHeight

public void setHeight(float height)
Set the heightof this box

Parameters:
height - The height of this box

intersects

public boolean intersects(Shape shape)
Check if this box touches another

Overrides:
intersects in class Shape
Parameters:
shape - The other shape to check against
Returns:
True if the rectangles touch

createPoints

protected void createPoints()
Description copied from class: Shape
Subclasses implement this to create the points of the shape.

Specified by:
createPoints in class Shape

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

contains

public static boolean contains(float xp,
                               float yp,
                               float xr,
                               float yr,
                               float widthr,
                               float heightr)
Check if a rectangle contains a point (static to use it everywhere)

Parameters:
xp - The x coordinate of the point to check
yp - The y coordinate of the point to check
xr - The x coordinate of the rectangle
yr - The y coordinate of the rectangle
widthr - The width of the rectangle
heightr - The height of the rectangle
Returns:
True if the point is within the rectangle

transform

public Shape transform(Transform transform)
Apply a transformation and return a new shape. This will not alter the current shape but will return the transformed shape.

Specified by:
transform in class Shape
Parameters:
transform - The transform to be applied
Returns:
The transformed shape.


Copyright © 2006 New Dawn Software. All Rights Reserved.