drasys.or.geom.rect2
Class Polygon

java.lang.Object
  |
  +--drasys.or.geom.rect2.Rect2
        |
        +--drasys.or.geom.rect2.Polygon

public class Polygon
extends Rect2
implements PolygonI, java.io.Serializable

An implementation of a polygon with optional holes in the 2D rectangular coordinate system. This polygon is a container object, it holds the points that define the vertices of the polygon. The points must be objects that implement the PointI interface and have immutable coordinates. The polygon also contains a set of polygons that represent holes in the polygon.

See Also:
Serialized Form

Constructor Summary
Polygon(PointI[] vertices)
           
Polygon(PointI[] vertices, PolygonI[] holes)
           
 
Method Summary
 PointI centroid()
          Returns the point at the mean X and Y for the vertices, the holes are ignored.
 double distanceProxyTo(PointI point)
          Returns an easily computable proxy that can be used to compare the distance from the polygon border to the point argument.
 double distanceTo(PointI point)
          Returns the distance from the polygon border to the point argument.
 boolean equals(java.lang.Object o)
          Returns true if the points and all the holes in each polygon are equal.
 PointI getPoint(int index)
          Returns the point at 'index' from the polygon.
 int hashCode()
           
 java.util.Enumeration holes()
          Returns an enumeration on the holes of the polygon.
 double length()
          Returns the length of the border of the polygon.
 PointI nearestPointTo(PointI point)
          Returns the point along the polygon border that is closest to the argument.
 PointI point(int index)
          Returns the point at 'index';
 RangeI range()
           
 int sizeOfHoles()
          Returns the number of holes in the polygon.
 int sizeOfVertices()
          Returns the number of vertices in the polygon.
 java.lang.String toString()
           
 java.util.Enumeration vertices()
          Returns an enumeration on the vertices of the polygon.
 
Methods inherited from class drasys.or.geom.rect2.Rect2
coordinateSystem, getCentroid, getDistanceProxyTo, getDistanceTo, getNearestPointTo, getRange
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Polygon

public Polygon(PointI[] vertices)

Polygon

public Polygon(PointI[] vertices,
               PolygonI[] holes)
Method Detail

point

public PointI point(int index)
Returns the point at 'index';
Specified by:
point in interface PolygonI

range

public RangeI range()

centroid

public PointI centroid()
Returns the point at the mean X and Y for the vertices, the holes are ignored.

sizeOfVertices

public int sizeOfVertices()
Returns the number of vertices in the polygon. The count includes the vertices in all the polygons in the hole tree.

sizeOfHoles

public int sizeOfHoles()
Returns the number of holes in the polygon. The count includes the holes in all the polygons in the hole tree.

getPoint

public PointI getPoint(int index)
Returns the point at 'index' from the polygon.

vertices

public java.util.Enumeration vertices()
Returns an enumeration on the vertices of the polygon. The objects returned implement 'drasys.or.geom.PointI'.

holes

public java.util.Enumeration holes()
Returns an enumeration on the holes of the polygon. The objects returned implement 'drasys.or.geom.PolygonI'.

nearestPointTo

public PointI nearestPointTo(PointI point)
Returns the point along the polygon border that is closest to the argument.

distanceTo

public double distanceTo(PointI point)
Returns the distance from the polygon border to the point argument.

distanceProxyTo

public double distanceProxyTo(PointI point)
Returns an easily computable proxy that can be used to compare the distance from the polygon border to the point argument.

length

public double length()
Returns the length of the border of the polygon.

hashCode

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

equals

public boolean equals(java.lang.Object o)
Returns true if the points and all the holes in each polygon are equal. The points are tested using the 'Point.equals()' static method.
Overrides:
equals in class java.lang.Object

toString

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


Copyright(C)1997-2000 by DRA Systems all rights reserved. OpsResearch.com