# C

# Transform Class

class Qul::PlatformInterface::TransformThe Transform class specifies 2D transformations of a coordinate system. More...

Header: | #include <platforminterface/transform.h> |

Since: | Qt 1.5 |

This class was introduced in Qt 1.5.

## Public Types

enum | Type { Identity, Translate, UniformScale, Scale, Rotation, …, Arbitrary } |

## Public Functions

Transform(Qul::PlatformInterface::Transform::Type type, float m11, float m12, float m21, float m22, float dx, float dy) | |

Transform() | |

float | m11() const |

float | m12() const |

float | m21() const |

float | m22() const |

float | determinant() const |

float | dx() const |

float | dy() const |

Qul::PlatformInterface::Transform | inverted(bool *invertible) const |

PlatformInterface::PointF | map(PlatformInterface::PointF point) const |

PlatformInterface::RectF | map(const PlatformInterface::RectF &rect) const |

Qul::PlatformInterface::Transform & | rotate(float angle) |

Qul::PlatformInterface::Transform & | scale(float sx, float sy) |

Qul::PlatformInterface::Transform & | translate(float x, float y) |

Qul::PlatformInterface::Transform | translated(float x, float y) const |

PlatformInterface::PointF | translation() const |

Qul::PlatformInterface::Transform::Type | type() const |

Qul::PlatformInterface::Transform | operator*(const Qul::PlatformInterface::Transform &transform) const |

bool | operator==(const Qul::PlatformInterface::Transform &transform) const |

## Static Public Members

Qul::PlatformInterface::Transform | fromRotation(float angle) |

Qul::PlatformInterface::Transform | fromScale(float sx, float sy) |

Qul::PlatformInterface::Transform | fromTranslation(float dx, float dy) |

## Detailed Description

A transformation specifies how to translate, scale, shear or rotate the coordinate system, and is typically used when rendering graphics.

The Transform type and its matrix can be set when a Transform object is constructed. The default constructor creates a Transform object with Identity type and matrix. Alternatively, a Transform object can be created using fromTranslation(), fromRotation() or fromScale() static functions. It is also possible to create Transform objects by applying basic matrix operations.

The Transform class supports mapping of graphic primitives: Using the map() functions a given point or region can be mapped to the coordinate system defined by the transformation.

Transform provides the type() function, which returns the type of current transformation. The inverted() function returns an inverted copy of the transformation, if it is invertible, otherwise it returns the identity. In addition, Transform provides the determinant() function, which returns the matrix's determinant.

Finally, the Transform class supports multiplication and equality comparison.

### Basic Matrix Operations

`m11` | `m12` |
---|---|

`m21` | `m22` |

`dx` | `dy` |

A Transform object contains a 3 x 2 matrix. The `dx`

and `dy`

elements specify horizontal and vertical translation. The `m11`

and `m22`

elements specify horizontal and vertical scaling. The `m12`

and `m21`

elements specify horizontal and vertical *shearing*.

Transform transforms a point in the plane to another point using the following formulas:

x' = m11*x + m21*y + dx y' = m22*y + m12*x + dy

The point *(x, y)* is the original point, and *(x', y')* is the transformed point. *(x', y')* can be transformed back to *(x, y)* by performing the same operation on the inverted() matrix.

The various matrix elements can be set when constructing the Transform. They can also be manipulated using the translate(), rotate() and scale() convenience functions. The currently set values can be retrieved using the m11(), m12(), m21(), m22(), dx() and dy() functions.

Translation is the simplest transformation. Setting `dx`

and `dy`

will move the coordinate system `dx`

units along the X axis and `dy`

units along the Y axis. Scaling can be done by setting `m11`

and `m22`

. For example, setting `m11`

to 2 and `m22`

to 1.5 will double the height and increase the width by 50%. The identity matrix has `m11`

and `m22`

set to 1 (all others are set to 0) mapping a point to itself. Shearing is controlled by `m12`

and `m21`

. Setting these elements to values different from zero will twist the coordinate system. Rotation is achieved by setting both, the shearing factors and the scaling factors.

- the transpose of the matrix is applied to vectors and rects so applying it to (x, y) is (m11 * x + m21 * y, m12 * x + m22 * y) (could also interpret as applying the transform from the right)
- consequently chaining two transforms A * B will mean A is applied first, then B
- shearing can be represented by Transform, but sheared blending is not supported by the drawing engine

**See also** Transform QML type

## Member Type Documentation

### enum Transform::Type

Constant | Value | Description |
---|---|---|

`Qul::PlatformInterface::Transform::Identity` | `0` | identity |

`Qul::PlatformInterface::Transform::Translate` | `1` | pure translation |

`Qul::PlatformInterface::Transform::UniformScale` | `2` | scale uniformly, then translate |

`Qul::PlatformInterface::Transform::Scale` | `3` | scale, then translate |

`Qul::PlatformInterface::Transform::Rotation` | `4` | rotate, then translate |

`Qul::PlatformInterface::Transform::RotationUniformScale` | `5` | rotate, scale (uniformly), then translate |

`Qul::PlatformInterface::Transform::ScaleRotation` | `6` | scale, then rotate, then translate |

`Qul::PlatformInterface::Transform::Arbitrary` | `7` | any matrix |

## Member Function Documentation

### Transform::Transform(Qul::PlatformInterface::Transform::Type *type*, float *m11*, float *m12*, float *m21*, float *m22*, float *dx*, float *dy*)

Constructs a Transform object with the given *type* and factors *m11*, *m12*, *m21*, *m22*, *dx* and *dy*.

**See also **Basic Matrix Operations.

### Transform::Transform()

The default constructor creates a Transform object with Identity type.

All elements are set to zero except scale factors `m11`

and `m22`

, which are set to 1.

**See also **Basic Matrix Operations.

### float Transform::m11() const

Returns the horizontal scaling factor.

**See also **scale() and Basic Matrix Operations.

### float Transform::m12() const

Returns the vertical shearing factor.

**Note: **Shearing can be represented by Transform, but sheared blending is not supported by the drawing engine.

**See also **Basic Matrix Operations.

### float Transform::m21() const

Returns the horizontal shearing factor.

**Note: **Shearing can be represented by Transform, but sheared blending is not supported by the drawing engine.

**See also **Basic Matrix Operations.

### float Transform::m22() const

Returns the vertical scaling factor.

**See also **scale() and Basic Matrix Operations.

### float Transform::determinant() const

Returns the determinant of this transformation's matrix.

### float Transform::dx() const

Returns the horizontal translation factor.

**See also **translate() and Basic Matrix Operations.

### float Transform::dy() const

Returns the vertical translation factor.

**See also **translate() and Basic Matrix Operations.

`[static] `

Qul::PlatformInterface::Transform Transform::fromRotation(float *angle*)

Returns a Transform object rotated by given *angle*.

**See also **rotate() and Basic Matrix Operations.

`[static] `

Qul::PlatformInterface::Transform Transform::fromScale(float *sx*, float *sy*)

Returns a Transform object with the given scale factors *sx* and *sy*.

**See also **scale() and Basic Matrix Operations.

`[static] `

Qul::PlatformInterface::Transform Transform::fromTranslation(float *dx*, float *dy*)

Returns a Transform object with the given translation factors *dx* and *dy*.

**See also **translated(), translate(), and Basic Matrix Operations.

### Qul::PlatformInterface::Transform Transform::inverted(bool **invertible*) const

Returns inverted copy of this transformation.

If the matrix of this transformation is not invertible, the returned Transform is of Identity type. If the given *invertible* is valid pointer, its value is set to true if the matrix is invertible, otherwise it is set to false.

**See also **Transform().

### PlatformInterface::PointF Transform::map(PlatformInterface::PointF *point*) const

Returns a copy of the given *point*, mapped to the coordinate system defined by this transformation.

**See also **Basic Matrix Operations.

### PlatformInterface::RectF Transform::map(const PlatformInterface::RectF &*rect*) const

Returns a copy of the given *rect*, mapped to the coordinate system defined by this transformation.

**See also **Basic Matrix Operations.

### Qul::PlatformInterface::Transform &Transform::rotate(float *angle*)

Returns a reference to `this`

transform object rotated by the given *angle*.

The *angle* is specified in degrees.

**See also **Basic Matrix Operations.

### Qul::PlatformInterface::Transform &Transform::scale(float *sx*, float *sy*)

Returns a reference to `this`

transform object scaled by the given factors *sx* and *sy*.

**See also **Basic Matrix Operations.

### Qul::PlatformInterface::Transform &Transform::translate(float *x*, float *y*)

Returns a reference to `this`

transform object, translated by the given factors *x* and *y*.

**See also **translated() and Basic Matrix Operations.

### Qul::PlatformInterface::Transform Transform::translated(float *x*, float *y*) const

Returns a copy of this transformation, translated by the given factors *x* and *y*.

**See also **translate() and Basic Matrix Operations.

### PlatformInterface::PointF Transform::translation() const

Returns translation factors of this transformation wrapped in Qul::PlatformInterface::PointF.

**See also **dx(), dy(), and Basic Matrix Operations.

### Qul::PlatformInterface::Transform::Type Transform::type() const

Returns the transformation type of this transform.

The transformation type captures all transformations. For example, if the transform both scales uniformly and rotates, the type would be RotationUniformScale.

Knowing the transformation type is useful for optimization: you can often optimize handling of specific transformations.

### Qul::PlatformInterface::Transform Transform::operator*(const Qul::PlatformInterface::Transform &*transform*) const

Returns the result of multiplying this transformation with the given *transform*.

**Note: **matrix multiplication is not commutative, i.e. a*b != b*a.

### bool Transform::operator==(const Qul::PlatformInterface::Transform &*transform*) const

Returns `true`

if this transformation is equal to the given *transform*, otherwise returns `false`

.

Available under certain Qt licenses.

Find out more.