jsky.util.java2d
Class ShapeUtilities

java.lang.Object
  extended by jsky.util.java2d.ShapeUtilities

public final class ShapeUtilities
extends java.lang.Object

A set of utilities on Java2D shapes.

Version:
$Revision: 1.1 $
Author:
John Reekie (johnr@eecs.berkeley.edu), Michael Shilman (michaels@eecs.berkeley.edu)

Constructor Summary
ShapeUtilities()
           
 
Method Summary
static java.awt.Shape cloneShape(java.awt.Shape s)
          Clone a shape.
static java.awt.Shape createCloudShape()
          Create the "cloud" shape.
static java.awt.Shape createSwatchShape()
          Create the "swatch" shape.
static boolean intersectsOutline(java.awt.geom.Rectangle2D r, java.awt.Shape s)
          Return true if the outline of the given shape intersects with the given rectangle.
static boolean isOrthogonal(java.awt.geom.AffineTransform at)
          Return true if the given transform maps a rectangle to a rectangle.
static java.lang.String printShapeAsCode(java.lang.String name, java.awt.Shape shape)
          Print a Shape to a String, as a code fragment that creates a new GeneralPath.
static java.awt.geom.Rectangle2D transformBounds(java.awt.geom.Rectangle2D rect, java.awt.geom.AffineTransform at)
          Given a bounding-box rectangle, return a new rectangle by transforming the argument rectangle and taking the bounding box of the result.
static java.awt.Shape transformModify(java.awt.Shape s, java.awt.geom.AffineTransform at)
          Transform a shape with the supplied transform.
static void transformModifyRect(java.awt.geom.RectangularShape s, java.awt.geom.AffineTransform at)
          Transform a rectangular shape with an orthogonal transform.
static java.awt.Shape translateModify(java.awt.Shape s, double x, double y)
          Translate a shape the given distance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ShapeUtilities

public ShapeUtilities()
Method Detail

cloneShape

public static java.awt.Shape cloneShape(java.awt.Shape s)
Clone a shape. This method is needed because Shape does not define clone(), although many shape classes do.


createCloudShape

public static java.awt.Shape createCloudShape()
Create the "cloud" shape. If running in JDK1.2 beta4, generate the shape on-the-fly using the Area class and return it. If running in JDK1.2 final, which has the screwed-up Area code, just generate a hardwired path (using code that was generated by running in beta4!!!) The shape is bounded by the rectangle (0,0,100,100).


createSwatchShape

public static java.awt.Shape createSwatchShape()
Create the "swatch" shape. If running in JDK1.2 beta4, generate the shape on-the-fly using the Area class and return it. If running in JDK1.2 final, which has the screwed-up Area code, just generate a hardwired path (using code that was generated by running in beta4!!!) The shape is bounded by the rectangle (0,0,100,100).


intersectsOutline

public static boolean intersectsOutline(java.awt.geom.Rectangle2D r,
                                        java.awt.Shape s)
Return true if the outline of the given shape intersects with the given rectangle.


isOrthogonal

public static boolean isOrthogonal(java.awt.geom.AffineTransform at)
Return true if the given transform maps a rectangle to a rectangle. If this method returns true, then the transformRectangle and transformRectangularShape methods will operate correctly.


printShapeAsCode

public static java.lang.String printShapeAsCode(java.lang.String name,
                                                java.awt.Shape shape)
Print a Shape to a String, as a code fragment that creates a new GeneralPath.


transformBounds

public static java.awt.geom.Rectangle2D transformBounds(java.awt.geom.Rectangle2D rect,
                                                        java.awt.geom.AffineTransform at)
Given a bounding-box rectangle, return a new rectangle by transforming the argument rectangle and taking the bounding box of the result. This method optimizes the calculation if the transform is orthogonal. Note that the argument rectangle is not modified, and the transform does not need to be orthogonal.


transformModifyRect

public static void transformModifyRect(java.awt.geom.RectangularShape s,
                                       java.awt.geom.AffineTransform at)
Transform a rectangular shape with an orthogonal transform. The passed rectangular shape will be modified according to the transform. By "orthogonal", it is meant any transform that returns true to to the isOrthogonal() method.


transformModify

public static java.awt.Shape transformModify(java.awt.Shape s,
                                             java.awt.geom.AffineTransform at)
Transform a shape with the supplied transform. If possible, this method modifies the shape directly and returns a pointer to that same shape. In particular, instances of Rectangle2D, Polygon2D, Polyline2D, and GeneralPath will be modified directly. (In the case of RectangularShape, only if the transform is orthogonal.) Otherwise, a general transformation is used that creates and returns a new instance of GeneralPath.


translateModify

public static java.awt.Shape translateModify(java.awt.Shape s,
                                             double x,
                                             double y)
Translate a shape the given distance. If possible, this method modifies the shape directly and returns a pointer to that same shape. In particular, instances of RectangularShape, Polygon2D, Polyline2D, and GeneralPath are modified directly. Otherwise, a general transformation is used that creates and returns a new instance of GeneralPath.