Class Transform


  • public class Transform
    extends java.lang.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 tx
      The X coordinate translation element M1,3 of the transform matrix.
      double ty
      The Y coordinate translation element M2,3 of the transform matrix.
      double xx
      The X coordinate scaling element M1,1 of the transform matrix.
      double xy
      The Y coordinate shearing element M2,1 of the transform matrix.
      double yx
      The X coordinate shearing element M1,2 of the transform matrix.
      double yy
      The Y coordinate scaling element M2,2 of the transform matrix.
    • Constructor Summary

      Constructors 
      Constructor Description
      Transform()
      Default constructor.
      Transform​(double xx, double yx, double tx, double xy, double yy, double ty)
      Constructor.
      Transform​(@NotNull Transform other)
      Copy constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      @NotNull Point apply​(float x, float y)
      Applies this transform to 2D point (x,y).
      void apply​(@NotNull Point p)
      Applies this transform to 2D point (x,y).
      void apply​(@NotNull Point[] points)
      Applies this transform to 2D points (x,y).
      void apply​(@NotNull Point[] points, int offset, int count)
      Applies this transform to 2D points (x,y).
      boolean equals​(@Nullable java.lang.Object obj)  
      int hashCode()  
      void invert()
      Inverts this transform.
      boolean isNear​(@NotNull Transform other)
      Floating point comparison with tolerance.
      void multiply​(double xx, double yx, double tx, double xy, double yy, double ty)
      Multiply this transform.
      void multiply​(@NotNull Transform other)
      Multiplies this transform by the second transform.
      void rotate​(double a)
      Multiplies the transform with a rotation transformation.
      void rotate​(double cosA, double sinA)
      Multiplies the transform with a rotation transformation.
      void rotate​(double a, double x0, double y0)
      Multiplies the transform with a rotation transformation.
      void rotate​(double cosA, double sinA, double x0, double y0)
      Multiplies the transform with a rotation transformation.
      void scale​(double s)
      Multiplies this transform with a scaling transformation.
      void scale​(double sx, double sy)
      Multiplies this transform with a scaling transformation.
      @NotNull java.lang.String toString()  
      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 Detail

      • 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 Detail

      • 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 Detail

      • 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:
        java.lang.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.
      • equals

        public boolean equals​(@Nullable
                              @Nullable java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

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

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