MATES 3.0-rc2

org.mates.util
Class BoundingBox

java.lang.Object
  extended byorg.mates.util.Bounds
      extended byorg.mates.util.BoundingBox

public class BoundingBox
extends Bounds

Class for defining the bounds on a rectangle in 2D Euclidean space.

Author:
Evan Sultanik
See Also:
Position

Constructor Summary
BoundingBox(double width, double height)
          Creates a new BoundingBox with a lower-left corner at the origin (0, 0) and an upper-right corner at (width, height).
BoundingBox(Position2D lowerLeft, Position2D upperRight)
          Creates a new BoundingBox by defining its lower-left corner and its upper-right corner.
 
Method Summary
 Position closestValidPosition(Position position)
          Returns the closest Position2D to position that is within these bounds.
 boolean contains(Position position)
          Returns true if the region defined by the bounds contains position.
 double getHeight()
          Returns the height of this bounding box.
 Position2D getLowerLeft()
          Returns the lower-left corner of the bounding box;
 Position2D getUpperRight()
          Returns the upper-right corner of the bounding box.
 double getWidth()
          Returns the width of this bounding box.
 void setLowerLeft(Position2D lowerLeft)
          Sets the lower-left corner of the bounding box.
 void setUpperRight(Position2D upperRight)
          Sets the upper-right corner of the bounding box.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BoundingBox

public BoundingBox(Position2D lowerLeft,
                   Position2D upperRight)
Creates a new BoundingBox by defining its lower-left corner and its upper-right corner.

Throws:
java.lang.IllegalArgumentException - if lowerLeft is either further to the right than or higher than upperRight.

BoundingBox

public BoundingBox(double width,
                   double height)
Creates a new BoundingBox with a lower-left corner at the origin (0, 0) and an upper-right corner at (width, height).

Throws:
java.lang.IllegalArgumentException - if either width or height is non-positive.
Method Detail

getUpperRight

public Position2D getUpperRight()
Returns the upper-right corner of the bounding box.


getLowerLeft

public Position2D getLowerLeft()
Returns the lower-left corner of the bounding box;


setUpperRight

public void setUpperRight(Position2D upperRight)
Sets the upper-right corner of the bounding box.


setLowerLeft

public void setLowerLeft(Position2D lowerLeft)
Sets the lower-left corner of the bounding box.


getWidth

public double getWidth()
Returns the width of this bounding box.


getHeight

public double getHeight()
Returns the height of this bounding box.


contains

public boolean contains(Position position)
Description copied from class: Bounds
Returns true if the region defined by the bounds contains position. The default implementation of this function always returns true.

Overrides:
contains in class Bounds

toString

public java.lang.String toString()

closestValidPosition

public Position closestValidPosition(Position position)
Returns the closest Position2D to position that is within these bounds. If position is within the bounds, itself will be returned (un-cloned). If position is not instanceof Position2D, null is returned.

Overrides:
closestValidPosition in class Bounds

MATES 3.0-rc2

Submit a bug or request a feature
http://mates.sourceforge.net/

Copyright 2004 Evan Sultanik