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

java.lang.Object
  extended byedu.umd.cfar.lamp.viper.geometry.PolyList
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
ConvexPolygon, Polygon, PolyLine

public class PolyList
extends java.lang.Object
implements java.lang.Cloneable

This class represents the intersection / union of several Convex Polygons. ConvexPolygon extends this, and if I ever have non-convex polygons, they should, too.


Field Summary
protected  Rational area
          The area.
protected  BoundingBox bbox
          A BoundingBox that surrounds the PolyList.
static boolean CARVE_POLYS
          This boolean should be set to 'false' to avoid carving polygons into simple polygons.
protected  boolean composed
          If true, then it is composed, and need to watch for redundancies.
protected  java.util.List originals
          While the polys list has no overlaps, the originals list does not.
protected  java.util.List polys
          The list of convex polygons that this data structure describes.
 
Constructor Summary
PolyList()
          Constructs an empty PolyList.
PolyList(PolyList old)
          Constructs a PolyList copy of an old PolyList.
 
Method Summary
protected  void addPoly(PolyList shape)
          Sets this PolyList into this unioned with the given shape.
 boolean addVertex(Pnt p)
          Adds the vertex to the polygon this represents; this is unimplemented in this root class.
 Rational area()
          Get the area of coverage by these polygons.
protected  void clearPolyList()
           
 java.lang.Object clone()
          Constructs a copy of this object.
 boolean contains(Pnt point)
          Tests to see if one of the subpolys contains the given point.
 boolean equals(java.lang.Object other)
          Checks to see if this equals the other space.
 BoundingBox getBoundingBox()
          Gets the closest box around the set of polygons.
 ConvexPolygon[] getConvexPolygonArray()
          Gets an array of non-overlapping ConvexPolygons whose union completely tiles the region described by this PolyList.
 int getFragmentationCount(PolyList other)
          Gets a count of how many original polygons the other hits.
 PolyList getIntersection(PolyList other)
          Get the intersection of this PolyList with another.
 java.util.Iterator getOriginals()
          Gets the original list of polygons added to this list, instead of the list of non-overlapping ones.
 java.util.Iterator getPoints()
          Gets the points in the polygon; to be implemented by the concrete subclasses.
protected  java.util.Iterator getPolys()
          Gets an iterator that goes through a list of polygons that are contained within this region, such that the union of all of them is equal to this region.
 int hashCode()
          Get a hashcode for this region.
protected  void initBbox()
          Creates a BoundingBox around this, for use by getBoundingBox, etc.
static PolyList intersection(PolyList alpha, PolyList zappa)
          Find the intersection of two PolyLists.
 boolean intersects(PolyList other)
          Tests to see if this region intersects the given region.
 java.lang.String toString()
          Returns a string representation of this list of convex polygons.
 java.lang.String toStringListOfPoints()
          Gets a list of the points as a String, usually for debugging.
static PolyList union(PolyList alpha, PolyList zappa)
          Generate the union of two PolyLists.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

composed

protected boolean composed
If true, then it is composed, and need to watch for redundancies.


polys

protected java.util.List polys
The list of convex polygons that this data structure describes. you know your object model is screwed when you have to use protected fields.


originals

protected java.util.List originals
While the polys list has no overlaps, the originals list does not. Instead, it offers quicker bounds checking, and fragmentation counts by keeping track of the original polygons that compose this.


bbox

protected BoundingBox bbox
A BoundingBox that surrounds the PolyList.


area

protected Rational area
The area. Negative if not set


CARVE_POLYS

public static boolean CARVE_POLYS
This boolean should be set to 'false' to avoid carving polygons into simple polygons. This can cause performance delays, and, as of now, can cause crashes, so it is a good idea for at least viper-gt to set this to false.

Constructor Detail

PolyList

public PolyList()
Constructs an empty PolyList.


PolyList

public PolyList(PolyList old)
Constructs a PolyList copy of an old PolyList.

Parameters:
old - The PolyList to copy.
Method Detail

clone

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

Returns:
A new Object that represents the same space.

equals

public boolean equals(java.lang.Object other)
Checks to see if this equals the other space.

Parameters:
other - The object to test with.
Returns:
true if they are equal.

hashCode

public int hashCode()
Get a hashcode for this region. It is generated from the area.

Returns:
An integer that is unique to this region.

toStringListOfPoints

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

Returns:
A bracketed String, with a list of parenthesized lists of points for each convex polygon.

toString

public java.lang.String toString()
Returns a string representation of this list of convex polygons.

Returns:
The same as toStringListOfPoints() right now.

area

public Rational area()
Get the area of coverage by these polygons.

Returns:
The nearest double value to the area.

union

public static PolyList union(PolyList alpha,
                             PolyList zappa)
Generate the union of two PolyLists.

Parameters:
alpha - A region of 2-dimensional space to unify.
zappa - Another region of 2-dimensional space to unify.
Returns:
A new PolyList representing the the space covered by both regions.

intersection

public static PolyList intersection(PolyList alpha,
                                    PolyList zappa)
Find the intersection of two PolyLists.

Parameters:
alpha - A region of 2-dimensional space.
zappa - Another region of 2-dimensional space to intersect with.
Returns:
A new PolyList representing the shared region.

getIntersection

public PolyList getIntersection(PolyList other)
Get the intersection of this PolyList with another.

Parameters:
other - The region to intersect with.
Returns:
A new PolyList that represents the shared region.

initBbox

protected void initBbox()
Creates a BoundingBox around this, for use by getBoundingBox, etc. This is called whenever the bbox is requested and it is currently set to null; the bbox field therefore acts as a dirty bit.


getBoundingBox

public BoundingBox getBoundingBox()
Gets the closest box around the set of polygons.

Returns:
the closest box around the set of polygons

getPolys

protected java.util.Iterator getPolys()
Gets an iterator that goes through a list of polygons that are contained within this region, such that the union of all of them is equal to this region.

Returns:
An Iterator that goes through the region.

getOriginals

public java.util.Iterator getOriginals()
Gets the original list of polygons added to this list, instead of the list of non-overlapping ones.

Returns:
an iterator of PolyLists.

contains

public boolean contains(Pnt point)
Tests to see if one of the subpolys contains the given point.

Parameters:
point - the point to test for
Returns:
true if the point is somoewhere within the polylist

clearPolyList

protected void clearPolyList()

addPoly

protected void addPoly(PolyList shape)
Sets this PolyList into this unioned with the given shape.

Parameters:
shape - the region to add to this.

getConvexPolygonArray

public ConvexPolygon[] getConvexPolygonArray()
Gets an array of non-overlapping ConvexPolygons whose union completely tiles the region described by this PolyList.

Returns:
a non-overlapping set of ConvexPolygons

getFragmentationCount

public int getFragmentationCount(PolyList other)
Gets a count of how many original polygons the other hits.

Parameters:
other - the polygon to test against
Returns:
the number of original polygons within the other that this polylist intersects

intersects

public boolean intersects(PolyList other)
Tests to see if this region intersects the given region.

Parameters:
other -
Returns:

getPoints

public java.util.Iterator getPoints()
Gets the points in the polygon; to be implemented by the concrete subclasses.

Returns:
the empty iterator

addVertex

public boolean addVertex(Pnt p)
                  throws BadDataException
Adds the vertex to the polygon this represents; this is unimplemented in this root class.

Parameters:
p - the point to add
Returns:
true if the addition of the point changes the shape
Throws:
BadDataException - if the point cannot be added
java.lang.UnsupportedOperationException - in this root class