Donner SVG 0.8.0
0.8.0 ยท ebf353960.8.0 main
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
donner::Transform2< T > Struct Template Reference

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

#include "donner/base/Transform.h"

Classes

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

Public Member Functions

 Transform2 ()
 Construct an identity transform.
 Transform2 (UninitializedTag)
 Construct an uninitialized transform.
 ~Transform2 ()=default
 Destructor.
 Transform2 (const Transform2< T > &)=default
 Copy constructor.
 Transform2 (Transform2< T > &&)=default
 Move constructor.
Transform2< T > & operator= (const Transform2< T > &)=default
 Copy assignment operator.
Transform2< T > & operator= (Transform2< T > &&)=default
 Move assignment operator.
bool isIdentity () const
 Returns true if this transform is equal to the identity matrix.
bool isTranslation () const
 Returns true if this transform is a pure translation (no rotation, scale, or skew).
Vector2< T > translation () const
 Returns the translation component of this transform as a vector.
T determinant () const
 Returns the determinant.
Transform2< 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.
Box2< T > transformBox (const Box2< T > &box) const
 Transform an axis-aligned bounding box, returning a new axis-aligned bounding box with the result.
Transform2< T > operator* (const Transform2< T > &rhs) const
 Composes two transforms: the result applies this transform first, then rhs.
bool operator== (const Transform2< T > &rhs) const
 Exact element-wise equality.

Static Public Member Functions

static Transform2 Rotate (T angleRadians)
 Return a 2D rotation matrix with the given angle, in radians.
static Transform2 Scale (T extent)
 Return a 2D scale matrix with uniform scaling.
static Transform2 Scale (const Vector2< T > &extent)
 Return a 2D scale matrix with horizontal and vertical scaling from a Vector2.
static Transform2 Scale (T x, T y)
 Return a 2D scale matrix with horizontal and vertical scaling, convenience API accepting two parameters.
static Transform2 Translate (const Vector2< T > &offset)
 Return a 2D translation matrix.
static Transform2 Translate (T x, T y)
 Return a 2D translation matrix, convenience API accepting two parameters.
static Transform2 SkewX (T theta)
 Returns a 2D skew transformation along the X axis.
static Transform2 SkewY (T theta)
 Returns a 2D skew transformation along the Y axis.

Public Attributes

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

Static Public Attributes

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

Friends

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

Detailed Description

template<typename T>
struct donner::Transform2< 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::Transform2::UninitializedTag

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

Tag type for constructing an uninitialized transform.

Constructor & Destructor Documentation

◆ Transform2()

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

Construct an uninitialized transform.

static constexpr const UninitializedTag uninitialized
Tag value for constructing an uninitialized transform.
Definition Transform.h:38
Transform2()
Construct an identity transform.
Definition Transform.h:55

Member Function Documentation

◆ inverse()

template<typename T>
Transform2< T > donner::Transform2< T >::inverse ( ) const
inline

Returns the inverse of this transform.

If the determinant is zero, the result contains non-finite values.

◆ isTranslation()

template<typename T>
bool donner::Transform2< T >::isTranslation ( ) const
inline

Returns true if this transform is a pure translation (no rotation, scale, or skew).

A pure translation has the form:

\[\begin{bmatrix} 1 & 0 & e \\ 0 & 1 & f \\ 0 & 0 & 1 \\ \end{bmatrix} \]

◆ operator*()

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

Composes two transforms: the result applies this transform first, then rhs.

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

A * T * R
Parameters
rhsTransform applied after this one.

◆ operator==()

template<typename T>
bool donner::Transform2< T >::operator== ( const Transform2< T > & rhs) const
inline

Exact element-wise equality.

No epsilon: this is the comparison a cache key needs, where any difference in the producing transform means the cached derivative has to be rebuilt. Compare with an explicit tolerance instead when the two transforms went through different arithmetic.

Parameters
rhsOther transform.

◆ Rotate()

template<typename T>
Transform2 donner::Transform2< T >::Rotate ( T angleRadians)
inlinestatic

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

Parameters
angleRadiansAngle in radians.

◆ Scale() [1/3]

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

Return a 2D scale matrix with horizontal and vertical scaling from a Vector2.

Parameters
extentScale x/y parameters.

◆ Scale() [2/3]

template<typename T>
Transform2 donner::Transform2< T >::Scale ( T extent)
inlinestatic

Return a 2D scale matrix with uniform scaling.

Parameters
extentScale x/y parameters.

◆ Scale() [3/3]

template<typename T>
Transform2 donner::Transform2< T >::Scale ( T x,
T y )
inlinestatic

Return a 2D scale matrix with horizontal and vertical scaling, convenience API accepting two parameters.

Parameters
xHorizontal scale.
yVertical scale.

◆ SkewX()

template<typename T>
Transform2 donner::Transform2< 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>
Transform2 donner::Transform2< 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>
Box2< T > donner::Transform2< T >::transformBox ( const Box2< 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::Transform2< 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::Transform2< 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() [1/2]

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

Return a 2D translation matrix.

Parameters
offsetTranslation offset.

◆ Translate() [2/2]

template<typename T>
Transform2 donner::Transform2< T >::Translate ( T x,
T y )
inlinestatic

Return a 2D translation matrix, convenience API accepting two parameters.

Parameters
xHorizontal translation offset.
yVertical translation offset.

Member Data Documentation

◆ data

template<typename T>
T donner::Transform2< 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: