Class XAffineTransform
- All Implemented Interfaces:
- Serializable,- Cloneable
- Direct Known Subclasses:
- AffineTransform2D
- 
       A set of public static methods working on any AffineTransform.
- 
       An abstract base class that override all mutable AffineTransformmethods in order to check for permission before changing the transform's state. IfcheckPermission()is defined to always throw an exception, thenXAffineTransformis immutable.
- Since:
- 2.3
- Author:
- Martin Desruisseaux (IRD), Simone Giannecchini
- See Also:
- 
Field SummaryFields inherited from class AffineTransformTYPE_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 SummaryConstructorsConstructorDescriptionXAffineTransform(double m00, double m10, double m01, double m11, double m02, double m12) Constructs a newXAffineTransformfrom 6 values representing the 6 specifiable entries of the 3×3 transformation matrix.Constructs a newXAffineTransformthat is a copy of the specifiedAffineTransformobject.
- 
Method SummaryModifier and TypeMethodDescriptionprotected voidChecks if the caller is allowed to change thisXAffineTransformstate.voidChecks for permission before concatenating this transform.static intReturns-1if one axis has been flipped,+1if no axis has been flipped, or 0 if unknown.static doubleReturns an estimation of the rotation angle in radians.static doubleReturns a global scale factor for the specified affine transform.static AffineTransformgetScaleInstance(double sx, double sy, double x, double y) Returns an affine transform representing a zoom carried out around a central point (x, y).static doubleReturns the magnitude of scale factor x by cancelling the effect of eventual flip and rotation.static doubleReturns the magnitude of scale factor y by cancelling the effect of eventual flip and rotation.static intReturns an estimation about whatever the specified transform swaps x and y axis.static Point2DinverseDeltaTransform(AffineTransform transform, Point2D source, Point2D dest) Calculates the inverse affine transform of a point without without applying the translation components.static Rectangle2DinverseTransform(AffineTransform transform, Rectangle2D bounds, Rectangle2D dest) Returns a rectangle which entirely contains the inverse transform ofbounds.booleanisIdentity(double tolerance) Checks whether or not thisXAffineTransformis the identity by using the providedtolerance.static booleanisIdentity(AffineTransform tr, double tolerance) Returnstrueif the specified affine transform is an identity transform up to the specified tolerance.voidChecks for permission before concatenating this transform.voidrotate(double theta) Checks for permission before rotating this transform.voidrotate(double theta, double x, double y) Checks for permission before rotating this transform.static voidround(AffineTransform tr, double tolerance) Checks whether the matrix coefficients are close to whole numbers.voidscale(double sx, double sy) Checks for permission before scaling this transform.voidChecks for permission before setting this transform.voidsetToRotation(double theta) Checks for permission before setting this transform.voidsetToRotation(double theta, double x, double y) Checks for permission before setting this transform.voidsetToScale(double sx, double sy) Checks for permission before setting this transform.voidsetToShear(double shx, double shy) Checks for permission before setting this transform.voidsetToTranslation(double tx, double ty) Checks for permission before setting this transform.voidsetTransform(double m00, double m10, double m01, double m11, double m02, double m12) Checks for permission before setting this transform.voidChecks for permission before setting this transform.voidshear(double shx, double shy) Checks for permission before shearing this transform.static Rectangle2Dtransform(AffineTransform transform, Rectangle2D bounds, Rectangle2D dest) Returns a rectangle which entirely contains the direct transform ofbounds.static Shapetransform(AffineTransform transform, Shape shape, boolean overwrite) Transforms the given shape.voidtranslate(double tx, double ty) Checks for permission before translating this transform.Methods inherited from class AffineTransformclone, 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, inverseTransform, invert, isIdentity, quadrantRotate, quadrantRotate, rotate, rotate, setToQuadrantRotation, setToQuadrantRotation, setToRotation, setToRotation, toString, transform, transform, transform, transform, transform, transform
- 
Constructor Details- 
XAffineTransformConstructs a newXAffineTransformthat is a copy of the specifiedAffineTransformobject.
- 
XAffineTransformpublic XAffineTransform(double m00, double m10, double m01, double m11, double m02, double m12) Constructs a newXAffineTransformfrom 6 values representing the 6 specifiable entries of the 3×3 transformation matrix. Those values are given unchanged to thesuper class constructor.- Since:
- 2.5
 
 
- 
- 
Method Details- 
checkPermissionChecks if the caller is allowed to change thisXAffineTransformstate. If this method is defined to thrown an exception in all case, then thisXAffineTransformis immutable.The default implementation throws the exception in all case, thus making this instance immutable. - Throws:
- UnsupportedOperationException- if this affine transform is immutable.
 
- 
translatepublic void translate(double tx, double ty) Checks for permission before translating this transform.- Overrides:
- translatein class- AffineTransform
 
- 
rotatepublic void rotate(double theta) Checks for permission before rotating this transform.- Overrides:
- rotatein class- AffineTransform
 
- 
rotatepublic void rotate(double theta, double x, double y) Checks for permission before rotating this transform.- Overrides:
- rotatein class- AffineTransform
 
- 
scalepublic void scale(double sx, double sy) Checks for permission before scaling this transform.- Overrides:
- scalein class- AffineTransform
 
- 
shearpublic void shear(double shx, double shy) Checks for permission before shearing this transform.- Overrides:
- shearin class- AffineTransform
 
- 
setToIdentitypublic void setToIdentity()Checks for permission before setting this transform.- Overrides:
- setToIdentityin class- AffineTransform
 
- 
setToTranslationpublic void setToTranslation(double tx, double ty) Checks for permission before setting this transform.- Overrides:
- setToTranslationin class- AffineTransform
 
- 
setToRotationpublic void setToRotation(double theta) Checks for permission before setting this transform.- Overrides:
- setToRotationin class- AffineTransform
 
- 
setToRotationpublic void setToRotation(double theta, double x, double y) Checks for permission before setting this transform.- Overrides:
- setToRotationin class- AffineTransform
 
- 
setToScalepublic void setToScale(double sx, double sy) Checks for permission before setting this transform.- Overrides:
- setToScalein class- AffineTransform
 
- 
setToShearpublic void setToShear(double shx, double shy) Checks for permission before setting this transform.- Overrides:
- setToShearin class- AffineTransform
 
- 
setTransformChecks for permission before setting this transform.- Overrides:
- setTransformin class- AffineTransform
 
- 
setTransformpublic void setTransform(double m00, double m10, double m01, double m11, double m02, double m12) Checks for permission before setting this transform.- Overrides:
- setTransformin class- AffineTransform
 
- 
concatenateChecks for permission before concatenating this transform.- Overrides:
- concatenatein class- AffineTransform
 
- 
preConcatenateChecks for permission before concatenating this transform.- Overrides:
- preConcatenatein class- AffineTransform
 
- 
isIdentitypublic boolean isIdentity(double tolerance) Checks whether or not thisXAffineTransformis the identity by using the providedtolerance.- Parameters:
- tolerance- The tolerance to use for this check.
- Returns:
- trueif the transform is identity,- falseotherwise.
- Since:
- 2.3.1
 
- 
isIdentityReturnstrueif the specified affine transform is an identity transform up to the specified tolerance. This method is equivalent to computing the difference between this matrix and an identity matrix (as created bynew AffineTransform()) and returningtrueif and only if all differences are smaller than or equal totolerance.This method is used for working around rounding error in affine transforms resulting from a computation, as in the example below: [ 1.0000000000000000001 0.0 0.0 ] [ 0.0 0.999999999999999999999 0.0 ] [ 0.0 0.0 1.0 ] - Parameters:
- tr- The affine transform to be checked for identity.
- tolerance- The tolerance value to use when checking for identity. return- trueif this tranformation is close enough to the identity,- falseotherwise.
- Since:
- 2.3.1
 
- 
transformTransforms the given shape. This method is similar tocreateTransformedShapeexcept that:- It tries to preserve the shape kind when possible. For example if the given shape is an instance of
       RectangularShapeand the given transform do not involve rotation, then the returned shape may be some instance of the same class.
- It tries to recycle the given object if overwriteistrue.
 - Parameters:
- transform- Affine transform to use.
- shape- The shape to transform.
- overwrite- If- true, this method is allowed to overwrite- shapewith the transform result. If- false, then- shapeis never modified.
- Returns:
- The direct transform of the given shape. May or may not be the same instance than the given shape.
- Since:
- 2.5
- See Also:
 
- It tries to preserve the shape kind when possible. For example if the given shape is an instance of
       
- 
transformpublic static Rectangle2D transform(AffineTransform transform, Rectangle2D bounds, Rectangle2D dest) Returns a rectangle which entirely contains the direct transform ofbounds. This operation is equivalent to:createTransformedShape(bounds).getBounds2D()- Parameters:
- transform- Affine transform to use.
- bounds- Rectangle to transform. This rectangle will not be modified except if- destis the same reference.
- dest- Rectangle in which to place the result. If null, a new rectangle will be created.
- Returns:
- The direct transform of the boundsrectangle.
- See Also:
 
- 
inverseTransformpublic static Rectangle2D inverseTransform(AffineTransform transform, Rectangle2D bounds, Rectangle2D dest) throws NoninvertibleTransformException Returns a rectangle which entirely contains the inverse transform ofbounds. This operation is equivalent to:createInverse().createTransformedShape(bounds).getBounds2D()- Parameters:
- transform- Affine transform to use.
- bounds- Rectangle to transform. This rectangle will not be modified.
- dest- Rectangle in which to place the result. If null, a new rectangle will be created.
- Returns:
- The inverse transform of the boundsrectangle.
- Throws:
- NoninvertibleTransformException- if the affine transform can't be inverted.
 
- 
inverseDeltaTransformpublic static Point2D inverseDeltaTransform(AffineTransform transform, Point2D source, Point2D dest) throws NoninvertibleTransformException Calculates the inverse affine transform of a point without without applying the translation components.- Parameters:
- transform- Affine transform to use.
- source- Point to transform. This rectangle will not be modified.
- dest- Point in which to place the result. If- null, a new point will be created.
- Returns:
- The inverse transform of the sourcepoint.
- Throws:
- NoninvertibleTransformException- if the affine transform can't be inverted.
 
- 
getSwapXYReturns an estimation about whatever the specified transform swaps x and y axis. This method assumes that the specified affine transform is built from arbitrary translations, scales or rotations, but no shear. It returns+1if the (x, y) axis order seems to be preserved,-1if the transform seems to swap axis to the (y, x) axis order, or0if this method can not make a decision.
- 
getRotationReturns an estimation of the rotation angle in radians. This method assumes that the specified affine transform is built from arbitrary translations, scales or rotations, but no shear. If a flip has been applied, then this method assumes that the flipped axis is the y one in source CRS space. For a grid to world CRS transform, this is the row number in grid coordinates.- Parameters:
- tr- The affine transform to inspect.
- Returns:
- An estimation of the rotation angle in radians, or NaNif the angle can not be estimated.
 
- 
getFlipReturns-1if one axis has been flipped,+1if no axis has been flipped, or 0 if unknown. A flipped axis in an axis with direction reversed (typically the y axis). This method assumes that the specified affine transform is built from arbitrary translations, scales or rotations, but no shear. Note that it is not possible to determine which of the x or y axis has been flipped.This method can be used in order to set the sign of a scale according the flipping state. The example below choose to apply the sign on the y scale, but this is an arbitrary (while common) choice: 
 This method is similar to the following code, except that this method distinguish between "unflipped" and "unknow" states.double scaleX0 = getScaleX0(transform); double scaleY0 = getScaleY0(transform); int flip = getFlip(transform); if (flip != 0) { scaleY0 *= flip; // ... continue the process here. }boolean flipped = (tr.getType() & AffineTransform.TYPE_FLIP) != 0;
- 
getScaleX0Returns the magnitude of scale factor x by cancelling the effect of eventual flip and rotation. This factor is calculated by . .
- 
getScaleY0Returns the magnitude of scale factor y by cancelling the effect of eventual flip and rotation. This factor is calculated by . .
- 
getScaleReturns a global scale factor for the specified affine transform. This scale factor will combinesgetScaleX0(java.awt.geom.AffineTransform)andgetScaleY0(java.awt.geom.AffineTransform). The way to compute such a "global" scale is somewhat arbitrary and may change in a future version.
- 
getScaleInstanceReturns an affine transform representing a zoom carried out around a central point (x, y). The transforms will leave the specified (x, y) coordinate unchanged.- Parameters:
- sx- Scale along x axis.
- sy- Scale along y axis.
- x- x coordinates of the central point.
- y- y coordinates of the central point.
- Returns:
- Affine transform of a zoom which leaves the (x,y) coordinate unchanged.
 
- 
roundChecks whether the matrix coefficients are close to whole numbers. If this is the case, these coefficients will be rounded up to the nearest whole numbers. This rounding up is useful, for example, for speeding up image displays. Above all, it is efficient when we know that a matrix has a chance of being close to the similarity matrix.- Parameters:
- tr- The matrix to round. Rounding will be applied in place.
- tolerance- The maximal departure from integers in order to allow rounding. It is typically a small number like- 1E-6.
- Since:
- 2.3.1
 
 
-