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
Modifier and TypeFieldDescriptionstatic final int
The type of affine transformation.static final int
The type of affine transformation.static final int
The type of affine transformation.static final int
The type of affine transformation.static final int
The type of affine transformation.static final int
The type of affine transformation.static final int
The type of affine transformation.static final int
The type of affine transformation.static final int
The type of affine transformation.static final int
The type of affine transformation. -
Constructor Summary
ConstructorDescriptionCreate an emptyAffineTransform
instance.AffineTransform
(double[] matrix) Create anAffineTransform
instance with the values provided.AffineTransform
(double m00, double m10, double m01, double m11, double m02, double m12) Create anAffineTransform
instance with the values provided.AffineTransform
(float[] matrix) Create anAffineTransform
instance with the values provided.Will create a newAffineTransform
instance with the values provided from the originalAffineTransform
instance. -
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.void
Multiply matrix of two AffineTransform objectsCreates a newAffineTransform
object that is invert of thisAffineTransform
object.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.deltaTransform
(Point src, Point dst) Performs the transformation on the source point and stores the result in the destination point.boolean
Compares this AffineTransform with the specified Object.double
Gets the determinant of the matrix representation of thisAffineTransform
.void
getMatrix
(double[] matrix) Fills the matrix parameter with the values of thisAffineTransform
instance.void
getMatrix
(float[] matrix) Fills the matrix parameter with the values of thisAffineTransform
instance.static AffineTransform
getRotateInstance
(double angle) Get an affine transformation representing a counter-clockwise rotation over the passed anglestatic 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 rotationstatic AffineTransform
getScaleInstance
(double scx, double scY) Get a newAffineTransform
instance representing a scale over the passed valuesdouble
Gets the scale factor of the x-axis.double
Gets the scale factor of the y-axis.static AffineTransform
getShearInstance
(double shx, double shy) Get a newAffineTransform
instance representing a shear over the passed valuesdouble
Gets the shear factor of the x-axis.double
Gets the shear factor of the y-axis.static AffineTransform
getTranslateInstance
(double mx, double my) Get a newAffineTransform
instance representing a translation over the passed valuesdouble
Gets translation factor of the x-axis.double
Gets translation factor of the y-axis.int
getType()
Method returns type of affine transformation.int
hashCode()
Returns a hash code value for the object.void
inverseTransform
(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.void
inverseTransform
(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.boolean
Gets whether thisAffineTransform
is an identity transformation.void
Multiply matrix of two AffineTransform objectsvoid
rotate
(double angle) Add a counter-clockwise rotation to this transformationvoid
rotate
(double angle, double px, double py) Add a counter-clockwise rotation to this transformation, using the passed point as the center of rotationvoid
scale
(double scx, double scy) void
Sets thisAffineTransform
to the identity transformation.void
setToRotation
(double angle) Set this affine transformation to represent a rotation over the passed anglevoid
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 rotationvoid
setToScale
(double scx, double scy) Sets thisAffineTransform
to represent a scale transformation.void
setToShear
(double shx, double shy) Sets thisAffineTransform
to represent a shear transformation.void
setToTranslation
(double mx, double my) Sets thisAffineTransform
to represent a translation transformation.void
setTransform
(double m00, double m10, double m01, double m11, double m02, double m12) Sets the values of thisAffineTransform
instance to the values provided.void
setTransform
(float m00, float m10, float m01, float m11, float m02, float m12) Sets the values of thisAffineTransform
instance to the values provided.void
Sets the values of thisAffineTransform
instance to the values provided.void
shear
(double shx, double shy) void
transform
(double[] src, int srcOff, double[] dst, int dstOff, int length) Transform the array of points according to the values of thisAffineTransform
object.void
transform
(double[] src, int srcOff, float[] dst, int dstOff, int length) Transform the array of points according to the values of thisAffineTransform
object.void
transform
(float[] src, int srcOff, double[] dst, int dstOff, int length) Transform the array of points according to the values of thisAffineTransform
object.void
transform
(float[] src, int srcOff, float[] dst, int dstOff, int length) Transform the array of points according to the values of thisAffineTransform
object.void
Transform the array of points according to the values of thisAffineTransform
object.Transform the point according to the values of thisAffineTransform
object.void
translate
(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 emptyAffineTransform
instance. The default type is for the transformation isTYPE_IDENTITY
-
AffineTransform
Will create a newAffineTransform
instance with the values provided from the originalAffineTransform
instance.- Parameters:
-
t
- The AffineTransform class to be used.
-
AffineTransform
public AffineTransform(double m00, double m10, double m01, double m11, double m02, double m12) Create anAffineTransform
instance 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 anAffineTransform
instance 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 anAffineTransform
instance 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 thisAffineTransform
is an identity transformation.- Returns:
-
true
if thisAffineTransform
is an identity transformation,false
otherwise.
-
getMatrix
public void getMatrix(float[] matrix) Fills the matrix parameter with the values of thisAffineTransform
instance.- Parameters:
-
matrix
- the array to be filled with the values of thisAffineTransform
instance.
-
getMatrix
public void getMatrix(double[] matrix) Fills the matrix parameter with the values of thisAffineTransform
instance.- Parameters:
-
matrix
- the array to be filled with the values of thisAffineTransform
instance.
-
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 thisAffineTransform
instance 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 thisAffineTransform
instance 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 thisAffineTransform
instance to the values provided.- Parameters:
-
t
- TheAffineTransform
instance to be used.
-
setToIdentity
public void setToIdentity()Sets thisAffineTransform
to the identity transformation. -
setToTranslation
public void setToTranslation(double mx, double my) Sets thisAffineTransform
to 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 thisAffineTransform
to 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 thisAffineTransform
to 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 newAffineTransform
instance representing a translation over the passed values- Parameters:
-
mx
- x-coordinate of translation -
my
- y-coordinate of translation - Returns:
-
AffineTransform
representing the translation
-
getScaleInstance
Get a newAffineTransform
instance representing a scale over the passed values- Parameters:
-
scx
- scale factor on the x-axis -
scY
- scale factor on the y-axis - Returns:
-
AffineTransform
representing the scale
-
getShearInstance
Get a newAffineTransform
instance representing a shear over the passed values- Parameters:
-
shx
- shear factor on the x-axis -
shy
- shear factor on the y-axis - Returns:
-
AffineTransform
representing 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:
-
AffineTransform
representing 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:
-
AffineTransform
representing 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 newAffineTransform
object that is invert of thisAffineTransform
object.- Returns:
-
a new
AffineTransform
object that is invert of thisAffineTransform
object. - Throws:
-
NoninvertibleTransformException
- if thisAffineTransform
object cannot be inverted.
-
transform
Transform the point according to the values of thisAffineTransform
object.- 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 thisAffineTransform
object.- 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 thisAffineTransform
object.- 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 thisAffineTransform
object.- 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 thisAffineTransform
object.- 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 thisAffineTransform
object.- 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:
-
clone
in 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.
-