edu.rit.draw.item
Class Polygon
- java.lang.Object
-
- edu.rit.draw.item.DrawingItem
-
- edu.rit.draw.item.OutlinedItem
-
- edu.rit.draw.item.FilledItem
-
- edu.rit.draw.item.ShapeItem
-
- edu.rit.draw.item.Polygon
-
- All Implemented Interfaces:
- java.io.Externalizable, java.io.Serializable
public class Polygon extends ShapeItem
Class Polygon provides a polygon DrawingItem whose boundary consists of one or more straight line segments. The polygon has an outline and a filled interior.- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class edu.rit.draw.item.FilledItem
NORMAL_FILL
-
Fields inherited from class edu.rit.draw.item.OutlinedItem
NORMAL_OUTLINE
-
-
Constructor Summary
Constructors Constructor and Description Polygon()Construct a new polygon.Polygon(Polygon thePolygon)Construct a new polygon with the same points, outline, and fill paint as the given polygon.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description Polygonadd()Add this polygon to the end of the default drawing's sequence of drawing items.Polygonadd(Drawing theDrawing)Add this polygon to the end of the given drawing's sequence of drawing items.PolygonaddFirst()Add this polygon to the beginning of the default drawing's sequence of drawing items.PolygonaddFirst(Drawing theDrawing)Add this polygon to the beginning of the given drawing's sequence of drawing items.Polygonby(double dx, double dy)Add a line segment to this polygon.Polygonby(Size theSize)Add a line segment to this polygon.Polygonclear()Clear this polygon.Polygonfill(Fill theFill)Set this polygon's fill paint.Polygonhby(double dx)Add a horizontal line segment to this polygon.Polygonhby(Size theSize)Add a horizontal line segment to this polygon.doubleheight()Returns the height of this polygon's bounding box.Polygonhto(double x)Add a horizontal line segment to this polygon.Polygonhto(Point thePoint)Add a horizontal line segment to this polygon.Pointnw()Returns the northwest corner point of this polygon's bounding box.Polygonoutline(Outline theOutline)Set this polygon's outline.voidreadExternal(java.io.ObjectInput in)Read this polygon from the given object input stream.Sizesize()Returns the size of this polygon's bounding box.Polygonto(double x, double y)Add a line segment to this polygon.Polygonto(Point thePoint)Add a line segment to this polygon.Polygonvby(double dy)Add a vertical line segment to this polygon.Polygonvby(Size theSize)Add a vertical line segment to this polygon.Polygonvto(double y)Add a vertical line segment to this polygon.Polygonvto(Point thePoint)Add a vertical line segment to this polygon.doublewidth()Returns the width of this polygon's bounding box.voidwriteExternal(java.io.ObjectOutput out)Write this polygon to the given object output stream.-
Methods inherited from class edu.rit.draw.item.FilledItem
defaultFill, defaultFill, fill
-
Methods inherited from class edu.rit.draw.item.OutlinedItem
defaultOutline, defaultOutline, outline
-
Methods inherited from class edu.rit.draw.item.DrawingItem
boundingBox, c, e, n, ne, s, se, sw, w
-
-
-
-
Constructor Detail
-
Polygon
public Polygon()
Construct a new polygon. The polygon has no points initially. The default outline and fill paint are used.
-
Polygon
public Polygon(Polygon thePolygon)
Construct a new polygon with the same points, outline, and fill paint as the given polygon.- Parameters:
thePolygon- Polygon.- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if thePolygon is null.
-
-
Method Detail
-
size
public Size size()
Returns the size of this polygon's bounding box.- Overrides:
sizein classDrawingItem- Returns:
- Size.
-
width
public double width()
Returns the width of this polygon's bounding box.- Specified by:
widthin classDrawingItem- Returns:
- Width.
-
height
public double height()
Returns the height of this polygon's bounding box.- Specified by:
heightin classDrawingItem- Returns:
- Height.
-
nw
public Point nw()
Returns the northwest corner point of this polygon's bounding box.- Specified by:
nwin classDrawingItem- Returns:
- Northwest corner point.
-
clear
public Polygon clear()
Clear this polygon. All of this polygon's line segments are removed.- Returns:
- This polygon.
-
to
public Polygon to(double x, double y)
Add a line segment to this polygon. The new endpoint is (x, y). If this polygon has no line segments, the to() method specifies this polygon's starting endpoint.- Parameters:
x- Endpoint's X coordinate.y- Endpoint's Y coordinate.- Returns:
- This polygon.
-
to
public Polygon to(Point thePoint)
Add a line segment to this polygon. The new endpoint is thePoint. If this polygon has no line segments, the to() method specifies this polygon's starting endpoint.- Parameters:
thePoint- Endpoint.- Returns:
- This polygon.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if thePoint is null.
-
hto
public Polygon hto(double x)
Add a horizontal line segment to this polygon. The new endpoint is (x, previous endpoint's Y coordinate).- Parameters:
x- Endpoint's X coordinate.- Returns:
- This polygon.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if there is no previous endpoint.
-
hto
public Polygon hto(Point thePoint)
Add a horizontal line segment to this polygon. The new endpoint is (thePoint's X coordinate, previous endpoint's Y coordinate).- Parameters:
thePoint- Endpoint.- Returns:
- This polygon.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if thePoint is null. Thrown if there is no previous endpoint.
-
vto
public Polygon vto(double y)
Add a vertical line segment to this polygon. The new endpoint is (previous endpoint's X coordinate, y).- Parameters:
y- Endpoint's Y coordinate.- Returns:
- This polygon.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if there is no previous endpoint.
-
vto
public Polygon vto(Point thePoint)
Add a vertical line segment to this polygon. The new endpoint is (previous endpoint's X coordinate, thePoint's Y coordinate).- Parameters:
thePoint- Endpoint.- Returns:
- This polygon.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if thePoint is null. Thrown if there is no previous endpoint.
-
by
public Polygon by(double dx, double dy)
Add a line segment to this polygon. The new endpoint is (previous endpoint's X coordinate + dx, previous endpoint's Y coordinate + dy).- Parameters:
dx- X distance.dy- Y distance.- Returns:
- This polygon.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if there is no previous endpoint.
-
by
public Polygon by(Size theSize)
Add a line segment to this polygon. The new endpoint is (previous endpoint's X coordinate + theSize.width(), previous endpoint's Y coordinate + theSize.height()).- Parameters:
theSize- Distance.- Returns:
- This polygon.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theSize is null. Thrown if there is no previous endpoint.
-
hby
public Polygon hby(double dx)
Add a horizontal line segment to this polygon. The new endpoint is (previous endpoint's X coordinate + dx, previous endpoint's Y coordinate).- Parameters:
dx- X distance.- Returns:
- This polygon.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if there is no previous endpoint.
-
hby
public Polygon hby(Size theSize)
Add a horizontal line segment to this polygon. The new endpoint is (previous endpoint's X coordinate + theSize.width(), previous endpoint's Y coordinate).- Parameters:
theSize- Distance.- Returns:
- This polygon.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theSize is null. Thrown if there is no previous endpoint.
-
vby
public Polygon vby(double dy)
Add a vertical line segment to this polygon. The new endpoint is (previous endpoint's X coordinate, previous endpoint's Y coordinate + dy).- Parameters:
dy- Y distance.- Returns:
- This polygon.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if there is no previous endpoint.
-
vby
public Polygon vby(Size theSize)
Add a vertical line segment to this polygon. The new endpoint is (previous endpoint's X coordinate, previous endpoint's Y coordinate + theSize.height()).- Parameters:
theSize- Distance.- Returns:
- This polygon.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theSize is null. Thrown if there is no previous endpoint.
-
add
public Polygon add()
Add this polygon to the end of the default drawing's sequence of drawing items.- Overrides:
addin classShapeItem- Returns:
- This polygon.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if there is no default drawing.- See Also:
Drawing.defaultDrawing()
-
add
public Polygon add(Drawing theDrawing)
Add this polygon to the end of the given drawing's sequence of drawing items.
-
addFirst
public Polygon addFirst()
Add this polygon to the beginning of the default drawing's sequence of drawing items.- Overrides:
addFirstin classShapeItem- Returns:
- This polygon.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if there is no default drawing.- See Also:
Drawing.defaultDrawing()
-
addFirst
public Polygon addFirst(Drawing theDrawing)
Add this polygon to the beginning of the given drawing's sequence of drawing items.
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOExceptionWrite this polygon to the given object output stream.- Specified by:
writeExternalin interfacejava.io.Externalizable- Overrides:
writeExternalin classFilledItem- Parameters:
out- Object output stream.- Throws:
java.io.IOException- Thrown if an I/O error occurred.
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundExceptionRead this polygon from the given object input stream.- Specified by:
readExternalin interfacejava.io.Externalizable- Overrides:
readExternalin classFilledItem- Parameters:
in- Object input stream.- Throws:
java.io.IOException- Thrown if an I/O error occurred.java.lang.ClassNotFoundException- Thrown if any class needed to deserialize this polygon cannot be found.
-
-
DMelt 3.0 © DataMelt by jWork.ORG