Class WTransform


public class WTransform extends WJavaScriptExposableObject
A value class that defines a 2D affine transformation matrix.

The matrix is encoded using 6 parameters:


 m11  m12   0
 m21  m22   0
 dx   dy    1

 

In this representation, getDx() (= getM31()) and getDy() (= getM32()) represent the translation components, and mxy represent a 2D matrix that contains the scale, rotation (and skew) components.

The transformation is used to represent a tansformed coordinate system, and provides methods to rotate(), scale(), shear() or translate() this coordinate system.

There are also 2 methods to decompose an arbitrary matrix into elementary operations:

with T a translation, R a rotation, Sxx a scale, and Sxy a skew component.

JavaScript exposability

A WTransform is JavaScript exposable. If a WTransform is JavaScript bound, it can be accessed in your custom JavaScript code through its handle's jsRef(). A transform is represented as a JavaScript array, e.g. a WTransform(m11, m12, m21, m22, dx, dy) will be represented in JavaScript by:


 [m11, m12, m21, m22, dx, dy]

 

As an exception to the general rule that JavaScript bound objects should not be modified, WTransform does support many modifications. These modifications will then accumulate in the JavaScript representation of the transform.

  • Field Details

    • Identity

      public static final WTransform Identity
      A constant that represents the identity transform.

      See Also:
  • Constructor Details

    • WTransform

      public WTransform()
      Default constructor.

      Creates the identity transformation matrix.

    • WTransform

      public WTransform(double m11, double m12, double m21, double m22, double dx, double dy)
      Construct a custom matrix by specifying the parameters.

      Creates a matrix from the specified parameters.

    • WTransform

      public WTransform(WTransform other)
      Copy constructor.
  • Method Details

    • assign

      public WTransform assign(WTransform rhs)
      Assignment method.

      Copies the transformation from the rhs.

    • clone

      public WTransform clone()
      Clone method.

      Clones this WTransform object.

      Specified by:
      clone in class WJavaScriptExposableObject
    • equals

      public boolean equals(WTransform rhs)
      Indicates whether some other object is "equal to" this one.

      Returns true if the transforms are exactly the same.

    • isIdentity

      public boolean isIdentity()
      Identity check.

      Returns true if the transform represents an identity transformation.

      Note: This is always false if the transform is JavaScript bound.

    • getM11

      public double getM11()
      Returns the horizontal scaling factor.
    • getM12

      public double getM12()
      Returns the vertical shearing factor.
    • getM13

      public double getM13()
      Returns m13 = 0.
    • getM21

      public double getM21()
      Returns the horizontal shearing factor.
    • getM22

      public double getM22()
      Returns the vertical scaling factor.
    • getM23

      public double getM23()
      Returns m23 = 0.
    • getM31

      public double getM31()
      Returns the horizontal translation factor.

      Is equivalent to getDx()

    • getM32

      public double getM32()
      Returns the vertical translation factor.

      Is equivalent to getDy()

    • getM33

      public double getM33()
      Returns m33 = 1.
    • getDx

      public double getDx()
      Returns the horizontal translation factor.

      Is equivalent to getM31()

    • getDy

      public double getDy()
      Returns the vertical translation factor.

      Is equivalent to getM32()

    • map

      public WPointF map(WPointF p)
      Applys the transformation to a point.

      Returns the transformed point.

      Note: If this transform or the given point are JavaScript bound, the resulting point will also be JavaScript bound.

      See Also:
    • map

      public void map(double x, double y, Double tx, Double ty)
      Applys the transformation to a point.

      Sets the point (tx, ty) to the transformation of the point (x, y).

      See Also:
    • map

      public WRectF map(WRectF rect)
      Applies the transformation to a rectangle.

      Since the rectangle is aligned with X and Y axes, this may increase the size of the rectangle even for a transformation that only rotates.

      Note: If this transform or the given rectangle are JavaScript bound, the resulting rectangle will also be JavaScript bound.

    • map

      public WPainterPath map(WPainterPath path)
      Applies the transformation to a painter path.

      This will transform all individual points according to the transformation. The radius of arcs will be unaffected.

      Note: If this transform or the given path are JavaScript bound, the resulting path will also be JavaScript bound.

    • reset

      public void reset()
      Resets the transformation to the identity.

      See Also:
    • rotate

      public WTransform rotate(double angle)
      Rotates the transformation.

      Applies a clock-wise rotation to the current transformation matrix, over angle degrees.

      See Also:
    • rotateRadians

      public WTransform rotateRadians(double angle)
      Rotates the transformation.

      Applies a clock-wise rotation to the current transformation matrix, over angle radians.

      See Also:
    • scale

      public WTransform scale(double sx, double sy)
      Scales the transformation.

      Scales the current transformation.

      See Also:
    • shear

      public WTransform shear(double sh, double sv)
      Shears the transformation.

      Shears the current transformation.

      See Also:
    • translate

      public WTransform translate(double dx, double dy)
      Translates the transformation.

      Translates the current transformation.

    • translate

      public WTransform translate(WPointF p)
      Translates the transformation.

      Translates the current transformation.

      Note: If this transform or the given point are JavaScript bound, the resulting transform will also be JavaScript bound.

    • multiplyAndAssign

      public WTransform multiplyAndAssign(WTransform Y)
      Adds a transform that is conceptually applied after this transform.
    • multiply

      public WTransform multiply(WTransform rhs)
      Multiply 2 transform objects.
    • getDeterminant

      public double getDeterminant()
      Returns the determinant.
    • getAdjoint

      public WTransform getAdjoint()
      Returns the adjoint.
    • getInverted

      public WTransform getInverted()
      Returns the inverted transformation.

      Returns this if the transformation could not be inverted (getDeterminant() == 0), and logs an error instead.

    • decomposeTranslateRotateScaleSkew

      public void decomposeTranslateRotateScaleSkew(WTransform.TRSSDecomposition result)
      Decomposes the transformation.

      Decomposes the transformation into elementary operations: translation (dx, dy ), followed by rotation (alpha), followed by scale (sx, sy) and vertical shearing factor (sh). The angle is expressed in radians.

      This performs a Gram-Schmidt orthonormalization.

    • decomposeTranslateRotateScaleRotate

      public void decomposeTranslateRotateScaleRotate(WTransform.TRSRDecomposition result)
      Decomposes the transformation.

      Decomposes the transformation into elementary operations: translation (dx, dy ), followed by rotation (alpha2), followed by scale (sx, sy) and again a rotation (alpha2). The angles are expressed in radians.

      This performs a Singular Value Decomposition (SVD).

    • degreesToRadians

      public static double degreesToRadians(double angle)
      Utility method to convert degrees to radians.
    • closeTo

      public boolean closeTo(WTransform other)
    • getJsValue

      public String getJsValue()
      Description copied from class: WJavaScriptExposableObject
      Returns a JavaScript representation of the value of this object.

      Note: The value returned will reflect the current server side value of the object. If this object is JavaScript bound, this value may not reflect the actual client side value. If you need access to the client side value, use getJsRef() intead.

      Specified by:
      getJsValue in class WJavaScriptExposableObject
    • assignFromJSON

      protected void assignFromJSON(com.google.gson.JsonElement value)
      Specified by:
      assignFromJSON in class WJavaScriptExposableObject