InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
PMMatrix Class Reference

#include <PMMatrix.h>

Public Types

enum  TransformFactorOrder { kFactorOrder_SKRT = 0, kFactorOrder_RKST = 14, kFactorOrder_End }
 
typedef base_type data_type
 

Public Member Functions

void ReadWrite (IPMStream *s)
 
constexpr PMMatrix () noexcept
 
constexpr PMMatrix (PMReal a, PMReal b, PMReal c, PMReal d, PMReal e, PMReal f) noexcept
 
constexpr PMMatrix (const PMMatrix &m) noexcept=default
 
constexpr PMMatrix (PMMatrix &&m) noexcept=default
 
 PMMatrix (const BRVCoordMatrix &m)
 
PMMatrixoperator= (const PMMatrix &m) noexcept=default
 
PMMatrixoperator= (PMMatrix &&m) noexcept=default
 
void SetMatrix (const BRVCoordMatrix &m)
 
void SetMatrix (const _t_BRVFixedMatrix &m)
 
void SetMatrix (const dvacore::geom::ScaleMatrixT< float > &m)
 
void GetAGMFixedMatrix (_t_BRVFixedMatrix *retMatrix) const
 
void GetAGMFloatMatrix (BRVCoordMatrix *retMatrix) const
 
void GetUIMatrixF32 (dvacore::geom::ScaleMatrixT< float > *retMatrix) const
 
bool16 operator== (const PMMatrix &other) const
 
bool16 operator!= (const PMMatrix &other) const
 
bool16 operator< (const PMMatrix &other) const
 
void Transform (PMReal *x, PMReal *y) const
 
void Transform (PMPoint *p) const
 
void Transform (PMPolygon4 *fourPoints) const
 
void Transform (PMRect *rect) const
 
void Transform (PMLineSeg *segment) const
 
const PMReal operator[] (int index) const
 
bool16 IsIdentity () const noexcept
 
bool exactly_identity () const noexcept
 
void ResetToIdentity () noexcept
 
PMReal Determinant () const
 
bool16 IsSingular () const
 
bool16 PreservesBoxes () const
 
void Invert ()
 
PMMatrix Inverse () const
 
void PreConcat (const PMMatrix &m)
 
void PostConcat (const PMMatrix &m)
 
void PermuteLeftPast (const PMMatrix &m)
 
void PermuteRightPast (const PMMatrix &m)
 
void PreScale (PMReal xScale, PMReal yScale)
 
void Scale (PMReal xScale, PMReal yScale)
 
const PMMatrixScaleFrom (const PMPoint &stationaryPoint, PMReal xScale, PMReal yScale)
 
void SkewHorizontal (PMReal xSkewAngleInDegrees)
 
void SkewVertical (PMReal ySkewAngleInDegrees)
 
void SkewFrom (const PMPoint &stationaryPoint, PMReal skewAngle, PMReal noSkewDirectionAngle)
 
void PreRotate (PMReal angleInDegrees)
 
void Rotate (PMReal angleInDegrees)
 
const PMMatrixRotateAbout (const PMPoint &center, PMReal angle)
 
void PreTranslate (PMReal x, PMReal y)
 
void PreTranslate (const PMPoint &offset)
 
void Translate (PMReal x, PMReal y)
 
void Translate (const PMPoint &offset)
 
void ScaleTo (PMReal xScale, PMReal yScale)
 
void ScaleTo (const PMPoint &stationaryPoint, PMReal xScale, PMReal yScale)
 
void SkewTo (PMReal xSkewAngleInDegrees)
 
void SkewTo (const PMPoint &stationaryPoint, PMReal xSkewAngleInDegrees)
 
void SkewToSlope (const PMPoint &stationaryPoint, PMReal skewSlope)
 
void RotateTo (PMReal thetaInDegrees)
 
void RotateTo (const PMPoint &stationaryPoint, PMReal thetaInDegrees)
 
void RotateTo (const PMPoint &stationaryPoint, PMReal cosineAngle, PMReal sineAngle)
 
void TranslateTo (PMReal x, PMReal y)
 
void SetOrigin (PMReal x, PMReal y)
 
uint32 GetMatrixFactors (PMMatrix *scale, PMMatrix *skew, PMMatrix *rotate, PMMatrix *translate, TransformFactorOrder factorOrder=kFactorOrder_SKRT) const
 
uint32 GetTransformValues (PMReal *xscale, PMReal *yscale, PMReal *skewslope, PMReal *costheta, PMReal *sintheta, PMReal *xtranslation, PMReal *ytranslation, TransformFactorOrder factorOrder=kFactorOrder_SKRT) const
 
uint32 GetMatrixContent () const
 
PMReal GetXScale () const
 
PMReal GetYScale () const
 
PMReal GetXSkewAngle () const
 
PMReal GetRotationAngle (bool16 zeroCentered=kFalse) const
 
PMReal GetXTranslation () const noexcept
 
PMReal GetYTranslation () const noexcept
 
void GetMatrixInfo (PMReal *rotAngle, PMReal *xSkewAngle, PMReal *xScale, PMReal *yScale) const
 
void SanityCheck () const
 

Static Public Attributes

static const uint32 kHasNoTransformContent = 0
 
static const uint32 kHasScaleContent = 1
 
static const uint32 kHasSkewContent = 2
 
static const uint32 kHasRotateContent = 4
 
static const uint32 kHasTranslateContent = 8
 
static const uint32 kHasAllTransformContent = (kHasScaleContent | kHasSkewContent | kHasRotateContent | kHasTranslateContent)
 

Friends

PMMatrix operator* (const PMMatrix &m1, const PMMatrix &m2)
 

Detailed Description

C++ class for dealing with matrix operations.

Constructor & Destructor Documentation

constexpr PMMatrix::PMMatrix ()
inlinenoexcept

Contruct an identity matrix: [ 1 0 0] [ 0 1 0] [ 0 0 1]

constexpr PMMatrix::PMMatrix (PMReal a,
PMReal b,
PMReal c,
PMReal d,
PMReal e,
PMReal f 
)
inlinenoexcept

Contruct a matrix with a, b, c, d, e, f as initial values: [ a b 0] [ c d 0] [ e f 1]

constexpr PMMatrix::PMMatrix (const PMMatrixm)
defaultnoexcept

Construct a matrix with the same perceptible value as m.

PMMatrix::PMMatrix (const BRVCoordMatrix & m)

Construct a PMMatrix from an AGM fixed or float matrix.

Parameters
mis the AGM matrix.

Member Function Documentation

PMReal PMMatrix::Determinant () const
Returns
the product of x and y scaling. I.e., given m = *this, return m[0]*m[3] - m[1]*m[2] where operator[] is as described above.
void PMMatrix::GetAGMFixedMatrix (_t_BRVFixedMatrix * retMatrix) const

Create and return an equivalent AGM matrix from this PMMatrix.

Parameters
retMatrixis the AGM matrix created.
void PMMatrix::GetAGMFloatMatrix (BRVCoordMatrix * retMatrix) const

Create and return an equivalent AGM float matrix from this PMMatrix.

Parameters
retMatrixis the AGM matrix created.
uint32 PMMatrix::GetMatrixContent () const

GetMatrixContent returns the value that would have been returned from a call to either GetMatrixFactors or GetTransformValues with all non-nil parameters and TransformFactorOrder == kFactorOrder_SKRT. This function is simply more efficient and perhaps more convenient.

uint32 PMMatrix::GetMatrixFactors (PMMatrixscale,
PMMatrixskew,
PMMatrixrotate,
PMMatrixtranslate,
TransformFactorOrder factorOrder = kFactorOrder_SKRT 
) const

GetMatrixFactors asserts if *this is singular. Otherwise, if scale, skew, rotate, and translate are non-nil pointers, then GetMatrixFactors writes matrices to the specified locations such that:

1) scale * skew * rotate * translate == *this if factorOrder == kFactorOrder_SKRT

   otherwise rotate * skew * scale * translate == *this if factorORder == kFactorOrder_RKST

2) scale[1] == scale[2] == scale[4] == scale[5] == 0.0

3) skew[1] == scale[4] == scale[5] == 0.0

   skew[0] == skew[3] == 1.0

4) rotate[0] == rotate[3]

   rotate[1] == -rotate[2]

   determinant(rotate) == 1.0

5) translate[0] == translate[3] == 1.0

   translate[1] == translate[2] == 0.0

Any nil-pointer passed makes GetMatrixFactors skip writing the corresponding matrix, but this does not change the factorization nor have any effect on the matrices whose values are written.

The return value of GetMatrixFactors is a combination of the above constants OR'd together as one unsigned value. If scale[0] or scale[3] differ from 1.0, then (result & kHasScaleContent). If skew[2] differs from 0.0 then (result & kHasSkewContent). If rotate[0] differs from 1.0 then (result & kHasRotateContent). And if either translate[4] or translate[5] differ from 0.0 then (result & kHasTranslateContent). Note the return value from GetMatrixFactors will not have any bits set for transform components whose factor was not requested. For example, GetMatrixFactors( nil, nil, &rotate, nil) will return either kHasNoTransformContent or kHasRotateContent even if the matrix has other transform components.

Note that the factorization returned from GetMatrixFactors, as described above, is not unique. In particular, for kFactorOrder_SKRT, if one changed the algebraic sign of scale[0], scale[3], rotate[0], rotate[1], rotate[2], and rotate[3], then the set of factors would still meet all the conditions above. Currently it is unspecified which of the two factorizations is returned. Code that relies on one or the other is incorrect.

void PMMatrix::GetMatrixInfo (PMRealrotAngle,
PMRealxSkewAngle,
PMRealxScale,
PMRealyScale 
) const

Returns the rotation angle, x skew angle, x and y scale factors represented by this matrix.

Parameters
rotAngleis the rotation angle of the matrx in the range [0, 360).
xSkewAngleis the x skew angle of the matrx in the range (-90, 90).
xScaleis the x scale factor.
yScaleis the y scale factor.
PMReal PMMatrix::GetRotationAngle (bool16 zeroCentered = kFalse) const
Returns
one of the angles whose sine and cosine would be returned in the fourth and fifth parameters to GetTransformValues with TransformFactorOrder == kFactorOrder_SKRT. Note the angle measurement returned is in degrees. The return value will be in the range (-180, 180] if zeroCentered is kTrue, otherwise it will be in the range [0, 360).
uint32 PMMatrix::GetTransformValues (PMRealxscale,
PMRealyscale,
PMRealskewslope,
PMRealcostheta,
PMRealsintheta,
PMRealxtranslation,
PMRealytranslation,
TransformFactorOrder factorOrder = kFactorOrder_SKRT 
) const

GetTransformValues writes to its non-nil parameters the free values in the matrices that would have been returned in a call to GetMatrixFactors. In particular, *xscale == scale[0], *yscale == scale[3], *skewslope == skew[2], *costheta == rotate[0], *sintheta == rotate[1], *xtranslation == translate[4], and *ytranslation == translate[5]. Any nil pointers cause GetTransformValues to skip writing the corresponding return value, with the restriction that the pair of parameters (xscale, yscale) must be both nil or both non-nil. Likewise for the the pair (costheta, sintheta) and the pair (xtranslation, ytranslation). Callers are not allowed to be "interested in" only one of the pair. GetTransformValues will assert on such a call.

The return value has the same meaning as the return value of GetMatrixFactors. And like GetMatrixFactors, the only bits set will be those whose corresponding transform values were requested with non-nil pointers.

And, as described for GetMatrixFactors, the 7-tuple returned from GetTransformValues, is not unique. In particular, for kFactorOrder_SKRT, if one changed the algebraic sign of xscale, yscale, costheta, and sintheta, then the set of values would still correctly characterize the matrix. Currently it is unspecified which of the two 7-tuples is returned. Code that relies on one or the other is incorrect.

void PMMatrix::GetUIMatrixF32 (dvacore::geom::ScaleMatrixT< float > * retMatrix) const

Return an equivalent Drover dvaui::ui::UI_MatrixF32 matrix from this PMMatrix.

Parameters
retMatrixis the Drover matrix created.
PMReal PMMatrix::GetXScale () const
Returns
the x scale factor that would be returned in the first parameter to GetTransformValues with TransformFactorOrder == kFactorOrder_SKRT.
PMReal PMMatrix::GetXSkewAngle () const
Returns
the x skew angle in degrees in the range (-90, 90) whose tangent would be returned in the third parameter to GetTransformValues with TransformFactorOrder == kFactorOrder_SKRT.
PMReal PMMatrix::GetXTranslation () const
inlinenoexcept
Returns
the x translation amount that would be returned in the sixth parameter to GetTransformValues with TransformFactorOrder == kFactorOrder_SKRT.
PMReal PMMatrix::GetYScale () const
Returns
the y scale factor that would be returned in the second parameter to GetTransformValues with TransformFactorOrder == kFactorOrder_SKRT.
PMReal PMMatrix::GetYTranslation () const
inlinenoexcept
Returns
the y translation amount that would be returned in the seventh parameter to GetTransformValues with TransformFactorOrder == kFactorOrder_SKRT.
PMMatrix PMMatrix::Inverse () const
Returns
the inverse matrix of this matrix. Original matrix is unchanged.
void PMMatrix::Invert ()

Replace the value of this matrix with its inverse discarding its previous value.

bool16 PMMatrix::IsIdentity () const
noexcept
Returns
kTrue if m * (*this) == m for all m. Otherwise return kFalse;
bool16 PMMatrix::IsSingular () const
inline
Returns
whether the product of x and y scaling is zero. Note if m.IsSingular() then m has no inverse and m.Invert() will assert.
bool16 PMMatrix::operator< (const PMMatrixother) const

A partial ordering on matrices for use in sorted containers

PMMatrix& PMMatrix::operator= (const PMMatrixm)
defaultnoexcept

Make *this have the same perceptible value as m. Returns *this.

bool16 PMMatrix::operator== (const PMMatrixother) const

Return kTrue if *this and other have the same perceptible value. Otherwise returns kFalse;

const PMReal PMMatrix::operator[] (int index) const

Extract the nth free value of *this as a PMReal. The index must be >= 0 and <= 5. In other words consider the following code:

PMReal a,b,c,d,e,f,x,y;



x = y = 0;

m.Transform( &x, &y);

e = x;

f = y;



x = 1; y = 0;

m.Transform( &x, &y);

a = x - e;

b = y - f;



x = 0; y = 1;

m.Transform( &x, &y);

c = x - e;

d = y - f;

Then m[0] returns a m[1] returns b m[2] returns c m[3] returns d m[4] returns e m[5] returns f

operator[] is simply more convenient and perhaps more efficient than using the above code. Note that the implementation of PMMatrix need not be an array of 6 PMReals even though this operator gives it that appearance.

void PMMatrix::PermuteLeftPast (const PMMatrixm)

PermuteLeftPast computes m * (*this) * inverse(m) and assigns the result to *this. I.e. computes the new value of this such that m * oldthis == newthis * m

void PMMatrix::PermuteRightPast (const PMMatrixm)

PermuteRigthPast computes inverse(m) * (*this) * m and assigns the result to *this. I.e. computes the new value of this such that oldthis * m == m * newthis

void PMMatrix::PostConcat (const PMMatrixm)

Set *this = (*this) * m.

void PMMatrix::PreConcat (const PMMatrixm)

Set *this = m * (*this).

void PMMatrix::PreRotate (PMReal angleInDegrees)

Set *this = PMMatrix( cosine(angleInDegrees), sine(angleInDegrees), -sine(angleInDegrees), cosine(angleInDegrees), 0, 0) * (*this);

void PMMatrix::PreScale (PMReal xScale,
PMReal yScale 
)

Set *this = PMMatrix(xScale, 0, 0, yScale, 0, 0) * (*this)

bool16 PMMatrix::PreservesBoxes () const
Returns
kTrue if an axes aligned rectangle (like PMRect) remains an axes aligned rectangle when transformed by *this. That is, *this contains no skew component and at most a 90-degree multiple rotation. This is equivalent to calling GetTransformValues and checking if skewslope == zero and (costheta == 0 || sintheta == 0) but is perhaps more efficient or more convenient.
void PMMatrix::PreTranslate (PMReal x,
PMReal y 
)

Set *this = PMMatrix( 1, 0, 0, 1, x, y) * (*this);

void PMMatrix::ReadWrite (IPMStreams)

Read/Write this matrix.

Parameters
sis the stream to read from and write to.
void PMMatrix::ResetToIdentity ()
noexcept

Set this matrix to the identity matrix discarding its previous value.

void PMMatrix::Rotate (PMReal angleInDegrees)

Set *this = (*this) * PMMatrix( cosine(angleInDegrees), sine(angleInDegrees), -sine(angleInDegrees), cosine(angleInDegrees), 0, 0);

void PMMatrix::RotateTo (PMReal thetaInDegrees)

Rotate the matrix to the specified angle.

Parameters
thetais the x skew angle.
void PMMatrix::Scale (PMReal xScale,
PMReal yScale 
)

Set *this = (*this) * PMMatrix(xScale, 0, 0, yScale, 0, 0)

void PMMatrix::ScaleTo (PMReal xScale,
PMReal yScale 
)

Scale the matrix to the specified x and y scale factors.

Parameters
xScaleis the x scale factor to scale to. yScale is the y scale factor to scale to.
void PMMatrix::SetMatrix (const BRVCoordMatrix & m)

Set the PMMatrix with an AGM float matrix.

Parameters
mis the AGM matrix.
void PMMatrix::SetMatrix (const _t_BRVFixedMatrix & m)

Set the PMMatrix with an AGM fixed matrix.

Parameters
mis the AGM matrix.
void PMMatrix::SetMatrix (const dvacore::geom::ScaleMatrixT< float > & m)

Set the PMMatrix with a Drover dvaui::ui::UI_MatrixF32 matrix. (which is a typedef of dvacore::geom::ScaleMatrixT<float>)

Parameters
mis the Drover matrix.
void PMMatrix::SkewHorizontal (PMReal xSkewAngleInDegrees)

Set *this = (*this) * PMMatrix(1, 0, tangent(xSkewAngleInDegrees), 1, 0, 0);

void PMMatrix::SkewTo (PMReal xSkewAngleInDegrees)

Skew the matrix to the specified x skew angle.

Parameters
xSkewAngleis the x skew angle.
void PMMatrix::SkewVertical (PMReal ySkewAngleInDegrees)

Set *this = (*this) * PMMatrix(1, tangent(ySkewAngleInDegrees), 0, 1, 0, 0);

void PMMatrix::Transform (PMRealx,
PMRealy 
) const

Compute the matrix product [ *x *y 1] * (*this) producing the result [ x' y' 1]. Then write x' back into *x and y' back into *y.

void PMMatrix::Transform (PMPolygon4fourPoints) const

Transforms each of the four points specified in fourPoints independently and writes the results back into the corresponding slots of the same PMPolygon4.

void PMMatrix::Transform (PMRectrect) const

Transforms rect and return (back in *rect) the smallest axes-aligned rectangle that contains the transformed rectangle.

void PMMatrix::Transform (PMLineSegsegment) const

Transform each of the two points specified in the segment independently, and write the results back into the PMLineSeg perhaps in reverse order if required to satisfy the invariant of PMLineSeg that segment.Top().Y() be no larger than segment.Bottom().Y().

void PMMatrix::Translate (PMReal x,
PMReal y 
)

Set *this = (*this) * PMMatrix( 1, 0, 0, 1, x, y);

void PMMatrix::TranslateTo (PMReal x,
PMReal y 
)

Set the origin to x and y.

Parameters
xis the origin to set to on the x-axis.
yis the origin to set to on the y-axis .

Friends And Related Function Documentation

PMMatrix operator* (const PMMatrixm1,
const PMMatrixm2 
)
friend
Returns
the matrix product m1.m2 without affecting the value of m1 or m2.