Algorithm
Development Kit 1.0

algs.model.nd
Class Hypercube

java.lang.Object
  extended by algs.model.nd.Hypercube
All Implemented Interfaces:
IHypercube

public class Hypercube
extends java.lang.Object
implements IHypercube

Represents a Hypercube in the n-dimensional Cartesian plane. Note that it is an invariant that getLeft(d) ≤ getRight(d) for all dimensions d

Since:
1.0
Version:
1.0, 6/15/08
Author:
George Heineman

Constructor Summary
Hypercube(double[] lows, double[] highs)
          Construct an n-dimensional hypercube.
Hypercube(double xlow, double xhigh, double ylow, double yhigh)
          Convenience method to construct a 2-dimensional Hypercube from two points.
Hypercube(IHypercube cube)
          Fill in values for this hypercube drawn from the IHypercube parameter.
Hypercube(int dimension)
          Construct an n-dimensional hypercube with origin coordinates.
 
Method Summary
 boolean contains(IHypercube h)
          Determine if the hypercube wholly contains the given hypercube h.
 int dimensionality()
          Return the dimensionality of this hypercube.
 boolean equals(java.lang.Object o)
          Determine equality by comparing coordinates on each dimension
 double getLeft(int d)
          Return the left-coordinate in the given dimension.
 double getRight(int d)
          Return the right-coordinate in the given dimension.
 int hashCode()
          Meaningful hashcode function.
 boolean intersects(double[] rawPoint)
          Determine intersection among all point coordinates (in raw, optimized form).
 boolean intersects(IHypercube h)
          Determine if the hypercube intersects the given hypercube h.
 boolean intersects(IMultiPoint p)
          Determine intersection among all point coordinates.
 void setLeft(int d, double value)
          Set the left-coordinate in the given dimension.
 void setRight(int d, double value)
          Set the right-coordinate in the given dimension.
 java.lang.String toString()
          Reasonable toString method.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Hypercube

public Hypercube(int dimension)
Construct an n-dimensional hypercube with origin coordinates.

Parameters:
dimension - the number of dimensions of the hypercube.

Hypercube

public Hypercube(IHypercube cube)
Fill in values for this hypercube drawn from the IHypercube parameter.

Parameters:
cube - The existing IHypercube object that we are to mimic

Hypercube

public Hypercube(double[] lows,
                 double[] highs)
Construct an n-dimensional hypercube.

The dimensionality is assumed to be the length of either array.

Parameters:
lows - vector of low values
highs - vector of high values
Throws:
java.lang.IllegalArgumentException - if n is < 2 or if the arrays differ in length.

Hypercube

public Hypercube(double xlow,
                 double xhigh,
                 double ylow,
                 double yhigh)
Convenience method to construct a 2-dimensional Hypercube from two points.

Note that the order of these parameters is at odds with what would be found in RectangularRegion.

Parameters:
xlow - x-low coordinate of a 2d hypercube.
xhigh - x-high coordinate of a 2d hypercube.
ylow - y-low coordinate of a 2d hypercube.
yhigh - y-high coordinate of a 2d hypercube.
Method Detail

dimensionality

public int dimensionality()
Return the dimensionality of this hypercube.

Specified by:
dimensionality in interface IHypercube

getLeft

public double getLeft(int d)
Return the left-coordinate in the given dimension.

Specified by:
getLeft in interface IHypercube
Parameters:
d - Desired dimension

setLeft

public void setLeft(int d,
                    double value)
Set the left-coordinate in the given dimension.

Parameters:
d - Desired dimension
value - new value.

getRight

public double getRight(int d)
Return the right-coordinate in the given dimension.

Specified by:
getRight in interface IHypercube
Parameters:
d - Desired dimension.

setRight

public void setRight(int d,
                     double value)
Set the right-coordinate in the given dimension.

Parameters:
d - Desired dimension
value - new value.

hashCode

public int hashCode()
Meaningful hashcode function.

Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Determine equality by comparing coordinates on each dimension

Overrides:
equals in class java.lang.Object
See Also:
Object.equals(Object)

intersects

public boolean intersects(double[] rawPoint)
Determine intersection among all point coordinates (in raw, optimized form).

Specified by:
intersects in interface IHypercube
Parameters:
rawPoint - array of the coordinates of the target IMultiPoint

intersects

public boolean intersects(IMultiPoint p)
Determine intersection among all point coordinates.

Specified by:
intersects in interface IHypercube
Parameters:
p - check for intersection among all coordinate dimensions for this IMultiPoint.

contains

public boolean contains(IHypercube h)
                 throws java.lang.IllegalArgumentException
Determine if the hypercube wholly contains the given hypercube h.

The hypercube presents closed intervals on all dimensions. Note that if -INF or +INF is present, then we can take care to ensure proper containment even in face of boundless dimensions.

Specified by:
contains in interface IHypercube
Parameters:
h - query hypercube
Throws:
If - dimensions are not the same
java.lang.IllegalArgumentException

intersects

public boolean intersects(IHypercube h)
                   throws java.lang.IllegalArgumentException
Determine if the hypercube intersects the given hypercube h.

The hypercube presents closed intervals on all dimensions. Note that if -INF or +INF is present, then we can take care to ensure proper containment even in face of boundless dimensions.

Specified by:
intersects in interface IHypercube
Parameters:
h - query hypercube
Throws:
If - dimensions are not the same
java.lang.IllegalArgumentException

toString

public java.lang.String toString()
Reasonable toString method.

Overrides:
toString in class java.lang.Object

Algorithm Development Kit 1.0

This code supports the Algorithms in a Nutshell book, published by O'Reilly Media, Inc. in November 2008. Please visit the book web page to learn of any changes to the code repository or to record a potential defect.