edu.umd.cfar.lamp.viper.geometry
Class Polygon

java.lang.Object
  extended byedu.umd.cfar.lamp.viper.geometry.PolyList
      extended byedu.umd.cfar.lamp.viper.geometry.Polygon
All Implemented Interfaces:
java.lang.Cloneable, HasCentroid, Moveable

public class Polygon
extends PolyList
implements java.lang.Cloneable, HasCentroid, Moveable

This class represents a series of line segments.


Field Summary
 
Fields inherited from class edu.umd.cfar.lamp.viper.geometry.PolyList
area, bbox, CARVE_POLYS, composed, originals, polys
 
Fields inherited from interface edu.umd.cfar.lamp.viper.geometry.Moveable
EAST, NORTH, NORTHEAST, NORTHWEST, SOUTH, SOUTHEAST, SOUTHWEST, WEST
 
Constructor Summary
Polygon()
          Constructs an empty, closed polygon.
Polygon(java.awt.geom.Point2D[] list)
          Converts a list of points into a polygon.
Polygon(Polygon old)
          Constructs a Polygon copy.
Polygon(java.lang.String S)
          Constructs a polygon from a list of points.
 
Method Summary
 boolean addVertex(Pnt v)
          Adds the point to the end of the polygon as a point on its exterior.
 java.lang.Object clone()
          Constructs a copy of this object.
 boolean equals(java.lang.Object o)
          Tests to see if the other object contains the same region as this polygon.
 BoundingBox getBoundingBox()
          Gets the closest bounding box surrounding this polygon.
 Pnt getCentroid()
          Gets a copy of the centroid.
 java.util.Iterator getPoints()
          Gets all the points around the outside of the polygon.
protected  void initBbox()
          Creates a BoundingBox around this, for use by getBoundingBox, etc.
 Moveable move(int direction, int distance)
          Creates a new copy of this movable item, shifted in the given direction by the given number of pixels.
 Moveable shift(int x, int y)
          Shifts the moveable by the given amount.
 java.lang.String toString()
          Gets a list of the points as a String, usually for debugging.
static Polygon valueOf(java.lang.String S)
          Constructs a polygon from a list of points.
 
Methods inherited from class edu.umd.cfar.lamp.viper.geometry.PolyList
addPoly, area, clearPolyList, contains, getConvexPolygonArray, getFragmentationCount, getIntersection, getOriginals, getPolys, hashCode, intersection, intersects, toStringListOfPoints, union
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Polygon

public Polygon()
Constructs an empty, closed polygon.


Polygon

public Polygon(Polygon old)
Constructs a Polygon copy.

Parameters:
old - The Polygon to copy.

Polygon

public Polygon(java.awt.geom.Point2D[] list)
Converts a list of points into a polygon. NB: This assumes that the points are all integers. Also assumes list[ 0 ] and list[ n - 1 ] are not the same point.

Parameters:
list - ordered set of points for the polygon

Polygon

public Polygon(java.lang.String S)
        throws BadDataException
Constructs a polygon from a list of points. Can construct a set of polygons, where each individual polygon is in brackets

Parameters:
S - a polygon is a list of parenthestized int pairs, and a set of polygons is delimited by brackets
Throws:
BadDataException - if the string isn't formatted properly
Method Detail

valueOf

public static Polygon valueOf(java.lang.String S)
Constructs a polygon from a list of points. Can construct a set of polygons, where each individual polygon is in brackets

Parameters:
S - a polygon is a list of parenthestized int pairs, and a set of polygons is delimited by brackets
Returns:
the described polygon or polylist

equals

public boolean equals(java.lang.Object o)
Tests to see if the other object contains the same region as this polygon.

Overrides:
equals in class PolyList
Parameters:
o - the PolyList or Polygon to compare with
Returns:
false if the two cover different regions

clone

public java.lang.Object clone()
Constructs a copy of this object.

Overrides:
clone in class PolyList
Returns:
A new Object that represents the same region.

toString

public java.lang.String toString()
Gets a list of the points as a String, usually for debugging.

Overrides:
toString in class PolyList
Returns:
A bracketed String, with a list of parenthesized lists of points for each convex polygon.

initBbox

protected void initBbox()
Creates a BoundingBox around this, for use by getBoundingBox, etc.

Overrides:
initBbox in class PolyList

getBoundingBox

public BoundingBox getBoundingBox()
Gets the closest bounding box surrounding this polygon.

Overrides:
getBoundingBox in class PolyList
Returns:
the closest bounding box

getPoints

public java.util.Iterator getPoints()
Gets all the points around the outside of the polygon. XXX Does not handle composed case, no points case.

Overrides:
getPoints in class PolyList
Returns:
an iterator through all the points on the polygon

addVertex

public boolean addVertex(Pnt v)
Adds the point to the end of the polygon as a point on its exterior. XXX Does not handle composed case, no points case.

Overrides:
addVertex in class PolyList
Parameters:
v - the point to add to the edge list
Returns:
true, if the point was added

getCentroid

public Pnt getCentroid()
Description copied from interface: HasCentroid
Gets a copy of the centroid.

Specified by:
getCentroid in interface HasCentroid
Returns:
the centroid of the object
See Also:
HasCentroid.getCentroid()

move

public Moveable move(int direction,
                     int distance)
Creates a new copy of this movable item, shifted in the given direction by the given number of pixels.

Specified by:
move in interface Moveable
Parameters:
direction - the direction to move the item
distance - the distance to move it
Returns:
the new item, the same as the old one, but shifted

shift

public Moveable shift(int x,
                      int y)
Shifts the moveable by the given amount.

Specified by:
shift in interface Moveable
Parameters:
x -
y -
Returns: