public class ShapeMap extends java.lang.Object implements java.lang.Iterable<Polygon2D>
NOTE: This class uses the Polygon2D and Point2D classes.
NOTE: Requires Sedgewick's and Wayne's StdDraw library.
Constructor and Description |
---|
ShapeMap()
Construct an empty ShapeMap.
|
ShapeMap(java.util.ArrayList<Polygon2D> polys,
Point2D src,
Point2D dest)
Construct a ShapeMap with a specified set of polygons and a specified source and destination point.
|
ShapeMap(Point2D src,
Point2D dest)
Construct a ShapeMap with a specified source and destination point.
|
ShapeMap(java.lang.String fileName)
Construct a ShapeMap using a specified input map file.
|
Modifier and Type | Method and Description |
---|---|
void |
addPolygon(Polygon2D poly)
Add a new polygon shape to this map.
|
Point2D |
destinationPoint()
Get the destination point (path ending point) of this map.
|
void |
draw()
Draw perimeter of each polygon in this ShapeMap.
|
void |
draw(java.awt.Color clr)
Draw perimeter of each polygon in this ShapeMap, with a given color.
|
void |
draw(java.awt.Color clr,
double penWidth)
Draw perimeter of each polygon in this ShapeMap, with a given color and pen width.
|
void |
drawFilled()
Draw and fill each polygon in this ShapeMap.
|
void |
drawFilled(java.awt.Color clr)
Draw and fill each polygon in this ShapeMap, with a given color.
|
java.util.List<Point2D> |
getAllPoints()
Get all points of all polygons in this shape map - does not include the source and destination points.
|
java.util.Iterator<Polygon2D> |
iterator()
Iterator supporting for-each style iteration over all polygons in this map.
|
static void |
shapeMapDemo()
Demonstrates construction and drawing of a shape map containing a single polygon.
|
Point2D |
sourcePoint()
Get the source point (path starting point) of this map.
|
public ShapeMap()
public ShapeMap(java.util.ArrayList<Polygon2D> polys, Point2D src, Point2D dest)
polys
- the list of polygons to construct the map withsrc
- the path source (starting) pointdest
- the path destination (ending) pointpublic ShapeMap(Point2D src, Point2D dest)
src
- the path source (starting) pointdest
- the path destination (ending) pointpublic ShapeMap(java.lang.String fileName)
fileName
- to load map frompublic void addPolygon(Polygon2D poly)
poly
- the polygon to add to the mappublic Point2D destinationPoint()
public void draw()
public void draw(java.awt.Color clr)
clr
- the pen color to usepublic void draw(java.awt.Color clr, double penWidth)
clr
- the pen color to usepenWidth
- width of the pen to usepublic void drawFilled()
public void drawFilled(java.awt.Color clr)
clr
- the pen color to usepublic java.util.List<Point2D> getAllPoints()
public java.util.Iterator<Polygon2D> iterator()
for (Polygon2D poly : sm) { poly.draw(); } // sm a ShapeMap object
iterator
in interface java.lang.Iterable<Polygon2D>
public static void shapeMapDemo()
public Point2D sourcePoint()