Donner
C++20 SVG rendering library
Loading...
Searching...
No Matches
donner::Transform< T > Struct Template Reference

A 2D matrix representing an affine transformation. More...

#include "donner/base/Transform.h"

Collaboration diagram for donner::Transform< T >:
[legend]

Classes

struct  UninitializedTag
 Tag type for constructing an uninitialized transform. More...
 

Public Member Functions

 Transform ()
 Construct an identity transform.
 
 Transform (UninitializedTag)
 Construct an uninitialized transform.
 
 ~Transform ()=default
 Destructor.
 
 Transform (const Transform< T > &)=default
 Copy constructor.
 
 Transform (Transform< T > &&)=default
 Move constructor.
 
Transform< T > & operator= (const Transform< T > &)=default
 Copy assignment operator.
 
Transform< T > & operator= (Transform< T > &&)=default
 Move assignment operator.
 
bool isIdentity () const
 Returns true if this transform is equal to the identity matrix.
 
determinant () const
 Returns the determinant.
 
Transform< T > inverse () const
 Returns the inverse of this transform.
 
Vector2< T > transformVector (const Vector2< T > &v) const
 Transforms a column vector, applying rotations/scaling but not translation.
 
Vector2< T > transformPosition (const Vector2< T > &v) const
 Transforms a position given as a vector.
 
Box< T > transformBox (const Box< T > &box) const
 Transform an axis-aligned bounding box, returning a new axis-aligned bounding box with the result.
 
Transform< T > operator* (const Transform< T > &rhs) const
 Post-multiplies rhs with this transform.
 

Static Public Member Functions

static Transform Rotation (T theta)
 Return a 2D rotation matrix with the given angle, in radians.
 
static Transform Scale (const Vector2< T > &extent)
 Return a 2D scale matrix.
 
static Transform Translate (const Vector2< T > &offset)
 Return a 2D translation matrix.
 
static Transform SkewX (T theta)
 Returns a 2D skew transformation along the X axis.
 
static Transform SkewY (T theta)
 Returns a 2D skew transformation along the Y axis.
 

Public Attributes

data [6]
 Storage for a 3x2 matrix, in column-major order.
 

Static Public Attributes

static constexpr UninitializedTag uninitialized = UninitializedTag()
 Tag value for constructing an uninitialized transform.
 

Friends

std::ostream & operator<< (std::ostream &os, const Transform< T > &t)
 Ostream output operator.
 

Detailed Description

template<typename T>
struct donner::Transform< T >

A 2D matrix representing an affine transformation.

It stores six parameters, and is equivalent to the 3x3 matrix:

\[ \begin{bmatrix} a & c & e \\ b & d & f \\ 0 & 0 & 1 \\ \end{bmatrix} \]

Elements are stored in column-major order.

Template Parameters
TElement type.

Class Documentation

◆ donner::Transform::UninitializedTag

struct donner::Transform::UninitializedTag
template<typename T>
struct donner::Transform< T >::UninitializedTag

Tag type for constructing an uninitialized transform.

Constructor & Destructor Documentation

◆ Transform()

template<typename T >
donner::Transform< T >::Transform ( UninitializedTag )
inlineexplicit

Construct an uninitialized transform.

A 2D matrix representing an affine transformation.
Definition Transform.h:31
static constexpr UninitializedTag uninitialized
Tag value for constructing an uninitialized transform.
Definition Transform.h:35

Member Function Documentation

◆ operator*()

template<typename T >
Transform< T > donner::Transform< T >::operator* ( const Transform< T > & rhs) const
inline

Post-multiplies rhs with this transform.

Example: Take A, transform by T, transform by R is written as

R * T * A
Parameters
rhsOther transform.

◆ Rotation()

template<typename T >
static Transform donner::Transform< T >::Rotation ( T theta)
inlinestatic

Return a 2D rotation matrix with the given angle, in radians.

Parameters
thetaAngle in radians.

◆ Scale()

template<typename T >
static Transform donner::Transform< T >::Scale ( const Vector2< T > & extent)
inlinestatic

Return a 2D scale matrix.

Parameters
extentScale x/y parameters.

◆ SkewX()

template<typename T >
static Transform donner::Transform< T >::SkewX ( T theta)
inlinestatic

Returns a 2D skew transformation along the X axis.

See also
https://www.w3.org/TR/css-transforms-1/#SkewXDefined
Parameters
thetaAngle in radians.

◆ SkewY()

template<typename T >
static Transform donner::Transform< T >::SkewY ( T theta)
inlinestatic

Returns a 2D skew transformation along the Y axis.

See also
https://www.w3.org/TR/css-transforms-1/#SkewYDefined
Parameters
thetaAngle in radians.

◆ transformBox()

template<typename T >
Box< T > donner::Transform< T >::transformBox ( const Box< T > & box) const
inline

Transform an axis-aligned bounding box, returning a new axis-aligned bounding box with the result.

Parameters
boxBox to transform.

◆ transformPosition()

template<typename T >
Vector2< T > donner::Transform< T >::transformPosition ( const Vector2< T > & v) const
inline

Transforms a position given as a vector.

\[ v' = M \begin{bmatrix} v_x \\ v_y \\ 1 \end{bmatrix} \]

Parameters
vVector to transform.
Returns
Transformed vector.

◆ transformVector()

template<typename T >
Vector2< T > donner::Transform< T >::transformVector ( const Vector2< T > & v) const
inline

Transforms a column vector, applying rotations/scaling but not translation.

\[ v' = M \begin{bmatrix} v_x \\ v_y \\ 0 \end{bmatrix} \]

Parameters
vVector to transform.
Returns
Transformed vector.

◆ Translate()

template<typename T >
static Transform donner::Transform< T >::Translate ( const Vector2< T > & offset)
inlinestatic

Return a 2D translation matrix.

Parameters
offsetTranslation offset.

Member Data Documentation

◆ data

template<typename T >
T donner::Transform< T >::data[6]

Storage for a 3x2 matrix, in column-major order.

Elements are stored in the following order:

  • 0 = scaleX (a)
  • 1 = skewY (b)
  • 2 = skewX (c)
  • 3 = scaleY (d)
  • 4 = translateX (e)
  • 5 = translateY (f)

The documentation for this struct was generated from the following file: