Package com.myscript.iink.graphics
Class Transform
java.lang.Object
com.myscript.iink.graphics.Transform
Represents a 2D affine transform, defined as a 3x3 matrix with an implicit
third raw of
[ 0 0 1 ]
:
[ x' ] [ xx yx tx ] [ x ] [ xx * x + yx * y + tx ] [ y' ] = [ xy yy ty ] * [ y ] = [ xy * x + yy * y + ty ] [ 1 ] [ 0 0 1 ] [ 1 ] [ 1 ]A transform is invalid if a value is infinite or not a number, or if the matrix is not invertible (when its determinant
(xx * yy - yx * xy)
is zero).-
Field Summary
FieldsModifier and TypeFieldDescriptiondouble
The X coordinate translation element M1,3 of the transform matrix.double
The Y coordinate translation element M2,3 of the transform matrix.double
The X coordinate scaling element M1,1 of the transform matrix.double
The Y coordinate shearing element M2,1 of the transform matrix.double
The X coordinate shearing element M1,2 of the transform matrix.double
The Y coordinate scaling element M2,2 of the transform matrix. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal @NotNull Point
apply
(float x, float y) Applies this transform to 2D point (x,y).final void
Applies this transform to 2D point (x,y).final void
Applies this transform to 2D points (x,y).final void
Applies this transform to 2D points (x,y).final void
Applies this transform to a rectangle.boolean
static @NotNull Transform
getTransform
(@NotNull Rectangle fromRect, @NotNull Rectangle toRect) Gets the transform to transform a rectangle into another.int
hashCode()
final void
invert()
Inverts this transform.final boolean
Floating point comparison with tolerance.final void
multiply
(double xx, double yx, double tx, double xy, double yy, double ty) Multiply this transform.final void
Multiplies this transform by the second transform.final void
rotate
(double a) Multiplies the transform with a rotation transformation.final void
rotate
(double cosA, double sinA) Multiplies the transform with a rotation transformation.final void
rotate
(double a, double x0, double y0) Multiplies the transform with a rotation transformation.final void
rotate
(double cosA, double sinA, double x0, double y0) Multiplies the transform with a rotation transformation.final void
scale
(double s) Multiplies this transform with a scaling transformation.final void
scale
(double sx, double sy) Multiplies this transform with a scaling transformation.final @NotNull String
toString()
final void
translate
(double tx, double ty) Multiplies the transform with a translation transformation.
-
Field Details
-
xx
public double xxThe X coordinate scaling element M1,1 of the transform matrix. -
yx
public double yxThe X coordinate shearing element M1,2 of the transform matrix. -
tx
public double txThe X coordinate translation element M1,3 of the transform matrix. -
xy
public double xyThe Y coordinate shearing element M2,1 of the transform matrix. -
yy
public double yyThe Y coordinate scaling element M2,2 of the transform matrix. -
ty
public double tyThe Y coordinate translation element M2,3 of the transform matrix.
-
-
Constructor Details
-
Transform
public Transform(double xx, double yx, double tx, double xy, double yy, double ty) Constructor.- Parameters:
xx
- The X coordinate scaling element M1,1 of the transform matrix.yx
- The X coordinate shearing element M1,2 of the transform matrix.tx
- The X coordinate translation element M1,3 of the transform matrix.xy
- The Y coordinate shearing element M2,1 of the transform matrix.yy
- The Y coordinate scaling element M2,2 of the transform matrix.ty
- The Y coordinate translation element M2,3 of the transform matrix.
-
Transform
public Transform()Default constructor. -
Transform
Copy constructor.- Parameters:
other
- copied object.
-
-
Method Details
-
isNear
Floating point comparison with tolerance.- Parameters:
other
- the compared object.- Returns:
true
if transforms are close to equal,false
otherwise/
-
invert
public final void invert()Inverts this transform.- Throws:
IllegalStateException
- when transform is not invertible
-
multiply
Multiplies this transform by the second transform.- Parameters:
other
- the right hand side operand.
-
multiply
public final void multiply(double xx, double yx, double tx, double xy, double yy, double ty) Multiply this transform.- Parameters:
xx
- The right hand transform side X coordinate scaling element M1,1.yx
- The right hand transform side X coordinate scaling element M1,2.tx
- The right hand transform side X coordinate scaling element M1,3.xy
- The right hand transform side Y coordinate scaling element M2,1.yy
- The right hand transform side Y coordinate scaling element M2,2.ty
- The right hand transform side Y coordinate scaling element M2,3.
-
translate
public final void translate(double tx, double ty) Multiplies the transform with a translation transformation. This is equivalent to callingmultiply(T)
, whereT
is aTransform
represented by the following matrix:[ 1 0 tx ] [ 0 1 ty ] [ 0 0 1 ]
- Parameters:
tx
- the translation offset along the x axis.ty
- the translation offset along the y axis.
-
scale
public final void scale(double s) Multiplies this transform with a scaling transformation. This is equivalent to callingmultiply(S)
, whereS
is aTransform
represented by the following matrix:[ s 0 0 ] [ 0 s 0 ] [ 0 0 1 ]
- Parameters:
s
- the scaling factor.
-
scale
public final void scale(double sx, double sy) Multiplies this transform with a scaling transformation. This is equivalent to callingmultiply(S)
, whereS
is aTransform
represented by the following matrix:[ sx 0 0 ] [ 0 sy 0 ] [ 0 0 1 ]
- Parameters:
sx
- the scaling factor along the x axis.sy
- the scaling factor along the y axis.
-
rotate
public final void rotate(double a) Multiplies the transform with a rotation transformation. This is equivalent to callingmultiply(R)
, whereR
is aTransform
represented by the following matrix:[ cos(a) -sin(a) 0 ] [ sin(a) cos(a) 0 ] [ 0 0 1 ]
- Parameters:
a
- the rotation angle in radians.
-
rotate
public final void rotate(double a, double x0, double y0) Multiplies the transform with a rotation transformation. This is equivalent to callingmultiply(R)
, whereR
is aTransform
represented by the following matrix:[ cos(a) -sin(a) -cos(a) * x0 + sin(a) * y0 + x0 ] [ sin(a) cos(a) -sin(a) * x0 - cos(a) * y0 + y0 ] [ 0 0 1 ]
- Parameters:
a
- the rotation angle in radians.x0
- the x position of the origin point.y0
- the y position of the origin point.
-
rotate
public final void rotate(double cosA, double sinA) Multiplies the transform with a rotation transformation. This is equivalent to callingmultiply(R)
, whereR
is aTransform
represented by the following matrix:[ cosA -sinA 0 ] [ sinA cosA 0 ] [ 0 0 1 ]
- Parameters:
cosA
- the cosine of rotation angle in radians.sinA
- the sinus of rotation angle in radians.
-
rotate
public final void rotate(double cosA, double sinA, double x0, double y0) Multiplies the transform with a rotation transformation. This is equivalent to callingmultiply(R)
, whereR
is aTransform
represented by the following matrix:[ cosA -sinA -cosA * x0 + sinA * y0 + x0 ] [ sinA cosA -sinA * x0 - cosA * y0 + y0 ] [ 0 0 1 ]
- Parameters:
cosA
- the cosine of rotation angle in radians.sinA
- the sinus of rotation angle in radians.x0
- the x position of the origin point.y0
- the y position of the origin point.
-
apply
Applies this transform to 2D point (x,y).- Parameters:
x
- the point x coordinate.y
- the point y coordinate.- Returns:
- the transformed point.
-
apply
Applies this transform to 2D point (x,y).- Parameters:
p
- the point.
-
apply
Applies this transform to 2D points (x,y).- Parameters:
points
- an array of points.
-
apply
Applies this transform to 2D points (x,y).- Parameters:
points
- an array of points.offset
- the offset in the array, to start transforming from.count
- the number of items to transform.
-
apply
Applies this transform to a rectangle.- Parameters:
rect
- the rectangle.- Throws:
IllegalStateException
- when this transform has a shear, rotation or negative scale component.- Since:
- 3.1
-
getTransform
@NotNull public static @NotNull Transform getTransform(@NotNull @NotNull Rectangle fromRect, @NotNull @NotNull Rectangle toRect) Gets the transform to transform a rectangle into another.- Parameters:
fromRect
- the source rectangle.toRect
- the destination rectangle.- Returns:
- the transform that transforms
fromRect
intotoRect
. - Throws:
IllegalArgumentException
- when a rectangle is invalid.- Since:
- 3.1
-
equals
-
hashCode
public int hashCode() -
toString
-