Matrix
- class Matrix
Matrix
holds a 3x3 matrix for transforming coordinates.This allows mapping
Point
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()
initializesMatrix
so it has no effect.setTranslate()
,setScale()
,setSkew()
,setRotate()
,set9()
andsetAll()
initializes allMatrix
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.Classes
Members:
Members:
Methods
Returns reference to const identity
Matrix
.Returns reference to a const
Matrix
with invalid values.Sets
Matrix
to.Returns
Matrix
set to scale and translate srcRect
to dstRect
.Overloaded function.
Sets
Matrix
to scale by (sx, sy).Fills affine with identity values in column major order.
Overloaded function.
Overloaded function.
Fills affine in column major order.
Decomposes
Matrix
into scale components and whatever remains.Sets internal cache to unknown state.
Writes text representation of
Matrix
to standard output.Returns one matrix value.
Returns nine scalar values contained by
Matrix
into list, in member value ascending order: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY, kMPersp0, kMPersp1, kMPersp2.Returns the maximum scaling factor of
Matrix
by decomposing the scaling and skewing elements.Returns the minimum scaling factor and the maximum scaling factor.
Returns the minimum scaling factor of
Matrix
by decomposing the scaling and skewing elements.Returns factor scaling input x-axis relative to input y-axis.
Returns factor scaling input y-axis relative to input x-axis.
Returns scale factor multiplied by x-axis input, contributing to x-axis output.
Returns scale factor multiplied by y-axis input, contributing to y-axis output.
Returns scale factor multiplied by y-axis input, contributing to x-axis output.
Returns scale factor multiplied by x-axis input, contributing to y-axis output.
Returns translation contributing to x-axis output.
Returns translation contributing to y-axis output.
Returns a bit field describing the transformations the matrix may perform.
Returns true if the matrix contains perspective elements.
Sets inverse to reciprocal matrix, returning true if
Matrix
can be inverted.Returns true if all elements of the matrix are finite.
Returns true if
Matrix
is identity.Returns true if
Matrix
at most scales and translates.Returns true if
Matrix
contains only translation, rotation, reflection, and uniform scale.Returns true if
Matrix
is identity, or translates.Overloaded function.
Returns geometric mean radius of ellipse formed by constructing circle of size radius, and mapping constructed circle with
Matrix
.Returns bounds of src corners mapped by
Matrix
.Returns bounds of src corners mapped by
Matrix
.Maps four corners of rect to dst.
Returns vector (dx, dy) multiplied by
Matrix
, treatingMatrix
translation as zero.Maps src vector array to vector
Point
array.A matrix is categorized as 'perspective' if the bottom row is not [0, 0, 1].
Overloaded function.
Overloaded function.
Overloaded function.
Sets
Matrix
toMatrix
constructed from translation (dx, dy) multiplied byMatrix
.Overloaded function.
Overloaded function.
Overloaded function.
Sets
Matrix
toMatrix
multiplied byMatrix
constructed from translation (dx, dy).Returns true if
Matrix
contains only translation, rotation, reflection, and scale.Returns one matrix value from a particular row/column.
Returns true SkMatrix maps SkRect to another SkRect.
Sets
Matrix
to identity; which has no effect on mappedPoint
.Returns writable
Matrix
value.Sets
Matrix
to nine scalar values in values, in member value ascending order: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY, kMPersp0, kMPersp1, kMPersp2.Sets
Matrix
to affine values, passed in column major order.Sets all values from parameters.
Sets
Matrix
to identity; which has no effect on mappedPoint
.Sets input x-axis perspective factor, which causes mapXY() to vary input x-axis values inversely proportional to input y-axis values.
Sets input y-axis perspective factor, which causes mapXY() to vary input y-axis values inversely proportional to input x-axis values.
Sets
Matrix
to map src to dst.Sets
Matrix
to rotate, scale, and translate using a compressed matrix form.Overloaded function.
Overloaded function.
Initializes
Matrix
with scale and translate elements.Sets horizontal scale factor.
Sets vertical scale factor.
Overloaded function.
Overloaded function.
Sets horizontal skew factor.
Sets vertical skew factor.
Overloaded function.
Sets horizontal translation.
Sets vertical translation.
Attributes
Methods
- static Matrix.Concat(a: skia.Matrix, b: skia.Matrix) skia.Matrix
Returns
Matrix
a multiplied byMatrix
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 (skia.Matrix) –
Matrix
on left side of multiply expressionb (skia.Matrix) –
Matrix
on right side of multiply expression
- Returns:
Matrix
computed from a times b
- static Matrix.I() skia.Matrix
Returns reference to const identity
Matrix
.Returned
Matrix
is set to:1 0 0 |0 1 0 |0 0 1 |- Returns:
const identity
Matrix
- static Matrix.InvalidMatrix() skia.Matrix
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 |- Returns:
const invalid
Matrix
- static Matrix.MakeAll(scaleX: float, skewX: float, transX: float, skewY: float, scaleY: float, transY: float, pers0: float, pers1: float, pers2: float) skia.Matrix
Sets
Matrix
to:| scaleX skewX transX | | skewY scaleY transY | | pers0 pers1 pers2 |
- Parameters:
scaleX (float) – horizontal scale factor
skewX (float) – horizontal skew factor
transX (float) – horizontal translation
skewY (float) – vertical skew factor
scaleY (float) – vertical scale factor
transY (float) – vertical translation
pers0 (float) – input x-axis perspective factor
pers1 (float) – input y-axis perspective factor
pers2 (float) – perspective scale factor
- Returns:
Matrix
constructed from parameters
- static Matrix.MakeRectToRect(src: skia.Rect, dst: skia.Rect, stf: skia.Matrix.ScaleToFit) skia.Matrix
Returns
Matrix
set to scale and translate srcRect
to dstRect
.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, returnsMatrix
set to:| 0 0 0 | | 0 0 0 | | 0 0 1 |
- static Matrix.RotateDeg(*args, **kwargs)
Overloaded function.
RotateDeg(deg: float) -> skia.Matrix
RotateDeg(deg: float, pt: skia.Point) -> skia.Matrix
- static Matrix.RotateRad(rad: float) skia.Matrix
- static Matrix.Scale(sx: float, sy: float) skia.Matrix
Sets
Matrix
to scale by (sx, sy).Returned matrix is:
sx 0 0 |0 sy 0 |0 0 1 |- Parameters:
sx (float) – horizontal scale factor
sy (float) – vertical scale factor
- Returns:
Matrix
with scale
- static Matrix.SetAffineIdentity() list[float]
Fills affine with identity values in column major order.
Sets affine to:
1 0 0 |0 1 0 |Affine 3 by 2 matrices in column major order are used by OpenGL and XPS.
- Returns:
List of float
- static Matrix.Translate(*args, **kwargs)
Overloaded function.
Translate(dx: float, dy: float) -> skia.Matrix
Translate(t: skia.Point) -> skia.Matrix
Translate(t: skia.IPoint) -> skia.Matrix
- Matrix.__init__(*args, **kwargs)
Overloaded function.
- Matrix.asAffine(self: skia.Matrix) object
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 None.- Returns:
list of float if
Matrix
does not contain perspective, else None
- Matrix.decomposeScale(self: skia.Matrix, scale: skia.Size, remaining: skia.Matrix) bool
Decomposes
Matrix
into scale components and whatever remains.Returns false if
Matrix
could not be decomposed.Sets scale to portion of
Matrix
that scale axes. Sets remaining toMatrix
with scaling factored out. remaining may be passed as nullptr to determine ifMatrix
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 success: Matrix = Remaining * scale.
- Parameters:
scale (skia.Size) – axes scaling factors; may be nullptr
remaining (skia.Matrix) –
Matrix
without scaling; may be nullptr
- Returns:
true if scale can be computed
- Matrix.dirtyMatrixTypeCache(self: skia.Matrix) None
Sets internal cache to unknown state.
Use to force update after repeated modifications to
Matrix
element reference returned by operator[](int index).
- Matrix.dump(self: skia.Matrix) None
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.
- Matrix.get(self: skia.Matrix, index: int) float
Returns one matrix value.
Asserts if index is out of range and SK_DEBUG is defined.
- Parameters:
index (int) – one of: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY, kMPersp0, kMPersp1, kMPersp2
- Returns:
value corresponding to index
- Matrix.get9(self: skia.Matrix) list[float]
Returns nine scalar values contained by
Matrix
into list, in member value ascending order: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY, kMPersp0, kMPersp1, kMPersp2.
- Matrix.getMaxScale(self: skia.Matrix) float
Returns the maximum scaling factor of
Matrix
by decomposing the scaling and skewing elements.Returns -1 if scale factor overflows or
Matrix
contains perspective.- Returns:
maximum scale factor
- Matrix.getMinMaxScales(self: skia.Matrix) tuple
Returns the minimum scaling factor and the maximum scaling factor.
Scaling factors are computed by decomposing the
Matrix
scaling and skewing elements.Returns (min, max) if scale factors are found; otherwise, returns (-1, -1).
- Returns:
tuple of min and max factors
- Matrix.getMinScale(self: skia.Matrix) float
Returns the minimum scaling factor of
Matrix
by decomposing the scaling and skewing elements.Returns -1 if scale factor overflows or
Matrix
contains perspective.- Returns:
minimum scale factor
- Matrix.getPerspX(self: skia.Matrix) float
Returns factor scaling input x-axis relative to input y-axis.
- Returns:
input x-axis perspective factor
- Matrix.getPerspY(self: skia.Matrix) float
Returns factor scaling input y-axis relative to input x-axis.
- Returns:
input y-axis perspective factor
- Matrix.getScaleX(self: skia.Matrix) float
Returns scale factor multiplied by x-axis input, contributing to x-axis output.
With
mapPoints()
, scalesPoint
along the x-axis.- Returns:
horizontal scale factor
- Matrix.getScaleY(self: skia.Matrix) float
Returns scale factor multiplied by y-axis input, contributing to y-axis output.
With
mapPoints()
, scalesPoint
along the y-axis.- Returns:
vertical scale factor
- Matrix.getSkewX(self: skia.Matrix) float
Returns scale factor multiplied by y-axis input, contributing to x-axis output.
With
mapPoints()
, skewsPoint
along the x-axis. Skewing both axes can rotatePoint
.- Returns:
horizontal scale factor
- Matrix.getSkewY(self: skia.Matrix) float
Returns scale factor multiplied by x-axis input, contributing to y-axis output.
With
mapPoints()
, skewsPoint
along the y-axis. Skewing both axes can rotatePoint
.- Returns:
vertical skew factor
- Matrix.getTranslateX(self: skia.Matrix) float
Returns translation contributing to x-axis output.
With
mapPoints()
, movesPoint
along the x-axis.- Returns:
horizontal translation factor
- Matrix.getTranslateY(self: skia.Matrix) float
Returns translation contributing to y-axis output.
With
mapPoints()
, movesPoint
along the y-axis.- Returns:
vertical translation factor
- Matrix.getType(self: skia.Matrix) skia.Matrix.TypeMask
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.
- Returns:
kIdentity_Mask, or combinations of: kTranslate_Mask, kScale_Mask, kAffine_Mask, kPerspective_Mask
- Matrix.hasPerspective(self: skia.Matrix) bool
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.
- Returns:
true if
Matrix
is in most general form
- Matrix.invert(self: skia.Matrix, inverse: skia.Matrix) bool
Sets inverse to reciprocal matrix, returning true if
Matrix
can be inverted.Geometrically, if
Matrix
maps from source to destination, inverseMatrix
maps from destination to source. IfMatrix
can not be inverted, inverse is unchanged.- Parameters:
inverse (skia.Matrix) – storage for inverted
Matrix
; may be nullptr- Returns:
true if
Matrix
can be inverted
- Matrix.isFinite(self: skia.Matrix) bool
Returns true if all elements of the matrix are finite.
Returns false if any element is infinity, or NaN.
- Returns:
true if matrix has only finite elements
- Matrix.isIdentity(self: skia.Matrix) bool
Returns true if
Matrix
is identity.Identity matrix is:
| 1 0 0 | | 0 1 0 | | 0 0 1 |
- Returns:
true if
Matrix
has no effect
- Matrix.isScaleTranslate(self: skia.Matrix) bool
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 |
- Returns:
true if
Matrix
is identity; or scales, translates, or both
- Matrix.isSimilarity(self: skia.Matrix, tol: float = 0.000244140625) bool
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 (float) – to be deprecated
- Returns:
true if
Matrix
only rotates, uniformly scales, translates
- Matrix.isTranslate(self: skia.Matrix) bool
Returns true if
Matrix
is identity, or translates.Matrix
form is:| 1 0 translate-x | | 0 1 translate-y | | 0 0 1 |
- Returns:
true if
Matrix
is identity, or translates
- Matrix.mapHomogeneousPoints(*args, **kwargs)
Overloaded function.
mapHomogeneousPoints(self: skia.Matrix, pts: list[skia.Point3]) -> object
Takes src
Point3
array and returns mappedPoint3
array.Point3
array is mapped by multiplying eachPoint3
byMatrix
. 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|
- pts:
Point3
array to transform
mapHomogeneousPoints(self: skia.Matrix, pts: list[skia.Point]) -> object
Returns homogeneous points, starting with 2D src points (with implied w = 1).
- pts:
Point
array to transform
- Matrix.mapPoints(self: skia.Matrix, pts: list[skia.Point]) list[skia.Point]
Takes src
Point
array and returns mappedPoint
array.Point
are mapped by multiplying eachPoint
byMatrix
. 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
- Parameters:
src (List[skia.Point]) – list of
Point
to transform
- Matrix.mapRadius(self: skia.Matrix, radius: float) float
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
- Returns:
average mapped radius
- Matrix.mapRect(self: skia.Matrix, src: skia.Rect, pc: skia.ApplyPerspectiveClip = skia.ApplyPerspectiveClip.kYes) skia.Rect
Returns bounds of src corners mapped by
Matrix
.- Parameters:
src (skia.Rect) – rectangle to map
pc (skia.ApplyPerspectiveClip) – whether to apply perspective clipping
- Returns:
mapped bounds
- Matrix.mapRectScaleTranslate(self: skia.Matrix, src: skia.Rect) skia.Rect
Returns 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.
- Matrix.mapRectToQuad(self: skia.Matrix, rect: skia.Rect) list[skia.Point]
Maps four corners of rect to dst.
Point
are mapped by multiplying each rect corner byMatrix
. 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
Note: this does not perform perspective clipping (as that might result in more than 4 points, so results are suspect if the matrix contains perspective.
- Matrix.mapVector(self: skia.Matrix, dx: float, dy: float) skia.Point
Returns vector (dx, dy) multiplied by
Matrix
, treatingMatrix
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 (float) – x-axis value of vector to map
dy (float) – y-axis value of vector to map
- Returns:
mapped vector
- Matrix.mapVectors(self: skia.Matrix, src: list[skia.Point]) list[skia.Point]
Maps src vector array to vector
Point
array.Vectors are mapped by multiplying each vector by
Matrix
, treatingMatrix
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
- Parameters:
src (List[skia.Point]) – vectors to transform
- Matrix.mapXY(self: skia.Matrix, x: float, y: float) skia.Point
Returns
Point
(x, y) multiplied byMatrix
.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
- Matrix.normalizePerspective(self: skia.Matrix) None
A matrix is categorized as ‘perspective’ if the bottom row is not [0, 0, 1].
However, for most uses (e.g. mapPoints) a bottom row of [0, 0, X] behaves like a non-perspective matrix, though it will be categorized as perspective. Calling
normalizePerspective()
will change the matrix such that, if its bottom row was [0, 0, X], it will be changed to [0, 0, 1] by scaling the rest of the matrix by 1/X:| A B C | | A/X B/X C/X | | D E F | -> \ | D/X E/X F/X | for X != 0 | 0 0 X | | 0 0 1 |
- Matrix.postConcat(self: skia.Matrix, other: skia.Matrix) skia.Matrix
Sets
Matrix
toMatrix
other multiplied byMatrix
.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 (skia.Matrix) –
Matrix
on left side of multiply expression
- Matrix.postRotate(*args, **kwargs)
Overloaded function.
postRotate(self: skia.Matrix, degrees: float, px: float, py: float) -> skia.Matrix
Sets
Matrix
toMatrix
constructed from rotating by degrees about pivot point (px, py), multiplied byMatrix
.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|
- degrees:
angle of axes relative to upright axes
- px:
pivot on x-axis
- py:
pivot on y-axis
postRotate(self: skia.Matrix, degrees: float) -> skia.Matrix
Sets
Matrix
toMatrix
constructed from rotating by degrees about pivot point (0, 0), multiplied byMatrix
.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 |
- degrees:
angle of axes relative to upright axes
- Matrix.postScale(*args, **kwargs)
Overloaded function.
postScale(self: skia.Matrix, sx: float, sy: float, px: float, py: float) -> skia.Matrix
Sets
Matrix
toMatrix
constructed from scaling by (sx, sy) about pivot point (px, py), multiplied byMatrix
.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 |
- sx:
horizontal scale factor
- sy:
vertical scale factor
- px:
pivot on x-axis
- py:
pivot on y-axis
postScale(self: skia.Matrix, sx: float, sy: float) -> skia.Matrix
Sets
Matrix
toMatrix
constructed from scaling by (sx, sy) about pivot point (0, 0), multiplied byMatrix
.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 |
- sx:
horizontal scale factor
- sy:
vertical scale factor
- Matrix.postSkew(*args, **kwargs)
Overloaded function.
postSkew(self: skia.Matrix, kx: float, ky: float, px: float, py: float) -> skia.Matrix
Sets
Matrix
toMatrix
constructed from skewing by (kx, ky) about pivot point (px, py), multiplied byMatrix
.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|
- kx:
horizontal skew factor
- ky:
vertical skew factor
- px:
pivot on x-axis
- py:
pivot on y-axis
postSkew(self: skia.Matrix, kx: float, ky: float) -> skia.Matrix
Sets
Matrix
toMatrix
constructed from skewing by (kx, ky) about pivot point (0, 0), multiplied byMatrix
.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 |
- kx:
horizontal skew factor
- ky:
vertical skew factor
- Matrix.postTranslate(self: skia.Matrix, dx: float, dy: float) skia.Matrix
Sets
Matrix
toMatrix
constructed from translation (dx, dy) multiplied byMatrix
.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 |
- Matrix.preConcat(self: skia.Matrix, other: skia.Matrix) skia.Matrix
Sets
Matrix
toMatrix
multiplied byMatrix
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 (skia.Matrix) –
Matrix
on right side of multiply expression
- Matrix.preRotate(*args, **kwargs)
Overloaded function.
preRotate(self: skia.Matrix, degrees: float, px: float, py: float) -> skia.Matrix
Sets
Matrix
toMatrix
multiplied byMatrix
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 |
- degrees:
angle of axes relative to upright axes
- px:
pivot on x-axis
- py:
pivot on y-axis
preRotate(self: skia.Matrix, degrees: float) -> skia.Matrix
Sets
Matrix
toMatrix
multiplied byMatrix
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 |
- degrees:
angle of axes relative to upright axes
- Matrix.preScale(*args, **kwargs)
Overloaded function.
preScale(self: skia.Matrix, sx: float, sy: float, px: float, py: float) -> skia.Matrix
Sets
Matrix
toMatrix
multiplied byMatrix
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 |
- sx:
horizontal scale factor
- sy:
vertical scale factor
- px:
pivot on x-axis
- py:
pivot on y-axis
preScale(self: skia.Matrix, sx: float, sy: float) -> skia.Matrix
Sets
Matrix
toMatrix
multiplied byMatrix
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 |
- sx:
horizontal scale factor
- sy:
vertical scale factor
- Matrix.preSkew(*args, **kwargs)
Overloaded function.
preSkew(self: skia.Matrix, kx: float, ky: float, px: float, py: float) -> skia.Matrix
Sets
Matrix
toMatrix
multiplied byMatrix
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 |
- kx:
horizontal skew factor
- ky:
vertical skew factor
- px:
pivot on x-axis
- py:
pivot on y-axis
preSkew(self: skia.Matrix, kx: float, ky: float) -> skia.Matrix
Sets
Matrix
toMatrix
multiplied byMatrix
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 |
- kx:
horizontal skew factor
- ky:
vertical skew factor
- Matrix.preTranslate(self: skia.Matrix, dx: float, dy: float) skia.Matrix
Sets
Matrix
toMatrix
multiplied byMatrix
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 |
- Matrix.preservesAxisAlignment(self: skia.Matrix) bool
Returns true
Matrix
mapsRect
to anotherRect
.If true,
Matrix
is identity, or scales, or rotates a multiple of 90 degrees, or mirrors on axes. In all cases,Matrix
may also have translation.Matrix
form is either:| scale-x 0 translate-x | | 0 scale-y translate-y | | 0 0 1 |
or:
| 0 rotate-x translate-x | | rotate-y 0 translate-y | | 0 0 1 |
for non-zero values of scale-x, scale-y, rotate-x, and rotate-y.
Also called
rectStaysRect()
; use the one that provides better inline documentation.
- Matrix.preservesRightAngles(self: skia.Matrix, tol: float = 0.000244140625) bool
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 (float) – to be deprecated
- Returns:
true if
Matrix
only rotates, scales, translates
- Matrix.rc(self: skia.Matrix, r: int, c: int) float
Returns one matrix value from a particular row/column. Asserts if index is out of range and SK_DEBUG is defined.
- Parameters:
r – matrix row to fetch
c – matrix column to fetch
- Returns:
value at the given matrix position
- Matrix.rectStaysRect(self: skia.Matrix) bool
Returns true SkMatrix maps SkRect to another SkRect.
If true,
Matrix
is identity, or scales, or rotates a multiple of 90 degrees, or mirrors on axes. In all cases,Matrix
may also have translation.Matrix
form is either:| scale-x 0 translate-x | | 0 scale-y translate-y | | 0 0 1 |
or:
| 0 rotate-x translate-x | | rotate-y 0 translate-y | | 0 0 1 | for non-zero values of scale-x, scale-y, rotate-x, and rotate-y.
Also called
preservesAxisAlignment()
; use the one that provides better inline documentation.
- Matrix.reset(self: skia.Matrix) skia.Matrix
Sets
Matrix
to identity; which has no effect on mappedPoint
.Sets
Matrix
to:| 1 0 0 | | 0 1 0 | | 0 0 1 |
Also called
setIdentity()
; use the one that provides better inline documentation.
- Matrix.set(self: skia.Matrix, index: int, value: float) None
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 toMatrix
value must be followed bydirtyMatrixTypeCache()
.- Parameters:
index (int) – one of: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY, kMPersp0, kMPersp1, kMPersp2
value – value to set
- Matrix.set9(self: skia.Matrix, buffer: list[float]) skia.Matrix
Sets
Matrix
to nine scalar values in values, in member value ascending order: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY, kMPersp0, kMPersp1, kMPersp2.Sets matrix to:
| values[0] values[1] values[2] | | values[3] values[4] values[5] | | values[6] values[7] values[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:
values – nine scalar values
- Matrix.setAffine(self: skia.Matrix, affine: list[float]) skia.Matrix
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 – 3 by 2 affine matrix
- Matrix.setAll(self: skia.Matrix, scaleX: float, skewX: float, transX: float, skewY: float, scaleY: float, transY: float, persp0: float, persp1: float, persp2: float) skia.Matrix
Sets all values from parameters.
Sets matrix to:
| scaleX skewX transX | | skewY scaleY transY | | persp0 persp1 persp2 |
- Parameters:
scaleX (float) – horizontal scale factor to store
skewX (float) – horizontal skew factor to store
transX (float) – horizontal translation to store
skewY (float) – vertical skew factor to store
scaleY (float) – vertical scale factor to store
transY (float) – vertical translation to store
persp0 (float) – input x-axis values perspective factor to store
persp1 (float) – input y-axis values perspective factor to store
persp2 (float) – perspective scale factor to store
- Matrix.setConcat(self: skia.Matrix, a: skia.Matrix, b: skia.Matrix) skia.Matrix
Sets
Matrix
toMatrix
a multiplied byMatrix
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 (skia.Matrix) –
Matrix
on left side of multiply expressionb (skia.Matrix) –
Matrix
on right side of multiply expression
- Matrix.setIdentity(self: skia.Matrix) skia.Matrix
Sets
Matrix
to identity; which has no effect on mappedPoint
.Sets
Matrix
to:| 1 0 0 | | 0 1 0 | | 0 0 1 |
Also called
reset()
; use the one that provides better inline documentation.
- Matrix.setPerspX(self: skia.Matrix, v: float) skia.Matrix
Sets input x-axis perspective factor, which causes mapXY() to vary input x-axis values inversely proportional to input y-axis values.
- Parameters:
v (float) – perspective factor
- Matrix.setPerspY(self: skia.Matrix, v: float) skia.Matrix
Sets input y-axis perspective factor, which causes mapXY() to vary input y-axis values inversely proportional to input x-axis values.
- Parameters:
v (float) – perspective factor
- Matrix.setPolyToPoly(self: skia.Matrix, src: list[skia.Point], dst: list[skia.Point]) bool
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, setsMatrix
to translate and returns true. If count is two or more, setsMatrix
to mapPoint
if possible; returns false ifMatrix
cannot be constructed. If count is four,Matrix
may include perspective.- Parameters:
src (List[skia.Point]) –
Point
to map fromdst (List[skia.Point]) –
Point
to map to
- Returns:
true if
Matrix
was constructed successfully
- Matrix.setRSXform(self: skia.Matrix, rsxForm: SkRSXform) skia.Matrix
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 (skia.RSXform) – compressed
RSXform
matrix- Returns:
reference to
Matrix
- Matrix.setRectToRect(self: skia.Matrix, src: skia.Rect, dst: skia.Rect, stf: skia.Matrix.ScaleToFit) bool
Sets
Matrix
to scale and translate srcRect
to dstRect
.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 setsMatrix
to:0 0 0 |0 0 0 |0 0 1 |
- Matrix.setRotate(*args, **kwargs)
Overloaded function.
setRotate(self: skia.Matrix, degrees: float, px: float, py: float) -> skia.Matrix
setRotate(self: skia.Matrix, degrees: float) -> skia.Matrix
Sets
Matrix
to rotate by degrees about a pivot point at (0, 0).Positive degrees rotates clockwise.
- degrees:
angle of axes relative to upright axes
- Matrix.setScale(*args, **kwargs)
Overloaded function.
setScale(self: skia.Matrix, sx: float, sy: float, px: float, py: float) -> skia.Matrix
setScale(self: skia.Matrix, sx: float, sy: float) -> skia.Matrix
Sets
Matrix
to scale by sx and sy about at pivot point at (0, 0).- sx:
horizontal scale factor
- sy:
vertical scale factor
- Matrix.setScaleTranslate(self: skia.Matrix, sx: float, sy: float, tx: float, ty: float) None
Initializes
Matrix
with scale and translate elements.sx 0 tx |0 sy ty |0 0 1 |- Parameters:
sx (float) – horizontal scale factor to store
sy (float) – vertical scale factor to store
tx (float) – horizontal translation to store
ty (float) – vertical translation to store
- Matrix.setScaleX(self: skia.Matrix, v: float) skia.Matrix
Sets horizontal scale factor.
- Parameters:
v (float) – horizontal scale factor to store
- Matrix.setScaleY(self: skia.Matrix, v: float) skia.Matrix
Sets vertical scale factor.
- Parameters:
v (float) – vertical scale factor to store
- Matrix.setSinCos(*args, **kwargs)
Overloaded function.
setSinCos(self: skia.Matrix, sinValue: float, cosValue: float, px: float, py: float) -> skia.Matrix
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.
- sinValue:
rotation vector x-axis component
- cosValue:
rotation vector y-axis component
- px:
pivot on x-axis
- py:
pivot on y-axis
setSinCos(self: skia.Matrix, sinValue: float, cosValue: float) -> skia.Matrix
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.
- sinValue:
rotation vector x-axis component
- cosValue:
rotation vector y-axis component
- Matrix.setSkew(*args, **kwargs)
Overloaded function.
setSkew(self: skia.Matrix, kx: float, ky: float, px: float, py: float) -> skia.Matrix
setSkew(self: skia.Matrix, kx: float, ky: float) -> skia.Matrix
Sets
Matrix
to skew by kx and ky, about a pivot point at (0, 0).- kx:
horizontal skew factor
- ky:
vertical skew factor
- Matrix.setSkewX(self: skia.Matrix, v: float) skia.Matrix
Sets horizontal skew factor.
- Parameters:
v (float) – horizontal skew factor to store
- Matrix.setSkewY(self: skia.Matrix, v: float) skia.Matrix
Sets vertical skew factor.
- Parameters:
v – vertical skew factor to store
- Matrix.setTranslate(*args, **kwargs)
Overloaded function.
setTranslate(self: skia.Matrix, dx: float, dy: float) -> skia.Matrix
Sets
Matrix
to translate by (dx, dy).- dx:
horizontal translation
- dy:
vertical translation
setTranslate(self: skia.Matrix, v: skia.Point) -> skia.Matrix
Sets
Matrix
to translate by (v.fX, v.fY).- v:
vector containing horizontal and vertical translation
- Matrix.setTranslateX(self: skia.Matrix, v: float) skia.Matrix
Sets horizontal translation.
- Parameters:
v (float) – horizontal translation to store
- Matrix.setTranslateY(self: skia.Matrix, v: float) skia.Matrix
Sets vertical translation.
- Parameters:
v (float) – vertical translation to store
Attributes
- Matrix.kAScaleX = 0
- Matrix.kAScaleY = 3
- Matrix.kASkewX = 2
- Matrix.kASkewY = 1
- Matrix.kATransX = 4
- Matrix.kATransY = 5
- Matrix.kAffine_Mask = <TypeMask.kAffine_Mask: 4>
- Matrix.kCenter_ScaleToFit = <ScaleToFit.kCenter_ScaleToFit: 2>
- Matrix.kEnd_ScaleToFit = <ScaleToFit.kEnd_ScaleToFit: 3>
- Matrix.kFill_ScaleToFit = <ScaleToFit.kFill_ScaleToFit: 0>
- Matrix.kIdentity_Mask = <TypeMask.kIdentity_Mask: 0>
- Matrix.kMPersp0 = 6
- Matrix.kMPersp1 = 7
- Matrix.kMPersp2 = 8
- Matrix.kMScaleX = 0
- Matrix.kMScaleY = 4
- Matrix.kMSkewX = 1
- Matrix.kMSkewY = 3
- Matrix.kMTransX = 2
- Matrix.kMTransY = 5
- Matrix.kPerspective_Mask = <TypeMask.kPerspective_Mask: 8>
- Matrix.kScale_Mask = <TypeMask.kScale_Mask: 2>
- Matrix.kStart_ScaleToFit = <ScaleToFit.kStart_ScaleToFit: 1>
- Matrix.kTranslate_Mask = <TypeMask.kTranslate_Mask: 1>