Wt: Wt::WTransform Class Reference

Wt 4.10.4

Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
Wt::WTransform Class Reference
Painting system

A value class that defines a 2D affine transformation matrix. More...

`#include <Wt/WTransform.h>`

Inheritance diagram for Wt::WTransform:
[legend]

## Classes
struct | TRSRDecomposition
| Result of a TRSR decomposition. More...
struct | TRSSDecomposition
| Result of a TRSS decomposition. More...

## Public Member Functions
| 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 (const WTransform &other)
| Copy constructor.
WTransform & | operator= (const WTransform &rhs)
| Assignment operator.
bool | operator== (const WTransform &rhs) const
| Comparison operator.
bool | operator!= (const WTransform &rhs) const
| Comparison operator.
bool | isIdentity () const
| Identity check.
double | m11 () const
| Returns the horizontal scaling factor.
double | m12 () const
| Returns the vertical shearing factor.
double | m13 () const
| Returns m13 = 0.
double | m21 () const
| Returns the horizontal shearing factor.
double | m22 () const
| Returns the vertical scaling factor.
double | m23 () const
| Returns m23 = 0.
double | m31 () const
| Returns the horizontal translation factor.
double | m32 () const
| Returns the vertical translation factor.
double | m33 () const
| Returns m33 = 1.
double | dx () const
| Returns the horizontal translation factor.
double | dy () const
| Returns the vertical translation factor.
WPointF | map (const WPointF &p) const
| Applys the transformation to a point.
void | map (double x, double y, double *tx, double *ty) const
| Applys the transformation to a point.
WRectF | map (const WRectF &rect) const
| Applies the transformation to a rectangle.
WPainterPath | map (const WPainterPath &path) const
| Applies the transformation to a painter path.
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 (const WPointF &p)
| Translates the transformation.
WTransform & | operator*= (const WTransform &rhs)
| Adds a transform that is conceptually applied after this transform.
WTransform | operator* (const WTransform &rhs) const
| Multiply 2 transform objects.
double | determinant () const
| Returns the determinant.
WTransform | adjoint () const
| Returns the adjoint.
WTransform | inverted () const
| Returns the inverted transformation.
void | decomposeTranslateRotateScaleSkew (TRSSDecomposition &result) const
| Decomposes the transformation.
void | decomposeTranslateRotateScaleRotate (TRSRDecomposition &result) const
| Decomposes the transformation.
virtual std::string | jsValue () const override
| Returns a JavaScript representation of the value of this object.
Public Member Functions inherited from Wt::WJavaScriptExposableObject
bool | isJavaScriptBound () const
| Returns whether this object is JavaScript bound.
std::string | jsRef () const
| Returns a JavaScript reference to this object.

## Static Public Member Functions
static double | degreesToRadians (double angle)
| Utility method to convert degrees to radians.

## Static Public Attributes
static const WTransform | Identity
| A constant that represents the identity transform.

## Detailed Description

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
Wt::WTransform::dx
double dx() const
Returns the horizontal translation factor.
Definition WTransform.h:167
Wt::WTransform::m21
double m21() const
Returns the horizontal shearing factor.
Definition WTransform.h:137
Wt::WTransform::m22
double m22() const
Returns the vertical scaling factor.
Definition WTransform.h:141
Wt::WTransform::m12
double m12() const
Returns the vertical shearing factor.
Definition WTransform.h:129
Wt::WTransform::dy
double dy() const
Returns the vertical translation factor.
Definition WTransform.h:173
Wt::WTransform::m11
double m11() const
Returns the horizontal scaling factor.
Definition WTransform.h:125

In this representation, dx() (= m31()) and dy() (= m32()) 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 &#x2218; R &#x2218; Sxx &#x2218; Sxy
- decomposeTranslateRotateScaleRotate() decomposes into a T &#x2218; R1 &#x2218; Sxx &#x2218; 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.

## Constructor & Destructor Documentation

## ◆ WTransform() [1/2]

Wt::WTransform::WTransform | ( |  | ) |

Default constructor.

Creates the identity transformation matrix.

## ◆ WTransform() [2/2]

Wt::WTransform::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.

## Member Function Documentation

## ◆ decomposeTranslateRotateScaleRotate()

void Wt::WTransform::decomposeTranslateRotateScaleRotate | ( | TRSRDecomposition & | result | ) | const

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).

## ◆ decomposeTranslateRotateScaleSkew()

void Wt::WTransform::decomposeTranslateRotateScaleSkew | ( | TRSSDecomposition & | result | ) | const

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.

## ◆ dx()

double Wt::WTransform::dx | ( |  | ) | const

Returns the horizontal translation factor.

Is equivalent to m31()

## ◆ dy()

double Wt::WTransform::dy | ( |  | ) | const

Returns the vertical translation factor.

Is equivalent to m32()

## ◆ inverted()

WTransform Wt::WTransform::inverted | ( |  | ) | const

Returns the inverted transformation.

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

## ◆ isIdentity()

bool Wt::WTransform::isIdentity | ( |  | ) | const

Identity check.

Returns true if the transform represents an identity transformation.

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

## ◆ jsValue()

virtual std::string Wt::WTransform::jsValue | ( |  | ) | const
| overridevirtual

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 jsRef() intead.

Implements Wt::WJavaScriptExposableObject.

## ◆ m31()

double Wt::WTransform::m31 | ( |  | ) | const

Returns the horizontal translation factor.

Is equivalent to dx()

## ◆ m32()

double Wt::WTransform::m32 | ( |  | ) | const

Returns the vertical translation factor.

Is equivalent to dy()

## ◆ map() [1/4]

WPainterPath Wt::WTransform::map | ( | const WPainterPath & | path | ) | const

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.

## ◆ map() [2/4]

WPointF Wt::WTransform::map | ( | const WPointF & | p | ) | const

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(double x, double y, double *tx, double *ty) const

## ◆ map() [3/4]

WRectF Wt::WTransform::map | ( | const WRectF & | rect | ) | const

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() [4/4]

void Wt::WTransform::map | ( | double | x,
|  | double | y,
|  | double * | tx,
|  | double * | ty ) const

Applys the transformation to a point.

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

See also
  map(const WPointF&) const

## ◆ operator!=()

bool Wt::WTransform::operator!= | ( | const WTransform & | rhs | ) | const

Comparison operator.

Returns `true` if the transforms are different.

## ◆ operator=()

WTransform & Wt::WTransform::operator= | ( | const WTransform & | rhs | ) |

Assignment operator.

Copies the transformation from the `rhs`.

## ◆ operator==()

bool Wt::WTransform::operator== | ( | const WTransform & | rhs | ) | const

Comparison operator.

Returns `true` if the transforms are exactly the same.

## ◆ reset()

void Wt::WTransform::reset | ( |  | ) |

Resets the transformation to the identity.

Exceptions

  WException | if the transform is JavaScript bound

See also
  isIdentity(), WTransform()

## ◆ rotate()

WTransform & Wt::WTransform::rotate | ( | double | angle | ) |

Rotates the transformation.

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

See also
  rotateRadians()

## ◆ rotateRadians()

WTransform & Wt::WTransform::rotateRadians | ( | double | angle | ) |

Rotates the transformation.

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

See also
  rotate()

## ◆ scale()

WTransform & Wt::WTransform::scale | ( | double | sx,
|  | double | sy )

Scales the transformation.

Scales the current transformation.

See also
  shear()

## ◆ shear()

WTransform & Wt::WTransform::shear | ( | double | sh,
|  | double | sv )

Shears the transformation.

Shears the current transformation.

See also
  scale(), rotate()

## ◆ translate() [1/2]

WTransform & Wt::WTransform::translate | ( | const 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.

## ◆ translate() [2/2]

WTransform & Wt::WTransform::translate | ( | double | dx,
|  | double | dy )

Translates the transformation.

Translates the current transformation.

## Member Data Documentation

## ◆ Identity

const WTransform Wt::WTransform::Identity
| static

A constant that represents the identity transform.

See also
  isIdentity()