org.starhope.appius.geometry
Class Polygon

java.lang.Object
  extended by org.starhope.appius.geometry.Polygon
All Implemented Interfaces:
PolygonPrimitive<Polygon>

public class Polygon
extends Object
implements PolygonPrimitive<Polygon>

General polygon consisting of a series of line segments

Author:
ewinkelman

Field Summary
protected  Circle boundingCircle
          WRITEME: Document this brpocock@star-hope.org
protected  Rectangle boundingRectangle
          Bounding rectangle
protected  Coord2D[] points
          WRITEME: Document this brpocock@star-hope.org
protected  LineSeg2D[] segments
          WRITEME: Document this brpocock@star-hope.org
 
Constructor Summary
  Polygon(Coord2D... newPoints)
          Constructs a closed polygon using the given set of points as line segments
private Polygon(Coord2D[] newPoints, LineSeg2D[] newSegments, Circle newBoundingCircle)
          Private constructor used during internal changes to avoid the overhead of recalcuating bounding stuff ASSUMES you know what you're doing!
  Polygon(double[] xPoints, double[] yPoints)
          Constructs a polygon from a pair of arrays.
  Polygon(List<Coord2D> newPoints)
          WRITEME: Document this constructor brpocock@star-hope.org
 
Method Summary
private  void computeBounds()
          Computes a rough bounding circle and rectangle
private  LineSeg2D[] computeSegments()
          Computes the line segments for the polygon
 boolean contains(Coord2D coord2d)
          Tests to see if we are inside of the polygon.
 boolean contains(double x, double y)
          Determines if the polygon contains that point
 Circle getBoundingCircle()
           
 Rectangle getBoundingRectangle()
          WRITEME: Document this method brpocock@star-hope.org
 Coord2D getCenter()
           
 Coord2D[] getPoints()
           
 LineSeg2D[] getSegments()
           
 Coord2D[] intersection(LineSeg2D lSeg2d)
          Gets all the intersection points between two polygons
 boolean intersects(LineSeg2D lSeg2d)
          Determines if the polygon intersects the line segment
 boolean intersects(PolygonPrimitive<?> polygon)
           Determines if this polygon intersects with another one
 boolean intersectsCircle(Circle circle)
          WRITEME: Document this method brpocock@star-hope.org
 boolean intersectsPoly(Polygon polygon)
          WRITEME: Document this method brpocock@star-hope.org
 boolean intersectsRect(Rectangle rectangle)
          WRITEME: Document this method brpocock@star-hope.org
 Polygon scale(double sizeScalar)
          WRITEME: Document this method brpocock@star-hope.org
 String toRoomVar()
           
 String toString()
          format roughly {(x,y),(x,y)…}
 Polygon translate(Coord2D coord2d)
          WRITEME: Document this method brpocock@star-hope.org
 Polygon translate(double x, double y)
          Translates the object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

boundingCircle

protected Circle boundingCircle
WRITEME: Document this brpocock@star-hope.org


boundingRectangle

protected Rectangle boundingRectangle
Bounding rectangle


points

protected final Coord2D[] points
WRITEME: Document this brpocock@star-hope.org


segments

protected final LineSeg2D[] segments
WRITEME: Document this brpocock@star-hope.org

Constructor Detail

Polygon

public Polygon(Coord2D... newPoints)
Constructs a closed polygon using the given set of points as line segments

Parameters:
newPoints - The points to use to construct the polygon

Polygon

private Polygon(Coord2D[] newPoints,
                LineSeg2D[] newSegments,
                Circle newBoundingCircle)
Private constructor used during internal changes to avoid the overhead of recalcuating bounding stuff ASSUMES you know what you're doing!

Parameters:
newPoints - WRITEME
newSegments - WRITEME
newBoundingCircle - WRITEME

Polygon

public Polygon(double[] xPoints,
               double[] yPoints)
        throws ParameterException
Constructs a polygon from a pair of arrays. Assumes that the arrays of like indexes form coordinate points from which it can assemble the polygon into line segments

Parameters:
xPoints - Array of x coordinate points
yPoints - Array of y coordinate points
Throws:
ParameterException - The number of x and y coordinates must match

Polygon

public Polygon(List<Coord2D> newPoints)
WRITEME: Document this constructor brpocock@star-hope.org

Parameters:
newPoints - WRITEME
Method Detail

computeBounds

private void computeBounds()
Computes a rough bounding circle and rectangle


computeSegments

private LineSeg2D[] computeSegments()
Computes the line segments for the polygon

Returns:
WRITEME

contains

public boolean contains(Coord2D coord2d)
Tests to see if we are inside of the polygon. Will give incorrect results if the polygon exceeds 100 000 units in size

Specified by:
contains in interface PolygonPrimitive<Polygon>
Parameters:
coord2d - WRITEME
Returns:
WRITEME
See Also:
PolygonPrimitive.contains(org.starhope.appius.geometry.Coord2D)

contains

public boolean contains(double x,
                        double y)
Description copied from interface: PolygonPrimitive
Determines if the polygon contains that point

Specified by:
contains in interface PolygonPrimitive<Polygon>
Parameters:
x - WRITEME
y - WRITEME
Returns:
WRITEME
See Also:
PolygonPrimitive.contains(double, double)

getBoundingCircle

public Circle getBoundingCircle()
Returns:
WRITEME

getBoundingRectangle

public Rectangle getBoundingRectangle()
WRITEME: Document this method brpocock@star-hope.org

Returns:
WRITEME

getCenter

public Coord2D getCenter()
Specified by:
getCenter in interface PolygonPrimitive<Polygon>
Returns:
the center point
See Also:
PolygonPrimitive.getCenter()

getPoints

public Coord2D[] getPoints()
Returns:
the points

getSegments

public LineSeg2D[] getSegments()
Returns:
the segments

intersection

public Coord2D[] intersection(LineSeg2D lSeg2d)
Gets all the intersection points between two polygons

Specified by:
intersection in interface PolygonPrimitive<Polygon>
Parameters:
lSeg2d - WRITEME
Returns:
WRITEME
See Also:
PolygonPrimitive.intersection(org.starhope.appius.geometry.LineSeg2D)

intersects

public boolean intersects(LineSeg2D lSeg2d)
Description copied from interface: PolygonPrimitive
Determines if the polygon intersects the line segment

Specified by:
intersects in interface PolygonPrimitive<Polygon>
Parameters:
lSeg2d - WRITEME
Returns:
WRITEME
See Also:
PolygonPrimitive.intersects(org.starhope.appius.geometry.LineSeg2D)

intersects

public boolean intersects(PolygonPrimitive<?> polygon)

Determines if this polygon intersects with another one

XXX: There has to be a better way than this

Specified by:
intersects in interface PolygonPrimitive<Polygon>
Parameters:
polygon - WRITEME
Returns:
WRITEME

intersectsCircle

public boolean intersectsCircle(Circle circle)
WRITEME: Document this method brpocock@star-hope.org

Specified by:
intersectsCircle in interface PolygonPrimitive<Polygon>
Parameters:
circle - WRITEME
Returns:
WRITEME

intersectsPoly

public boolean intersectsPoly(Polygon polygon)
WRITEME: Document this method brpocock@star-hope.org

Specified by:
intersectsPoly in interface PolygonPrimitive<Polygon>
Parameters:
polygon - WRITEME
Returns:
WRITEME

intersectsRect

public boolean intersectsRect(Rectangle rectangle)
WRITEME: Document this method brpocock@star-hope.org

Specified by:
intersectsRect in interface PolygonPrimitive<Polygon>
Parameters:
rectangle - WRITEME
Returns:
WRITEME

scale

public Polygon scale(double sizeScalar)
Description copied from interface: PolygonPrimitive
WRITEME: Document this method brpocock@star-hope.org

Specified by:
scale in interface PolygonPrimitive<Polygon>
Parameters:
sizeScalar - WRITEME
Returns:
WRITEME
See Also:
PolygonPrimitive.scale(double)

toRoomVar

public String toRoomVar()
Returns:
a string in x,y~x,y notation for room variables

toString

public String toString()
format roughly {(x,y),(x,y)…}

Overrides:
toString in class Object
See Also:
Object.toString()

translate

public Polygon translate(Coord2D coord2d)
Description copied from interface: PolygonPrimitive
WRITEME: Document this method brpocock@star-hope.org

Specified by:
translate in interface PolygonPrimitive<Polygon>
Parameters:
coord2d - The amount to move
Returns:
WRITEME
See Also:
PolygonPrimitive.translate(org.starhope.appius.geometry.Coord2D)

translate

public Polygon translate(double x,
                         double y)
Description copied from interface: PolygonPrimitive
Translates the object

Specified by:
translate in interface PolygonPrimitive<Polygon>
Parameters:
x - The amount to move on the x-axis
y - The amount to move on the y-axis
Returns:
WRITEME
See Also:
PolygonPrimitive.translate(double, double)