soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SMatrix Class Reference

The SMatrix class holds a 3x3 matrix for transforming coordinates. SMatrix does not have a constructor, so it must be explicitly initialized using either reset() - to construct an identity matrix, or one of the set functions (e.g., setTranslate, setRotate, etc.). More...

#include <SMatrix.h>

Inheritance diagram for SMatrix:
_IxForm

Public Types

enum  TypeMask {
  kIdentity_Mask = 0 , kTranslate_Mask = 0x01 , kScale_Mask = 0x02 , kAffine_Mask = 0x04 ,
  kPerspective_Mask = 0x08
}
 Enum of bit fields for the mask returned by getType(). Use this to identify the complexity of the matrix. More...
 
enum  {
  kAScaleX , kASkewY , kASkewX , kAScaleY ,
  kATransX , kATransY
}
 Enum for affine array indices. Affine arrays are in column major order because that's how PDF and XPS like it. More...
 
enum  ScaleToFit { kFill_ScaleToFit , kStart_ScaleToFit , kCenter_ScaleToFit , kEnd_ScaleToFit }
 Enum for scale-to-fit options. More...
 
enum  { kMaxFlattenSize = 9 * sizeof(float) + sizeof(uint32_t) }
 
typedef void(* MapXYProc) (const SMatrix &mat, float x, float y, SPoint *result)
 Function pointer type for mapping a single point (x, y) to a transformed point.
 
typedef void(* MapPtsProc) (const SMatrix &mat, SPoint dst[], const SPoint src[], int count)
 Function pointer type for mapping an array of points.
 

Public Member Functions

 SMatrix ()
 Default constructor, initializes the matrix to identity.
 
 SMatrix (const float data[9])
 Constructor that initializes the matrix with the given data array.
 
SMatrixoperator*= (const SMatrix &src)
 Multiplies the matrix by another matrix.
 
SMatrix operator* (const SMatrix &src) const
 Multiplies the matrix by another matrix.
 
SMatrixoperator= (const SMatrix &src)
 Assignment operator.
 
SMatrixtranslate (float dx, float dy)
 Post-concats the matrix with a translation.
 
SMatrixscale (float sx, float sy)
 Post-concats the matrix with a scale.
 
SMatrixshear (float sh, float sv)
 Post-concats the matrix with a shear.
 
SMatrixrotate (float deg)
 Post-concats the matrix with a rotation.
 
IxFormData () SCONST OVERRIDE
 Returns a pointer to the matrix data.
 
void reset () OVERRIDE
 Resets the matrix to the identity matrix.
 
void setIdentity () OVERRIDE
 Sets the matrix to the identity matrix.
 
BOOL isIdentity () SCONST OVERRIDE
 Checks if the matrix is the identity matrix.
 
void setTranslate (float dx, float dy) OVERRIDE
 Sets the matrix to a translation.
 
void setScale (float sx, float sy) OVERRIDE
 Sets the matrix to a scale.
 
void setScale2 (float sx, float sy, float px, float py) OVERRIDE
 Sets the matrix to a scale with pivot point.
 
void setRotate (float degrees) OVERRIDE
 Sets the matrix to a rotation.
 
void setRotate2 (float degrees, float px, float py) OVERRIDE
 Sets the matrix to a rotation with pivot point.
 
void setSkew (float kx, float ky) OVERRIDE
 Sets the matrix to a skew.
 
void setSkew2 (float kx, float ky, float px, float py) OVERRIDE
 Sets the matrix to a skew with pivot point.
 
TypeMask getType () const
 Returns a bitfield describing the transformations the matrix may perform. The bitfield is computed conservatively, so it may include false positives. For example, when kPerspective_Mask is true, all other bits may be set to true even in the case of a non-perspective transform.
 
bool isScaleTranslate () const
 Checks if the matrix contains only scale and translation.
 
bool rectStaysRect () const
 Returns true if the matrix will map a rectangle to another rectangle. This can be true if the matrix is identity, scale-only, or rotates a multiple of 90 degrees.
 
bool preservesAxisAlignment () const
 Alias for rectStaysRect().
 
bool hasPerspective () const
 Checks if the matrix contains perspective elements.
 
bool isSimilarity (float tol=((1.0f)/(1<< 12))) const
 Checks if the matrix contains only translation, rotation/reflection, or uniform scale. Returns false if other transformation types are included or if the matrix is degenerate.
 
bool preservesRightAngles (float tol=((1.0f)/(1<< 12))) const
 Checks if the matrix contains only translation, rotation/reflection, or scale (non-uniform scale is allowed). Returns false if other transformation types are included or if the matrix is degenerate.
 
float operator[] (int index) const
 Accesses the matrix element at the specified index.
 
float get (int index) const
 Accesses the matrix element at the specified index.
 
float & operator[] (int index)
 Accesses the matrix element at the specified index.
 
void set (int index, float value)
 Sets the matrix element at the specified index.
 
void setMatrix (const float data[9], int matType=kUnknown_Mask)
 Sets the matrix to the specified data array.
 
void setTranslate (const SVector2D &v)
 Sets the matrix to a translation.
 
bool setIDiv (int divx, int divy)
 Sets the matrix to scale by 1/divx and 1/divy.
 
void setSinCos (float sinValue, float cosValue, float px, float py)
 Sets the matrix to rotate by the specified sine and cosine values, with a pivot point at (px, py).
 
void setSinCos (float sinValue, float cosValue)
 Sets the matrix to rotate by the specified sine and cosine values.
 
void setConcat (const SMatrix &a, const SMatrix &b)
 Sets the matrix to the concatenation of the two specified matrices.
 
void preTranslate (float dx, float dy)
 Pre-concats the matrix with the specified translation.
 
void preTranslate (int dx, int dy)
 Pre-concats the matrix with the specified translation.
 
void preScale (float sx, float sy, float px, float py)
 Pre-concats the matrix with the specified scale.
 
void preScale (float sx, float sy)
 Pre-concats the matrix with the specified scale.
 
void preRotate (float degrees, float px, float py)
 Pre-concats the matrix with the specified rotation.
 
void preRotate (float degrees)
 Pre-concats the matrix with the specified rotation.
 
void preSkew (float kx, float ky, float px, float py)
 Pre-concats the matrix with the specified skew.
 
void preSkew (float kx, float ky)
 Pre-concats the matrix with the specified skew.
 
void preConcat (const SMatrix &other)
 Pre-concats the matrix with the specified matrix.
 
void postTranslate (float dx, float dy)
 Post-concats the matrix with the specified translation.
 
void postTranslate (int dx, int dy)
 Post-concats the matrix with the specified translation.
 
void postScale (float sx, float sy, float px, float py)
 Post-concats the matrix with the specified scale.
 
void postScale (float sx, float sy)
 Post-concats the matrix with the specified scale.
 
bool postIDiv (int divx, int divy)
 Post-concats the matrix by dividing it by the specified integers.
 
void postRotate (float degrees, float px, float py)
 Post-concats the matrix with the specified rotation.
 
void postRotate (float degrees)
 Post-concats the matrix with the specified rotation.
 
void postSkew (float kx, float ky, float px, float py)
 Post-concats the matrix with the specified skew.
 
void postSkew (float kx, float ky)
 Post-concats the matrix with the specified skew.
 
void postConcat (const SMatrix &other)
 Post-concats the matrix with the specified matrix.
 
bool setRectToRect (const SRect &src, const SRect &dst, ScaleToFit stf)
 Set the matrix to the scale and translate values that map the source rectangle to the destination rectangle, returning true if the result can be represented.
 
bool setPolyToPoly (const SPoint src[], const SPoint dst[], int count)
 Set the matrix such that the specified src points would map to the specified dst points. count must be within [0..4].
 
bool invert (SMatrix *inverse) const
 If this matrix can be inverted, return true and if inverse is not null, set inverse to be the inverse of this matrix. If this matrix cannot be inverted, ignore inverse and return false.
 
bool asAffine (float affine[6]) const
 Fills the passed array with the affine values in column major order. If the matrix is a perspective transform, returns false and does not change the passed array.
 
void mapPoints (SPoint dst[], const SPoint src[], int count) const
 Apply this matrix to the array of points specified by src, and write the transformed points into the array of points specified by dst. dst[] = M * src[].
 
void mapPoints (SPoint pts[], int count) const
 Apply this matrix to the array of points, overwriting it with the transformed values. dst[] = M * pts[].
 
void mapPointsWithStride (SPoint pts[], size_t stride, int count) const
 Like mapPoints but with custom byte stride between the points. Stride should be a multiple of sizeof(float).
 
void mapPointsWithStride (SPoint dst[], SPoint src[], size_t stride, int count) const
 Like mapPoints but with custom byte stride between the points.
 
void mapHomogeneousPoints (float dst[], const float src[], int count) const
 Apply this matrix to the array of homogeneous points, specified by src, where a homogeneous point is defined by 3 contiguous scalar values, and write the transformed points into the array of scalars specified by dst. dst[] = M * src[].
 
void mapXY (float x, float y, SPoint *result) const
 Apply this matrix to the point (x, y) and store the result in *result.
 
void mapVectors (SVector2D dst[], const SVector2D src[], int count) const
 Apply this matrix to the array of vectors specified by src, and write the transformed vectors into the array of vectors specified by dst. This is similar to mapPoints, but ignores any translation in the matrix.
 
void mapVectors (SVector2D vecs[], int count) const
 Apply this matrix to the array of vectors specified by src, and write the transformed vectors into the array of vectors specified by dst. This is similar to mapPoints, but ignores any translation in the matrix.
 
bool mapRect (SRect *dst, const SRect &src) const
 Apply this matrix to the src rectangle, and write the transformed rectangle into dst. This is accomplished by transforming the 4 corners of src, and then setting dst to the bounds of those points.
 
bool mapRect (SRect *rect) const
 Apply this matrix to the rectangle, and write the transformed rectangle back into it. This is accomplished by transforming the 4 corners of rect, and then setting it to the bounds of those points.
 
void mapRectToQuad (SPoint dst[4], const SRect &rect) const
 Apply this matrix to the src rectangle, and write the four transformed points into dst. The points written to dst will be the original top-left, top-right, bottom-right, and bottom-left points transformed by the matrix.
 
float mapRadius (float radius) const
 Return the mean radius of a circle after it has been mapped by this matrix. NOTE: in perspective this value assumes the circle has its center at the origin.
 
MapXYProc getMapXYProc () const
 Get the appropriate MapXYProc for this matrix.
 
MapPtsProc getMapPtsProc () const
 Get the appropriate MapPtsProc for this matrix.
 
bool cheapEqualTo (const SMatrix &m) const
 Efficient comparison of two matrices. It distinguishes between zero and negative zero. It will return false when the sign of zero values is the only difference between the two matrices. It considers NaN values to be equal to themselves. So a matrix full of NaNs is "cheap equal" to another matrix full of NaNs iff the NaN values are bitwise identical while according to strict the strict == test a matrix with a NaN value is equal to nothing, including itself.
 
float getMinScale () const
 Calculates the minimum scaling factor of the matrix as computed from the SVD of the upper left 2x2. If the matrix has perspective -1 is returned.
 
float getMaxScale () const
 Calculates the maximum scaling factor of the matrix as computed from the SVD of the upper left 2x2. If the matrix has perspective -1 is returned.
 
bool getMinMaxScales (float scaleFactors[2]) const
 Gets both the min and max scale factors. The min scale factor is scaleFactors[0] and the max is scaleFactors[1]. If the matrix has perspective false will be returned and scaleFactors will be unchanged.
 
void dirtyMatrixTypeCache ()
 Testing routine; the matrix's type cache should never need to be manually invalidated during normal use.
 

Static Public Member Functions

static void SetAffineIdentity (float affine[6])
 Fills the passed array with affine identity values in column major order.
 
static MapXYProc GetMapXYProc (TypeMask mask)
 Get the appropriate MapXYProc for the given type mask.
 
static MapPtsProc GetMapPtsProc (TypeMask mask)
 Get the appropriate MapPtsProc for the given type mask.
 
static const SMatrixI ()
 Return a reference to a const identity matrix.
 
static const SMatrixInvalidMatrix ()
 Return a reference to a const matrix that is "invalid", one that could never be used.
 
static SMatrix Concat (const SMatrix &a, const SMatrix &b)
 Return the concatenation of two matrices, a * b.
 
static float SFloatSinCos (float radians, float *cosValue)
 

Friends

class SkPerspIter
 
bool operator== (const SMatrix &a, const SMatrix &b)
 Equality operator.
 
bool operator!= (const SMatrix &a, const SMatrix &b)
 Inequality operator.
 

Additional Inherited Members

- Public Attributes inherited from _IxForm
float fMat [kMCount]
 Array of floats representing the matrix elements.
 

Detailed Description

The SMatrix class holds a 3x3 matrix for transforming coordinates. SMatrix does not have a constructor, so it must be explicitly initialized using either reset() - to construct an identity matrix, or one of the set functions (e.g., setTranslate, setRotate, etc.).

Definition at line 20 of file SMatrix.h.

Member Typedef Documentation

◆ MapPtsProc

typedef void(* SMatrix::MapPtsProc) (const SMatrix &mat, SPoint dst[], const SPoint src[], int count)

Function pointer type for mapping an array of points.

Definition at line 808 of file SMatrix.h.

◆ MapXYProc

typedef void(* SMatrix::MapXYProc) (const SMatrix &mat, float x, float y, SPoint *result)

Function pointer type for mapping a single point (x, y) to a transformed point.

Definition at line 782 of file SMatrix.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Enum for affine array indices. Affine arrays are in column major order because that's how PDF and XPS like it.

Definition at line 296 of file SMatrix.h.

◆ anonymous enum

anonymous enum

Definition at line 846 of file SMatrix.h.

◆ ScaleToFit

Enum for scale-to-fit options.

Enumerator
kFill_ScaleToFit 

Scale in X and Y independently, so that src matches dst exactly. This may change the aspect ratio of the src.

kStart_ScaleToFit 

Compute a scale that will maintain the original src aspect ratio, but will also ensure that src fits entirely inside dst. At least one axis (X or Y) will fit exactly. kStart aligns the result to the left and top edges of dst.

kCenter_ScaleToFit 

Compute a scale that will maintain the original src aspect ratio, but will also ensure that src fits entirely inside dst. At least one axis (X or Y) will fit exactly. The result is centered inside dst.

kEnd_ScaleToFit 

Compute a scale that will maintain the original src aspect ratio, but will also ensure that src fits entirely inside dst. At least one axis (X or Y) will fit exactly. kEnd aligns the result to the right and bottom edges of dst.

Definition at line 543 of file SMatrix.h.

◆ TypeMask

Enum of bit fields for the mask returned by getType(). Use this to identify the complexity of the matrix.

Enumerator
kIdentity_Mask 

Set if the matrix is identity.

kTranslate_Mask 

Set if the matrix has translation.

kScale_Mask 

Set if the matrix has X or Y scale.

kAffine_Mask 

Set if the matrix skews or rotates.

kPerspective_Mask 

Set if the matrix is in perspective.

Definition at line 209 of file SMatrix.h.

Constructor & Destructor Documentation

◆ SMatrix() [1/2]

SMatrix::SMatrix ( )
inline

Default constructor, initializes the matrix to identity.

Definition at line 27 of file SMatrix.h.

◆ SMatrix() [2/2]

SMatrix::SMatrix ( const float data[9])

Constructor that initializes the matrix with the given data array.

Parameters
dataArray of 9 floats representing the matrix elements.

Definition at line 35 of file SMatrix.cpp.

Member Function Documentation

◆ asAffine()

bool SMatrix::asAffine ( float affine[6]) const

Fills the passed array with the affine values in column major order. If the matrix is a perspective transform, returns false and does not change the passed array.

Parameters
affineArray to fill with affine values. Ignored if NULL.
Returns
True if the matrix is affine, false otherwise.

Definition at line 859 of file SMatrix.cpp.

◆ cheapEqualTo()

bool SMatrix::cheapEqualTo ( const SMatrix & m) const
inline

Efficient comparison of two matrices. It distinguishes between zero and negative zero. It will return false when the sign of zero values is the only difference between the two matrices. It considers NaN values to be equal to themselves. So a matrix full of NaNs is "cheap equal" to another matrix full of NaNs iff the NaN values are bitwise identical while according to strict the strict == test a matrix with a NaN value is equal to nothing, including itself.

Parameters
mMatrix to compare with.
Returns
True if matrices are cheaply equal, false otherwise.

Definition at line 841 of file SMatrix.h.

◆ Concat()

static SMatrix SMatrix::Concat ( const SMatrix & a,
const SMatrix & b )
inlinestatic

Return the concatenation of two matrices, a * b.

Parameters
aFirst matrix.
bSecond matrix.
Returns
Resulting matrix.

Definition at line 894 of file SMatrix.h.

◆ Data()

IxForm * SMatrix::Data ( )

Returns a pointer to the matrix data.

Returns
Pointer to the matrix data.

Definition at line 1772 of file SMatrix.cpp.

◆ dirtyMatrixTypeCache()

void SMatrix::dirtyMatrixTypeCache ( )
inline

Testing routine; the matrix's type cache should never need to be manually invalidated during normal use.

Definition at line 905 of file SMatrix.h.

◆ get()

float SMatrix::get ( int index) const
inline

Accesses the matrix element at the specified index.

Parameters
indexIndex of the matrix element.
Returns
Matrix element value.

Definition at line 322 of file SMatrix.h.

◆ GetMapPtsProc()

static MapPtsProc SMatrix::GetMapPtsProc ( TypeMask mask)
inlinestatic

Get the appropriate MapPtsProc for the given type mask.

Parameters
maskType mask of the matrix.
Returns
Pointer to the MapPtsProc function.

Definition at line 815 of file SMatrix.h.

◆ getMapPtsProc()

MapPtsProc SMatrix::getMapPtsProc ( ) const
inline

Get the appropriate MapPtsProc for this matrix.

Returns
Pointer to the MapPtsProc function.

Definition at line 825 of file SMatrix.h.

◆ GetMapXYProc()

static MapXYProc SMatrix::GetMapXYProc ( TypeMask mask)
inlinestatic

Get the appropriate MapXYProc for the given type mask.

Parameters
maskType mask of the matrix.
Returns
Pointer to the MapXYProc function.

Definition at line 789 of file SMatrix.h.

◆ getMapXYProc()

MapXYProc SMatrix::getMapXYProc ( ) const
inline

Get the appropriate MapXYProc for this matrix.

Returns
Pointer to the MapXYProc function.

Definition at line 799 of file SMatrix.h.

◆ getMaxScale()

float SMatrix::getMaxScale ( ) const

Calculates the maximum scaling factor of the matrix as computed from the SVD of the upper left 2x2. If the matrix has perspective -1 is returned.

Returns
Maximum scale factor.

Definition at line 1658 of file SMatrix.cpp.

◆ getMinMaxScales()

bool SMatrix::getMinMaxScales ( float scaleFactors[2]) const

Gets both the min and max scale factors. The min scale factor is scaleFactors[0] and the max is scaleFactors[1]. If the matrix has perspective false will be returned and scaleFactors will be unchanged.

Parameters
scaleFactorsArray to store the min and max scale factors.
Returns
True if the matrix does not have perspective, false otherwise.

Definition at line 1671 of file SMatrix.cpp.

◆ getMinScale()

float SMatrix::getMinScale ( ) const

Calculates the minimum scaling factor of the matrix as computed from the SVD of the upper left 2x2. If the matrix has perspective -1 is returned.

Returns
Minimum scale factor.

Definition at line 1645 of file SMatrix.cpp.

◆ getType()

TypeMask SMatrix::getType ( ) const
inline

Returns a bitfield describing the transformations the matrix may perform. The bitfield is computed conservatively, so it may include false positives. For example, when kPerspective_Mask is true, all other bits may be set to true even in the case of a non-perspective transform.

Returns
Bitfield describing the transformations.

Definition at line 225 of file SMatrix.h.

◆ hasPerspective()

bool SMatrix::hasPerspective ( ) const
inline

Checks if the matrix contains perspective elements.

Returns
True if the matrix has perspective elements, false otherwise.

Definition at line 271 of file SMatrix.h.

◆ I()

const SMatrix & SMatrix::I ( )
static

Return a reference to a const identity matrix.

Returns
Reference to the identity matrix.

Definition at line 1691 of file SMatrix.cpp.

◆ InvalidMatrix()

const SMatrix & SMatrix::InvalidMatrix ( )
static

Return a reference to a const matrix that is "invalid", one that could never be used.

Returns
Reference to the invalid matrix.

Definition at line 1698 of file SMatrix.cpp.

◆ invert()

bool SMatrix::invert ( SMatrix * inverse) const
inline

If this matrix can be inverted, return true and if inverse is not null, set inverse to be the inverse of this matrix. If this matrix cannot be inverted, ignore inverse and return false.

Parameters
inversePointer to the matrix to store the inverse.
Returns
True if the matrix can be inverted, false otherwise.

Definition at line 600 of file SMatrix.h.

◆ isIdentity()

BOOL SMatrix::isIdentity ( )

Checks if the matrix is the identity matrix.

Returns
True if the matrix is identity, false otherwise.

Definition at line 1777 of file SMatrix.cpp.

◆ isScaleTranslate()

bool SMatrix::isScaleTranslate ( ) const
inline

Checks if the matrix contains only scale and translation.

Returns
True if the matrix contains only scale and translation, false otherwise.

Definition at line 239 of file SMatrix.h.

◆ isSimilarity()

bool SMatrix::isSimilarity ( float tol = ( (1.0f) / (1 << 12))) const

Checks if the matrix contains only translation, rotation/reflection, or uniform scale. Returns false if other transformation types are included or if the matrix is degenerate.

Parameters
tolTolerance for floating-point comparison (default is SK_ScalarNearlyZero).
Returns
True if the matrix is a similarity transform, false otherwise.

Definition at line 172 of file SMatrix.cpp.

◆ mapHomogeneousPoints()

void SMatrix::mapHomogeneousPoints ( float dst[],
const float src[],
int count ) const

Apply this matrix to the array of homogeneous points, specified by src, where a homogeneous point is defined by 3 contiguous scalar values, and write the transformed points into the array of scalars specified by dst. dst[] = M * src[].

Parameters
dstWhere the transformed coordinates are written. It must contain at least 3 * count entries.
srcThe original coordinates that are to be transformed. It must contain at least 3 * count entries.
countThe number of triples (homogeneous points) in src to read, and then transform into dst.

Definition at line 1155 of file SMatrix.cpp.

◆ mapPoints() [1/2]

void SMatrix::mapPoints ( SPoint dst[],
const SPoint src[],
int count ) const

Apply this matrix to the array of points specified by src, and write the transformed points into the array of points specified by dst. dst[] = M * src[].

Parameters
dstWhere the transformed coordinates are written. It must contain at least count entries.
srcThe original coordinates that are to be transformed. It must contain at least count entries.
countThe number of points in src to read, and then transform into dst.

Definition at line 1135 of file SMatrix.cpp.

◆ mapPoints() [2/2]

void SMatrix::mapPoints ( SPoint pts[],
int count ) const
inline

Apply this matrix to the array of points, overwriting it with the transformed values. dst[] = M * pts[].

Parameters
ptsThe points to be transformed. It must contain at least count entries.
countThe number of points in pts.

Definition at line 646 of file SMatrix.h.

◆ mapPointsWithStride() [1/2]

void SMatrix::mapPointsWithStride ( SPoint dst[],
SPoint src[],
size_t stride,
int count ) const
inline

Like mapPoints but with custom byte stride between the points.

Parameters
dstArray of transformed points.
srcArray of original points.
strideByte stride between points.
countNumber of points to transform.

Definition at line 676 of file SMatrix.h.

◆ mapPointsWithStride() [2/2]

void SMatrix::mapPointsWithStride ( SPoint pts[],
size_t stride,
int count ) const
inline

Like mapPoints but with custom byte stride between the points. Stride should be a multiple of sizeof(float).

Parameters
ptsArray of points to transform.
strideByte stride between points.
countNumber of points to transform.

Definition at line 658 of file SMatrix.h.

◆ mapRadius()

float SMatrix::mapRadius ( float radius) const

Return the mean radius of a circle after it has been mapped by this matrix. NOTE: in perspective this value assumes the circle has its center at the origin.

Parameters
radiusOriginal radius of the circle.
Returns
Mapped radius of the circle.

Definition at line 1237 of file SMatrix.cpp.

◆ mapRect() [1/2]

bool SMatrix::mapRect ( SRect * dst,
const SRect & src ) const

Apply this matrix to the src rectangle, and write the transformed rectangle into dst. This is accomplished by transforming the 4 corners of src, and then setting dst to the bounds of those points.

Parameters
dstWhere the transformed rectangle is written.
srcThe original rectangle to be transformed.
Returns
The result of calling rectStaysRect().

Definition at line 1216 of file SMatrix.cpp.

◆ mapRect() [2/2]

bool SMatrix::mapRect ( SRect * rect) const
inline

Apply this matrix to the rectangle, and write the transformed rectangle back into it. This is accomplished by transforming the 4 corners of rect, and then setting it to the bounds of those points.

Parameters
rectThe rectangle to transform.
Returns
The result of calling rectStaysRect().

Definition at line 750 of file SMatrix.h.

◆ mapRectToQuad()

void SMatrix::mapRectToQuad ( SPoint dst[4],
const SRect & rect ) const
inline

Apply this matrix to the src rectangle, and write the four transformed points into dst. The points written to dst will be the original top-left, top-right, bottom-right, and bottom-left points transformed by the matrix.

Parameters
dstWhere the transformed quad is written.
rectThe original rectangle to be transformed.

Definition at line 762 of file SMatrix.h.

◆ mapVectors() [1/2]

void SMatrix::mapVectors ( SVector2D dst[],
const SVector2D src[],
int count ) const

Apply this matrix to the array of vectors specified by src, and write the transformed vectors into the array of vectors specified by dst. This is similar to mapPoints, but ignores any translation in the matrix.

Parameters
dstWhere the transformed coordinates are written. It must contain at least count entries.
srcThe original coordinates that are to be transformed. It must contain at least count entries.
countThe number of vectors in src to read, and then transform into dst.

Definition at line 1189 of file SMatrix.cpp.

◆ mapVectors() [2/2]

void SMatrix::mapVectors ( SVector2D vecs[],
int count ) const
inline

Apply this matrix to the array of vectors specified by src, and write the transformed vectors into the array of vectors specified by dst. This is similar to mapPoints, but ignores any translation in the matrix.

Parameters
vecsThe vectors to be transformed. It must contain at least count entries.
countThe number of vectors in vecs.

Definition at line 728 of file SMatrix.h.

◆ mapXY()

void SMatrix::mapXY ( float x,
float y,
SPoint * result ) const
inline

Apply this matrix to the point (x, y) and store the result in *result.

Parameters
xX-coordinate of the point.
yY-coordinate of the point.
resultPointer to store the transformed point.

Definition at line 705 of file SMatrix.h.

◆ operator*()

SMatrix SMatrix::operator* ( const SMatrix & matrix) const

Multiplies the matrix by another matrix.

Parameters
srcThe matrix to multiply with.
Returns
New matrix resulting from the multiplication.

Returns the result of multiplying this matrix by the given matrix.

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

Definition at line 1731 of file SMatrix.cpp.

◆ operator*=()

SMatrix & SMatrix::operator*= ( const SMatrix & matrix)

Multiplies the matrix by another matrix.

Parameters
srcThe matrix to multiply with.
Returns
Reference to the modified matrix.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns the result of multiplying this matrix by the given matrix.

Definition at line 1715 of file SMatrix.cpp.

◆ operator=()

SMatrix & SMatrix::operator= ( const SMatrix & src)

Assignment operator.

Parameters
srcThe matrix to assign from.
Returns
Reference to the modified matrix.

Assigns the given matrix's values to this matrix.

Definition at line 1741 of file SMatrix.cpp.

◆ operator[]() [1/2]

float & SMatrix::operator[] ( int index)
inline

Accesses the matrix element at the specified index.

Parameters
indexIndex of the matrix element.
Returns
Reference to the matrix element.

Definition at line 333 of file SMatrix.h.

◆ operator[]() [2/2]

float SMatrix::operator[] ( int index) const
inline

Accesses the matrix element at the specified index.

Parameters
indexIndex of the matrix element.
Returns
Matrix element value.

Definition at line 311 of file SMatrix.h.

◆ postConcat()

void SMatrix::postConcat ( const SMatrix & other)

Post-concats the matrix with the specified matrix.

Parameters
otherMatrix to post-concatenate.

Definition at line 793 of file SMatrix.cpp.

◆ postIDiv()

bool SMatrix::postIDiv ( int divx,
int divy )

Post-concats the matrix by dividing it by the specified integers.

Parameters
divxDivision factor in the x-direction.
divyDivision factor in the y-direction.
Returns
True if successful, false if either divx or divy is zero.

Definition at line 435 of file SMatrix.cpp.

◆ postRotate() [1/2]

void SMatrix::postRotate ( float degrees)

Post-concats the matrix with the specified rotation.

Parameters
degreesRotation angle in degrees.

Definition at line 548 of file SMatrix.cpp.

◆ postRotate() [2/2]

void SMatrix::postRotate ( float degrees,
float px,
float py )

Post-concats the matrix with the specified rotation.

Parameters
degreesRotation angle in degrees.
pxPivot point x-coordinate.
pyPivot point y-coordinate.

Definition at line 541 of file SMatrix.cpp.

◆ postScale() [1/2]

void SMatrix::postScale ( float sx,
float sy )

Post-concats the matrix with the specified scale.

Parameters
sxScale factor in the x-direction.
syScale factor in the y-direction.

Definition at line 422 of file SMatrix.cpp.

◆ postScale() [2/2]

void SMatrix::postScale ( float sx,
float sy,
float px,
float py )

Post-concats the matrix with the specified scale.

Parameters
sxScale factor in the x-direction.
syScale factor in the y-direction.
pxPivot point x-coordinate.
pyPivot point y-coordinate.

Definition at line 411 of file SMatrix.cpp.

◆ postSkew() [1/2]

void SMatrix::postSkew ( float kx,
float ky )

Post-concats the matrix with the specified skew.

Parameters
kxSkew factor in the x-direction.
kySkew factor in the y-direction.

Definition at line 610 of file SMatrix.cpp.

◆ postSkew() [2/2]

void SMatrix::postSkew ( float kx,
float ky,
float px,
float py )

Post-concats the matrix with the specified skew.

Parameters
kxSkew factor in the x-direction.
kySkew factor in the y-direction.
pxPivot point x-coordinate.
pyPivot point y-coordinate.

Definition at line 603 of file SMatrix.cpp.

◆ postTranslate() [1/2]

void SMatrix::postTranslate ( float dx,
float dy )

Post-concats the matrix with the specified translation.

Parameters
dxTranslation in the x-direction.
dyTranslation in the y-direction.

Definition at line 300 of file SMatrix.cpp.

◆ postTranslate() [2/2]

void SMatrix::postTranslate ( int dx,
int dy )

Post-concats the matrix with the specified translation.

Parameters
dxTranslation in the x-direction.
dyTranslation in the y-direction.

Definition at line 406 of file SMatrix.cpp.

◆ preConcat()

void SMatrix::preConcat ( const SMatrix & other)

Pre-concats the matrix with the specified matrix.

Parameters
otherMatrix to pre-concatenate.

Definition at line 783 of file SMatrix.cpp.

◆ preRotate() [1/2]

void SMatrix::preRotate ( float degrees)

Pre-concats the matrix with the specified rotation.

Parameters
degreesRotation angle in degrees.

Definition at line 534 of file SMatrix.cpp.

◆ preRotate() [2/2]

void SMatrix::preRotate ( float degrees,
float px,
float py )

Pre-concats the matrix with the specified rotation.

Parameters
degreesRotation angle in degrees.
pxPivot point x-coordinate.
pyPivot point y-coordinate.

Definition at line 527 of file SMatrix.cpp.

◆ preScale() [1/2]

void SMatrix::preScale ( float sx,
float sy )

Pre-concats the matrix with the specified scale.

Parameters
sxScale factor in the x-direction.
syScale factor in the y-direction.

Definition at line 383 of file SMatrix.cpp.

◆ preScale() [2/2]

void SMatrix::preScale ( float sx,
float sy,
float px,
float py )

Pre-concats the matrix with the specified scale.

Parameters
sxScale factor in the x-direction.
syScale factor in the y-direction.
pxPivot point x-coordinate.
pyPivot point y-coordinate.

Definition at line 371 of file SMatrix.cpp.

◆ preservesAxisAlignment()

bool SMatrix::preservesAxisAlignment ( ) const
inline

Alias for rectStaysRect().

Returns
True if the matrix preserves rectangle shape, false otherwise.

Definition at line 262 of file SMatrix.h.

◆ preservesRightAngles()

bool SMatrix::preservesRightAngles ( float tol = ( (1.0f) / (1 << 12))) const

Checks if the matrix contains only translation, rotation/reflection, or scale (non-uniform scale is allowed). Returns false if other transformation types are included or if the matrix is degenerate.

Parameters
tolTolerance for floating-point comparison (default is SK_ScalarNearlyZero).
Returns
True if the matrix preserves right angles, false otherwise.

Definition at line 205 of file SMatrix.cpp.

◆ preSkew() [1/2]

void SMatrix::preSkew ( float kx,
float ky )

Pre-concats the matrix with the specified skew.

Parameters
kxSkew factor in the x-direction.
kySkew factor in the y-direction.

Definition at line 596 of file SMatrix.cpp.

◆ preSkew() [2/2]

void SMatrix::preSkew ( float kx,
float ky,
float px,
float py )

Pre-concats the matrix with the specified skew.

Parameters
kxSkew factor in the x-direction.
kySkew factor in the y-direction.
pxPivot point x-coordinate.
pyPivot point y-coordinate.

Definition at line 589 of file SMatrix.cpp.

◆ preTranslate() [1/2]

void SMatrix::preTranslate ( float dx,
float dy )

Pre-concats the matrix with the specified translation.

Parameters
dxTranslation in the x-direction.
dyTranslation in the y-direction.

Definition at line 274 of file SMatrix.cpp.

◆ preTranslate() [2/2]

void SMatrix::preTranslate ( int dx,
int dy )

Pre-concats the matrix with the specified translation.

Parameters
dxTranslation in the x-direction.
dyTranslation in the y-direction.

Definition at line 295 of file SMatrix.cpp.

◆ rectStaysRect()

bool SMatrix::rectStaysRect ( ) const
inline

Returns true if the matrix will map a rectangle to another rectangle. This can be true if the matrix is identity, scale-only, or rotates a multiple of 90 degrees.

Returns
True if the matrix preserves rectangle shape, false otherwise.

Definition at line 249 of file SMatrix.h.

◆ reset()

void SMatrix::reset ( )

Resets the matrix to the identity matrix.

Definition at line 46 of file SMatrix.cpp.

◆ rotate()

SMatrix & SMatrix::rotate ( float deg)
inline

Post-concats the matrix with a rotation.

Parameters
degRotation angle in degrees.
Returns
Reference to the modified matrix.

Definition at line 121 of file SMatrix.h.

◆ scale()

SMatrix & SMatrix::scale ( float sx,
float sy )
inline

Post-concats the matrix with a scale.

Parameters
sxScale factor in the x-direction.
syScale factor in the y-direction.
Returns
Reference to the modified matrix.

Definition at line 98 of file SMatrix.h.

◆ set()

void SMatrix::set ( int index,
float value )
inline

Sets the matrix element at the specified index.

Parameters
indexIndex of the matrix element.
valueNew value for the matrix element.

Definition at line 345 of file SMatrix.h.

◆ SetAffineIdentity()

void SMatrix::SetAffineIdentity ( float affine[6])
static

Fills the passed array with affine identity values in column major order.

Parameters
affineArray to fill with affine identity values. Must not be NULL.

Definition at line 849 of file SMatrix.cpp.

◆ setConcat()

void SMatrix::setConcat ( const SMatrix & a,
const SMatrix & b )

Sets the matrix to the concatenation of the two specified matrices.

Parameters
aFirst matrix.
bSecond matrix.

Definition at line 724 of file SMatrix.cpp.

◆ setIdentity()

void SMatrix::setIdentity ( )

Sets the matrix to the identity matrix.

Definition at line 1767 of file SMatrix.cpp.

◆ setIDiv()

bool SMatrix::setIDiv ( int divx,
int divy )

Sets the matrix to scale by 1/divx and 1/divy.

Parameters
divxDivision factor in the x-direction.
divyDivision factor in the y-direction.
Returns
True if successful, false if either divx or divy is zero.

Definition at line 361 of file SMatrix.cpp.

◆ setMatrix()

void SMatrix::setMatrix ( const float data[9],
int matType = kUnknown_Mask )

Sets the matrix to the specified data array.

Parameters
dataArray of 9 floats representing the matrix elements.
matTypeType mask for the matrix (default is kUnknown_Mask).

Definition at line 1761 of file SMatrix.cpp.

◆ setPolyToPoly()

bool SMatrix::setPolyToPoly ( const SPoint src[],
const SPoint dst[],
int count )

Set the matrix such that the specified src points would map to the specified dst points. count must be within [0..4].

Parameters
srcArray of source points.
dstArray of destination points.
countNumber of points to use for the transformation.
Returns
True if the matrix was set to the specified transformation.

Definition at line 1490 of file SMatrix.cpp.

◆ setRectToRect()

bool SMatrix::setRectToRect ( const SRect & src,
const SRect & dst,
ScaleToFit stf )

Set the matrix to the scale and translate values that map the source rectangle to the destination rectangle, returning true if the result can be represented.

Parameters
srcSource rectangle to map from.
dstDestination rectangle to map to.
stfScaleToFit option.
Returns
True if the matrix can be represented by the rectangle mapping.

Definition at line 619 of file SMatrix.cpp.

◆ setRotate()

void SMatrix::setRotate ( float degrees)

Sets the matrix to a rotation.

Parameters
degreesRotation angle in degrees.

Definition at line 520 of file SMatrix.cpp.

◆ setRotate2()

void SMatrix::setRotate2 ( float degrees,
float px,
float py )

Sets the matrix to a rotation with pivot point.

Parameters
degreesRotation angle in degrees.
pxPivot point x-coordinate.
pyPivot point y-coordinate.

Definition at line 513 of file SMatrix.cpp.

◆ setScale()

void SMatrix::setScale ( float sx,
float sy )

Sets the matrix to a scale.

Parameters
sxScale factor in the x-direction.
syScale factor in the y-direction.

Definition at line 343 of file SMatrix.cpp.

◆ setScale2()

void SMatrix::setScale2 ( float sx,
float sy,
float px,
float py )

Sets the matrix to a scale with pivot point.

Parameters
sxScale factor in the x-direction.
syScale factor in the y-direction.
pxPivot point x-coordinate.
pyPivot point y-coordinate.

Definition at line 323 of file SMatrix.cpp.

◆ setSinCos() [1/2]

void SMatrix::setSinCos ( float sinValue,
float cosValue )

Sets the matrix to rotate by the specified sine and cosine values.

Parameters
sinValueSine of the rotation angle.
cosValueCosine of the rotation angle.

Definition at line 497 of file SMatrix.cpp.

◆ setSinCos() [2/2]

void SMatrix::setSinCos ( float sinValue,
float cosValue,
float px,
float py )

Sets the matrix to rotate by the specified sine and cosine values, with a pivot point at (px, py).

Parameters
sinValueSine of the rotation angle.
cosValueCosine of the rotation angle.
pxPivot point x-coordinate.
pyPivot point y-coordinate.

Definition at line 459 of file SMatrix.cpp.

◆ setSkew()

void SMatrix::setSkew ( float kx,
float ky )

Sets the matrix to a skew.

Parameters
kxSkew factor in the x-direction.
kySkew factor in the y-direction.

Definition at line 573 of file SMatrix.cpp.

◆ setSkew2()

void SMatrix::setSkew2 ( float kx,
float ky,
float px,
float py )

Sets the matrix to a skew with pivot point.

Parameters
kxSkew factor in the x-direction.
kySkew factor in the y-direction.
pxPivot point x-coordinate.
pyPivot point y-coordinate.

Definition at line 557 of file SMatrix.cpp.

◆ setTranslate() [1/2]

void SMatrix::setTranslate ( const SVector2D & v)
inline

Sets the matrix to a translation.

Parameters
vTranslation vector.

Definition at line 363 of file SMatrix.h.

◆ setTranslate() [2/2]

void SMatrix::setTranslate ( float dx,
float dy )

Sets the matrix to a translation.

Parameters
dxTranslation in the x-direction.
dyTranslation in the y-direction.

Definition at line 256 of file SMatrix.cpp.

◆ SFloatSinCos()

float SMatrix::SFloatSinCos ( float radians,
float * cosValue )
static

Definition at line 477 of file SMatrix.cpp.

◆ shear()

SMatrix & SMatrix::shear ( float sh,
float sv )
inline

Post-concats the matrix with a shear.

Parameters
shShear factor in the x-direction.
svShear factor in the y-direction.
Returns
Reference to the modified matrix.

Definition at line 110 of file SMatrix.h.

◆ translate()

SMatrix & SMatrix::translate ( float dx,
float dy )
inline

Post-concats the matrix with a translation.

Parameters
dxTranslation in the x-direction.
dyTranslation in the y-direction.
Returns
Reference to the modified matrix.

Definition at line 86 of file SMatrix.h.

Friends And Related Symbol Documentation

◆ operator!=

bool operator!= ( const SMatrix & a,
const SMatrix & b )
friend

Inequality operator.

Parameters
aFirst matrix.
bSecond matrix.
Returns
True if matrices are not equal, false otherwise.

Definition at line 74 of file SMatrix.h.

◆ operator==

bool operator== ( const SMatrix & a,
const SMatrix & b )
friend

Equality operator.

Parameters
aFirst matrix.
bSecond matrix.
Returns
True if matrices are equal, false otherwise.

Definition at line 153 of file SMatrix.cpp.

◆ SkPerspIter

friend class SkPerspIter
friend

Definition at line 995 of file SMatrix.h.


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