|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.geom.AffineTransform
org.geotools.referencing.operation.matrix.XAffineTransform
public class XAffineTransform
Utility methods for affine transforms. This class provides two kind of services:
A set of public static methods working on any AffineTransform
.
An abstract base class that override all mutable AffineTransform
methods
in order to check for permission before changing the transform's state.
If checkPermission()
is defined to always throw an exception,
then XAffineTransform
is immutable.
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 | |
---|---|
XAffineTransform(java.awt.geom.AffineTransform tr)
Constructs a new XAffineTransform that is a
copy of the specified AffineTransform object. |
|
XAffineTransform(double m00,
double m10,
double m01,
double m11,
double m02,
double m12)
Constructs a new XAffineTransform from 6 values representing the 6 specifiable
entries of the 3×3 transformation matrix. |
Method Summary | |
---|---|
protected void |
checkPermission()
Checks if the caller is allowed to change this XAffineTransform state. |
void |
concatenate(java.awt.geom.AffineTransform Tx)
Checks for permission before concatenating this transform. |
static int |
getFlip(java.awt.geom.AffineTransform tr)
Returns -1 if one axis has been flipped, +1 if no axis has been flipped,
or 0 if unknown. |
static double |
getRotation(java.awt.geom.AffineTransform tr)
Returns an estimation of the rotation angle in radians. |
static double |
getScale(java.awt.geom.AffineTransform tr)
Returns a global scale factor for the specified affine transform. |
static java.awt.geom.AffineTransform |
getScaleInstance(double sx,
double sy,
double x,
double y)
Returns an affine transform representing a zoom carried out around a central point (x, y). |
static double |
getScaleX0(java.awt.geom.AffineTransform tr)
Returns the magnitude of scale factor x by cancelling the effect of eventual flip and rotation. |
static double |
getScaleY0(java.awt.geom.AffineTransform tr)
Returns the magnitude of scale factor y by cancelling the effect of eventual flip and rotation. |
static int |
getSwapXY(java.awt.geom.AffineTransform tr)
Returns an estimation about whatever the specified transform swaps x and y axis. |
static java.awt.geom.Point2D |
inverseDeltaTransform(java.awt.geom.AffineTransform transform,
java.awt.geom.Point2D source,
java.awt.geom.Point2D dest)
Calculates the inverse affine transform of a point without without applying the translation components. |
static java.awt.geom.Rectangle2D |
inverseTransform(java.awt.geom.AffineTransform transform,
java.awt.geom.Rectangle2D bounds,
java.awt.geom.Rectangle2D dest)
Returns a rectangle which entirely contains the inverse transform of bounds . |
static boolean |
isIdentity(java.awt.geom.AffineTransform tr,
double tolerance)
Returns true if the specified affine transform is an identity transform up to the
specified tolerance. |
boolean |
isIdentity(double tolerance)
Checks whether or not this XAffineTransform is the identity by
using the provided tolerance . |
void |
preConcatenate(java.awt.geom.AffineTransform Tx)
Checks for permission before concatenating this transform. |
void |
rotate(double theta)
Checks for permission before rotating this transform. |
void |
rotate(double theta,
double x,
double y)
Checks for permission before rotating this transform. |
static void |
round(java.awt.geom.AffineTransform tr,
double tolerance)
Checks whether the matrix coefficients are close to whole numbers. |
void |
scale(double sx,
double sy)
Checks for permission before scaling this transform. |
void |
setToIdentity()
Checks for permission before setting this transform. |
void |
setToRotation(double theta)
Checks for permission before setting this transform. |
void |
setToRotation(double theta,
double x,
double y)
Checks for permission before setting this transform. |
void |
setToScale(double sx,
double sy)
Checks for permission before setting this transform. |
void |
setToShear(double shx,
double shy)
Checks for permission before setting this transform. |
void |
setToTranslation(double tx,
double ty)
Checks for permission before setting this transform. |
void |
setTransform(java.awt.geom.AffineTransform Tx)
Checks for permission before setting this transform. |
void |
setTransform(double m00,
double m10,
double m01,
double m11,
double m02,
double m12)
Checks for permission before setting this transform. |
void |
shear(double shx,
double shy)
Checks for permission before shearing this transform. |
static java.awt.geom.Rectangle2D |
transform(java.awt.geom.AffineTransform transform,
java.awt.geom.Rectangle2D bounds,
java.awt.geom.Rectangle2D dest)
Returns a rectangle which entirely contains the direct transform of bounds . |
static java.awt.Shape |
transform(java.awt.geom.AffineTransform transform,
java.awt.Shape shape,
boolean overwrite)
Transforms the given shape. |
void |
translate(double tx,
double ty)
Checks for permission before translating this transform. |
Methods inherited from class java.awt.geom.AffineTransform |
---|
clone, 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 |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public XAffineTransform(java.awt.geom.AffineTransform tr)
XAffineTransform
that is a
copy of the specified AffineTransform
object.
public XAffineTransform(double m00, double m10, double m01, double m11, double m02, double m12)
XAffineTransform
from 6 values representing the 6 specifiable
entries of the 3×3 transformation matrix. Those values are given unchanged to the
super
class constructor
.
Method Detail |
---|
protected void checkPermission() throws java.lang.UnsupportedOperationException
XAffineTransform
state.
If this method is defined to thrown an exception in all case, then this
XAffineTransform
is immutable.
The default implementation throws the exception in all case, thus making this instance immutable.
java.lang.UnsupportedOperationException
- if this affine transform is immutable.public void translate(double tx, double ty)
translate
in class java.awt.geom.AffineTransform
public void rotate(double theta)
rotate
in class java.awt.geom.AffineTransform
public void rotate(double theta, double x, double y)
rotate
in class java.awt.geom.AffineTransform
public void scale(double sx, double sy)
scale
in class java.awt.geom.AffineTransform
public void shear(double shx, double shy)
shear
in class java.awt.geom.AffineTransform
public void setToIdentity()
setToIdentity
in class java.awt.geom.AffineTransform
public void setToTranslation(double tx, double ty)
setToTranslation
in class java.awt.geom.AffineTransform
public void setToRotation(double theta)
setToRotation
in class java.awt.geom.AffineTransform
public void setToRotation(double theta, double x, double y)
setToRotation
in class java.awt.geom.AffineTransform
public void setToScale(double sx, double sy)
setToScale
in class java.awt.geom.AffineTransform
public void setToShear(double shx, double shy)
setToShear
in class java.awt.geom.AffineTransform
public void setTransform(java.awt.geom.AffineTransform Tx)
setTransform
in class java.awt.geom.AffineTransform
public void setTransform(double m00, double m10, double m01, double m11, double m02, double m12)
setTransform
in class java.awt.geom.AffineTransform
public void concatenate(java.awt.geom.AffineTransform Tx)
concatenate
in class java.awt.geom.AffineTransform
public void preConcatenate(java.awt.geom.AffineTransform Tx)
preConcatenate
in class java.awt.geom.AffineTransform
public boolean isIdentity(double tolerance)
XAffineTransform
is the identity by
using the provided tolerance
.
tolerance
- The tolerance to use for this check.
true
if the transform is identity, false
otherwise.public static boolean isIdentity(java.awt.geom.AffineTransform tr, double tolerance)
true
if 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 by new AffineTransform()
) and returning true
if and only if all differences are
smaller than or equal to tolerance
.
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 ]
tr
- The affine transform to be checked for identity.tolerance
- The tolerance value to use when checking for identity.
return true
if this tranformation is close enough to the
identity, false
otherwise.public static java.awt.Shape transform(java.awt.geom.AffineTransform transform, java.awt.Shape shape, boolean overwrite)
createTransformedShape
except that:
RectangularShape
and the given transform do not involve
rotation, then the returned shape may be some instance of the same class.overwrite
is true
.
transform
- Affine transform to use.shape
- The shape to transform.overwrite
- If true
, this method is allowed to overwrite shape
with the
transform result. If false
, then shape
is never modified.
AffineTransform.createTransformedShape(java.awt.Shape)
public static java.awt.geom.Rectangle2D transform(java.awt.geom.AffineTransform transform, java.awt.geom.Rectangle2D bounds, java.awt.geom.Rectangle2D dest)
bounds
. This operation is equivalent to:
createTransformedShape(bounds).getBounds2D()
transform
- Affine transform to use.bounds
- Rectangle to transform. This rectangle will not be modified except
if dest
is the same reference.dest
- Rectangle in which to place the result.
If null, a new rectangle will be created.
bounds
rectangle.CRS.transform(
org.opengis.referencing.operation.MathTransform2D, Rectangle2D, Rectangle2D)
public static java.awt.geom.Rectangle2D inverseTransform(java.awt.geom.AffineTransform transform, java.awt.geom.Rectangle2D bounds, java.awt.geom.Rectangle2D dest) throws java.awt.geom.NoninvertibleTransformException
bounds
. This operation is equivalent to:
createInverse().createTransformedShape(bounds).getBounds2D()
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.
bounds
rectangle.
java.awt.geom.NoninvertibleTransformException
- if the affine transform can't be inverted.public static java.awt.geom.Point2D inverseDeltaTransform(java.awt.geom.AffineTransform transform, java.awt.geom.Point2D source, java.awt.geom.Point2D dest) throws java.awt.geom.NoninvertibleTransformException
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.
source
point.
java.awt.geom.NoninvertibleTransformException
- if the affine transform can't be inverted.public static int getSwapXY(java.awt.geom.AffineTransform tr)
+1
if the (x, y) axis order seems to be
preserved, -1
if the transform seems to swap axis to the (y,
x) axis order, or 0
if this method can not make a decision.
public static double getRotation(java.awt.geom.AffineTransform tr)
tr
- The affine transform to inspect.
NaN
if the angle can not be estimated.public static int getFlip(java.awt.geom.AffineTransform tr)
-1
if one axis has been flipped, +1
if 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:
double scaleX0 = getScaleX0(transform);
double scaleY0 = getScaleY0(transform);
int flip = getFlip(transform);
if (flip != 0) {
scaleY0 *= flip;
// ... continue the process here.
}
This method is similar to the following code, except that this method
distinguish between "unflipped" and "unknow" states.
boolean flipped = (tr.getType() & AffineTransform.TYPE_FLIP) != 0;
public static double getScaleX0(java.awt.geom.AffineTransform tr)
public static double getScaleY0(java.awt.geom.AffineTransform tr)
public static double getScale(java.awt.geom.AffineTransform tr)
getScaleX0(java.awt.geom.AffineTransform)
and getScaleY0(java.awt.geom.AffineTransform)
.
The way to compute such a "global" scale is somewhat arbitrary and may change
in a future version.
public static java.awt.geom.AffineTransform getScaleInstance(double sx, double sy, double x, double y)
sx
- Scale along x axis.sy
- Scale along y axis.x
- x coordinates of the central point.y
- y coordinates of the central point.
public static void round(java.awt.geom.AffineTransform tr, double tolerance)
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
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |