computational.geometry
Class Polygon

java.lang.Object
  extended by computational.geometry.Polygon
All Implemented Interfaces:
Shape, java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
SimplePolygon

public class Polygon
extends java.lang.Object
implements Shape, java.lang.Cloneable, java.io.Serializable

See Also:
Serialized Form

Nested Class Summary
 class Polygon.Edge
           
static class Polygon.Vertex
           
 
Field Summary
protected  java.util.Map vertices
          Set of polygon's indexed vertices.
 
Constructor Summary
Polygon()
          CONSTRUCTORS
Polygon(java.util.List points)
           
Polygon(Polygon poly)
           
Polygon(java.lang.String label)
           
Polygon(java.lang.String label, java.util.List points)
           
 
Method Summary
 boolean addVertex(Point p)
          SET METHODS
 boolean addVertex(Point p, Segment s)
           
 double area()
          POLYGON AREA
 Rectangle boundingBox()
           
 void clear()
           
 java.lang.Object clone()
          Object Extension
 boolean contains(Point p)
          Tells whether the shape encloses a given point.
 boolean deleteVertex(java.lang.Integer index)
           
 boolean deleteVertex(Point p)
           
 void draw(java.awt.Graphics gfx)
          Draws the shape, using the current graphics context's color.
 void drawLabels(java.awt.Graphics gfx)
          Draws the shape's associated labels, using the graphics context's color.
 void drawPoints(java.awt.Graphics gfx)
          Draws the shape's defining points, using the graphics context's color.
 boolean equals(java.lang.Object obj)
          Determines whether or not two polygons are equal.
 Polygon.Vertex getBottomVertex()
           
 Polygon.Edge getEdge(int index)
           
 java.util.List getEdges()
           
 Polygon.Vertex getFirstVertex()
           
 java.util.List getIndices()
           
 java.lang.String getLabel()
          Returns the string label associated to this polygon.
 Polygon.Vertex getLeftVertex()
           
 Polygon.Vertex getNext(Polygon.Vertex v)
           
 java.util.List getPoints()
          Shape Implementation
 Polygon.Vertex getPrevious(Polygon.Vertex v)
           
 Polygon.Vertex getRightVertex()
           
 Polygon.Vertex getTopVertex()
          FINDING EXTREME VERTICES
 Polygon.Vertex getVertex(int index)
           
 java.util.List getVertices()
           
 java.lang.Integer indexOf(Point p)
           
 boolean isClockwiseOriented()
          Checking polygon properties
 boolean isConvex()
           
 boolean isSimple()
           
 boolean moveVertex(java.lang.Integer index, int dx, int dy)
           
 boolean moveVertex(Point p, int dx, int dy)
           
 double perimeter()
          POLYGON PERIMETER
protected  void restore(Polygon memento)
           
 void setLabel(java.lang.String label)
          Sets the polygon's label.
 int size()
          GET METHODS
 java.lang.String toString()
          Returns a string representation of this polygon.
 void translate(int dx, int dy)
          Translates the shape by the given amount.
 void updateExtremeVertices()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

vertices

protected java.util.Map vertices
Set of polygon's indexed vertices.

Constructor Detail

Polygon

public Polygon()
CONSTRUCTORS


Polygon

public Polygon(java.util.List points)

Polygon

public Polygon(Polygon poly)

Polygon

public Polygon(java.lang.String label)

Polygon

public Polygon(java.lang.String label,
               java.util.List points)
Method Detail

addVertex

public boolean addVertex(Point p)
                  throws SimplicityViolatedException,
                         ConvexityViolatedException
SET METHODS

Throws:
SimplicityViolatedException
ConvexityViolatedException

addVertex

public boolean addVertex(Point p,
                         Segment s)
                  throws SimplicityViolatedException,
                         ConvexityViolatedException
Throws:
SimplicityViolatedException
ConvexityViolatedException

area

public double area()
POLYGON AREA


boundingBox

public Rectangle boundingBox()

clear

public void clear()

clone

public java.lang.Object clone()
Object Extension

Overrides:
clone in class java.lang.Object

contains

public boolean contains(Point p)
Description copied from interface: Shape
Tells whether the shape encloses a given point. To the aims of this test, we consider the shape to be closed, so that a point lying on the shape's boundaries results as enclosed in the shape.

Specified by:
contains in interface Shape
Parameters:
p - the point we test for encloseness.
Returns:
true iff the point is enclosed in the shape.

deleteVertex

public boolean deleteVertex(java.lang.Integer index)
                     throws SimplicityViolatedException,
                            ConvexityViolatedException
Throws:
SimplicityViolatedException
ConvexityViolatedException

deleteVertex

public boolean deleteVertex(Point p)
                     throws SimplicityViolatedException,
                            ConvexityViolatedException
Throws:
SimplicityViolatedException
ConvexityViolatedException

draw

public void draw(java.awt.Graphics gfx)
Description copied from interface: Shape
Draws the shape, using the current graphics context's color.

Specified by:
draw in interface Shape
Parameters:
gfx - the graphics context where this shape has to be drawn.

drawLabels

public void drawLabels(java.awt.Graphics gfx)
Description copied from interface: Shape
Draws the shape's associated labels, using the graphics context's color.

Specified by:
drawLabels in interface Shape
Parameters:
gfx - the graphics context where this shape's labels have to be drawn.

drawPoints

public void drawPoints(java.awt.Graphics gfx)
Description copied from interface: Shape
Draws the shape's defining points, using the graphics context's color.

Specified by:
drawPoints in interface Shape
Parameters:
gfx - the graphics context where this shape's points have to be drawn.

equals

public boolean equals(java.lang.Object obj)
Determines whether or not two polygons are equal. Two instances of Polygon are equal if their vertices, taken in some order, are equal.

Overrides:
equals in class java.lang.Object
Parameters:
obj - an object to be compared with this Polygon
Returns:
true if the object to be compared is an instance of Polygon and has the same vertices; false otherwise.

getBottomVertex

public Polygon.Vertex getBottomVertex()

getEdge

public Polygon.Edge getEdge(int index)

getEdges

public java.util.List getEdges()

getFirstVertex

public Polygon.Vertex getFirstVertex()

getIndices

public java.util.List getIndices()

getLabel

public java.lang.String getLabel()
Returns the string label associated to this polygon. The returned string may possibly be empty, but may never be null.

Specified by:
getLabel in interface Shape
Returns:
the string label associated to this point.

getLeftVertex

public Polygon.Vertex getLeftVertex()

getNext

public Polygon.Vertex getNext(Polygon.Vertex v)

getPoints

public java.util.List getPoints()
Shape Implementation

Specified by:
getPoints in interface Shape
Returns:
the shape's cloned defining points.

getPrevious

public Polygon.Vertex getPrevious(Polygon.Vertex v)

getRightVertex

public Polygon.Vertex getRightVertex()

getTopVertex

public Polygon.Vertex getTopVertex()
FINDING EXTREME VERTICES


getVertex

public Polygon.Vertex getVertex(int index)

getVertices

public java.util.List getVertices()

indexOf

public java.lang.Integer indexOf(Point p)

isClockwiseOriented

public boolean isClockwiseOriented()
Checking polygon properties


isConvex

public boolean isConvex()

isSimple

public boolean isSimple()

moveVertex

public boolean moveVertex(java.lang.Integer index,
                          int dx,
                          int dy)
                   throws SimplicityViolatedException,
                          ConvexityViolatedException
Throws:
SimplicityViolatedException
ConvexityViolatedException

moveVertex

public boolean moveVertex(Point p,
                          int dx,
                          int dy)
                   throws SimplicityViolatedException,
                          ConvexityViolatedException
Throws:
SimplicityViolatedException
ConvexityViolatedException

perimeter

public double perimeter()
POLYGON PERIMETER


restore

protected void restore(Polygon memento)

setLabel

public void setLabel(java.lang.String label)
Sets the polygon's label.

Specified by:
setLabel in interface Shape
Parameters:
the - polygon's new label.

size

public int size()
GET METHODS


toString

public java.lang.String toString()
Returns a string representation of this polygon. The string is composed of the polygon's label (if any), and the vertices' string representations.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of this polygon.

translate

public void translate(int dx,
                      int dy)
Description copied from interface: Shape
Translates the shape by the given amount.

Specified by:
translate in interface Shape
Parameters:
dx - the amount to translate along the X-axis

updateExtremeVertices

public void updateExtremeVertices()