cs2110.collision
Class BoundingBox

java.lang.Object
  extended by cs2110.collision.BoundingBox

public class BoundingBox
extends java.lang.Object

An instance is a 2D bounding box.


Field Summary
 Vector2D lower
          The corner of the bounding box with the smaller x,y coordinates.
 Vector2D upper
          The corner of the bounding box with the larger x,y coordinates.
 
Constructor Summary
BoundingBox(BoundingBox b)
          Constructor: an instance is a copy of bounding box b.
BoundingBox(Vector2D lower, Vector2D upper)
          Constructor: An instance with lower as smaller coordinates and upper as larger coordinates.
 
Method Summary
 boolean contains(Vector2D p)
          Return true iff this bounding box contains p.
 BoundingBox displaced(Vector2D d)
          Return the result of displacing this bounding box by d.
static BoundingBox findBBox(java.util.Iterator<Block> iter)
          Return the bounding box of blocks given by iter.
 double getArea()
          Return the area of this bounding box.
 Vector2D getCenter()
          Return the center of this bounding box.
 double getHeight()
          Return the height of this bounding box (along y-dimension).
 double getLength()
          Return the larger of the width and height of this bounding box.
 double getWidth()
          Return the width of this bounding box (along x-dimension).
 boolean overlaps(BoundingBox box)
          Return true iff this bounding box overlaps with box.
 java.lang.String toString()
          Return a representation of this bounding box.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

lower

public Vector2D lower
The corner of the bounding box with the smaller x,y coordinates.


upper

public Vector2D upper
The corner of the bounding box with the larger x,y coordinates.

Constructor Detail

BoundingBox

public BoundingBox(BoundingBox b)
Constructor: an instance is a copy of bounding box b.


BoundingBox

public BoundingBox(Vector2D lower,
                   Vector2D upper)
Constructor: An instance with lower as smaller coordinates and upper as larger coordinates.

Parameters:
lower - Corner with smaller coordinates.
upper - Corner with larger coordinates.
Method Detail

getWidth

public double getWidth()
Return the width of this bounding box (along x-dimension).

Returns:
Width of this bounding box.

getHeight

public double getHeight()
Return the height of this bounding box (along y-dimension).

Returns:
Height of this bounding box.

getLength

public double getLength()
Return the larger of the width and height of this bounding box.

Returns:
Returns the dimension (width or height) of maximum length.

getCenter

public Vector2D getCenter()
Return the center of this bounding box.

Returns:
The center of this bounding box.

displaced

public BoundingBox displaced(Vector2D d)
Return the result of displacing this bounding box by d.

Parameters:
d - A displacement vector.
Returns:
The result of displacing this bounding box by vector d.

contains

public boolean contains(Vector2D p)
Return true iff this bounding box contains p.

Parameters:
p - A point.
Returns:
True iff this bounding box contains point p.

getArea

public double getArea()
Return the area of this bounding box.

Returns:
The area of this bounding box.

overlaps

public boolean overlaps(BoundingBox box)
Return true iff this bounding box overlaps with box.

Parameters:
box - A bounding box.
Returns:
True iff this bounding box overlaps with box.

findBBox

public static BoundingBox findBBox(java.util.Iterator<Block> iter)
Return the bounding box of blocks given by iter.

Parameters:
iter - An iterator of blocks.
Returns:
The bounding box of the blocks given by the iterator.

toString

public java.lang.String toString()
Return a representation of this bounding box.

Overrides:
toString in class java.lang.Object