view
Class Surrounding

java.lang.Object
  extended by view.Surrounding

public class Surrounding
extends java.lang.Object

Class Surrounding describes surrounding boxes for 2D geometries. This box is defined in terms of X coordinate of the left/right edge and Y coordinate of the top/bottom edge.


Field Summary
protected  int maxx
           
protected  int maxy
           
protected  int minx
           
protected  int miny
           
 
Constructor Summary
Surrounding()
          Constructs a surrounding rectangle for a point at 0, 0
Surrounding(int aMinx, int aMiny, int aMaxx, int aMaxy)
          Constructs a surrounding box defined by the left, top, right, bottom edge
Surrounding(java.awt.Point center, int size)
          Constructs a surrounding square whose the given 2D point is the center
Surrounding(java.awt.Point center, int width, int height)
          Constructs a surrounding rectangle whose the given 2D point is the center
Surrounding(Surrounding another)
          Copy constructor
 
Method Summary
 int bottom()
          getter
 boolean contains(java.awt.Point p)
          Tests if the given 2D point is inside this box
 java.awt.Point getCenterPoint()
          Calculates the center of this box by calling getCenterX() and getCenterY()
 int getCenterX()
          Calculates the X coordinate of the center of this box
 int getCenterY()
          Calculates the Y coordinate of the center of this box
 void grow(int gw, int gh)
          Grows this box by the given extents
 void growBottom(int d)
          Grows this box towards the bottom edge by the given extent
 void growLeft(int d)
          Grows this box towards the left edge by the given extent
 void growRight(int d)
          Grows this box towards the right edge by the given extent
 void growTop(int d)
          Grows this box towards the top edge by the given extent
 int height()
          Calculates the height of this box
 boolean isWithin(Surrounding another)
          Tests if the given box is completely within this box
 int left()
          getter
 int right()
          getter
 int top()
          getter
 int width()
          Calculates the width of this box
 void wrap(java.awt.Point p)
          Grows this box if neccessary to wrap the given 2D point
 void wrap(Surrounding another, int leftD, int topD, int rightD, int bottomD)
          Grows this box if neccessary to wrap the given box by the given extents
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

minx

protected int minx

maxx

protected int maxx

miny

protected int miny

maxy

protected int maxy
Constructor Detail

Surrounding

public Surrounding()
Constructs a surrounding rectangle for a point at 0, 0


Surrounding

public Surrounding(java.awt.Point center,
                   int size)
Constructs a surrounding square whose the given 2D point is the center

Parameters:
center - center of the surrounding square to construct
size - size of the surrounding square to construct

Surrounding

public Surrounding(java.awt.Point center,
                   int width,
                   int height)
Constructs a surrounding rectangle whose the given 2D point is the center

Parameters:
center - center of the surrounding square to construct
width - width of the surrounding rectangle to construct
height - height of the surrounding rectangle to construct

Surrounding

public Surrounding(Surrounding another)
Copy constructor

Parameters:
another - another surrounding box

Surrounding

public Surrounding(int aMinx,
                   int aMiny,
                   int aMaxx,
                   int aMaxy)
Constructs a surrounding box defined by the left, top, right, bottom edge

Parameters:
aMinx - X coordinate of the left edge
aMiny - Y coordinate of the top edge
aMaxx - X coordinate of the right edge
aMaxy - Y coordinate of the bottom edge
Method Detail

isWithin

public boolean isWithin(Surrounding another)
Tests if the given box is completely within this box

Parameters:
another - a surrounding box to test
Returns:
true if another is completely within this box, false otherwise

contains

public boolean contains(java.awt.Point p)
Tests if the given 2D point is inside this box

Parameters:
p - a 2D point
Returns:
true if p is inside this box, false otherwise

wrap

public void wrap(Surrounding another,
                 int leftD,
                 int topD,
                 int rightD,
                 int bottomD)
Grows this box if neccessary to wrap the given box by the given extents

Parameters:
another - a box to be wrapped
leftD - the distance to the left edge
topD - the distance to the top edge
rightD - the distance to the right edge
bottomD - the distance to the bottom edge

wrap

public void wrap(java.awt.Point p)
Grows this box if neccessary to wrap the given 2D point

Parameters:
p - a 2D point to be wrapped

width

public int width()
Calculates the width of this box

Returns:
the width of this box

height

public int height()
Calculates the height of this box

Returns:
the height of this box

left

public int left()
getter

Returns:
X coordinate of the left edge

top

public int top()
getter

Returns:
Y coordinate of the top edge

right

public int right()
getter

Returns:
X coordinate of the right edge

bottom

public int bottom()
getter

Returns:
Y coordinate of the bottom edge

getCenterX

public int getCenterX()
Calculates the X coordinate of the center of this box

Returns:
X coordinate of the center of this box
See Also:
getCenterY(), getCenterPoint()

getCenterY

public int getCenterY()
Calculates the Y coordinate of the center of this box

Returns:
Y coordinate of the center of this box
See Also:
getCenterX(), getCenterPoint()

getCenterPoint

public java.awt.Point getCenterPoint()
Calculates the center of this box by calling getCenterX() and getCenterY()

Returns:
center point of this box
See Also:
getCenterX(), getCenterY()

grow

public void grow(int gw,
                 int gh)
Grows this box by the given extents

Parameters:
gw - horizontal extent
gh - vertical extent

growLeft

public void growLeft(int d)
Grows this box towards the left edge by the given extent

Parameters:
d - horizontal extent

growRight

public void growRight(int d)
Grows this box towards the right edge by the given extent

Parameters:
d - horizontal extent

growTop

public void growTop(int d)
Grows this box towards the top edge by the given extent

Parameters:
d - vertical extent

growBottom

public void growBottom(int d)
Grows this box towards the bottom edge by the given extent

Parameters:
d - vertical extent