Class Transform

java.lang.Object
com.myscript.iink.graphics.Transform

public class Transform extends Object
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

    Fields
    Modifier and Type
    Field
    Description
    double
    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
    Constructor
    Description
    Default constructor.
    Transform(double xx, double yx, double tx, double xy, double yy, double ty)
    Constructor.
    Transform(@NotNull Transform other)
    Copy constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    final @NotNull Point
    apply(float x, float y)
    Applies this transform to 2D point (x,y).
    final void
    apply(@NotNull Point p)
    Applies this transform to 2D point (x,y).
    final void
    apply(@NotNull Point[] points)
    Applies this transform to 2D points (x,y).
    final void
    apply(@NotNull Point[] points, int offset, int count)
    Applies this transform to 2D points (x,y).
    final void
    apply(@NotNull Rectangle rect)
    Applies this transform to a rectangle.
    boolean
    equals(@Nullable Object obj)
     
    static @NotNull Transform
    getTransform(@NotNull Rectangle fromRect, @NotNull Rectangle toRect)
    Gets the transform to transform a rectangle into another.
    int
     
    final void
    Inverts this transform.
    final boolean
    isNear(@NotNull Transform other)
    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
    multiply(@NotNull Transform other)
    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
     
    final void
    translate(double tx, double ty)
    Multiplies the transform with a translation transformation.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • xx

      public double xx
      The X coordinate scaling element M1,1 of the transform matrix.
    • yx

      public double yx
      The X coordinate shearing element M1,2 of the transform matrix.
    • tx

      public double tx
      The X coordinate translation element M1,3 of the transform matrix.
    • xy

      public double xy
      The Y coordinate shearing element M2,1 of the transform matrix.
    • yy

      public double yy
      The Y coordinate scaling element M2,2 of the transform matrix.
    • ty

      public double ty
      The 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

      public Transform(@NotNull @NotNull Transform other)
      Copy constructor.
      Parameters:
      other - copied object.
  • Method Details

    • isNear

      public final boolean isNear(@NotNull @NotNull Transform other)
      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

      public final void multiply(@NotNull @NotNull Transform other)
      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 calling multiply(T), where T is a Transform 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 calling multiply(S), where S is a Transform 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 calling multiply(S), where S is a Transform 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 calling multiply(R), where R is a Transform 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 calling multiply(R), where R is a Transform 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 calling multiply(R), where R is a Transform 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 calling multiply(R), where R is a Transform 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

      @NotNull public final @NotNull Point apply(float x, float y)
      Applies this transform to 2D point (x,y).
      Parameters:
      x - the point x coordinate.
      y - the point y coordinate.
      Returns:
      the transformed point.
    • apply

      public final void apply(@NotNull @NotNull Point p)
      Applies this transform to 2D point (x,y).
      Parameters:
      p - the point.
    • apply

      public final void apply(@NotNull @NotNull Point[] points)
      Applies this transform to 2D points (x,y).
      Parameters:
      points - an array of points.
    • apply

      public final void apply(@NotNull @NotNull Point[] points, int offset, int count)
      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

      public final void apply(@NotNull @NotNull Rectangle rect)
      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 into toRect.
      Throws:
      IllegalArgumentException - when a rectangle is invalid.
      Since:
      3.1
    • equals

      public boolean equals(@Nullable @Nullable Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      @NotNull public final @NotNull String toString()
      Overrides:
      toString in class Object