com.seisw.util.geom
Class PolySimple

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

public class PolySimple
extends java.lang.Object
implements Poly

PolySimple is a simple polygon - contains only one inner polygon.

WARNING: This type of Poly cannot be used for an inner polygon that is a hole.

Author:
Dan Bridenbecker, Solution Engineering, Inc.

Field Summary
protected  java.util.List m_List
          The list of Point2D objects in the polygon.
 
Constructor Summary
PolySimple()
          Creates a new instance of PolySimple
 
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)
          Throws IllegalStateexception if called
 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()
          Returns the area of the polygon.
 java.awt.geom.Rectangle2D getBounds()
          Returns the bounding rectangle of this polygon.
 Poly getInnerPoly(int polyIndex)
          Returns this if polyIndex = 0, else it throws IllegalStateException.
 int getNumInnerPoly()
          Always returns 1.
 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()
          Always returns false since PolySimples cannot be holes.
 void setContributing(int polyIndex, boolean contributes)
          Set whether or not this inner polygon is constributing to the set operation.
 void setIsHole(boolean isHole)
          Throws IllegalStateException if called.
 java.lang.String toString()
          Return a string briefly describing the polygon.
 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
The list of Point2D objects in the polygon.

Constructor Detail

PolySimple

public PolySimple()
Creates a new instance of PolySimple

Method Detail

equals

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

WARNING: This method failse if the first point appears more than once in the list.


hashCode

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

WARNING:Hash and Equals break contract.

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()
Return a string briefly describing the polygon.


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.

Specified by:
add in interface Poly

add

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

Specified by:
add in interface Poly

add

public void add(Poly p)
Throws IllegalStateexception if called

Specified by:
add in interface Poly

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.

Specified by:
getBounds in interface Poly

getInnerPoly

public Poly getInnerPoly(int polyIndex)
Returns this if polyIndex = 0, else it throws IllegalStateException.

Specified by:
getInnerPoly in interface Poly

getNumInnerPoly

public int getNumInnerPoly()
Always returns 1.

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()
Always returns false since PolySimples cannot be holes.

Specified by:
isHole in interface Poly

setIsHole

public void setIsHole(boolean isHole)
Throws IllegalStateException if called.

Specified by:
setIsHole in interface Poly

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
Throws:
java.lang.IllegalStateException - if polyIndex != 0

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 polyIndex != 0

intersection

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

Specified by:
intersection in interface Poly
Returns:
The returned Poly is of type PolySimple

union

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

Specified by:
union in interface Poly
Returns:
The returned Poly is of type PolySimple

xor

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

Specified by:
xor in interface Poly
Returns:
The returned Poly is of type PolySimple

getArea

public double getArea()
Returns the area of the polygon.

The algorithm for the area of a complex polygon was take from code by Joseph O'Rourke author of " Computational Geometry in C".

Specified by:
getArea in interface Poly


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