com.seisw.util.geom
Class PolyDefault

java.lang.Object
  extended bycom.seisw.util.geom.PolyDefault
All Implemented Interfaces:
Poly

public class PolyDefault
extends java.lang.Object
implements Poly

PolyDefault is a default Poly implementation. It provides support for both complex and simple polygons. A complex polygon is a polygon that consists of more than one polygon. A simple polygon is a more traditional polygon that contains of one inner polygon and is just a collection of points.

Implementation Note: If a point is added to an empty PolyDefault object, it will create an inner polygon of type PolySimple.

Author:
Dan Bridenbecker, Solution Engineering, Inc.
See Also:
PolySimple

Field Summary
protected  java.util.List m_List
           
 
Constructor Summary
PolyDefault()
          Creates a new instance of PolyDefault
PolyDefault(boolean isHole)
           
 
Method Summary
 void add(double x, double y)
          Add a point to the first inner polygon.
 void add(java.awt.geom.Point2D p)
          Add a point to the first inner polygon.
 void add(Poly p)
          Add an inner polygon to this polygon - assumes that adding polygon does not have any inner polygons.
 void clear()
          Remove all of the points.
 boolean equals(java.lang.Object obj)
          Return true if the given object is equal to this one.
 double getArea()
          Return the area of the polygon in square units.
 java.awt.geom.Rectangle2D getBounds()
          Returns the bounding rectangle of this polygon.
 Poly getInnerPoly(int polyIndex)
          Returns the polygon at this index.
 int getNumInnerPoly()
          Returns the number of inner polygons - inner polygons are assumed to return one here.
 int getNumPoints()
          Return the number points of the first inner polygon
 double getX(int index)
          Return the X value of the point at the index in the first inner polygon
 double getY(int index)
          Return the Y value of the point at the index in the first inner polygon
 int hashCode()
          Return the hashCode of the object.
 Poly intersection(Poly p)
          Return a Poly that is the intersection of this polygon with the given polygon.
 boolean isContributing(int polyIndex)
          Return true if the given inner polygon is contributing to the set operation.
 boolean isEmpty()
          Return true if the polygon is empty
 boolean isHole()
          Return true if this polygon is a hole.
 void setContributing(int polyIndex, boolean contributes)
          Set whether or not this inner polygon is constributing to the set operation.
 void setIsHole(boolean isHole)
          Set whether or not this polygon is a hole.
 java.lang.String toString()
           
 Poly union(Poly p)
          Return a Poly that is the union of this polygon with the given polygon.
 Poly xor(Poly p)
          Return a Poly that is the exclusive-or of this polygon with the given polygon.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

m_List

protected java.util.List m_List
Constructor Detail

PolyDefault

public PolyDefault()
Creates a new instance of PolyDefault


PolyDefault

public PolyDefault(boolean isHole)
Method Detail

equals

public boolean equals(java.lang.Object obj)
Return true if the given object is equal to this one.


hashCode

public int hashCode()
Return the hashCode of the object.

Returns:
an integer value that is the same for two objects whenever their internal representation is the same (equals() is true)

toString

public java.lang.String toString()

clear

public void clear()
Remove all of the points. Creates an empty polygon.

Specified by:
clear in interface Poly

add

public void add(double x,
                double y)
Add a point to the first inner polygon.

Implementation Note: If a point is added to an empty PolyDefault object, it will create an inner polygon of type PolySimple.

Specified by:
add in interface Poly

add

public void add(java.awt.geom.Point2D p)
Add a point to the first inner polygon.

Implementation Note: If a point is added to an empty PolyDefault object, it will create an inner polygon of type PolySimple.

Specified by:
add in interface Poly

add

public void add(Poly p)
Add an inner polygon to this polygon - assumes that adding polygon does not have any inner polygons.

Specified by:
add in interface Poly
Throws:
java.lang.IllegalStateException - if the number of inner polygons is greater than zero and this polygon was designated a hole. This would break the assumption that only simple polygons can be holes.

isEmpty

public boolean isEmpty()
Return true if the polygon is empty

Specified by:
isEmpty in interface Poly

getBounds

public java.awt.geom.Rectangle2D getBounds()
Returns the bounding rectangle of this polygon. WARNING Not supported on complex polygons.

Specified by:
getBounds in interface Poly

getInnerPoly

public Poly getInnerPoly(int polyIndex)
Returns the polygon at this index.

Specified by:
getInnerPoly in interface Poly

getNumInnerPoly

public int getNumInnerPoly()
Returns the number of inner polygons - inner polygons are assumed to return one here.

Specified by:
getNumInnerPoly in interface Poly

getNumPoints

public int getNumPoints()
Return the number points of the first inner polygon

Specified by:
getNumPoints in interface Poly

getX

public double getX(int index)
Return the X value of the point at the index in the first inner polygon

Specified by:
getX in interface Poly

getY

public double getY(int index)
Return the Y value of the point at the index in the first inner polygon

Specified by:
getY in interface Poly

isHole

public boolean isHole()
Return true if this polygon is a hole. Holes are assumed to be inner polygons of a more complex polygon.

Specified by:
isHole in interface Poly
Throws:
java.lang.IllegalStateException - if called on a complex polygon.

setIsHole

public void setIsHole(boolean isHole)
Set whether or not this polygon is a hole. Cannot be called on a complex polygon.

Specified by:
setIsHole in interface Poly
Throws:
java.lang.IllegalStateException - if called on a complex polygon.

isContributing

public boolean isContributing(int polyIndex)
Return true if the given inner polygon is contributing to the set operation. This method should NOT be used outside the Clip algorithm.

Specified by:
isContributing in interface Poly

setContributing

public void setContributing(int polyIndex,
                            boolean contributes)
Set whether or not this inner polygon is constributing to the set operation. This method should NOT be used outside the Clip algorithm.

Specified by:
setContributing in interface Poly
Throws:
java.lang.IllegalStateException - if called on a complex polygon

intersection

public Poly intersection(Poly p)
Return a Poly that is the intersection of this polygon with the given polygon. The returned polygon could be complex.

Specified by:
intersection in interface Poly
Returns:
the returned Poly will be an instance of PolyDefault.

union

public Poly union(Poly p)
Return a Poly that is the union of this polygon with the given polygon. The returned polygon could be complex.

Specified by:
union in interface Poly
Returns:
the returned Poly will be an instance of PolyDefault.

xor

public Poly xor(Poly p)
Return a Poly that is the exclusive-or of this polygon with the given polygon. The returned polygon could be complex.

Specified by:
xor in interface Poly
Returns:
the returned Poly will be an instance of PolyDefault.

getArea

public double getArea()
Return the area of the polygon in square units.

Specified by:
getArea in interface Poly


Copyright © 2004 Solution Engineering, Inc. All Rights Reserved.