ProGAL.geom2d
Class Polygon

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<Point>
              extended by ProGAL.geom2d.Polygon
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<Point>, java.util.Collection<Point>, java.util.List<Point>, java.util.RandomAccess, Shape
Direct Known Subclasses:
ConvexPolygon

public class Polygon
extends java.util.ArrayList<Point>
implements Shape

See Also:
Serialized Form

Constructor Summary
Polygon()
           
Polygon(java.util.List<Point> corners)
           
Polygon(Point[] points)
           
Polygon(Point p0, Point p1, Point p2)
           
Polygon(PointSet points)
           
 
Method Summary
 void deleteLast()
          deletes last corner of the polygon
 void draw(J2DScene scene)
           
 void draw(J2DScene scene, java.awt.Color clr)
          draws the polygon
 Point getCenter()
          Get the geometric center of the shape.
 ConvexPolygon getConvexPolygon()
          returns convex hull of a simple polygon in O(n) time
 Point getCorner(int i)
           
 void insertAfter(Point p, int index)
          inserts point p into the polygon after the corner with specified index
 boolean isConvex()
           
 int leftExtremePointIndx()
          returns the index of the leftmost point (in case of ties, index of the bottommost one is returned)
static void main(java.lang.String[] args)
           
 int rightExtremePointIndx()
          returns the index of the rightmost point (in case of ties, index of the topmost one is returned)
 void setCorner(Point p, int i)
           
 void shift(int shiftStep)
          first corner of the polygon is moved by shiftStep positions
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, remove, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, removeAll, retainAll, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, removeAll, retainAll, subList
 

Constructor Detail

Polygon

public Polygon()

Polygon

public Polygon(java.util.List<Point> corners)

Polygon

public Polygon(Point p0,
               Point p1,
               Point p2)

Polygon

public Polygon(PointSet points)

Polygon

public Polygon(Point[] points)
Method Detail

getCorner

public Point getCorner(int i)

setCorner

public void setCorner(Point p,
                      int i)

insertAfter

public void insertAfter(Point p,
                        int index)
inserts point p into the polygon after the corner with specified index


deleteLast

public void deleteLast()
deletes last corner of the polygon


leftExtremePointIndx

public int leftExtremePointIndx()
returns the index of the leftmost point (in case of ties, index of the bottommost one is returned)


rightExtremePointIndx

public int rightExtremePointIndx()
returns the index of the rightmost point (in case of ties, index of the topmost one is returned)


shift

public void shift(int shiftStep)
first corner of the polygon is moved by shiftStep positions


isConvex

public boolean isConvex()

getCenter

public Point getCenter()
Description copied from interface: Shape
Get the geometric center of the shape. The center of a shape can be interpreted in many ways (center of mass, circumcenter, inscribed center etc.). No strict requirement is given here, but typically the circumcenter should be supplied. This method is most prominently used to find the average center-position of a collection of shapes such that scene-viewers can be centered on the scene.

Specified by:
getCenter in interface Shape

draw

public void draw(J2DScene scene,
                 java.awt.Color clr)
draws the polygon


draw

public void draw(J2DScene scene)

getConvexPolygon

public ConvexPolygon getConvexPolygon()
returns convex hull of a simple polygon in O(n) time


main

public static void main(java.lang.String[] args)