Class WTransform
public class WTransform extends WJavaScriptExposableObject
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:
decomposeTranslateRotateScaleSkew()
decomposes into a T ∘ R ∘ Sxx ∘ SxydecomposeTranslateRotateScaleRotate()
decomposes into a T ∘ R1 ∘ Sxx ∘ R2
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.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
WTransform.TRSRDecomposition
Result of a TRSR decomposition.static class
WTransform.TRSSDecomposition
Result of a TRSS decomposition. -
Field Summary
Fields Modifier and Type Field Description static WTransform
Identity
A constant that represents the identity transform. -
Constructor Summary
Constructors Constructor Description WTransform()
Default constructor.WTransform(double m11, double m12, double m21, double m22, double dx, double dy)
Construct a custom matrix by specifying the parameters.WTransform(WTransform other)
Copy constructor. -
Method Summary
Modifier and Type Method Description WTransform
assign(WTransform rhs)
Assignment method.protected void
assignFromJSON(com.google.gson.JsonElement value)
WTransform
clone()
Clone method.boolean
closeTo(WTransform other)
void
decomposeTranslateRotateScaleRotate(WTransform.TRSRDecomposition result)
Decomposes the transformation.void
decomposeTranslateRotateScaleSkew(WTransform.TRSSDecomposition result)
Decomposes the transformation.static double
degreesToRadians(double angle)
Utility method to convert degrees to radians.boolean
equals(WTransform rhs)
Indicates whether some other object is "equal to" this one.WTransform
getAdjoint()
Returns the adjoint.double
getDeterminant()
Returns the determinant.double
getDx()
Returns the horizontal translation factor.double
getDy()
Returns the vertical translation factor.WTransform
getInverted()
Returns the inverted transformation.java.lang.String
getJsValue()
Returns a JavaScript representation of the value of this object.double
getM11()
Returns the horizontal scaling factor.double
getM12()
Returns the vertical shearing factor.double
getM13()
Returns m13 = 0.double
getM21()
Returns the horizontal shearing factor.double
getM22()
Returns the vertical scaling factor.double
getM23()
Returns m23 = 0.double
getM31()
Returns the horizontal translation factor.double
getM32()
Returns the vertical translation factor.double
getM33()
Returns m33 = 1.boolean
isIdentity()
Identity check.void
map(double x, double y, java.lang.Double tx, java.lang.Double ty)
Applys the transformation to a point.WPainterPath
map(WPainterPath path)
Applies the transformation to a painter path.WPointF
map(WPointF p)
Applys the transformation to a point.WRectF
map(WRectF rect)
Applies the transformation to a rectangle.WTransform
multiply(WTransform rhs)
Multiply 2 transform objects.WTransform
multiplyAndAssign(WTransform Y)
Adds a transform that is conceptually applied after this transform.void
reset()
Resets the transformation to the identity.WTransform
rotate(double angle)
Rotates the transformation.WTransform
rotateRadians(double angle)
Rotates the transformation.WTransform
scale(double sx, double sy)
Scales the transformation.WTransform
shear(double sh, double sv)
Shears the transformation.WTransform
translate(double dx, double dy)
Translates the transformation.WTransform
translate(WPointF p)
Translates the transformation.Methods inherited from class eu.webtoolkit.jwt.WJavaScriptExposableObject
assignBinding, assignBinding, checkModifiable, closeTo, getJsRef, isJavaScriptBound, sameBindingAs
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
Identity
A constant that represents the identity transform.- See Also:
isIdentity()
-
-
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
Copy constructor.
-
-
Method Details
-
assign
Assignment method.Copies the transformation from the
rhs
. -
clone
Clone method.Clones this
WTransform
object.- Specified by:
clone
in classWJavaScriptExposableObject
-
equals
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
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. -
map
public void map(double x, double y, java.lang.Double tx, java.lang.Double ty)Applys the transformation to a point.Sets the point (tx,
ty
) to the transformation of the point (x,y
).- See Also:
map(WPointF p)
-
map
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
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:
isIdentity()
,WTransform()
-
rotate
Rotates the transformation.Applies a clock-wise rotation to the current transformation matrix, over
angle
degrees.- See Also:
rotateRadians(double angle)
-
rotateRadians
Rotates the transformation.Applies a clock-wise rotation to the current transformation matrix, over
angle
radians.- See Also:
rotate(double angle)
-
scale
Scales the transformation.Scales the current transformation.
- See Also:
shear(double sh, double sv)
-
shear
Shears the transformation.Shears the current transformation.
- See Also:
scale(double sx, double sy)
,rotate(double angle)
-
translate
Translates the transformation.Translates the current transformation.
-
translate
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
Adds a transform that is conceptually applied after this transform. -
multiply
Multiply 2 transform objects. -
getDeterminant
public double getDeterminant()Returns the determinant. -
getAdjoint
Returns the adjoint. -
getInverted
Returns the inverted transformation.Returns
this
if the transformation could not be inverted (getDeterminant()
== 0), and logs an error instead. -
decomposeTranslateRotateScaleSkew
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
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
-
getJsValue
public java.lang.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 classWJavaScriptExposableObject
-
assignFromJSON
protected void assignFromJSON(com.google.gson.JsonElement value)- Specified by:
assignFromJSON
in classWJavaScriptExposableObject
-