SkMatrix Reference

Matrix

Class SkMatrix

Constant

SkMatrix related constants are defined by enum, enum class, #define, const, and constexpr.

Topic Description
ScaleToFit options to map Rects
TypeMask bit field for Matrix complexity
kAScaleX horizontal scale factor
kAScaleY vertical scale factor
kASkewX horizontal skew factor
kASkewY vertical skew factor
kATransX horizontal translation
kATransY vertical translation
kAffine Mask skew or rotate Matrix
kCenter ScaleToFit scales and aligns to center
kEnd ScaleToFit scales and aligns to right and bottom
kFill ScaleToFit scales in x and y to fill destination Rect
kIdentity Mask identity Matrix; all bits clear
kMPersp0 input x perspective factor
kMPersp1 input y perspective factor
kMPersp2 perspective bias
kMScaleX horizontal scale factor
kMScaleY vertical scale factor
kMSkewX horizontal skew factor
kMSkewY vertical skew factor
kMTransX horizontal translation
kMTransY vertical translation
kPerspective Mask perspective Matrix
kScale Mask scale Matrix
kStart ScaleToFit scales and aligns to left and top
kTranslate Mask translation Matrix
Matrix holds a 3x3 matrix for transforming coordinates. This allows mapping Points and Vectors with translation, scaling, skewing, rotation, and perspective.

Matrix elements are in row major order. Matrix does not have a constructor, so it must be explicitly initialized. setIdentity initializes Matrix so it has no effect. setTranslate, setScale, setSkew, setRotate, set9 and setAll initializes all Matrix elements with the corresponding mapping.

Matrix includes a hidden variable that classifies the type of matrix to improve performance. Matrix is not thread safe unless getType is called first.

Overview

Topic Description
Constants enum and enum class, and their const values
Constructors functions that construct SkMatrix
Functions global and class member functions
Operators operator overloading methods
Related Functions similar member functions grouped together

Member Function

SkMatrix member functions read and modify the structure properties.

Topic Description
Concat returns the concatenation of Matrix pair
I returns a reference to a const identity Matrix
InvalidMatrix returns a reference to a const invalid Matrix
MakeAll constructs all nine values
MakeRectToRect constructs from source Rect to destination Rect
MakeScale constructs from scale in x and y
MakeTrans constructs from translate in x and y
SetAffineIdentity sets 3x2 array to identity
asAffine copies to 3x2 array
cheapEqualTo compares Matrix pair using memcmp()
decomposeScale separates scale if possible
dirtyMatrixTypeCache sets internal cache to unknown state
dump sends text representation using floats to standard output
fixedStepInX returns step in x for a position in y
get returns one of nine Matrix values
get9 returns all nine Matrix values
getMaxScale returns maximum scaling, if possible
getMinMaxScales returns minimum and maximum scaling, if possible
getMinScale returns minimum scaling, if possible
getPerspX returns input x perspective factor
getPerspY returns input y perspective factor
getScaleX returns horizontal scale factor
getScaleY returns vertical scale factor
getSkewX returns horizontal skew factor
getSkewY returns vertical skew factor
getTranslateX returns horizontal translation
getTranslateY returns vertical translation
getType returns transform complexity
hasPerspective returns if transform includes perspective
invert returns inverse, if possible
isFinite returns if all Matrix values are not infinity, NaN
isFixedStepInX returns if transformation supports fixed step in x
isIdentity returns if matrix equals the identity Matrix
isScaleTranslate returns if transform is limited to scale and translate
isSimilarity returns if transform is limited to square scale and rotation
isTranslate returns if transform is limited to translate
mapHomogeneousPoints maps Point3 array
mapPoints maps Point array
mapRadius returns mean radius of mapped Circle
mapRect returns bounds of mapped Rect
mapRectScaleTranslate returns bounds of mapped Rect
mapRectToQuad maps Rect to Point array
mapVector maps Vector
mapVectors maps Vector array
mapXY maps Point
postConcat post-multiplies Matrix by Matrix parameter
postIDiv post-multiplies Matrix by inverse scale
postRotate post-multiplies Matrix by rotation
postScale post-multiplies Matrix by scale
postSkew post-multiplies Matrix by skew
postTranslate post-multiplies Matrix by translation
preConcat pre-multiplies Matrix by Matrix parameter
preRotate pre-multiplies Matrix by rotation
preScale pre-multiplies Matrix by scale
preSkew pre-multiplies Matrix by skew
preTranslate pre-multiplies Matrix by translation
preservesAxisAlignment returns if mapping restricts to 90 degree multiples and mirroring
preservesRightAngles returns if mapped 90 angle remains 90 degrees
rectStaysRect returns if mapped Rect can be represented by another Rect
reset sets Matrix to identity
set sets one value
set9 sets all values from Scalar array
setAffine sets left two columns
setAll sets all values from parameters
setConcat sets to Matrix parameter multiplied by Matrix parameter
setIdentity sets Matrix to identity
setPerspX sets input x perspective factor
setPerspY sets input y perspective factor
setPolyToPoly sets to map one to four points to an equal array of points
setRSXform sets to rotate, scale, and translate
setRectToRect sets to map one Rect to another
setRotate sets to rotate about a point
setScale sets to scale about a point
setScaleTranslate sets to scale and translate
setScaleX sets horizontal scale factor
setScaleY sets vertical scale factor
setSinCos sets to rotate and scale about a point
setSkew sets to skew about a point
setSkewX sets horizontal skew factor
setSkewY sets vertical skew factor
setTranslate sets to translate in x and y
setTranslateX sets horizontal translation
setTranslateY sets vertical translation

Related Function

SkMatrix global, struct, and class related member functions share a topic.

Topic Description
AffineIndex affine member indices
MemberIndex member indices
Property values and attributes
Set sets one or more matrix values
Transform map points with Matrix
Utility rarely called management functions

Constructor

SkMatrix can be constructed or initialized by these functions, including C++ class constructors.

Topic Description
I returns a reference to a const identity Matrix
InvalidMatrix returns a reference to a const invalid Matrix
MakeAll constructs all nine values
MakeRectToRect constructs from source Rect to destination Rect
MakeScale constructs from scale in x and y
MakeScale(SkScalar sx, SkScalar sy)
MakeScale(SkScalar scale)
MakeTrans constructs from translate in x and y
SetAffineIdentity sets 3x2 array to identity
asAffine copies to 3x2 array
reset sets Matrix to identity
setAffine sets left two columns
setConcat sets to Matrix parameter multiplied by Matrix parameter
setIdentity sets Matrix to identity
setRSXform sets to rotate, scale, and translate
setRotate sets to rotate about a point
setRotate(SkScalar degrees, SkScalar px, SkScalar py)
setRotate(SkScalar degrees)
setScale sets to scale about a point
setScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
setScale(SkScalar sx, SkScalar sy)
setScaleTranslate sets to scale and translate
setSinCos sets to rotate and scale about a point
setSinCos(SkScalar sinValue, SkScalar cosValue, SkScalar px, SkScalar py)
setSinCos(SkScalar sinValue, SkScalar cosValue)
setSkew sets to skew about a point
setSkew(SkScalar kx, SkScalar ky, SkScalar px, SkScalar py)
setSkew(SkScalar kx, SkScalar ky)
setTranslate sets to translate in x and y
setTranslate(SkScalar dx, SkScalar dy)
setTranslate(const SkVector& v)

MakeScale

static SkMatrix SK_WARN_UNUSED_RESULT MakeScale(SkScalar sx, SkScalar sy)

Sets Matrix to scale by (sx, sy). Returned matrix is:

| sx  0  0 |
|  0 sy  0 |
|  0  0  1 |

Parameters

sx horizontal scale factor
sy vertical scale factor

Return Value

Matrix with scale

Example

See Also

setScale[2] postScale[2] preScale[2]


static SkMatrix SK_WARN_UNUSED_RESULT MakeScale(SkScalar scale)

Sets Matrix to scale by (scale, scale). Returned matrix is:

| scale   0   0 |
|   0   scale 0 |
|   0     0   1 |

Parameters

scale horizontal and vertical scale factor

Return Value

Matrix with scale

Example

See Also

setScale[2] postScale[2] preScale[2]


MakeTrans

static SkMatrix SK_WARN_UNUSED_RESULT MakeTrans(SkScalar dx, SkScalar dy)

Sets Matrix to translate by (dx, dy). Returned matrix is:

| 1 0 dx |
| 0 1 dy |
| 0 0  1 |

Parameters

dx horizontal translation
dy vertical translation

Return Value

Matrix with translation

Example

See Also

setTranslate[2] postTranslate preTranslate


MakeAll

static SkMatrix SK_WARN_UNUSED_RESULT MakeAll(SkScalar scaleX, SkScalar skewX, SkScalar transX,
                                              SkScalar skewY, SkScalar scaleY, SkScalar transY,
                                              SkScalar pers0, SkScalar pers1, SkScalar pers2)

Sets Matrix to:

| scaleX  skewX transX |
|  skewY scaleY transY |
|  pers0  pers1  pers2 |

Parameters

scaleX horizontal scale factor
skewX horizontal skew factor
transX horizontal translation
skewY vertical skew factor
scaleY vertical scale factor
transY vertical translation
pers0 input x-axis perspective factor
pers1 input y-axis perspective factor
pers2 perspective scale factor

Return Value

Matrix constructed from parameters

Example

See Also

setAll set9 postConcat preConcat


Enum SkMatrix::TypeMask

    enum TypeMask {
        kIdentity Mask = 0,
        kTranslate Mask = 0x01,
        kScale Mask = 0x02,
        kAffine Mask = 0x04,
        kPerspective Mask = 0x08,
    };

Enum of bit fields for mask returned by getType. Used to identify the complexity of Matrix, to optimize performance.

Constants

Const Value Description
SkMatrix::kIdentity_Mask 0 all bits clear if Matrix is identity
SkMatrix::kTranslate_Mask 1 set if Matrix has translation
SkMatrix::kScale_Mask 2 set if Matrix has x or y scale
SkMatrix::kAffine_Mask 4 set if Matrix skews or rotates
SkMatrix::kPerspective_Mask 8 set if Matrix has perspective

Example

#### Example Output ~~~~ after reset: kIdentity_Mask after postTranslate: kTranslate_Mask after postScale: kTranslate_Mask kScale_Mask after postScale: kTranslate_Mask kScale_Mask kAffine_Mask after setPolyToPoly: kTranslate_Mask kScale_Mask kAffine_Mask kPerspective_Mask ~~~~

See Also

getType

Property

Topic Description
decomposeScale separates scale if possible
fixedStepInX returns step in x for a position in y
get returns one of nine Matrix values
get9 returns all nine Matrix values
getMaxScale returns maximum scaling, if possible
getMinMaxScales returns minimum and maximum scaling, if possible
getMinScale returns minimum scaling, if possible
getPerspX returns input x perspective factor
getPerspY returns input y perspective factor
getScaleX returns horizontal scale factor
getScaleY returns vertical scale factor
getSkewX returns horizontal skew factor
getSkewY returns vertical skew factor
getTranslateX returns horizontal translation
getTranslateY returns vertical translation
getType returns transform complexity
hasPerspective returns if transform includes perspective
isFinite returns if all Matrix values are not infinity, NaN
isFixedStepInX returns if transformation supports fixed step in x
isIdentity returns if matrix equals the identity Matrix
isScaleTranslate returns if transform is limited to scale and translate
isSimilarity returns if transform is limited to square scale and rotation
isTranslate returns if transform is limited to translate
preservesAxisAlignment returns if mapping restricts to 90 degree multiples and mirroring
preservesRightAngles returns if mapped 90 angle remains 90 degrees
rectStaysRect returns if mapped Rect can be represented by another Rect

getType

TypeMask getType() const

Returns a bit field describing the transformations the matrix may perform. The bit field is computed conservatively, so it may include false positives. For example, when kPerspective Mask is set, all other bits are set.

Return Value

kIdentity Mask, or combinations of: kTranslate Mask, kScale Mask, kAffine Mask, kPerspective Mask

Example

#### Example Output ~~~~ identity flags hex: 0 decimal: 0 set all flags hex: f decimal: 15 ~~~~

See Also

TypeMask


isIdentity

bool isIdentity() const

Returns true if Matrix is identity. Identity matrix is:

| 1 0 0 |
| 0 1 0 |
| 0 0 1 |

Return Value

true if Matrix has no effect

Example

#### Example Output ~~~~ is identity: true is identity: false ~~~~

See Also

reset setIdentity getType


isScaleTranslate

bool isScaleTranslate() const

Returns true if Matrix at most scales and translates. Matrix may be identity, contain only scale elements, only translate elements, or both. Matrix form is:

| scale-x    0    translate-x |
|    0    scale-y translate-y |
|    0       0         1      |

Return Value

true if Matrix is identity; or scales, translates, or both

Example

#### Example Output ~~~~ is scale-translate: true is scale-translate: true is scale-translate: true is scale-translate: true ~~~~

See Also

setScale[2] isTranslate setTranslate[2] getType


isTranslate

bool isTranslate() const

Returns true if Matrix is identity, or translates. Matrix form is:

| 1 0 translate-x |
| 0 1 translate-y |
| 0 0      1      |

Return Value

true if Matrix is identity, or translates

Example

#### Example Output ~~~~ is translate: true is translate: true is translate: false is translate: false ~~~~

See Also

setTranslate[2] getType


rectStaysRect

bool rectStaysRect() const

Returns true Matrix maps Rect to another Rect. If true, Matrix is identity, or scales, or rotates a multiple of 90 degrees, or mirrors on axes. In all cases, Matrix may also have translation. Matrix form is either:

| scale-x    0    translate-x |
|    0    scale-y translate-y |
|    0       0         1      |

or

|    0     rotate-x translate-x |
| rotate-y    0     translate-y |
|    0        0          1      |

for non-zero values of scale-x, scale-y, rotate-x, and rotate-y.

Also called preservesAxisAlignment; use the one that provides better inline documentation.

Return Value

true if Matrix maps one Rect into another

Example

#### Example Output ~~~~ rectStaysRect: true rectStaysRect: true rectStaysRect: true rectStaysRect: true ~~~~

See Also

preservesAxisAlignment preservesRightAngles


preservesAxisAlignment

bool preservesAxisAlignment() const

Returns true Matrix maps Rect to another Rect. If true, Matrix is identity, or scales, or rotates a multiple of 90 degrees, or mirrors on axes. In all cases, Matrix may also have translation. Matrix form is either:

| scale-x    0    translate-x |
|    0    scale-y translate-y |
|    0       0         1      |

or

|    0     rotate-x translate-x |
| rotate-y    0     translate-y |
|    0        0          1      |

for non-zero values of scale-x, scale-y, rotate-x, and rotate-y.

Also called rectStaysRect; use the one that provides better inline documentation.

Return Value

true if Matrix maps one Rect into another

Example

#### Example Output ~~~~ preservesAxisAlignment: true preservesAxisAlignment: true preservesAxisAlignment: true preservesAxisAlignment: true ~~~~

See Also

rectStaysRect preservesRightAngles


hasPerspective

bool hasPerspective() const

Returns true if the matrix contains perspective elements. Matrix form is:

|       --            --              --          |
|       --            --              --          |
| perspective-x  perspective-y  perspective-scale |

where perspective-x or perspective-y is non-zero, or perspective-scale is not one. All other elements may have any value.

Return Value

true if Matrix is in most general form

Example

See Also

setAll set9 MakeAll


isSimilarity

bool isSimilarity(SkScalar tol = SK ScalarNearlyZero) const

Returns true if Matrix contains only translation, rotation, reflection, and uniform scale. Returns false if Matrix contains different scales, skewing, perspective, or degenerate forms that collapse to a line or point.

Describes that the Matrix makes rendering with and without the matrix are visually alike; a transformed circle remains a circle. Mathematically, this is referred to as similarity of a Euclidean Space, or a similarity transformation.

Preserves right angles, keeping the arms of the angle equal lengths.

Parameters

tol to be deprecated

Return Value

true if Matrix only rotates, uniformly scales, translates

Example

String is drawn four times through but only two are visible. Drawing the pair with isSimilarity false reveals the pair not visible through the matrix.

See Also

isScaleTranslate preservesRightAngles rectStaysRect isFixedStepInX


preservesRightAngles

bool preservesRightAngles(SkScalar tol = SK ScalarNearlyZero) const

Returns true if Matrix contains only translation, rotation, reflection, and scale. Scale may differ along rotated axes. Returns false if Matrix skewing, perspective, or degenerate forms that collapse to a line or point.

Preserves right angles, but not requiring that the arms of the angle retain equal lengths.

Parameters

tol to be deprecated

Return Value

true if Matrix only rotates, scales, translates

Example

Equal scale is both similar and preserves right angles. Unequal scale is not similar but preserves right angles. Skews are not similar and do not preserve right angles.

See Also

isScaleTranslate isSimilarity rectStaysRect isFixedStepInX


MemberIndex

Constants

Const Value Description
SkMatrix::kMScaleX 0 horizontal scale factor
SkMatrix::kMSkewX 1 horizontal skew factor
SkMatrix::kMTransX 2 horizontal translation
SkMatrix::kMSkewY 3 vertical skew factor
SkMatrix::kMScaleY 4 vertical scale factor
SkMatrix::kMTransY 5 vertical translation
SkMatrix::kMPersp0 6 input x perspective factor
SkMatrix::kMPersp1 7 input y perspective factor
SkMatrix::kMPersp2 8 perspective bias
    static constexpr int kMScaleX = 0;
    static constexpr int kMSkewX  = 1;
    static constexpr int kMTransX = 2;
    static constexpr int kMSkewY  = 3;
    static constexpr int kMScaleY = 4;
    static constexpr int kMTransY = 5;
    static constexpr int kMPersp0 = 6;
    static constexpr int kMPersp1 = 7;
    static constexpr int kMPersp2 = 8;

Matrix organizes its values in row order. These members correspond to each value in Matrix.

Constants

Const Value Description
SkMatrix::kMScaleX 0 horizontal scale factor
SkMatrix::kMSkewX 1 horizontal skew factor
SkMatrix::kMTransX 2 horizontal translation
SkMatrix::kMSkewY 3 vertical skew factor
SkMatrix::kMScaleY 4 vertical scale factor
SkMatrix::kMTransY 5 vertical translation
SkMatrix::kMPersp0 6 input x perspective factor
SkMatrix::kMPersp1 7 input y perspective factor
SkMatrix::kMPersp2 8 perspective bias

Example

See Also

get set

AffineIndex

Constants

Const Value Description
SkMatrix::kAScaleX 0 horizontal scale factor
SkMatrix::kASkewY 1 vertical skew factor
SkMatrix::kASkewX 2 horizontal skew factor
SkMatrix::kAScaleY 3 vertical scale factor
SkMatrix::kATransX 4 horizontal translation
SkMatrix::kATransY 5 vertical translation
    static constexpr int kAScaleX = 0;
    static constexpr int kASkewY  = 1;
    static constexpr int kASkewX  = 2;
    static constexpr int kAScaleY = 3;
    static constexpr int kATransX = 4;
    static constexpr int kATransY = 5;

Affine arrays are in column major order to match the matrix used by PDF and XPS.

Constants

Const Value Description
SkMatrix::kAScaleX 0 horizontal scale factor
SkMatrix::kASkewY 1 vertical skew factor
SkMatrix::kASkewX 2 horizontal skew factor
SkMatrix::kAScaleY 3 vertical scale factor
SkMatrix::kATransX 4 horizontal translation
SkMatrix::kATransY 5 vertical translation

See Also

SetAffineIdentity asAffine setAffine

Operator

SkMatrix operators inline class member functions with arithmetic equivalents.

Topic Description
Concat returns the concatenation of Matrix pair
cheapEqualTo compares Matrix pair using memcmp()
invert returns inverse, if possible
operator!=(const SkMatrix& a, const SkMatrix& b) returns true if members are unequal
operator==(const SkMatrix& a, const SkMatrix& b) returns true if members are equal
operator[](int index) returns writable reference to Matrix value
operator[](int index) const returns Matrix value

operator[]

SkScalar operator[](int index) _const

Returns one matrix value. Asserts if index is out of range and SK_DEBUG is defined.

Parameters

index one of: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY, kMPersp0, kMPersp1, kMPersp2

Return Value

value corresponding to index

Example

#### Example Output ~~~~ matrix[SkMatrix::kMScaleX] == 42 matrix[SkMatrix::kMScaleY] == 24 ~~~~

See Also

get set


get

SkScalar get(int index) const

Returns one matrix value. Asserts if index is out of range and SK_DEBUG is defined.

Parameters

index one of: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY, kMPersp0, kMPersp1, kMPersp2

Return Value

value corresponding to index

Example

#### Example Output ~~~~ matrix.get(SkMatrix::kMSkewX) == 42 matrix.get(SkMatrix::kMSkewY) == 24 ~~~~

See Also

operator[](int index) set


getScaleX

SkScalar getScaleX() const

Returns scale factor multiplied by x-axis input, contributing to x-axis output. With mapPoints, scales Points along the x-axis.

Return Value

horizontal scale factor

Example

#### Example Output ~~~~ matrix.getScaleX() == 42 ~~~~

See Also

get getScaleY setScaleX setScale[2]


getScaleY

SkScalar getScaleY() const

Returns scale factor multiplied by y-axis input, contributing to y-axis output. With mapPoints, scales Points along the y-axis.

Return Value

vertical scale factor

Example

#### Example Output ~~~~ matrix.getScaleY() == 24 ~~~~

See Also

get getScaleX setScaleY setScale[2]


getSkewY

SkScalar getSkewY() const

Returns scale factor multiplied by x-axis input, contributing to y-axis output. With mapPoints, skews Points along the y-axis. Skewing both axes can rotate Points.

Return Value

vertical skew factor

Example

#### Example Output ~~~~ matrix.getSkewY() == 24 ~~~~

See Also

get getSkewX setSkewY setSkew[2]


getSkewX

SkScalar getSkewX() const

Returns scale factor multiplied by y-axis input, contributing to x-axis output. With mapPoints, skews Points along the x-axis. Skewing both axes can rotate Points.

Return Value

horizontal scale factor

Example

#### Example Output ~~~~ matrix.getSkewX() == 42 ~~~~

See Also

get getSkewY setSkewX setSkew[2]


getTranslateX

SkScalar getTranslateX() const

Returns translation contributing to x-axis output. With mapPoints, moves Points along the x-axis.

Return Value

horizontal translation factor

Example

#### Example Output ~~~~ matrix.getTranslateX() == 42 ~~~~

See Also

get getTranslateY setTranslateX setTranslate[2]


getTranslateY

SkScalar getTranslateY() const

Returns translation contributing to y-axis output. With mapPoints, moves Points along the y-axis.

Return Value

vertical translation factor

Example

#### Example Output ~~~~ matrix.getTranslateY() == 24 ~~~~

See Also

get getTranslateX setTranslateY setTranslate[2]


getPerspX

SkScalar getPerspX() const

Returns factor scaling input x-axis relative to input y-axis.

Return Value

input x-axis perspective factor

Example

See Also

kMPersp0 getPerspY


getPerspY

SkScalar getPerspY() const

Returns factor scaling input y-axis relative to input x-axis.

Return Value

input y-axis perspective factor

Example

See Also

kMPersp1 getPerspX


operator[]

SkScalar& operator[](int index)

Returns writable Matrix value. Asserts if index is out of range and SK_DEBUG is defined. Clears internal cache anticipating that caller will change Matrix value.

Next call to read Matrix state may recompute cache; subsequent writes to Matrix value must be followed by dirtyMatrixTypeCache.

Parameters

index one of: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY, kMPersp0, kMPersp1, kMPersp2

Return Value

writable value corresponding to index

Example

#### Example Output ~~~~ with identity matrix: x = 24 after skew x mod: x = 24 after 2nd skew x mod: x = 24 after dirty cache: x = 66 ~~~~

See Also

get dirtyMatrixTypeCache set


Set

Topic Description
postConcat post-multiplies Matrix by Matrix parameter
postIDiv post-multiplies Matrix by inverse scale
postRotate post-multiplies Matrix by rotation
postRotate(SkScalar degrees, SkScalar px, SkScalar py)
postRotate(SkScalar degrees)
postScale post-multiplies Matrix by scale
postScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
postScale(SkScalar sx, SkScalar sy)
postSkew post-multiplies Matrix by skew
postSkew(SkScalar kx, SkScalar ky, SkScalar px, SkScalar py)
postSkew(SkScalar kx, SkScalar ky)
postTranslate post-multiplies Matrix by translation
preConcat pre-multiplies Matrix by Matrix parameter
preRotate pre-multiplies Matrix by rotation
preRotate(SkScalar degrees, SkScalar px, SkScalar py)
preRotate(SkScalar degrees)
preScale pre-multiplies Matrix by scale
preScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
preScale(SkScalar sx, SkScalar sy)
preSkew pre-multiplies Matrix by skew
preSkew(SkScalar kx, SkScalar ky, SkScalar px, SkScalar py)
preSkew(SkScalar kx, SkScalar ky)
preTranslate pre-multiplies Matrix by translation
set sets one value
set9 sets all values from Scalar array
setAll sets all values from parameters
setPerspX sets input x perspective factor
setPerspY sets input y perspective factor
setPolyToPoly sets to map one to four points to an equal array of points
setRectToRect sets to map one Rect to another
setScaleX sets horizontal scale factor
setScaleY sets vertical scale factor
setSkewX sets horizontal skew factor
setSkewY sets vertical skew factor
setTranslateX sets horizontal translation
setTranslateY sets vertical translation

set

void set(int index, SkScalar value)

Sets Matrix value. Asserts if index is out of range and SK_DEBUG is defined. Safer than operator[]; internal cache is always maintained.

Parameters

index one of: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY, kMPersp0, kMPersp1, kMPersp2
value Scalar to store in Matrix

Example

#### Example Output ~~~~ with identity matrix: x = 24 after skew x mod: x = 24 after 2nd skew x mod: x = 66 ~~~~

See Also

operator[] get


setScaleX

void setScaleX(SkScalar v)

Sets horizontal scale factor.

Parameters

v horizontal scale factor to store

Example

See Also

set setScale[2] setScaleY


setScaleY

void setScaleY(SkScalar v)

Sets vertical scale factor.

Parameters

v vertical scale factor to store

Example

See Also

set setScale[2] setScaleX


setSkewY

void setSkewY(SkScalar v)

Sets vertical skew factor.

Parameters

v vertical skew factor to store

Example

See Also

set setSkew[2] setSkewX


setSkewX

void setSkewX(SkScalar v)

Sets horizontal skew factor.

Parameters

v horizontal skew factor to store

Example

See Also

set setSkew[2] setSkewX


setTranslateX

void setTranslateX(SkScalar v)

Sets horizontal translation.

Parameters

v horizontal translation to store

Example

See Also

set setTranslate[2] setTranslateY


setTranslateY

void setTranslateY(SkScalar v)

Sets vertical translation.

Parameters

v vertical translation to store

Example

See Also

set setTranslate[2] setTranslateX


setPerspX

void setPerspX(SkScalar v)

Sets input x-axis perspective factor, which causes mapXY to vary input x-axis values inversely proportional to input y-axis values.

Parameters

v perspective factor

Example

See Also

getPerspX set setAll set9 MakeAll


setPerspY

void setPerspY(SkScalar v)

Sets input y-axis perspective factor, which causes mapXY to vary input y-axis values inversely proportional to input x-axis values.

Parameters

v perspective factor

Example

See Also

getPerspY set setAll set9 MakeAll


setAll

void setAll(SkScalar scaleX, SkScalar skewX, SkScalar transX, SkScalar skewY, SkScalar scaleY,
            SkScalar transY, SkScalar persp0, SkScalar persp1, SkScalar persp2)

Sets all values from parameters. Sets matrix to:

| scaleX  skewX transX |
|  skewY scaleY transY |
| persp0 persp1 persp2 |

Parameters

scaleX horizontal scale factor to store
skewX horizontal skew factor to store
transX horizontal translation to store
skewY vertical skew factor to store
scaleY vertical scale factor to store
transY vertical translation to store
persp0 input x-axis values perspective factor to store
persp1 input y-axis values perspective factor to store
persp2 perspective scale factor to store

Example

See Also

set9 MakeAll


get9

void get9(SkScalar buffer[9]) const

Copies nine Scalar values contained by Matrix into buffer, in member value ascending order: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY, kMPersp0, kMPersp1, kMPersp2.

Parameters

buffer storage for nine Scalar values

Example

#### Example Output ~~~~ {4, 0, 3}, {0, 5, 4}, {0, 0, 1} ~~~~

See Also

set9


set9

void set9(const SkScalar buffer[9])

Sets Matrix to nine Scalar values in buffer, in member value ascending order: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY, kMPersp0, kMPersp1, kMPersp2.

Sets matrix to:

| buffer[0] buffer[1] buffer[2] |
| buffer[3] buffer[4] buffer[5] |
| buffer[6] buffer[7] buffer[8] |

In the future, set9 followed by get9 may not return the same values. Since Matrix maps non-homogeneous coordinates, scaling all nine values produces an equivalent transformation, possibly improving precision.

Parameters

buffer nine Scalar values

Example

See Also

setAll get9 MakeAll


reset

void reset()

Sets Matrix to identity; which has no effect on mapped Points. Sets Matrix to:

| 1 0 0 |
| 0 1 0 |
| 0 0 1 |

Also called setIdentity; use the one that provides better inline documentation.

Example

#### Example Output ~~~~ m.isIdentity(): true ~~~~

See Also

isIdentity setIdentity


setIdentity

void setIdentity()

Sets Matrix to identity; which has no effect on mapped Points. Sets Matrix to:

| 1 0 0 |
| 0 1 0 |
| 0 0 1 |

Also called reset; use the one that provides better inline documentation.

Example

#### Example Output ~~~~ m.isIdentity(): true ~~~~

See Also

isIdentity reset


setTranslate

void setTranslate(SkScalar dx, SkScalar dy)

Sets Matrix to translate by (dx, dy).

Parameters

dx horizontal translation
dy vertical translation

Example

See Also

setTranslateX setTranslateY


void setTranslate(const SkVector& v)

Sets Matrix to translate by (v.fX, v.fY).

Parameters

v Vector containing horizontal and vertical translation

Example

See Also

setTranslateX setTranslateY MakeTrans


setScale

void setScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)

Sets Matrix to scale by sx and sy, about a pivot point at (px, py). The pivot point is unchanged when mapped with Matrix.

Parameters

sx horizontal scale factor
sy vertical scale factor
px pivot x
py pivot y

Example

See Also

setScaleX setScaleY MakeScale[2] preScale[2] postScale[2]


void setScale(SkScalar sx, SkScalar sy)

Sets Matrix to scale by sx and sy about at pivot point at (0, 0).

Parameters

sx horizontal scale factor
sy vertical scale factor

Example

See Also

setScaleX setScaleY MakeScale[2] preScale[2] postScale[2]


setRotate

void setRotate(SkScalar degrees, SkScalar px, SkScalar py)

Sets Matrix to rotate by degrees about a pivot point at (px, py). The pivot point is unchanged when mapped with Matrix.

Positive degrees rotates clockwise.

Parameters

degrees angle of axes relative to upright axes
px pivot x
py pivot y

Example

See Also

setSinCos[2] preRotate[2] postRotate[2]


void setRotate(SkScalar degrees)

Sets Matrix to rotate by degrees about a pivot point at (0, 0). Positive degrees rotates clockwise.

Parameters

degrees angle of axes relative to upright axes

Example

See Also

setSinCos[2] preRotate[2] postRotate[2]


setSinCos

void setSinCos(SkScalar sinValue, SkScalar cosValue, SkScalar px, SkScalar py)

Sets Matrix to rotate by sinValue and cosValue, about a pivot point at (px, py). The pivot point is unchanged when mapped with Matrix.

Vector (sinValue, cosValue) describes the angle of rotation relative to (0, 1). Vector length specifies scale.

Parameters

sinValue rotation vector x-axis component
cosValue rotation vector y-axis component
px pivot x-axis
py pivot y-axis

Example

See Also

setRotate[2] setScale[2] setRSXform


void setSinCos(SkScalar sinValue, SkScalar cosValue)

Sets Matrix to rotate by sinValue and cosValue, about a pivot point at (0, 0).

Vector (sinValue, cosValue) describes the angle of rotation relative to (0, 1). Vector length specifies scale.

Parameters

sinValue rotation vector x-axis component
cosValue rotation vector y-axis component

Example

Canvas needs offset after applying Matrix to pivot about Rect center.

See Also

setRotate[2] setScale[2] setRSXform


setRSXform

SkMatrix& setRSXform(const SkRSXform& rsxForm)

Sets Matrix to rotate, scale, and translate using a compressed matrix form.

Vector (rsxForm.fSSin, rsxForm.fSCos) describes the angle of rotation relative to (0, 1). Vector length specifies scale. Mapped point is rotated and scaled by Vector, then translated by (rsxForm.fTx, rsxForm.fTy).

Parameters

rsxForm compressed RSXform matrix

Return Value

reference to Matrix

Example

Canvas needs offset after applying Matrix to pivot about Rect center.

See Also

setSinCos[2] setScale[2] setTranslate[2]


setSkew

void setSkew(SkScalar kx, SkScalar ky, SkScalar px, SkScalar py)

Sets Matrix to skew by kx and ky, about a pivot point at (px, py). The pivot point is unchanged when mapped with Matrix.

Parameters

kx horizontal skew factor
ky vertical skew factor
px pivot x
py pivot y

Example

See Also

setSkewX setSkewY preSkew[2] postSkew[2]


void setSkew(SkScalar kx, SkScalar ky)

Sets Matrix to skew by kx and ky, about a pivot point at (0, 0).

Parameters

kx horizontal skew factor
ky vertical skew factor

Example

See Also

setSkewX setSkewY preSkew[2] postSkew[2]


setConcat

void setConcat(const SkMatrix& a, const SkMatrix& b)

Sets Matrix to Matrix a multiplied by Matrix b. Either a or b may be this.

Given:

    | A B C |      | J K L |
a = | D E F |, b = | M N O |
    | G H I |      | P Q R |

sets Matrix to:

        | A B C |   | J K L |   | AJ+BM+CP AK+BN+CQ AL+BO+CR |
a * b = | D E F | * | M N O | = | DJ+EM+FP DK+EN+FQ DL+EO+FR |
        | G H I |   | P Q R |   | GJ+HM+IP GK+HN+IQ GL+HO+IR |

Parameters

a Matrix on left side of multiply expression
b Matrix on right side of multiply expression

Example

setPolyToPoly creates perspective matrices, one the inverse of the other. Multiplying the matrix by its inverse turns into an identity matrix.

See Also

Concat preConcat postConcat SkCanvas::concat


preTranslate

void preTranslate(SkScalar dx, SkScalar dy)

Sets Matrix to Matrix multiplied by Matrix constructed from translation (dx, dy). This can be thought of as moving the point to be mapped before applying Matrix.

Given:

         | A B C |               | 1 0 dx |
Matrix = | D E F |,  T(dx, dy) = | 0 1 dy |
         | G H I |               | 0 0  1 |

sets Matrix to:

                     | A B C | | 1 0 dx |   | A B A*dx+B*dy+C |
Matrix * T(dx, dy) = | D E F | | 0 1 dy | = | D E D*dx+E*dy+F |
                     | G H I | | 0 0  1 |   | G H G*dx+H*dy+I |

Parameters

dx x-axis translation before applying Matrix
dy y-axis translation before applying Matrix

Example

See Also

postTranslate setTranslate[2] MakeTrans


preScale

void preScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)

Sets Matrix to Matrix multiplied by Matrix constructed from scaling by (sx, sy) about pivot point (px, py). This can be thought of as scaling about a pivot point before applying Matrix.

Given:

         | A B C |                       | sx  0 dx |
Matrix = | D E F |,  S(sx, sy, px, py) = |  0 sy dy |
         | G H I |                       |  0  0  1 |

where

dx = px - sx * px
dy = py - sy * py

sets Matrix to:

                             | A B C | | sx  0 dx |   | A*sx B*sy A*dx+B*dy+C |
Matrix * S(sx, sy, px, py) = | D E F | |  0 sy dy | = | D*sx E*sy D*dx+E*dy+F |
                             | G H I | |  0  0  1 |   | G*sx H*sy G*dx+H*dy+I |

Parameters

sx horizontal scale factor
sy vertical scale factor
px pivot x
py pivot y

Example

See Also

postScale[2] setScale[2] MakeScale[2]


void preScale(SkScalar sx, SkScalar sy)

Sets Matrix to Matrix multiplied by Matrix constructed from scaling by (sx, sy) about pivot point (0, 0). This can be thought of as scaling about the origin before applying Matrix.

Given:

         | A B C |               | sx  0  0 |
Matrix = | D E F |,  S(sx, sy) = |  0 sy  0 |
         | G H I |               |  0  0  1 |

sets Matrix to:

                     | A B C | | sx  0  0 |   | A*sx B*sy C |
Matrix * S(sx, sy) = | D E F | |  0 sy  0 | = | D*sx E*sy F |
                     | G H I | |  0  0  1 |   | G*sx H*sy I |

Parameters

sx horizontal scale factor
sy vertical scale factor

Example

See Also

postScale[2] setScale[2] MakeScale[2]


preRotate

void preRotate(SkScalar degrees, SkScalar px, SkScalar py)

Sets Matrix to Matrix multiplied by Matrix constructed from rotating by degrees about pivot point (px, py). This can be thought of as rotating about a pivot point before applying Matrix.

Positive degrees rotates clockwise.

Given:

         | A B C |                        | c -s dx |
Matrix = | D E F |,  R(degrees, px, py) = | s  c dy |
         | G H I |                        | 0  0  1 |

where

c  = cos(degrees)
s  = sin(degrees)
dx =  s * py + (1 - c) * px
dy = -s * px + (1 - c) * py

sets Matrix to:

                              | A B C | | c -s dx |   | Ac+Bs -As+Bc A*dx+B*dy+C |
Matrix * R(degrees, px, py) = | D E F | | s  c dy | = | Dc+Es -Ds+Ec D*dx+E*dy+F |
                              | G H I | | 0  0  1 |   | Gc+Hs -Gs+Hc G*dx+H*dy+I |

Parameters

degrees angle of axes relative to upright axes
px pivot x
py pivot y

Example

See Also

postRotate[2] setRotate[2]


void preRotate(SkScalar degrees)

Sets Matrix to Matrix multiplied by Matrix constructed from rotating by degrees about pivot point (0, 0). This can be thought of as rotating about the origin before applying Matrix.

Positive degrees rotates clockwise.

Given:

         | A B C |                        | c -s 0 |
Matrix = | D E F |,  R(degrees, px, py) = | s  c 0 |
         | G H I |                        | 0  0 1 |

where

c  = cos(degrees)
s  = sin(degrees)

sets Matrix to:

                              | A B C | | c -s 0 |   | Ac+Bs -As+Bc C |
Matrix * R(degrees, px, py) = | D E F | | s  c 0 | = | Dc+Es -Ds+Ec F |
                              | G H I | | 0  0 1 |   | Gc+Hs -Gs+Hc I |

Parameters

degrees angle of axes relative to upright axes

Example

See Also

postRotate[2] setRotate[2]


preSkew

void preSkew(SkScalar kx, SkScalar ky, SkScalar px, SkScalar py)

Sets Matrix to Matrix multiplied by Matrix constructed from skewing by (kx, ky) about pivot point (px, py). This can be thought of as skewing about a pivot point before applying Matrix.

Given:

         | A B C |                       |  1 kx dx |
Matrix = | D E F |,  K(kx, ky, px, py) = | ky  1 dy |
         | G H I |                       |  0  0  1 |

where

dx = -kx * py
dy = -ky * px

sets Matrix to:

                             | A B C | |  1 kx dx |   | A+B*ky A*kx+B A*dx+B*dy+C |
Matrix * K(kx, ky, px, py) = | D E F | | ky  1 dy | = | D+E*ky D*kx+E D*dx+E*dy+F |
                             | G H I | |  0  0  1 |   | G+H*ky G*kx+H G*dx+H*dy+I |

Parameters

kx horizontal skew factor
ky vertical skew factor
px pivot x
py pivot y

Example

See Also

postSkew[2] setSkew[2]


void preSkew(SkScalar kx, SkScalar ky)

Sets Matrix to Matrix multiplied by Matrix constructed from skewing by (kx, ky) about pivot point (0, 0). This can be thought of as skewing about the origin before applying Matrix.

Given:

         | A B C |               |  1 kx 0 |
Matrix = | D E F |,  K(kx, ky) = | ky  1 0 |
         | G H I |               |  0  0 1 |

sets Matrix to:

                     | A B C | |  1 kx 0 |   | A+B*ky A*kx+B C |
Matrix * K(kx, ky) = | D E F | | ky  1 0 | = | D+E*ky D*kx+E F |
                     | G H I | |  0  0 1 |   | G+H*ky G*kx+H I |

Parameters

kx horizontal skew factor
ky vertical skew factor

Example

See Also

postSkew[2] setSkew[2]


preConcat

void preConcat(const SkMatrix& other)

Sets Matrix to Matrix multiplied by Matrix other. This can be thought of mapping by other before applying Matrix.

Given:

         | A B C |          | J K L |
Matrix = | D E F |, other = | M N O |
         | G H I |          | P Q R |

sets Matrix to:

                 | A B C |   | J K L |   | AJ+BM+CP AK+BN+CQ AL+BO+CR |
Matrix * other = | D E F | * | M N O | = | DJ+EM+FP DK+EN+FQ DL+EO+FR |
                 | G H I |   | P Q R |   | GJ+HM+IP GK+HN+IQ GL+HO+IR |

Parameters

other Matrix on right side of multiply expression

Example

setPolyToPoly creates perspective matrices, one the inverse of the other. Multiplying the matrix by its inverse turns into an identity matrix.

See Also

postConcat setConcat Concat


postTranslate

void postTranslate(SkScalar dx, SkScalar dy)

Sets Matrix to Matrix constructed from translation (dx, dy) multiplied by Matrix. This can be thought of as moving the point to be mapped after applying Matrix.

Given:

         | J K L |               | 1 0 dx |
Matrix = | M N O |,  T(dx, dy) = | 0 1 dy |
         | P Q R |               | 0 0  1 |

sets Matrix to:

                     | 1 0 dx | | J K L |   | J+dx*P K+dx*Q L+dx*R |
T(dx, dy) * Matrix = | 0 1 dy | | M N O | = | M+dy*P N+dy*Q O+dy*R |
                     | 0 0  1 | | P Q R |   |      P      Q      R |

Parameters

dx x-axis translation after applying Matrix
dy y-axis translation after applying Matrix

Example

Compare with preTranslate example.

See Also

preTranslate setTranslate[2] MakeTrans


postScale

void postScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)

Sets Matrix to Matrix constructed from scaling by (sx, sy) about pivot point (px, py), multiplied by Matrix. This can be thought of as scaling about a pivot point after applying Matrix.

Given:

         | J K L |                       | sx  0 dx |
Matrix = | M N O |,  S(sx, sy, px, py) = |  0 sy dy |
         | P Q R |                       |  0  0  1 |

where

dx = px - sx * px
dy = py - sy * py

sets Matrix to:

                             | sx  0 dx | | J K L |   | sx*J+dx*P sx*K+dx*Q sx*L+dx+R |
S(sx, sy, px, py) * Matrix = |  0 sy dy | | M N O | = | sy*M+dy*P sy*N+dy*Q sy*O+dy*R |
                             |  0  0  1 | | P Q R |   |         P         Q         R |

Parameters

sx horizontal scale factor
sy vertical scale factor
px pivot x
py pivot y

Example

See Also

preScale[2] setScale[2] MakeScale[2]


void postScale(SkScalar sx, SkScalar sy)

Sets Matrix to Matrix constructed from scaling by (sx, sy) about pivot point (0, 0), multiplied by Matrix. This can be thought of as scaling about the origin after applying Matrix.

Given:

         | J K L |               | sx  0  0 |
Matrix = | M N O |,  S(sx, sy) = |  0 sy  0 |
         | P Q R |               |  0  0  1 |

sets Matrix to:

                     | sx  0  0 | | J K L |   | sx*J sx*K sx*L |
S(sx, sy) * Matrix = |  0 sy  0 | | M N O | = | sy*M sy*N sy*O |
                     |  0  0  1 | | P Q R |   |    P    Q    R |

Parameters

sx horizontal scale factor
sy vertical scale factor

Example

See Also

preScale[2] setScale[2] MakeScale[2]


postIDiv

bool postIDiv(int divx, int divy)

Sets Matrix to Matrix constructed from scaling by(1/divx, 1/divy) about pivot point (px, py), multiplied by Matrix.

Returns false if either divx or divy is zero.

Given:

         | J K L |                   | sx  0  0 |
Matrix = | M N O |,  I(divx, divy) = |  0 sy  0 |
         | P Q R |                   |  0  0  1 |

where

sx = 1 / divx
sy = 1 / divy

sets Matrix to:

                         | sx  0  0 | | J K L |   | sx*J sx*K sx*L |
I(divx, divy) * Matrix = |  0 sy  0 | | M N O | = | sy*M sy*N sy*O |
                         |  0  0  1 | | P Q R |   |    P    Q    R |

Parameters

divx integer divisor for inverse scale in x
divy integer divisor for inverse scale in y

Return Value

true on successful scale

Example

See Also

postScale[2] MakeScale[2]


postRotate

void postRotate(SkScalar degrees, SkScalar px, SkScalar py)

Sets Matrix to Matrix constructed from rotating by degrees about pivot point (px, py), multiplied by Matrix. This can be thought of as rotating about a pivot point after applying Matrix.

Positive degrees rotates clockwise.

Given:

         | J K L |                        | c -s dx |
Matrix = | M N O |,  R(degrees, px, py) = | s  c dy |
         | P Q R |                        | 0  0  1 |

where

c  = cos(degrees)
s  = sin(degrees)
dx =  s * py + (1 - c) * px
dy = -s * px + (1 - c) * py

sets Matrix to:

                              |c -s dx| |J K L|   |cJ-sM+dx*P cK-sN+dx*Q cL-sO+dx+R|
R(degrees, px, py) * Matrix = |s  c dy| |M N O| = |sJ+cM+dy*P sK+cN+dy*Q sL+cO+dy*R|
                              |0  0  1| |P Q R|   |         P          Q          R|

Parameters

degrees angle of axes relative to upright axes
px pivot x
py pivot y

Example

See Also

preRotate[2] setRotate[2]


void postRotate(SkScalar degrees)

Sets Matrix to Matrix constructed from rotating by degrees about pivot point (0, 0), multiplied by Matrix. This can be thought of as rotating about the origin after applying Matrix.

Positive degrees rotates clockwise.

Given:

         | J K L |                        | c -s 0 |
Matrix = | M N O |,  R(degrees, px, py) = | s  c 0 |
         | P Q R |                        | 0  0 1 |

where

c  = cos(degrees)
s  = sin(degrees)

sets Matrix to:

                              | c -s dx | | J K L |   | cJ-sM cK-sN cL-sO |
R(degrees, px, py) * Matrix = | s  c dy | | M N O | = | sJ+cM sK+cN sL+cO |
                              | 0  0  1 | | P Q R |   |     P     Q     R |

Parameters

degrees angle of axes relative to upright axes

Example

See Also

preRotate[2] setRotate[2]


postSkew

void postSkew(SkScalar kx, SkScalar ky, SkScalar px, SkScalar py)

Sets Matrix to Matrix constructed from skewing by (kx, ky) about pivot point (px, py), multiplied by Matrix. This can be thought of as skewing about a pivot point after applying Matrix.

Given:

         | J K L |                       |  1 kx dx |
Matrix = | M N O |,  K(kx, ky, px, py) = | ky  1 dy |
         | P Q R |                       |  0  0  1 |

where

dx = -kx * py
dy = -ky * px

sets Matrix to:

                             | 1 kx dx| |J K L|   |J+kx*M+dx*P K+kx*N+dx*Q L+kx*O+dx+R|
K(kx, ky, px, py) * Matrix = |ky  1 dy| |M N O| = |ky*J+M+dy*P ky*K+N+dy*Q ky*L+O+dy*R|
                             | 0  0  1| |P Q R|   |          P           Q           R|

Parameters

kx horizontal skew factor
ky vertical skew factor
px pivot x
py pivot y

Example

See Also

preSkew[2] setSkew[2]


void postSkew(SkScalar kx, SkScalar ky)

Sets Matrix to Matrix constructed from skewing by (kx, ky) about pivot point (0, 0), multiplied by Matrix. This can be thought of as skewing about the origin after applying Matrix.

Given:

         | J K L |               |  1 kx 0 |
Matrix = | M N O |,  K(kx, ky) = | ky  1 0 |
         | P Q R |               |  0  0 1 |

sets Matrix to:

                     |  1 kx 0 | | J K L |   | J+kx*M K+kx*N L+kx*O |
K(kx, ky) * Matrix = | ky  1 0 | | M N O | = | ky*J+M ky*K+N ky*L+O |
                     |  0  0 1 | | P Q R |   |      P      Q      R |

Parameters

kx horizontal skew factor
ky vertical skew factor

Example

See Also

preSkew[2] setSkew[2]


postConcat

void postConcat(const SkMatrix& other)

Sets Matrix to Matrix other multiplied by Matrix. This can be thought of mapping by other after applying Matrix.

Given:

         | J K L |           | A B C |
Matrix = | M N O |,  other = | D E F |
         | P Q R |           | G H I |

sets Matrix to:

                 | A B C |   | J K L |   | AJ+BM+CP AK+BN+CQ AL+BO+CR |
other * Matrix = | D E F | * | M N O | = | DJ+EM+FP DK+EN+FQ DL+EO+FR |
                 | G H I |   | P Q R |   | GJ+HM+IP GK+HN+IQ GL+HO+IR |

Parameters

other Matrix on left side of multiply expression

Example

See Also

preConcat setConcat Concat


Enum SkMatrix::ScaleToFit

    enum ScaleToFit {
        kFill ScaleToFit,
        kStart ScaleToFit,
        kCenter ScaleToFit,
        kEnd ScaleToFit,
    };

ScaleToFit describes how Matrix is constructed to map one Rect to another. ScaleToFit may allow Matrix to have unequal horizontal and vertical scaling, or may restrict Matrix to square scaling. If restricted, ScaleToFit specifies how Matrix maps to the side or center of the destination Rect.

Constants

Const Value Description
SkMatrix::kFill_ScaleToFit 0 Computes Matrix that scales in x and y independently, so that source Rect is mapped to completely fill destination Rect. The aspect ratio of source Rect may change.
SkMatrix::kStart_ScaleToFit 1 Computes Matrix that maintains source Rect aspect ratio, mapping source Rect width or height to destination Rect. Aligns mapping to left and top edges of destination Rect.
SkMatrix::kCenter_ScaleToFit 2 Computes Matrix that maintains source Rect aspect ratio, mapping source Rect width or height to destination Rect. Aligns mapping to center of destination Rect.
SkMatrix::kEnd_ScaleToFit 3 Computes Matrix that maintains source Rect aspect ratio, mapping source Rect width or height to destination Rect. Aligns mapping to right and bottom edges of destination Rect.

Example

See Also

setRectToRect MakeRectToRect setPolyToPoly

setRectToRect

bool setRectToRect(const SkRect& src, const SkRect& dst, ScaleToFit stf)

Sets Matrix to scale and translate src Rect to dst Rect. stf selects whether mapping completely fills dst or preserves the aspect ratio, and how to align src within dst. Returns false if src is empty, and sets Matrix to identity. Returns true if dst is empty, and sets Matrix to:

| 0 0 0 |
| 0 0 0 |
| 0 0 1 |

Parameters

src Rect to map from
dst Rect to map to
stf one of: kFill ScaleToFit, kStart ScaleToFit, kCenter ScaleToFit, kEnd ScaleToFit

Return Value

true if Matrix can represent Rect mapping

Example

#### Example Output ~~~~ src: 0, 0, 0, 0 dst: 0, 0, 0, 0 success: false [ 1.0000 0.0000 0.0000][ 0.0000 1.0000 0.0000][ 0.0000 0.0000 1.0000] src: 0, 0, 0, 0 dst: 5, 6, 8, 9 success: false [ 1.0000 0.0000 0.0000][ 0.0000 1.0000 0.0000][ 0.0000 0.0000 1.0000] src: 1, 2, 3, 4 dst: 0, 0, 0, 0 success: true [ 0.0000 0.0000 0.0000][ 0.0000 0.0000 0.0000][ 0.0000 0.0000 1.0000] src: 1, 2, 3, 4 dst: 5, 6, 8, 9 success: true [ 1.5000 0.0000 3.5000][ 0.0000 1.5000 3.0000][ 0.0000 0.0000 1.0000] ~~~~

See Also

MakeRectToRect ScaleToFit setPolyToPoly SkRect::isEmpty


MakeRectToRect

static SkMatrix MakeRectToRect(const SkRect& src, const SkRect& dst, ScaleToFit stf)

Returns Matrix set to scale and translate src Rect to dst Rect. stf selects whether mapping completely fills dst or preserves the aspect ratio, and how to align src within dst. Returns the identity Matrix if src is empty. If dst is empty, returns Matrix set to:

| 0 0 0 |
| 0 0 0 |
| 0 0 1 |

Parameters

src Rect to map from
dst Rect to map to
stf one of: kFill ScaleToFit, kStart ScaleToFit, kCenter ScaleToFit, kEnd ScaleToFit

Return Value

Matrix mapping src to dst

Example

#### Example Output ~~~~ src: 0, 0, 0, 0 dst: 0, 0, 0, 0 [ 1.0000 0.0000 0.0000][ 0.0000 1.0000 0.0000][ 0.0000 0.0000 1.0000] src: 0, 0, 0, 0 dst: 5, 6, 8, 9 [ 1.0000 0.0000 0.0000][ 0.0000 1.0000 0.0000][ 0.0000 0.0000 1.0000] src: 1, 2, 3, 4 dst: 0, 0, 0, 0 [ 0.0000 0.0000 0.0000][ 0.0000 0.0000 0.0000][ 0.0000 0.0000 1.0000] src: 1, 2, 3, 4 dst: 5, 6, 8, 9 [ 1.5000 0.0000 3.5000][ 0.0000 1.5000 3.0000][ 0.0000 0.0000 1.0000] ~~~~

See Also

setRectToRect ScaleToFit setPolyToPoly SkRect::isEmpty


setPolyToPoly

bool setPolyToPoly(const SkPoint src[], const SkPoint dst[], int count)

Sets Matrix to map src to dst. count must be zero or greater, and four or less.

If count is zero, sets Matrix to identity and returns true. If count is one, sets Matrix to translate and returns true. If count is two or more, sets Matrix to map Points if possible; returns false if Matrix cannot be constructed. If count is four, Matrix may include perspective.

Parameters

src Points to map from
dst Points to map to
count number of Points in src and dst

Return Value

true if Matrix was constructed successfully

Example

See Also

setRectToRect MakeRectToRect


invert

bool SK_WARN_UNUSED_RESULT invert(SkMatrix* inverse) const

Sets inverse to reciprocal matrix, returning true if Matrix can be inverted. Geometrically, if Matrix maps from source to destination, inverse Matrix maps from destination to source. If Matrix can not be inverted, inverse is unchanged.

Parameters

inverse storage for inverted Matrix; may be nullptr

Return Value

true if Matrix can be inverted

Example

See Also

Concat


SetAffineIdentity

static void SetAffineIdentity(SkScalar affine[6])

Fills affine with identity values in column major order. Sets affine to:

| 1 0 0 |
| 0 1 0 |

Affine 3x2 matrices in column major order are used by OpenGL and XPS.

Parameters

affine storage for 3x2 affine matrix

Example

#### Example Output ~~~~ ScaleX: 1 SkewY: 0 SkewX: 0 ScaleY: 1 TransX: 0 TransY: 0 ~~~~

See Also

setAffine asAffine


asAffine

bool SK_WARN_UNUSED_RESULT asAffine(SkScalar affine[6]) const

Fills affine in column major order. Sets affine to:

| scale-x  skew-x translate-x |
| skew-y  scale-y translate-y |

If Matrix contains perspective, returns false and leaves affine unchanged.

Parameters

affine storage for 3x2 affine matrix; may be nullptr

Return Value

true if Matrix does not contain perspective

Example

#### Example Output ~~~~ ScaleX: 2 SkewY: 5 SkewX: 3 ScaleY: 6 TransX: 4 TransY: 7 ~~~~

See Also

setAffine SetAffineIdentity


setAffine

void setAffine(const SkScalar affine[6])

Sets Matrix to affine values, passed in column major order. Given affine, column, then row, as:

| scale-x  skew-x translate-x |
|  skew-y scale-y translate-y |

Matrix is set, row, then column, to:

| scale-x  skew-x translate-x |
|  skew-y scale-y translate-y |
|       0       0           1 |

Parameters

affine 3x2 affine matrix

Example

#### Example Output ~~~~ ScaleX: 2 SkewY: 5 SkewX: 3 ScaleY: 6 TransX: 4 TransY: 7 [ 2.0000 3.0000 4.0000][ 5.0000 6.0000 7.0000][ 0.0000 0.0000 1.0000] ~~~~

See Also

asAffine SetAffineIdentity


Transform

Topic Description
mapHomogeneousPoints maps Point3 array
mapPoints maps Point array
mapPoints(SkPoint dst[], const SkPoint src[], int count) const
mapPoints(SkPoint pts[], int count) const
mapRadius returns mean radius of mapped Circle
mapRect returns bounds of mapped Rect
mapRect(SkRect* dst, const SkRect& src) const
mapRect(SkRect* rect) const
mapRect(const SkRect& src) const
mapRectScaleTranslate returns bounds of mapped Rect
mapRectToQuad maps Rect to Point array
mapVector maps Vector
mapVector(SkScalar dx, SkScalar dy, SkVector* result) const
mapVector(SkScalar dx, SkScalar dy) const
mapVectors maps Vector array
mapVectors(SkVector dst[], const SkVector src[], int count) const
mapVectors(SkVector vecs[], int count) const
mapXY maps Point
mapXY(SkScalar x, SkScalar y, SkPoint* result) const
mapXY(SkScalar x, SkScalar y) const

mapPoints

void mapPoints(SkPoint dst[], const SkPoint src[], int count) const

Maps src Point array of length count to dst Point array of equal or greater length. Points are mapped by multiplying each Point by Matrix. Given:

         | A B C |        | x |
Matrix = | D E F |,  pt = | y |
         | G H I |        | 1 |

where

for (i = 0; i < count; ++i) {
    x = src[i].fX
    y = src[i].fY
}

each dst Point is computed as:

              |A B C| |x|                               Ax+By+C   Dx+Ey+F
Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , -------
              |G H I| |1|                               Gx+Hy+I   Gx+Hy+I

src and dst may point to the same storage.

Parameters

dst storage for mapped Points
src Points to transform
count number of Points to transform

Example

See Also

mapXY[2] mapHomogeneousPoints mapVectors[2]


void mapPoints(SkPoint pts[], int count) const

Maps pts Point array of length count in place. Points are mapped by multiplying each Point by Matrix. Given:

         | A B C |        | x |
Matrix = | D E F |,  pt = | y |
         | G H I |        | 1 |

where

for (i = 0; i < count; ++i) {
    x = pts[i].fX
    y = pts[i].fY
}

each resulting pts Point is computed as:

              |A B C| |x|                               Ax+By+C   Dx+Ey+F
Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , -------
              |G H I| |1|                               Gx+Hy+I   Gx+Hy+I

Parameters

pts storage for mapped Points
count number of Points to transform

Example

See Also

mapXY[2] mapHomogeneousPoints mapVectors[2]


mapHomogeneousPoints

void mapHomogeneousPoints(SkPoint3 dst[], const SkPoint3 src[], int count) const

Maps src Point3 array of length count to dst Point3 array, which must of length count or greater. Point3 array is mapped by multiplying each Point3 by Matrix. Given:

         | A B C |         | x |
Matrix = | D E F |,  src = | y |
         | G H I |         | z |

each resulting dst Point is computed as:

               |A B C| |x|
Matrix * src = |D E F| |y| = |Ax+By+Cz Dx+Ey+Fz Gx+Hy+Iz|
               |G H I| |z|

Parameters

dst storage for mapped Point3 array
src Point3 array to transform
count items in Point3 array to transform

Example

See Also

mapPoints[2] mapXY[2] mapVectors[2]


mapXY

void mapXY(SkScalar x, SkScalar y, SkPoint* result) const

Maps Point (x, y) to result. Point is mapped by multiplying by Matrix. Given:

         | A B C |        | x |
Matrix = | D E F |,  pt = | y |
         | G H I |        | 1 |

result is computed as:

              |A B C| |x|                               Ax+By+C   Dx+Ey+F
Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , -------
              |G H I| |1|                               Gx+Hy+I   Gx+Hy+I

Parameters

x x-axis value of Point to map
y y-axis value of Point to map
result storage for mapped Point

Example

See Also

mapPoints[2] mapVectors[2]


SkPoint mapXY(SkScalar x, SkScalar y) const

Returns Point (x, y) multiplied by Matrix. Given:

         | A B C |        | x |
Matrix = | D E F |,  pt = | y |
         | G H I |        | 1 |

result is computed as:

              |A B C| |x|                               Ax+By+C   Dx+Ey+F
Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , -------
              |G H I| |1|                               Gx+Hy+I   Gx+Hy+I

Parameters

x x-axis value of Point to map
y y-axis value of Point to map

Return Value

mapped Point

Example

See Also

mapPoints[2] mapVectors[2]


mapVectors

void mapVectors(SkVector dst[], const SkVector src[], int count) const

Maps src Vector array of length count to Vector Point array of equal or greater length. Vectors are mapped by multiplying each Vector by Matrix, treating Matrix translation as zero. Given:

         | A B 0 |         | x |
Matrix = | D E 0 |,  src = | y |
         | G H I |         | 1 |

where

for (i = 0; i < count; ++i) {
    x = src[i].fX
    y = src[i].fY
}

each dst Vector is computed as:

               |A B 0| |x|                            Ax+By     Dx+Ey
Matrix * src = |D E 0| |y| = |Ax+By Dx+Ey Gx+Hy+I| = ------- , -------
               |G H I| |1|                           Gx+Hy+I   Gx+Hy+I

src and dst may point to the same storage.

Parameters

dst storage for mapped Vectors
src Vectors to transform
count number of Vectors to transform

Example

See Also

mapVector[2] mapPoints[2] mapXY[2]


void mapVectors(SkVector vecs[], int count) const

Maps vecs Vector array of length count in place, multiplying each Vector by Matrix, treating Matrix translation as zero. Given:

         | A B 0 |         | x |
Matrix = | D E 0 |,  vec = | y |
         | G H I |         | 1 |

where

for (i = 0; i < count; ++i) {
    x = vecs[i].fX
    y = vecs[i].fY
}

each result Vector is computed as:

               |A B 0| |x|                            Ax+By     Dx+Ey
Matrix * vec = |D E 0| |y| = |Ax+By Dx+Ey Gx+Hy+I| = ------- , -------
               |G H I| |1|                           Gx+Hy+I   Gx+Hy+I

Parameters

vecs Vectors to transform, and storage for mapped Vectors
count number of Vectors to transform

Example

See Also

mapVector[2] mapPoints[2] mapXY[2]


mapVector

void mapVector(SkScalar dx, SkScalar dy, SkVector* result) const

Maps Vector (x, y) to result. Vector is mapped by multiplying by Matrix, treating Matrix translation as zero. Given:

         | A B 0 |         | dx |
Matrix = | D E 0 |,  vec = | dy |
         | G H I |         |  1 |

each result Vector is computed as:

               |A B 0| |dx|                                        A*dx+B*dy     D*dx+E*dy
Matrix * vec = |D E 0| |dy| = |A*dx+B*dy D*dx+E*dy G*dx+H*dy+I| = ----------- , -----------
               |G H I| | 1|                                       G*dx+H*dy+I   G*dx+*dHy+I

Parameters

dx x-axis value of Vector to map
dy y-axis value of Vector to map
result storage for mapped Vector

Example

See Also

mapVectors[2] mapPoints[2] mapXY[2]


SkVector mapVector(SkScalar dx, SkScalar dy) const

Returns Vector (x, y) multiplied by Matrix, treating Matrix translation as zero. Given:

         | A B 0 |         | dx |
Matrix = | D E 0 |,  vec = | dy |
         | G H I |         |  1 |

each result Vector is computed as:

               |A B 0| |dx|                                        A*dx+B*dy     D*dx+E*dy
Matrix * vec = |D E 0| |dy| = |A*dx+B*dy D*dx+E*dy G*dx+H*dy+I| = ----------- , -----------
               |G H I| | 1|                                       G*dx+H*dy+I   G*dx+*dHy+I

Parameters

dx x-axis value of Vector to map
dy y-axis value of Vector to map

Return Value

mapped Vector

Example

See Also

mapVectors[2] mapPoints[2] mapXY[2]


mapRect

bool mapRect(SkRect* dst, const SkRect& src) const

Sets dst to bounds of src corners mapped by Matrix. Returns true if mapped corners are dst corners.

Returned value is the same as calling rectStaysRect.

Parameters

dst storage for bounds of mapped Points
src Rect to map

Return Value

true if dst is equivalent to mapped src

Example

See Also

mapPoints[2] rectStaysRect


bool mapRect(SkRect* rect) const

Sets rect to bounds of rect corners mapped by Matrix. Returns true if mapped corners are computed rect corners.

Returned value is the same as calling rectStaysRect.

Parameters

rect rectangle to map, and storage for bounds of mapped corners

Return Value

true if result is equivalent to mapped src

Example

See Also

mapRectScaleTranslate mapPoints[2] rectStaysRect


SkRect mapRect(const SkRect& src) const

Returns bounds of src corners mapped by Matrix.

Parameters

src rectangle to map

Return Value

mapped bounds

Example

See Also

mapRectToQuad mapRectScaleTranslate


mapRectToQuad

void mapRectToQuad(SkPoint dst[4], const SkRect& rect) const

Maps four corners of rect to dst. Points are mapped by multiplying each rect corner by Matrix. rect corner is processed in this order: (rect.fLeft, rect.fTop), (rect.fRight, rect.fTop), (rect.fRight, rect.fBottom), (rect.fLeft, rect.fBottom).

rect may be empty: rect.fLeft may be greater than or equal to rect.fRight; rect.fTop may be greater than or equal to rect.fBottom.

Given:

         | A B C |        | x |
Matrix = | D E F |,  pt = | y |
         | G H I |        | 1 |

where pt is initialized from each of (rect.fLeft, rect.fTop), (rect.fRight, rect.fTop), (rect.fRight, rect.fBottom), (rect.fLeft, rect.fBottom), each dst Point is computed as:

              |A B C| |x|                               Ax+By+C   Dx+Ey+F
Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , -------
              |G H I| |1|                               Gx+Hy+I   Gx+Hy+I

Parameters

dst storage for mapped corner Points
rect Rect to map

Example

See Also

mapRect[2][3] mapRectScaleTranslate


mapRectScaleTranslate

void mapRectScaleTranslate(SkRect* dst, const SkRect& src) const

Sets dst to bounds of src corners mapped by Matrix. If matrix contains elements other than scale or translate: asserts if SK_DEBUG is defined; otherwise, results are undefined.

Parameters

dst storage for bounds of mapped Points
src Rect to map

Example

See Also

mapRect[2][3] mapRectToQuad isScaleTranslate rectStaysRect


mapRadius

SkScalar mapRadius(SkScalar radius) const

Returns geometric mean radius of ellipse formed by constructing Circle of size radius, and mapping constructed Circle with Matrix. The result squared is equal to the major axis length times the minor axis length. Result is not meaningful if Matrix contains perspective elements.

Parameters

radius Circle size to map

Return Value

average mapped radius

Example

The area enclosed by a square with sides equal to mappedRadius is the same as the area enclosed by the ellipse major and minor axes.

See Also

mapVector[2]


isFixedStepInX

bool isFixedStepInX() const

Returns true if a unit step on x-axis at some y-axis value mapped through Matrix can be represented by a constant Vector. Returns true if getType returns kIdentity Mask, or combinations of: kTranslate Mask, kScale Mask, and kAffine Mask.

May return true if getType returns kPerspective Mask, but only when Matrix does not include rotation or skewing along the y-axis.

Return Value

true if Matrix does not have complex perspective

Example

#### Example Output ~~~~ [ 1.0000 0.0000 0.0000][ 0.0000 1.0000 0.0000][ 0.0000 0.0000 1.0000] isFixedStepInX: true [ 1.0000 0.0000 0.0000][ 0.0000 2.0000 0.0000][ 0.0000 0.0000 1.0000] isFixedStepInX: true [ 1.0000 0.0000 0.0000][ 0.0000 1.0000 0.0000][ 0.0000 0.1000 1.0000] isFixedStepInX: true [ 1.0000 0.0000 0.0000][ 0.0000 2.0000 0.0000][ 0.0000 0.1000 1.0000] isFixedStepInX: true [ 1.0000 0.0000 0.0000][ 0.0000 1.0000 0.0000][ 0.1000 0.0000 1.0000] isFixedStepInX: false [ 1.0000 0.0000 0.0000][ 0.0000 2.0000 0.0000][ 0.1000 0.0000 1.0000] isFixedStepInX: false [ 1.0000 0.0000 0.0000][ 0.0000 1.0000 0.0000][ 0.1000 0.1000 1.0000] isFixedStepInX: false [ 1.0000 0.0000 0.0000][ 0.0000 2.0000 0.0000][ 0.1000 0.1000 1.0000] isFixedStepInX: false ~~~~

See Also

fixedStepInX getType


fixedStepInX

SkVector fixedStepInX(SkScalar y) const

Returns Vector representing a unit step on x-axis at y mapped through Matrix. If isFixedStepInX is false, returned value is undefined.

Parameters

y position of line parallel to x-axis

Return Value

Vector advance of mapped unit step on x-axis

Example

See Also

isFixedStepInX getType


cheapEqualTo

bool cheapEqualTo(const SkMatrix& m) const

Returns true if Matrix equals m, using an efficient comparison.

Returns false when the sign of zero values is the different; when one matrix has positive zero value and the other has negative zero value.

Returns true even when both Matrices contain NaN.

NaN never equals any value, including itself. To improve performance, NaN values are treated as bit patterns that are equal if their bit patterns are equal.

Parameters

m Matrix to compare

Return Value

true if m and Matrix are represented by identical bit patterns

Example

#### Example Output ~~~~ identity: a == b a.cheapEqualTo(b): true neg zero: a == b a.cheapEqualTo(b): false one NaN: a != b a.cheapEqualTo(b): false both NaN: a != b a.cheapEqualTo(b): true ~~~~

See Also

operator==(const SkMatrix& a, const SkMatrix& b)


operator==

bool operator==(const SkMatrix& a, const SkMatrix& b)

Compares a and b; returns true if a and b are numerically equal. Returns true even if sign of zero values are different. Returns false if either Matrix contains NaN, even if the other Matrix also contains NaN.

Parameters

a Matrix to compare
b Matrix to compare

Return Value

true if Matrix a and Matrix b are numerically equal

Example

#### Example Output ~~~~ identity: a == b a.cheapEqualTo(b): true ~~~~

See Also

cheapEqualTo operator!=(const SkMatrix& a, const SkMatrix& b)


operator!=

bool operator!=(const SkMatrix& a, const SkMatrix& b)

Compares a and b; returns true if a and b are not numerically equal. Returns false even if sign of zero values are different. Returns true if either Matrix contains NaN, even if the other Matrix also contains NaN.

Parameters

a Matrix to compare
b Matrix to compare

Return Value

true if Matrix a and Matrix b are numerically not equal

Example

See Also

cheapEqualTo operator==(const SkMatrix& a, const SkMatrix& b)


Utility

Topic Description
dirtyMatrixTypeCache sets internal cache to unknown state
dump sends text representation using floats to standard output

dump

void dump() const

Writes text representation of Matrix to standard output. Floating point values are written with limited precision; it may not be possible to reconstruct original Matrix from output.

Example

#### Example Output ~~~~ [ 0.7071 -0.7071 0.0000][ 0.7071 0.7071 0.0000][ 0.0000 0.0000 1.0000] [ 0.7071 -0.7071 0.0000][ 0.7071 0.7071 0.0000][ 0.0000 0.0000 1.0000] matrix != nearlyEqual ~~~~

See Also

SkPath::dump[2]


getMinScale

SkScalar getMinScale() const

Returns the minimum scaling factor of Matrix by decomposing the scaling and skewing elements. Returns -1 if scale factor overflows or Matrix contains perspective.

Return Value

minimum scale factor

Example

#### Example Output ~~~~ matrix.getMinScale() 24 ~~~~

See Also

getMaxScale getMinMaxScales


getMaxScale

SkScalar getMaxScale() const

Returns the maximum scaling factor of Matrix by decomposing the scaling and skewing elements. Returns -1 if scale factor overflows or Matrix contains perspective.

Return Value

maximum scale factor

Example

#### Example Output ~~~~ matrix.getMaxScale() 42 ~~~~

See Also

getMinScale getMinMaxScales


getMinMaxScales

bool SK_WARN_UNUSED_RESULT getMinMaxScales(SkScalar scaleFactors[2]) const

Sets scaleFactors[0] to the minimum scaling factor, and scaleFactors[1] to the maximum scaling factor. Scaling factors are computed by decomposing the Matrix scaling and skewing elements.

Returns true if scaleFactors are found; otherwise, returns false and sets scaleFactors to undefined values.

Parameters

scaleFactors storage for minimum and maximum scale factors

Return Value

true if scale factors were computed correctly

Example

#### Example Output ~~~~ matrix.getMinMaxScales() false 2 2 ~~~~

See Also

getMinScale getMaxScale


decomposeScale

bool decomposeScale(SkSize* scale, SkMatrix* remaining = nullptr) const

Decomposes Matrix into scale components and whatever remains. Returns false if Matrix could not be decomposed.

Sets scale to portion of Matrix that scale axes. Sets remaining to Matrix with scaling factored out. remaining may be passed as nullptr to determine if Matrix can be decomposed without computing remainder.

Returns true if scale components are found. scale and remaining are unchanged if Matrix contains perspective; scale factors are not finite, or are nearly zero.

On successMatrix = scale * Remaining

Parameters

scale axes scaling factors; may be nullptr
remaining Matrix without scaling; may be nullptr

Return Value

true if scale can be computed

Example

#### Example Output ~~~~ [ 0.0000 -0.2500 0.0000][ 0.5000 0.0000 0.0000][ 0.0000 0.0000 1.0000] success: true scale: 0.5, 0.25 [ 0.0000 -0.5000 0.0000][ 2.0000 0.0000 0.0000][ 0.0000 0.0000 1.0000] [ 0.0000 -0.2500 0.0000][ 0.5000 0.0000 0.0000][ 0.0000 0.0000 1.0000] ~~~~

See Also

setScale[2] MakeScale[2]


I

static const SkMatrix& I()

Returns reference to const identity Matrix. Returned Matrix is set to:

| 1 0 0 |
| 0 1 0 |
| 0 0 1 |

Return Value

const identity Matrix

Example

#### Example Output ~~~~ m1 == m2 m2 == m3 ~~~~

See Also

reset setIdentity


InvalidMatrix

static const SkMatrix& InvalidMatrix()

Returns reference to a const Matrix with invalid values. Returned Matrix is set to:

| SK_ScalarMax SK_ScalarMax SK_ScalarMax |
| SK_ScalarMax SK_ScalarMax SK_ScalarMax |
| SK_ScalarMax SK_ScalarMax SK_ScalarMax |

Return Value

const invalid Matrix

Example

#### Example Output ~~~~ scaleX 3.40282e+38 ~~~~

See Also

SeeAlso getType


Concat

static SkMatrix Concat(const SkMatrix& a, const SkMatrix& b)

Returns Matrix a multiplied by Matrix b.

Given:

    | A B C |      | J K L |
a = | D E F |, b = | M N O |
    | G H I |      | P Q R |

sets Matrix to:

        | A B C |   | J K L |   | AJ+BM+CP AK+BN+CQ AL+BO+CR |
a * b = | D E F | * | M N O | = | DJ+EM+FP DK+EN+FQ DL+EO+FR |
        | G H I |   | P Q R |   | GJ+HM+IP GK+HN+IQ GL+HO+IR |

Parameters

a Matrix on left side of multiply expression
b Matrix on right side of multiply expression

Return Value

Matrix computed from a times b

Example

setPolyToPoly creates perspective matrices, one the inverse of the other. Multiplying the matrix by its inverse turns into an identity matrix.

See Also

preConcat postConcat


dirtyMatrixTypeCache

void dirtyMatrixTypeCache()

Sets internal cache to unknown state. Use to force update after repeated modifications to Matrix element reference returned by operator[](int index).

Example

#### Example Output ~~~~ with identity matrix: x = 24 after skew x mod: x = 24 after 2nd skew x mod: x = 24 after dirty cache: x = 66 ~~~~

See Also

operator[](int index) getType


setScaleTranslate

void setScaleTranslate(SkScalar sx, SkScalar sy, SkScalar tx, SkScalar ty)

Initializes Matrix with scale and translate elements.

| sx  0 tx |
|  0 sy ty |
|  0  0  1 |

Parameters

sx horizontal scale factor to store
sy vertical scale factor to store
tx horizontal translation to store
ty vertical translation to store

Example

#### Example Output ~~~~ [ 1.0000 0.0000 3.0000][ 0.0000 2.0000 4.0000][ 0.0000 0.0000 1.0000] ~~~~

See Also

setScale[2] preTranslate postTranslate


isFinite

bool isFinite() const

Returns true if all elements of the matrix are finite. Returns false if any element is infinity, or NaN.

Return Value

true if matrix has only finite elements

Example

#### Example Output ~~~~ [ 1.0000 0.0000 nan][ 0.0000 1.0000 0.0000][ 0.0000 0.0000 1.0000] matrix is finite: false matrix != matrix ~~~~

See Also

operator==