com.infomatiq.jsi
Class Rectangle

java.lang.Object
  |
  +--com.infomatiq.jsi.Rectangle

public class Rectangle
extends java.lang.Object

Currently hardcoded to 2 dimensions, but could be extended.

Version:
1.0b1
Author:
aled.morris@infomatiq.co.uk

Field Summary
static int DIMENSIONS
          Number of dimensions in a rectangle.
 float[] max
          array containing the minimum value for each dimension; ie { min(x), min(y) }
 float[] min
          array containing the maximum value for each dimension; ie { max(x), max(y) }
 
Constructor Summary
Rectangle(float[] min, float[] max)
          Constructor.
Rectangle(float x1, float y1, float x2, float y2)
          Constructor.
 
Method Summary
 void add(Rectangle r)
          Computes the union of this rectangle and the passed rectangle, storing the result in this rectangle.
 float area()
          Compute the area of this rectangle.
 boolean containedBy(Rectangle r)
          Determine whether this rectangle is contained by the passed rectangle
 boolean contains(Rectangle r)
          Determine whether this rectangle contains the passed rectangle
 Rectangle copy()
          Make a copy of this rectangle
 float distance(Point p)
          Return the distance between this rectangle and the passed point.
 float distance(Rectangle r)
          Return the distance between this rectangle and the passed rectangle.
 boolean edgeOverlaps(Rectangle r)
          Determine whether an edge of this rectangle overlies the equivalent edge of the passed rectangle
 float enlargement(Rectangle r)
          Calculate the area by which this rectangle would be enlarged if added to the passed rectangle.
 boolean equals(java.lang.Object o)
          Determine whether this rectangle is equal to a given object.
 float furthestDistance(Rectangle r)
          Return the furthst possible distance between this rectangle and the passed rectangle.
 boolean intersects(Rectangle r)
          Determine whether this rectangle intersects the passed rectangle
 boolean sameObject(java.lang.Object o)
          Determine whether this rectangle is the same as another object Note that two rectangles can be equal but not the same object, if they both have the same bounds.
 void set(float[] min, float[] max)
          Sets the size of the rectangle.
 void set(float x1, float y1, float x2, float y2)
          Sets the size of the rectangle.
 java.lang.String toString()
          Return a string representation of this rectangle, in the form: (1.2, 3.4), (5.6, 7.8)
 Rectangle union(Rectangle r)
          Find the the union of this rectangle and the passed rectangle.
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DIMENSIONS

public static final int DIMENSIONS
Number of dimensions in a rectangle. In theory this could be exended to three or more dimensions.

See Also:
Constant Field Values

max

public float[] max
array containing the minimum value for each dimension; ie { min(x), min(y) }


min

public float[] min
array containing the maximum value for each dimension; ie { max(x), max(y) }

Constructor Detail

Rectangle

public Rectangle(float x1,
                 float y1,
                 float x2,
                 float y2)
Constructor.

Parameters:
x1 - coordinate of any corner of the rectangle
y1 - (see x1)
x2 - coordinate of the opposite corner
y2 - (see x2)

Rectangle

public Rectangle(float[] min,
                 float[] max)
Constructor.

Parameters:
min - array containing the minimum value for each dimension; ie { min(x), min(y) }
max - array containing the maximum value for each dimension; ie { max(x), max(y) }
Method Detail

set

public void set(float x1,
                float y1,
                float x2,
                float y2)
Sets the size of the rectangle.

Parameters:
x1 - coordinate of any corner of the rectangle
y1 - (see x1)
x2 - coordinate of the opposite corner
y2 - (see x2)

set

public void set(float[] min,
                float[] max)
Sets the size of the rectangle.

Parameters:
min - array containing the minimum value for each dimension; ie { min(x), min(y) }
max - array containing the maximum value for each dimension; ie { max(x), max(y) }

copy

public Rectangle copy()
Make a copy of this rectangle

Returns:
copy of this rectangle

edgeOverlaps

public boolean edgeOverlaps(Rectangle r)
Determine whether an edge of this rectangle overlies the equivalent edge of the passed rectangle


intersects

public boolean intersects(Rectangle r)
Determine whether this rectangle intersects the passed rectangle

Parameters:
r - The rectangle that might intersect this rectangle
Returns:
true if the rectangles intersect, false if they do not intersect

contains

public boolean contains(Rectangle r)
Determine whether this rectangle contains the passed rectangle

Parameters:
r - The rectangle that might be contained by this rectangle
Returns:
true if this rectangle contains the passed rectangle, false if it does not

containedBy

public boolean containedBy(Rectangle r)
Determine whether this rectangle is contained by the passed rectangle

Parameters:
r - The rectangle that might contain this rectangle
Returns:
true if the passed rectangle contains this rectangle, false if it does not

distance

public float distance(Point p)
Return the distance between this rectangle and the passed point. If the rectangle contains the point, the distance is zero.

Parameters:
p - Point to find the distance to
Returns:
distance beween this rectangle and the passed point.

distance

public float distance(Rectangle r)
Return the distance between this rectangle and the passed rectangle. If the rectangles overlap, the distance is zero.

Parameters:
r - Rectangle to find the distance to
Returns:
distance between this rectangle and the passed rectangle

furthestDistance

public float furthestDistance(Rectangle r)
Return the furthst possible distance between this rectangle and the passed rectangle. Find the distance between this rectangle and each corner of the passed rectangle, and use the maximum.


enlargement

public float enlargement(Rectangle r)
Calculate the area by which this rectangle would be enlarged if added to the passed rectangle. Neither rectangle is altered.

Parameters:
r - Rectangle to union with this rectangle, in order to compute the difference in area of the union and the original rectangle

area

public float area()
Compute the area of this rectangle.

Returns:
The area of this rectangle

add

public void add(Rectangle r)
Computes the union of this rectangle and the passed rectangle, storing the result in this rectangle.

Parameters:
r - Rectangle to add to this rectangle

union

public Rectangle union(Rectangle r)
Find the the union of this rectangle and the passed rectangle. Neither rectangle is altered

Parameters:
r - The rectangle to union with this rectangle

equals

public boolean equals(java.lang.Object o)
Determine whether this rectangle is equal to a given object. Equality is determined by the bounds of the rectangle.

Overrides:
equals in class java.lang.Object

sameObject

public boolean sameObject(java.lang.Object o)
Determine whether this rectangle is the same as another object Note that two rectangles can be equal but not the same object, if they both have the same bounds.

Parameters:
o - The object to compare with this rectangle.

toString

public java.lang.String toString()
Return a string representation of this rectangle, in the form: (1.2, 3.4), (5.6, 7.8)

Overrides:
toString in class java.lang.Object
Returns:
String String representation of this rectangle.