spatial
Class MBR

java.lang.Object
  |
  +--spatial.MBR

public class MBR
extends java.lang.Object

An n-dimensional minimum bounding rectangle.


Field Summary
static int DEPTH
          The depth dimension.
static int HEIGHT
          The height dimension.
protected static int[] P2
          Array of 2^i.
static int WIDTH
          The width dimension.
static int X
          The x dimension.
static int Y
          The y dimension.
static int Z
          The z dimension.
 
Constructor Summary
MBR(int d)
          Constructs a new rectangle with the specified dimension.
MBR(int[] coords)
          Constructor of a MBR from a multi-dimensional point.
MBR(int[] coords, int[] exts)
          Constructor of a MBR from a multi-dimensional point and an extension array.
MBR(int x, int width)
          Constructor of a one-dimensional interval.
MBR(int x, int y, int width, int height)
          Constructor of a two-dimensional MBR.
MBR(int x, int y, int z, int width, int height, int depth)
          Constructor of a three-dimensional quader.
MBR(java.awt.Point p)
          Constructor of a two-dimensional MBR from a point.
MBR(java.awt.Rectangle r)
          Constructor of a two-dimensional MBR.
 
Method Summary
 void add(int[] point)
          Adds a specified point to this MBR.
 void add(MBR r)
          Adds a specified MBR to this MBR.
 int center(int d)
          Returns the center coordinate of the specified dimension.
 java.lang.Object clone()
          Creates a clone of this object.
static MBR clone(MBR r)
          Creates a clone of a spefied MBR.
 double computeBorder()
          Computes the border of the MBR.
 double computeVolume()
          Computes the volume of the MBR.
 boolean contains(int[] point)
          Checks whether this MBR contains the specified point.
 boolean contains(int[] point, int tolerance)
          Checks whether this MBR contains the specified point with a given tolerance.
 boolean contains(MBR r)
          Determines whether this MBR contains the specified MBR.
 boolean contains(MBR r, int tolerance)
          Determines whether this MBR contains the specified MBR with a given tolerance.
 boolean equals(java.lang.Object obj)
          Checks whether two MBRs are equal.
 int extension(int d)
          Returns the extension of the specified dimension.
 java.awt.Rectangle extractRectangle(int dimX, int dimY)
          Extracts a rectangle representing the specified dimensions.
 int[] getCenterCoords()
          Returns the center coordinates.
 int[] getExtensions()
          Returns the extensions.
 int[] getMaxCoords()
          Returns the maximum coordinates.
 int[] getMinCoords()
          Returns the minimum coordinates.
 void grow(int[] values)
          Grows the MBR according to the specified values.
 MBR intersection(MBR r)
          Computes the intersection of this MBR with the specified MBR.
 double intersectionVolume(MBR r)
          Computes the volume of the intersection of this MBR with the specified MBR.
 boolean intersects(MBR r)
          Determines whether this MBR and the specified MBR intersect.
 boolean intersects(MBR r, int tolerance)
          Determines whether this MBR and the specified MBR intersect with a given tolerance.
 int max(int d)
          Returns the maximum coordinate of the specified dimension.
 int min(int d)
          Returns the minimum coordinate of the specified dimension.
 int numOfDimensions()
          Returns the number of dimensions.
 long quadDistanceFromCenter(int[] point)
          Returns the quadratic distance from the center of the MBR to the specified point.
 void setBounds(int[] coords, int[] extensions)
          Sets this MBR to the specified coordinates and extensions.
 void setBounds(int x, int width)
          Sets this MBR to the specified interval.
 void setBounds(int x, int y, int width, int height)
          Sets this MBR to the specified 2D-MBR.
 void setBounds(int x, int y, int z, int width, int height, int depth)
          Sets this MBR to the specified 3D-MBR.
 void setBounds(MBR r)
          Sets this MBR to the specified MBR.
 MBR setBoundsByPoints(int[] p1, int[] p2)
          Sets this MBR to the specified points.
 void setExtension(int d, int value)
          Sets the extension of the specified dimension.
 void setLocation(int[] coords)
          Moves the MBR to the specified location.
 void setMin(int d, int value)
          Sets the minimum coordinate of the specified dimension.
 void setSize(int[] extensions)
          Sets the size of this MBR to match the specified extensions.
 java.lang.String toString()
          Returns the string represenation of the mbr.
 void translate(int[] values)
          Translates the MBR according to the specified values.
 MBR union(MBR r)
          Computes the union of this MBR with the specified MBR.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

X

public static final int X
The x dimension.

See Also:
Constant Field Values

Y

public static final int Y
The y dimension.

See Also:
Constant Field Values

Z

public static final int Z
The z dimension.

See Also:
Constant Field Values

WIDTH

public static final int WIDTH
The width dimension.

See Also:
Constant Field Values

HEIGHT

public static final int HEIGHT
The height dimension.

See Also:
Constant Field Values

DEPTH

public static final int DEPTH
The depth dimension.

See Also:
Constant Field Values

P2

protected static final int[] P2
Array of 2^i.

Constructor Detail

MBR

public MBR(int[] coords)
Constructor of a MBR from a multi-dimensional point.

Parameters:
coords - the coordinates of the point

MBR

public MBR(int[] coords,
           int[] exts)
Constructor of a MBR from a multi-dimensional point and an extension array.

Parameters:
coords - the coordinates of the point
exts - the extensions

MBR

public MBR(int d)
Constructs a new rectangle with the specified dimension.


MBR

public MBR(int x,
           int width)
Constructor of a one-dimensional interval.

Parameters:
x - the mininum coordinate
width - the length of the interval

MBR

public MBR(int x,
           int y,
           int width,
           int height)
Constructor of a two-dimensional MBR.

Parameters:
width - the width of the MBR
height - the height of the MBR

MBR

public MBR(int x,
           int y,
           int z,
           int width,
           int height,
           int depth)
Constructor of a three-dimensional quader.

Parameters:
width - the width of the MBR
height - the height of the MBR
depth - the depth of the MBR

MBR

public MBR(java.awt.Point p)
Constructor of a two-dimensional MBR from a point.

Parameters:
p - a point

MBR

public MBR(java.awt.Rectangle r)
Constructor of a two-dimensional MBR.

Parameters:
r - the rectangle
Method Detail

add

public void add(int[] point)
         throws java.lang.IllegalArgumentException
Adds a specified point to this MBR.

Parameters:
point - the additional point
java.lang.IllegalArgumentException

add

public void add(MBR r)
Adds a specified MBR to this MBR.

Parameters:
r - the additional MBR

center

public int center(int d)
           throws java.lang.IllegalArgumentException
Returns the center coordinate of the specified dimension.

Parameters:
d - the dimension (starts with 0)
Returns:
the center coordinate
Throws:
java.lang.IllegalArgumentException - If the dimension is too small or too large.

clone

public java.lang.Object clone()
Creates a clone of this object.

Overrides:
clone in class java.lang.Object
Returns:
the clone

clone

public static MBR clone(MBR r)
Creates a clone of a spefied MBR.

Returns:
the clone (or null if r == null)

computeBorder

public double computeBorder()
Computes the border of the MBR.

Returns:
the border

computeVolume

public double computeVolume()
Computes the volume of the MBR.

Returns:
the volume

contains

public boolean contains(int[] point)
Checks whether this MBR contains the specified point.

Parameters:
point - the point
Returns:
true if the point is inside this MBR; false otherwise.

contains

public boolean contains(int[] point,
                        int tolerance)
Checks whether this MBR contains the specified point with a given tolerance.

Parameters:
point - the point
tolerance - the tolerance
Returns:
true if the point is inside this MBR; false otherwise.

contains

public boolean contains(MBR r)
Determines whether this MBR contains the specified MBR.

Parameters:
r - the other MBR
Returns:
true if this MBR contains the other MBR; false otherwise

contains

public boolean contains(MBR r,
                        int tolerance)
Determines whether this MBR contains the specified MBR with a given tolerance.

Parameters:
r - the other MBR
tolerance - the tolerance
Returns:
true if this MBR contains the other MBR; false otherwise

equals

public boolean equals(java.lang.Object obj)
Checks whether two MBRs are equal.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the other object
Returns:
true if the objects are equal; false otherwise.

extension

public int extension(int d)
              throws java.lang.IllegalArgumentException
Returns the extension of the specified dimension.

Parameters:
d - the dimension (starts with 0)
Returns:
the extension
Throws:
java.lang.IllegalArgumentException - If the dimension is too small or too large.

extractRectangle

public java.awt.Rectangle extractRectangle(int dimX,
                                           int dimY)
                                    throws java.lang.IllegalArgumentException
Extracts a rectangle representing the specified dimensions.

Parameters:
dimX - the x dimension (starts with 0)
dimY - the y dimension (starts with 0)
Returns:
the rectangle
Throws:
java.lang.IllegalArgumentException - If the dimensions are too small or too large.

getCenterCoords

public int[] getCenterCoords()
Returns the center coordinates.

Returns:
the center coordinates

getExtensions

public int[] getExtensions()
Returns the extensions.

Returns:
the extensions

getMaxCoords

public int[] getMaxCoords()
Returns the maximum coordinates.

Returns:
the maximum coordinates

getMinCoords

public int[] getMinCoords()
Returns the minimum coordinates.

Returns:
the minimum coordinates

grow

public void grow(int[] values)
          throws java.lang.IllegalArgumentException
Grows the MBR according to the specified values. The grow method does not check whether the resulting extensions are non-negative.

Parameters:
values - the delta extensions
Throws:
java.lang.IllegalArgumentException - If array size is wrong.

intersection

public MBR intersection(MBR r)
Computes the intersection of this MBR with the specified MBR. Returns a new MBR that represents the intersection of the two MBRs.

Parameters:
r - the other MBR
Returns:
the resulting rectangle (or null)

intersectionVolume

public double intersectionVolume(MBR r)
Computes the volume of the intersection of this MBR with the specified MBR.

Parameters:
r - the other MBR
Returns:
the resulting volume (0 if the MBRs do not intersect)

intersects

public boolean intersects(MBR r)
Determines whether this MBR and the specified MBR intersect. Two MBRs intersect if their intersection is nonempty.

Parameters:
r - the other MBR
Returns:
true if the specified MBR and this MBR intersect; false otherwise

intersects

public boolean intersects(MBR r,
                          int tolerance)
Determines whether this MBR and the specified MBR intersect with a given tolerance. Two MBRs intersect if their intersection is nonempty.

Parameters:
r - the other MBR
tolerance - the tolerance
Returns:
true if the specified MBR and this MBR intersect; false otherwise

max

public int max(int d)
        throws java.lang.IllegalArgumentException
Returns the maximum coordinate of the specified dimension.

Parameters:
d - the dimension (starts with 0)
Returns:
the maximum coordinate
Throws:
java.lang.IllegalArgumentException - If the dimension is too small or too large.

min

public int min(int d)
        throws java.lang.IllegalArgumentException
Returns the minimum coordinate of the specified dimension.

Parameters:
d - the dimension (starts with 0)
Returns:
the minimum coordinate
Throws:
java.lang.IllegalArgumentException - If the dimension is too small or too large.

numOfDimensions

public int numOfDimensions()
Returns the number of dimensions.

Returns:
2

quadDistanceFromCenter

public long quadDistanceFromCenter(int[] point)
Returns the quadratic distance from the center of the MBR to the specified point.

Parameters:
point - the point
Returns:
the distance
Throws:
java.lang.IllegalArgumentException - If array size is wrong.

setBounds

public void setBounds(int[] coords,
                      int[] extensions)
               throws java.lang.IllegalArgumentException
Sets this MBR to the specified coordinates and extensions.

Parameters:
coords - the minimum coordinates
extensions - the extensions
Throws:
java.lang.IllegalArgumentException - If array sizes are wrong.

setBoundsByPoints

public MBR setBoundsByPoints(int[] p1,
                             int[] p2)
                      throws java.lang.IllegalArgumentException
Sets this MBR to the specified points.

Parameters:
p1 - one extreme point
p2 - the other extreme point
Returns:
this
Throws:
java.lang.IllegalArgumentException - If array sizes are wrong.

setBounds

public void setBounds(int x,
                      int width)
               throws java.lang.IllegalArgumentException
Sets this MBR to the specified interval.

Parameters:
x - the mininum coordinate
width - the length of the interval
Throws:
java.lang.IllegalArgumentException - If dimension is wrong.

setBounds

public void setBounds(int x,
                      int y,
                      int width,
                      int height)
               throws java.lang.IllegalArgumentException
Sets this MBR to the specified 2D-MBR.

Parameters:
width - the width of the MBR
height - the height of the MBR
Throws:
java.lang.IllegalArgumentException - If dimension is wrong.

setBounds

public void setBounds(int x,
                      int y,
                      int z,
                      int width,
                      int height,
                      int depth)
               throws java.lang.IllegalArgumentException
Sets this MBR to the specified 3D-MBR.

Parameters:
width - the width of the MBR
height - the height of the MBR
depth - the depth of the MBR
Throws:
java.lang.IllegalArgumentException - If dimension is wrong.

setBounds

public void setBounds(MBR r)
               throws java.lang.IllegalArgumentException
Sets this MBR to the specified MBR.

Parameters:
r - the bounds
Throws:
java.lang.IllegalArgumentException - If argument is wrong.

setExtension

public void setExtension(int d,
                         int value)
                  throws java.lang.IllegalArgumentException
Sets the extension of the specified dimension.

Parameters:
d - the dimension (starts with 0)
value - the new value of the extension
Throws:
java.lang.IllegalArgumentException - If the dimension is too small or too large.

setLocation

public void setLocation(int[] coords)
                 throws java.lang.IllegalArgumentException
Moves the MBR to the specified location.

Parameters:
coords - the minimum coordinates
Throws:
java.lang.IllegalArgumentException - If array size is wrong.

setMin

public void setMin(int d,
                   int value)
            throws java.lang.IllegalArgumentException
Sets the minimum coordinate of the specified dimension.

Parameters:
d - the dimension (starts with 0)
value - the new value of the minimum coordinate
Throws:
java.lang.IllegalArgumentException - If the dimension is too small or too large.

setSize

public void setSize(int[] extensions)
             throws java.lang.IllegalArgumentException
Sets the size of this MBR to match the specified extensions.

Parameters:
extensions - the extensions
Throws:
java.lang.IllegalArgumentException - If array size is wrong.

toString

public java.lang.String toString()
Returns the string represenation of the mbr.

Overrides:
toString in class java.lang.Object
Returns:
the string

translate

public void translate(int[] values)
               throws java.lang.IllegalArgumentException
Translates the MBR according to the specified values.

Parameters:
values - the delta coordinates
Throws:
java.lang.IllegalArgumentException - If array size is wrong.

union

public MBR union(MBR r)
Computes the union of this MBR with the specified MBR. Returns a new MBR that represents the union of the two MBRs.

Parameters:
r - the other MBR
Returns:
the resulting rectangle