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.Cloneable
TheAffineTransform
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
Fields Modifier and Type Field Description (package private) double
m00
The values of transformation matrix(package private) double
m01
(package private) double
m02
(package private) double
m10
(package private) double
m11
(package private) double
m12
(package private) int
type
The transformationtype
static int
TYPE_FLIP
The type of affine transformation.static int
TYPE_GENERAL_ROTATION
The type of affine transformation.static int
TYPE_GENERAL_SCALE
The type of affine transformation.static int
TYPE_GENERAL_TRANSFORM
The type of affine transformation.static int
TYPE_IDENTITY
The type of affine transformation.static int
TYPE_MASK_ROTATION
The type of affine transformation.static int
TYPE_MASK_SCALE
The type of affine transformation.static int
TYPE_QUADRANT_ROTATION
The type of affine transformation.static int
TYPE_TRANSLATION
The type of affine transformation.static int
TYPE_UNIFORM_SCALE
The type of affine transformation.(package private) static int
TYPE_UNKNOWN
TheTYPE_UNKNOWN
is an initial type value.(package private) static double
ZERO
The min value equivalent to zero.
-
Constructor Summary
Constructors Constructor Description AffineTransform()
Create 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.AffineTransform(AffineTransform t)
Will create a newAffineTransform
instance with the values provided from the originalAffineTransform
instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description AffineTransform
clone()
Creates a "deep copy" of this AffineTransform, meaning the object returned by this method will be independent of the object being cloned.void
concatenate(AffineTransform t)
Multiply matrix of two AffineTransform objectsAffineTransform
createInverse()
Creates 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.Point
deltaTransform(Point src, Point dst)
Performs the transformation on the source point and stores the result in the destination point.boolean
equals(java.lang.Object o)
Compares this AffineTransform with the specified Object.double
getDeterminant()
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
getScaleX()
Gets the scale factor of the x-axis.double
getScaleY()
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
getShearX()
Gets the shear factor of the x-axis.double
getShearY()
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
getTranslateX()
Gets translation factor of the x-axis.double
getTranslateY()
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.Point
inverseTransform(Point src, Point dst)
Performs the inverse transformation on the source point and stores the result in the destination point.boolean
isIdentity()
Gets whether thisAffineTransform
is an identity transformation.(package private) AffineTransform
multiply(AffineTransform t1, AffineTransform t2)
Multiply matrix of two AffineTransform objectsvoid
preConcatenate(AffineTransform t)
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
setToIdentity()
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
setTransform(AffineTransform t)
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(Point[] src, int srcOff, Point[] dst, int dstOff, int length)
Transform the array of points according to the values of thisAffineTransform
object.Point
transform(Point src, Point dst)
Transform the point according to the values of thisAffineTransform
object.void
translate(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_UNKNOWN
is 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 emptyAffineTransform
instance. The default type is for the transformation isTYPE_IDENTITY
-
AffineTransform
public AffineTransform(AffineTransform t)
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 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 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
public void setTransform(AffineTransform t)
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 radianspx
- x-coordinate of center of rotationpy
- y-coordinate of center of rotation
-
getTranslateInstance
public static AffineTransform getTranslateInstance(double mx, double my)
Get a newAffineTransform
instance representing a translation over the passed values- Parameters:
mx
- x-coordinate of translationmy
- y-coordinate of translation- Returns:
AffineTransform
representing the translation
-
getScaleInstance
public static AffineTransform getScaleInstance(double scx, double scY)
Get a newAffineTransform
instance representing a scale over the passed values- Parameters:
scx
- scale factor on the x-axisscY
- scale factor on the y-axis- Returns:
AffineTransform
representing the scale
-
getShearInstance
public static AffineTransform getShearInstance(double shx, double shy)
Get a newAffineTransform
instance representing a shear over the passed values- Parameters:
shx
- shear factor on the x-axisshy
- shear factor on the y-axis- Returns:
AffineTransform
representing 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:
AffineTransform
representing 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:
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 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 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
public Point transform(Point src, Point dst)
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
public void transform(Point[] src, int srcOff, Point[] 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, 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
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 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
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:
clone
in 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:
equals
in classjava.lang.Object
- Parameters:
o
- The object to compare this AffineTransform with.- Returns:
true
if the object is the same as this AffineTransform,false
otherwise.
-
hashCode
public int hashCode()
Returns a hash code value for the object.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- a hash code value for this object.
-
-