ca.utoronto.cs.prefuseextensions.geom
Class Sector2D

java.lang.Object
  extended by java.awt.geom.Area
      extended by ca.utoronto.cs.prefuseextensions.geom.Sector2D
All Implemented Interfaces:
java.awt.Shape, java.lang.Cloneable

public class Sector2D
extends java.awt.geom.Area
implements java.awt.Shape, java.lang.Cloneable

Sector2D is the class for all objects that store a 2D sector defined by a outer bounding rectangle, width, start angle, and angular extent (length of the arc). The bounding rectangle defines the outer boundary of the full ellipse of which the outer arc is a partial section. The width defines the width of the sector between the inner arc and outer arc. The width is used to calculate an inner bounding rectangle which defines the outer boundary of the full ellipse of which the inner arc is a partial section. The angles are specified relative to the non-square extents of the bounding rectangles such that 45 degrees always falls on the line from the center of the ellipses to the upper right corner of the bounding rectangles. As a result, if the bounding rectangles are noticeably longer along one axis than the other, the angles to the start and end of the arc segment will be skewed farther along the longer axis of the bounds. Because of the use of radians by prefuse layouts, input angles are in radians. Angles are converted to degrees (and returned in degree) for use by java2d.awt.geom.Arc2D which forms the inner and outer arcs of the Sector2D The actual storage representation of the coordinates is maintained by the Area superclass and 2 Arc2D objects. This code is not an extension of prefuse, see license-rsf-tree.txt.

Version:
$Revision: 1.3 $
Author:
Christopher Collins

Field Summary
static int CONSTANT_SECTOR_WIDTH
          Maintain sector width as constant when drawing elliptical sectors.
static int PROPORTIONAL_SECTOR_WIDTH
          Alter sector width to be proportional between height and width of framing rectangle when drawing elliptical sectors.
 
Constructor Summary
Sector2D()
          Creates an empty sector2D.
Sector2D(java.awt.geom.Arc2D innerArc, java.awt.geom.Arc2D outerArc)
          Creates a Sector2D with the given inner and outer arcs as the bounds.
Sector2D(double centerX, double centerY, double innerRadius, double outerRadius, double startAngle, double angleExtent)
          Creates a Sector2D centered at the given coordinates and with the specified inner and outer radii and angular span.
Sector2D(double x, double y, double w, double h, double startAngle, double angleExtent, double width)
          Creates a Sector2D within the given rectangular bounds, start angle, angle extents, and width.
Sector2D(java.awt.geom.Rectangle2D ellipseBounds, double startAngle, double angleExtent, double width)
          Creates a Sector2D within the given rectangular bounds, start angle, angle extents, and width.
Sector2D(Sector2D sector)
          Creates a Sector2D with dimensions the same as a given Sector2D.
 
Method Summary
 java.lang.Object clone()
          Create a copy of this Sector2D.
 double getAngleExtent()
          Returns the angular extent of this sector.
 double getAngleStart()
          Returns the angular start of this sector.
 double getCenterX()
          Returns the x-coordinate of the center of the framing rectangle of the sector in double precision.
 double getCenterY()
          Returns the y-coordinate of the center of the framing rectangle of the sector in double precision.
 int getEllipseMethod()
          Gets the current method of drawing elliptical sectors.
 java.awt.geom.Rectangle2D getFrame()
          Returns the framing Rectangle2D that defines the overall shape of this object.
 double getHeight()
          Returns the height of the framing rectangle in double precision.
 java.awt.geom.Arc2D getInnerArc()
          Get the Arc2D (PIE shaped) which forms the inner arc of this Sector2D.
 double getInnerRadius()
          Get the radius of the ellipse for which the inner arc is a part.
 double getMaxX()
          Returns the maximum x value (the right corner) of the bounding box which contains the ellipse which the outer arc of this sector is part.
 double getMaxY()
          Returns the maximum y value (the lower corner) of the bounding box which contains the ellipse which the outer arc of this sector is part.
 java.awt.geom.Arc2D getOuterArc()
          Get the Arc2D (PIE shaped) which forms the outer arc of this Sector2D
 double getOuterRadius()
          Get the radius of the ellipse for which the outer arc is a part.
 double getSectorWidth()
          Returns the difference in radius between the outer and inner arcs forming this sector.
 double getWidth()
          Returns the width of the framing rectangle in double precision.
 double getX()
          Returns the X coordinate of the upper left corner of the framing rectangle in double precision.
 double getY()
          Returns the Y coordinate of the upper left corner of the framing rectangle in double precision.
 void scale(double scaleAmount)
          Scales the bounding frame up or down by the absolute value scaleAmount.
 void scale(double scaleAmount, double newSectorWidth)
          Scales the bounding frame up or down by the absolute value scaleAmount.
 void setAngleExtent(double angleExtent)
          Sets this sectors angular span to the given value.
 void setAngleStart(double startAngle)
          Sets the angle start to the given value.
 void setEllipseMethod(int ellipseMethod)
          Sets the ellipse drawing method.
 void setFrame(double x, double y, double w, double h)
          Sets the location and size of the outer bounds of this Sector2D to the specified rectangular values.
 void setInnerArc(java.awt.geom.Arc2D innerArc)
          Sets the inner arc of this Sector2D to the dimensions of the given arc.
 void setInnerRadius(double innerRadius)
          Sets the inner radius this Sector2D to the given value.
 void setOuterArc(java.awt.geom.Arc2D outerArc)
          Sets the outer arc of this Sector2D to the dimensions of the given arc.
 void setOuterRadius(double outerRadius)
          Sets the outer radius this Sector2D to the given radius.
 void setRadii(double innerRadius, double outerRadius)
          Sets the inner and outer radii this Sector2D to the given values.
 void setSector(double x, double y, double w, double h, double startAngle, double angleExtent, double width)
          Sets the dimensions of this sector as given.
 void setSector(Sector2D sector)
          Sets this Sector to be the same as the specified Sector.
 void setSectorByCenter(double centerX, double centerY, double innerRadius, double outerRadius, double startAngle, double angleExtent)
          Set this sector centered at the given coordinates and with the specified inner and outer radii and angular span.
 void setSectorWidth(double width)
          Set the width of this sector as specified.
 
Methods inherited from class java.awt.geom.Area
add, contains, contains, contains, contains, createTransformedArea, equals, exclusiveOr, getBounds, getBounds2D, getPathIterator, getPathIterator, intersect, intersects, intersects, isEmpty, isPolygonal, isRectangular, isSingular, reset, subtract, transform
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.awt.Shape
contains, contains, contains, contains, getBounds, getBounds2D, getPathIterator, getPathIterator, intersects, intersects
 

Field Detail

CONSTANT_SECTOR_WIDTH

public static final int CONSTANT_SECTOR_WIDTH
Maintain sector width as constant when drawing elliptical sectors.

See Also:
setEllipseMethod(int), Constant Field Values

PROPORTIONAL_SECTOR_WIDTH

public static final int PROPORTIONAL_SECTOR_WIDTH
Alter sector width to be proportional between height and width of framing rectangle when drawing elliptical sectors.

See Also:
setEllipseMethod(int), Constant Field Values
Constructor Detail

Sector2D

public Sector2D()
Creates an empty sector2D.


Sector2D

public Sector2D(Sector2D sector)
Creates a Sector2D with dimensions the same as a given Sector2D.

Parameters:
sector - the Sector2D whose dimensions will be copied

Sector2D

public Sector2D(java.awt.geom.Arc2D innerArc,
                java.awt.geom.Arc2D outerArc)
         throws java.lang.IllegalArgumentException
Creates a Sector2D with the given inner and outer arcs as the bounds.

Parameters:
innerArc - the inner arc which specifies the inner radius and angles of the sector
outerArc - the outer arc which specifies the outer radius and angles of the sector
Throws:
java.lang.IllegalArgumentException - if the arcs do not span the same angles or if the innerArc radius is not less than or equal to outerArc radius.

Sector2D

public Sector2D(java.awt.geom.Rectangle2D ellipseBounds,
                double startAngle,
                double angleExtent,
                double width)
         throws java.lang.IllegalArgumentException
Creates a Sector2D within the given rectangular bounds, start angle, angle extents, and width. The outer arc will fit within the bounding box and the width is calculated inward.

Parameters:
ellipseBounds - the bounded rectangle for the outer arc of this sector2D
startAngle - the angle to start this Sector2D
angleExtent - the angular width of this Sector2D
width - the width of the Sector2D, extending inward from the outer arc
Throws:
java.lang.IllegalArgumentException - if the width exceeds the radius of the outer arc (half the width of the ellipseBounds

Sector2D

public Sector2D(double x,
                double y,
                double w,
                double h,
                double startAngle,
                double angleExtent,
                double width)
         throws java.lang.IllegalArgumentException
Creates a Sector2D within the given rectangular bounds, start angle, angle extents, and width. The outer arc will fit within the bounding box and the width is calculated inward.

Parameters:
x - the x-coordinate of the upper-left corner of the bounding rectangle
y - the y-coordinate of the upper-left corner of the bounding rectangle
w - the width of the bounding rectangle
h - the height of the bounding rectangle
startAngle - the angle to start this Sector2D
angleExtent - the angular width of this Sector2D
width - the width of this Sector2D, extending inward from the outer arc
Throws:
java.lang.IllegalArgumentException - if the width exceeds the radius of the outer arc (half the rectangle width w

Sector2D

public Sector2D(double centerX,
                double centerY,
                double innerRadius,
                double outerRadius,
                double startAngle,
                double angleExtent)
         throws java.lang.IllegalArgumentException
Creates a Sector2D centered at the given coordinates and with the specified inner and outer radii and angular span.

Parameters:
centerX - the x-coordinate of the centre of bounding box of this Sector2D
centerY - the y-coordinate of the centre of bounding box of this Sector2D
innerRadius - the radius of the inner arc of this Sector2D
outerRadius - the radius of the outer arc of this Sector2D
startAngle - the angle to start this Sector2D in radians
angleExtent - the angular width of this Sector2D in radians
Throws:
java.lang.IllegalArgumentException - if the innerRadius is greater than the outerRadius
Method Detail

clone

public java.lang.Object clone()
Create a copy of this Sector2D.

Overrides:
clone in class java.awt.geom.Area
Returns:
A copy of this Sector2D cast to Object.

setInnerArc

public void setInnerArc(java.awt.geom.Arc2D innerArc)
                 throws java.lang.IllegalArgumentException
Sets the inner arc of this Sector2D to the dimensions of the given arc.

Parameters:
innerArc - the new arc to set this inner arc to match
Throws:
java.lang.IllegalArgumentException - if innerArc is not a PIE arc of angles the same as the outer arc and bounding box within that of the outer arc.

getInnerArc

public java.awt.geom.Arc2D getInnerArc()
Get the Arc2D (PIE shaped) which forms the inner arc of this Sector2D.

Returns:
the Arc2D which forms the inner arc of this Sector2D.

setOuterArc

public void setOuterArc(java.awt.geom.Arc2D outerArc)
                 throws java.lang.IllegalArgumentException
Sets the outer arc of this Sector2D to the dimensions of the given arc. Sets the angular dimensions of the entire sector to the those of outerArc.

Parameters:
outerArc - the new arc to set this outer arc to match
Throws:
java.lang.IllegalArgumentException - if outerArc is not a PIE arc with a bounding box which contains that of the inner arc.

getOuterArc

public java.awt.geom.Arc2D getOuterArc()
Get the Arc2D (PIE shaped) which forms the outer arc of this Sector2D

Returns:
the Arc2D which forms the outer arc of this Sector2D

setOuterRadius

public void setOuterRadius(double outerRadius)
                    throws java.lang.IllegalArgumentException
Sets the outer radius this Sector2D to the given radius. Resets the dimensions to square.

Parameters:
outerRadius - the new value for the outer radius of this Sector2D
Throws:
java.lang.IllegalArgumentException - if outerRadius is not greater than or equal to the current inner radius

getOuterRadius

public double getOuterRadius()
Get the radius of the ellipse for which the outer arc is a part.

Returns:
radius of the ellipse which the outer arc is part of

setRadii

public void setRadii(double innerRadius,
                     double outerRadius)
              throws java.lang.IllegalArgumentException
Sets the inner and outer radii this Sector2D to the given values.

Parameters:
innerRadius - the new value for the inner radius of this Sector2D
outerRadius - the new value for the outer radius of this Sector2D
Throws:
java.lang.IllegalArgumentException - if the given outer radius is not greater than or equal to the given inner radius

setInnerRadius

public void setInnerRadius(double innerRadius)
                    throws java.lang.IllegalArgumentException
Sets the inner radius this Sector2D to the given value.

Parameters:
innerRadius - the new value for the inner radius of this Sector2D
Throws:
java.lang.IllegalArgumentException - if innerRadius is greater than the current outer radius

getInnerRadius

public double getInnerRadius()
Get the radius of the ellipse for which the inner arc is a part.

Returns:
radius of the ellipse which the inner arc is part of
Throws:
java.lang.IllegalStateException - if the x and y radii are different (sector is elliptical).

scale

public void scale(double scaleAmount)
Scales the bounding frame up or down by the absolute value scaleAmount. The sector center is unchanged.

Parameters:
scaleAmount - the amount to grow or shrink the width and height of the bounding frame

scale

public void scale(double scaleAmount,
                  double newSectorWidth)
Scales the bounding frame up or down by the absolute value scaleAmount. The sector center is unchanged. The sector width is simultaneously reset to newSectorWidth.

Parameters:
scaleAmount - the amount to grow or shrink the width and height of the bounding frame
newSectorWidth - the sector width for the scaled sector

setSector

public void setSector(double x,
                      double y,
                      double w,
                      double h,
                      double startAngle,
                      double angleExtent,
                      double width)
               throws java.lang.IllegalArgumentException
Sets the dimensions of this sector as given.

Parameters:
x - the x-coordinate of the upper-left corner of the bounding rectangle
y - the y-coordinate of the upper-left corner of the bounding rectangle
w - the width of the bounding rectangle
h - the height of the bounding rectangle
startAngle - the angle to start this Sector2D in radians
angleExtent - the angular width of this Sector2D in radians
width - the width of this Sector2D, extending inward from the outer arc
Throws:
java.lang.IllegalArgumentException - if double (sector) width would exceed outer bounding box or if width is less than zero.
See Also:
Arc2D.setArc(double, double, double, double, double, double, int)

setSectorByCenter

public void setSectorByCenter(double centerX,
                              double centerY,
                              double innerRadius,
                              double outerRadius,
                              double startAngle,
                              double angleExtent)
                       throws java.lang.IllegalArgumentException
Set this sector centered at the given coordinates and with the specified inner and outer radii and angular span. Sector forms part of a circle (bounding box is a square).

Parameters:
centerX - the x-coordinate of the centre of bounding box of this Sector2D
centerY - the y-coordinate of the centre of bounding box of this Sector2D
innerRadius - the radius of the inner arc of this Sector2D in radians
outerRadius - the radius of the outer arc of this Sector2D in radians
startAngle - the angle to start this Sector2D
angleExtent - the angular width of this Sector2D
Throws:
java.lang.IllegalArgumentException - if the innerRadius is greater than the outerRadius
See Also:
Arc2D.setArc(double, double, double, double, double, double, int)

setAngleStart

public void setAngleStart(double startAngle)
Sets the angle start to the given value. 0 is measured as horizontal (to the right).

Parameters:
startAngle - the new starting angle in radians
See Also:
Arc2D.setAngleStart(double)

setAngleExtent

public void setAngleExtent(double angleExtent)
Sets this sectors angular span to the given value.

Parameters:
angleExtent - the new angular span for this sector in radians
See Also:
Arc2D.setAngleExtent(double)

setSectorWidth

public void setSectorWidth(double width)
                    throws java.lang.IllegalArgumentException
Set the width of this sector as specified. Outer radius and bounding box remain unchanged.

Parameters:
width - the width (inward from outer radius) to make this sector
Throws:
java.lang.IllegalArgumentException - if double sector width would exceed outer bounding box and bounding box width is > 0

setFrame

public void setFrame(double x,
                     double y,
                     double w,
                     double h)
              throws java.lang.IllegalArgumentException
Sets the location and size of the outer bounds of this Sector2D to the specified rectangular values. Sector width, angular start and angular extents are unchanged. New width must be greater than sector width.

Parameters:
x - the coordinates to which to set the location of the upper left corner of the outer bounds of this Rectangle2D
y - the coordinates to which to set the location of the upper left corner of the outer bounds of this Rectangle2D
w - the width to set the outer bounding box of this Sector2D
h - the height to set the outer bounding box of this Sector2D
Throws:
java.lang.IllegalArgumentException - if w is less than twice the sector width

setSector

public void setSector(Sector2D sector)
Sets this Sector to be the same as the specified Sector.

Parameters:
sector - the sector to copy

getAngleExtent

public double getAngleExtent()
Returns the angular extent of this sector.

Returns:
the angular span of this sector, in degrees

getAngleStart

public double getAngleStart()
Returns the angular start of this sector. 0 is measured as horizontal, to the right.

Returns:
the start angle of this sector, in degrees

getX

public double getX()
Returns the X coordinate of the upper left corner of the framing rectangle in double precision.

Returns:
the X coordinate of the upper left corner of the framing rectangle

getY

public double getY()
Returns the Y coordinate of the upper left corner of the framing rectangle in double precision.

Returns:
the Y coordinate of the upper left corner of the framing rectangle

getWidth

public double getWidth()
Returns the width of the framing rectangle in double precision.

Returns:
the width of the framing rectangle

getHeight

public double getHeight()
Returns the height of the framing rectangle in double precision.

Returns:
the height of the framing rectangle

getMaxX

public double getMaxX()
Returns the maximum x value (the right corner) of the bounding box which contains the ellipse which the outer arc of this sector is part.

Returns:
the maximum x value, determined by the outer arc

getMaxY

public double getMaxY()
Returns the maximum y value (the lower corner) of the bounding box which contains the ellipse which the outer arc of this sector is part.

Returns:
the maximum y value, determined by the outer arc

getCenterX

public double getCenterX()
Returns the x-coordinate of the center of the framing rectangle of the sector in double precision.

Returns:
the x-coordinate of center of the framing rectangle of the sector

getCenterY

public double getCenterY()
Returns the y-coordinate of the center of the framing rectangle of the sector in double precision.

Returns:
the y-coordinate of center of the framing rectangle of the sector

getFrame

public java.awt.geom.Rectangle2D getFrame()
Returns the framing Rectangle2D that defines the overall shape of this object.

Returns:
a Rectangle2D, specified in double coordinates

getSectorWidth

public double getSectorWidth()
Returns the difference in radius between the outer and inner arcs forming this sector.

Returns:
the width of the sector

setEllipseMethod

public void setEllipseMethod(int ellipseMethod)
Sets the ellipse drawing method.

Arcs forming Sectors contained in (non-square) rectangles are parts of ellipses. Inner arc can be designated to maintain constant sector width (inner and outer angles will not match because w/h proportions will differ) or proportional (changing) sector width (default). This behaviour is managed by the value of ellipseMethod and (@link #setSectorWidth(double)).

Parameters:
ellipseMethod - Can be either CONSTANT_SECTOR_WIDTH or PROPORTIONAL_SECTOR_WIDTH
Throws:
java.lang.IllegalArgumentException - if ellipseMethod is not one of CONSTANT_SECTOR_WIDTH or PROPORTIONAL_SECTOR_WIDTH

getEllipseMethod

public int getEllipseMethod()
Gets the current method of drawing elliptical sectors.

Returns:
the current method of drawing elliptical sectors, either CONSTANT_SECTOR_WIDTH or PROPORTIONAL_SECTOR_WIDTH