Package org.eclipse.gef.geometry.planar
Class AffineTransform
java.lang.Object
org.eclipse.gef.geometry.planar.AffineTransform
- All Implemented Interfaces:
Cloneable
The AffineTransform
class provides methods to create and modify
2-dimensional affine transformations.
It delegates to the AffineTransform
functionality.
-
Constructor Summary
ConstructorDescriptionCreates 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
Modifier and TypeMethodDescriptionclone()
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
.deltaTransform
(Point pt) Transforms the givenPoint
with thisAffineTransform
without applying the translation components of the transformation matrix of thisAffineTransform
.boolean
getCopy()
Returns a copy of thisAffineTransform
.double
Computes the determinant of the transformation matrix of thisAffineTransform
.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[]
Returns the 6 specifiable elements of the transformation matrix of thisAffineTransform
.Returns the rotation component of thisAffineTransform
.double
Returns the x coordinate scaling of thisAffineTransform
's transformation matrix.double
Returns the y coordinate scaling of thisAffineTransform
's transformation matrix.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
Returns the x coordinate translation of thisAffineTransform
's transformation matrix.double
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
.Inverse transforms the givenPoint
with thisAffineTransform
.invert()
Inverts thisAffineTransform
.boolean
Checks if the transformation matrix of thisAffineTransform
equals the identity matrix.Concatenates thisAffineTransform
and the givenAffineTransform
in reverse order, multiplying the transformation matrix of thisAffineTransform
from the right with the transformation matrix of the otherAffineTransform
.quadrantRotate
(int numquadrants) Adds a rotation by an integer multiple of 90deg to the transformation matrix of thisAffineTransform
.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
(double theta) Adds a rotation with the given angle (in radians) to the transformation matrix of thisAffineTransform
.rotate
(double vecx, double vecy) Adds a rotation to the transformation matrix of thisAffineTransform
.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
(double vecx, double vecy, double anchorx, double anchory) Adds a rotation around aPoint
to the transformation matrix of thisAffineTransform
.scale
(double sx, double sy) Adds an x and y scaling to the transformation matrix of thisAffineTransform
.Sets the transformation matrix of thisAffineTransform
to the identity matrix.setToQuadrantRotation
(int numquadrants) Sets the transformation matrix of thisAffineTransform
to a pure rotation matrix where the rotation angle is an integer multiple of 90deg.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
(double theta) Sets the transformation matrix of thisAffineTransform
to a pure rotation matrix by the given angle specified in radians.setToRotation
(double vecx, double vecy) Sets the transformation matrix of thisAffineTransform
to a pure rotation matrix.setToRotation
(double theta, double anchorx, double anchory) Sets the transformation matrix of thisAffineTransform
to a pure rotation and translation matrix.setToRotation
(double vecx, double vecy, double anchorx, double anchory) Sets the transformation matrix of thisAffineTransform
to a pure rotation and translation matrix.setToScale
(double sx, double sy) Sets the transformation matrix of thisAffineTransform
to a pure scaling matrix.setToShear
(double shx, double shy) Sets the transformation matrix of thisAffineTransform
to a pure shearing matrix.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.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.Sets the transformation matrix of thisAffineTransform
to the transformation matrix of the givenAffineTransform
.shear
(double shx, double shy) Adds an x and y shearing to the transformation matrix of thisAffineTransform
.toString()
translate
(double tx, double ty) Sets the translation values of the x and y coordinates of the transformation matrix of thisAffineTransform
.
-
Constructor Details
-
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:
-
-
Method Details
-
clone
-
concatenate
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
Transforms the givenPoint
with thisAffineTransform
without applying the translation components of the transformation matrix of thisAffineTransform
. -
equals
-
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
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
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
Transforms the givenPoint
with thisAffineTransform
by multiplying the transformation matrix of thisAffineTransform
with the givenPoint
. -
getTransformed
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() -
inverseTransform
public void inverseTransform(double[] srcPts, int srcOff, double[] dstPts, int dstOff, int numPts) throws 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:
NoninvertibleTransformException
- when thisAffineTransform
is not invertible.
-
inverseTransform
Inverse transforms the givenPoint
with thisAffineTransform
.- Parameters:
pt
- thePoint
to inverse transform- Returns:
- a new, inverse transformed
Point
- Throws:
NoninvertibleTransformException
- when thisAffineTransform
is not invertible.
-
invert
Inverts thisAffineTransform
.- Returns:
this
for convenience- Throws:
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
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
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
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
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
Adds a rotation to the transformation matrix of thisAffineTransform
. The given coordinates specify aVector
whoseAngle
to the x-axis is the applied rotationAngle
. -
rotate
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
-
scale
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
Sets the transformation matrix of thisAffineTransform
to the identity matrix.- Returns:
this
for convenience
-
setToQuadrantRotation
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
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
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
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
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
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
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
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
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
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
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
-
translate
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
-