com.partnersoft.geometry.xy
Class XyArc

java.lang.Object
  extended by com.partnersoft.geometry.xy.XyArc
All Implemented Interfaces:
Immutable, XyPath<XyArc>, XyShape<XyArc>, java.lang.Iterable<XyPoint>

public class XyArc
extends java.lang.Object
implements XyPath<XyArc>

A partial circle in (x, y) space.

Copyright 2007 Partner Software, Inc.

Version:
$Id: XyArc.java 1704 2009-01-13 22:16:02Z paul $
Author:
Paul Reavis

Constructor Summary
XyArc(XyPoint center, double radius, XyDeflection deflection)
          Creates a new XyArc from the given center, radius, and deflection.
XyArc(XyPoint center, double radius, XyDirection start, XyDirection end, boolean clockwise)
          Creates a new XyArc starting at the given start angle and ending at the given end angle.
 
Method Summary
 boolean containsDirection(XyDirection direction)
          Returns true if the given angle is part of this arc.
 boolean equals(java.lang.Object nother)
           
 XyAngle getAngle()
          Returns the angular width (the angular difference between the start and end directions positions).
 XyBounds getBounds()
          Returns an XyBounds object representing the rectangular extents of this shape.
 XyPoint getCenter()
          Geometric center of circle.
 XyDirection getEnd()
          Ending direction for arc.
 XyPoint getEndPoint()
          Returns the last point in the shape.
 double getLength()
          Returns the length of the path.
 double getRadius()
          Returns the radius of the circle containing this arc.
 XyDirection getStart()
          Starting direction for arc.
 XyPoint getStartPoint()
          Returns the first point in the shape.
 boolean isClockwise()
          If true, arc proceeds clockwise from start to end.
 java.util.Iterator<XyPoint> iterator()
           
 XyArc reversed()
          Returns a modified version of this arc with the start and end swapped and the clockwise flag reversed.
 XyArc scaledBy(double scale)
          Return a scaled version of the shape by multiplying all coordinates by the given factor in both dimensions.
 XyArc scaledBy(double scaleX, double scaleY)
           
 XyPolyline toPolyline()
          Same as XyPath.toPolyline(XyAngle) with a default angle granularity of 1/60 circle (6 degrees, pi/30 radians).
 XyPolyline toPolyline(XyAngle granularity)
          Converts this area to a polyline which approximates it in some fashion.
 java.lang.String toString()
           
 XyShape transformedBy(XyTransform transform)
          Transform the shape using the given transform.
 XyArc translatedBy(double offsetX, double offsetY)
          Translate the shape by adding all coordinates to the given x and y offsets.
 XyArc withCenter(XyPoint newCenter)
          Returns a modified version of this arc with the given center.
 XyArc withClockwise(boolean newClockwise)
          Returns a modified version of this arc with the given clockwise flag.
 XyArc withEnd(XyDirection newEnd)
          Returns a modified version of this arc with the given end direction.
 XyArc withRadius(double newRadius)
          Returns a modified version of this arc with the given radius.
 XyArc withStart(XyDirection newStart)
          Returns a modified version of this arc with the given start direction.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XyArc

public XyArc(XyPoint center,
             double radius,
             XyDirection start,
             XyDirection end,
             boolean clockwise)
Creates a new XyArc starting at the given start angle and ending at the given end angle. If the clockwise flag is true, it proceeds clockwise around the circle from start to end; otherwise it proceeds counter-clockwise.


XyArc

public XyArc(XyPoint center,
             double radius,
             XyDeflection deflection)
Creates a new XyArc from the given center, radius, and deflection.

Method Detail

withStart

public XyArc withStart(XyDirection newStart)
Returns a modified version of this arc with the given start direction.


withEnd

public XyArc withEnd(XyDirection newEnd)
Returns a modified version of this arc with the given end direction.


withCenter

public XyArc withCenter(XyPoint newCenter)
Returns a modified version of this arc with the given center.


withRadius

public XyArc withRadius(double newRadius)
Returns a modified version of this arc with the given radius.


withClockwise

public XyArc withClockwise(boolean newClockwise)
Returns a modified version of this arc with the given clockwise flag. If this is different from the current setting, it will reverse the direction of the arc so that it goes the opposite way around the circle, and so that its angle is 360 - current.


reversed

public XyArc reversed()
Returns a modified version of this arc with the start and end swapped and the clockwise flag reversed. This is a mathematically identical wedge, but with different path-traversal behavior.


containsDirection

public boolean containsDirection(XyDirection direction)
Returns true if the given angle is part of this arc. Deals with the confusing problems of the repeating nature of circular coordinates.


toPolyline

public XyPolyline toPolyline(XyAngle granularity)
Description copied from interface: XyPath
Converts this area to a polyline which approximates it in some fashion. For example, a curve can be converted to a polyline with enough segments to roughly approximate its shape. Paths consisting of linked line segments can be represented exactly.

The angle parameter allows a certain level of control of the output. Essentially it dictates the minimum angular granularity used to approximate curved paths. For example, an arc would be turned into a polyline by placing points around the arc's slice of a circle, separated by the given angle.

Specified by:
toPolyline in interface XyPath<XyArc>

toPolyline

public XyPolyline toPolyline()
Description copied from interface: XyPath
Same as XyPath.toPolyline(XyAngle) with a default angle granularity of 1/60 circle (6 degrees, pi/30 radians).

Specified by:
toPolyline in interface XyPath<XyArc>

getLength

public double getLength()
Description copied from interface: XyPath
Returns the length of the path.

Specified by:
getLength in interface XyPath<XyArc>
Returns:
geometric length of this shape

getStartPoint

public XyPoint getStartPoint()
Description copied from interface: XyPath
Returns the first point in the shape.

Specified by:
getStartPoint in interface XyPath<XyArc>

getEndPoint

public XyPoint getEndPoint()
Description copied from interface: XyPath
Returns the last point in the shape.

Specified by:
getEndPoint in interface XyPath<XyArc>

scaledBy

public XyArc scaledBy(double scale)
Description copied from interface: XyShape
Return a scaled version of the shape by multiplying all coordinates by the given factor in both dimensions. This resulting shape must be of the same class as the original.

Specified by:
scaledBy in interface XyShape<XyArc>
Parameters:
scale - scaling factor
Returns:
scaled result

scaledBy

public XyArc scaledBy(double scaleX,
                      double scaleY)

translatedBy

public XyArc translatedBy(double offsetX,
                          double offsetY)
Description copied from interface: XyShape
Translate the shape by adding all coordinates to the given x and y offsets. The resulting shape must be of the same class as the original.

Specified by:
translatedBy in interface XyShape<XyArc>
Parameters:
offsetX - offset for the x dimension
offsetY - offset for the y dimension
Returns:
offset result

transformedBy

public XyShape transformedBy(XyTransform transform)
Description copied from interface: XyShape
Transform the shape using the given transform. Due to potential distortion the result may be a different type of shape than this one.

Specified by:
transformedBy in interface XyShape<XyArc>
Parameters:
transform - affine transform to apply.
Returns:
transformed result

getBounds

public XyBounds getBounds()
Description copied from interface: XyShape
Returns an XyBounds object representing the rectangular extents of this shape.

Specified by:
getBounds in interface XyShape<XyArc>

iterator

public java.util.Iterator<XyPoint> iterator()
Specified by:
iterator in interface java.lang.Iterable<XyPoint>

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object nother)
Overrides:
equals in class java.lang.Object

getCenter

public XyPoint getCenter()
Geometric center of circle.

Returns:
center of circle.

getRadius

public double getRadius()
Returns the radius of the circle containing this arc.


isClockwise

public boolean isClockwise()
If true, arc proceeds clockwise from start to end. If false, it proceeds counter-clockwise.


getStart

public XyDirection getStart()
Starting direction for arc. Arc proceeds either clockwise or counter-clockwise from this direction to the end.


getEnd

public XyDirection getEnd()
Ending direction for arc. Arc comes in either clockwise or counter-clockwise from the start angle to this direction.


getAngle

public XyAngle getAngle()
Returns the angular width (the angular difference between the start and end directions positions).