Package com.itextpdf.kernel.geom
Class AffineTransform
java.lang.Object
com.itextpdf.kernel.geom.AffineTransform
- All Implemented Interfaces:
-
Cloneable
The
AffineTransform class 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
FieldsModifier and TypeFieldDescriptionstatic final intThe type of affine transformation.static final intThe type of affine transformation.static final intThe type of affine transformation.static final intThe type of affine transformation.static final intThe type of affine transformation.static final intThe type of affine transformation.static final intThe type of affine transformation.static final intThe type of affine transformation.static final intThe type of affine transformation.static final intThe type of affine transformation. -
Constructor Summary
ConstructorsConstructorDescriptionCreate 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.Will create a newAffineTransforminstance with the values provided from the originalAffineTransforminstance. -
Method Summary
Modifier and TypeMethodDescriptionclone()Creates a "deep copy" of this AffineTransform, meaning the object returned by this method will be independent of the object being cloned.voidMultiply matrix of two AffineTransform objectsCreates 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.deltaTransform(Point src, Point dst) Performs the transformation on the source point and stores the result in the destination point.booleanCompares this AffineTransform with the specified Object.doubleGets 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 valuesdoubleGets the scale factor of the x-axis.doubleGets the scale factor of the y-axis.static AffineTransformgetShearInstance(double shx, double shy) Get a newAffineTransforminstance representing a shear over the passed valuesdoubleGets the shear factor of the x-axis.doubleGets the shear factor of the y-axis.static AffineTransformgetTranslateInstance(double mx, double my) Get a newAffineTransforminstance representing a translation over the passed valuesdoubleGets translation factor of the x-axis.doubleGets 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.inverseTransform(Point src, Point dst) Performs the inverse transformation on the source point and stores the result in the destination point.booleanGets whether thisAffineTransformis an identity transformation.voidMultiply 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) voidSets 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.voidSets 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 the array of points according to the values of thisAffineTransformobject.Transform the point according to the values of thisAffineTransformobject.voidtranslate(double mx, double my)
-
Field Details
-
TYPE_IDENTITY
public static final int TYPE_IDENTITYThe type of affine transformation. SeegetType().- See Also:
-
TYPE_TRANSLATION
public static final int TYPE_TRANSLATIONThe type of affine transformation. SeegetType().- See Also:
-
TYPE_UNIFORM_SCALE
public static final int TYPE_UNIFORM_SCALEThe type of affine transformation. SeegetType().- See Also:
-
TYPE_GENERAL_SCALE
public static final int TYPE_GENERAL_SCALEThe type of affine transformation. SeegetType().- See Also:
-
TYPE_QUADRANT_ROTATION
public static final int TYPE_QUADRANT_ROTATIONThe type of affine transformation. SeegetType().- See Also:
-
TYPE_GENERAL_ROTATION
public static final int TYPE_GENERAL_ROTATIONThe type of affine transformation. SeegetType().- See Also:
-
TYPE_GENERAL_TRANSFORM
public static final int TYPE_GENERAL_TRANSFORMThe type of affine transformation. SeegetType().- See Also:
-
TYPE_FLIP
public static final int TYPE_FLIPThe type of affine transformation. SeegetType().- See Also:
-
TYPE_MASK_SCALE
public static final int TYPE_MASK_SCALEThe type of affine transformation. SeegetType().- See Also:
-
TYPE_MASK_ROTATION
public static final int TYPE_MASK_ROTATIONThe type of affine transformation. SeegetType().- See Also:
-
-
Constructor Details
-
AffineTransform
public AffineTransform()Create an emptyAffineTransforminstance. The default type is for the transformation isTYPE_IDENTITY -
AffineTransform
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 Details
-
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
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 radians -
px- x-coordinate of center of rotation -
py- y-coordinate of center of rotation
-
getTranslateInstance
Get a newAffineTransforminstance representing a translation over the passed values- Parameters:
-
mx- x-coordinate of translation -
my- y-coordinate of translation - Returns:
-
AffineTransformrepresenting the translation
-
getScaleInstance
Get a newAffineTransforminstance representing a scale over the passed values- Parameters:
-
scx- scale factor on the x-axis -
scY- scale factor on the y-axis - Returns:
-
AffineTransformrepresenting the scale
-
getShearInstance
Get a newAffineTransforminstance representing a shear over the passed values- Parameters:
-
shx- shear factor on the x-axis -
shy- shear factor on the y-axis - Returns:
-
AffineTransformrepresenting the shear
-
getRotateInstance
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
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 over -
x- x-coordinate of center of rotation -
y- 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 over -
px- x-coordinate of center of rotation -
py- y-coordinate of center of rotation
-
concatenate
Multiply matrix of two AffineTransform objects- Parameters:
-
t- - the AffineTransform object is a multiplier.
-
preConcatenate
Multiply matrix of two AffineTransform objects- Parameters:
-
t- - the AffineTransform object is a multiplicand.
-
createInverse
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
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
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
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
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 NoninvertibleTransformException Performs 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 NoninvertibleTransformException Performs 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
Creates a "deep copy" of this AffineTransform, meaning the object returned by this method will be independent of the object being cloned.- Overrides:
-
clonein classObject - Returns:
- the copied AffineTransform.
- Throws:
-
CloneNotSupportedException
-
equals
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. -
hashCode
public int hashCode()Returns a hash code value for the object.
-