SkMatrix Reference

Matrix

Overview

Overview Subtopic

namedescription
Constantenum and enum class, const values
Constructorfunctions that construct SkMatrix
Member Functionstatic functions and member methods
Operatoroperator overloading methods
Related Functionsimilar methods grouped together

Class SkMatrix

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.

Member Function

namedescription
Concatreturns the concatenation of Matrix pair
Ireturns a reference to a const identity Matrix
InvalidMatrixreturns a reference to a const invalid Matrix
MakeAllconstructs all nine values
MakeRectToRectconstructs from source Rect to destination Rect
MakeScaleconstructs from scale in x and y
MakeTransconstructs from translate in x and y
SetAffineIdentitysets 3x2 array to identity
asAffinecopies to 3x2 array
cheapEqualTocompares Matrix pair using memcmp()
decomposeScaleseparates scale if possible
dirtyMatrixTypeCachesets internal cache to unknown state
dumpsends text representation using floats to standard output
fixedStepInXreturns step in x for a position in y
getreturns one of nine Matrix values
get9returns all nine Matrix values
getMaxScalereturns maximum scaling, if possible
getMinMaxScalesreturns minimum and maximum scaling, if possible
getMinScalereturns minimum scaling, if possible
getPerspXreturns input x perspective factor
getPerspYreturns input y perspective factor
getScaleXreturns horizontal scale factor
getScaleYreturns vertical scale factor
getSkewXreturns horizontal skew factor
getSkewYreturns vertical skew factor
getTranslateXreturns horizontal translation
getTranslateYreturns vertical translation
getTypereturns transform complexity
hasPerspectivereturns if transform includes perspective
invertreturns inverse, if possible
isFinitereturns if all Matrix values are not infinity, NaN
isFixedStepInXreturns if transformation supports fixed step in x
isIdentityreturns if matrix equals the identity Matrix
isScaleTranslatereturns if transform is limited to scale and translate
isSimilarityreturns if transform is limited to square scale and rotation
isTranslatereturns if transform is limited to translate
mapHomogeneousPointsmaps Point3 array
mapPointsmaps Point array
mapRadiusreturns mean radius of mapped Circle
mapRectreturns bounds of mapped Rect
mapRectScaleTranslatereturns bounds of mapped Rect
mapRectToQuadmaps Rect to Point array
mapVectormaps Vector
mapVectorsmaps Vector array
mapXYmaps Point
postConcatpost-multiplies Matrix by Matrix parameter
postIDivpost-multiplies Matrix by inverse scale
postRotatepost-multiplies Matrix by rotation
postScalepost-multiplies Matrix by scale
postSkewpost-multiplies Matrix by skew
postTranslatepost-multiplies Matrix by translation
preConcatpre-multiplies Matrix by Matrix parameter
preRotatepre-multiplies Matrix by rotation
preScalepre-multiplies Matrix by scale
preSkewpre-multiplies Matrix by skew
preTranslatepre-multiplies Matrix by translation
preservesAxisAlignmentreturns if mapping restricts to 90 degree multiples and mirroring
preservesRightAnglesreturns if mapped 90 angle remains 90 degrees
rectStaysRectreturns if mapped Rect can be represented by another Rect
resetsets Matrix to identity
setsets one value
set9sets all values from Scalar array
setAffinesets left two columns
setAllsets all values from parameters
setConcatsets to Matrix parameter multiplied by Matrix parameter
setIdentitysets Matrix to identity
setPerspXsets input x perspective factor
setPerspYsets input y perspective factor
setPolyToPolysets to map one to four points to an equal array of points
setRSXformsets to rotate, scale, and translate
setRectToRectsets to map one Rect to another
setRotatesets to rotate about a point
setScalesets to scale about a point
setScaleTranslatesets to scale and translate
setScaleXsets horizontal scale factor
setScaleYsets vertical scale factor
setSinCossets to rotate and scale about a point
setSkewsets to skew about a point
setSkewXsets horizontal skew factor
setSkewYsets vertical skew factor
setTranslatesets to translate in x and y
setTranslateXsets horizontal translation
setTranslateYsets vertical translation
toStringconverts Matrix to machine readable form

Related Function

namedescription
Propertyvalues and attributes
Setset one or more matrix values
Transformmap points with Matrix
Utilityrarely called management functions

Constructor

namedescription
Ireturns a reference to a const identity Matrix
InvalidMatrixreturns a reference to a const invalid Matrix
MakeAllconstructs all nine values
MakeRectToRectconstructs from source Rect to destination Rect
MakeScaleconstructs from scale in x and y
MakeScale(SkScalar sx, SkScalar sy)
MakeScale(SkScalar scale)
MakeTransconstructs from translate in x and y
SetAffineIdentitysets 3x2 array to identity
asAffinecopies to 3x2 array
resetsets Matrix to identity
setAffinesets left two columns
setConcatsets to Matrix parameter multiplied by Matrix parameter
setIdentitysets Matrix to identity
setRSXformsets to rotate, scale, and translate
setRotatesets to rotate about a point
setRotate(SkScalar degrees, SkScalar px, SkScalar py)
setRotate(SkScalar degrees)
setScalesets to scale about a point
setScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
setScale(SkScalar sx, SkScalar sy)
setScaleTranslatesets to scale and translate
setSinCossets to rotate and scale about a point
setSinCos(SkScalar sinValue, SkScalar cosValue, SkScalar px, SkScalar py)
setSinCos(SkScalar sinValue, SkScalar cosValue)
setSkewsets to skew about a point
setSkew(SkScalar kx, SkScalar ky, SkScalar px, SkScalar py)
setSkew(SkScalar kx, SkScalar ky)
setTranslatesets to translate in x and y
setTranslate(SkScalar dx, SkScalar dy)
setTranslate(const SkVector& v)

MakeScale

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

Parameters

Return Value

Matrix with scale

Example

See Also

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


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

Parameters

Return Value

Matrix with scale

Example

See Also

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


MakeTrans

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

Parameters

Return Value

Matrix with translation

Example

See Also

setTranslate[2] postTranslate preTranslate


MakeAll

Sets Matrix to:

Parameters

Return Value

Matrix constructed from parameters

Example

See Also

setAll set9 postConcat preConcat


Enum SkMatrix::TypeMask

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

Constants

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

namedescription
decomposeScaleseparates scale if possible
fixedStepInXreturns step in x for a position in y
getreturns one of nine Matrix values
get9returns all nine Matrix values
getMaxScalereturns maximum scaling, if possible
getMinMaxScalesreturns minimum and maximum scaling, if possible
getMinScalereturns minimum scaling, if possible
getPerspXreturns input x perspective factor
getPerspYreturns input y perspective factor
getScaleXreturns horizontal scale factor
getScaleYreturns vertical scale factor
getSkewXreturns horizontal skew factor
getSkewYreturns vertical skew factor
getTranslateXreturns horizontal translation
getTranslateYreturns vertical translation
getTypereturns transform complexity
hasPerspectivereturns if transform includes perspective
isFinitereturns if all Matrix values are not infinity, NaN
isFixedStepInXreturns if transformation supports fixed step in x
isIdentityreturns if matrix equals the identity Matrix
isScaleTranslatereturns if transform is limited to scale and translate
isSimilarityreturns if transform is limited to square scale and rotation
isTranslatereturns if transform is limited to translate
preservesAxisAlignmentreturns if mapping restricts to 90 degree multiples and mirroring
preservesRightAnglesreturns if mapped 90 angle remains 90 degrees
rectStaysRectreturns if mapped Rect can be represented by another Rect

getType

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

Returns true if Matrix is identity. Identity matrix is:

Return Value

true if Matrix has no effect

Example

Example Output

is identity: true
is identity: false

See Also

reset setIdentity getType


isScaleTranslate

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:

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

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

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

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

or

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

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

or

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

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

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

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

Return Value

true if Matrix only rotates, uniformly scales, translates

Example

See Also

isScaleTranslate preservesRightAngles rectStaysRect isFixedStepInX


preservesRightAngles

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

Return Value

true if Matrix only rotates, scales, translates

Example

See Also

isScaleTranslate isSimilarity rectStaysRect isFixedStepInX


Enum SkMatrix::_anonymous

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

Constants

Example

See Also

get set

Enum SkMatrix::_anonymous_2

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

Constants

See Also

SetAffineIdentity asAffine setAffine

Operator

namedescription
Concatreturns the concatenation of Matrix pair
cheapEqualTocompares Matrix pair using memcmp()
invertreturns 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) constreturns Matrix value

operator[]

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

Parameters

Return Value

value corresponding to index

Example

Example Output

matrix[SkMatrix::kMScaleX] == 42
matrix[SkMatrix::kMScaleY] == 24

See Also

get set


get

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

Parameters

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

Returns scale factor multiplied by x input, contributing to x 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

Returns scale factor multiplied by y input, contributing to y 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

Returns scale factor multiplied by x input, contributing to y output. With mapPoints, skews Points along the y-axis. Skew x and y together can rotate Points.

Return Value

vertical skew factor

Example

Example Output

matrix.getSkewY() == 24

See Also

get getSkewX setSkewY setSkew[2]


getSkewX

Returns scale factor multiplied by y input, contributing to x output. With mapPoints, skews Points along the x-axis. Skew x and y together can rotate Points.

Return Value

horizontal scale factor

Example

Example Output

matrix.getSkewX() == 42

See Also

get getSkewY setSkewX setSkew[2]


getTranslateX

Returns translation contributing to x 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

Returns translation contributing to y 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

Returns factor scaling input x relative to input y.

Return Value

input x perspective factor

Example

See Also

kMPersp0 getPerspY


getPerspY

Returns factor scaling input y relative to input x.

Return Value

input y perspective factor

Example

See Also

kMPersp1 getPerspX


operator[]

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

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

namedescription
postConcatpost-multiplies Matrix by Matrix parameter
postIDivpost-multiplies Matrix by inverse scale
postRotatepost-multiplies Matrix by rotation
postRotate(SkScalar degrees, SkScalar px, SkScalar py)
postRotate(SkScalar degrees)
postScalepost-multiplies Matrix by scale
postScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
postScale(SkScalar sx, SkScalar sy)
postSkewpost-multiplies Matrix by skew
postSkew(SkScalar kx, SkScalar ky, SkScalar px, SkScalar py)
postSkew(SkScalar kx, SkScalar ky)
postTranslatepost-multiplies Matrix by translation
preConcatpre-multiplies Matrix by Matrix parameter
preRotatepre-multiplies Matrix by rotation
preRotate(SkScalar degrees, SkScalar px, SkScalar py)
preRotate(SkScalar degrees)
preScalepre-multiplies Matrix by scale
preScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
preScale(SkScalar sx, SkScalar sy)
preSkewpre-multiplies Matrix by skew
preSkew(SkScalar kx, SkScalar ky, SkScalar px, SkScalar py)
preSkew(SkScalar kx, SkScalar ky)
preTranslatepre-multiplies Matrix by translation
setsets one value
set9sets all values from Scalar array
setAllsets all values from parameters
setPerspXsets input x perspective factor
setPerspYsets input y perspective factor
setPolyToPolysets to map one to four points to an equal array of points
setRectToRectsets to map one Rect to another
setScaleXsets horizontal scale factor
setScaleYsets vertical scale factor
setSkewXsets horizontal skew factor
setSkewYsets vertical skew factor
setTranslateXsets horizontal translation
setTranslateYsets vertical translation

set

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

Parameters

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

Sets horizontal scale factor.

Parameters

Example

See Also

set setScale[2] setScaleY


setScaleY

Sets vertical scale factor.

Parameters

Example

See Also

set setScale[2] setScaleX


setSkewY

Sets vertical skew factor.

Parameters

Example

See Also

set setSkew[2] setSkewX


setSkewX

Sets horizontal skew factor.

Parameters

Example

See Also

set setSkew[2] setSkewX


setTranslateX

Sets horizontal translation.

Parameters

Example

See Also

set setTranslate[2] setTranslateY


setTranslateY

Sets vertical translation.

Parameters

Example

See Also

set setTranslate[2] setTranslateX


setPerspX

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

Parameters

Example

See Also

getPerspX set setAll set9 MakeAll


setPerspY

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

Parameters

Example

See Also

getPerspY set setAll set9 MakeAll


setAll

Sets all values from parameters. Sets matrix to:

Parameters

Example

See Also

set9 MakeAll


get9

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

Parameters

Example

Example Output

{4, 0, 3},
{0, 5, 4},
{0, 0, 1}

See Also

set9


set9

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:

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

Example

See Also

setAll get9 MakeAll


reset

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

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

Example

Example Output

m.isIdentity(): true

See Also

isIdentity setIdentity


setIdentity

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

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

Example

Example Output

m.isIdentity(): true

See Also

isIdentity reset


setTranslate

Sets Matrix to translate by (dx, dy).

Parameters

Example

See Also

setTranslateX setTranslateY


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

Parameters

Example

See Also

setTranslateX setTranslateY MakeTrans


setScale

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

Example

See Also

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


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

Parameters

Example

See Also

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


setRotate

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

Example

See Also

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


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

Parameters

Example

See Also

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


setSinCos

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

Example

See Also

setRotate[2] setScale[2] setRSXform


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

Example

See Also

setRotate[2] setScale[2] setRSXform


setRSXform

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

Return Value

reference to Matrix

Example

See Also

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


setSkew

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

Example

See Also

setSkewX setSkewY preSkew[2] postSkew[2]


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

Parameters

Example

See Also

setSkewX setSkewY preSkew[2] postSkew[2]


setConcat

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

Given:

sets Matrix to:

Parameters

Example

See Also

Concat preConcat postConcat SkCanvas::concat


preTranslate

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:

sets Matrix to:

Parameters

Example

See Also

postTranslate setTranslate[2] MakeTrans


preScale

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:

where

sets Matrix to:

Parameters

Example

See Also

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


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:

sets Matrix to:

Parameters

Example

See Also

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


preRotate

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:

where

sets Matrix to:

Parameters

Example

See Also

postRotate[2] setRotate[2]


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:

where

sets Matrix to:

Parameters

Example

See Also

postRotate[2] setRotate[2]


preSkew

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:

where

sets Matrix to:

Parameters

Example

See Also

postSkew[2] setSkew[2]


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:

sets Matrix to:

Parameters

Example

See Also

postSkew[2] setSkew[2]


preConcat

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

Given:

sets Matrix to:

Parameters

Example

See Also

postConcat setConcat Concat


postTranslate

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:

sets Matrix to:

Parameters

Example

See Also

preTranslate setTranslate[2] MakeTrans


postScale

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:

where

sets Matrix to:

Parameters

Example

See Also

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


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:

sets Matrix to:

Parameters

Example

See Also

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


postIDiv

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:

where

sets Matrix to:

Parameters

Return Value

true on successful scale

Example

See Also

postScale[2] MakeScale[2]


postRotate

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:

where

sets Matrix to:

Parameters

Example

See Also

preRotate[2] setRotate[2]


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:

where

sets Matrix to:

Parameters

Example

See Also

preRotate[2] setRotate[2]


postSkew

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:

where

sets Matrix to:

Parameters

Example

See Also

preSkew[2] setSkew[2]


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:

sets Matrix to:

Parameters

Example

See Also

preSkew[2] setSkew[2]


postConcat

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

Given:

sets Matrix to:

Parameters

Example

See Also

preConcat setConcat Concat


Enum SkMatrix::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

Example

See Also

setRectToRect MakeRectToRect setPolyToPoly

setRectToRect

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:

Parameters

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

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:

Parameters

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

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

Return Value

true if Matrix was constructed successfully

Example

See Also

setRectToRect MakeRectToRect


invert

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

Return Value

true if Matrix can be inverted

Example

See Also

Concat


SetAffineIdentity

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

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

Parameters

Example

Example Output

ScaleX: 1 SkewY: 0 SkewX: 0 ScaleY: 1 TransX: 0 TransY: 0

See Also

setAffine asAffine


asAffine

Fills affine in column major order. Sets affine to:

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

Parameters

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

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

Matrix is set, row, then column, to:

Parameters

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

namedescription
mapHomogeneousPointsmaps Point3 array
mapPointsmaps Point array
mapPoints(SkPoint dst[], const SkPoint src[], int count) const
mapPoints(SkPoint pts[], int count) const
mapRadiusreturns mean radius of mapped Circle
mapRectreturns bounds of mapped Rect
mapRect(SkRect* dst, const SkRect& src) const
mapRect(SkRect* rect) const
mapRectScaleTranslatereturns bounds of mapped Rect
mapRectToQuadmaps Rect to Point array
mapVectormaps Vector
mapVector(SkScalar dx, SkScalar dy, SkVector* result) const
mapVector(SkScalar dx, SkScalar dy) const
mapVectorsmaps Vector array
mapVectors(SkVector dst[], const SkVector src[], int count) const
mapVectors(SkVector vecs[], int count) const
mapXYmaps Point
mapXY(SkScalar x, SkScalar y, SkPoint* result) const
mapXY(SkScalar x, SkScalar y) const

mapPoints

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:

where

each dst Point is computed as:

src and dst may point to the same storage.

Parameters

Example

See Also

mapXY[2] mapHomogeneousPoints mapVectors[2]


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

where

each resulting pts Point is computed as:

Parameters

Example

See Also

mapXY[2] mapHomogeneousPoints mapVectors[2]


mapHomogeneousPoints

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:

each resulting dst Point is computed as:

Parameters

Example

See Also

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


mapXY

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

result is computed as:

Parameters

Example

See Also

mapPoints[2] mapVectors[2]


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

result is computed as:

Parameters

Return Value

mapped Point

Example

See Also

mapPoints[2] mapVectors[2]


mapVectors

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:

where

each dst Vector is computed as:

src and dst may point to the same storage.

Parameters

Example

See Also

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


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

where

each result Vector is computed as:

Parameters

Example

See Also

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


mapVector

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

each result Vector is computed as:

Parameters

Example

See Also

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


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

each result Vector is computed as:

Parameters

Return Value

mapped Vector

Example

See Also

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


mapRect

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

Return Value

true if dst is equivalent to mapped src

Example

See Also

mapPoints[2] rectStaysRect


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

Return Value

true if result is equivalent to mapped src

Example

See Also

mapRectScaleTranslate mapPoints[2] rectStaysRect


mapRectToQuad

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:

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:

Parameters

Example

See Also

mapRect[2] mapRectScaleTranslate


mapRectScaleTranslate

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

Example

See Also

mapRect[2] mapRectToQuad isScaleTranslate rectStaysRect


mapRadius

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

Return Value

average mapped radius

Example

See Also

mapVector[2]


isFixedStepInX

Returns true if a unit step in x at some y 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

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

Parameters

Return Value

Vector advance of mapped unit step in x

Example

See Also

isFixedStepInX getType


cheapEqualTo

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

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==

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

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!=

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

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

namedescription
dirtyMatrixTypeCachesets internal cache to unknown state
dumpsends text representation using floats to standard output
toStringconverts Matrix to machine readable form

dump

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

toString


toString

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

Parameters

Example

Example Output

mStr  [  0.7071  -0.7071   0.0000][  0.7071   0.7071   0.0000][  0.0000   0.0000   1.0000]
neStr [  0.7071  -0.7071   0.0000][  0.7071   0.7071   0.0000][  0.0000   0.0000   1.0000]
matrix != nearlyEqual

See Also

dump


getMinScale

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

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

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

Return Value

true if scale factors were computed correctly

Example

Example Output

matrix.getMinMaxScales() false 2 2

See Also

getMinScale getMaxScale


decomposeScale

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

Sets scale to portion of Matrix that scales in x and y. Sets remaining to Matrix with x and y 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

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

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

Return Value

const identity Matrix

Example

Example Output

m1 == m2
m2 == m3

See Also

reset setIdentity


InvalidMatrix

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

Return Value

const invalid Matrix

Example

Example Output

scaleX 3.40282e+38

See Also

SeeAlso getType


Concat

Returns Matrix a multiplied by Matrix b.

Given:

sets Matrix to:

Parameters

Return Value

Matrix computed from a times b

Example

See Also

preConcat postConcat


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

Initializes Matrix with scale and translate elements.

Parameters

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

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==