Package org.eclipse.gef.geometry.planar
Class AffineTransform
- java.lang.Object
-
- org.eclipse.gef.geometry.planar.AffineTransform
-
- All Implemented Interfaces:
java.lang.Cloneable
public class AffineTransform extends java.lang.Object implements java.lang.Cloneable
The
AffineTransform
class provides methods to create and modify 2-dimensional affine transformations.It delegates to the
AffineTransform
functionality.
-
-
Constructor Summary
Constructors Constructor Description AffineTransform()
Creates a newAffineTransform
with its transformation matrix set to the identity matrix.AffineTransform(double[] flatmatrix)
Creates a newAffineTransform
with its transformation matrix set to the values of the passed-in array.AffineTransform(double m00, double m10, double m01, double m11, double m02, double m12)
Creates a newAffineTransform
with its transformation matrix set to the specified values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
clone()
AffineTransform
concatenate(AffineTransform Tx)
Concatenates thisAffineTransform
and the givenAffineTransform
, multiplying the transformation matrix of thisAffineTransform
from the left with the transformation matrix of the otherAffineTransform
.void
deltaTransform(double[] srcPts, int srcOff, double[] dstPts, int dstOff, int numPts)
Transforms an array ofPoint
s specified by their coordinate values with thisAffineTransform
without applying the translation components of the transformation matrix of thisAffineTransform
.Point
deltaTransform(Point pt)
Transforms the givenPoint
with thisAffineTransform
without applying the translation components of the transformation matrix of thisAffineTransform
.boolean
equals(java.lang.Object obj)
AffineTransform
getCopy()
Returns a copy of thisAffineTransform
.double
getDeterminant()
Computes the determinant of the transformation matrix of thisAffineTransform
.AffineTransform
getInverse()
Creates a newAffineTransform
that represents the inverse transformation of thisAffineTransform
.double
getM00()
Returns the matrix component in the first row and first column.double
getM01()
Returns the matrix component in the first row and second column.double
getM10()
Returns the matrix component in the second row and first column.double
getM11()
Returns the matrix component in the second row and second column.double[]
getMatrix()
Returns the 6 specifiable elements of the transformation matrix of thisAffineTransform
.Angle
getRotation()
Returns the rotation component of thisAffineTransform
.double
getScaleX()
Returns the x coordinate scaling of thisAffineTransform
's transformation matrix.double
getScaleY()
Returns the y coordinate scaling of thisAffineTransform
's transformation matrix.Point
getTransformed(Point ptSrc)
Transforms the givenPoint
with thisAffineTransform
by multiplying the transformation matrix of thisAffineTransform
with the givenPoint
.Point[]
getTransformed(Point[] points)
Transforms the given array ofPoint
s with thisAffineTransform
by multiplying the transformation matrix of thisAffineTransform
individually with each of the givenPoint
s.double
getTranslateX()
Returns the x coordinate translation of thisAffineTransform
's transformation matrix.double
getTranslateY()
Returns the y coordinate translation of thisAffineTransform
's transformation matrix.int
getType()
Returns the type of transformation represented by thisAffineTransform
.int
hashCode()
void
inverseTransform(double[] srcPts, int srcOff, double[] dstPts, int dstOff, int numPts)
Inverse transforms an array ofPoint
s specified by their coordinate values with thisAffineTransform
.Point
inverseTransform(Point pt)
Inverse transforms the givenPoint
with thisAffineTransform
.AffineTransform
invert()
Inverts thisAffineTransform
.boolean
isIdentity()
Checks if the transformation matrix of thisAffineTransform
equals the identity matrix.AffineTransform
preConcatenate(AffineTransform Tx)
Concatenates thisAffineTransform
and the givenAffineTransform
in reverse order, multiplying the transformation matrix of thisAffineTransform
from the right with the transformation matrix of the otherAffineTransform
.AffineTransform
quadrantRotate(int numquadrants)
Adds a rotation by an integer multiple of 90deg to the transformation matrix of thisAffineTransform
.AffineTransform
quadrantRotate(int numquadrants, double anchorx, double anchory)
Adds a rotation by an integer multiple of 90deg around thePoint
specified by the given x and y coordinates to the transformation matrix of thisAffineTransform
.AffineTransform
rotate(double theta)
Adds a rotation with the given angle (in radians) to the transformation matrix of thisAffineTransform
.AffineTransform
rotate(double vecx, double vecy)
Adds a rotation to the transformation matrix of thisAffineTransform
.AffineTransform
rotate(double theta, double anchorx, double anchory)
Adds a rotation with the given angle (in radians) around thePoint
specified by the given x and y coordinates to the transformation matrix of thisAffineTransform
.AffineTransform
rotate(double vecx, double vecy, double anchorx, double anchory)
Adds a rotation around aPoint
to the transformation matrix of thisAffineTransform
.AffineTransform
scale(double sx, double sy)
Adds an x and y scaling to the transformation matrix of thisAffineTransform
.AffineTransform
setToIdentity()
Sets the transformation matrix of thisAffineTransform
to the identity matrix.AffineTransform
setToQuadrantRotation(int numquadrants)
Sets the transformation matrix of thisAffineTransform
to a pure rotation matrix where the rotation angle is an integer multiple of 90deg.AffineTransform
setToQuadrantRotation(int numquadrants, double anchorx, double anchory)
Sets the transformation matrix of thisAffineTransform
to a pure rotation and translation matrix where the rotation angle is an integer multiple of 90deg and the rotation is around thePoint
specified by the given x and y coordinates.AffineTransform
setToRotation(double theta)
Sets the transformation matrix of thisAffineTransform
to a pure rotation matrix by the given angle specified in radians.AffineTransform
setToRotation(double vecx, double vecy)
Sets the transformation matrix of thisAffineTransform
to a pure rotation matrix.AffineTransform
setToRotation(double theta, double anchorx, double anchory)
Sets the transformation matrix of thisAffineTransform
to a pure rotation and translation matrix.AffineTransform
setToRotation(double vecx, double vecy, double anchorx, double anchory)
Sets the transformation matrix of thisAffineTransform
to a pure rotation and translation matrix.AffineTransform
setToScale(double sx, double sy)
Sets the transformation matrix of thisAffineTransform
to a pure scaling matrix.AffineTransform
setToShear(double shx, double shy)
Sets the transformation matrix of thisAffineTransform
to a pure shearing matrix.AffineTransform
setToTranslation(double tx, double ty)
Sets the transformation matrix of thisAffineTransform
to a pure translation matrix that translatesPoint
s by the given x and y values.AffineTransform
setTransform(double m00, double m10, double m01, double m11, double m02, double m12)
Sets the respective values of the transformation matrix of thisAffineTransform
to the supplied ones.AffineTransform
setTransform(AffineTransform Tx)
Sets the transformation matrix of thisAffineTransform
to the transformation matrix of the givenAffineTransform
.AffineTransform
shear(double shx, double shy)
Adds an x and y shearing to the transformation matrix of thisAffineTransform
.java.lang.String
toString()
AffineTransform
translate(double tx, double ty)
Sets the translation values of the x and y coordinates of the transformation matrix of thisAffineTransform
.
-
-
-
Constructor Detail
-
AffineTransform
public AffineTransform()
Creates a newAffineTransform
with its transformation matrix set to the identity matrix.
-
AffineTransform
public AffineTransform(double m00, double m10, double m01, double m11, double m02, double m12)
Creates a newAffineTransform
with its transformation matrix set to the specified values. Note that rotation is a combination of shearing and scaling.- Parameters:
m00
- the value of the transformation matrix in row 0 and column 0 (x coordinate scaling)m10
- the value of the transformation matrix in row 1 and column 0 (y coordinate shearing)m01
- the value of the transformation matrix in row 0 and column 1 (x coordinate shearing)m11
- the value of the transformation matrix in row 1 and column 1 (y coordinate scaling)m02
- the value of the transformation matrix in row 0 and column 2 (x coordinate translation)m12
- the value of the transformation matrix in row 1 and column 2 (y coordinate translation)
-
AffineTransform
public AffineTransform(double[] flatmatrix)
Creates a newAffineTransform
with its transformation matrix set to the values of the passed-in array. See theAffineTransform(double, double, double, double, double, double)
or theAffineTransform(double[])
method for a specification of the values in the array.- Parameters:
flatmatrix
- the values for the transformation matrix- See Also:
AffineTransform(double, double, double, double, double, double)
-
-
Method Detail
-
clone
public java.lang.Object clone()
- Overrides:
clone
in classjava.lang.Object
-
concatenate
public AffineTransform concatenate(AffineTransform Tx)
Concatenates thisAffineTransform
and the givenAffineTransform
, multiplying the transformation matrix of thisAffineTransform
from the left with the transformation matrix of the otherAffineTransform
.- Parameters:
Tx
- theAffineTransform
that is concatenated with thisAffineTransform
- Returns:
this
for convenience
-
deltaTransform
public void deltaTransform(double[] srcPts, int srcOff, double[] dstPts, int dstOff, int numPts)
Transforms an array ofPoint
s specified by their coordinate values with thisAffineTransform
without applying the translation components of the transformation matrix of thisAffineTransform
.- Parameters:
srcPts
- the array of x and y coordinates specifying thePoint
s that are transformedsrcOff
- the index of the srcPts array where the x coordinate of the firstPoint
to transform is founddstPts
- the destination array of x and y coordinates for the result of the transformationdstOff
- the index of the dstPts array where the x coordinate of the first transformedPoint
is storednumPts
- the number ofPoint
s to transform
-
deltaTransform
public Point deltaTransform(Point pt)
Transforms the givenPoint
with thisAffineTransform
without applying the translation components of the transformation matrix of thisAffineTransform
.
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
getCopy
public AffineTransform getCopy()
Returns a copy of thisAffineTransform
.- Returns:
- a copy of this
AffineTransform
-
getDeterminant
public double getDeterminant()
Computes the determinant of the transformation matrix of thisAffineTransform
.- Returns:
- the determinant of the transformation matrix of this
AffineTransform
-
getInverse
public AffineTransform getInverse()
Creates a newAffineTransform
that represents the inverse transformation of thisAffineTransform
.- Returns:
- a new
AffineTransform
that represents the inverse transformation of thisAffineTransform
-
getM00
public double getM00()
Returns the matrix component in the first row and first column.- Returns:
- The matrix component in the first row and first column.
-
getM01
public double getM01()
Returns the matrix component in the first row and second column.- Returns:
- The matrix component in the first row and second column.
-
getM10
public double getM10()
Returns the matrix component in the second row and first column.- Returns:
- The matrix component in the second row and first column.
-
getM11
public double getM11()
Returns the matrix component in the second row and second column.- Returns:
- The matrix component in the second row and second column.
-
getMatrix
public double[] getMatrix()
Returns the 6 specifiable elements of the transformation matrix of thisAffineTransform
.- Returns:
- the 6 specifiable elements of the transformation matrix of this
AffineTransform
-
getRotation
public Angle getRotation()
Returns the rotation component of thisAffineTransform
.- Returns:
- The rotation component of this
AffineTransform
.
-
getScaleX
public double getScaleX()
Returns the x coordinate scaling of thisAffineTransform
's transformation matrix.- Returns:
- the x coordinate scaling of this
AffineTransform
's transformation matrix
-
getScaleY
public double getScaleY()
Returns the y coordinate scaling of thisAffineTransform
's transformation matrix.- Returns:
- the y coordinate scaling of this
AffineTransform
's transformation matrix
-
getTransformed
public Point getTransformed(Point ptSrc)
Transforms the givenPoint
with thisAffineTransform
by multiplying the transformation matrix of thisAffineTransform
with the givenPoint
.
-
getTransformed
public Point[] getTransformed(Point[] points)
Transforms the given array ofPoint
s with thisAffineTransform
by multiplying the transformation matrix of thisAffineTransform
individually with each of the givenPoint
s.
-
getTranslateX
public double getTranslateX()
Returns the x coordinate translation of thisAffineTransform
's transformation matrix.- Returns:
- the x coordinate translation of this
AffineTransform
's transformation matrix
-
getTranslateY
public double getTranslateY()
Returns the y coordinate translation of thisAffineTransform
's transformation matrix.- Returns:
- the y coordinate translation of this
AffineTransform
's transformation matrix
-
getType
public int getType()
Returns the type of transformation represented by thisAffineTransform
. See theAffineTransform.getType()
method for a specification of the return type of this method.- Returns:
- the type of transformation represented by this
AffineTransform
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
inverseTransform
public void inverseTransform(double[] srcPts, int srcOff, double[] dstPts, int dstOff, int numPts) throws java.awt.geom.NoninvertibleTransformException
Inverse transforms an array ofPoint
s specified by their coordinate values with thisAffineTransform
.- Parameters:
srcPts
- the array of x and y coordinates specifying thePoint
s that are inverse transformedsrcOff
- the index of the srcPts array where the x coordinate of the firstPoint
to inverse transform is founddstPts
- the destination array of x and y coordinates for the result of the inverse transformationdstOff
- the index of the dstPts array where the x coordinate of the first inverse transformedPoint
is storednumPts
- the number ofPoint
s to inverse transform- Throws:
java.awt.geom.NoninvertibleTransformException
- when thisAffineTransform
is not invertible.
-
inverseTransform
public Point inverseTransform(Point pt) throws java.awt.geom.NoninvertibleTransformException
Inverse transforms the givenPoint
with thisAffineTransform
.- Parameters:
pt
- thePoint
to inverse transform- Returns:
- a new, inverse transformed
Point
- Throws:
java.awt.geom.NoninvertibleTransformException
- when thisAffineTransform
is not invertible.
-
invert
public AffineTransform invert() throws java.awt.geom.NoninvertibleTransformException
Inverts thisAffineTransform
.- Returns:
this
for convenience- Throws:
java.awt.geom.NoninvertibleTransformException
- when thisAffineTransform
is not invertible.
-
isIdentity
public boolean isIdentity()
Checks if the transformation matrix of thisAffineTransform
equals the identity matrix.- Returns:
true
if the transformation matrix of thisAffineTransform
equals the identity matrix, otherwisefalse
-
preConcatenate
public AffineTransform preConcatenate(AffineTransform Tx)
Concatenates thisAffineTransform
and the givenAffineTransform
in reverse order, multiplying the transformation matrix of thisAffineTransform
from the right with the transformation matrix of the otherAffineTransform
.- Parameters:
Tx
- theAffineTransform
that is concatenated with thisAffineTransform
in reverse order- Returns:
this
for convenience
-
quadrantRotate
public AffineTransform quadrantRotate(int numquadrants)
Adds a rotation by an integer multiple of 90deg to the transformation matrix of thisAffineTransform
. The integer multiple of 90deg is specified by the given number of quadrants.- Parameters:
numquadrants
- the integer that defines the number of quadrants to rotate by- Returns:
this
for convenience
-
quadrantRotate
public AffineTransform quadrantRotate(int numquadrants, double anchorx, double anchory)
Adds a rotation by an integer multiple of 90deg around thePoint
specified by the given x and y coordinates to the transformation matrix of thisAffineTransform
.
-
rotate
public AffineTransform rotate(double theta)
Adds a rotation with the given angle (in radians) to the transformation matrix of thisAffineTransform
.- Parameters:
theta
- the rotation angle in radians- Returns:
this
for convenience
-
rotate
public AffineTransform rotate(double vecx, double vecy)
Adds a rotation to the transformation matrix of thisAffineTransform
. The given coordinates specify aVector
whoseAngle
to the x-axis is the applied rotationAngle
.
-
rotate
public AffineTransform rotate(double theta, double anchorx, double anchory)
Adds a rotation with the given angle (in radians) around thePoint
specified by the given x and y coordinates to the transformation matrix of thisAffineTransform
.
-
rotate
public AffineTransform rotate(double vecx, double vecy, double anchorx, double anchory)
-
scale
public AffineTransform scale(double sx, double sy)
Adds an x and y scaling to the transformation matrix of thisAffineTransform
.- Parameters:
sx
- the x scaling factor added to the transformation matrix of thisAffineTransform
sy
- the y scaling factor added to the transformation matrix of thisAffineTransform
- Returns:
this
for convenience
-
setToIdentity
public AffineTransform setToIdentity()
Sets the transformation matrix of thisAffineTransform
to the identity matrix.- Returns:
this
for convenience
-
setToQuadrantRotation
public AffineTransform setToQuadrantRotation(int numquadrants)
Sets the transformation matrix of thisAffineTransform
to a pure rotation matrix where the rotation angle is an integer multiple of 90deg.- Parameters:
numquadrants
- the integer that defines the number of quadrants to rotate by- Returns:
this
for convenience
-
setToQuadrantRotation
public AffineTransform setToQuadrantRotation(int numquadrants, double anchorx, double anchory)
Sets the transformation matrix of thisAffineTransform
to a pure rotation and translation matrix where the rotation angle is an integer multiple of 90deg and the rotation is around thePoint
specified by the given x and y coordinates.
-
setToRotation
public AffineTransform setToRotation(double theta)
Sets the transformation matrix of thisAffineTransform
to a pure rotation matrix by the given angle specified in radians.- Parameters:
theta
- the rotation angle (in radians)- Returns:
this
for convenience
-
setToRotation
public AffineTransform setToRotation(double vecx, double vecy)
Sets the transformation matrix of thisAffineTransform
to a pure rotation matrix. The given x and y coordinates specify aVector
whoseAngle
to the x-axis defines the rotationAngle
.
-
setToRotation
public AffineTransform setToRotation(double theta, double anchorx, double anchory)
Sets the transformation matrix of thisAffineTransform
to a pure rotation and translation matrix. Thus, the resulting transformation matrix rotatesPoint
s by the given angle (in radians) around thePoint
specified by the given x and y coordinates.
-
setToRotation
public AffineTransform setToRotation(double vecx, double vecy, double anchorx, double anchory)
Sets the transformation matrix of thisAffineTransform
to a pure rotation and translation matrix. The firstly given x and y coordinates specify aVector
whoseAngle
to the x-axis defines the rotationAngle
. The secondly given x and y coordinates specify thePoint
to rotate around.- Parameters:
vecx
- the x coordinate of theVector
whoseAngle
to the x-axis defines the rotationAngle
vecy
- the y coordinate of theVector
whoseAngle
to the x-axis defines the rotationAngle
anchorx
- the x coordinate of thePoint
to rotate aroundanchory
- the y coordinate of thePoint
to rotate around- Returns:
this
for convenience
-
setToScale
public AffineTransform setToScale(double sx, double sy)
Sets the transformation matrix of thisAffineTransform
to a pure scaling matrix.- Parameters:
sx
- the x scaling factorsy
- the y scaling factor- Returns:
this
for convenience
-
setToShear
public AffineTransform setToShear(double shx, double shy)
Sets the transformation matrix of thisAffineTransform
to a pure shearing matrix.- Parameters:
shx
- the x shearing factorshy
- the y shearing factor- Returns:
this
for convenience
-
setToTranslation
public AffineTransform setToTranslation(double tx, double ty)
Sets the transformation matrix of thisAffineTransform
to a pure translation matrix that translatesPoint
s by the given x and y values.- Parameters:
tx
- the x translation valuety
- the y translation value- Returns:
this
for convenience
-
setTransform
public AffineTransform setTransform(AffineTransform Tx)
Sets the transformation matrix of thisAffineTransform
to the transformation matrix of the givenAffineTransform
.- Parameters:
Tx
- theAffineTransform
specifying the new transformation matrix of thisAffineTransform
- Returns:
this
for convenience
-
setTransform
public AffineTransform setTransform(double m00, double m10, double m01, double m11, double m02, double m12)
Sets the respective values of the transformation matrix of thisAffineTransform
to the supplied ones. Note that rotation is a combination of shearing and scaling.- Parameters:
m00
- the value of the transformation matrix in row 0 and column 0 (x coordinate scaling)m10
- the value of the transformation matrix in row 1 and column 0 (y coordinate shearing)m01
- the value of the transformation matrix in row 0 and column 1 (x coordinate shearing)m11
- the value of the transformation matrix in row 1 and column 1 (y coordinate scaling)m02
- the value of the transformation matrix in row 0 and column 2 (x coordinate translation)m12
- the value of the transformation matrix in row 1 and column 2 (y coordinate translation)- Returns:
this
for convenience
-
shear
public AffineTransform shear(double shx, double shy)
Adds an x and y shearing to the transformation matrix of thisAffineTransform
.- Parameters:
shx
- the x shearing factor added to the transformation matrix of thisAffineTransform
shy
- the y shearing factor added to the transformation matrix of thisAffineTransform
- Returns:
this
for convenience
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
translate
public AffineTransform translate(double tx, double ty)
Sets the translation values of the x and y coordinates of the transformation matrix of thisAffineTransform
.- Parameters:
tx
- the x coordinate translationty
- the y coordinate translation- Returns:
this
for convenience
-
-