SkMatrix Reference === # Matrix # 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. # Overview ## Subtopics | topics | description | | --- | --- | ## Operators | function | description | | --- | --- | | 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) const | Returns Matrix value. | | operator[](int index) | Returns writable reference to Matrix value. | ## Member Functions | function | 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. | | toString | Converts Matrix to machine readable form. | ## 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 postScale preScale ---
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 postScale preScale --- ## 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 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 perspective factor
pers1 input y 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
SkMatrix::kIdentity_Mask 0all bits clear if Matrix is identity
SkMatrix::kTranslate_Mask 1set if Matrix has translation
SkMatrix::kScale_Mask 2set if Matrix has x or y scale
SkMatrix::kAffine_Mask 4set if Matrix skews or rotates
SkMatrix::kPerspective_Mask 8set 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 ## 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 isTranslate setTranslate 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 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 in x or y. 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 in x or y. 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 --- ## Enum SkMatrix::_anonymous
enum {
kMScaleX,
kMSkewX,
kMTransX,
kMSkewY,
kMScaleY,
kMTransY,
kMPersp0,
kMPersp1,
kMPersp2,
};
Matrix organizes its values in row order. These members correspond to each value in Matrix. ### Constants
SkMatrix::kMScaleX 0horizontal scale factor
SkMatrix::kMSkewX 1horizontal skew factor
SkMatrix::kMTransX 2horizontal translation
SkMatrix::kMSkewY 3vertical skew factor
SkMatrix::kMScaleY 4vertical scale factor
SkMatrix::kMTransY 5vertical translation
SkMatrix::kMPersp0 6input x perspective factor
SkMatrix::kMPersp1 7input y perspective factor
SkMatrix::kMPersp2 8perspective bias
### Example
### See Also get set ## Enum SkMatrix::_anonymous_2
enum {
kAScaleX,
kASkewY,
kASkewX,
kAScaleY,
kATransX,
kATransY,
};
Affine arrays are in column major order to match the matrix used by PDF and XPS. ### Constants
SkMatrix::kAScaleX 0horizontal scale factor
SkMatrix::kASkewY 1vertical skew factor
SkMatrix::kASkewX 2horizontal skew factor
SkMatrix::kAScaleY 3vertical scale factor
SkMatrix::kATransX 4horizontal translation
SkMatrix::kATransY 5vertical translation
### See Also SetAffineIdentity asAffine setAffine ## 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 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 --- ## getScaleY
SkScalar getScaleY() const
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 --- ## getSkewY
SkScalar getSkewY() const
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 --- ## getSkewX
SkScalar getSkewX() const
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 --- ## getTranslateX
SkScalar getTranslateX() const
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 --- ## getTranslateY
SkScalar getTranslateY() const
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 --- ## getPerspX
SkScalar getPerspX() const
Returns factor scaling input x relative to input y. ### Return Value input x perspective factor ### Example
### See Also kMPersp0 getPerspY --- ## getPerspY
SkScalar getPerspY() const
Returns factor scaling input y relative to input x. ### Return Value input y 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
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 setScaleY --- ## setScaleY
void setScaleY(SkScalar v)
Sets vertical scale factor. ### Parameters
v vertical scale factor to store
### Example
### See Also set setScale setScaleX --- ## setSkewY
void setSkewY(SkScalar v)
Sets vertical skew factor. ### Parameters
v vertical skew factor to store
### Example
### See Also set setSkew setSkewX --- ## setSkewX
void setSkewX(SkScalar v)
Sets horizontal skew factor. ### Parameters
v horizontal skew factor to store
### Example
### See Also set setSkew setSkewX --- ## setTranslateX
void setTranslateX(SkScalar v)
Sets horizontal translation. ### Parameters
v horizontal translation to store
### Example
### See Also set setTranslate setTranslateY --- ## setTranslateY
void setTranslateY(SkScalar v)
Sets vertical translation. ### Parameters
v vertical translation to store
### Example
### See Also set setTranslate setTranslateX --- ## setPerspX
void setPerspX(SkScalar v)
Sets input x perspective factor, which causes mapXY to vary input x inversely proportional to input y. ### Parameters
v perspective factor
### Example
### See Also getPerspX set setAll set9 MakeAll --- ## setPerspY
void setPerspY(SkScalar v)
Sets input y perspective factor, which causes mapXY to vary input y inversely proportional to input x. ### 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 perspective factor to store
persp1 input y 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 preScale postScale ---
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 preScale postScale --- ## 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 preRotate postRotate ---
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 preRotate postRotate --- ## 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 component
cosValue rotation vector y component
px pivot x
py pivot y
### Example
### See Also setRotate setScale 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 component
cosValue rotation vector y component
### Example
Canvas needs offset after applying Matrix to pivot about Rect center.
### See Also setRotate setScale 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 setScale setTranslate --- ## 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 postSkew ---
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 postSkew --- ## 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 translation before applying Matrix
dy y translation before applying Matrix
### Example
### See Also postTranslate setTranslate 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 setScale MakeScale ---
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 setScale MakeScale --- ## 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 setRotate ---
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 setRotate --- ## 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 setSkew ---
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 setSkew --- ## 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 translation after applying Matrix
dy y translation after applying Matrix
### Example
Compare with preTranslate example.
### See Also preTranslate setTranslate 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 setScale MakeScale ---
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 setScale MakeScale --- ## 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 MakeScale --- ## 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 setRotate ---
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 setRotate --- ## 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 setSkew ---
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 setSkew --- ## 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
SkMatrix::kFill_ScaleToFit 0Computes 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 1Computes 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 2Computes 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 3Computes 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 --- ## 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 mapHomogeneousPoints mapVectors ---
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 mapHomogeneousPoints mapVectors --- ## 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 mapXY mapVectors --- ## 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-coordinate of Point to map
y y-coordinate of Point to map
result storage for mapped Point
### Example
### See Also mapPoints mapVectors ---
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-coordinate of Point to map
y y-coordinate of Point to map
### Return Value mapped Point ### Example
### See Also mapPoints mapVectors --- ## 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 mapPoints mapXY ---
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 mapPoints mapXY --- ## 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-coordinate of Vector to map
dy y-coordinate of Vector to map
result storage for mapped Vector
### Example
### See Also mapVectors mapPoints mapXY ---
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-coordinate of Vector to map
dy y-coordinate of Vector to map
### Return Value mapped Vector ### Example
### See Also mapVectors mapPoints mapXY --- ## 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 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 rectStaysRect --- ## 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 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 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 --- ## isFixedStepInX
bool isFixedStepInX() const
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
SkVector fixedStepInX(SkScalar y) const
Returns Vector representing a unit step in x 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 in x ### 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 m and Matrix 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 m and Matrix are numerically not equal ### Example
### See Also cheapEqualTo operator==(const SkMatrix& a, const SkMatrix& b) --- ## 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 toString --- ## toString
void toString(SkString* str) const
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
str storage for string representation of Matrix
### 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
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 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
scale x and y 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 MakeScale --- ## 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 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== ---