com.mizar.geometry
Class Geometry

java.lang.Object
  extended by com.mizar.geometry.Geometry
Direct Known Subclasses:
Arc, Ellipse, Line, Point, Polyline

public class Geometry
extends java.lang.Object


Nested Class Summary
 class Geometry.Results
           
 
Field Summary
protected  double[] defaultOrdinates
           
protected  int dimensions
           
protected  boolean geographic
           
static int LEFTSIDE
           
protected  int maximumCoordinates
           
protected  double[] mbr
           
protected  int minimumCoordinates
           
static int ONLINE
           
protected  double[] ordinates
           
protected  double precision
           
protected  Geometry.Results results
           
static int RIGHTSIDE
           
static java.lang.String[] SIDE
           
protected  int toStringDecimals
           
 
Constructor Summary
Geometry()
           
Geometry(double[] ordinates)
           
 
Method Summary
 boolean adjustEndPoints(double[] point, double tolerance)
          Adjusts the endpoints of this geometry to match point if they fall within the tolerance.
 boolean adjustEndPoints(Geometry geom)
          Adjusts the endpoints of this geometry to match that of the template geometry.
 boolean adjustEndPoints(Geometry geom, double tolerance)
          Adjusts the endpoints of this geometry to match that of the template geometry.
 boolean adjustEndPoints(Point point, double tolerance)
           
 double[] changeDimensions(int newDimensions, double[] fillValues)
          Changes the dimensionality of the element optionally setting fill values.
 double[] computeMbr()
          The method computes the minimum bounding rectangle of the geometry.
static double[] computeMbr(double[] mbr, double[] ordinates, int dimensions)
           
static double[] computeMbr(double[] ordinates, int dimensions)
          The method computes the minimum bounding rectangle of the geometry.
static double computeNearestDistance(double[] source, double[] target)
           
 double computeNearestDistance(Geometry target)
          Note this method just compares the distance between given vertices, which might not be the closest distance between two Geometries.
 boolean connectsTo(double[] endPoints)
          The method tests if any of the endpoints of the two geometries match.
 boolean connectsTo(double[] firstPoint, double[] lastPoint)
          The method tests if any of the endpoints of the two geometries match.
 boolean connectsTo(double x1, double y1, double x2, double y2)
          The method tests if any of the endpoints of the two geometries match.
 boolean connectsTo(Geometry geom)
          The method tests if any of the endpoints of the two geometries match.
 double[] constructDefaultPoint()
          Use this method to create new points to ensure that they are dimension matched and contain the default values;
 boolean equals(java.lang.Object obj)
          Compares two Geometry objects by class, ordinates array length and actual values.
static double[] expandMbr(double[] mbr)
           
 double[] getCoordinate(int coordinateIndex)
           
static double[] getCoordinates(double[] ordinates, int firstCoordinateIndex, int numberOfCoordinates, int dimensions, int dimensionsToCopy)
           
 double[] getCoordinates(int dimensionsToCopy)
           
 double[] getCoordinates(int firstCoordinateIndex, int numberOfCoordinates)
           
 double[] getCoordinates(int firstCoordinateIndex, int numberOfCoordinates, int dimensionsToCopy)
           
 double[] getDefaultOrdinates()
           
 int getDimensions()
           
 int getEndCoordinateIndex()
           
 double[] getFirstPoint()
           
 double[] getFirstPoint(int dimensions)
           
 double[] getLastPoint()
           
 double[] getLastPoint(int dimensions)
           
static int getLeastDimension(java.util.ArrayList geometries)
           
 double getLeastPrecise(Geometry geometry)
           
 double getLength()
           
 double getLength(int firstCoordinate, int lastCoordinate)
           
 int getMaximumCoordinates()
           
 double[] getMbr()
          This method returns the mean bounding rectangle of the geometry.
static double[] getMbrCorner(double[] mbr, int cornerNumber)
           
 double[] getMbrCorner(int cornerNumber)
           
 int getMinimumCoordinates()
           
 double getMostPrecise(Geometry geometry)
           
 int getNumberOfCoordiates()
           
 double[] getOrdinates()
           
 Point[] getPoints()
           
 double[] getPointWithMatchingDimensions(double[] point)
           
 double getPrecision()
           
static double[] getRange(double[] coords, int dim)
           
static int[] getRange(int[] coords, int dim)
           
 Geometry.Results getResults()
           
 double[] getSegment(int segmentIndex)
          A convenient form of the getCoordinates(int,int) method that returns the beginning and end points of a segment.
 int getToStringDecimals()
           
 double[] getXYCoordinates()
           
static double[] getXYCoordinates(double[] ordinates, int dimensions)
           
 int hashCode()
           
 boolean isCoveredByMbr(double[] point2d)
           
static boolean isEqualOrBetween(double scalar_1, double scalar_2, double test, double precision)
           
 boolean isGeographic()
           
 boolean isInsideMbr(double[] point2d)
           
 boolean isSame(Geometry geom)
          Compares two geometries based on dimensions and ordinates using the precision of the most precise Geometry.
 Geometry mbrIntersect(Geometry otherMbr)
           
 boolean mbrOverlap(double[] otherMbr)
           
 boolean mbrOverlap(Geometry otherGeometry)
           
 double mbrOverlapRatio(Geometry otherMbr)
           
static boolean mbrValid(double[] mbr)
           
static double[] polygonizeMbr(double[] mbr)
           
static int quadrant(double[] point)
           
static double[] seedMbr()
           
 void setCoordinate(double[] coordinate, int coordinateIndex)
           
 void setCoordinates(double[] coordinates, int firstCoordinateIndex, int numberOfCoordinates)
          Assumes that the ordinate array exists and is large enough to receive coordinates
 void setCoordinates(double[] coordinates, int firstCoordinateIndex, int numberOfCoordinates, int inDimensions)
           
 void setDefaultOrdinates(double[] defaultOrdinates)
           
 void setDimensions(int dimensions)
           
 void setFirstPoint(double[] point)
           
 void setGeographic(boolean geographic)
           
 void setLastPoint(double[] point)
           
 void setMaximumCoordinates(int maximumCoordinates)
           
 void setMinimumCoordinates(int minimumCoordinates)
           
 void setOrdinates(double[] ordinates)
           
 void setPrecision(double precision)
           
 void setSegment(double[] segment, int segmentIndex)
          A convenient form of the setCoordinates(double[],int,int) method that sets the beginning and end points of a segment.
 void setToStringDecimals(int toStringDecimals)
           
 java.lang.String toString()
           
static double[] updateMbr(double[] mbr, double[] ordinates, int dimensions)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ONLINE

public static final int ONLINE
See Also:
Constant Field Values

LEFTSIDE

public static final int LEFTSIDE
See Also:
Constant Field Values

RIGHTSIDE

public static final int RIGHTSIDE
See Also:
Constant Field Values

SIDE

public static final java.lang.String[] SIDE

dimensions

protected int dimensions

maximumCoordinates

protected int maximumCoordinates

minimumCoordinates

protected int minimumCoordinates

precision

protected double precision

ordinates

protected double[] ordinates

defaultOrdinates

protected double[] defaultOrdinates

results

protected Geometry.Results results

mbr

protected double[] mbr

toStringDecimals

protected int toStringDecimals

geographic

protected boolean geographic
Constructor Detail

Geometry

public Geometry()

Geometry

public Geometry(double[] ordinates)
         throws GeometryException
Throws:
GeometryException
Method Detail

equals

public boolean equals(java.lang.Object obj)
Compares two Geometry objects by class, ordinates array length and actual values.

Overrides:
equals in class java.lang.Object
Parameters:
obj. - The other Geometry object to compare
Returns:

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

computeNearestDistance

public double computeNearestDistance(Geometry target)
                              throws GeometryException
Note this method just compares the distance between given vertices, which might not be the closest distance between two Geometries.

Parameters:
target - a target geometry
Returns:
the closest distance between a point on this Geometry and the target Geometry.
Throws:
GeometryException
See Also:
for a method that does a more expensive search

computeNearestDistance

public static double computeNearestDistance(double[] source,
                                            double[] target)
                                     throws GeometryException
Throws:
GeometryException

getPoints

public Point[] getPoints()
                  throws GeometryException
Throws:
GeometryException

getMostPrecise

public double getMostPrecise(Geometry geometry)
Parameters:
geometry -
Returns:

getLeastPrecise

public double getLeastPrecise(Geometry geometry)
Parameters:
geometry -
Returns:

setDimensions

public void setDimensions(int dimensions)
                   throws GeometryException
Parameters:
dimensions - ignored as the library is currently hardcoded to dimensions = 2
Throws:
GeometryException

getDimensions

public int getDimensions()
Returns:
always returns 2

setPrecision

public void setPrecision(double precision)
Parameters:
precision -

getPrecision

public double getPrecision()
Returns:

setMaximumCoordinates

public void setMaximumCoordinates(int maximumCoordinates)
Parameters:
maximumCoordinates -

getMaximumCoordinates

public int getMaximumCoordinates()
Returns:

setMinimumCoordinates

public void setMinimumCoordinates(int minimumCoordinates)
Parameters:
minimumCoordinates -

getMinimumCoordinates

public int getMinimumCoordinates()
Returns:

getEndCoordinateIndex

public int getEndCoordinateIndex()
                          throws GeometryException
Throws:
GeometryException

setOrdinates

public void setOrdinates(double[] ordinates)
                  throws GeometryException
Parameters:
ordinates -
Throws:
GeometryException

getPointWithMatchingDimensions

public double[] getPointWithMatchingDimensions(double[] point)

constructDefaultPoint

public double[] constructDefaultPoint()
Use this method to create new points to ensure that they are dimension matched and contain the default values;

Returns:
an array of doubles populated with the defaultOrdinates.

getNumberOfCoordiates

public int getNumberOfCoordiates()
Returns:
the number of Coordinates computed as ordinates.area()/dimensions

changeDimensions

public double[] changeDimensions(int newDimensions,
                                 double[] fillValues)
Changes the dimensionality of the element optionally setting fill values. If fillValues is null and the dimensionality is increased new ordinates will be filled with zeros. If newDimensions matches dimensions the ordinate array is returned unchanged. The method returns null if ordinates is null.

Parameters:
newDimensions -
fillValues -
Returns:
a reference to the new ordinate array.

getOrdinates

public double[] getOrdinates()
Returns:

setCoordinate

public void setCoordinate(double[] coordinate,
                          int coordinateIndex)
                   throws GeometryException
Parameters:
coordinate -
coordinateIndex -
Throws:
GeometryException

setCoordinates

public void setCoordinates(double[] coordinates,
                           int firstCoordinateIndex,
                           int numberOfCoordinates)
                    throws GeometryException
Assumes that the ordinate array exists and is large enough to receive coordinates

Parameters:
coordinates -
firstCoordinateIndex -
numberOfCoordinates -
Throws:
GeometryException

setCoordinates

public void setCoordinates(double[] coordinates,
                           int firstCoordinateIndex,
                           int numberOfCoordinates,
                           int inDimensions)
                    throws GeometryException
Throws:
GeometryException

getCoordinate

public double[] getCoordinate(int coordinateIndex)
                       throws GeometryException
Parameters:
coordinateIndex -
Returns:
Throws:
GeometryException

setSegment

public void setSegment(double[] segment,
                       int segmentIndex)
                throws GeometryException
A convenient form of the setCoordinates(double[],int,int) method that sets the beginning and end points of a segment.

Parameters:
segment -
segmentIndex -
Throws:
GeometryException

getSegment

public double[] getSegment(int segmentIndex)
                    throws GeometryException
A convenient form of the getCoordinates(int,int) method that returns the beginning and end points of a segment.

Parameters:
segmentIndex -
Returns:
Throws:
GeometryException

getCoordinates

public double[] getCoordinates(int dimensionsToCopy)
                        throws GeometryException
Throws:
GeometryException

getCoordinates

public double[] getCoordinates(int firstCoordinateIndex,
                               int numberOfCoordinates)
                        throws GeometryException
Parameters:
firstCoordinateIndex -
numberOfCoordinates -
Returns:
Throws:
GeometryException

getCoordinates

public double[] getCoordinates(int firstCoordinateIndex,
                               int numberOfCoordinates,
                               int dimensionsToCopy)
                        throws GeometryException
Throws:
GeometryException

getCoordinates

public static double[] getCoordinates(double[] ordinates,
                                      int firstCoordinateIndex,
                                      int numberOfCoordinates,
                                      int dimensions,
                                      int dimensionsToCopy)
                               throws GeometryException
Throws:
GeometryException

getXYCoordinates

public double[] getXYCoordinates()
                          throws GeometryException
Throws:
GeometryException

getXYCoordinates

public static double[] getXYCoordinates(double[] ordinates,
                                        int dimensions)
                                 throws GeometryException
Throws:
GeometryException

setFirstPoint

public void setFirstPoint(double[] point)
                   throws GeometryException
Parameters:
point -
Throws:
GeometryException

getFirstPoint

public double[] getFirstPoint()
                       throws GeometryException
Returns:
Throws:
GeometryException

getFirstPoint

public double[] getFirstPoint(int dimensions)
                       throws GeometryException
Parameters:
dimensions -
Returns:
Throws:
GeometryException

setLastPoint

public void setLastPoint(double[] point)
                  throws GeometryException
Parameters:
point -
Throws:
GeometryException

getLastPoint

public double[] getLastPoint()
                      throws GeometryException
Returns:
Throws:
GeometryException

getLastPoint

public double[] getLastPoint(int dimensions)
                      throws GeometryException
Parameters:
dimensions -
Returns:
Throws:
GeometryException

connectsTo

public boolean connectsTo(Geometry geom)
                   throws GeometryException
The method tests if any of the endpoints of the two geometries match. The precision of this geometry is used.

Parameters:
geom -
Returns:
true if the geometeries could form a continuous linear element.
Throws:
GeometryException
See Also:
adjustEndPoints(Geometry), connectsTo(double[], double[])

connectsTo

public boolean connectsTo(double[] endPoints)
                   throws GeometryException
The method tests if any of the endpoints of the two geometries match. The precision of this geometry is used.

Parameters:
endPoints -
Returns:
Throws:
GeometryException
See Also:
connectsTo(double[], double[])

connectsTo

public boolean connectsTo(double x1,
                          double y1,
                          double x2,
                          double y2)
                   throws GeometryException
The method tests if any of the endpoints of the two geometries match. The precision of this geometry is used.

Parameters:
x1 -
y1 -
x2 -
y2 -
Returns:
Throws:
GeometryException
See Also:
connectsTo(double[], double[])

connectsTo

public boolean connectsTo(double[] firstPoint,
                          double[] lastPoint)
                   throws GeometryException
The method tests if any of the endpoints of the two geometries match. The precision of this geometry is used.

Parameters:
firstPoint -
lastPoint -
Returns:
Throws:
GeometryException

adjustEndPoints

public boolean adjustEndPoints(Geometry geom)
                        throws GeometryException
Adjusts the endpoints of this geometry to match that of the template geometry. The method is commonly used to 'snap' two geometries together. The method compares all four ends to each other and thus may adjust both the first and last points. The precision of this geometry is used.

Parameters:
geom -
Returns:
Throws:
GeometryException
See Also:
, Geometry#adjustEndPoints(polyline,double)

adjustEndPoints

public boolean adjustEndPoints(Geometry geom,
                               double tolerance)
                        throws GeometryException
Adjusts the endpoints of this geometry to match that of the template geometry. The method is commonly used to 'snap' two geometries together. The method compares all four ends to each other and thus may adjust both the first and last points. The precision of this geometry is used.

Parameters:
geom -
tolerance - adjust endpoints within this distance of each other
Returns:
Throws:
GeometryException
See Also:
connectsTo(com.mizar.geometry.Geometry)

adjustEndPoints

public boolean adjustEndPoints(double[] point,
                               double tolerance)
                        throws GeometryException
Adjusts the endpoints of this geometry to match point if they fall within the tolerance. The method is commonly used to 'snap' two geometries together. The precision of this geometry is used.

Parameters:
point -
tolerance - adjust endpoints within this distance of each other
Returns:
Throws:
GeometryException

adjustEndPoints

public boolean adjustEndPoints(Point point,
                               double tolerance)
                        throws GeometryException
Throws:
GeometryException

getLength

public double getLength()
                 throws GeometryException
Throws:
GeometryException

getLength

public double getLength(int firstCoordinate,
                        int lastCoordinate)
                 throws GeometryException
Throws:
GeometryException

getRange

public static double[] getRange(double[] coords,
                                int dim)

getRange

public static int[] getRange(int[] coords,
                             int dim)

getLeastDimension

public static int getLeastDimension(java.util.ArrayList geometries)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:

isSame

public boolean isSame(Geometry geom)
Compares two geometries based on dimensions and ordinates using the precision of the most precise Geometry.

Parameters:
geom -
Returns:
true if the two Geometrys are effectively the same.

isEqualOrBetween

public static boolean isEqualOrBetween(double scalar_1,
                                       double scalar_2,
                                       double test,
                                       double precision)
Parameters:
scalar_1 -
scalar_2 -
test - a value to test if it is between scalar_1 and scalar_2
Returns:
true if test is equal to either, or between scalar_1 and scalar_2

quadrant

public static int quadrant(double[] point)
Parameters:
point -
Returns:
{+,+} = 1; {+,-} = 2; {-,-} = 3; {-,+} = 4

computeMbr

public double[] computeMbr()
                    throws GeometryException
The method computes the minimum bounding rectangle of the geometry.

Returns:
an array of the minX, minY, maxX, and maxY values
Throws:
GeometryException
See Also:
getMbr(), computeMbr(double[], int)

computeMbr

public static double[] computeMbr(double[] ordinates,
                                  int dimensions)
                           throws GeometryException
The method computes the minimum bounding rectangle of the geometry.

Returns:
an array of the minX, minY, maxX, and maxY values
Throws:
GeometryException
See Also:
computeMbr()

computeMbr

public static double[] computeMbr(double[] mbr,
                                  double[] ordinates,
                                  int dimensions)
                           throws GeometryException
Throws:
GeometryException

seedMbr

public static double[] seedMbr()
Returns:
a 4 ordinate maximum bounding range set to + and - Double.MAX_VALUE

polygonizeMbr

public static double[] polygonizeMbr(double[] mbr)
Parameters:
mbr - a 4 ordinate mean bounding rectangle with minX, minY, maxX, maxY ordinates
Returns:
a 10 ordinate polygon array describing the same area.

mbrValid

public static boolean mbrValid(double[] mbr)
Parameters:
mbr - a 4 ordinate maximum bounding range to check
Returns:
true if all four ordinates are inside the seed values
See Also:
seedMbr()

updateMbr

public static double[] updateMbr(double[] mbr,
                                 double[] ordinates,
                                 int dimensions)
Parameters:
mbr - a 4 ordinate maximum bounding range to check
ordinates - an array of ordinates (1 or more) to test against mbr
dimensions - the dimensions of the coordinates in the ordinate array
Returns:
updated mbr

expandMbr

public static double[] expandMbr(double[] mbr)
Parameters:
mbr - a 4 ordinate maximum bounding range to expand
Returns:
a 10 ordinate polygon (the first two ordinates match the last two)

getMbr

public double[] getMbr()
                throws GeometryException
This method returns the mean bounding rectangle of the geometry. Changing a geometry does not automatically update the MBR. If you think that the MBR might have changed you should call computerMbr()

Returns:
Throws:
GeometryException
See Also:
computeMbr()

isCoveredByMbr

public boolean isCoveredByMbr(double[] point2d)
                       throws GeometryException
Parameters:
point2d -
Returns:
true if the point is inside or on the boundary of the mean bounding rectangle of the geometry
Throws:
GeometryException
See Also:
getMbr()

isInsideMbr

public boolean isInsideMbr(double[] point2d)
                    throws GeometryException
Parameters:
point2d -
Returns:
true if point2d is inside the boundary of the mean bounding rectangle of the geometry
Throws:
GeometryException
See Also:
getMbr()

mbrOverlapRatio

public double mbrOverlapRatio(Geometry otherMbr)
                       throws GeometryException
Parameters:
otherMbr - a Geometry assumed to be a 5 coordinate orthoganal rectangle or MBR
Returns:
the ratio of area of otherMbr covered by this MBR
Throws:
GeometryException

mbrIntersect

public Geometry mbrIntersect(Geometry otherMbr)
                      throws GeometryException
Throws:
GeometryException

mbrOverlap

public boolean mbrOverlap(Geometry otherGeometry)
                   throws GeometryException
Parameters:
otherGeometry -
Returns:
true if any corner of the otherGeometry mean bounding rectangle falls on or inside the mbr of this geometry
Throws:
GeometryException

mbrOverlap

public boolean mbrOverlap(double[] otherMbr)
                   throws GeometryException
Parameters:
otherMbr - an array of minX,minY,maxX,maxY
Returns:
true if any corner of the otherMbr falls on or inside the mbr of this geometry
Throws:
GeometryException

getMbrCorner

public double[] getMbrCorner(int cornerNumber)
                      throws GeometryException
Parameters:
cornerNumber - 0=minX,minY 1=minX,maxY 2= maxX,minY 3= maxX, maxY
Returns:
the XY ordinates of the mbr corner
Throws:
GeometryException

getMbrCorner

public static double[] getMbrCorner(double[] mbr,
                                    int cornerNumber)

getResults

public Geometry.Results getResults()

setDefaultOrdinates

public void setDefaultOrdinates(double[] defaultOrdinates)

getDefaultOrdinates

public double[] getDefaultOrdinates()

setToStringDecimals

public void setToStringDecimals(int toStringDecimals)
Parameters:
toStringDecimals - number of decimal places to use in the toString method

getToStringDecimals

public int getToStringDecimals()

setGeographic

public void setGeographic(boolean geographic)

isGeographic

public boolean isGeographic()