Package com.itextpdf.kernel.geom
Class AffineTransform
- java.lang.Object
-
- com.itextpdf.kernel.geom.AffineTransform
-
- All Implemented Interfaces:
java.lang.Cloneable
public class AffineTransform extends java.lang.Object implements java.lang.CloneableTheAffineTransformclass represents an affine transformation, which is a combination of linear transformations such as translation, scaling, rotation, and shearing which allows preservation of the straightness of lines.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) doublem00The values of transformation matrix(package private) doublem01(package private) doublem02(package private) doublem10(package private) doublem11(package private) doublem12(package private) inttypeThe transformationtypestatic intTYPE_FLIPThe type of affine transformation.static intTYPE_GENERAL_ROTATIONThe type of affine transformation.static intTYPE_GENERAL_SCALEThe type of affine transformation.static intTYPE_GENERAL_TRANSFORMThe type of affine transformation.static intTYPE_IDENTITYThe type of affine transformation.static intTYPE_MASK_ROTATIONThe type of affine transformation.static intTYPE_MASK_SCALEThe type of affine transformation.static intTYPE_QUADRANT_ROTATIONThe type of affine transformation.static intTYPE_TRANSLATIONThe type of affine transformation.static intTYPE_UNIFORM_SCALEThe type of affine transformation.(package private) static intTYPE_UNKNOWNTheTYPE_UNKNOWNis an initial type value.(package private) static doubleZEROThe min value equivalent to zero.
-
Constructor Summary
Constructors Constructor Description AffineTransform()Create an emptyAffineTransforminstance.AffineTransform(double[] matrix)Create anAffineTransforminstance with the values provided.AffineTransform(double m00, double m10, double m01, double m11, double m02, double m12)Create anAffineTransforminstance with the values provided.AffineTransform(float[] matrix)Create anAffineTransforminstance with the values provided.AffineTransform(AffineTransform t)Will create a newAffineTransforminstance with the values provided from the originalAffineTransforminstance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description AffineTransformclone()Creates a "deep copy" of this AffineTransform, meaning the object returned by this method will be independent of the object being cloned.voidconcatenate(AffineTransform t)Multiply matrix of two AffineTransform objectsAffineTransformcreateInverse()Creates a newAffineTransformobject that is invert of thisAffineTransformobject.voiddeltaTransform(double[] src, int srcOff, double[] dst, int dstOff, int length)Performs the delta transformation on the source array of points and stores the result in the destination array of points.PointdeltaTransform(Point src, Point dst)Performs the transformation on the source point and stores the result in the destination point.booleanequals(java.lang.Object o)Compares this AffineTransform with the specified Object.doublegetDeterminant()Gets the determinant of the matrix representation of thisAffineTransform.voidgetMatrix(double[] matrix)Fills the matrix parameter with the values of thisAffineTransforminstance.voidgetMatrix(float[] matrix)Fills the matrix parameter with the values of thisAffineTransforminstance.static AffineTransformgetRotateInstance(double angle)Get an affine transformation representing a counter-clockwise rotation over the passed anglestatic AffineTransformgetRotateInstance(double angle, double x, double y)Get an affine transformation representing a counter-clockwise rotation over the passed angle, using the passed point as the center of rotationstatic AffineTransformgetScaleInstance(double scx, double scY)Get a newAffineTransforminstance representing a scale over the passed valuesdoublegetScaleX()Gets the scale factor of the x-axis.doublegetScaleY()Gets the scale factor of the y-axis.static AffineTransformgetShearInstance(double shx, double shy)Get a newAffineTransforminstance representing a shear over the passed valuesdoublegetShearX()Gets the shear factor of the x-axis.doublegetShearY()Gets the shear factor of the y-axis.static AffineTransformgetTranslateInstance(double mx, double my)Get a newAffineTransforminstance representing a translation over the passed valuesdoublegetTranslateX()Gets translation factor of the x-axis.doublegetTranslateY()Gets translation factor of the y-axis.intgetType()Method returns type of affine transformation.inthashCode()Returns a hash code value for the object.voidinverseTransform(double[] src, int srcOff, double[] dst, int dstOff, int length)Performs the inverse transformation on the source array of points and stores the result in the destination array of points.voidinverseTransform(float[] src, int srcOff, float[] dst, int dstOff, int length)Performs the inverse transformation on the source array of points and stores the result in the destination array of points.PointinverseTransform(Point src, Point dst)Performs the inverse transformation on the source point and stores the result in the destination point.booleanisIdentity()Gets whether thisAffineTransformis an identity transformation.(package private) AffineTransformmultiply(AffineTransform t1, AffineTransform t2)Multiply matrix of two AffineTransform objectsvoidpreConcatenate(AffineTransform t)Multiply matrix of two AffineTransform objectsvoidrotate(double angle)Add a counter-clockwise rotation to this transformationvoidrotate(double angle, double px, double py)Add a counter-clockwise rotation to this transformation, using the passed point as the center of rotationvoidscale(double scx, double scy)voidsetToIdentity()Sets thisAffineTransformto the identity transformation.voidsetToRotation(double angle)Set this affine transformation to represent a rotation over the passed anglevoidsetToRotation(double angle, double px, double py)Set this affine transformation to represent a rotation over the passed angle, using the passed point as the center of rotationvoidsetToScale(double scx, double scy)Sets thisAffineTransformto represent a scale transformation.voidsetToShear(double shx, double shy)Sets thisAffineTransformto represent a shear transformation.voidsetToTranslation(double mx, double my)Sets thisAffineTransformto represent a translation transformation.voidsetTransform(double m00, double m10, double m01, double m11, double m02, double m12)Sets the values of thisAffineTransforminstance to the values provided.voidsetTransform(float m00, float m10, float m01, float m11, float m02, float m12)Sets the values of thisAffineTransforminstance to the values provided.voidsetTransform(AffineTransform t)Sets the values of thisAffineTransforminstance to the values provided.voidshear(double shx, double shy)voidtransform(double[] src, int srcOff, double[] dst, int dstOff, int length)Transform the array of points according to the values of thisAffineTransformobject.voidtransform(double[] src, int srcOff, float[] dst, int dstOff, int length)Transform the array of points according to the values of thisAffineTransformobject.voidtransform(float[] src, int srcOff, double[] dst, int dstOff, int length)Transform the array of points according to the values of thisAffineTransformobject.voidtransform(float[] src, int srcOff, float[] dst, int dstOff, int length)Transform the array of points according to the values of thisAffineTransformobject.voidtransform(Point[] src, int srcOff, Point[] dst, int dstOff, int length)Transform the array of points according to the values of thisAffineTransformobject.Pointtransform(Point src, Point dst)Transform the point according to the values of thisAffineTransformobject.voidtranslate(double mx, double my)
-
-
-
Field Detail
-
TYPE_IDENTITY
public static final int TYPE_IDENTITY
The type of affine transformation. SeegetType().- See Also:
- Constant Field Values
-
TYPE_TRANSLATION
public static final int TYPE_TRANSLATION
The type of affine transformation. SeegetType().- See Also:
- Constant Field Values
-
TYPE_UNIFORM_SCALE
public static final int TYPE_UNIFORM_SCALE
The type of affine transformation. SeegetType().- See Also:
- Constant Field Values
-
TYPE_GENERAL_SCALE
public static final int TYPE_GENERAL_SCALE
The type of affine transformation. SeegetType().- See Also:
- Constant Field Values
-
TYPE_QUADRANT_ROTATION
public static final int TYPE_QUADRANT_ROTATION
The type of affine transformation. SeegetType().- See Also:
- Constant Field Values
-
TYPE_GENERAL_ROTATION
public static final int TYPE_GENERAL_ROTATION
The type of affine transformation. SeegetType().- See Also:
- Constant Field Values
-
TYPE_GENERAL_TRANSFORM
public static final int TYPE_GENERAL_TRANSFORM
The type of affine transformation. SeegetType().- See Also:
- Constant Field Values
-
TYPE_FLIP
public static final int TYPE_FLIP
The type of affine transformation. SeegetType().- See Also:
- Constant Field Values
-
TYPE_MASK_SCALE
public static final int TYPE_MASK_SCALE
The type of affine transformation. SeegetType().- See Also:
- Constant Field Values
-
TYPE_MASK_ROTATION
public static final int TYPE_MASK_ROTATION
The type of affine transformation. SeegetType().- See Also:
- Constant Field Values
-
TYPE_UNKNOWN
static final int TYPE_UNKNOWN
TheTYPE_UNKNOWNis an initial type value.- See Also:
- Constant Field Values
-
ZERO
static final double ZERO
The min value equivalent to zero. If absolute value less then ZERO it considered as zero.- See Also:
- Constant Field Values
-
m00
double m00
The values of transformation matrix
-
m10
double m10
-
m01
double m01
-
m11
double m11
-
m02
double m02
-
m12
double m12
-
type
int type
The transformationtype
-
-
Constructor Detail
-
AffineTransform
public AffineTransform()
Create an emptyAffineTransforminstance. The default type is for the transformation isTYPE_IDENTITY
-
AffineTransform
public AffineTransform(AffineTransform t)
Will create a newAffineTransforminstance with the values provided from the originalAffineTransforminstance.- Parameters:
t- The AffineTransform class to be used.
-
AffineTransform
public AffineTransform(double m00, double m10, double m01, double m11, double m02, double m12)Create anAffineTransforminstance with the values provided. The default type is for the transformation isTYPE_UNKNOWN- Parameters:
m00- The value of the first row and first column of the matrix.m10- The value of the second row and first column of the matrix.m01- The value of the first row and second column of the matrix.m11- The value of the second row and second column of the matrix.m02- The value of the first row and third column of the matrix.m12- The value of the second row and third column of the matrix.
-
AffineTransform
public AffineTransform(float[] matrix)
Create anAffineTransforminstance with the values provided. The default type is for the transformation isTYPE_UNKNOWN- Parameters:
matrix- The array of values to be used for the transformation matrix.
-
AffineTransform
public AffineTransform(double[] matrix)
Create anAffineTransforminstance with the values provided. The default type is for the transformation isTYPE_UNKNOWN- Parameters:
matrix- The array of values to be used for the transformation matrix.
-
-
Method Detail
-
getType
public int getType()
Method returns type of affine transformation.Transform matrix is m00 m01 m02 m10 m11 m12
According analytic geometry new basis vectors are (m00, m01) and (m10, m11), translation vector is (m02, m12). Original basis vectors are (1, 0) and (0, 1). Type transformations classification:
TYPE_IDENTITY- new basis equals original one and zero translationTYPE_TRANSLATION- translation vector isn't zeroTYPE_UNIFORM_SCALE- vectors length of new basis equalsTYPE_GENERAL_SCALE- vectors length of new basis doesn't equalTYPE_FLIP- new basis vector orientation differ from original oneTYPE_QUADRANT_ROTATION- new basis is rotated by 90, 180, 270, or 360 degreesTYPE_GENERAL_ROTATION- new basis is rotated by arbitrary angleTYPE_GENERAL_TRANSFORM- transformation can't be inversed
- Returns:
- the type of this AffineTransform
-
getScaleX
public double getScaleX()
Gets the scale factor of the x-axis.- Returns:
- the scale factor of the x-axis.
-
getScaleY
public double getScaleY()
Gets the scale factor of the y-axis.- Returns:
- the scale factor of the y-axis.
-
getShearX
public double getShearX()
Gets the shear factor of the x-axis.- Returns:
- the shear factor of the x-axis.
-
getShearY
public double getShearY()
Gets the shear factor of the y-axis.- Returns:
- the shear factor of the y-axis.
-
getTranslateX
public double getTranslateX()
Gets translation factor of the x-axis.- Returns:
- the translation factor of the x-axis.
-
getTranslateY
public double getTranslateY()
Gets translation factor of the y-axis.- Returns:
- the translation factor of the y-axis.
-
isIdentity
public boolean isIdentity()
Gets whether thisAffineTransformis an identity transformation.- Returns:
trueif thisAffineTransformis an identity transformation,falseotherwise.
-
getMatrix
public void getMatrix(float[] matrix)
Fills the matrix parameter with the values of thisAffineTransforminstance.- Parameters:
matrix- the array to be filled with the values of thisAffineTransforminstance.
-
getMatrix
public void getMatrix(double[] matrix)
Fills the matrix parameter with the values of thisAffineTransforminstance.- Parameters:
matrix- the array to be filled with the values of thisAffineTransforminstance.
-
getDeterminant
public double getDeterminant()
Gets the determinant of the matrix representation of thisAffineTransform.- Returns:
- the determinant of the matrix representation of this
AffineTransform.
-
setTransform
public void setTransform(float m00, float m10, float m01, float m11, float m02, float m12)Sets the values of thisAffineTransforminstance to the values provided. The type of the transformation is set toTYPE_UNKNOWN.- Parameters:
m00- The value of the first row and first column of the matrix.m10- The value of the second row and first column of the matrix.m01- The value of the first row and second column of the matrix.m11- The value of the second row and second column of the matrix.m02- The value of the first row and third column of the matrix.m12- The value of the second row and third column of the matrix.
-
setTransform
public void setTransform(double m00, double m10, double m01, double m11, double m02, double m12)Sets the values of thisAffineTransforminstance to the values provided. The type of the transformation is set toTYPE_UNKNOWN.- Parameters:
m00- The value of the first row and first column of the matrix.m10- The value of the second row and first column of the matrix.m01- The value of the first row and second column of the matrix.m11- The value of the second row and second column of the matrix.m02- The value of the first row and third column of the matrix.m12- The value of the second row and third column of the matrix.
-
setTransform
public void setTransform(AffineTransform t)
Sets the values of thisAffineTransforminstance to the values provided.- Parameters:
t- TheAffineTransforminstance to be used.
-
setToIdentity
public void setToIdentity()
Sets thisAffineTransformto the identity transformation.
-
setToTranslation
public void setToTranslation(double mx, double my)Sets thisAffineTransformto represent a translation transformation.- Parameters:
mx- The value of the translation on the x-axis.my- The value of the translation on the y-axis.
-
setToScale
public void setToScale(double scx, double scy)Sets thisAffineTransformto represent a scale transformation.- Parameters:
scx- The value of the scale factor on the x-axis.scy- The value of the scale factor on the y-axis.
-
setToShear
public void setToShear(double shx, double shy)Sets thisAffineTransformto represent a shear transformation.- Parameters:
shx- The value of the shear factor on the x-axis.shy- The value of the shear factor on the y-axis.
-
setToRotation
public void setToRotation(double angle)
Set this affine transformation to represent a rotation over the passed angle- Parameters:
angle- angle to rotate over in radians
-
setToRotation
public void setToRotation(double angle, double px, double py)Set this affine transformation to represent a rotation over the passed angle, using the passed point as the center of rotation- Parameters:
angle- angle to rotate over in radianspx- x-coordinate of center of rotationpy- y-coordinate of center of rotation
-
getTranslateInstance
public static AffineTransform getTranslateInstance(double mx, double my)
Get a newAffineTransforminstance representing a translation over the passed values- Parameters:
mx- x-coordinate of translationmy- y-coordinate of translation- Returns:
AffineTransformrepresenting the translation
-
getScaleInstance
public static AffineTransform getScaleInstance(double scx, double scY)
Get a newAffineTransforminstance representing a scale over the passed values- Parameters:
scx- scale factor on the x-axisscY- scale factor on the y-axis- Returns:
AffineTransformrepresenting the scale
-
getShearInstance
public static AffineTransform getShearInstance(double shx, double shy)
Get a newAffineTransforminstance representing a shear over the passed values- Parameters:
shx- shear factor on the x-axisshy- shear factor on the y-axis- Returns:
AffineTransformrepresenting the shear
-
getRotateInstance
public static AffineTransform getRotateInstance(double angle)
Get an affine transformation representing a counter-clockwise rotation over the passed angle- Parameters:
angle- angle in radians to rotate over- Returns:
AffineTransformrepresenting the rotation
-
getRotateInstance
public static AffineTransform getRotateInstance(double angle, double x, double y)
Get an affine transformation representing a counter-clockwise rotation over the passed angle, using the passed point as the center of rotation- Parameters:
angle- angle in radians to rotate overx- x-coordinate of center of rotationy- y-coordinate of center of rotation- Returns:
AffineTransformrepresenting the rotation
-
translate
public void translate(double mx, double my)
-
scale
public void scale(double scx, double scy)
-
shear
public void shear(double shx, double shy)
-
rotate
public void rotate(double angle)
Add a counter-clockwise rotation to this transformation- Parameters:
angle- angle in radians to rotate over
-
rotate
public void rotate(double angle, double px, double py)Add a counter-clockwise rotation to this transformation, using the passed point as the center of rotation- Parameters:
angle- angle in radians to rotate overpx- x-coordinate of center of rotationpy- y-coordinate of center of rotation
-
multiply
AffineTransform multiply(AffineTransform t1, AffineTransform t2)
Multiply matrix of two AffineTransform objects- Parameters:
t1- - the AffineTransform object is a multiplicand.t2- - the AffineTransform object is a multiplier.- Returns:
- an AffineTransform object that is a result of t1 multiplied by matrix t2.
-
concatenate
public void concatenate(AffineTransform t)
Multiply matrix of two AffineTransform objects- Parameters:
t- - the AffineTransform object is a multiplier.
-
preConcatenate
public void preConcatenate(AffineTransform t)
Multiply matrix of two AffineTransform objects- Parameters:
t- - the AffineTransform object is a multiplicand.
-
createInverse
public AffineTransform createInverse() throws NoninvertibleTransformException
Creates a newAffineTransformobject that is invert of thisAffineTransformobject.- Returns:
- a new
AffineTransformobject that is invert of thisAffineTransformobject. - Throws:
NoninvertibleTransformException- if thisAffineTransformobject cannot be inverted.
-
transform
public Point transform(Point src, Point dst)
Transform the point according to the values of thisAffineTransformobject.- Parameters:
src- The point to be transformed.dst- The point that will hold the result of the transformation.- Returns:
- The point that holds the result of the transformation.
-
transform
public void transform(Point[] src, int srcOff, Point[] dst, int dstOff, int length)
Transform the array of points according to the values of thisAffineTransformobject.- Parameters:
src- The array of points to be transformed.srcOff- The offset of the first point in the array.dst- The array of points that will hold the result of the transformation.dstOff- The offset of the first point in the destination array.length- The number of points to be transformed.
-
transform
public void transform(double[] src, int srcOff, double[] dst, int dstOff, int length)Transform the array of points according to the values of thisAffineTransformobject.- Parameters:
src- The array of points to be transformed.srcOff- The offset of the first point in the array.dst- The array of points that will hold the result of the transformation.dstOff- The offset of the first point in the destination array.length- The number of points to be transformed.
-
transform
public void transform(float[] src, int srcOff, float[] dst, int dstOff, int length)Transform the array of points according to the values of thisAffineTransformobject.- Parameters:
src- The array of points to be transformed.srcOff- The offset of the first point in the array.dst- The array of points that will hold the result of the transformation.dstOff- The offset of the first point in the destination array.length- The number of points to be transformed.
-
transform
public void transform(float[] src, int srcOff, double[] dst, int dstOff, int length)Transform the array of points according to the values of thisAffineTransformobject.- Parameters:
src- The array of points to be transformed.srcOff- The offset of the first point in the array.dst- The array of points that will hold the result of the transformation.dstOff- The offset of the first point in the destination array.length- The number of points to be transformed.
-
transform
public void transform(double[] src, int srcOff, float[] dst, int dstOff, int length)Transform the array of points according to the values of thisAffineTransformobject.- Parameters:
src- The array of points to be transformed.srcOff- The offset of the first point in the array.dst- The array of points that will hold the result of the transformation.dstOff- The offset of the first point in the destination array.length- The number of points to be transformed.
-
deltaTransform
public Point deltaTransform(Point src, Point dst)
Performs the transformation on the source point and stores the result in the destination point.- Parameters:
src- The source point to be transformed.dst- The destination point that will hold the result of the transformation.- Returns:
- The modified destination point.
-
deltaTransform
public void deltaTransform(double[] src, int srcOff, double[] dst, int dstOff, int length)Performs the delta transformation on the source array of points and stores the result in the destination array of points.- Parameters:
src- The source array of data to be transformed.srcOff- The offset of the first point in the source array.dst- The destination array of data that will hold the result of the transformation.dstOff- The offset of the first point in the destination array.length- The number of points to be transformed.
-
inverseTransform
public Point inverseTransform(Point src, Point dst) throws NoninvertibleTransformException
Performs the inverse transformation on the source point and stores the result in the destination point.- Parameters:
src- The source point to be transformed.dst- The destination point that will hold the result of the transformation.- Returns:
- The modified destination point.
- Throws:
NoninvertibleTransformException- if the matrix cannot be inverted.
-
inverseTransform
public void inverseTransform(double[] src, int srcOff, double[] dst, int dstOff, int length) throws NoninvertibleTransformExceptionPerforms the inverse transformation on the source array of points and stores the result in the destination array of points.- Parameters:
src- The source array of data to be transformed.srcOff- The offset of the first point in the source array.dst- The destination array of data that will hold the result of the transformation.dstOff- The offset of the first point in the destination array.length- The number of points to be transformed.- Throws:
NoninvertibleTransformException- if the matrix cannot be inverted.
-
inverseTransform
public void inverseTransform(float[] src, int srcOff, float[] dst, int dstOff, int length) throws NoninvertibleTransformExceptionPerforms the inverse transformation on the source array of points and stores the result in the destination array of points.- Parameters:
src- The source array of data to be transformed.srcOff- The offset of the first point in the source array.dst- The destination array of data that will hold the result of the transformation.dstOff- The offset of the first point in the destination array.length- The number of points to be transformed.- Throws:
NoninvertibleTransformException- if the matrix cannot be inverted.
-
clone
public AffineTransform clone() throws java.lang.CloneNotSupportedException
Creates a "deep copy" of this AffineTransform, meaning the object returned by this method will be independent of the object being cloned.- Overrides:
clonein classjava.lang.Object- Returns:
- the copied AffineTransform.
- Throws:
java.lang.CloneNotSupportedException
-
equals
public boolean equals(java.lang.Object o)
Compares this AffineTransform with the specified Object. If the object is the same as this AffineTransform, this method returns true. Otherwise, this method checks if the Object is an instance of AffineTransform and if the values of the two AffineTransforms are equal.- Overrides:
equalsin classjava.lang.Object- Parameters:
o- The object to compare this AffineTransform with.- Returns:
trueif the object is the same as this AffineTransform,falseotherwise.
-
hashCode
public int hashCode()
Returns a hash code value for the object.- Overrides:
hashCodein classjava.lang.Object- Returns:
- a hash code value for this object.
-
-