edu.rit.draw.item
Class Arc
- java.lang.Object
-
- edu.rit.draw.item.DrawingItem
-
- edu.rit.draw.item.OutlinedItem
-
- edu.rit.draw.item.Arc
-
- All Implemented Interfaces:
- java.io.Externalizable, java.io.Serializable
public class Arc extends OutlinedItem implements java.io.Externalizable
Class Arc provides a DrawingItem that is a circular arc. The arc has an outline but no filled interior. The arc is defined by the following attributes:-
center() -- The arc's center point. The default is (0,0).
-
radius() -- The arc's radius. The default is 1.
-
start() -- The arc's starting angle in radians. This is the angle
from the positive X axis to the arc's starting point. The default is 0.
- extent() -- The arc's angular extent in radians. This is the angle from the arc's starting point to the arc's ending point. The default is π/2.
Angles increase from the positive X axis towards the positive Y axis. Since the positive X axis points to the right and the positive Y axis points down, angles increase in the clockwise direction. (This is the opposite of the usual mathematical convention, where the positive Y axis points upwards.)
The static defaultCenter(), defaultRadius(), defaultStart(), and defaultExtent() methods are provided to set the default center point, radius, starting angle, and angular extent. If the center point, radius, starting angle, or angular extent is not specified, the current default center point, radius, starting angle, or angular extent is used.
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field and Description static PointNORMAL_CENTERThe normal center point: (0,0).static doubleNORMAL_EXTENTThe normal angular extent: π/2.static doubleNORMAL_RADIUSThe normal radius: 1.static doubleNORMAL_STARTThe normal starting angle: 0.-
Fields inherited from class edu.rit.draw.item.OutlinedItem
NORMAL_OUTLINE
-
-
Constructor Summary
Constructors Constructor and Description Arc()Construct a new arc.Arc(Arc theArc)Construct a new arc with the same center point, radius, starting angle, and angular extent as the given arc.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description Arcadd()Add this arc to the end of the default drawing's sequence of drawing items.Arcadd(Drawing theDrawing)Add this arc to the end of the given drawing's sequence of drawing items.ArcaddFirst()Add this arc to the beginning of the default drawing's sequence of drawing items.ArcaddFirst(Drawing theDrawing)Add this arc to the beginning of the given drawing's sequence of drawing items.Pointcenter()Returns this arc's center point.Arccenter(Point theCenter)Set this arc's center point.static PointdefaultCenter()Returns the default center point.static voiddefaultCenter(Point theCenter)Set the default center point.static doubledefaultExtent()Returns the default angular extent.static voiddefaultExtent(double theExtent)Set the default angular extent.static doubledefaultRadius()Returns the default radius.static voiddefaultRadius(double theRadius)Set the default radius.static doubledefaultStart()Returns the default starting angle.static voiddefaultStart(double theStart)Set the default starting angle.voiddraw(java.awt.Graphics2D g2d)Draw this drawing item in the given graphics context.doubleextent()Returns this arc's angular extent.Arcextent(double theExtent)Set this arc's angular extent.doubleheight()Returns the height of this drawing item's bounding box.Pointnw()Returns the northwest corner point of this drawing item's bounding box.Arcoutline(Outline theOutline)Set this arc's outline.doubleradius()Returns this arc's radius.Arcradius(double theRadius)Set this arc's radius.voidreadExternal(java.io.ObjectInput in)Read this arc from the given object input stream.Sizesize()Returns the size of this drawing item's bounding box.doublestart()Returns this arc's starting angle.Arcstart(double theStart)Set this arc's starting angle.doublewidth()Returns the width of this drawing item's bounding box.voidwriteExternal(java.io.ObjectOutput out)Write this arc to the given object output stream.-
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
-
-
-
-
Field Detail
-
NORMAL_CENTER
public static final Point NORMAL_CENTER
The normal center point: (0,0).
-
NORMAL_RADIUS
public static final double NORMAL_RADIUS
The normal radius: 1.- See Also:
- Constant Field Values
-
NORMAL_START
public static final double NORMAL_START
The normal starting angle: 0.- See Also:
- Constant Field Values
-
NORMAL_EXTENT
public static final double NORMAL_EXTENT
The normal angular extent: π/2.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Arc
public Arc()
Construct a new arc. The default center point, radius, starting angle, and angular extent are used.
-
Arc
public Arc(Arc theArc)
Construct a new arc with the same center point, radius, starting angle, and angular extent as the given arc.- Parameters:
theArc- Arc.- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theArc is null.
-
-
Method Detail
-
defaultCenter
public static Point defaultCenter()
Returns the default center point.- Returns:
- Default center point.
-
defaultCenter
public static void defaultCenter(Point theCenter)
Set the default center point. Before calling this method the first time, the default center point is (0,0).- Parameters:
theCenter- Default center point.- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theCenter is null.
-
defaultRadius
public static double defaultRadius()
Returns the default radius.- Returns:
- Default radius.
-
defaultRadius
public static void defaultRadius(double theRadius)
Set the default radius. Before calling this method the first time, the default radius is 1.- Parameters:
theRadius- Default radius.- Throws:
java.lang.IllegalArgumentException- (unchecked exception) Thrown if theRadius <= 0.
-
defaultStart
public static double defaultStart()
Returns the default starting angle.- Returns:
- Default starting angle (radians).
-
defaultStart
public static void defaultStart(double theStart)
Set the default starting angle. Before calling this method the first time, the default starting angle is 0.- Parameters:
theStart- Default starting angle (radians).
-
defaultExtent
public static double defaultExtent()
Returns the default angular extent.- Returns:
- Default angular extent (radians).
-
defaultExtent
public static void defaultExtent(double theExtent)
Set the default angular extent. Before calling this method the first time, the default angular extent is π/2.- Parameters:
theExtent- Default angular extent (radians).
-
size
public Size size()
Returns the size of this drawing item's bounding box.- Overrides:
sizein classDrawingItem- Returns:
- Size.
-
width
public double width()
Returns the width of this drawing item's bounding box.- Specified by:
widthin classDrawingItem- Returns:
- Width.
-
height
public double height()
Returns the height of this drawing item's bounding box.- Specified by:
heightin classDrawingItem- Returns:
- Height.
-
nw
public Point nw()
Returns the northwest corner point of this drawing item's bounding box.- Specified by:
nwin classDrawingItem- Returns:
- Northwest corner point.
-
outline
public Arc outline(Outline theOutline)
Set this arc's outline.- Overrides:
outlinein classOutlinedItem- Parameters:
theOutline- Outline, or Outline.NONE.- Returns:
- This arc.
-
center
public Point center()
Returns this arc's center point.- Returns:
- Center point.
-
center
public Arc center(Point theCenter)
Set this arc's center point.- Parameters:
theCenter- Center point.- Returns:
- This arc.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theCenter is null.
-
radius
public double radius()
Returns this arc's radius.- Returns:
- Radius.
-
radius
public Arc radius(double theRadius)
Set this arc's radius.- Parameters:
theRadius- Radius.- Returns:
- This arc.
- Throws:
java.lang.IllegalArgumentException- (unchecked exception) Thrown if theRadius <= 0.
-
start
public double start()
Returns this arc's starting angle.- Returns:
- Starting angle (radians).
-
start
public Arc start(double theStart)
Set this arc's starting angle.- Parameters:
theStart- Starting angle (radians).- Returns:
- This arc.
-
extent
public double extent()
Returns this arc's angular extent.- Returns:
- Angular extent (radians).
-
extent
public Arc extent(double theExtent)
Set this arc's angular extent.- Parameters:
theExtent- Angular extent (radians).- Returns:
- This arc.
-
add
public Arc add()
Add this arc to the end of the default drawing's sequence of drawing items.- Overrides:
addin classOutlinedItem- Returns:
- This arc.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if there is no default drawing.- See Also:
Drawing.defaultDrawing()
-
add
public Arc add(Drawing theDrawing)
Add this arc to the end of the given drawing's sequence of drawing items.- Overrides:
addin classOutlinedItem- Parameters:
theDrawing- Drawing.- Returns:
- This arc.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theDrawing is null.
-
addFirst
public Arc addFirst()
Add this arc to the beginning of the default drawing's sequence of drawing items.- Overrides:
addFirstin classOutlinedItem- Returns:
- This arc.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if there is no default drawing.- See Also:
Drawing.defaultDrawing()
-
addFirst
public Arc addFirst(Drawing theDrawing)
Add this arc to the beginning of the given drawing's sequence of drawing items.- Overrides:
addFirstin classOutlinedItem- Parameters:
theDrawing- Drawing.- Returns:
- This arc.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theDrawing is null.
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOExceptionWrite this arc to the given object output stream.- Specified by:
writeExternalin interfacejava.io.Externalizable- Overrides:
writeExternalin classOutlinedItem- 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 arc from the given object input stream.- Specified by:
readExternalin interfacejava.io.Externalizable- Overrides:
readExternalin classOutlinedItem- 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 line cannot be found.
-
draw
public void draw(java.awt.Graphics2D g2d)
Draw this drawing item in the given graphics context. This method is allowed to change the graphics context's paint, stroke, and transform, and it doesn't have to change them back.- Overrides:
drawin classDrawingItem- Parameters:
g2d- 2-D graphics context.
-
-
DMelt 3.0 © DataMelt by jWork.ORG