GlobalNavigation
Class PolygonObstacle

java.lang.Object
  extended by GlobalNavigation.PolygonObstacle

public class PolygonObstacle
extends java.lang.Object

Represents a polygonal obstacle.

Obstacles are initially empty (i.e. no vertices). Vertices are then added with any of the addVertex() methods, in CCW order. close() is then called to finish the polygon. From then on, the polygon is immutable.


Field Summary
protected  boolean closed
          Whether this polygon has been closed.
 java.awt.Color color
           
protected  java.awt.geom.GeneralPath path
          Underlying implementation of the geometry.
protected  boolean started
          Whether this polygon has been started.
 
Constructor Summary
PolygonObstacle()
           
 
Method Summary
 void addVertex(double x, double y)
          Covers addVertex(float, float).
 void addVertex(float x, float y)
          Add a vertex to this polygon.
 void addVertex(java.awt.geom.Point2D vertex)
          Covers addVertex(double, double).
 void close()
          Close this polygon.
 boolean contains(double x, double y)
          Check whether this obstacle polygon contains a point.
 boolean contains(java.awt.geom.Point2D p)
          Check whether this obstacle polygon contains a point.
 java.util.List<java.awt.geom.Point2D.Double> getVertices()
          Covers getVertices(List), always makes a new list.
 java.util.List<java.awt.geom.Point2D.Double> getVertices(java.util.List<java.awt.geom.Point2D.Double> vertices)
          Get the vertices of this polygon in the order in which they were added.
 boolean intersects(double x, double y, double w, double h)
          Check whether a rectangle intersects this obstacle polygon.
 boolean intersects(java.awt.geom.Rectangle2D r)
          Check whether a rectangle intersects this obstacle polygon.
 java.lang.String toString()
          Covers toStringBuffer(java.lang.StringBuffer), internally conses a StringBuffer.
 void toStringBuffer(java.lang.StringBuffer sb)
          Append a human-readable string representation of this obstacle to a StringBuffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

path

protected java.awt.geom.GeneralPath path

Underlying implementation of the geometry.


started

protected boolean started

Whether this polygon has been started.


closed

protected boolean closed

Whether this polygon has been closed.


color

public java.awt.Color color
Constructor Detail

PolygonObstacle

public PolygonObstacle()
Method Detail

addVertex

public void addVertex(java.awt.geom.Point2D vertex)

Covers addVertex(double, double).


addVertex

public void addVertex(double x,
                      double y)

Covers addVertex(float, float).


addVertex

public void addVertex(float x,
                      float y)

Add a vertex to this polygon.

Vertices must be added in CCW order.

Throws:
java.lang.IllegalStateException - iff closed

close

public void close()

Close this polygon.

Throws:
java.lang.IllegalStateException - iff not started or already closed

contains

public boolean contains(double x,
                        double y)

Check whether this obstacle polygon contains a point.

Parameters:
x - the point x coord
y - the point y coord

contains

public boolean contains(java.awt.geom.Point2D p)

Check whether this obstacle polygon contains a point.

Parameters:
p - the point

intersects

public boolean intersects(double x,
                          double y,
                          double w,
                          double h)

Check whether a rectangle intersects this obstacle polygon.

Parameters:
x - the rectangle llc x coord
y - the rectangle llc y coord
w - the rectangle width
h - the rectangle height

intersects

public boolean intersects(java.awt.geom.Rectangle2D r)

Check whether a rectangle intersects this obstacle polygon.

Parameters:
r - the rectangle

getVertices

public java.util.List<java.awt.geom.Point2D.Double> getVertices()

Covers getVertices(List), always makes a new list.


getVertices

public java.util.List<java.awt.geom.Point2D.Double> getVertices(java.util.List<java.awt.geom.Point2D.Double> vertices)

Get the vertices of this polygon in the order in which they were added.

Parameters:
vertices - if non-null the vertices are added to this list (else a fresh one is consed)
Returns:
the vertices

toString

public java.lang.String toString()

Covers toStringBuffer(java.lang.StringBuffer), internally conses a StringBuffer.

Overrides:
toString in class java.lang.Object

toStringBuffer

public void toStringBuffer(java.lang.StringBuffer sb)

Append a human-readable string representation of this obstacle to a StringBuffer.

Parameters:
sb - the StringBuffer