JUCE
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
AffineTransform Class Referencefinal

Represents a 2D affine-transformation matrix. More...

Public Member Functions

 AffineTransform ()=default
 Creates an identity transform. More...
 
 AffineTransform (const AffineTransform &)=default
 Creates a copy of another transform. More...
 
 AffineTransform (float mat00, float mat01, float mat02, float mat10, float mat11, float mat12) noexcept
 Creates a transform from a set of raw matrix values. More...
 
AffineTransformoperator= (const AffineTransform &)=default
 Copies from another AffineTransform object. More...
 
bool operator== (const AffineTransform &other) const noexcept
 Compares two transforms. More...
 
bool operator!= (const AffineTransform &other) const noexcept
 Compares two transforms. More...
 
template<typename ValueType >
void transformPoint (ValueType &x, ValueType &y) const noexcept
 Transforms a 2D coordinate using this matrix. More...
 
template<typename ValueType >
void transformPoints (ValueType &x1, ValueType &y1, ValueType &x2, ValueType &y2) const noexcept
 Transforms two 2D coordinates using this matrix. More...
 
template<typename ValueType >
void transformPoints (ValueType &x1, ValueType &y1, ValueType &x2, ValueType &y2, ValueType &x3, ValueType &y3) const noexcept
 Transforms three 2D coordinates using this matrix. More...
 
AffineTransform translated (float deltaX, float deltaY) const noexcept
 Returns a new transform which is the same as this one followed by a translation. More...
 
template<typename PointType >
AffineTransform translated (PointType delta) const noexcept
 Returns a new transform which is the same as this one followed by a translation. More...
 
AffineTransform withAbsoluteTranslation (float translationX, float translationY) const noexcept
 Returns a copy of this transform with the specified translation matrix values. More...
 
AffineTransform rotated (float angleInRadians) const noexcept
 Returns a transform which is the same as this one followed by a rotation. More...
 
AffineTransform rotated (float angleInRadians, float pivotX, float pivotY) const noexcept
 Returns a transform which is the same as this one followed by a rotation about a given point. More...
 
AffineTransform scaled (float factorX, float factorY) const noexcept
 Returns a transform which is the same as this one followed by a re-scaling. More...
 
AffineTransform scaled (float factor) const noexcept
 Returns a transform which is the same as this one followed by a re-scaling. More...
 
AffineTransform scaled (float factorX, float factorY, float pivotX, float pivotY) const noexcept
 Returns a transform which is the same as this one followed by a re-scaling. More...
 
AffineTransform sheared (float shearX, float shearY) const noexcept
 Returns a transform which is the same as this one followed by a shear. More...
 
AffineTransform inverted () const noexcept
 Returns a matrix which is the inverse operation of this one. More...
 
AffineTransform followedBy (const AffineTransform &other) const noexcept
 Returns the result of concatenating another transformation after this one. More...
 
bool isIdentity () const noexcept
 Returns true if this transform has no effect on points. More...
 
bool isSingularity () const noexcept
 Returns true if this transform maps to a singularity - i.e. More...
 
bool isOnlyTranslation () const noexcept
 Returns true if the transform only translates, and doesn't scale or rotate the points. More...
 
float getTranslationX () const noexcept
 If this transform is only a translation, this returns the X offset. More...
 
float getTranslationY () const noexcept
 If this transform is only a translation, this returns the X offset. More...
 
float getDeterminant () const noexcept
 Returns the determinant of the transform. More...
 
 JUCE_DEPRECATED (float getScaleFactor() const noexcept)
 This method has been deprecated. More...
 

Static Public Member Functions

static AffineTransform translation (float deltaX, float deltaY) noexcept
 Returns a new transform which is a translation. More...
 
template<typename PointType >
static AffineTransform translation (PointType delta) noexcept
 Returns a new transform which is a translation. More...
 
static AffineTransform rotation (float angleInRadians) noexcept
 Returns a new transform which is a rotation about (0, 0). More...
 
static AffineTransform rotation (float angleInRadians, float pivotX, float pivotY) noexcept
 Returns a new transform which is a rotation about a given point. More...
 
static AffineTransform scale (float factorX, float factorY) noexcept
 Returns a new transform which is a re-scale about the origin. More...
 
static AffineTransform scale (float factor) noexcept
 Returns a new transform which is a re-scale about the origin. More...
 
static AffineTransform scale (float factorX, float factorY, float pivotX, float pivotY) noexcept
 Returns a new transform which is a re-scale centred around the point provided. More...
 
static AffineTransform shear (float shearX, float shearY) noexcept
 Returns a shear transform, centred around the origin (0, 0). More...
 
static AffineTransform verticalFlip (float height) noexcept
 Returns a transform that will flip coordinates vertically within a window of the given height. More...
 
static AffineTransform fromTargetPoints (float x00, float y00, float x10, float y10, float x01, float y01) noexcept
 Returns the transform that will map three known points onto three coordinates that are supplied. More...
 
static AffineTransform fromTargetPoints (float sourceX1, float sourceY1, float targetX1, float targetY1, float sourceX2, float sourceY2, float targetX2, float targetY2, float sourceX3, float sourceY3, float targetX3, float targetY3) noexcept
 Returns the transform that will map three specified points onto three target points. More...
 
template<typename PointType >
static AffineTransform fromTargetPoints (PointType source1, PointType target1, PointType source2, PointType target2, PointType source3, PointType target3) noexcept
 Returns the transform that will map three specified points onto three target points. More...
 

Public Attributes

float mat00 { 1.0f }
 
float mat01 { 0.0f }
 
float mat02 { 0.0f }
 
float mat10 { 0.0f }
 
float mat11 { 1.0f }
 
float mat12 { 0.0f }
 

Detailed Description

Represents a 2D affine-transformation matrix.

An affine transformation is a transformation such as a rotation, scale, shear, resize or translation.

These are used for various 2D transformation tasks, e.g. with Path objects.

See also
Path, Point, Line

Constructor & Destructor Documentation

◆ AffineTransform() [1/3]

AffineTransform::AffineTransform ( )
default

Creates an identity transform.

◆ AffineTransform() [2/3]

AffineTransform::AffineTransform ( const AffineTransform )
default

Creates a copy of another transform.

◆ AffineTransform() [3/3]

AffineTransform::AffineTransform ( float  mat00,
float  mat01,
float  mat02,
float  mat10,
float  mat11,
float  mat12 
)
noexcept

Creates a transform from a set of raw matrix values.

The resulting matrix is:

(mat00 mat01 mat02)
(mat10 mat11 mat12)
(  0     0     1  )

Member Function Documentation

◆ operator=()

AffineTransform& AffineTransform::operator= ( const AffineTransform )
default

Copies from another AffineTransform object.

◆ operator==()

bool AffineTransform::operator== ( const AffineTransform other) const
noexcept

Compares two transforms.

◆ operator!=()

bool AffineTransform::operator!= ( const AffineTransform other) const
noexcept

Compares two transforms.

◆ transformPoint()

template<typename ValueType >
void AffineTransform::transformPoint ( ValueType &  x,
ValueType &  y 
) const
noexcept

Transforms a 2D coordinate using this matrix.

◆ transformPoints() [1/2]

template<typename ValueType >
void AffineTransform::transformPoints ( ValueType &  x1,
ValueType &  y1,
ValueType &  x2,
ValueType &  y2 
) const
noexcept

Transforms two 2D coordinates using this matrix.

This is just a shortcut for calling transformPoint() on each of these pairs of coordinates in turn. (And putting all the calculations into one function hopefully also gives the compiler a bit more scope for pipelining it).

◆ transformPoints() [2/2]

template<typename ValueType >
void AffineTransform::transformPoints ( ValueType &  x1,
ValueType &  y1,
ValueType &  x2,
ValueType &  y2,
ValueType &  x3,
ValueType &  y3 
) const
noexcept

Transforms three 2D coordinates using this matrix.

This is just a shortcut for calling transformPoint() on each of these pairs of coordinates in turn. (And putting all the calculations into one function hopefully also gives the compiler a bit more scope for pipelining it).

◆ translated() [1/2]

AffineTransform AffineTransform::translated ( float  deltaX,
float  deltaY 
) const
noexcept

Returns a new transform which is the same as this one followed by a translation.

◆ translated() [2/2]

template<typename PointType >
AffineTransform AffineTransform::translated ( PointType  delta) const
noexcept

Returns a new transform which is the same as this one followed by a translation.

◆ translation() [1/2]

static AffineTransform AffineTransform::translation ( float  deltaX,
float  deltaY 
)
staticnoexcept

Returns a new transform which is a translation.

◆ translation() [2/2]

template<typename PointType >
static AffineTransform AffineTransform::translation ( PointType  delta)
staticnoexcept

Returns a new transform which is a translation.

References BlocksProtocol::scale.

◆ withAbsoluteTranslation()

AffineTransform AffineTransform::withAbsoluteTranslation ( float  translationX,
float  translationY 
) const
noexcept

Returns a copy of this transform with the specified translation matrix values.

◆ rotated() [1/2]

AffineTransform AffineTransform::rotated ( float  angleInRadians) const
noexcept

Returns a transform which is the same as this one followed by a rotation.

The rotation is specified by a number of radians to rotate clockwise, centred around the origin (0, 0).

◆ rotated() [2/2]

AffineTransform AffineTransform::rotated ( float  angleInRadians,
float  pivotX,
float  pivotY 
) const
noexcept

Returns a transform which is the same as this one followed by a rotation about a given point.

The rotation is specified by a number of radians to rotate clockwise, centred around the coordinates passed in.

◆ rotation() [1/2]

static AffineTransform AffineTransform::rotation ( float  angleInRadians)
staticnoexcept

Returns a new transform which is a rotation about (0, 0).

◆ rotation() [2/2]

static AffineTransform AffineTransform::rotation ( float  angleInRadians,
float  pivotX,
float  pivotY 
)
staticnoexcept

Returns a new transform which is a rotation about a given point.

◆ scaled() [1/3]

AffineTransform AffineTransform::scaled ( float  factorX,
float  factorY 
) const
noexcept

Returns a transform which is the same as this one followed by a re-scaling.

The scaling is centred around the origin (0, 0).

◆ scaled() [2/3]

AffineTransform AffineTransform::scaled ( float  factor) const
noexcept

Returns a transform which is the same as this one followed by a re-scaling.

The scaling is centred around the origin (0, 0).

◆ scaled() [3/3]

AffineTransform AffineTransform::scaled ( float  factorX,
float  factorY,
float  pivotX,
float  pivotY 
) const
noexcept

Returns a transform which is the same as this one followed by a re-scaling.

The scaling is centred around the origin provided.

◆ scale() [1/3]

static AffineTransform AffineTransform::scale ( float  factorX,
float  factorY 
)
staticnoexcept

Returns a new transform which is a re-scale about the origin.

◆ scale() [2/3]

static AffineTransform AffineTransform::scale ( float  factor)
staticnoexcept

Returns a new transform which is a re-scale about the origin.

◆ scale() [3/3]

static AffineTransform AffineTransform::scale ( float  factorX,
float  factorY,
float  pivotX,
float  pivotY 
)
staticnoexcept

Returns a new transform which is a re-scale centred around the point provided.

◆ sheared()

AffineTransform AffineTransform::sheared ( float  shearX,
float  shearY 
) const
noexcept

Returns a transform which is the same as this one followed by a shear.

The shear is centred around the origin (0, 0).

◆ shear()

static AffineTransform AffineTransform::shear ( float  shearX,
float  shearY 
)
staticnoexcept

Returns a shear transform, centred around the origin (0, 0).

◆ verticalFlip()

static AffineTransform AffineTransform::verticalFlip ( float  height)
staticnoexcept

Returns a transform that will flip coordinates vertically within a window of the given height.

This is handy for converting between upside-down coordinate systems such as OpenGL or CoreGraphics.

◆ inverted()

AffineTransform AffineTransform::inverted ( ) const
noexcept

Returns a matrix which is the inverse operation of this one.

Some matrices don't have an inverse - in this case, the method will just return an identity transform.

◆ fromTargetPoints() [1/3]

static AffineTransform AffineTransform::fromTargetPoints ( float  x00,
float  y00,
float  x10,
float  y10,
float  x01,
float  y01 
)
staticnoexcept

Returns the transform that will map three known points onto three coordinates that are supplied.

This returns the transform that will transform (0, 0) into (x00, y00), (1, 0) to (x10, y10), and (0, 1) to (x01, y01).

◆ fromTargetPoints() [2/3]

static AffineTransform AffineTransform::fromTargetPoints ( float  sourceX1,
float  sourceY1,
float  targetX1,
float  targetY1,
float  sourceX2,
float  sourceY2,
float  targetX2,
float  targetY2,
float  sourceX3,
float  sourceY3,
float  targetX3,
float  targetY3 
)
staticnoexcept

Returns the transform that will map three specified points onto three target points.

◆ fromTargetPoints() [3/3]

template<typename PointType >
static AffineTransform AffineTransform::fromTargetPoints ( PointType  source1,
PointType  target1,
PointType  source2,
PointType  target2,
PointType  source3,
PointType  target3 
)
staticnoexcept

Returns the transform that will map three specified points onto three target points.

◆ followedBy()

AffineTransform AffineTransform::followedBy ( const AffineTransform other) const
noexcept

Returns the result of concatenating another transformation after this one.

◆ isIdentity()

bool AffineTransform::isIdentity ( ) const
noexcept

Returns true if this transform has no effect on points.

◆ isSingularity()

bool AffineTransform::isSingularity ( ) const
noexcept

Returns true if this transform maps to a singularity - i.e.

if it has no inverse.

◆ isOnlyTranslation()

bool AffineTransform::isOnlyTranslation ( ) const
noexcept

Returns true if the transform only translates, and doesn't scale or rotate the points.

◆ getTranslationX()

float AffineTransform::getTranslationX ( ) const
noexcept

If this transform is only a translation, this returns the X offset.

See also
isOnlyTranslation

◆ getTranslationY()

float AffineTransform::getTranslationY ( ) const
noexcept

If this transform is only a translation, this returns the X offset.

See also
isOnlyTranslation

References JUCE_DEPRECATED, and JUCE_DEPRECATED_STATIC.

◆ getDeterminant()

float AffineTransform::getDeterminant ( ) const
noexcept

Returns the determinant of the transform.

◆ JUCE_DEPRECATED()

AffineTransform::JUCE_DEPRECATED ( float getScaleFactor() const  noexcept)

This method has been deprecated.

You can calculate the scale factor using:

This method produces incorrect values for transforms containing rotations.

Returns the approximate scale factor by which lengths will be transformed. Obviously a length may be scaled by entirely different amounts depending on its direction, so this is only appropriate as a rough guide.

Member Data Documentation

◆ mat00

float AffineTransform::mat00 { 1.0f }

◆ mat01

float AffineTransform::mat01 { 0.0f }

◆ mat02

float AffineTransform::mat02 { 0.0f }

◆ mat10

float AffineTransform::mat10 { 0.0f }

◆ mat11

float AffineTransform::mat11 { 1.0f }

◆ mat12

float AffineTransform::mat12 { 0.0f }

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