edu.umd.cs.piccolo.util
Class PAffineTransform

java.lang.Object
  extended by java.awt.geom.AffineTransform
      extended by edu.umd.cs.piccolo.util.PAffineTransform
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class PAffineTransform
extends java.awt.geom.AffineTransform

PAffineTransform is a subclass of AffineTransform that has been extended with convenience methods.

Version:
1.0
Author:
Jesse Grosjean
See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.awt.geom.AffineTransform
TYPE_FLIP, TYPE_GENERAL_ROTATION, TYPE_GENERAL_SCALE, TYPE_GENERAL_TRANSFORM, TYPE_IDENTITY, TYPE_MASK_ROTATION, TYPE_MASK_SCALE, TYPE_QUADRANT_ROTATION, TYPE_TRANSLATION, TYPE_UNIFORM_SCALE
 
Constructor Summary
PAffineTransform()
          Constructs a new AffineTransform representing the Identity transformation.
PAffineTransform(java.awt.geom.AffineTransform tx)
          Constructs a new AffineTransform that is a copy of the specified AffineTransform object.
PAffineTransform(double[] flatmatrix)
          Constructs a new AffineTransform from an array of double precision values representing either the 4 non-translation entries or the 6 specifiable entries of the 3x3 transformation matrix.
PAffineTransform(double m00, double m10, double m01, double m11, double m02, double m12)
          Constructs a new AffineTransform from 6 double precision values representing the 6 specifiable entries of the 3x3 transformation matrix.
PAffineTransform(float[] flatmatrix)
          Constructs a new AffineTransform from an array of floating point values representing either the 4 non-translation entries or the 6 specifiable entries of the 3x3 transformation matrix.
PAffineTransform(float m00, float m10, float m01, float m11, float m02, float m12)
          Constructs a new AffineTransform from 6 floating point values representing the 6 specifiable entries of the 3x3 transformation matrix.
 
Method Summary
 double getRotation()
          Returns the rotation applied to this affine transform in radians.
 double getScale()
          Returns the scale applied to this transform.
 java.awt.geom.Dimension2D inverseTransform(java.awt.geom.Dimension2D dimSrc, java.awt.geom.Dimension2D dimDst)
          Applies the inverse of this transform to the source dimension if possible.
 java.awt.geom.Point2D inverseTransform(java.awt.geom.Point2D ptSrc, java.awt.geom.Point2D ptDst)
          Applies the inverse of this transform to the source point if possible.
 java.awt.geom.Rectangle2D inverseTransform(java.awt.geom.Rectangle2D rectSrc, java.awt.geom.Rectangle2D rectDst)
          Applies the inverse of this transform to the source rectangle and stores the result in rectDst.
 void scaleAboutPoint(double scale, double x, double y)
          Scales the transform about the given point by the given scale.
 void setOffset(double tx, double ty)
          Applies modifies the transform so that it translates by the given offset.
 void setRotation(double theta)
          Set rotation in radians.
 void setScale(double scale)
          Sets the scale about to the origin of this transform to the scale provided.
 java.awt.geom.Dimension2D transform(java.awt.geom.Dimension2D dimSrc, java.awt.geom.Dimension2D dimDst)
          Applies the transform to the provided dimension.
 java.awt.geom.Rectangle2D transform(java.awt.geom.Rectangle2D rectSrc, java.awt.geom.Rectangle2D rectDst)
          Applies this transform to the source rectangle and stores the result in rectDst.
 
Methods inherited from class java.awt.geom.AffineTransform
clone, concatenate, createInverse, createTransformedShape, deltaTransform, deltaTransform, equals, getDeterminant, getMatrix, getQuadrantRotateInstance, getQuadrantRotateInstance, getRotateInstance, getRotateInstance, getRotateInstance, getRotateInstance, getScaleInstance, getScaleX, getScaleY, getShearInstance, getShearX, getShearY, getTranslateInstance, getTranslateX, getTranslateY, getType, hashCode, inverseTransform, invert, isIdentity, preConcatenate, quadrantRotate, quadrantRotate, rotate, rotate, rotate, rotate, scale, setToIdentity, setToQuadrantRotation, setToQuadrantRotation, setToRotation, setToRotation, setToRotation, setToRotation, setToScale, setToShear, setToTranslation, setTransform, setTransform, shear, toString, transform, transform, transform, transform, transform, transform, translate
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PAffineTransform

public PAffineTransform()
Constructs a new AffineTransform representing the Identity transformation.


PAffineTransform

public PAffineTransform(double[] flatmatrix)
Constructs a new AffineTransform from an array of double precision values representing either the 4 non-translation entries or the 6 specifiable entries of the 3x3 transformation matrix. The values are retrieved from the array as { m00 m10 m01 m11 [m02 m12]}.

Parameters:
flatmatrix - the double array containing the values to be set in the new AffineTransform object. The length of the array is assumed to be at least 4. If the length of the array is less than 6, only the first 4 values are taken. If the length of the array is greater than 6, the first 6 values are taken.

PAffineTransform

public PAffineTransform(float[] flatmatrix)
Constructs a new AffineTransform from an array of floating point values representing either the 4 non-translation entries or the 6 specifiable entries of the 3x3 transformation matrix. The values are retrieved from the array as { m00 m10 m01 m11 [m02 m12]}.

Parameters:
flatmatrix - the float array containing the values to be set in the new AffineTransform object. The length of the array is assumed to be at least 4. If the length of the array is less than 6, only the first 4 values are taken. If the length of the array is greater than 6, the first 6 values are taken.

PAffineTransform

public PAffineTransform(double m00,
                        double m10,
                        double m01,
                        double m11,
                        double m02,
                        double m12)
Constructs a new AffineTransform from 6 double precision values representing the 6 specifiable entries of the 3x3 transformation matrix.

Parameters:
m00 - the X coordinate scaling element of the 3x3 matrix
m10 - the Y coordinate shearing element of the 3x3 matrix
m01 - the X coordinate shearing element of the 3x3 matrix
m11 - the Y coordinate scaling element of the 3x3 matrix
m02 - the X coordinate translation element of the 3x3 matrix
m12 - the Y coordinate translation element of the 3x3 matrix

PAffineTransform

public PAffineTransform(float m00,
                        float m10,
                        float m01,
                        float m11,
                        float m02,
                        float m12)
Constructs a new AffineTransform from 6 floating point values representing the 6 specifiable entries of the 3x3 transformation matrix.

Parameters:
m00 - the X coordinate scaling element of the 3x3 matrix
m10 - the Y coordinate shearing element of the 3x3 matrix
m01 - the X coordinate shearing element of the 3x3 matrix
m11 - the Y coordinate scaling element of the 3x3 matrix
m02 - the X coordinate translation element of the 3x3 matrix
m12 - the Y coordinate translation element of the 3x3 matrix

PAffineTransform

public PAffineTransform(java.awt.geom.AffineTransform tx)
Constructs a new AffineTransform that is a copy of the specified AffineTransform object.

Parameters:
tx - transform to copy
Method Detail

scaleAboutPoint

public void scaleAboutPoint(double scale,
                            double x,
                            double y)
Scales the transform about the given point by the given scale.

Parameters:
scale - to transform the transform by
x - x coordinate around which the scale should take place
y - y coordinate around which the scale should take place

getScale

public double getScale()
Returns the scale applied to this transform. Note that it does so by computing the change in length of a unit segment after being passed through the transform. This means that a transform that a transform that doesn't scale the in the x but doubles the y will be reported as 2.

Returns:
the different in length of a unit segment after being transformed.

setScale

public void setScale(double scale)
Sets the scale about to the origin of this transform to the scale provided.

Parameters:
scale - The desired resulting scale

setOffset

public void setOffset(double tx,
                      double ty)
Applies modifies the transform so that it translates by the given offset.

Parameters:
tx - x translation of resulting transform
ty - y translation of resulting transform

getRotation

public double getRotation()
Returns the rotation applied to this affine transform in radians. The value returned will be between 0 and 2pi.

Returns:
rotation in radians

setRotation

public void setRotation(double theta)
Set rotation in radians. This is not cumulative.

Parameters:
theta - desired rotation in radians.

transform

public java.awt.geom.Dimension2D transform(java.awt.geom.Dimension2D dimSrc,
                                           java.awt.geom.Dimension2D dimDst)
Applies the transform to the provided dimension.

Parameters:
dimSrc - source dimension
dimDst - will be changed to be the transformed dimension, may be null
Returns:
the transformed dimension

inverseTransform

public java.awt.geom.Point2D inverseTransform(java.awt.geom.Point2D ptSrc,
                                              java.awt.geom.Point2D ptDst)
Applies the inverse of this transform to the source point if possible.

Overrides:
inverseTransform in class java.awt.geom.AffineTransform
Parameters:
ptSrc - point to be transformed
ptDst - result of transform will be placed in this point
Returns:
the transformed point

inverseTransform

public java.awt.geom.Dimension2D inverseTransform(java.awt.geom.Dimension2D dimSrc,
                                                  java.awt.geom.Dimension2D dimDst)
Applies the inverse of this transform to the source dimension if possible.

Parameters:
dimSrc - dimension to be transformed
dimDst - result of transform will be placed in this dimension
Returns:
the transformed dimension

transform

public java.awt.geom.Rectangle2D transform(java.awt.geom.Rectangle2D rectSrc,
                                           java.awt.geom.Rectangle2D rectDst)
Applies this transform to the source rectangle and stores the result in rectDst.

Parameters:
rectSrc - rectangle to be transformed
rectDst - result of transform will be placed in this rectangle
Returns:
the transformed rectangle

inverseTransform

public java.awt.geom.Rectangle2D inverseTransform(java.awt.geom.Rectangle2D rectSrc,
                                                  java.awt.geom.Rectangle2D rectDst)
Applies the inverse of this transform to the source rectangle and stores the result in rectDst.

Parameters:
rectSrc - rectangle to be transformed
rectDst - result of transform will be placed in this rectangle
Returns:
the transformed rectangle