public class Shape extends Object
Shape class represents a collection of Points that can easily
model a polygonal shape. Points can be added in order via code or given using a file, one
point per line separated by a comma. The points can then be accessed in the order they were
added one at a time, using the method getPoints.
Example usage:
Point a = new Point(3, 4);
Point b = new Point(2, 5);
Shape s = new Shape();
s.addPoint(a);
s.addPoint(b);
s.addPoint(new Point(1, 1));
for (Point p : s.getPoints()) {
System.out.println(p);
}
A Shape can also be created using file in the following format:
3, 4 2, 5 1, 1
Example file usage:
FileResource fr = new FileResource();
Shape s = new Shape(fr);
for (Point p : s.getPoints()) {
System.out.println(p);
}
This software is licensed with an Apache 2 license, see http://www.apache.org/licenses/LICENSE-2.0 for details.
| Constructor and Description |
|---|
Shape()
Create an empty
Shape object, one with no points. |
Shape(FileResource file)
Create a
Shape object from a file with x,y coordinates
of points, in order, one pair of x,y per line. |
| Modifier and Type | Method and Description |
|---|---|
void |
addPoint(Point p)
Add a point to this shape/polygon.
|
Point |
getLastPoint()
Return the last point added to this shape/polygon
|
Iterable<Point> |
getPoints()
Allow access to this shape one point at a time.
|
public Shape()
Shape object, one with no points.public Shape(FileResource file)
Shape object from a file with x,y coordinates
of points, in order, one pair of x,y per line.
Each x,y are comma-separated, e.g.,
3,4 -2,5whitespace on line is skipped.
file - is the FileResource accessible and bound to a file
with one pair of points per linepublic void addPoint(Point p)
p - is the Point added to this shapepublic Point getLastPoint()