java.lang.Objectcomputational.geometry.Polygon
public class Polygon
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 |
---|
protected java.util.Map vertices
Constructor Detail |
---|
public Polygon()
public Polygon(java.util.List points)
public Polygon(Polygon poly)
public Polygon(java.lang.String label)
public Polygon(java.lang.String label, java.util.List points)
Method Detail |
---|
public boolean addVertex(Point p) throws SimplicityViolatedException, ConvexityViolatedException
SimplicityViolatedException
ConvexityViolatedException
public boolean addVertex(Point p, Segment s) throws SimplicityViolatedException, ConvexityViolatedException
SimplicityViolatedException
ConvexityViolatedException
public double area()
public Rectangle boundingBox()
public void clear()
public java.lang.Object clone()
clone
in class java.lang.Object
public boolean contains(Point p)
Shape
contains
in interface Shape
p
- the point we test for encloseness.
public boolean deleteVertex(java.lang.Integer index) throws SimplicityViolatedException, ConvexityViolatedException
SimplicityViolatedException
ConvexityViolatedException
public boolean deleteVertex(Point p) throws SimplicityViolatedException, ConvexityViolatedException
SimplicityViolatedException
ConvexityViolatedException
public void draw(java.awt.Graphics gfx)
Shape
draw
in interface Shape
gfx
- the graphics context where this shape has to be drawn.public void drawLabels(java.awt.Graphics gfx)
Shape
drawLabels
in interface Shape
gfx
- the graphics context where this shape's labels have
to be drawn.public void drawPoints(java.awt.Graphics gfx)
Shape
drawPoints
in interface Shape
gfx
- the graphics context where this shape's points have
to be drawn.public boolean equals(java.lang.Object obj)
Polygon
are equal if their vertices,
taken in some order, are equal.
equals
in class java.lang.Object
obj
- an object to be compared with this Polygon
true
if the object to be compared is
an instance of Polygon
and has
the same vertices; false
otherwise.public Polygon.Vertex getBottomVertex()
public Polygon.Edge getEdge(int index)
public java.util.List getEdges()
public Polygon.Vertex getFirstVertex()
public java.util.List getIndices()
public java.lang.String getLabel()
null
.
getLabel
in interface Shape
public Polygon.Vertex getLeftVertex()
public Polygon.Vertex getNext(Polygon.Vertex v)
public java.util.List getPoints()
getPoints
in interface Shape
public Polygon.Vertex getPrevious(Polygon.Vertex v)
public Polygon.Vertex getRightVertex()
public Polygon.Vertex getTopVertex()
public Polygon.Vertex getVertex(int index)
public java.util.List getVertices()
public java.lang.Integer indexOf(Point p)
public boolean isClockwiseOriented()
public boolean isConvex()
public boolean isSimple()
public boolean moveVertex(java.lang.Integer index, int dx, int dy) throws SimplicityViolatedException, ConvexityViolatedException
SimplicityViolatedException
ConvexityViolatedException
public boolean moveVertex(Point p, int dx, int dy) throws SimplicityViolatedException, ConvexityViolatedException
SimplicityViolatedException
ConvexityViolatedException
public double perimeter()
protected void restore(Polygon memento)
public void setLabel(java.lang.String label)
setLabel
in interface Shape
the
- polygon's new label.public int size()
public java.lang.String toString()
toString
in class java.lang.Object
public void translate(int dx, int dy)
Shape
translate
in interface Shape
dx
- the amount to translate along the X-axispublic void updateExtremeVertices()