blob: b39e9130214e69d18e8f4de43e986549561e59fa [file] [log] [blame]
Cary Clarkbc5697d2017-10-04 14:31:33 -04001#Topic Matrix
Cary Clark154beea2017-10-26 07:58:48 -04002#Alias Matrices
Cary Clarkbc5697d2017-10-04 14:31:33 -04003#Alias Matrix_Reference
4
5#Class SkMatrix
6
Cary Clark154beea2017-10-26 07:58:48 -04007Matrix holds a 3x3 matrix for transforming coordinates. This allows mapping
8Points and Vectors with translation, scaling, skewing, rotation, and
9perspective.
Cary Clark884dd7d2017-10-11 10:37:52 -040010
Cary Clark154beea2017-10-26 07:58:48 -040011Matrix elements are in row major order. Matrix does not have a constructor,
12so it must be explicitly initialized. setIdentity initializes Matrix
13so it has no effect. setTranslate, setScale, setSkew, setRotate, set9 and setAll
14initializes all Matrix elements with the corresponding mapping.
Cary Clark884dd7d2017-10-11 10:37:52 -040015
Cary Clark154beea2017-10-26 07:58:48 -040016Matrix includes a hidden variable that classifies the type of matrix to
17improve performance. Matrix is not thread safe unless getType is called first.
Cary Clarkbc5697d2017-10-04 14:31:33 -040018
19#Topic Overview
20
21#Subtopic Subtopics
22#ToDo manually add subtopics ##
23#Table
24#Legend
25# topics # description ##
26#Legend ##
27#Table ##
28##
29
Cary Clark5081eed2018-01-22 07:55:48 -050030#Subtopic Constructors
31#Table
32#Legend
33# name # description ##
34#Legend ##
35# MakeAll # Constructs all nine values. ##
36# MakeRectToRect # Constructs from source Rect to destination Rect. ##
37# MakeScale # Constructs from scale in x and y. ##
38# MakeTrans # Constructs from translate in x and y. ##
39#Table ##
40#Subtopic ##
41
Cary Clarkbc5697d2017-10-04 14:31:33 -040042#Subtopic Operators
43#Table
44#Legend
Cary Clark154beea2017-10-26 07:58:48 -040045# function # description ##
Cary Clarkbc5697d2017-10-04 14:31:33 -040046#Legend ##
Cary Clark154beea2017-10-26 07:58:48 -040047# operator!=(const SkMatrix& a, const SkMatrix& b) # Returns true if members are unequal. ##
48# operator==(const SkMatrix& a, const SkMatrix& b) # Returns true if members are equal. ##
Cary Clark154beea2017-10-26 07:58:48 -040049# operator[](int index) # Returns writable reference to Matrix value. ##
Cary Clark5081eed2018-01-22 07:55:48 -050050# operator[](int index)_const # Returns Matrix value. ##
Cary Clarkbc5697d2017-10-04 14:31:33 -040051#Table ##
52#Subtopic ##
53
54#Subtopic Member_Functions
55#Table
56#Legend
Cary Clark154beea2017-10-26 07:58:48 -040057# function # description ##
Cary Clarkbc5697d2017-10-04 14:31:33 -040058#Legend ##
Cary Clark884dd7d2017-10-11 10:37:52 -040059# Concat # Returns the concatenation of Matrix pair. ##
Cary Clark884dd7d2017-10-11 10:37:52 -040060# I # Returns a reference to a const identity Matrix. ##
61# InvalidMatrix # Returns a reference to a const invalid Matrix. ##
Cary Clarkbef063a2017-10-31 15:44:45 -040062# MakeAll # Constructs all nine values. ##
Cary Clark884dd7d2017-10-11 10:37:52 -040063# MakeRectToRect # Constructs from source Rect to destination Rect. ##
64# MakeScale # Constructs from scale in x and y. ##
65# MakeTrans # Constructs from translate in x and y. ##
Cary Clark154beea2017-10-26 07:58:48 -040066# SetAffineIdentity # Sets 3x2 array to identity. ##
67# asAffine # Copies to 3x2 array. ##
Cary Clark884dd7d2017-10-11 10:37:52 -040068# cheapEqualTo # Compares Matrix pair using memcmp(). ##
69# decomposeScale # Separates scale if possible. ##
Cary Clark154beea2017-10-26 07:58:48 -040070# dirtyMatrixTypeCache # Sets internal cache to unknown state. ##
71# dump() # Sends text representation using floats to standard output. ##
Cary Clark884dd7d2017-10-11 10:37:52 -040072# fixedStepInX # Returns step in x for a position in y. ##
Cary Clark154beea2017-10-26 07:58:48 -040073# get() # Returns one of nine Matrix values. ##
Cary Clark884dd7d2017-10-11 10:37:52 -040074# get9 # Returns all nine Matrix values. ##
Cary Clark884dd7d2017-10-11 10:37:52 -040075# getMaxScale # Returns maximum scaling, if possible. ##
76# getMinMaxScales # Returns minimum and maximum scaling, if possible. ##
77# getMinScale # Returns minimum scaling, if possible. ##
Cary Clark154beea2017-10-26 07:58:48 -040078# getPerspX # Returns input x perspective factor. ##
79# getPerspY # Returns input y perspective factor. ##
Cary Clark884dd7d2017-10-11 10:37:52 -040080# getScaleX # Returns horizontal scale factor. ##
Cary Clark154beea2017-10-26 07:58:48 -040081# getScaleY # Returns vertical scale factor. ##
Cary Clark884dd7d2017-10-11 10:37:52 -040082# getSkewX # Returns horizontal skew factor. ##
83# getSkewY # Returns vertical skew factor. ##
Cary Clark154beea2017-10-26 07:58:48 -040084# getTranslateX # Returns horizontal translation. ##
85# getTranslateY # Returns vertical translation. ##
Cary Clark884dd7d2017-10-11 10:37:52 -040086# getType # Returns transform complexity. ##
87# hasPerspective # Returns if transform includes perspective. ##
Cary Clark154beea2017-10-26 07:58:48 -040088# invert() # Returns inverse, if possible. ##
Cary Clark884dd7d2017-10-11 10:37:52 -040089# isFinite # Returns if all Matrix values are not infinity, NaN. ##
90# isFixedStepInX # Returns if transformation supports fixed step in x. ##
91# isIdentity # Returns if matrix equals the identity Matrix .##
92# isScaleTranslate # Returns if transform is limited to scale and translate. ##
93# isSimilarity # Returns if transform is limited to square scale and rotation. ##
94# isTranslate # Returns if transform is limited to translate. ##
Cary Clark154beea2017-10-26 07:58:48 -040095# mapHomogeneousPoints # Maps Point3 array. ##
96# mapPoints # Maps Point array. ##
Cary Clark154beea2017-10-26 07:58:48 -040097# mapRadius # Returns mean radius of mapped Circle. ##
98# mapRect # Returns bounds of mapped Rect. ##
99# mapRectScaleTranslate # Returns bounds of mapped Rect. ##
100# mapRectToQuad # Maps Rect to Point array. ##
101# mapVector # Maps Vector. ##
102# mapVectors # Maps Vector array. ##
103# mapXY # Maps Point. ##
104# postConcat # Post-multiplies Matrix by Matrix parameter. ##
105# postIDiv # Post-multiplies Matrix by inverse scale. ##
106# postRotate # Post-multiplies Matrix by rotation. ##
107# postScale # Post-multiplies Matrix by scale. ##
108# postSkew # Post-multiplies Matrix by skew. ##
109# postTranslate # Post-multiplies Matrix by translation. ##
110# preConcat # Pre-multiplies Matrix by Matrix parameter.##
111# preRotate # Pre-multiplies Matrix by rotation. ##
112# preScale # Pre-multiplies Matrix by scale. ##
113# preSkew # Pre-multiplies Matrix by skew. ##
114# preTranslate # Pre-multiplies Matrix by translation. ##
115# preservesAxisAlignment # Returns if mapping restricts to 90 degree multiples and mirroring. ##
116# preservesRightAngles # Returns if mapped 90 angle remains 90 degrees. ##
117# rectStaysRect # Returns if mapped Rect can be represented by another Rect. ##
118# reset() # Sets Matrix to identity. ##
119# set() # Sets one value. ##
120# set9 # Sets all values from Scalar array. ##
121# setAffine # Sets left two columns. ##
122# setAll # Sets all values from parameters. ##
123# setConcat # Sets to Matrix parameter multiplied by Matrix parameter. ##
124# setIdentity # Sets Matrix to identity. ##
125# setPerspX # Sets input x perspective factor. ##
126# setPerspY # Sets input y perspective factor. ##
127# setPolyToPoly # Sets to map one to four points to an equal array of points. ##
128# setRSXform # Sets to rotate, scale, and translate. ##
129# setRectToRect # Sets to map one Rect to another. ##
130# setRotate # Sets to rotate about a point. ##
131# setScale # Sets to scale about a point. ##
132# setScaleTranslate # Sets to scale and translate. ##
133# setScaleX # Sets horizontal scale factor. ##
134# setScaleY # Sets vertical scale factor ##
135# setSinCos # Sets to rotate and scale about a point. ##
136# setSkew # Sets to skew about a point. ##
137# setSkewX # Sets horizontal skew factor. ##
138# setSkewY # Sets vertical skew factor. ##
139# setTranslate # Sets to translate in x and y. ##
140# setTranslateX # Sets horizontal translation. ##
141# setTranslateY # Sets vertical translation. ##
142# toString # Converts Matrix to machine readable form. ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400143#Table ##
144#Subtopic ##
145
146#Topic ##
147
148# ------------------------------------------------------------------------------
149
150#Method static SkMatrix SK_WARN_UNUSED_RESULT MakeScale(SkScalar sx, SkScalar sy)
151
Cary Clarkab2621d2018-01-30 10:08:57 -0500152#Line # Constructs from scale in x and y. ##
Cary Clark154beea2017-10-26 07:58:48 -0400153Sets Matrix to scale by (sx, sy). Returned matrix is:
Cary Clarkbc5697d2017-10-04 14:31:33 -0400154
Cary Clark154beea2017-10-26 07:58:48 -0400155#Code
156#Literal
157| sx 0 0 |
158| 0 sy 0 |
159| 0 0 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -0400160##
161
Cary Clark154beea2017-10-26 07:58:48 -0400162#Param sx horizontal scale factor ##
163#Param sy vertical scale factor ##
164
165#Return Matrix with scale ##
166
167#Example
168#Image 4
169canvas->concat(SkMatrix::MakeScale(4, 3));
170canvas->drawBitmap(source, 0, 0);
171##
172
173#SeeAlso setScale postScale preScale
Cary Clarkbc5697d2017-10-04 14:31:33 -0400174
175##
176
177# ------------------------------------------------------------------------------
178
179#Method static SkMatrix SK_WARN_UNUSED_RESULT MakeScale(SkScalar scale)
180
Cary Clark154beea2017-10-26 07:58:48 -0400181Sets Matrix to scale by (scale, scale). Returned matrix is:
Cary Clarkbc5697d2017-10-04 14:31:33 -0400182
Cary Clark154beea2017-10-26 07:58:48 -0400183#Code
184#Literal
185| scale 0 0 |
186| 0 scale 0 |
187| 0 0 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -0400188##
189
Cary Clark154beea2017-10-26 07:58:48 -0400190#Param scale horizontal and vertical scale factor ##
191
192#Return Matrix with scale ##
193
194#Example
195#Image 4
196canvas->concat(SkMatrix::MakeScale(4));
197canvas->drawBitmap(source, 0, 0);
198##
199
200#SeeAlso setScale postScale preScale
Cary Clarkbc5697d2017-10-04 14:31:33 -0400201
202##
203
204# ------------------------------------------------------------------------------
205
206#Method static SkMatrix SK_WARN_UNUSED_RESULT MakeTrans(SkScalar dx, SkScalar dy)
207
Cary Clarkab2621d2018-01-30 10:08:57 -0500208#Line # Constructs from translate in x and y. ##
Cary Clark154beea2017-10-26 07:58:48 -0400209Sets Matrix to translate by (dx, dy). Returned matrix is:
Cary Clarkbc5697d2017-10-04 14:31:33 -0400210
Cary Clark154beea2017-10-26 07:58:48 -0400211#Code
212#Literal
Cary Clarkcfee6ec2017-10-26 10:34:05 -0400213| 1 0 dx |
214| 0 1 dy |
215| 0 0 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -0400216##
217
Cary Clark154beea2017-10-26 07:58:48 -0400218#Param dx horizontal translation ##
219#Param dy vertical translation ##
220
221#Return Matrix with translation ##
222
223#Example
224#Image 4
225SkMatrix matrix = SkMatrix::MakeTrans(64, 48);
226for (int i = 0; i < 4; ++i) {
227 canvas->drawBitmap(source, 0, 0);
228 canvas->concat(matrix);
229}
230##
231
232#SeeAlso setTranslate postTranslate preTranslate
Cary Clarkbc5697d2017-10-04 14:31:33 -0400233
234##
235
236# ------------------------------------------------------------------------------
237
Cary Clarkbef063a2017-10-31 15:44:45 -0400238#Method static SkMatrix SK_WARN_UNUSED_RESULT MakeAll(SkScalar scaleX, SkScalar skewX, SkScalar transX,
239 SkScalar skewY, SkScalar scaleY, SkScalar transY,
240 SkScalar pers0, SkScalar pers1, SkScalar pers2)
Cary Clarkab2621d2018-01-30 10:08:57 -0500241#Line # Constructs all nine values. ##
Cary Clarkbef063a2017-10-31 15:44:45 -0400242
243
244Sets Matrix to:
245
246#Code
247#Literal
248| scaleX skewX transX |
249| skewY scaleY transY |
250| pers0 pers1 pers2 |
251##
252
253#Param scaleX horizontal scale factor ##
254#Param skewX horizontal skew factor ##
255#Param transX horizontal translation ##
256#Param skewY vertical skew factor ##
257#Param scaleY vertical scale factor ##
258#Param transY vertical translation ##
259#Param pers0 input x perspective factor ##
260#Param pers1 input y perspective factor ##
261#Param pers2 perspective scale factor ##
262
263#Return Matrix constructed from parameters ##
264
265#Example
266 SkPaint p;
267 p.setAntiAlias(true);
268 p.setTextSize(64);
269 for (SkScalar sx : { -1, 1 } ) {
270 for (SkScalar sy : { -1, 1 } ) {
271 SkAutoCanvasRestore autoRestore(canvas, true);
272 SkMatrix m = SkMatrix::MakeAll(sx, 1, 128, 0, sy, 128, 0, 0, 1);
273 canvas->concat(m);
274 canvas->drawString("K", 0, 0, p);
275 }
276 }
277##
278
279#SeeAlso setAll set9 postConcat preConcat
280
281##
282
283
284# ------------------------------------------------------------------------------
285
Cary Clarkbc5697d2017-10-04 14:31:33 -0400286#Enum TypeMask
287
288#Code
289 enum TypeMask {
290 kIdentity_Mask = 0,
291 kTranslate_Mask = 0x01,
292 kScale_Mask = 0x02,
293 kAffine_Mask = 0x04,
294 kPerspective_Mask = 0x08,
295 };
296##
297
Cary Clark154beea2017-10-26 07:58:48 -0400298Enum of bit fields for mask returned by getType.
299Used to identify the complexity of Matrix, to optimize performance.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400300
Cary Clark154beea2017-10-26 07:58:48 -0400301#Const kIdentity_Mask 0
302all bits clear if Matrix is identity
Cary Clarkbc5697d2017-10-04 14:31:33 -0400303##
Cary Clark154beea2017-10-26 07:58:48 -0400304#Const kTranslate_Mask 1
305set if Matrix has translation
Cary Clarkbc5697d2017-10-04 14:31:33 -0400306##
Cary Clark154beea2017-10-26 07:58:48 -0400307#Const kScale_Mask 2
308set if Matrix has x or y scale
Cary Clarkbc5697d2017-10-04 14:31:33 -0400309##
Cary Clark154beea2017-10-26 07:58:48 -0400310#Const kAffine_Mask 4
311set if Matrix skews or rotates
Cary Clarkbc5697d2017-10-04 14:31:33 -0400312##
Cary Clark154beea2017-10-26 07:58:48 -0400313#Const kPerspective_Mask 8
314set if Matrix has perspective
Cary Clarkbc5697d2017-10-04 14:31:33 -0400315##
316
317#Example
Cary Clark154beea2017-10-26 07:58:48 -0400318 auto debugster = [](const char* prefix, const SkMatrix& matrix) -> void {
319 SkString typeMask;
320 typeMask += SkMatrix::kIdentity_Mask == matrix.getType() ? "kIdentity_Mask " : "";
321 typeMask += SkMatrix::kTranslate_Mask & matrix.getType() ? "kTranslate_Mask " : "";
322 typeMask += SkMatrix::kScale_Mask & matrix.getType() ? "kScale_Mask " : "";
323 typeMask += SkMatrix::kAffine_Mask & matrix.getType() ? "kAffine_Mask " : "";
324 typeMask += SkMatrix::kPerspective_Mask & matrix.getType() ? "kPerspective_Mask" : "";
325 SkDebugf("after %s: %s\n", prefix, typeMask.c_str());
326 };
327SkMatrix matrix;
328matrix.reset();
329debugster("reset", matrix);
330matrix.postTranslate(1, 0);
331debugster("postTranslate", matrix);
332matrix.postScale(2, 1);
333debugster("postScale", matrix);
334matrix.postRotate(45);
335debugster("postScale", matrix);
336SkPoint polys[][4] = {{{0, 0}, {0, 1}, {1, 1}, {1, 0}}, {{0, 0}, {0, 1}, {2, 1}, {1, 0}}};
337matrix.setPolyToPoly(polys[0], polys[1], 4);
338debugster("setPolyToPoly", matrix);
339#StdOut
340after reset: kIdentity_Mask
341after postTranslate: kTranslate_Mask
342after postScale: kTranslate_Mask kScale_Mask
343after postScale: kTranslate_Mask kScale_Mask kAffine_Mask
344after setPolyToPoly: kTranslate_Mask kScale_Mask kAffine_Mask kPerspective_Mask
345##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400346##
347
Cary Clark154beea2017-10-26 07:58:48 -0400348#SeeAlso getType
Cary Clarkbc5697d2017-10-04 14:31:33 -0400349
350##
351
352# ------------------------------------------------------------------------------
353
354#Method TypeMask getType() const
355
Cary Clarkab2621d2018-01-30 10:08:57 -0500356#Line # Returns transform complexity. ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400357Returns a bit field describing the transformations the matrix may
358perform. The bit field is computed conservatively, so it may include
Cary Clark154beea2017-10-26 07:58:48 -0400359false positives. For example, when kPerspective_Mask is set, all
360other bits are set.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400361
Cary Clark154beea2017-10-26 07:58:48 -0400362#Return kIdentity_Mask, or combinations of: kTranslate_Mask, kScale_Mask,
363 kAffine_Mask, kPerspective_Mask
Cary Clarkbc5697d2017-10-04 14:31:33 -0400364##
365
Cary Clark154beea2017-10-26 07:58:48 -0400366#Example
367SkMatrix matrix;
368matrix.setAll(1, 0, 0, 0, 1, 0, 0, 0, 1);
369SkDebugf("identity flags hex: %0x decimal: %d\n", matrix.getType(), matrix.getType());
370matrix.setAll(1, 0, 0, 0, 1, 0, 0, 0, .5f);
371SkDebugf("set all flags hex: %0x decimal: %d\n", matrix.getType(), matrix.getType());
372#StdOut
373identity flags hex: 0 decimal: 0
374set all flags hex: f decimal: 15
375##
376##
377
378#SeeAlso TypeMask
Cary Clarkbc5697d2017-10-04 14:31:33 -0400379
380##
381
382# ------------------------------------------------------------------------------
383
384#Method bool isIdentity() const
385
Cary Clarkab2621d2018-01-30 10:08:57 -0500386#Line # Returns if matrix equals the identity Matrix . ##
Cary Clark154beea2017-10-26 07:58:48 -0400387Returns true if Matrix is identity. Identity matrix is:
Cary Clarkbc5697d2017-10-04 14:31:33 -0400388
Cary Clark154beea2017-10-26 07:58:48 -0400389#Code
390#Literal
391| 1 0 0 |
392| 0 1 0 |
393| 0 0 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -0400394##
395
Cary Clark154beea2017-10-26 07:58:48 -0400396#Return true if Matrix has no effect ##
397
398#Example
399SkMatrix matrix;
400matrix.setAll(1, 0, 0, 0, 1, 0, 0, 0, 1);
401SkDebugf("is identity: %s\n", matrix.isIdentity() ? "true" : "false");
402matrix.setAll(1, 0, 0, 0, 1, 0, 0, 0, 2);
403SkDebugf("is identity: %s\n", matrix.isIdentity() ? "true" : "false");
404#StdOut
405is identity: true
406is identity: false
407##
408##
409
410#SeeAlso reset() setIdentity getType
Cary Clarkbc5697d2017-10-04 14:31:33 -0400411
412##
413
414# ------------------------------------------------------------------------------
415
416#Method bool isScaleTranslate() const
417
Cary Clarkab2621d2018-01-30 10:08:57 -0500418#Line # Returns if transform is limited to scale and translate. ##
Cary Clark154beea2017-10-26 07:58:48 -0400419Returns true if Matrix at most scales and translates. Matrix may be identity,
420contain only scale elements, only translate elements, or both. Matrix form is:
Cary Clarkbc5697d2017-10-04 14:31:33 -0400421
Cary Clark154beea2017-10-26 07:58:48 -0400422#Code
423#Literal
424| scale-x 0 translate-x |
425| 0 scale-y translate-y |
426| 0 0 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -0400427##
428
Cary Clark154beea2017-10-26 07:58:48 -0400429#Return true if Matrix is identity; or scales, translates, or both ##
430
431#Example
432SkMatrix matrix;
433for (SkScalar scaleX : { 1, 2 } ) {
434 for (SkScalar translateX : { 0, 20 } ) {
435 matrix.setAll(scaleX, 0, translateX, 0, 1, 0, 0, 0, 1);
436 SkDebugf("is scale-translate: %s\n", matrix.isScaleTranslate() ? "true" : "false");
437 }
438}
439#StdOut
440is scale-translate: true
441is scale-translate: true
442is scale-translate: true
443is scale-translate: true
444##
445##
446
447#SeeAlso setScale isTranslate setTranslate getType
Cary Clarkbc5697d2017-10-04 14:31:33 -0400448
449##
450
451# ------------------------------------------------------------------------------
452
453#Method bool isTranslate() const
454
Cary Clarkab2621d2018-01-30 10:08:57 -0500455#Line # Returns if transform is limited to translate. ##
Cary Clark154beea2017-10-26 07:58:48 -0400456Returns true if Matrix is identity, or translates. Matrix form is:
Cary Clarkbc5697d2017-10-04 14:31:33 -0400457
Cary Clark154beea2017-10-26 07:58:48 -0400458#Code
459#Literal
460| 1 0 translate-x |
461| 0 1 translate-y |
462| 0 0 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -0400463##
464
Cary Clark154beea2017-10-26 07:58:48 -0400465#Return true if Matrix is identity, or translates ##
466
467#Example
468SkMatrix matrix;
469for (SkScalar scaleX : { 1, 2 } ) {
470 for (SkScalar translateX : { 0, 20 } ) {
471 matrix.setAll(scaleX, 0, translateX, 0, 1, 0, 0, 0, 1);
472 SkDebugf("is translate: %s\n", matrix.isTranslate() ? "true" : "false");
473 }
474}
475#StdOut
476is translate: true
477is translate: true
478is translate: false
479is translate: false
480##
481##
482
483#SeeAlso setTranslate getType
Cary Clarkbc5697d2017-10-04 14:31:33 -0400484
485##
486
487# ------------------------------------------------------------------------------
488
489#Method bool rectStaysRect() const
490
Cary Clarkab2621d2018-01-30 10:08:57 -0500491#Line # Returns if mapped Rect can be represented by another Rect. ##
Cary Clark154beea2017-10-26 07:58:48 -0400492Returns true Matrix maps Rect to another Rect. If true, Matrix is identity,
493or scales, or rotates a multiple of 90 degrees, or mirrors in x or y. In all
494cases, Matrix may also have translation. Matrix form is either:
Cary Clarkbc5697d2017-10-04 14:31:33 -0400495
Cary Clark154beea2017-10-26 07:58:48 -0400496#Code
497#Literal
498| scale-x 0 translate-x |
499| 0 scale-y translate-y |
500| 0 0 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -0400501##
502
Cary Clark154beea2017-10-26 07:58:48 -0400503or
504
505#Code
506#Literal
507| 0 rotate-x translate-x |
508| rotate-y 0 translate-y |
509| 0 0 1 |
510##
511
512for non-zero values of scale-x, scale-y, rotate-x, and rotate-y.
513
514Also called preservesAxisAlignment; use the one that provides better inline
515documentation.
516
517#Return true if Matrix maps one Rect into another ##
518
519#Example
520SkMatrix matrix;
521for (SkScalar angle: { 0, 90, 180, 270 } ) {
522 matrix.setRotate(angle);
523 SkDebugf("rectStaysRect: %s\n", matrix.rectStaysRect() ? "true" : "false");
524}
525#StdOut
526rectStaysRect: true
527rectStaysRect: true
528rectStaysRect: true
529rectStaysRect: true
530##
531##
532
533#SeeAlso preservesAxisAlignment preservesRightAngles
Cary Clarkbc5697d2017-10-04 14:31:33 -0400534
535##
536
537# ------------------------------------------------------------------------------
538
539#Method bool preservesAxisAlignment() const
540
Cary Clarkab2621d2018-01-30 10:08:57 -0500541#Line # Returns if mapping restricts to 90 degree multiples and mirroring. ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400542
Cary Clark154beea2017-10-26 07:58:48 -0400543Returns true Matrix maps Rect to another Rect. If true, Matrix is identity,
544or scales, or rotates a multiple of 90 degrees, or mirrors in x or y. In all
545cases, Matrix may also have translation. Matrix form is either:
Cary Clarkbc5697d2017-10-04 14:31:33 -0400546
Cary Clark154beea2017-10-26 07:58:48 -0400547#Code
548#Literal
549| scale-x 0 translate-x |
550| 0 scale-y translate-y |
551| 0 0 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -0400552##
553
Cary Clark154beea2017-10-26 07:58:48 -0400554or
555
556#Code
557#Literal
558| 0 rotate-x translate-x |
559| rotate-y 0 translate-y |
560| 0 0 1 |
561##
562
563for non-zero values of scale-x, scale-y, rotate-x, and rotate-y.
564
565Also called rectStaysRect; use the one that provides better inline
566documentation.
567
568#Return true if Matrix maps one Rect into another ##
569
570#Example
571SkMatrix matrix;
572for (SkScalar angle: { 0, 90, 180, 270 } ) {
573 matrix.setRotate(angle);
574 SkDebugf("preservesAxisAlignment: %s\n", matrix.preservesAxisAlignment() ? "true" : "false");
575}
576#StdOut
577preservesAxisAlignment: true
578preservesAxisAlignment: true
579preservesAxisAlignment: true
580preservesAxisAlignment: true
581##
582##
583
584#SeeAlso rectStaysRect preservesRightAngles
Cary Clarkbc5697d2017-10-04 14:31:33 -0400585
586##
587
588# ------------------------------------------------------------------------------
589
590#Method bool hasPerspective() const
591
Cary Clarkab2621d2018-01-30 10:08:57 -0500592#Line # Returns if transform includes perspective. ##
Cary Clark154beea2017-10-26 07:58:48 -0400593Returns true if the matrix contains perspective elements. Matrix form is:
Cary Clarkbc5697d2017-10-04 14:31:33 -0400594
Cary Clark154beea2017-10-26 07:58:48 -0400595#Code
596#Literal
597| -- -- -- |
598| -- -- -- |
599| perspective-x perspective-y perspective-scale |
Cary Clarkbc5697d2017-10-04 14:31:33 -0400600##
601
Cary Clark154beea2017-10-26 07:58:48 -0400602where perspective-x or perspective-y is non-zero, or perspective-scale is
603not one. All other elements may have any value.
604
605#Return true if Matrix is in most general form ##
606
607#Example
608#Image 4
609SkMatrix matrix;
610SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}};
611SkRect::Make(source.bounds()).toQuad(bitmapBounds);
612matrix.setPolyToPoly(bitmapBounds, perspect, 4);
613canvas->concat(matrix);
614SkString string;
615string.printf("hasPerspective %s", matrix.hasPerspective() ? "true" : "false");
616canvas->drawBitmap(source, 0, 0);
617SkPaint paint;
618paint.setAntiAlias(true);
619paint.setTextSize(48);
620canvas->drawString(string, 0, source.bounds().height() + 48, paint);
621##
622
Cary Clarkbef063a2017-10-31 15:44:45 -0400623#SeeAlso setAll set9 MakeAll
Cary Clarkbc5697d2017-10-04 14:31:33 -0400624
625##
626
627# ------------------------------------------------------------------------------
628
629#Method bool isSimilarity(SkScalar tol = SK_ScalarNearlyZero) const
630
Cary Clarkab2621d2018-01-30 10:08:57 -0500631#Line # Returns if transform is limited to square scale and rotation. ##
Cary Clark154beea2017-10-26 07:58:48 -0400632Returns true if Matrix contains only translation, rotation, reflection, and
633uniform scale.
634Returns false if Matrix contains different scales, skewing, perspective, or
635degenerate forms that collapse to a line or point.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400636
Cary Clark154beea2017-10-26 07:58:48 -0400637Describes that the Matrix makes rendering with and without the matrix are
638visually alike; a transformed circle remains a circle. Mathematically, this is
Cary Clarka560c472017-11-27 10:44:06 -0500639referred to as similarity of a Euclidean_Space, or a similarity transformation.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400640
Cary Clark154beea2017-10-26 07:58:48 -0400641Preserves right angles, keeping the arms of the angle equal lengths.
642
643#Param tol to be deprecated ##
644
645#Return true if Matrix only rotates, uniformly scales, translates ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400646
647#Example
Cary Clark154beea2017-10-26 07:58:48 -0400648#Description
649String is drawn four times through but only two are visible. Drawing the pair
650with isSimilarity false reveals the pair not visible through the matrix.
651##
652 SkPaint p;
653 p.setAntiAlias(true);
654 SkMatrix m;
655 int below = 175;
656 for (SkScalar sx : { -1, 1 } ) {
657 for (SkScalar sy : { -1, 1 } ) {
658 m.setAll(sx, 1, 128, 1, sy, 32, 0, 0, 1);
659 bool isSimilarity = m.isSimilarity();
660 SkString str;
661 str.printf("sx: %g sy: %g sim: %s", sx, sy, isSimilarity ? "true" : "false");
662 {
663 SkAutoCanvasRestore autoRestore(canvas, true);
664 canvas->concat(m);
665 canvas->drawString(str, 0, 0, p);
666 }
667 if (!isSimilarity) {
668 canvas->drawString(str, 40, below, p);
669 below += 20;
670 }
671 }
672 }
Cary Clarkbc5697d2017-10-04 14:31:33 -0400673##
674
Cary Clark154beea2017-10-26 07:58:48 -0400675#SeeAlso isScaleTranslate preservesRightAngles rectStaysRect isFixedStepInX
Cary Clarkbc5697d2017-10-04 14:31:33 -0400676
677##
678
679# ------------------------------------------------------------------------------
680
681#Method bool preservesRightAngles(SkScalar tol = SK_ScalarNearlyZero) const
682
Cary Clarkab2621d2018-01-30 10:08:57 -0500683#Line # Returns if mapped 90 angle remains 90 degrees. ##
Cary Clark154beea2017-10-26 07:58:48 -0400684Returns true if Matrix contains only translation, rotation, reflection, and
685scale. Scale may differ along rotated axes.
686Returns false if Matrix skewing, perspective, or degenerate forms that collapse
687to a line or point.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400688
Cary Clark154beea2017-10-26 07:58:48 -0400689Preserves right angles, but not requiring that the arms of the angle
690retain equal lengths.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400691
Cary Clark154beea2017-10-26 07:58:48 -0400692#Param tol to be deprecated ##
693
694#Return true if Matrix only rotates, scales, translates ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400695
696#Example
Cary Clark154beea2017-10-26 07:58:48 -0400697#Height 128
698#Description
699Equal scale is both similar and preserves right angles.
700Unequal scale is not similar but preserves right angles.
701Skews are not similar and do not preserve right angles.
702##
703SkPaint p;
704p.setAntiAlias(true);
705SkMatrix m;
706int pos = 0;
707for (SkScalar sx : { 1, 2 } ) {
708 for (SkScalar kx : { 0, 1 } ) {
709 m.setAll(sx, kx, 16, 0, 1, 32, 0, 0, 1);
710 bool isSimilarity = m.isSimilarity();
711 bool preservesRightAngles = m.preservesRightAngles();
712 SkString str;
713 str.printf("sx: %g kx: %g %s %s", sx, kx, isSimilarity ? "sim" : "",
714 preservesRightAngles ? "right" : "");
715 SkAutoCanvasRestore autoRestore(canvas, true);
716 canvas->concat(m);
717 canvas->drawString(str, 0, pos, p);
718 pos += 20;
719 }
720}
Cary Clarkbc5697d2017-10-04 14:31:33 -0400721##
722
Cary Clark154beea2017-10-26 07:58:48 -0400723#SeeAlso isScaleTranslate isSimilarity rectStaysRect isFixedStepInX
Cary Clarkbc5697d2017-10-04 14:31:33 -0400724
725##
726
727# ------------------------------------------------------------------------------
728
Cary Clark154beea2017-10-26 07:58:48 -0400729#Enum
Cary Clarkbc5697d2017-10-04 14:31:33 -0400730
731#Code
732 enum {
733 kMScaleX,
734 kMSkewX,
735 kMTransX,
736 kMSkewY,
737 kMScaleY,
738 kMTransY,
739 kMPersp0,
740 kMPersp1,
741 kMPersp2,
742 };
743##
744
Cary Clark154beea2017-10-26 07:58:48 -0400745Matrix organizes its values in row order. These members correspond to
746each value in Matrix.
747
Cary Clarkbc5697d2017-10-04 14:31:33 -0400748#Const kMScaleX 0
Cary Clark154beea2017-10-26 07:58:48 -0400749horizontal scale factor
Cary Clarkbc5697d2017-10-04 14:31:33 -0400750##
751#Const kMSkewX 1
Cary Clark154beea2017-10-26 07:58:48 -0400752horizontal skew factor
Cary Clarkbc5697d2017-10-04 14:31:33 -0400753##
754#Const kMTransX 2
Cary Clark154beea2017-10-26 07:58:48 -0400755horizontal translation
Cary Clarkbc5697d2017-10-04 14:31:33 -0400756##
757#Const kMSkewY 3
Cary Clark154beea2017-10-26 07:58:48 -0400758vertical skew factor
Cary Clarkbc5697d2017-10-04 14:31:33 -0400759##
760#Const kMScaleY 4
Cary Clark154beea2017-10-26 07:58:48 -0400761vertical scale factor
Cary Clarkbc5697d2017-10-04 14:31:33 -0400762##
763#Const kMTransY 5
Cary Clark154beea2017-10-26 07:58:48 -0400764vertical translation
Cary Clarkbc5697d2017-10-04 14:31:33 -0400765##
766#Const kMPersp0 6
Cary Clark154beea2017-10-26 07:58:48 -0400767input x perspective factor
Cary Clarkbc5697d2017-10-04 14:31:33 -0400768##
769#Const kMPersp1 7
Cary Clark154beea2017-10-26 07:58:48 -0400770input y perspective factor
Cary Clarkbc5697d2017-10-04 14:31:33 -0400771##
772#Const kMPersp2 8
Cary Clark154beea2017-10-26 07:58:48 -0400773perspective bias
Cary Clarkbc5697d2017-10-04 14:31:33 -0400774##
775
776#Example
Cary Clark154beea2017-10-26 07:58:48 -0400777SkPaint black;
778black.setAntiAlias(true);
779black.setTextSize(48);
780SkPaint gray = black;
781gray.setColor(0xFF9f9f9f);
782SkScalar offset[] = { 1.5f, 1.5f, 20, 1.5f, 1.5f, 20, .03f, .01f, 2 };
783for (int i : { SkMatrix::kMScaleX, SkMatrix::kMSkewX, SkMatrix::kMTransX,
784 SkMatrix::kMSkewY, SkMatrix::kMScaleY, SkMatrix::kMTransY,
785 SkMatrix::kMPersp0, SkMatrix::kMPersp1, SkMatrix::kMPersp2 } ) {
786 SkMatrix m;
787 m.setIdentity();
788 m.set(i, offset[i]);
789 SkAutoCanvasRestore autoRestore(canvas, true);
790 canvas->translate(22 + (i % 3) * 88, 44 + (i / 3) * 88);
791 canvas->drawString("&", 0, 0, gray);
792 canvas->concat(m);
793 canvas->drawString("&", 0, 0, black);
794}
Cary Clarkbc5697d2017-10-04 14:31:33 -0400795##
796
Cary Clark154beea2017-10-26 07:58:48 -0400797#SeeAlso get() set()
Cary Clarkbc5697d2017-10-04 14:31:33 -0400798
799##
800
801# ------------------------------------------------------------------------------
802
Cary Clark154beea2017-10-26 07:58:48 -0400803#Enum
Cary Clarkbc5697d2017-10-04 14:31:33 -0400804
805#Code
806 enum {
807 kAScaleX,
808 kASkewY,
809 kASkewX,
810 kAScaleY,
811 kATransX,
812 kATransY,
813 };
814##
815
Cary Clark154beea2017-10-26 07:58:48 -0400816Affine arrays are in column major order to match the matrix used by
817PDF and XPS.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400818
819#Const kAScaleX 0
Cary Clark154beea2017-10-26 07:58:48 -0400820horizontal scale factor
Cary Clarkbc5697d2017-10-04 14:31:33 -0400821##
822#Const kASkewY 1
Cary Clark154beea2017-10-26 07:58:48 -0400823vertical skew factor
Cary Clarkbc5697d2017-10-04 14:31:33 -0400824##
825#Const kASkewX 2
Cary Clark154beea2017-10-26 07:58:48 -0400826horizontal skew factor
Cary Clarkbc5697d2017-10-04 14:31:33 -0400827##
828#Const kAScaleY 3
Cary Clark154beea2017-10-26 07:58:48 -0400829vertical scale factor
Cary Clarkbc5697d2017-10-04 14:31:33 -0400830##
831#Const kATransX 4
Cary Clark154beea2017-10-26 07:58:48 -0400832horizontal translation
Cary Clarkbc5697d2017-10-04 14:31:33 -0400833##
834#Const kATransY 5
Cary Clark154beea2017-10-26 07:58:48 -0400835vertical translation
Cary Clarkbc5697d2017-10-04 14:31:33 -0400836##
837
Cary Clark154beea2017-10-26 07:58:48 -0400838#NoExample
Cary Clarkbc5697d2017-10-04 14:31:33 -0400839##
840
Cary Clark154beea2017-10-26 07:58:48 -0400841#SeeAlso SetAffineIdentity asAffine setAffine
Cary Clarkbc5697d2017-10-04 14:31:33 -0400842
843##
844
845# ------------------------------------------------------------------------------
846
Cary Clarka560c472017-11-27 10:44:06 -0500847#Method SkScalar operator[](int index)_const
Cary Clarkbc5697d2017-10-04 14:31:33 -0400848
Cary Clarkab2621d2018-01-30 10:08:57 -0500849#Line # Returns Matrix value. ##
Cary Clark154beea2017-10-26 07:58:48 -0400850Returns one matrix value. Asserts if index is out of range and SK_DEBUG is
851defined.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400852
Cary Clark154beea2017-10-26 07:58:48 -0400853#Param index one of: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY,
854 kMPersp0, kMPersp1, kMPersp2
Cary Clarkbc5697d2017-10-04 14:31:33 -0400855##
856
Cary Clark154beea2017-10-26 07:58:48 -0400857#Return value corresponding to index ##
858
859#Example
860SkMatrix matrix;
861matrix.setScale(42, 24);
862SkDebugf("matrix[SkMatrix::kMScaleX] %c= 42\n", matrix[SkMatrix::kMScaleX] == 42 ? '=' : '!');
863SkDebugf("matrix[SkMatrix::kMScaleY] %c= 24\n", matrix[SkMatrix::kMScaleY] == 24 ? '=' : '!');
864#StdOut
865matrix[SkMatrix::kMScaleX] == 42
866matrix[SkMatrix::kMScaleY] == 24
867##
868##
869
870#SeeAlso get set
Cary Clarkbc5697d2017-10-04 14:31:33 -0400871
872##
873
874# ------------------------------------------------------------------------------
875
876#Method SkScalar get(int index) const
877
Cary Clarkab2621d2018-01-30 10:08:57 -0500878#Line # Returns one of nine Matrix values. ##
Cary Clark154beea2017-10-26 07:58:48 -0400879Returns one matrix value. Asserts if index is out of range and SK_DEBUG is
880defined.
Cary Clarkbc5697d2017-10-04 14:31:33 -0400881
Cary Clark154beea2017-10-26 07:58:48 -0400882#Param index one of: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY,
883 kMPersp0, kMPersp1, kMPersp2
Cary Clarkbc5697d2017-10-04 14:31:33 -0400884##
885
Cary Clark154beea2017-10-26 07:58:48 -0400886#Return value corresponding to index ##
887
888#Example
889SkMatrix matrix;
890matrix.setSkew(42, 24);
891SkDebugf("matrix.get(SkMatrix::kMSkewX) %c= 42\n",
892 matrix.get(SkMatrix::kMSkewX) == 42 ? '=' : '!');
893SkDebugf("matrix.get(SkMatrix::kMSkewY) %c= 24\n",
894 matrix.get(SkMatrix::kMSkewY) == 24 ? '=' : '!');
895#StdOut
896matrix.get(SkMatrix::kMSkewX) == 42
897matrix.get(SkMatrix::kMSkewY) == 24
898##
899##
900
901#SeeAlso operator[](int index) set
Cary Clarkbc5697d2017-10-04 14:31:33 -0400902
903##
904
905# ------------------------------------------------------------------------------
906
907#Method SkScalar getScaleX() const
908
Cary Clarkab2621d2018-01-30 10:08:57 -0500909#Line # Returns horizontal scale factor. ##
Cary Clark154beea2017-10-26 07:58:48 -0400910Returns scale factor multiplied by x input, contributing to x output.
911With mapPoints, scales Points along the x-axis.
912
913#Return horizontal scale factor ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400914
915#Example
Cary Clark154beea2017-10-26 07:58:48 -0400916SkMatrix matrix;
917matrix.setScale(42, 24);
918SkDebugf("matrix.getScaleX() %c= 42\n", matrix.getScaleX() == 42 ? '=' : '!');
919#StdOut
920matrix.getScaleX() == 42
921##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400922##
923
Cary Clark154beea2017-10-26 07:58:48 -0400924#SeeAlso get getScaleY setScaleX setScale
Cary Clarkbc5697d2017-10-04 14:31:33 -0400925
926##
927
928# ------------------------------------------------------------------------------
929
930#Method SkScalar getScaleY() const
931
Cary Clarkab2621d2018-01-30 10:08:57 -0500932#Line # Returns vertical scale factor. ##
Cary Clark154beea2017-10-26 07:58:48 -0400933Returns scale factor multiplied by y input, contributing to y output.
934With mapPoints, scales Points along the y-axis.
935
936#Return vertical scale factor ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400937
938#Example
Cary Clark154beea2017-10-26 07:58:48 -0400939SkMatrix matrix;
940matrix.setScale(42, 24);
941SkDebugf("matrix.getScaleY() %c= 24\n", matrix.getScaleY() == 24 ? '=' : '!');
942#StdOut
943matrix.getScaleY() == 24
944##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400945##
946
Cary Clark154beea2017-10-26 07:58:48 -0400947#SeeAlso get getScaleX setScaleY setScale
Cary Clarkbc5697d2017-10-04 14:31:33 -0400948
949##
950
951# ------------------------------------------------------------------------------
952
953#Method SkScalar getSkewY() const
954
Cary Clarkab2621d2018-01-30 10:08:57 -0500955#Line # Returns vertical skew factor. ##
Cary Clark154beea2017-10-26 07:58:48 -0400956Returns scale factor multiplied by x input, contributing to y output.
957With mapPoints, skews Points along the y-axis.
958Skew x and y together can rotate Points.
959
960#Return vertical skew factor ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400961
962#Example
Cary Clark154beea2017-10-26 07:58:48 -0400963SkMatrix matrix;
964matrix.setSkew(42, 24);
965SkDebugf("matrix.getSkewY() %c= 24\n", matrix.getSkewY() == 24 ? '=' : '!');
966#StdOut
967matrix.getSkewY() == 24
968##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400969##
970
Cary Clark154beea2017-10-26 07:58:48 -0400971#SeeAlso get getSkewX setSkewY setSkew
Cary Clarkbc5697d2017-10-04 14:31:33 -0400972
973##
974
975# ------------------------------------------------------------------------------
976
977#Method SkScalar getSkewX() const
978
Cary Clarkab2621d2018-01-30 10:08:57 -0500979#Line # Returns horizontal skew factor. ##
Cary Clark154beea2017-10-26 07:58:48 -0400980Returns scale factor multiplied by y input, contributing to x output.
981With mapPoints, skews Points along the x-axis.
982Skew x and y together can rotate Points.
983
984#Return horizontal scale factor ##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400985
986#Example
Cary Clark154beea2017-10-26 07:58:48 -0400987SkMatrix matrix;
988matrix.setSkew(42, 24);
989SkDebugf("matrix.getSkewX() %c= 42\n", matrix.getSkewX() == 42 ? '=' : '!');
990#StdOut
991matrix.getSkewX() == 42
992##
Cary Clarkbc5697d2017-10-04 14:31:33 -0400993##
994
Cary Clark154beea2017-10-26 07:58:48 -0400995#SeeAlso get getSkewY setSkewX setSkew
Cary Clarkbc5697d2017-10-04 14:31:33 -0400996
997##
998
999# ------------------------------------------------------------------------------
1000
1001#Method SkScalar getTranslateX() const
1002
Cary Clarkab2621d2018-01-30 10:08:57 -05001003#Line # Returns horizontal translation. ##
Cary Clark154beea2017-10-26 07:58:48 -04001004Returns translation contributing to x output.
1005With mapPoints, moves Points along the x-axis.
1006
1007#Return horizontal translation factor ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001008
1009#Example
Cary Clark154beea2017-10-26 07:58:48 -04001010SkMatrix matrix;
1011matrix.setTranslate(42, 24);
1012SkDebugf("matrix.getTranslateX() %c= 42\n", matrix.getTranslateX() == 42 ? '=' : '!');
1013#StdOut
1014matrix.getTranslateX() == 42
1015##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001016##
1017
Cary Clark154beea2017-10-26 07:58:48 -04001018#SeeAlso get getTranslateY setTranslateX setTranslate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001019
1020##
1021
1022# ------------------------------------------------------------------------------
1023
1024#Method SkScalar getTranslateY() const
1025
Cary Clarkab2621d2018-01-30 10:08:57 -05001026#Line # Returns vertical translation. ##
Cary Clark154beea2017-10-26 07:58:48 -04001027Returns translation contributing to y output.
1028With mapPoints, moves Points along the y-axis.
1029
1030#Return vertical translation factor ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001031
1032#Example
Cary Clark154beea2017-10-26 07:58:48 -04001033SkMatrix matrix;
1034matrix.setTranslate(42, 24);
1035SkDebugf("matrix.getTranslateY() %c= 24\n", matrix.getTranslateY() == 24 ? '=' : '!');
1036#StdOut
1037matrix.getTranslateY() == 24
1038##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001039##
1040
Cary Clark154beea2017-10-26 07:58:48 -04001041#SeeAlso get getTranslateX setTranslateY setTranslate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001042
1043##
1044
1045# ------------------------------------------------------------------------------
1046
1047#Method SkScalar getPerspX() const
1048
Cary Clarkab2621d2018-01-30 10:08:57 -05001049#Line # Returns input x perspective factor. ##
Cary Clark154beea2017-10-26 07:58:48 -04001050Returns factor scaling input x relative to input y.
1051
1052#Return input x perspective factor ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001053
1054#Example
Cary Clark154beea2017-10-26 07:58:48 -04001055 SkMatrix m;
1056 m.setIdentity();
1057 m.set(SkMatrix::kMPersp0, -0.004f);
1058 SkAutoCanvasRestore autoRestore(canvas, true);
1059 canvas->translate(22, 144);
1060 SkPaint black;
1061 black.setAntiAlias(true);
1062 black.setTextSize(24);
1063 SkPaint gray = black;
1064 gray.setColor(0xFF9f9f9f);
1065 SkString string;
1066 string.appendScalar(m.getPerspX());
1067 canvas->drawString(string, 0, -72, gray);
1068 canvas->concat(m);
1069 canvas->drawString(string, 0, 0, black);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001070##
1071
Cary Clark154beea2017-10-26 07:58:48 -04001072#SeeAlso kMPersp0 getPerspY
Cary Clarkbc5697d2017-10-04 14:31:33 -04001073
1074##
1075
1076# ------------------------------------------------------------------------------
1077
1078#Method SkScalar getPerspY() const
1079
Cary Clarkab2621d2018-01-30 10:08:57 -05001080#Line # Returns input y perspective factor. ##
Cary Clark154beea2017-10-26 07:58:48 -04001081
1082Returns factor scaling input y relative to input x.
1083
1084#Return input y perspective factor ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001085
1086#Example
Cary Clark154beea2017-10-26 07:58:48 -04001087 SkMatrix m;
1088 m.setIdentity();
1089 m.set(SkMatrix::kMPersp1, -0.004f);
1090 SkAutoCanvasRestore autoRestore(canvas, true);
1091 canvas->translate(22, 144);
1092 SkPaint black;
1093 black.setAntiAlias(true);
1094 black.setTextSize(24);
1095 SkPaint gray = black;
1096 gray.setColor(0xFF9f9f9f);
1097 SkString string;
1098 string.appendScalar(m.getPerspY());
1099 canvas->drawString(string, 0, -72, gray);
1100 canvas->concat(m);
1101 canvas->drawString(string, 0, 0, black);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001102##
1103
Cary Clark154beea2017-10-26 07:58:48 -04001104#SeeAlso kMPersp1 getPerspX
Cary Clarkbc5697d2017-10-04 14:31:33 -04001105
1106##
1107
1108# ------------------------------------------------------------------------------
1109
Cary Clark154beea2017-10-26 07:58:48 -04001110#Method SkScalar& operator[](int index)
Cary Clarkbc5697d2017-10-04 14:31:33 -04001111
Cary Clarkab2621d2018-01-30 10:08:57 -05001112#Line # Returns writable reference to Matrix value. ##
Cary Clark154beea2017-10-26 07:58:48 -04001113Returns writable Matrix value. Asserts if index is out of range and SK_DEBUG is
1114defined. Clears internal cache anticipating that caller will change Matrix value.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001115
Cary Clark154beea2017-10-26 07:58:48 -04001116Next call to read Matrix state may recompute cache; subsequent writes to Matrix
1117value must be followed by dirtyMatrixTypeCache.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001118
Cary Clark154beea2017-10-26 07:58:48 -04001119#Param index one of: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY,
1120 kMPersp0, kMPersp1, kMPersp2
Cary Clarkbc5697d2017-10-04 14:31:33 -04001121##
1122
Cary Clark154beea2017-10-26 07:58:48 -04001123#Return writable value corresponding to index ##
1124
1125#Example
1126SkMatrix matrix;
1127matrix.setIdentity();
1128SkDebugf("with identity matrix: x = %g\n", matrix.mapXY(24, 42).fX);
1129SkScalar& skewRef = matrix[SkMatrix::kMSkewX];
1130skewRef = 0;
1131SkDebugf("after skew x mod: x = %g\n", matrix.mapXY(24, 42).fX);
1132skewRef = 1;
1133SkDebugf("after 2nd skew x mod: x = %g\n", matrix.mapXY(24, 42).fX);
1134matrix.dirtyMatrixTypeCache();
1135SkDebugf("after dirty cache: x = %g\n", matrix.mapXY(24, 42).fX);
1136#StdOut
1137with identity matrix: x = 24
1138after skew x mod: x = 24
1139after 2nd skew x mod: x = 24
1140after dirty cache: x = 66
1141##
1142##
1143
1144#SeeAlso get dirtyMatrixTypeCache set
Cary Clarkbc5697d2017-10-04 14:31:33 -04001145
1146##
1147
1148# ------------------------------------------------------------------------------
1149
1150#Method void set(int index, SkScalar value)
1151
Cary Clarkab2621d2018-01-30 10:08:57 -05001152#Line # Sets one value. ##
Cary Clark154beea2017-10-26 07:58:48 -04001153Sets Matrix value. Asserts if index is out of range and SK_DEBUG is
1154defined. Safer than operator[]; internal cache is always maintained.
1155
1156#Param index one of: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY,
1157 kMPersp0, kMPersp1, kMPersp2
1158##
1159#Param value Scalar to store in Matrix ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001160
1161#Example
Cary Clark154beea2017-10-26 07:58:48 -04001162SkMatrix matrix;
1163matrix.setIdentity();
1164SkDebugf("with identity matrix: x = %g\n", matrix.mapXY(24, 42).fX);
1165matrix.set(SkMatrix::kMSkewX, 0);
1166SkDebugf("after skew x mod: x = %g\n", matrix.mapXY(24, 42).fX);
1167matrix.set(SkMatrix::kMSkewX, 1);
1168SkDebugf("after 2nd skew x mod: x = %g\n", matrix.mapXY(24, 42).fX);
1169#StdOut
1170with identity matrix: x = 24
1171after skew x mod: x = 24
1172after 2nd skew x mod: x = 66
1173##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001174##
1175
Cary Clark154beea2017-10-26 07:58:48 -04001176#SeeAlso operator[] get
Cary Clarkbc5697d2017-10-04 14:31:33 -04001177
Cary Clark154beea2017-10-26 07:58:48 -04001178#Method ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001179
1180# ------------------------------------------------------------------------------
1181
1182#Method void setScaleX(SkScalar v)
1183
Cary Clarkab2621d2018-01-30 10:08:57 -05001184#Line # Sets horizontal scale factor. ##
Cary Clark154beea2017-10-26 07:58:48 -04001185Sets horizontal scale factor.
1186
1187#Param v horizontal scale factor to store ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001188
1189#Example
Cary Clark154beea2017-10-26 07:58:48 -04001190#Height 64
1191SkPaint paint;
1192paint.setAntiAlias(true);
1193paint.setTextSize(24);
1194canvas->drawString("normal", 12, 24, paint);
1195SkMatrix matrix;
1196matrix.setIdentity();
1197matrix.setScaleX(3);
1198canvas->concat(matrix);
1199canvas->drawString("x scale", 0, 48, paint);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001200##
1201
Cary Clark154beea2017-10-26 07:58:48 -04001202#SeeAlso set setScale setScaleY
Cary Clarkbc5697d2017-10-04 14:31:33 -04001203
Cary Clark154beea2017-10-26 07:58:48 -04001204#Method ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001205
1206# ------------------------------------------------------------------------------
1207
1208#Method void setScaleY(SkScalar v)
1209
Cary Clarkab2621d2018-01-30 10:08:57 -05001210#Line # Sets vertical scale factor ##
Cary Clark154beea2017-10-26 07:58:48 -04001211Sets vertical scale factor.
1212
1213#Param v vertical scale factor to store ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001214
1215#Example
Cary Clark154beea2017-10-26 07:58:48 -04001216#Height 192
1217SkPaint paint;
1218paint.setAntiAlias(true);
1219paint.setTextSize(24);
1220canvas->drawString("normal", 12, 24, paint);
1221SkMatrix matrix;
1222matrix.setIdentity();
1223matrix.setScaleY(3);
1224canvas->concat(matrix);
1225canvas->drawString("y scale", 12, 48, paint);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001226##
1227
Cary Clark154beea2017-10-26 07:58:48 -04001228#SeeAlso set setScale setScaleX
Cary Clarkbc5697d2017-10-04 14:31:33 -04001229
Cary Clark154beea2017-10-26 07:58:48 -04001230#Method ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001231
1232# ------------------------------------------------------------------------------
1233
1234#Method void setSkewY(SkScalar v)
1235
Cary Clarkab2621d2018-01-30 10:08:57 -05001236#Line # Sets vertical skew factor. ##
Cary Clark154beea2017-10-26 07:58:48 -04001237Sets vertical skew factor.
1238
1239#Param v vertical skew factor to store ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001240
1241#Example
Cary Clark154beea2017-10-26 07:58:48 -04001242#Height 96
1243SkPaint paint;
1244paint.setAntiAlias(true);
1245paint.setTextSize(24);
1246canvas->drawString("normal", 12, 24, paint);
1247SkMatrix matrix;
1248matrix.setIdentity();
1249matrix.setSkewY(.3f);
1250canvas->concat(matrix);
1251canvas->drawString("y skew", 12, 48, paint);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001252##
1253
Cary Clark154beea2017-10-26 07:58:48 -04001254#SeeAlso set setSkew setSkewX
Cary Clarkbc5697d2017-10-04 14:31:33 -04001255
Cary Clark154beea2017-10-26 07:58:48 -04001256#Method ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001257
1258# ------------------------------------------------------------------------------
1259
1260#Method void setSkewX(SkScalar v)
1261
Cary Clarkab2621d2018-01-30 10:08:57 -05001262#Line # Sets horizontal skew factor. ##
Cary Clark154beea2017-10-26 07:58:48 -04001263Sets horizontal skew factor.
1264
1265#Param v horizontal skew factor to store ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001266
1267#Example
Cary Clark154beea2017-10-26 07:58:48 -04001268#Height 64
1269SkPaint paint;
1270paint.setAntiAlias(true);
1271paint.setTextSize(24);
1272canvas->drawString("normal", 12, 24, paint);
1273SkMatrix matrix;
1274matrix.setIdentity();
1275matrix.setSkewX(-.7f);
1276canvas->concat(matrix);
1277canvas->drawString("x skew", 36, 48, paint);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001278##
1279
Cary Clark154beea2017-10-26 07:58:48 -04001280#SeeAlso set setSkew setSkewX
Cary Clarkbc5697d2017-10-04 14:31:33 -04001281
Cary Clark154beea2017-10-26 07:58:48 -04001282#Method ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001283
1284# ------------------------------------------------------------------------------
1285
1286#Method void setTranslateX(SkScalar v)
1287
Cary Clarkab2621d2018-01-30 10:08:57 -05001288#Line # Sets horizontal translation. ##
Cary Clark154beea2017-10-26 07:58:48 -04001289Sets horizontal translation.
1290
1291#Param v horizontal translation to store ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001292
1293#Example
Cary Clark154beea2017-10-26 07:58:48 -04001294#Height 48
1295SkPaint paint;
1296paint.setAntiAlias(true);
1297paint.setTextSize(24);
1298canvas->drawString("normal", 8, 24, paint);
1299SkMatrix matrix;
1300matrix.setIdentity();
1301matrix.setTranslateX(96);
1302canvas->concat(matrix);
1303canvas->drawString("x translate", 8, 24, paint);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001304##
1305
Cary Clark154beea2017-10-26 07:58:48 -04001306#SeeAlso set setTranslate setTranslateY
Cary Clarkbc5697d2017-10-04 14:31:33 -04001307
Cary Clark154beea2017-10-26 07:58:48 -04001308#Method ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001309
1310# ------------------------------------------------------------------------------
1311
1312#Method void setTranslateY(SkScalar v)
1313
Cary Clarkab2621d2018-01-30 10:08:57 -05001314#Line # Sets vertical translation. ##
Cary Clark154beea2017-10-26 07:58:48 -04001315Sets vertical translation.
1316
1317#Param v vertical translation to store ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001318
1319#Example
Cary Clark154beea2017-10-26 07:58:48 -04001320#Height 64
1321SkPaint paint;
1322paint.setAntiAlias(true);
1323paint.setTextSize(24);
1324canvas->drawString("normal", 8, 24, paint);
1325SkMatrix matrix;
1326matrix.setIdentity();
1327matrix.setTranslateY(24);
1328canvas->concat(matrix);
1329canvas->drawString("y translate", 8, 24, paint);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001330##
1331
Cary Clark154beea2017-10-26 07:58:48 -04001332#SeeAlso set setTranslate setTranslateX
Cary Clarkbc5697d2017-10-04 14:31:33 -04001333
Cary Clark154beea2017-10-26 07:58:48 -04001334#Method ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001335
1336# ------------------------------------------------------------------------------
1337
1338#Method void setPerspX(SkScalar v)
1339
Cary Clarkab2621d2018-01-30 10:08:57 -05001340#Line # Sets input x perspective factor. ##
Cary Clark154beea2017-10-26 07:58:48 -04001341Sets input x perspective factor, which causes mapXY to vary input x inversely
1342proportional to input y.
1343
1344#Param v perspective factor ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001345
1346#Example
Cary Clark154beea2017-10-26 07:58:48 -04001347#Image 4
1348for (SkScalar perspX : { -.003f, 0.f, .003f, .012f } ) {
1349 SkMatrix matrix;
1350 matrix.setIdentity();
1351 matrix.setPerspX(perspX);
1352 canvas->save();
1353 canvas->concat(matrix);
1354 canvas->drawBitmap(source, 0, 0);
1355 canvas->restore();
1356 canvas->translate(64, 64);
1357}
Cary Clarkbc5697d2017-10-04 14:31:33 -04001358##
1359
Cary Clarkbef063a2017-10-31 15:44:45 -04001360#SeeAlso getPerspX set setAll set9 MakeAll
Cary Clarkbc5697d2017-10-04 14:31:33 -04001361
Cary Clark154beea2017-10-26 07:58:48 -04001362#Method ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001363
1364# ------------------------------------------------------------------------------
1365
1366#Method void setPerspY(SkScalar v)
1367
Cary Clarkab2621d2018-01-30 10:08:57 -05001368#Line # Sets input y perspective factor. ##
Cary Clark154beea2017-10-26 07:58:48 -04001369Sets input y perspective factor, which causes mapXY to vary input y inversely
1370proportional to input x.
1371
1372#Param v perspective factor ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001373
1374#Example
Cary Clark154beea2017-10-26 07:58:48 -04001375#Image 4
1376for (SkScalar perspX : { -.003f, 0.f, .003f, .012f } ) {
1377 SkMatrix matrix;
1378 matrix.setIdentity();
1379 matrix.setPerspY(perspX);
1380 canvas->save();
1381 canvas->concat(matrix);
1382 canvas->drawBitmap(source, 0, 0);
1383 canvas->restore();
1384 canvas->translate(64, 64);
1385}
Cary Clarkbc5697d2017-10-04 14:31:33 -04001386##
1387
Cary Clarkbef063a2017-10-31 15:44:45 -04001388#SeeAlso getPerspY set setAll set9 MakeAll
Cary Clarkbc5697d2017-10-04 14:31:33 -04001389
Cary Clark154beea2017-10-26 07:58:48 -04001390#Method ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001391
1392# ------------------------------------------------------------------------------
1393
1394#Method void setAll(SkScalar scaleX, SkScalar skewX, SkScalar transX,
1395 SkScalar skewY, SkScalar scaleY, SkScalar transY,
1396 SkScalar persp0, SkScalar persp1, SkScalar persp2)
Cary Clarkab2621d2018-01-30 10:08:57 -05001397#Line # Sets all values from parameters. ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001398
Cary Clark154beea2017-10-26 07:58:48 -04001399Sets all values from parameters. Sets matrix to:
1400
1401#Code
1402#Literal
1403| scaleX skewX transX |
1404| skewY scaleY transY |
1405| persp0 persp1 persp2 |
1406##
1407
1408#Param scaleX horizontal scale factor to store ##
1409#Param skewX horizontal skew factor to store ##
1410#Param transX horizontal translation to store ##
1411#Param skewY vertical skew factor to store ##
1412#Param scaleY vertical scale factor to store ##
1413#Param transY vertical translation to store ##
1414#Param persp0 input x perspective factor to store ##
1415#Param persp1 input y perspective factor to store ##
1416#Param persp2 perspective scale factor to store ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001417
1418#Example
Cary Clark2ade9972017-11-02 17:49:34 -04001419#Height 128
Cary Clark154beea2017-10-26 07:58:48 -04001420 SkPaint p;
1421 p.setAntiAlias(true);
1422 p.setTextSize(64);
1423 SkMatrix m;
1424 for (SkScalar sx : { -1, 1 } ) {
1425 for (SkScalar sy : { -1, 1 } ) {
1426 SkAutoCanvasRestore autoRestore(canvas, true);
Cary Clark2ade9972017-11-02 17:49:34 -04001427 m.setAll(sx, 1, 128, 0, sy, 64, 0, 0, 1);
Cary Clark154beea2017-10-26 07:58:48 -04001428 canvas->concat(m);
1429 canvas->drawString("K", 0, 0, p);
1430 }
1431 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04001432##
1433
Cary Clarkbef063a2017-10-31 15:44:45 -04001434#SeeAlso set9 MakeAll
Cary Clarkbc5697d2017-10-04 14:31:33 -04001435
Cary Clark154beea2017-10-26 07:58:48 -04001436#Method ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001437
1438# ------------------------------------------------------------------------------
1439
1440#Method void get9(SkScalar buffer[9]) const
1441
Cary Clarkab2621d2018-01-30 10:08:57 -05001442#Line # Returns all nine Matrix values. ##
Cary Clark154beea2017-10-26 07:58:48 -04001443Copies nine Scalar values contained by Matrix into buffer, in member value
1444ascending order: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY,
1445kMPersp0, kMPersp1, kMPersp2.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001446
Cary Clark154beea2017-10-26 07:58:48 -04001447#Param buffer storage for nine Scalar values ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001448
1449#Example
Cary Clark154beea2017-10-26 07:58:48 -04001450SkMatrix matrix = SkMatrix::MakeRectToRect({0, 0, 1, 1}, {3, 4, 7, 9},
1451 SkMatrix::kFill_ScaleToFit);
1452SkScalar b[9];
1453matrix.get9(b);
1454SkDebugf("{%g, %g, %g},\n{%g, %g, %g},\n{%g, %g, %g}\n", b[0], b[1], b[2],
1455 b[3], b[4], b[5], b[6], b[7], b[8]);
1456#StdOut
1457{4, 0, 3},
1458{0, 5, 4},
1459{0, 0, 1}
1460##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001461##
1462
Cary Clark154beea2017-10-26 07:58:48 -04001463#SeeAlso set9
Cary Clarkbc5697d2017-10-04 14:31:33 -04001464
Cary Clark154beea2017-10-26 07:58:48 -04001465#Method ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001466
1467# ------------------------------------------------------------------------------
1468
1469#Method void set9(const SkScalar buffer[9])
1470
Cary Clarkab2621d2018-01-30 10:08:57 -05001471#Line # Sets all values from Scalar array. ##
Cary Clark154beea2017-10-26 07:58:48 -04001472Sets Matrix to nine Scalar values in buffer, in member value ascending order:
1473kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY, kMPersp0, kMPersp1,
1474kMPersp2.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001475
Cary Clark154beea2017-10-26 07:58:48 -04001476Sets matrix to:
Cary Clarkbc5697d2017-10-04 14:31:33 -04001477
Cary Clark154beea2017-10-26 07:58:48 -04001478#Code
1479#Literal
1480| buffer[0] buffer[1] buffer[2] |
1481| buffer[3] buffer[4] buffer[5] |
1482| buffer[6] buffer[7] buffer[8] |
1483##
1484
1485In the future, set9 followed by get9 may not return the same values. Since Matrix
1486maps non-homogeneous coordinates, scaling all nine values produces an equivalent
1487transformation, possibly improving precision.
1488
1489#Param buffer nine Scalar values ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001490
1491#Example
Cary Clark154beea2017-10-26 07:58:48 -04001492#Image 4
1493SkMatrix m;
1494SkScalar buffer[9] = {4, 0, 3, 0, 5, 4, 0, 0, 1};
1495m.set9(buffer);
1496canvas->concat(m);
1497canvas->drawBitmap(source, 0, 0);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001498##
1499
Cary Clarkbef063a2017-10-31 15:44:45 -04001500#SeeAlso setAll get9 MakeAll
Cary Clarkbc5697d2017-10-04 14:31:33 -04001501
Cary Clark154beea2017-10-26 07:58:48 -04001502#Method ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001503
1504# ------------------------------------------------------------------------------
1505
1506#Method void reset()
1507
Cary Clarkab2621d2018-01-30 10:08:57 -05001508#Line # Sets Matrix to identity. ##
Cary Clark154beea2017-10-26 07:58:48 -04001509Sets Matrix to identity; which has no effect on mapped Points. Sets Matrix to:
1510
1511#Code
1512#Literal
1513| 1 0 0 |
1514| 0 1 0 |
1515| 0 0 1 |
1516##
1517
1518Also called setIdentity(); use the one that provides better inline
1519documentation.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001520
1521#Example
Cary Clark154beea2017-10-26 07:58:48 -04001522SkMatrix m;
1523m.reset();
1524SkDebugf("m.isIdentity(): %s\n", m.isIdentity() ? "true" : "false");
1525#StdOut
1526m.isIdentity(): true
1527##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001528##
1529
Cary Clark154beea2017-10-26 07:58:48 -04001530#SeeAlso isIdentity setIdentity
Cary Clarkbc5697d2017-10-04 14:31:33 -04001531
Cary Clark154beea2017-10-26 07:58:48 -04001532#Method ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001533
1534# ------------------------------------------------------------------------------
1535
1536#Method void setIdentity()
1537
Cary Clarkab2621d2018-01-30 10:08:57 -05001538#Line # Sets Matrix to identity. ##
Cary Clark154beea2017-10-26 07:58:48 -04001539Sets Matrix to identity; which has no effect on mapped Points. Sets Matrix to:
1540
1541#Code
1542#Literal
1543| 1 0 0 |
1544| 0 1 0 |
1545| 0 0 1 |
1546##
1547
1548Also called reset(); use the one that provides better inline
1549documentation.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001550
1551#Example
Cary Clark154beea2017-10-26 07:58:48 -04001552SkMatrix m;
1553m.setIdentity();
1554SkDebugf("m.isIdentity(): %s\n", m.isIdentity() ? "true" : "false");
1555#StdOut
1556m.isIdentity(): true
1557##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001558##
1559
Cary Clark154beea2017-10-26 07:58:48 -04001560#SeeAlso isIdentity reset
Cary Clarkbc5697d2017-10-04 14:31:33 -04001561
Cary Clark154beea2017-10-26 07:58:48 -04001562#Method ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001563
1564# ------------------------------------------------------------------------------
1565
1566#Method void setTranslate(SkScalar dx, SkScalar dy)
1567
Cary Clarkab2621d2018-01-30 10:08:57 -05001568#Line # Sets to translate in x and y. ##
Cary Clark154beea2017-10-26 07:58:48 -04001569Sets Matrix to translate by (dx, dy).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001570
Cary Clark154beea2017-10-26 07:58:48 -04001571#Param dx horizontal translation ##
1572#Param dy vertical translation ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001573
1574#Example
Cary Clark154beea2017-10-26 07:58:48 -04001575#Height 64
1576SkPaint paint;
1577paint.setAntiAlias(true);
1578paint.setTextSize(24);
1579canvas->drawString("normal", 8, 24, paint);
1580SkMatrix matrix;
1581matrix.setTranslate(96, 24);
1582canvas->concat(matrix);
1583canvas->drawString("translate", 8, 24, paint);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001584##
1585
Cary Clark154beea2017-10-26 07:58:48 -04001586#SeeAlso setTranslateX setTranslateY
Cary Clarkbc5697d2017-10-04 14:31:33 -04001587
Cary Clark154beea2017-10-26 07:58:48 -04001588#Method ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001589
1590# ------------------------------------------------------------------------------
1591
1592#Method void setTranslate(const SkVector& v)
1593
Cary Clark154beea2017-10-26 07:58:48 -04001594Sets Matrix to translate by (v.fX, v.fY).
1595
1596#Param v Vector containing horizontal and vertical translation ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001597
1598#Example
Cary Clark154beea2017-10-26 07:58:48 -04001599#Height 64
1600SkPaint paint;
1601paint.setAntiAlias(true);
1602paint.setTextSize(24);
1603canvas->drawString("normal", 8, 24, paint);
1604SkMatrix matrix;
1605matrix.setTranslate({96, 24});
1606canvas->concat(matrix);
1607canvas->drawString("translate", 8, 24, paint);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001608##
1609
Cary Clark154beea2017-10-26 07:58:48 -04001610#SeeAlso setTranslateX setTranslateY MakeTrans
Cary Clarkbc5697d2017-10-04 14:31:33 -04001611
Cary Clark154beea2017-10-26 07:58:48 -04001612#Method ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001613
1614# ------------------------------------------------------------------------------
1615
1616#Method void setScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
1617
Cary Clarkab2621d2018-01-30 10:08:57 -05001618#Line # Sets to scale about a point. ##
Cary Clark154beea2017-10-26 07:58:48 -04001619Sets Matrix to scale by sx and sy, about a pivot point at (px, py).
1620The pivot point is unchanged when mapped with Matrix.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001621
Cary Clark154beea2017-10-26 07:58:48 -04001622#Param sx horizontal scale factor ##
1623#Param sy vertical scale factor ##
1624#Param px pivot x ##
1625#Param py pivot y ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001626
1627#Example
Cary Clark2ade9972017-11-02 17:49:34 -04001628#Height 128
Cary Clark154beea2017-10-26 07:58:48 -04001629 SkPaint p;
1630 p.setAntiAlias(true);
1631 p.setTextSize(64);
1632 SkMatrix m;
1633 for (SkScalar sx : { -1, 1 } ) {
1634 for (SkScalar sy : { -1, 1 } ) {
1635 SkAutoCanvasRestore autoRestore(canvas, true);
Cary Clark2ade9972017-11-02 17:49:34 -04001636 m.setScale(sx, sy, 128, 64);
Cary Clark154beea2017-10-26 07:58:48 -04001637 canvas->concat(m);
Cary Clark2ade9972017-11-02 17:49:34 -04001638 canvas->drawString("%", 128, 64, p);
Cary Clark154beea2017-10-26 07:58:48 -04001639 }
1640 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04001641##
1642
Cary Clark154beea2017-10-26 07:58:48 -04001643#SeeAlso setScaleX setScaleY MakeScale preScale postScale
Cary Clarkbc5697d2017-10-04 14:31:33 -04001644
Cary Clark154beea2017-10-26 07:58:48 -04001645#Method ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001646
1647# ------------------------------------------------------------------------------
1648
1649#Method void setScale(SkScalar sx, SkScalar sy)
1650
Cary Clark154beea2017-10-26 07:58:48 -04001651Sets Matrix to scale by sx and sy about at pivot point at (0, 0).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001652
Cary Clark154beea2017-10-26 07:58:48 -04001653#Param sx horizontal scale factor ##
1654#Param sy vertical scale factor ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001655
1656#Example
Cary Clark2ade9972017-11-02 17:49:34 -04001657#Height 128
Cary Clark154beea2017-10-26 07:58:48 -04001658 SkPaint p;
1659 p.setAntiAlias(true);
1660 p.setTextSize(64);
1661 SkMatrix m;
1662 for (SkScalar sx : { -1, 1 } ) {
1663 for (SkScalar sy : { -1, 1 } ) {
1664 SkAutoCanvasRestore autoRestore(canvas, true);
1665 m.setScale(sx, sy);
Cary Clark2ade9972017-11-02 17:49:34 -04001666 m.postTranslate(128, 64);
Cary Clark154beea2017-10-26 07:58:48 -04001667 canvas->concat(m);
Cary Clark2ade9972017-11-02 17:49:34 -04001668 canvas->drawString("@", 0, 0, p);
Cary Clark154beea2017-10-26 07:58:48 -04001669 }
1670 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04001671##
1672
Cary Clark154beea2017-10-26 07:58:48 -04001673#SeeAlso setScaleX setScaleY MakeScale preScale postScale
Cary Clarkbc5697d2017-10-04 14:31:33 -04001674
Cary Clark154beea2017-10-26 07:58:48 -04001675#Method ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001676
1677# ------------------------------------------------------------------------------
1678
1679#Method void setRotate(SkScalar degrees, SkScalar px, SkScalar py)
1680
Cary Clarkab2621d2018-01-30 10:08:57 -05001681#Line # Sets to rotate about a point. ##
Cary Clark154beea2017-10-26 07:58:48 -04001682Sets Matrix to rotate by degrees about a pivot point at (px, py).
1683The pivot point is unchanged when mapped with Matrix.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001684
Cary Clark154beea2017-10-26 07:58:48 -04001685Positive degrees rotates clockwise.
1686
1687#Param degrees angle of axes relative to upright axes ##
1688#Param px pivot x ##
1689#Param py pivot y ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001690
1691#Example
Cary Clark154beea2017-10-26 07:58:48 -04001692#Height 128
1693 SkPaint paint;
1694 paint.setColor(SK_ColorGRAY);
1695 paint.setAntiAlias(true);
1696 SkRect rect = {20, 20, 100, 100};
1697 canvas->drawRect(rect, paint);
1698 paint.setColor(SK_ColorRED);
1699 SkMatrix matrix;
1700 matrix.setRotate(25, rect.centerX(), rect.centerY());
1701 canvas->concat(matrix);
1702 canvas->drawRect(rect, paint);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001703##
1704
Cary Clark154beea2017-10-26 07:58:48 -04001705#SeeAlso setSinCos preRotate postRotate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001706
Cary Clark154beea2017-10-26 07:58:48 -04001707#Method ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001708
1709# ------------------------------------------------------------------------------
1710
1711#Method void setRotate(SkScalar degrees)
1712
Cary Clark154beea2017-10-26 07:58:48 -04001713Sets Matrix to rotate by degrees about a pivot point at (0, 0).
1714Positive degrees rotates clockwise.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001715
Cary Clark154beea2017-10-26 07:58:48 -04001716#Param degrees angle of axes relative to upright axes ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001717
1718#Example
Cary Clark154beea2017-10-26 07:58:48 -04001719#Height 128
1720 SkPaint paint;
1721 paint.setColor(SK_ColorGRAY);
1722 paint.setAntiAlias(true);
1723 SkRect rect = {20, 20, 100, 100};
1724 canvas->drawRect(rect, paint);
1725 paint.setColor(SK_ColorRED);
1726 SkMatrix matrix;
1727 matrix.setRotate(25);
1728 canvas->translate(rect.centerX(), rect.centerY());
1729 canvas->concat(matrix);
1730 canvas->translate(-rect.centerX(), -rect.centerY());
1731 canvas->drawRect(rect, paint);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001732##
1733
Cary Clark154beea2017-10-26 07:58:48 -04001734#SeeAlso setSinCos preRotate postRotate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001735
Cary Clark154beea2017-10-26 07:58:48 -04001736#Method ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001737
1738# ------------------------------------------------------------------------------
1739
1740#Method void setSinCos(SkScalar sinValue, SkScalar cosValue,
1741 SkScalar px, SkScalar py)
Cary Clarkab2621d2018-01-30 10:08:57 -05001742#Line # Sets to rotate and scale about a point. ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001743
Cary Clark154beea2017-10-26 07:58:48 -04001744Sets Matrix to rotate by sinValue and cosValue, about a pivot point at (px, py).
1745The pivot point is unchanged when mapped with Matrix.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001746
Cary Clark154beea2017-10-26 07:58:48 -04001747Vector (sinValue, cosValue) describes the angle of rotation relative to (0, 1).
1748Vector length specifies scale.
1749
1750#Param sinValue rotation vector x component ##
1751#Param cosValue rotation vector y component ##
1752#Param px pivot x ##
1753#Param py pivot y ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001754
1755#Example
Cary Clark154beea2017-10-26 07:58:48 -04001756#Height 128
1757 SkPaint paint;
1758 paint.setColor(SK_ColorGRAY);
1759 paint.setAntiAlias(true);
1760 SkRect rect = {20, 20, 100, 100};
1761 canvas->drawRect(rect, paint);
1762 paint.setColor(SK_ColorRED);
1763 SkMatrix matrix;
1764 matrix.setSinCos(.25f, .85f, rect.centerX(), rect.centerY());
1765 canvas->concat(matrix);
1766 canvas->drawRect(rect, paint);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001767##
1768
Cary Clark154beea2017-10-26 07:58:48 -04001769#SeeAlso setRotate setScale setRSXform
Cary Clarkbc5697d2017-10-04 14:31:33 -04001770
Cary Clark154beea2017-10-26 07:58:48 -04001771#Method ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001772
1773# ------------------------------------------------------------------------------
1774
1775#Method void setSinCos(SkScalar sinValue, SkScalar cosValue)
1776
Cary Clark154beea2017-10-26 07:58:48 -04001777Sets Matrix to rotate by sinValue and cosValue, about a pivot point at (0, 0).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001778
Cary Clark154beea2017-10-26 07:58:48 -04001779Vector (sinValue, cosValue) describes the angle of rotation relative to (0, 1).
1780Vector length specifies scale.
1781
1782#Param sinValue rotation vector x component ##
1783#Param cosValue rotation vector y component ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001784
1785#Example
Cary Clark154beea2017-10-26 07:58:48 -04001786#Description
1787Canvas needs offset after applying Matrix to pivot about Rect center.
1788##
1789#Height 128
1790 SkPaint paint;
1791 paint.setColor(SK_ColorGRAY);
1792 paint.setAntiAlias(true);
1793 SkRect rect = {20, 20, 100, 100};
1794 canvas->drawRect(rect, paint);
1795 paint.setColor(SK_ColorRED);
1796 SkMatrix matrix;
1797 matrix.setSinCos(.25f, .85f);
1798 matrix.postTranslate(rect.centerX(), rect.centerY());
1799 canvas->concat(matrix);
1800 canvas->translate(-rect.centerX(), -rect.centerY());
1801 canvas->drawRect(rect, paint);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001802##
1803
Cary Clark154beea2017-10-26 07:58:48 -04001804#SeeAlso setRotate setScale setRSXform
Cary Clarkbc5697d2017-10-04 14:31:33 -04001805
Cary Clark154beea2017-10-26 07:58:48 -04001806#Method ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001807
1808# ------------------------------------------------------------------------------
1809
1810#Method SkMatrix& setRSXform(const SkRSXform& rsxForm)
1811
Cary Clarkab2621d2018-01-30 10:08:57 -05001812#Line # Sets to rotate, scale, and translate. ##
Cary Clark154beea2017-10-26 07:58:48 -04001813Sets Matrix to rotate, scale, and translate using a compressed matrix form.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001814
Cary Clark154beea2017-10-26 07:58:48 -04001815Vector (rsxForm.fSSin, rsxForm.fSCos) describes the angle of rotation relative
1816to (0, 1). Vector length specifies scale. Mapped point is rotated and scaled
1817by Vector, then translated by (rsxForm.fTx, rsxForm.fTy).
1818
1819#Param rsxForm compressed RSXform matrix ##
1820
1821#Return reference to Matrix ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001822
1823#Example
Cary Clark154beea2017-10-26 07:58:48 -04001824#Description
1825Canvas needs offset after applying Matrix to pivot about Rect center.
1826##
1827#Height 128
1828 SkPaint paint;
1829 paint.setColor(SK_ColorGRAY);
1830 paint.setAntiAlias(true);
1831 SkRect rect = {20, 20, 100, 100};
1832 canvas->drawRect(rect, paint);
1833 paint.setColor(SK_ColorRED);
1834 SkMatrix matrix;
1835 matrix.setRSXform(SkRSXform::Make(.85f, .25f, rect.centerX(), rect.centerY()));
1836 canvas->concat(matrix);
1837 canvas->translate(-rect.centerX(), -rect.centerY());
1838 canvas->drawRect(rect, paint);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001839##
1840
Cary Clark154beea2017-10-26 07:58:48 -04001841#SeeAlso setSinCos setScale setTranslate
Cary Clarkbc5697d2017-10-04 14:31:33 -04001842
Cary Clark154beea2017-10-26 07:58:48 -04001843#Method ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001844
1845# ------------------------------------------------------------------------------
1846
1847#Method void setSkew(SkScalar kx, SkScalar ky, SkScalar px, SkScalar py)
1848
Cary Clarkab2621d2018-01-30 10:08:57 -05001849#Line # Sets to skew about a point. ##
Cary Clark154beea2017-10-26 07:58:48 -04001850Sets Matrix to skew by kx and ky, about a pivot point at (px, py).
1851The pivot point is unchanged when mapped with Matrix.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001852
Cary Clark154beea2017-10-26 07:58:48 -04001853#Param kx horizontal skew factor ##
1854#Param ky vertical skew factor ##
1855#Param px pivot x ##
1856#Param py pivot y ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001857
1858#Example
Cary Clark154beea2017-10-26 07:58:48 -04001859 SkPaint p;
1860 p.setAntiAlias(true);
1861 p.setTextSize(48);
1862 SkMatrix m;
1863 for (SkScalar sx : { -1, 0, 1 } ) {
1864 for (SkScalar sy : { -1, 0, 1 } ) {
1865 SkAutoCanvasRestore autoRestore(canvas, true);
1866 m.setSkew(sx, sy, 96 + 64 * sx, 128 + 48 * sy);
1867 canvas->concat(m);
1868 canvas->drawString("K", 96 + 64 * sx, 128 + 48 * sy, p);
1869 }
1870 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04001871##
1872
Cary Clark154beea2017-10-26 07:58:48 -04001873#SeeAlso setSkewX setSkewY preSkew postSkew
Cary Clarkbc5697d2017-10-04 14:31:33 -04001874
Cary Clark154beea2017-10-26 07:58:48 -04001875#Method ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001876
1877# ------------------------------------------------------------------------------
1878
1879#Method void setSkew(SkScalar kx, SkScalar ky)
1880
Cary Clark154beea2017-10-26 07:58:48 -04001881Sets Matrix to skew by kx and ky, about a pivot point at (0, 0).
Cary Clarkbc5697d2017-10-04 14:31:33 -04001882
Cary Clark154beea2017-10-26 07:58:48 -04001883#Param kx horizontal skew factor ##
1884#Param ky vertical skew factor ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001885
1886#Example
Cary Clark154beea2017-10-26 07:58:48 -04001887 SkPaint p;
1888 p.setAntiAlias(true);
1889 p.setTextSize(48);
1890 SkMatrix m;
1891 for (SkScalar sx : { -1, 0, 1 } ) {
1892 for (SkScalar sy : { -1, 0, 1 } ) {
1893 SkAutoCanvasRestore autoRestore(canvas, true);
1894 m.setSkew(sx, sy);
1895 m.postTranslate(96 + 64 * sx, 128 + 48 * sy);
1896 canvas->concat(m);
1897 canvas->drawString("K", 0, 0, p);
1898 }
1899 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04001900##
1901
Cary Clark154beea2017-10-26 07:58:48 -04001902#SeeAlso setSkewX setSkewY preSkew postSkew
Cary Clarkbc5697d2017-10-04 14:31:33 -04001903
Cary Clark154beea2017-10-26 07:58:48 -04001904#Method ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001905
1906# ------------------------------------------------------------------------------
1907
1908#Method void setConcat(const SkMatrix& a, const SkMatrix& b)
1909
Cary Clarkab2621d2018-01-30 10:08:57 -05001910#Line # Sets to Matrix parameter multiplied by Matrix parameter. ##
Cary Clark154beea2017-10-26 07:58:48 -04001911Sets Matrix to Matrix a multiplied by Matrix b. Either a or b may be this.
Cary Clarkbc5697d2017-10-04 14:31:33 -04001912
Cary Clark154beea2017-10-26 07:58:48 -04001913Given:
1914
1915#Code
1916#Literal
1917 | A B C | | J K L |
1918a = | D E F |, b = | M N O |
1919 | G H I | | P Q R |
1920##
1921
1922sets Matrix to:
1923
1924#Code
1925#Literal
1926 | A B C | | J K L | | AJ+BM+CP AK+BN+CQ AL+BO+CR |
1927a * b = | D E F | * | M N O | = | DJ+EM+FP DK+EN+FQ DL+EO+FR |
1928 | G H I | | P Q R | | GJ+HM+IP GK+HN+IQ GL+HO+IR |
1929##
1930
1931#Param a Matrix on left side of multiply expression ##
1932#Param b Matrix on right side of multiply expression ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001933
1934#Example
Cary Clark154beea2017-10-26 07:58:48 -04001935#Image 3
1936#Description
1937setPolyToPoly creates perspective matrices, one the inverse of the other.
1938Multiplying the matrix by its inverse turns into an identity matrix.
1939##
1940SkMatrix matrix, matrix2;
1941SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}};
1942SkRect::Make(source.bounds()).toQuad(bitmapBounds);
1943matrix.setPolyToPoly(bitmapBounds, perspect, 4);
1944matrix2.setPolyToPoly(perspect, bitmapBounds, 4);
1945matrix.setConcat(matrix, matrix2);
1946canvas->concat(matrix);
1947canvas->drawBitmap(source, 0, 0);
Cary Clarkbc5697d2017-10-04 14:31:33 -04001948##
1949
Cary Clark154beea2017-10-26 07:58:48 -04001950#SeeAlso Concat preConcat postConcat SkCanvas::concat
Cary Clarkbc5697d2017-10-04 14:31:33 -04001951
Cary Clark154beea2017-10-26 07:58:48 -04001952#Method ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001953
1954# ------------------------------------------------------------------------------
1955
1956#Method void preTranslate(SkScalar dx, SkScalar dy)
1957
Cary Clarkab2621d2018-01-30 10:08:57 -05001958#Line # Pre-multiplies Matrix by translation. ##
Cary Clark154beea2017-10-26 07:58:48 -04001959Sets Matrix to Matrix multiplied by Matrix constructed from translation (dx, dy).
1960This can be thought of as moving the point to be mapped before applying Matrix.
1961
1962Given:
1963
1964#Code
1965#Literal
1966 | A B C | | 1 0 dx |
1967Matrix = | D E F |, T(dx, dy) = | 0 1 dy |
1968 | G H I | | 0 0 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -04001969##
1970
Cary Clark154beea2017-10-26 07:58:48 -04001971sets Matrix to:
1972
1973#Code
1974#Literal
1975 | A B C | | 1 0 dx | | A B A*dx+B*dy+C |
1976Matrix * T(dx, dy) = | D E F | | 0 1 dy | = | D E D*dx+E*dy+F |
1977 | G H I | | 0 0 1 | | G H G*dx+H*dy+I |
1978##
1979
1980#Param dx x translation before applying Matrix ##
1981#Param dy y translation before applying Matrix ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04001982
1983#Example
Cary Clark154beea2017-10-26 07:58:48 -04001984#Height 160
1985 SkPaint paint;
1986 paint.setAntiAlias(true);
1987 SkRect rect = {20, 20, 100, 100};
1988 for (int i = 0; i < 2; ++i ) {
1989 SkMatrix matrix;
1990 i == 0 ? matrix.reset(): matrix.setRotate(25, rect.centerX(), 320);
1991 {
1992 SkAutoCanvasRestore acr(canvas, true);
1993 canvas->concat(matrix);
1994 paint.setColor(SK_ColorGRAY);
1995 canvas->drawRect(rect, paint);
1996 }
1997 paint.setColor(SK_ColorRED);
1998 for (int j = 0; j < 2; ++j ) {
1999 SkAutoCanvasRestore acr(canvas, true);
2000 matrix.preTranslate(40, 40);
2001 canvas->concat(matrix);
2002 canvas->drawCircle(0, 0, 3, paint);
2003 }
2004 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04002005##
2006
Cary Clark154beea2017-10-26 07:58:48 -04002007#SeeAlso postTranslate setTranslate MakeTrans
Cary Clarkbc5697d2017-10-04 14:31:33 -04002008
Cary Clark154beea2017-10-26 07:58:48 -04002009#Method ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002010
2011# ------------------------------------------------------------------------------
2012
2013#Method void preScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
2014
Cary Clarkab2621d2018-01-30 10:08:57 -05002015#Line # Pre-multiplies Matrix by scale. ##
Cary Clark154beea2017-10-26 07:58:48 -04002016Sets Matrix to Matrix multiplied by Matrix constructed from scaling by (sx, sy)
2017about pivot point (px, py).
2018This can be thought of as scaling about a pivot point before applying Matrix.
2019
2020Given:
2021
2022#Code
2023#Literal
2024 | A B C | | sx 0 dx |
2025Matrix = | D E F |, S(sx, sy, px, py) = | 0 sy dy |
2026 | G H I | | 0 0 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -04002027##
2028
Cary Clark154beea2017-10-26 07:58:48 -04002029where
2030
2031#Code
2032#Literal
2033dx = px - sx * px
2034dy = py - sy * py
2035##
2036
2037sets Matrix to:
2038
2039#Code
2040#Literal
2041 | A B C | | sx 0 dx | | A*sx B*sy A*dx+B*dy+C |
2042Matrix * S(sx, sy, px, py) = | D E F | | 0 sy dy | = | D*sx E*sy D*dx+E*dy+F |
2043 | G H I | | 0 0 1 | | G*sx H*sy G*dx+H*dy+I |
2044##
2045
2046#Param sx horizontal scale factor ##
2047#Param sy vertical scale factor ##
2048#Param px pivot x ##
2049#Param py pivot y ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002050
2051#Example
Cary Clark154beea2017-10-26 07:58:48 -04002052#Image 3
2053SkMatrix matrix;
2054SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}};
2055SkRect::Make(source.bounds()).toQuad(bitmapBounds);
2056matrix.setPolyToPoly(bitmapBounds, perspect, 4);
2057matrix.preScale(.75f, 1.5f, source.width() / 2, source.height() / 2);
2058canvas->concat(matrix);
2059canvas->drawBitmap(source, 0, 0);
Cary Clarkbc5697d2017-10-04 14:31:33 -04002060##
2061
Cary Clark154beea2017-10-26 07:58:48 -04002062#SeeAlso postScale setScale MakeScale
Cary Clarkbc5697d2017-10-04 14:31:33 -04002063
Cary Clark154beea2017-10-26 07:58:48 -04002064#Method ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002065
2066# ------------------------------------------------------------------------------
2067
2068#Method void preScale(SkScalar sx, SkScalar sy)
2069
Cary Clark154beea2017-10-26 07:58:48 -04002070Sets Matrix to Matrix multiplied by Matrix constructed from scaling by (sx, sy)
2071about pivot point (0, 0).
2072This can be thought of as scaling about the origin before applying Matrix.
2073
2074Given:
2075
2076#Code
2077#Literal
2078 | A B C | | sx 0 0 |
2079Matrix = | D E F |, S(sx, sy) = | 0 sy 0 |
2080 | G H I | | 0 0 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -04002081##
2082
Cary Clark154beea2017-10-26 07:58:48 -04002083sets Matrix to:
2084
2085#Code
2086#Literal
2087 | A B C | | sx 0 0 | | A*sx B*sy C |
2088Matrix * S(sx, sy) = | D E F | | 0 sy 0 | = | D*sx E*sy F |
2089 | G H I | | 0 0 1 | | G*sx H*sy I |
2090##
2091
2092#Param sx horizontal scale factor ##
2093#Param sy vertical scale factor ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002094
2095#Example
Cary Clark154beea2017-10-26 07:58:48 -04002096#Image 3
2097SkMatrix matrix;
2098SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}};
2099SkRect::Make(source.bounds()).toQuad(bitmapBounds);
2100matrix.setPolyToPoly(bitmapBounds, perspect, 4);
2101matrix.preScale(.75f, 1.5f);
2102canvas->concat(matrix);
2103canvas->drawBitmap(source, 0, 0);
Cary Clarkbc5697d2017-10-04 14:31:33 -04002104##
2105
Cary Clark154beea2017-10-26 07:58:48 -04002106#SeeAlso postScale setScale MakeScale
Cary Clarkbc5697d2017-10-04 14:31:33 -04002107
Cary Clark154beea2017-10-26 07:58:48 -04002108#Method ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002109
2110# ------------------------------------------------------------------------------
2111
2112#Method void preRotate(SkScalar degrees, SkScalar px, SkScalar py)
2113
Cary Clarkab2621d2018-01-30 10:08:57 -05002114#Line # Pre-multiplies Matrix by rotation. ##
Cary Clark154beea2017-10-26 07:58:48 -04002115Sets Matrix to Matrix multiplied by Matrix constructed from rotating by degrees
2116about pivot point (px, py).
2117This can be thought of as rotating about a pivot point before applying Matrix.
2118
2119Positive degrees rotates clockwise.
2120
2121Given:
2122
2123#Code
2124#Literal
2125 | A B C | | c -s dx |
2126Matrix = | D E F |, R(degrees, px, py) = | s c dy |
2127 | G H I | | 0 0 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -04002128##
2129
Cary Clark154beea2017-10-26 07:58:48 -04002130where
2131
2132#Code
2133#Literal
2134c = cos(degrees)
2135s = sin(degrees)
2136dx = s * py + (1 - c) * px
2137dy = -s * px + (1 - c) * py
2138##
2139
2140sets Matrix to:
2141
2142#Code
2143#Literal
2144 | A B C | | c -s dx | | Ac+Bs -As+Bc A*dx+B*dy+C |
2145Matrix * R(degrees, px, py) = | D E F | | s c dy | = | Dc+Es -Ds+Ec D*dx+E*dy+F |
2146 | G H I | | 0 0 1 | | Gc+Hs -Gs+Hc G*dx+H*dy+I |
2147##
2148
2149#Param degrees angle of axes relative to upright axes ##
2150#Param px pivot x ##
2151#Param py pivot y ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002152
2153#Example
Cary Clark154beea2017-10-26 07:58:48 -04002154#Image 3
2155SkMatrix matrix;
2156SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}};
2157SkRect::Make(source.bounds()).toQuad(bitmapBounds);
2158matrix.setPolyToPoly(bitmapBounds, perspect, 4);
2159matrix.preRotate(45, source.width() / 2, source.height() / 2);
2160canvas->concat(matrix);
2161canvas->drawBitmap(source, 0, 0);
Cary Clarkbc5697d2017-10-04 14:31:33 -04002162##
2163
Cary Clark154beea2017-10-26 07:58:48 -04002164#SeeAlso postRotate setRotate
Cary Clarkbc5697d2017-10-04 14:31:33 -04002165
Cary Clark154beea2017-10-26 07:58:48 -04002166#Method ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002167
2168# ------------------------------------------------------------------------------
2169
2170#Method void preRotate(SkScalar degrees)
2171
Cary Clark154beea2017-10-26 07:58:48 -04002172Sets Matrix to Matrix multiplied by Matrix constructed from rotating by degrees
2173about pivot point (0, 0).
2174This can be thought of as rotating about the origin before applying Matrix.
2175
2176Positive degrees rotates clockwise.
2177
2178Given:
2179
2180#Code
2181#Literal
2182 | A B C | | c -s 0 |
2183Matrix = | D E F |, R(degrees, px, py) = | s c 0 |
2184 | G H I | | 0 0 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -04002185##
2186
Cary Clark154beea2017-10-26 07:58:48 -04002187where
2188
2189#Code
2190#Literal
2191c = cos(degrees)
2192s = sin(degrees)
2193##
2194
2195sets Matrix to:
2196
2197#Code
2198#Literal
2199 | A B C | | c -s 0 | | Ac+Bs -As+Bc C |
2200Matrix * R(degrees, px, py) = | D E F | | s c 0 | = | Dc+Es -Ds+Ec F |
2201 | G H I | | 0 0 1 | | Gc+Hs -Gs+Hc I |
2202##
2203
2204#Param degrees angle of axes relative to upright axes ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002205
2206#Example
Cary Clark154beea2017-10-26 07:58:48 -04002207#Image 3
2208SkMatrix matrix;
2209SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}};
2210SkRect::Make(source.bounds()).toQuad(bitmapBounds);
2211matrix.setPolyToPoly(bitmapBounds, perspect, 4);
2212matrix.preRotate(45);
2213canvas->concat(matrix);
2214canvas->drawBitmap(source, 0, 0);
Cary Clarkbc5697d2017-10-04 14:31:33 -04002215##
2216
Cary Clark154beea2017-10-26 07:58:48 -04002217#SeeAlso postRotate setRotate
Cary Clarkbc5697d2017-10-04 14:31:33 -04002218
Cary Clark154beea2017-10-26 07:58:48 -04002219#Method ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002220
2221# ------------------------------------------------------------------------------
2222
2223#Method void preSkew(SkScalar kx, SkScalar ky, SkScalar px, SkScalar py)
2224
Cary Clarkab2621d2018-01-30 10:08:57 -05002225#Line # Pre-multiplies Matrix by skew. ##
Cary Clark154beea2017-10-26 07:58:48 -04002226Sets Matrix to Matrix multiplied by Matrix constructed from skewing by (kx, ky)
2227about pivot point (px, py).
2228This can be thought of as skewing about a pivot point before applying Matrix.
2229
2230Given:
2231
2232#Code
2233#Literal
2234 | A B C | | 1 kx dx |
2235Matrix = | D E F |, K(kx, ky, px, py) = | ky 1 dy |
2236 | G H I | | 0 0 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -04002237##
2238
Cary Clark154beea2017-10-26 07:58:48 -04002239where
2240
2241#Code
2242#Literal
2243dx = -kx * py
2244dy = -ky * px
2245##
2246
2247sets Matrix to:
2248
2249#Code
2250#Literal
2251 | A B C | | 1 kx dx | | A+B*ky A*kx+B A*dx+B*dy+C |
2252Matrix * K(kx, ky, px, py) = | D E F | | ky 1 dy | = | D+E*ky D*kx+E D*dx+E*dy+F |
2253 | G H I | | 0 0 1 | | G+H*ky G*kx+H G*dx+H*dy+I |
2254##
2255
2256#Param kx horizontal skew factor ##
2257#Param ky vertical skew factor ##
2258#Param px pivot x ##
2259#Param py pivot y ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002260
2261#Example
Cary Clark154beea2017-10-26 07:58:48 -04002262#Image 3
2263SkMatrix matrix;
2264SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}};
2265SkRect::Make(source.bounds()).toQuad(bitmapBounds);
2266matrix.setPolyToPoly(bitmapBounds, perspect, 4);
2267matrix.preSkew(.5f, 0, source.width() / 2, source.height() / 2);
2268canvas->concat(matrix);
2269canvas->drawBitmap(source, 0, 0);
Cary Clarkbc5697d2017-10-04 14:31:33 -04002270##
2271
Cary Clark154beea2017-10-26 07:58:48 -04002272#SeeAlso postSkew setSkew
Cary Clarkbc5697d2017-10-04 14:31:33 -04002273
Cary Clark154beea2017-10-26 07:58:48 -04002274#Method ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002275
2276# ------------------------------------------------------------------------------
2277
2278#Method void preSkew(SkScalar kx, SkScalar ky)
2279
Cary Clark154beea2017-10-26 07:58:48 -04002280Sets Matrix to Matrix multiplied by Matrix constructed from skewing by (kx, ky)
2281about pivot point (0, 0).
2282This can be thought of as skewing about the origin before applying Matrix.
2283
2284Given:
2285
2286#Code
2287#Literal
2288 | A B C | | 1 kx 0 |
2289Matrix = | D E F |, K(kx, ky) = | ky 1 0 |
2290 | G H I | | 0 0 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -04002291##
2292
Cary Clark154beea2017-10-26 07:58:48 -04002293sets Matrix to:
2294
2295#Code
2296#Literal
2297 | A B C | | 1 kx 0 | | A+B*ky A*kx+B C |
2298Matrix * K(kx, ky) = | D E F | | ky 1 0 | = | D+E*ky D*kx+E F |
2299 | G H I | | 0 0 1 | | G+H*ky G*kx+H I |
2300##
2301
2302#Param kx horizontal skew factor ##
2303#Param ky vertical skew factor ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002304
2305#Example
Cary Clark154beea2017-10-26 07:58:48 -04002306#Image 3
2307SkMatrix matrix;
2308SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}};
2309SkRect::Make(source.bounds()).toQuad(bitmapBounds);
2310matrix.setPolyToPoly(bitmapBounds, perspect, 4);
2311matrix.preSkew(.5f, 0);
2312canvas->concat(matrix);
2313canvas->drawBitmap(source, 0, 0);
Cary Clarkbc5697d2017-10-04 14:31:33 -04002314##
2315
Cary Clark154beea2017-10-26 07:58:48 -04002316#SeeAlso postSkew setSkew
Cary Clarkbc5697d2017-10-04 14:31:33 -04002317
Cary Clark154beea2017-10-26 07:58:48 -04002318#Method ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002319
2320# ------------------------------------------------------------------------------
2321
2322#Method void preConcat(const SkMatrix& other)
2323
Cary Clarkab2621d2018-01-30 10:08:57 -05002324#Line # Pre-multiplies Matrix by Matrix parameter. ##
Cary Clark154beea2017-10-26 07:58:48 -04002325Sets Matrix to Matrix multiplied by Matrix other.
2326This can be thought of mapping by other before applying Matrix.
2327
2328Given:
2329
2330#Code
2331#Literal
2332 | A B C | | J K L |
2333Matrix = | D E F |, other = | M N O |
2334 | G H I | | P Q R |
Cary Clarkbc5697d2017-10-04 14:31:33 -04002335##
2336
Cary Clark154beea2017-10-26 07:58:48 -04002337sets Matrix to:
2338
2339#Code
2340#Literal
2341 | A B C | | J K L | | AJ+BM+CP AK+BN+CQ AL+BO+CR |
2342Matrix * other = | D E F | * | M N O | = | DJ+EM+FP DK+EN+FQ DL+EO+FR |
2343 | G H I | | P Q R | | GJ+HM+IP GK+HN+IQ GL+HO+IR |
2344##
2345
2346#Param other Matrix on right side of multiply expression ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002347
2348#Example
Cary Clark154beea2017-10-26 07:58:48 -04002349#Image 3
2350#Description
2351setPolyToPoly creates perspective matrices, one the inverse of the other.
2352Multiplying the matrix by its inverse turns into an identity matrix.
2353##
2354SkMatrix matrix, matrix2;
2355SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}};
2356SkRect::Make(source.bounds()).toQuad(bitmapBounds);
2357matrix.setPolyToPoly(bitmapBounds, perspect, 4);
2358matrix2.setPolyToPoly(perspect, bitmapBounds, 4);
2359matrix.preConcat(matrix2);
2360canvas->concat(matrix);
2361canvas->drawBitmap(source, 0, 0);
Cary Clarkbc5697d2017-10-04 14:31:33 -04002362##
2363
Cary Clark154beea2017-10-26 07:58:48 -04002364#SeeAlso postConcat setConcat Concat
Cary Clarkbc5697d2017-10-04 14:31:33 -04002365
Cary Clark154beea2017-10-26 07:58:48 -04002366#Method ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002367
2368# ------------------------------------------------------------------------------
2369
2370#Method void postTranslate(SkScalar dx, SkScalar dy)
2371
Cary Clarkab2621d2018-01-30 10:08:57 -05002372#Line # Post-multiplies Matrix by translation. ##
Cary Clark154beea2017-10-26 07:58:48 -04002373Sets Matrix to Matrix constructed from translation (dx, dy) multiplied by Matrix.
2374This can be thought of as moving the point to be mapped after applying Matrix.
2375
2376Given:
2377
2378#Code
2379#Literal
2380 | J K L | | 1 0 dx |
2381Matrix = | M N O |, T(dx, dy) = | 0 1 dy |
2382 | P Q R | | 0 0 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -04002383##
2384
Cary Clark154beea2017-10-26 07:58:48 -04002385sets Matrix to:
2386
2387#Code
2388#Literal
2389 | 1 0 dx | | J K L | | J+dx*P K+dx*Q L+dx*R |
2390T(dx, dy) * Matrix = | 0 1 dy | | M N O | = | M+dy*P N+dy*Q O+dy*R |
2391 | 0 0 1 | | P Q R | | P Q R |
2392##
2393
2394#Param dx x translation after applying Matrix ##
2395#Param dy y translation after applying Matrix ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002396
2397#Example
Cary Clark154beea2017-10-26 07:58:48 -04002398#Height 160
2399#Description
2400Compare with preTranslate example.
2401##
2402 SkPaint paint;
2403 paint.setAntiAlias(true);
2404 SkRect rect = {20, 20, 100, 100};
2405 for (int i = 0; i < 2; ++i ) {
2406 SkMatrix matrix;
2407 i == 0 ? matrix.reset(): matrix.setRotate(25, rect.centerX(), 320);
2408 {
2409 SkAutoCanvasRestore acr(canvas, true);
2410 canvas->concat(matrix);
2411 paint.setColor(SK_ColorGRAY);
2412 canvas->drawRect(rect, paint);
2413 }
2414 paint.setColor(SK_ColorRED);
2415 for (int j = 0; j < 2; ++j ) {
2416 SkAutoCanvasRestore acr(canvas, true);
2417 matrix.postTranslate(40, 40);
2418 canvas->concat(matrix);
2419 canvas->drawCircle(0, 0, 3, paint);
2420 }
2421 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04002422##
2423
Cary Clark154beea2017-10-26 07:58:48 -04002424#SeeAlso preTranslate setTranslate MakeTrans
Cary Clarkbc5697d2017-10-04 14:31:33 -04002425
Cary Clark154beea2017-10-26 07:58:48 -04002426#Method ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002427
2428# ------------------------------------------------------------------------------
2429
2430#Method void postScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
2431
Cary Clarkab2621d2018-01-30 10:08:57 -05002432#Line # Post-multiplies Matrix by scale. ##
Cary Clark154beea2017-10-26 07:58:48 -04002433Sets Matrix to Matrix constructed from scaling by (sx, sy) about pivot point
2434(px, py), multiplied by Matrix.
2435This can be thought of as scaling about a pivot point after applying Matrix.
2436
2437Given:
2438
2439#Code
2440#Literal
2441 | J K L | | sx 0 dx |
2442Matrix = | M N O |, S(sx, sy, px, py) = | 0 sy dy |
2443 | P Q R | | 0 0 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -04002444##
2445
Cary Clark154beea2017-10-26 07:58:48 -04002446where
2447
2448#Code
2449#Literal
2450dx = px - sx * px
2451dy = py - sy * py
2452##
2453
2454sets Matrix to:
2455
2456#Code
2457#Literal
2458 | sx 0 dx | | J K L | | sx*J+dx*P sx*K+dx*Q sx*L+dx+R |
2459S(sx, sy, px, py) * Matrix = | 0 sy dy | | M N O | = | sy*M+dy*P sy*N+dy*Q sy*O+dy*R |
2460 | 0 0 1 | | P Q R | | P Q R |
2461##
2462
2463#Param sx horizontal scale factor ##
2464#Param sy vertical scale factor ##
2465#Param px pivot x ##
2466#Param py pivot y ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002467
2468#Example
Cary Clark154beea2017-10-26 07:58:48 -04002469#Image 3
2470SkMatrix matrix;
2471SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}};
2472SkRect::Make(source.bounds()).toQuad(bitmapBounds);
2473matrix.setPolyToPoly(bitmapBounds, perspect, 4);
2474matrix.postScale(.75f, 1.5f, source.width() / 2, source.height() / 2);
2475canvas->concat(matrix);
2476canvas->drawBitmap(source, 0, 0);
Cary Clarkbc5697d2017-10-04 14:31:33 -04002477##
2478
Cary Clark154beea2017-10-26 07:58:48 -04002479#SeeAlso preScale setScale MakeScale
Cary Clarkbc5697d2017-10-04 14:31:33 -04002480
2481##
2482
2483# ------------------------------------------------------------------------------
2484
2485#Method void postScale(SkScalar sx, SkScalar sy)
2486
Cary Clark154beea2017-10-26 07:58:48 -04002487Sets Matrix to Matrix constructed from scaling by (sx, sy) about pivot point
2488(0, 0), multiplied by Matrix.
2489This can be thought of as scaling about the origin after applying Matrix.
2490
2491Given:
2492
2493#Code
2494#Literal
2495 | J K L | | sx 0 0 |
2496Matrix = | M N O |, S(sx, sy) = | 0 sy 0 |
2497 | P Q R | | 0 0 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -04002498##
2499
Cary Clark154beea2017-10-26 07:58:48 -04002500sets Matrix to:
2501
2502#Code
2503#Literal
2504 | sx 0 0 | | J K L | | sx*J sx*K sx*L |
2505S(sx, sy) * Matrix = | 0 sy 0 | | M N O | = | sy*M sy*N sy*O |
2506 | 0 0 1 | | P Q R | | P Q R |
2507##
2508
2509#Param sx horizontal scale factor ##
2510#Param sy vertical scale factor ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002511
2512#Example
Cary Clark154beea2017-10-26 07:58:48 -04002513#Image 3
2514SkMatrix matrix;
2515SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}};
2516SkRect::Make(source.bounds()).toQuad(bitmapBounds);
2517matrix.setPolyToPoly(bitmapBounds, perspect, 4);
2518matrix.postScale(.75f, 1.5f);
2519canvas->concat(matrix);
2520canvas->drawBitmap(source, 0, 0);
Cary Clarkbc5697d2017-10-04 14:31:33 -04002521##
2522
Cary Clark154beea2017-10-26 07:58:48 -04002523#SeeAlso preScale setScale MakeScale
Cary Clarkbc5697d2017-10-04 14:31:33 -04002524
2525##
2526
2527# ------------------------------------------------------------------------------
2528
2529#Method bool postIDiv(int divx, int divy)
2530
Cary Clarkab2621d2018-01-30 10:08:57 -05002531#Line # Post-multiplies Matrix by inverse scale. ##
Cary Clark154beea2017-10-26 07:58:48 -04002532Sets Matrix to Matrix constructed from scaling by
Cary Clarkbc5697d2017-10-04 14:31:33 -04002533#Formula
Cary Clark154beea2017-10-26 07:58:48 -04002534(1/divx, 1/divy)
2535##
2536about pivot point (px, py), multiplied by Matrix.
2537
2538Returns false if either divx or divy is zero.
2539
2540Given:
2541
2542#Code
2543#Literal
2544 | J K L | | sx 0 0 |
2545Matrix = | M N O |, I(divx, divy) = | 0 sy 0 |
2546 | P Q R | | 0 0 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -04002547##
2548
Cary Clark154beea2017-10-26 07:58:48 -04002549where
Cary Clarkbc5697d2017-10-04 14:31:33 -04002550
Cary Clark154beea2017-10-26 07:58:48 -04002551#Code
2552#Literal
2553sx = 1 / divx
2554sy = 1 / divy
2555##
2556
2557sets Matrix to:
2558
2559#Code
2560#Literal
2561 | sx 0 0 | | J K L | | sx*J sx*K sx*L |
2562I(divx, divy) * Matrix = | 0 sy 0 | | M N O | = | sy*M sy*N sy*O |
2563 | 0 0 1 | | P Q R | | P Q R |
2564##
2565
2566#Param divx integer divisor for inverse scale in x ##
2567#Param divy integer divisor for inverse scale in y ##
2568
2569#Return true on successful scale ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002570
2571#Example
Cary Clark154beea2017-10-26 07:58:48 -04002572#Image 3
2573SkMatrix matrix, matrix2;
2574SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}};
2575SkRect::Make(source.bounds()).toQuad(bitmapBounds);
2576matrix.setPolyToPoly(bitmapBounds, perspect, 4);
2577matrix.postIDiv(1, 2);
2578canvas->concat(matrix);
2579canvas->drawBitmap(source, 0, 0);
Cary Clarkbc5697d2017-10-04 14:31:33 -04002580##
2581
Cary Clark154beea2017-10-26 07:58:48 -04002582#SeeAlso postScale MakeScale
Cary Clarkbc5697d2017-10-04 14:31:33 -04002583
2584##
2585
2586# ------------------------------------------------------------------------------
2587
2588#Method void postRotate(SkScalar degrees, SkScalar px, SkScalar py)
2589
Cary Clarkab2621d2018-01-30 10:08:57 -05002590#Line # Post-multiplies Matrix by rotation. ##
Cary Clark154beea2017-10-26 07:58:48 -04002591Sets Matrix to Matrix constructed from rotating by degrees about pivot point
2592(px, py), multiplied by Matrix.
2593This can be thought of as rotating about a pivot point after applying Matrix.
2594
2595Positive degrees rotates clockwise.
2596
2597Given:
2598
2599#Code
2600#Literal
2601 | J K L | | c -s dx |
2602Matrix = | M N O |, R(degrees, px, py) = | s c dy |
2603 | P Q R | | 0 0 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -04002604##
2605
Cary Clark154beea2017-10-26 07:58:48 -04002606where
2607
2608#Code
2609#Literal
2610c = cos(degrees)
2611s = sin(degrees)
2612dx = s * py + (1 - c) * px
2613dy = -s * px + (1 - c) * py
2614##
2615
2616sets Matrix to:
2617
2618#Code
2619#Literal
2620 |c -s dx| |J K L| |cJ-sM+dx*P cK-sN+dx*Q cL-sO+dx+R|
2621R(degrees, px, py) * Matrix = |s c dy| |M N O| = |sJ+cM+dy*P sK+cN+dy*Q sL+cO+dy*R|
2622 |0 0 1| |P Q R| | P Q R|
2623##
2624
2625#Param degrees angle of axes relative to upright axes ##
2626#Param px pivot x ##
2627#Param py pivot y ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002628
2629#Example
Cary Clark154beea2017-10-26 07:58:48 -04002630#Image 3
2631SkMatrix matrix;
2632SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}};
2633SkRect::Make(source.bounds()).toQuad(bitmapBounds);
2634matrix.setPolyToPoly(bitmapBounds, perspect, 4);
2635matrix.postRotate(45, source.width() / 2, source.height() / 2);
2636canvas->concat(matrix);
2637canvas->drawBitmap(source, 0, 0);
Cary Clarkbc5697d2017-10-04 14:31:33 -04002638##
2639
Cary Clark154beea2017-10-26 07:58:48 -04002640#SeeAlso preRotate setRotate
Cary Clarkbc5697d2017-10-04 14:31:33 -04002641
2642##
2643
2644# ------------------------------------------------------------------------------
2645
2646#Method void postRotate(SkScalar degrees)
2647
Cary Clark154beea2017-10-26 07:58:48 -04002648Sets Matrix to Matrix constructed from rotating by degrees about pivot point
2649(0, 0), multiplied by Matrix.
2650This can be thought of as rotating about the origin after applying Matrix.
2651
2652Positive degrees rotates clockwise.
2653
2654Given:
2655
2656#Code
2657#Literal
2658 | J K L | | c -s 0 |
2659Matrix = | M N O |, R(degrees, px, py) = | s c 0 |
2660 | P Q R | | 0 0 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -04002661##
2662
Cary Clark154beea2017-10-26 07:58:48 -04002663where
2664
2665#Code
2666#Literal
2667c = cos(degrees)
2668s = sin(degrees)
2669##
2670
2671sets Matrix to:
2672
2673#Code
2674#Literal
2675 | c -s dx | | J K L | | cJ-sM cK-sN cL-sO |
2676R(degrees, px, py) * Matrix = | s c dy | | M N O | = | sJ+cM sK+cN sL+cO |
2677 | 0 0 1 | | P Q R | | P Q R |
2678##
2679
2680#Param degrees angle of axes relative to upright axes ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002681
2682#Example
Cary Clark154beea2017-10-26 07:58:48 -04002683#Image 3
2684SkMatrix matrix;
2685SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}};
2686SkRect::Make(source.bounds()).toQuad(bitmapBounds);
2687matrix.setPolyToPoly(bitmapBounds, perspect, 4);
2688matrix.postRotate(45);
2689canvas->concat(matrix);
2690canvas->drawBitmap(source, 0, 0);
Cary Clarkbc5697d2017-10-04 14:31:33 -04002691##
2692
Cary Clark154beea2017-10-26 07:58:48 -04002693#SeeAlso preRotate setRotate
Cary Clarkbc5697d2017-10-04 14:31:33 -04002694
2695##
2696
2697# ------------------------------------------------------------------------------
2698
2699#Method void postSkew(SkScalar kx, SkScalar ky, SkScalar px, SkScalar py)
2700
Cary Clarkab2621d2018-01-30 10:08:57 -05002701#Line # Post-multiplies Matrix by skew. ##
Cary Clark154beea2017-10-26 07:58:48 -04002702Sets Matrix to Matrix constructed from skewing by (kx, ky) about pivot point
2703(px, py), multiplied by Matrix.
2704This can be thought of as skewing about a pivot point after applying Matrix.
2705
2706Given:
2707
2708#Code
2709#Literal
2710 | J K L | | 1 kx dx |
2711Matrix = | M N O |, K(kx, ky, px, py) = | ky 1 dy |
2712 | P Q R | | 0 0 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -04002713##
2714
Cary Clark154beea2017-10-26 07:58:48 -04002715where
2716
2717#Code
2718#Literal
2719dx = -kx * py
2720dy = -ky * px
2721##
2722
2723sets Matrix to:
2724
2725#Code
2726#Literal
2727 | 1 kx dx| |J K L| |J+kx*M+dx*P K+kx*N+dx*Q L+kx*O+dx+R|
2728K(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|
2729 | 0 0 1| |P Q R| | P Q R|
2730##
2731
2732#Param kx horizontal skew factor ##
2733#Param ky vertical skew factor ##
2734#Param px pivot x ##
2735#Param py pivot y ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002736
2737#Example
Cary Clark154beea2017-10-26 07:58:48 -04002738#Image 3
2739SkMatrix matrix;
2740SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}};
2741SkRect::Make(source.bounds()).toQuad(bitmapBounds);
2742matrix.setPolyToPoly(bitmapBounds, perspect, 4);
2743matrix.postSkew(.5f, 0, source.width() / 2, source.height() / 2);
2744canvas->concat(matrix);
2745canvas->drawBitmap(source, 0, 0);
Cary Clarkbc5697d2017-10-04 14:31:33 -04002746##
2747
Cary Clark154beea2017-10-26 07:58:48 -04002748#SeeAlso preSkew setSkew
Cary Clarkbc5697d2017-10-04 14:31:33 -04002749
2750##
2751
2752# ------------------------------------------------------------------------------
2753
2754#Method void postSkew(SkScalar kx, SkScalar ky)
2755
Cary Clark154beea2017-10-26 07:58:48 -04002756Sets Matrix to Matrix constructed from skewing by (kx, ky) about pivot point
2757(0, 0), multiplied by Matrix.
2758This can be thought of as skewing about the origin after applying Matrix.
2759
2760Given:
2761
2762#Code
2763#Literal
2764 | J K L | | 1 kx 0 |
2765Matrix = | M N O |, K(kx, ky) = | ky 1 0 |
2766 | P Q R | | 0 0 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -04002767##
2768
Cary Clark154beea2017-10-26 07:58:48 -04002769sets Matrix to:
2770
2771#Code
2772#Literal
2773 | 1 kx 0 | | J K L | | J+kx*M K+kx*N L+kx*O |
2774K(kx, ky) * Matrix = | ky 1 0 | | M N O | = | ky*J+M ky*K+N ky*L+O |
2775 | 0 0 1 | | P Q R | | P Q R |
2776##
2777
2778#Param kx horizontal skew factor ##
2779#Param ky vertical skew factor ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002780
2781#Example
Cary Clark154beea2017-10-26 07:58:48 -04002782#Image 3
2783SkMatrix matrix;
2784SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}};
2785SkRect::Make(source.bounds()).toQuad(bitmapBounds);
2786matrix.setPolyToPoly(bitmapBounds, perspect, 4);
2787matrix.postSkew(.5f, 0);
2788canvas->concat(matrix);
2789canvas->drawBitmap(source, 0, 0);
Cary Clarkbc5697d2017-10-04 14:31:33 -04002790##
2791
Cary Clark154beea2017-10-26 07:58:48 -04002792#SeeAlso preSkew setSkew
Cary Clarkbc5697d2017-10-04 14:31:33 -04002793
2794##
2795
2796# ------------------------------------------------------------------------------
2797
2798#Method void postConcat(const SkMatrix& other)
2799
Cary Clarkab2621d2018-01-30 10:08:57 -05002800#Line # Post-multiplies Matrix by Matrix parameter. ##
Cary Clark154beea2017-10-26 07:58:48 -04002801Sets Matrix to Matrix other multiplied by Matrix.
2802This can be thought of mapping by other after applying Matrix.
2803
2804Given:
2805
2806#Code
2807#Literal
2808 | J K L | | A B C |
2809Matrix = | M N O |, other = | D E F |
2810 | P Q R | | G H I |
Cary Clarkbc5697d2017-10-04 14:31:33 -04002811##
2812
Cary Clark154beea2017-10-26 07:58:48 -04002813sets Matrix to:
2814
2815#Code
2816#Literal
2817 | A B C | | J K L | | AJ+BM+CP AK+BN+CQ AL+BO+CR |
2818other * Matrix = | D E F | * | M N O | = | DJ+EM+FP DK+EN+FQ DL+EO+FR |
2819 | G H I | | P Q R | | GJ+HM+IP GK+HN+IQ GL+HO+IR |
2820##
2821
2822#Param other Matrix on left side of multiply expression ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002823
2824#Example
Cary Clark154beea2017-10-26 07:58:48 -04002825#Image 3
2826#Height 64
2827SkMatrix matrix, matrix2;
2828SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}};
2829SkRect::Make(source.bounds()).toQuad(bitmapBounds);
2830matrix.setPolyToPoly(bitmapBounds, perspect, 4);
2831matrix.postConcat(matrix);
2832canvas->concat(matrix);
2833canvas->drawBitmap(source, 0, 0);
Cary Clarkbc5697d2017-10-04 14:31:33 -04002834##
2835
Cary Clark154beea2017-10-26 07:58:48 -04002836#SeeAlso preConcat setConcat Concat
Cary Clarkbc5697d2017-10-04 14:31:33 -04002837
2838##
2839
2840# ------------------------------------------------------------------------------
2841
2842#Enum ScaleToFit
2843
2844#Code
2845 enum ScaleToFit {
2846 kFill_ScaleToFit,
2847 kStart_ScaleToFit,
2848 kCenter_ScaleToFit,
2849 kEnd_ScaleToFit,
2850 };
2851##
2852
Cary Clark154beea2017-10-26 07:58:48 -04002853ScaleToFit describes how Matrix is constructed to map one Rect to another.
2854ScaleToFit may allow Matrix to have unequal horizontal and vertical scaling,
2855or may restrict Matrix to square scaling. If restricted, ScaleToFit specifies
2856how Matrix maps to the side or center of the destination Rect.
2857
2858#Const kFill_ScaleToFit 0
2859 Computes Matrix that scales in x and y independently, so that source Rect is
2860 mapped to completely fill destination Rect. The aspect ratio of source Rect
2861 may change.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002862##
Cary Clark154beea2017-10-26 07:58:48 -04002863#Const kStart_ScaleToFit 1
2864 Computes Matrix that maintains source Rect aspect ratio, mapping source Rect
2865 width or height to destination Rect. Aligns mapping to left and top edges
2866 of destination Rect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002867##
Cary Clark154beea2017-10-26 07:58:48 -04002868#Const kCenter_ScaleToFit 2
2869 Computes Matrix that maintains source Rect aspect ratio, mapping source Rect
2870 width or height to destination Rect. Aligns mapping to center of destination
2871 Rect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002872##
Cary Clark154beea2017-10-26 07:58:48 -04002873#Const kEnd_ScaleToFit 3
2874 Computes Matrix that maintains source Rect aspect ratio, mapping source Rect
2875 width or height to destination Rect. Aligns mapping to right and bottom
2876 edges of destination Rect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04002877##
2878
2879#Example
Cary Clark154beea2017-10-26 07:58:48 -04002880 const char* labels[] = { "Fill", "Start", "Center", "End" };
2881 SkRect rects[] = {{5, 5, 59, 59}, {5, 74, 59, 108}, {10, 123, 44, 172}, {10, 187, 54, 231}};
2882 SkRect bounds;
2883 source.getBounds(&bounds);
2884 SkPaint paint;
2885 paint.setAntiAlias(true);
2886 for (auto fit : { SkMatrix::kFill_ScaleToFit, SkMatrix::kStart_ScaleToFit,
2887 SkMatrix::kCenter_ScaleToFit, SkMatrix::kEnd_ScaleToFit } ) {
2888 for (auto rect : rects ) {
2889 canvas->drawRect(rect, paint);
2890 SkMatrix matrix;
2891 if (!matrix.setRectToRect(bounds, rect, fit)) {
2892 continue;
2893 }
2894 SkAutoCanvasRestore acr(canvas, true);
2895 canvas->concat(matrix);
2896 canvas->drawBitmap(source, 0, 0);
2897 }
2898 canvas->drawString(labels[fit], 10, 255, paint);
2899 canvas->translate(64, 0);
2900 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04002901##
2902
Cary Clark154beea2017-10-26 07:58:48 -04002903#SeeAlso setRectToRect MakeRectToRect setPolyToPoly
Cary Clarkbc5697d2017-10-04 14:31:33 -04002904
2905##
2906
2907# ------------------------------------------------------------------------------
2908
2909#Method bool setRectToRect(const SkRect& src, const SkRect& dst, ScaleToFit stf)
2910
Cary Clarkab2621d2018-01-30 10:08:57 -05002911#Line # Sets to map one Rect to another. ##
Cary Clark154beea2017-10-26 07:58:48 -04002912Sets Matrix to scale and translate src Rect to dst Rect. stf selects whether
2913mapping completely fills dst or preserves the aspect ratio, and how to align
2914src within dst. Returns false if src is empty, and sets Matrix to identity.
2915Returns true if dst is empty, and sets Matrix to:
Cary Clarkbc5697d2017-10-04 14:31:33 -04002916
Cary Clark154beea2017-10-26 07:58:48 -04002917#Code
2918#Literal
2919| 0 0 0 |
2920| 0 0 0 |
2921| 0 0 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -04002922##
2923
Cary Clark154beea2017-10-26 07:58:48 -04002924#Param src Rect to map from ##
2925#Param dst Rect to map to ##
2926#Param stf one of: kFill_ScaleToFit, kStart_ScaleToFit,
2927 kCenter_ScaleToFit, kEnd_ScaleToFit
Cary Clarkbc5697d2017-10-04 14:31:33 -04002928##
2929
Cary Clark154beea2017-10-26 07:58:48 -04002930#Return true if Matrix can represent Rect mapping ##
2931
Cary Clarkbc5697d2017-10-04 14:31:33 -04002932#Example
Cary Clark154beea2017-10-26 07:58:48 -04002933 const SkRect srcs[] = { {0, 0, 0, 0}, {1, 2, 3, 4} };
2934 const SkRect dsts[] = { {0, 0, 0, 0}, {5, 6, 8, 9} };
2935 for (auto src : srcs) {
2936 for (auto dst : dsts) {
2937 SkMatrix matrix;
2938 matrix.setAll(-1, -1, -1, -1, -1, -1, -1, -1, -1);
2939 bool success = matrix.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit);
2940 SkDebugf("src: %g, %g, %g, %g dst: %g, %g, %g, %g success: %s\n",
2941 src.fLeft, src.fTop, src.fRight, src.fBottom,
2942 dst.fLeft, dst.fTop, dst.fRight, dst.fBottom, success ? "true" : "false");
2943 matrix.dump();
2944 }
2945 }
2946#StdOut
2947src: 0, 0, 0, 0 dst: 0, 0, 0, 0 success: false
2948[ 1.0000 0.0000 0.0000][ 0.0000 1.0000 0.0000][ 0.0000 0.0000 1.0000]
2949src: 0, 0, 0, 0 dst: 5, 6, 8, 9 success: false
2950[ 1.0000 0.0000 0.0000][ 0.0000 1.0000 0.0000][ 0.0000 0.0000 1.0000]
2951src: 1, 2, 3, 4 dst: 0, 0, 0, 0 success: true
2952[ 0.0000 0.0000 0.0000][ 0.0000 0.0000 0.0000][ 0.0000 0.0000 1.0000]
2953src: 1, 2, 3, 4 dst: 5, 6, 8, 9 success: true
2954[ 1.5000 0.0000 3.5000][ 0.0000 1.5000 3.0000][ 0.0000 0.0000 1.0000]
2955##
Cary Clarkbc5697d2017-10-04 14:31:33 -04002956##
2957
Cary Clark154beea2017-10-26 07:58:48 -04002958#SeeAlso MakeRectToRect ScaleToFit setPolyToPoly SkRect::isEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -04002959
2960##
2961
2962# ------------------------------------------------------------------------------
2963
2964#Method static SkMatrix MakeRectToRect(const SkRect& src, const SkRect& dst, ScaleToFit stf)
2965
Cary Clarkab2621d2018-01-30 10:08:57 -05002966#Line # Constructs from source Rect to destination Rect. ##
Cary Clark154beea2017-10-26 07:58:48 -04002967Returns Matrix set to scale and translate src Rect to dst Rect. stf selects
2968whether mapping completely fills dst or preserves the aspect ratio, and how to
2969align src within dst. Returns the identity Matrix if src is empty. If dst is
2970empty, returns Matrix set to:
Cary Clarkbc5697d2017-10-04 14:31:33 -04002971
Cary Clark154beea2017-10-26 07:58:48 -04002972#Code
2973#Literal
2974| 0 0 0 |
2975| 0 0 0 |
2976| 0 0 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -04002977##
2978
Cary Clark154beea2017-10-26 07:58:48 -04002979#Param src Rect to map from ##
2980#Param dst Rect to map to ##
2981#Param stf one of: kFill_ScaleToFit, kStart_ScaleToFit,
2982 kCenter_ScaleToFit, kEnd_ScaleToFit
2983##
2984
2985#Return Matrix mapping src to dst ##
2986
2987#Example
2988 const SkRect srcs[] = { {0, 0, 0, 0}, {1, 2, 3, 4} };
2989 const SkRect dsts[] = { {0, 0, 0, 0}, {5, 6, 8, 9} };
2990 for (auto src : srcs) {
2991 for (auto dst : dsts) {
2992 SkMatrix matrix = SkMatrix::MakeRectToRect(src, dst, SkMatrix::kFill_ScaleToFit);
2993 SkDebugf("src: %g, %g, %g, %g dst: %g, %g, %g, %g\n",
2994 src.fLeft, src.fTop, src.fRight, src.fBottom,
2995 dst.fLeft, dst.fTop, dst.fRight, dst.fBottom);
2996 matrix.dump();
2997 }
2998 }
2999#StdOut
3000src: 0, 0, 0, 0 dst: 0, 0, 0, 0
3001[ 1.0000 0.0000 0.0000][ 0.0000 1.0000 0.0000][ 0.0000 0.0000 1.0000]
3002src: 0, 0, 0, 0 dst: 5, 6, 8, 9
3003[ 1.0000 0.0000 0.0000][ 0.0000 1.0000 0.0000][ 0.0000 0.0000 1.0000]
3004src: 1, 2, 3, 4 dst: 0, 0, 0, 0
3005[ 0.0000 0.0000 0.0000][ 0.0000 0.0000 0.0000][ 0.0000 0.0000 1.0000]
3006src: 1, 2, 3, 4 dst: 5, 6, 8, 9
3007[ 1.5000 0.0000 3.5000][ 0.0000 1.5000 3.0000][ 0.0000 0.0000 1.0000]
3008##
3009##
3010
3011#SeeAlso setRectToRect ScaleToFit setPolyToPoly SkRect::isEmpty
Cary Clarkbc5697d2017-10-04 14:31:33 -04003012
3013##
3014
3015# ------------------------------------------------------------------------------
3016
3017#Method bool setPolyToPoly(const SkPoint src[], const SkPoint dst[], int count)
3018
Cary Clarkab2621d2018-01-30 10:08:57 -05003019#Line # Sets to map one to four points to an equal array of points. ##
Cary Clark154beea2017-10-26 07:58:48 -04003020Sets Matrix to map src to dst. count must be zero or greater, and four or less.
Cary Clarkbc5697d2017-10-04 14:31:33 -04003021
Cary Clark154beea2017-10-26 07:58:48 -04003022If count is zero, sets Matrix to identity and returns true.
3023If count is one, sets Matrix to translate and returns true.
3024If count is two or more, sets Matrix to map Points if possible; returns false
3025if Matrix cannot be constructed. If count is four, Matrix may include
3026perspective.
Cary Clarkbc5697d2017-10-04 14:31:33 -04003027
Cary Clark154beea2017-10-26 07:58:48 -04003028#Param src Points to map from ##
3029#Param dst Points to map to ##
3030#Param count number of Points in src and dst ##
3031
3032#Return true if Matrix was constructed successfully
Cary Clarkbc5697d2017-10-04 14:31:33 -04003033##
3034
3035#Example
Cary Clark154beea2017-10-26 07:58:48 -04003036 const SkPoint src[] = { { 0, 0}, {30, 0}, {30, -30}, { 0, -30} };
3037 const SkPoint dst[] = { {50, 0}, {80, -10}, {90, -30}, {60, -40} };
3038 SkPaint blackPaint;
3039 blackPaint.setAntiAlias(true);
3040 blackPaint.setTextSize(42);
3041 SkPaint redPaint = blackPaint;
3042 redPaint.setColor(SK_ColorRED);
3043 for (int count : { 1, 2, 3, 4 } ) {
3044 canvas->translate(35, 55);
3045 for (int index = 0; index < count; ++index) {
3046 canvas->drawCircle(src[index], 3, blackPaint);
3047 canvas->drawCircle(dst[index], 3, blackPaint);
3048 if (index > 0) {
3049 canvas->drawLine(src[index], src[index - 1], blackPaint);
3050 canvas->drawLine(dst[index], dst[index - 1], blackPaint);
3051 }
3052 }
3053 SkMatrix matrix;
3054 matrix.setPolyToPoly(src, dst, count);
3055 canvas->drawString("A", src[0].fX, src[0].fY, redPaint);
3056 SkAutoCanvasRestore acr(canvas, true);
3057 canvas->concat(matrix);
3058 canvas->drawString("A", src[0].fX, src[0].fY, redPaint);
3059 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04003060##
3061
Cary Clark154beea2017-10-26 07:58:48 -04003062#SeeAlso setRectToRect MakeRectToRect
Cary Clarkbc5697d2017-10-04 14:31:33 -04003063
3064##
3065
3066# ------------------------------------------------------------------------------
3067
3068#Method bool SK_WARN_UNUSED_RESULT invert(SkMatrix* inverse) const
3069
Cary Clarkab2621d2018-01-30 10:08:57 -05003070#Line # Returns inverse, if possible. ##
Cary Clark154beea2017-10-26 07:58:48 -04003071Sets inverse to reciprocal matrix, returning true if Matrix can be inverted.
3072Geometrically, if Matrix maps from source to destination, inverse Matrix
3073maps from destination to source. If Matrix can not be inverted, inverse is
3074unchanged.
Cary Clarkbc5697d2017-10-04 14:31:33 -04003075
Cary Clark154beea2017-10-26 07:58:48 -04003076#Param inverse storage for inverted Matrix; may be nullptr ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04003077
Cary Clark154beea2017-10-26 07:58:48 -04003078#Return true if Matrix can be inverted ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04003079
3080#Example
Cary Clark154beea2017-10-26 07:58:48 -04003081#Height 128
3082 const SkPoint src[] = { { 10, 120}, {120, 120}, {120, 10}, { 10, 10} };
3083 const SkPoint dst[] = { {150, 120}, {200, 100}, {240, 30}, { 130, 40} };
3084 SkPaint paint;
3085 paint.setAntiAlias(true);
3086 SkMatrix matrix;
3087 matrix.setPolyToPoly(src, dst, 4);
3088 canvas->drawPoints(SkCanvas::kPolygon_PointMode, 4, src, paint);
3089 canvas->drawPoints(SkCanvas::kPolygon_PointMode, 4, dst, paint);
3090 paint.setColor(SK_ColorBLUE);
3091 paint.setStrokeWidth(3);
3092 paint.setStrokeCap(SkPaint::kRound_Cap);
3093 canvas->drawPoints(SkCanvas::kPoints_PointMode, 4, dst, paint);
3094 matrix.invert(&matrix);
3095 canvas->concat(matrix);
3096 canvas->drawPoints(SkCanvas::kPoints_PointMode, 4, dst, paint);
Cary Clarkbc5697d2017-10-04 14:31:33 -04003097##
3098
Cary Clark154beea2017-10-26 07:58:48 -04003099#SeeAlso Concat
Cary Clarkbc5697d2017-10-04 14:31:33 -04003100
3101##
3102
3103# ------------------------------------------------------------------------------
3104
3105#Method static void SetAffineIdentity(SkScalar affine[6])
3106
Cary Clarkab2621d2018-01-30 10:08:57 -05003107#Line # Sets 3x2 array to identity. ##
Cary Clark154beea2017-10-26 07:58:48 -04003108Fills affine with identity values in column major order.
3109Sets affine to:
Cary Clarkbc5697d2017-10-04 14:31:33 -04003110
Cary Clark154beea2017-10-26 07:58:48 -04003111#Code
3112#Literal
3113| 1 0 0 |
3114| 0 1 0 |
Cary Clarkbc5697d2017-10-04 14:31:33 -04003115##
3116
Cary Clark154beea2017-10-26 07:58:48 -04003117Affine 3x2 matrices in column major order are used by OpenGL and XPS.
3118
3119#Param affine storage for 3x2 affine matrix ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04003120
3121#Example
Cary Clark154beea2017-10-26 07:58:48 -04003122 SkScalar affine[6];
3123 SkMatrix::SetAffineIdentity(affine);
3124 const char* names[] = { "ScaleX", "SkewY", "SkewX", "ScaleY", "TransX", "TransY" };
3125 for (int i = 0; i < 6; ++i) {
3126 SkDebugf("%s: %g ", names[i], affine[i]);
3127 }
3128 SkDebugf("\n");
3129#StdOut
3130ScaleX: 1 SkewY: 0 SkewX: 0 ScaleY: 1 TransX: 0 TransY: 0
3131##
Cary Clarkbc5697d2017-10-04 14:31:33 -04003132##
3133
Cary Clark154beea2017-10-26 07:58:48 -04003134#SeeAlso setAffine asAffine
Cary Clarkbc5697d2017-10-04 14:31:33 -04003135
3136##
3137
3138# ------------------------------------------------------------------------------
3139
3140#Method bool SK_WARN_UNUSED_RESULT asAffine(SkScalar affine[6]) const
3141
Cary Clarkab2621d2018-01-30 10:08:57 -05003142#Line # Copies to 3x2 array. ##
Cary Clark154beea2017-10-26 07:58:48 -04003143Fills affine in column major order. Sets affine to:
Cary Clarkbc5697d2017-10-04 14:31:33 -04003144
Cary Clark154beea2017-10-26 07:58:48 -04003145#Code
3146#Literal
3147| scale-x skew-x translate-x |
3148| skew-y scale-y translate-y |
Cary Clarkbc5697d2017-10-04 14:31:33 -04003149##
3150
Cary Clark154beea2017-10-26 07:58:48 -04003151If Matrix contains perspective, returns false and leaves affine unchanged.
3152
3153#Param affine storage for 3x2 affine matrix; may be nullptr ##
3154
3155#Return true if Matrix does not contain perspective ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04003156
3157#Example
Cary Clark154beea2017-10-26 07:58:48 -04003158SkMatrix matrix;
3159matrix.setAll(2, 3, 4, 5, 6, 7, 0, 0, 1);
3160SkScalar affine[6];
3161matrix.asAffine(affine);
3162const char* names[] = { "ScaleX", "SkewY", "SkewX", "ScaleY", "TransX", "TransY" };
3163for (int i = 0; i < 6; ++i) {
3164 SkDebugf("%s: %g ", names[i], affine[i]);
3165}
3166SkDebugf("\n");
3167#StdOut
3168ScaleX: 2 SkewY: 5 SkewX: 3 ScaleY: 6 TransX: 4 TransY: 7
3169##
Cary Clarkbc5697d2017-10-04 14:31:33 -04003170##
3171
Cary Clark154beea2017-10-26 07:58:48 -04003172#SeeAlso setAffine SetAffineIdentity
Cary Clarkbc5697d2017-10-04 14:31:33 -04003173
3174##
3175
3176# ------------------------------------------------------------------------------
3177
3178#Method void setAffine(const SkScalar affine[6])
3179
Cary Clarkab2621d2018-01-30 10:08:57 -05003180#Line # Sets left two columns. ##
Cary Clark154beea2017-10-26 07:58:48 -04003181Sets Matrix to affine values, passed in column major order. Given affine,
3182column, then row, as:
Cary Clarkbc5697d2017-10-04 14:31:33 -04003183
Cary Clark154beea2017-10-26 07:58:48 -04003184#Code
3185#Literal
3186| scale-x skew-x translate-x |
3187| skew-y scale-y translate-y |
Cary Clarkbc5697d2017-10-04 14:31:33 -04003188##
3189
Cary Clark154beea2017-10-26 07:58:48 -04003190Matrix is set, row, then column, to:
3191
3192#Code
3193#Literal
3194| scale-x skew-x translate-x |
3195| skew-y scale-y translate-y |
3196| 0 0 1 |
3197##
3198
3199#Param affine 3x2 affine matrix ##
3200
3201#Example
3202SkMatrix matrix;
3203matrix.setAll(2, 3, 4, 5, 6, 7, 0, 0, 1);
3204SkScalar affine[6];
3205matrix.asAffine(affine);
3206const char* names[] = { "ScaleX", "SkewY", "SkewX", "ScaleY", "TransX", "TransY" };
3207for (int i = 0; i < 6; ++i) {
3208 SkDebugf("%s: %g ", names[i], affine[i]);
3209}
3210SkDebugf("\n");
3211matrix.reset();
3212matrix.setAffine(affine);
3213matrix.dump();
3214#StdOut
3215ScaleX: 2 SkewY: 5 SkewX: 3 ScaleY: 6 TransX: 4 TransY: 7
3216[ 2.0000 3.0000 4.0000][ 5.0000 6.0000 7.0000][ 0.0000 0.0000 1.0000]
3217##
3218##
3219
3220#SeeAlso asAffine SetAffineIdentity
Cary Clarkbc5697d2017-10-04 14:31:33 -04003221
3222##
3223
3224# ------------------------------------------------------------------------------
3225
3226#Method void mapPoints(SkPoint dst[], const SkPoint src[], int count) const
3227
Cary Clarkab2621d2018-01-30 10:08:57 -05003228#Line # Maps Point array. ##
Cary Clark154beea2017-10-26 07:58:48 -04003229Maps src Point array of length count to dst Point array of equal or greater
3230length. Points are mapped by multiplying each Point by Matrix. Given:
3231
3232#Code
3233#Literal
3234 | A B C | | x |
3235Matrix = | D E F |, pt = | y |
3236 | G H I | | 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -04003237##
3238
Cary Clark154beea2017-10-26 07:58:48 -04003239where
3240
3241#Code
3242#Literal
3243for (i = 0; i < count; ++i) {
3244 x = src[i].fX
3245 y = src[i].fY
3246}
Cary Clarkbc5697d2017-10-04 14:31:33 -04003247##
Cary Clark154beea2017-10-26 07:58:48 -04003248
3249each dst Point is computed as:
3250
3251#Code
3252#Literal
3253 |A B C| |x| Ax+By+C Dx+Ey+F
3254Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , -------
3255 |G H I| |1| Gx+Hy+I Gx+Hy+I
Cary Clarkbc5697d2017-10-04 14:31:33 -04003256##
Cary Clark154beea2017-10-26 07:58:48 -04003257
3258src and dst may point to the same storage.
3259
3260#Param dst storage for mapped Points ##
3261#Param src Points to transform ##
3262#Param count number of Points to transform ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04003263
3264#Example
Cary Clark154beea2017-10-26 07:58:48 -04003265 SkMatrix matrix;
3266 matrix.reset();
3267 const int count = 4;
3268 SkPoint src[count];
3269 matrix.mapRectToQuad(src, {40, 70, 180, 220} );
3270 SkPaint paint;
3271 paint.setARGB(77, 23, 99, 154);
3272 for (int i = 0; i < 5; ++i) {
3273 SkPoint dst[count];
3274 matrix.mapPoints(dst, src, count);
3275 canvas->drawPoints(SkCanvas::kPolygon_PointMode, count, dst, paint);
3276 matrix.preRotate(35, 128, 128);
3277 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04003278##
3279
Brian Salomonfa3783f2018-01-05 13:49:07 -05003280#SeeAlso mapXY mapHomogeneousPoints mapVectors
Cary Clarkbc5697d2017-10-04 14:31:33 -04003281
3282##
3283
3284# ------------------------------------------------------------------------------
3285
3286#Method void mapPoints(SkPoint pts[], int count) const
3287
Cary Clark154beea2017-10-26 07:58:48 -04003288Maps pts Point array of length count in place. Points are mapped by multiplying
3289each Point by Matrix. Given:
3290
3291#Code
3292#Literal
3293 | A B C | | x |
3294Matrix = | D E F |, pt = | y |
3295 | G H I | | 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -04003296##
3297
Cary Clark154beea2017-10-26 07:58:48 -04003298where
3299
3300#Code
3301#Literal
3302for (i = 0; i < count; ++i) {
3303 x = pts[i].fX
3304 y = pts[i].fY
3305}
Cary Clarkbc5697d2017-10-04 14:31:33 -04003306##
Cary Clark154beea2017-10-26 07:58:48 -04003307
3308each resulting pts Point is computed as:
3309
3310#Code
3311#Literal
3312 |A B C| |x| Ax+By+C Dx+Ey+F
3313Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , -------
3314 |G H I| |1| Gx+Hy+I Gx+Hy+I
Cary Clarkbc5697d2017-10-04 14:31:33 -04003315##
3316
Cary Clark154beea2017-10-26 07:58:48 -04003317#Param pts storage for mapped Points ##
3318#Param count number of Points to transform ##
3319
Cary Clarkbc5697d2017-10-04 14:31:33 -04003320#Example
Cary Clark154beea2017-10-26 07:58:48 -04003321 SkMatrix matrix;
3322 matrix.setRotate(35, 128, 128);
3323 const int count = 4;
3324 SkPoint pts[count];
3325 matrix.mapRectToQuad(pts, {40, 70, 180, 220} );
3326 SkPaint paint;
3327 paint.setARGB(77, 23, 99, 154);
3328 for (int i = 0; i < 5; ++i) {
3329 canvas->drawPoints(SkCanvas::kPolygon_PointMode, count, pts, paint);
3330 matrix.mapPoints(pts, count);
3331 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04003332##
3333
Brian Salomonfa3783f2018-01-05 13:49:07 -05003334#SeeAlso mapXY mapHomogeneousPoints mapVectors
Cary Clarkbc5697d2017-10-04 14:31:33 -04003335
3336##
3337
3338# ------------------------------------------------------------------------------
3339
Cary Clark154beea2017-10-26 07:58:48 -04003340#Method void mapHomogeneousPoints(SkPoint3 dst[], const SkPoint3 src[], int count) const
Cary Clarkbc5697d2017-10-04 14:31:33 -04003341
Cary Clarkab2621d2018-01-30 10:08:57 -05003342#Line # Maps Point3 array. ##
Cary Clark154beea2017-10-26 07:58:48 -04003343Maps src Point3 array of length count to dst Point3 array, which must of length count or
3344greater. Point3 array is mapped by multiplying each Point3 by Matrix. Given:
3345
3346#Code
3347#Literal
3348 | A B C | | x |
3349Matrix = | D E F |, src = | y |
3350 | G H I | | z |
Cary Clarkbc5697d2017-10-04 14:31:33 -04003351##
3352
Cary Clark154beea2017-10-26 07:58:48 -04003353each resulting dst Point is computed as:
3354
3355#Code
3356#Literal
3357 |A B C| |x|
3358Matrix * src = |D E F| |y| = |Ax+By+Cz Dx+Ey+Fz Gx+Hy+Iz|
3359 |G H I| |z|
Cary Clarkbc5697d2017-10-04 14:31:33 -04003360##
Cary Clark154beea2017-10-26 07:58:48 -04003361
3362#Param dst storage for mapped Point3 array ##
3363#Param src Point3 array to transform ##
3364#Param count items in Point3 array to transform ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04003365
3366#Example
Cary Clark154beea2017-10-26 07:58:48 -04003367 SkPoint3 src[] = {{3, 3, 1}, {8, 2, 2}, {5, 0, 4}, {0, 1, 3},
3368 {3, 7, 1}, {8, 6, 2}, {5, 4, 4}, {0, 5, 3}};
3369 int lines[] = { 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7 };
3370 constexpr int count = SK_ARRAY_COUNT(src);
3371 auto debugster = [=](SkPoint3 src[]) -> void {
3372 for (size_t i = 0; i < SK_ARRAY_COUNT(lines); i += 2) {
3373 const SkPoint3& s = src[lines[i]];
3374 const SkPoint3& e = src[lines[i + 1]];
3375 SkPaint paint;
3376 paint.setARGB(77, 23, 99, 154);
3377 canvas->drawLine(s.fX / s.fZ, s.fY / s.fZ, e.fX / e.fZ, e.fY / e.fZ, paint);
3378 }
3379 };
3380 canvas->save();
3381 canvas->translate(5, 5);
3382 canvas->scale(15, 15);
3383 debugster(src);
3384 canvas->restore();
3385 canvas->translate(128, 128);
3386 SkMatrix matrix;
3387 matrix.setAll(15, 0, 0, 0, 15, 0, -0.08, 0.04, 1);
Cary Clarka560c472017-11-27 10:44:06 -05003388 matrix.mapHomogeneousPoints(src, src, count);
Cary Clark154beea2017-10-26 07:58:48 -04003389 debugster(src);
Cary Clarkbc5697d2017-10-04 14:31:33 -04003390##
3391
Brian Salomonfa3783f2018-01-05 13:49:07 -05003392#SeeAlso mapPoints mapXY mapVectors
Cary Clarkbc5697d2017-10-04 14:31:33 -04003393
3394##
3395
3396# ------------------------------------------------------------------------------
3397
3398#Method void mapXY(SkScalar x, SkScalar y, SkPoint* result) const
3399
Cary Clarkab2621d2018-01-30 10:08:57 -05003400#Line # Maps Point. ##
Cary Clark154beea2017-10-26 07:58:48 -04003401Maps Point (x, y) to result. Point is mapped by multiplying by Matrix. Given:
Cary Clarkbc5697d2017-10-04 14:31:33 -04003402
Cary Clark154beea2017-10-26 07:58:48 -04003403#Code
3404#Literal
3405 | A B C | | x |
3406Matrix = | D E F |, pt = | y |
3407 | G H I | | 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -04003408##
3409
Cary Clark154beea2017-10-26 07:58:48 -04003410result is computed as:
3411
3412#Code
3413#Literal
3414 |A B C| |x| Ax+By+C Dx+Ey+F
3415Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , -------
3416 |G H I| |1| Gx+Hy+I Gx+Hy+I
3417##
3418
3419#Param x x-coordinate of Point to map ##
3420#Param y y-coordinate of Point to map ##
3421#Param result storage for mapped Point ##
3422
3423#Example
3424 SkPaint paint;
3425 paint.setAntiAlias(true);
3426 SkMatrix matrix;
3427 matrix.setRotate(60, 128, 128);
3428 SkPoint lines[] = {{50, 50}, {150, 50}, {150, 150}};
3429 for (size_t i = 0; i < SK_ARRAY_COUNT(lines); ++i) {
3430 SkPoint pt;
3431 matrix.mapXY(lines[i].fX, lines[i].fY, &pt);
3432 canvas->drawCircle(pt.fX, pt.fY, 3, paint);
3433 }
3434 canvas->concat(matrix);
3435 canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(lines), lines, paint);
3436##
3437
Brian Salomonfa3783f2018-01-05 13:49:07 -05003438#SeeAlso mapPoints mapVectors
Cary Clarkbc5697d2017-10-04 14:31:33 -04003439
3440##
3441
3442# ------------------------------------------------------------------------------
3443
3444#Method SkPoint mapXY(SkScalar x, SkScalar y) const
3445
Cary Clark154beea2017-10-26 07:58:48 -04003446Returns Point (x, y) multiplied by Matrix. Given:
Cary Clarkbc5697d2017-10-04 14:31:33 -04003447
Cary Clark154beea2017-10-26 07:58:48 -04003448#Code
3449#Literal
3450 | A B C | | x |
3451Matrix = | D E F |, pt = | y |
3452 | G H I | | 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -04003453##
3454
Cary Clark154beea2017-10-26 07:58:48 -04003455result is computed as:
3456
3457#Code
3458#Literal
3459 |A B C| |x| Ax+By+C Dx+Ey+F
3460Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , -------
3461 |G H I| |1| Gx+Hy+I Gx+Hy+I
3462##
3463
3464#Param x x-coordinate of Point to map ##
3465#Param y y-coordinate of Point to map ##
3466
3467#Return mapped Point ##
3468
3469#Example
3470#Image 4
3471SkMatrix matrix;
3472SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {30, 206}};
3473SkRect::Make(source.bounds()).toQuad(bitmapBounds);
3474matrix.setPolyToPoly(bitmapBounds, perspect, 4);
3475SkPaint paint;
3476paint.setAntiAlias(true);
3477paint.setStrokeWidth(3);
3478for (int x : { 0, source.width() } ) {
3479 for (int y : { 0, source.height() } ) {
3480 canvas->drawPoint(matrix.mapXY(x, y), paint);
3481 }
3482}
3483canvas->concat(matrix);
3484canvas->drawBitmap(source, 0, 0);
3485##
3486
Brian Salomonfa3783f2018-01-05 13:49:07 -05003487#SeeAlso mapPoints mapVectors
Cary Clarkbc5697d2017-10-04 14:31:33 -04003488
3489##
3490
3491# ------------------------------------------------------------------------------
3492
3493#Method void mapVectors(SkVector dst[], const SkVector src[], int count) const
3494
Cary Clarkab2621d2018-01-30 10:08:57 -05003495#Line # Maps Vector array. ##
Cary Clark154beea2017-10-26 07:58:48 -04003496Maps src Vector array of length count to Vector Point array of equal or greater
3497length. Vectors are mapped by multiplying each Vector by Matrix, treating
3498Matrix translation as zero. Given:
Cary Clarkbc5697d2017-10-04 14:31:33 -04003499
Cary Clark154beea2017-10-26 07:58:48 -04003500#Code
3501#Literal
3502 | A B 0 | | x |
3503Matrix = | D E 0 |, src = | y |
3504 | G H I | | 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -04003505##
Cary Clark154beea2017-10-26 07:58:48 -04003506
3507where
3508
3509#Code
3510#Literal
3511for (i = 0; i < count; ++i) {
3512 x = src[i].fX
3513 y = src[i].fY
3514}
Cary Clarkbc5697d2017-10-04 14:31:33 -04003515##
Cary Clark154beea2017-10-26 07:58:48 -04003516
3517each dst Vector is computed as:
3518
3519#Code
3520#Literal
3521 |A B 0| |x| Ax+By Dx+Ey
3522Matrix * src = |D E 0| |y| = |Ax+By Dx+Ey Gx+Hy+I| = ------- , -------
3523 |G H I| |1| Gx+Hy+I Gx+Hy+I
Cary Clarkbc5697d2017-10-04 14:31:33 -04003524##
3525
Cary Clark154beea2017-10-26 07:58:48 -04003526src and dst may point to the same storage.
3527
3528#Param dst storage for mapped Vectors ##
3529#Param src Vectors to transform ##
3530#Param count number of Vectors to transform ##
3531
Cary Clarkbc5697d2017-10-04 14:31:33 -04003532#Example
Cary Clark154beea2017-10-26 07:58:48 -04003533 SkPaint paint;
3534 paint.setAntiAlias(true);
3535 paint.setStyle(SkPaint::kStroke_Style);
3536 SkMatrix matrix;
3537 matrix.reset();
3538 const SkVector radii[] = {{8, 4}, {9, 1}, {6, 2}, {7, 3}};
3539 for (int i = 0; i < 4; ++i) {
3540 SkVector rScaled[4];
3541 matrix.preScale(1.5f, 2.f);
3542 matrix.mapVectors(rScaled, radii, SK_ARRAY_COUNT(radii));
3543 SkRRect rrect;
3544 rrect.setRectRadii({20, 20, 180, 70}, rScaled);
3545 canvas->drawRRect(rrect, paint);
3546 canvas->translate(0, 60);
3547 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04003548##
3549
Brian Salomonfa3783f2018-01-05 13:49:07 -05003550#SeeAlso mapVector mapPoints mapXY
Cary Clarkbc5697d2017-10-04 14:31:33 -04003551
3552##
3553
3554# ------------------------------------------------------------------------------
3555
3556#Method void mapVectors(SkVector vecs[], int count) const
3557
Cary Clark154beea2017-10-26 07:58:48 -04003558Maps vecs Vector array of length count in place, multiplying each Vector by
3559Matrix, treating Matrix translation as zero. Given:
Cary Clarkbc5697d2017-10-04 14:31:33 -04003560
Cary Clark154beea2017-10-26 07:58:48 -04003561#Code
3562#Literal
3563 | A B 0 | | x |
3564Matrix = | D E 0 |, vec = | y |
3565 | G H I | | 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -04003566##
Cary Clark154beea2017-10-26 07:58:48 -04003567
3568where
3569
3570#Code
3571#Literal
3572for (i = 0; i < count; ++i) {
3573 x = vecs[i].fX
3574 y = vecs[i].fY
3575}
Cary Clarkbc5697d2017-10-04 14:31:33 -04003576##
3577
Cary Clark154beea2017-10-26 07:58:48 -04003578each result Vector is computed as:
3579
3580#Code
3581#Literal
3582 |A B 0| |x| Ax+By Dx+Ey
3583Matrix * vec = |D E 0| |y| = |Ax+By Dx+Ey Gx+Hy+I| = ------- , -------
3584 |G H I| |1| Gx+Hy+I Gx+Hy+I
3585##
3586
3587#Param vecs Vectors to transform, and storage for mapped Vectors ##
3588#Param count number of Vectors to transform ##
3589
Cary Clarkbc5697d2017-10-04 14:31:33 -04003590#Example
Cary Clark154beea2017-10-26 07:58:48 -04003591 SkPaint paint;
3592 paint.setAntiAlias(true);
3593 paint.setStyle(SkPaint::kStroke_Style);
3594 SkMatrix matrix;
3595 matrix.setScale(2, 3);
3596 SkVector radii[] = {{7, 7}, {3, 3}, {2, 2}, {4, 0}};
3597 for (int i = 0; i < 4; ++i) {
3598 SkRRect rrect;
3599 rrect.setRectRadii({20, 20, 180, 70}, radii);
3600 canvas->drawRRect(rrect, paint);
3601 canvas->translate(0, 60);
3602 matrix.mapVectors(radii, SK_ARRAY_COUNT(radii));
3603 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04003604##
3605
Brian Salomonfa3783f2018-01-05 13:49:07 -05003606#SeeAlso mapVector mapPoints mapXY
Cary Clarkbc5697d2017-10-04 14:31:33 -04003607
3608##
3609
3610# ------------------------------------------------------------------------------
3611
3612#Method void mapVector(SkScalar dx, SkScalar dy, SkVector* result) const
3613
Cary Clarkab2621d2018-01-30 10:08:57 -05003614#Line # Maps Vector. ##
Cary Clark154beea2017-10-26 07:58:48 -04003615Maps Vector (x, y) to result. Vector is mapped by multiplying by Matrix,
3616treating Matrix translation as zero. Given:
Cary Clarkbc5697d2017-10-04 14:31:33 -04003617
Cary Clark154beea2017-10-26 07:58:48 -04003618#Code
3619#Literal
3620 | A B 0 | | dx |
3621Matrix = | D E 0 |, vec = | dy |
3622 | G H I | | 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -04003623##
3624
Cary Clark154beea2017-10-26 07:58:48 -04003625each result Vector is computed as:
3626
3627#Code
3628#Literal
3629#Outdent
3630 |A B 0| |dx| A*dx+B*dy D*dx+E*dy
3631Matrix * vec = |D E 0| |dy| = |A*dx+B*dy D*dx+E*dy G*dx+H*dy+I| = ----------- , -----------
3632 |G H I| | 1| G*dx+H*dy+I G*dx+*dHy+I
3633##
3634
3635#Param dx x-coordinate of Vector to map ##
3636#Param dy y-coordinate of Vector to map ##
3637#Param result storage for mapped Vector ##
3638
3639#Example
3640 SkPaint paint;
3641 paint.setColor(SK_ColorGREEN);
3642 paint.setAntiAlias(true);
3643 paint.setTextSize(48);
3644 SkMatrix matrix;
3645 matrix.setRotate(90);
3646 SkVector offset = { 7, 7 };
3647 for (int i = 0; i < 4; ++i) {
3648 paint.setImageFilter(SkDropShadowImageFilter::Make(offset.fX, offset.fY, 3, 3,
3649 SK_ColorBLUE, SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, nullptr));
3650 matrix.mapVector(offset.fX, offset.fY, &offset);
3651 canvas->translate(0, 60);
3652 canvas->drawString("Text", 50, 0, paint);
3653 }
3654##
3655
Brian Salomonfa3783f2018-01-05 13:49:07 -05003656#SeeAlso mapVectors mapPoints mapXY
Cary Clarkbc5697d2017-10-04 14:31:33 -04003657
3658##
3659
3660# ------------------------------------------------------------------------------
3661
3662#Method SkVector mapVector(SkScalar dx, SkScalar dy) const
3663
Cary Clark154beea2017-10-26 07:58:48 -04003664Returns Vector (x, y) multiplied by Matrix, treating Matrix translation as zero.
3665Given:
Cary Clarkbc5697d2017-10-04 14:31:33 -04003666
Cary Clark154beea2017-10-26 07:58:48 -04003667#Code
3668#Literal
3669 | A B 0 | | dx |
3670Matrix = | D E 0 |, vec = | dy |
3671 | G H I | | 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -04003672##
3673
Cary Clark154beea2017-10-26 07:58:48 -04003674each result Vector is computed as:
3675
3676#Code
3677#Literal
3678#Outdent
3679 |A B 0| |dx| A*dx+B*dy D*dx+E*dy
3680Matrix * vec = |D E 0| |dy| = |A*dx+B*dy D*dx+E*dy G*dx+H*dy+I| = ----------- , -----------
3681 |G H I| | 1| G*dx+H*dy+I G*dx+*dHy+I
3682##
3683
3684#Param dx x-coordinate of Vector to map ##
3685#Param dy y-coordinate of Vector to map ##
3686
3687#Return mapped Vector ##
3688
3689#Example
3690 SkPaint paint;
3691 paint.setColor(SK_ColorGREEN);
3692 paint.setAntiAlias(true);
3693 paint.setTextSize(48);
3694 SkMatrix matrix;
3695 matrix.setRotate(90);
3696 SkVector offset = { 7, 7 };
3697 for (int i = 0; i < 4; ++i) {
3698 paint.setImageFilter(SkDropShadowImageFilter::Make(offset.fX, offset.fY, 3, 3,
3699 SK_ColorBLUE, SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, nullptr));
3700 offset = matrix.mapVector(offset.fX, offset.fY);
3701 canvas->translate(0, 60);
3702 canvas->drawString("Text", 50, 0, paint);
3703 }
3704##
3705
Brian Salomonfa3783f2018-01-05 13:49:07 -05003706#SeeAlso mapVectors mapPoints mapXY
Cary Clarkbc5697d2017-10-04 14:31:33 -04003707
3708##
3709
3710# ------------------------------------------------------------------------------
3711
3712#Method bool mapRect(SkRect* dst, const SkRect& src) const
3713
Cary Clarkab2621d2018-01-30 10:08:57 -05003714#Line # Returns bounds of mapped Rect. ##
Cary Clark154beea2017-10-26 07:58:48 -04003715Sets dst to bounds of src corners mapped by Matrix.
3716Returns true if mapped corners are dst corners.
Cary Clarkbc5697d2017-10-04 14:31:33 -04003717
Cary Clark154beea2017-10-26 07:58:48 -04003718Returned value is the same as calling rectStaysRect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04003719
Cary Clark154beea2017-10-26 07:58:48 -04003720#Param dst storage for bounds of mapped Points ##
3721#Param src Rect to map ##
3722
3723#Return true if dst is equivalent to mapped src ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04003724
3725#Example
Cary Clark154beea2017-10-26 07:58:48 -04003726 SkPaint paint;
3727 paint.setAntiAlias(true);
3728 SkMatrix matrix;
3729 matrix.setRotate(45, 128, 128);
3730 SkRect rotatedBounds, bounds = {40, 50, 190, 200};
3731 matrix.mapRect(&rotatedBounds, bounds );
3732 paint.setColor(SK_ColorGRAY);
3733 canvas->drawRect(rotatedBounds, paint);
3734 canvas->concat(matrix);
3735 paint.setColor(SK_ColorRED);
3736 canvas->drawRect(bounds, paint);
Cary Clarkbc5697d2017-10-04 14:31:33 -04003737##
3738
Cary Clark154beea2017-10-26 07:58:48 -04003739#SeeAlso mapPoints rectStaysRect
Cary Clarkbc5697d2017-10-04 14:31:33 -04003740
3741##
3742
3743# ------------------------------------------------------------------------------
3744
3745#Method bool mapRect(SkRect* rect) const
3746
Cary Clark154beea2017-10-26 07:58:48 -04003747Sets rect to bounds of rect corners mapped by Matrix.
3748Returns true if mapped corners are computed rect corners.
Cary Clarkbc5697d2017-10-04 14:31:33 -04003749
Cary Clark154beea2017-10-26 07:58:48 -04003750Returned value is the same as calling rectStaysRect.
Cary Clarkbc5697d2017-10-04 14:31:33 -04003751
Cary Clark154beea2017-10-26 07:58:48 -04003752#Param rect rectangle to map, and storage for bounds of mapped corners ##
3753
3754#Return true if result is equivalent to mapped src ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04003755
3756#Example
Cary Clark154beea2017-10-26 07:58:48 -04003757 SkPaint paint;
3758 paint.setAntiAlias(true);
3759 SkMatrix matrix;
3760 matrix.setRotate(45, 128, 128);
3761 SkRect bounds = {40, 50, 190, 200};
3762 matrix.mapRect(&bounds);
3763 paint.setColor(SK_ColorGRAY);
3764 canvas->drawRect(bounds, paint);
3765 canvas->concat(matrix);
3766 paint.setColor(SK_ColorRED);
3767 canvas->drawRect({40, 50, 190, 200}, paint);
Cary Clarkbc5697d2017-10-04 14:31:33 -04003768##
3769
Cary Clark154beea2017-10-26 07:58:48 -04003770#SeeAlso mapRectScaleTranslate mapPoints rectStaysRect
Cary Clarkbc5697d2017-10-04 14:31:33 -04003771
3772##
3773
3774# ------------------------------------------------------------------------------
3775
3776#Method void mapRectToQuad(SkPoint dst[4], const SkRect& rect) const
3777
Cary Clarkab2621d2018-01-30 10:08:57 -05003778#Line # Maps Rect to Point array. ##
Cary Clark154beea2017-10-26 07:58:48 -04003779Maps four corners of rect to dst. Points are mapped by multiplying each
3780rect corner by Matrix. rect corner is processed in this order:
3781(rect.fLeft, rect.fTop), (rect.fRight, rect.fTop), (rect.fRight, rect.fBottom),
3782(rect.fLeft, rect.fBottom).
Cary Clarkbc5697d2017-10-04 14:31:33 -04003783
Cary Clark154beea2017-10-26 07:58:48 -04003784rect may be empty: rect.fLeft may be greater than or equal to rect.fRight;
3785rect.fTop may be greater than or equal to rect.fBottom.
3786
3787Given:
3788
3789#Code
3790#Literal
3791 | A B C | | x |
3792Matrix = | D E F |, pt = | y |
3793 | G H I | | 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -04003794##
Cary Clark154beea2017-10-26 07:58:48 -04003795
3796where pt is initialized from each of (rect.fLeft, rect.fTop),
3797(rect.fRight, rect.fTop), (rect.fRight, rect.fBottom), (rect.fLeft, rect.fBottom),
3798each dst Point is computed as:
3799
3800#Code
3801#Literal
3802 |A B C| |x| Ax+By+C Dx+Ey+F
3803Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , -------
3804 |G H I| |1| Gx+Hy+I Gx+Hy+I
Cary Clarkbc5697d2017-10-04 14:31:33 -04003805##
3806
Cary Clark154beea2017-10-26 07:58:48 -04003807#Param dst storage for mapped corner Points ##
3808#Param rect Rect to map ##
3809
Cary Clarkbc5697d2017-10-04 14:31:33 -04003810#Example
Cary Clark2ade9972017-11-02 17:49:34 -04003811#Height 192
Cary Clark154beea2017-10-26 07:58:48 -04003812 SkPaint paint;
3813 paint.setAntiAlias(true);
3814 SkMatrix matrix;
3815 matrix.setRotate(60, 128, 128);
3816 SkRect rect = {50, 50, 150, 150};
3817 SkPoint pts[4];
3818 matrix.mapRectToQuad(pts, rect);
3819 for (int i = 0; i < 4; ++i) {
3820 canvas->drawCircle(pts[i].fX, pts[i].fY, 3, paint);
3821 }
3822 canvas->concat(matrix);
3823 paint.setStyle(SkPaint::kStroke_Style);
3824 canvas->drawRect(rect, paint);
Cary Clarkbc5697d2017-10-04 14:31:33 -04003825##
3826
Cary Clark154beea2017-10-26 07:58:48 -04003827#SeeAlso mapRect mapRectScaleTranslate
Cary Clarkbc5697d2017-10-04 14:31:33 -04003828
3829##
3830
3831# ------------------------------------------------------------------------------
3832
3833#Method void mapRectScaleTranslate(SkRect* dst, const SkRect& src) const
3834
Cary Clarkab2621d2018-01-30 10:08:57 -05003835#Line # Returns bounds of mapped Rect. ##
Cary Clark154beea2017-10-26 07:58:48 -04003836Sets dst to bounds of src corners mapped by Matrix. If matrix contains
3837elements other than scale or translate: asserts if SK_DEBUG is defined;
3838otherwise, results are undefined.
Cary Clarkbc5697d2017-10-04 14:31:33 -04003839
Cary Clark154beea2017-10-26 07:58:48 -04003840#Param dst storage for bounds of mapped Points ##
3841#Param src Rect to map ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04003842
3843#Example
Cary Clark154beea2017-10-26 07:58:48 -04003844 SkPaint paint;
3845 SkMatrix matrix;
3846 SkRect rect = {100, 50, 150, 180};
3847 matrix.setScale(2, .5f, rect.centerX(), rect.centerY());
3848 SkRect rotated;
3849 matrix.mapRectScaleTranslate(&rotated, rect);
3850 paint.setStyle(SkPaint::kStroke_Style);
3851 canvas->drawRect(rect, paint);
3852 paint.setColor(SK_ColorRED);
3853 canvas->drawRect(rotated, paint);
Cary Clarkbc5697d2017-10-04 14:31:33 -04003854##
3855
Cary Clark154beea2017-10-26 07:58:48 -04003856#SeeAlso mapRect mapRectToQuad isScaleTranslate rectStaysRect
Cary Clarkbc5697d2017-10-04 14:31:33 -04003857
3858##
3859
3860# ------------------------------------------------------------------------------
3861
3862#Method SkScalar mapRadius(SkScalar radius) const
3863
Cary Clarkab2621d2018-01-30 10:08:57 -05003864#Line # Returns mean radius of mapped Circle. ##
Cary Clark154beea2017-10-26 07:58:48 -04003865Returns geometric mean radius of ellipse formed by constructing Circle of
3866size radius, and mapping constructed Circle with Matrix. The result squared is
3867equal to the major axis length times the minor axis length.
3868Result is not meaningful if Matrix contains perspective elements.
Cary Clarkbc5697d2017-10-04 14:31:33 -04003869
Cary Clark154beea2017-10-26 07:58:48 -04003870#Param radius Circle size to map ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04003871
Cary Clark154beea2017-10-26 07:58:48 -04003872#Return average mapped radius ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04003873
3874#Example
Cary Clark154beea2017-10-26 07:58:48 -04003875#Description
3876The area enclosed by a square with sides equal to mappedRadius is the same as
3877the area enclosed by the ellipse major and minor axes.
3878##
3879 SkPaint paint;
3880 paint.setAntiAlias(true);
3881 SkMatrix matrix;
3882 const SkPoint center = {108, 93};
3883 matrix.setScale(2, .5f, center.fX, center.fY);
3884 matrix.postRotate(45, center.fX, center.fY);
3885 const SkScalar circleRadius = 50;
3886 SkScalar mappedRadius = matrix.mapRadius(circleRadius);
3887 SkVector minorAxis, majorAxis;
3888 matrix.mapVector(0, circleRadius, &minorAxis);
3889 matrix.mapVector(circleRadius, 0, &majorAxis);
3890 SkString mappedArea;
3891 mappedArea.printf("area = %g", mappedRadius * mappedRadius);
3892 canvas->drawString(mappedArea, 145, 250, paint);
3893 canvas->drawString("mappedRadius", center.fX + mappedRadius + 3, center.fY, paint);
3894 paint.setColor(SK_ColorRED);
3895 SkString axArea;
3896 axArea.printf("area = %g", majorAxis.length() * minorAxis.length());
3897 paint.setStyle(SkPaint::kFill_Style);
3898 canvas->drawString(axArea, 15, 250, paint);
3899 paint.setStyle(SkPaint::kStroke_Style);
3900 canvas->drawRect({10, 200, 10 + majorAxis.length(), 200 + minorAxis.length()}, paint);
3901 paint.setColor(SK_ColorBLACK);
3902 canvas->drawLine(center.fX, center.fY, center.fX + mappedRadius, center.fY, paint);
3903 canvas->drawLine(center.fX, center.fY, center.fX, center.fY + mappedRadius, paint);
3904 canvas->drawRect({140, 180, 140 + mappedRadius, 180 + mappedRadius}, paint);
3905 canvas->concat(matrix);
3906 canvas->drawCircle(center.fX, center.fY, circleRadius, paint);
3907 paint.setColor(SK_ColorRED);
3908 canvas->drawLine(center.fX, center.fY, center.fX + circleRadius, center.fY, paint);
3909 canvas->drawLine(center.fX, center.fY, center.fX, center.fY + circleRadius, paint);
Cary Clarkbc5697d2017-10-04 14:31:33 -04003910##
3911
Cary Clark154beea2017-10-26 07:58:48 -04003912#SeeAlso mapVector
Cary Clarkbc5697d2017-10-04 14:31:33 -04003913
3914##
3915
3916# ------------------------------------------------------------------------------
3917
3918#Method bool isFixedStepInX() const
3919
Cary Clarkab2621d2018-01-30 10:08:57 -05003920#Line # Returns if transformation supports fixed step in x. ##
Cary Clark154beea2017-10-26 07:58:48 -04003921Returns true if a unit step in x at some y mapped through Matrix can be
3922represented by a constant Vector. Returns true if getType returns kIdentity_Mask,
3923or combinations of: kTranslate_Mask, kScale_Mask, and kAffine_Mask.
Cary Clarkbc5697d2017-10-04 14:31:33 -04003924
Cary Clark154beea2017-10-26 07:58:48 -04003925May return true if getType returns kPerspective_Mask, but only when Matrix
3926does not include rotation or skewing along the y-axis.
3927
3928#Return true if Matrix does not have complex perspective ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04003929
3930#Example
Cary Clark154beea2017-10-26 07:58:48 -04003931 SkMatrix matrix;
3932 for (SkScalar px : { 0.0f, 0.1f } ) {
3933 for (SkScalar py : { 0.0f, 0.1f } ) {
3934 for (SkScalar sy : { 1, 2 } ) {
3935 matrix.setAll(1, 0, 0, 0, sy, 0, px, py, 1);
3936 matrix.dump();
3937 SkDebugf("isFixedStepInX: %s\n", matrix.isFixedStepInX() ? "true" : "false");
3938 }
3939 }
3940 }
3941#StdOut
3942[ 1.0000 0.0000 0.0000][ 0.0000 1.0000 0.0000][ 0.0000 0.0000 1.0000]
3943isFixedStepInX: true
3944[ 1.0000 0.0000 0.0000][ 0.0000 2.0000 0.0000][ 0.0000 0.0000 1.0000]
3945isFixedStepInX: true
3946[ 1.0000 0.0000 0.0000][ 0.0000 1.0000 0.0000][ 0.0000 0.1000 1.0000]
3947isFixedStepInX: true
3948[ 1.0000 0.0000 0.0000][ 0.0000 2.0000 0.0000][ 0.0000 0.1000 1.0000]
3949isFixedStepInX: true
3950[ 1.0000 0.0000 0.0000][ 0.0000 1.0000 0.0000][ 0.1000 0.0000 1.0000]
3951isFixedStepInX: false
3952[ 1.0000 0.0000 0.0000][ 0.0000 2.0000 0.0000][ 0.1000 0.0000 1.0000]
3953isFixedStepInX: false
3954[ 1.0000 0.0000 0.0000][ 0.0000 1.0000 0.0000][ 0.1000 0.1000 1.0000]
3955isFixedStepInX: false
3956[ 1.0000 0.0000 0.0000][ 0.0000 2.0000 0.0000][ 0.1000 0.1000 1.0000]
3957isFixedStepInX: false
3958##
Cary Clarkbc5697d2017-10-04 14:31:33 -04003959##
3960
Cary Clark154beea2017-10-26 07:58:48 -04003961#SeeAlso fixedStepInX getType
Cary Clarkbc5697d2017-10-04 14:31:33 -04003962
3963##
3964
3965# ------------------------------------------------------------------------------
3966
3967#Method SkVector fixedStepInX(SkScalar y) const
3968
Cary Clarkab2621d2018-01-30 10:08:57 -05003969#Line # Returns step in x for a position in y. ##
Cary Clark154beea2017-10-26 07:58:48 -04003970Returns Vector representing a unit step in x at y mapped through Matrix.
3971If isFixedStepInX is false, returned value is undefined.
Cary Clarkbc5697d2017-10-04 14:31:33 -04003972
Cary Clark154beea2017-10-26 07:58:48 -04003973#Param y position of line parallel to x-axis ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04003974
Cary Clark154beea2017-10-26 07:58:48 -04003975#Return Vector advance of mapped unit step in x ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04003976
3977#Example
Cary Clark154beea2017-10-26 07:58:48 -04003978#Image 3
3979 SkMatrix matrix;
3980 const SkPoint center = { 128, 128 };
3981 matrix.setScale(20, 25, center.fX, center.fY);
3982 matrix.postRotate(75, center.fX, center.fY);
3983 {
3984 SkAutoCanvasRestore acr(canvas, true);
3985 canvas->concat(matrix);
3986 canvas->drawBitmap(source, 0, 0);
3987 }
3988 if (matrix.isFixedStepInX()) {
3989 SkPaint paint;
3990 paint.setAntiAlias(true);
3991 SkVector step = matrix.fixedStepInX(128);
3992 SkVector end = center + step;
3993 canvas->drawLine(center, end, paint);
3994 SkVector arrow = { step.fX + step.fY, step.fY - step.fX};
3995 arrow = arrow * .25f;
3996 canvas->drawLine(end, end - arrow, paint);
3997 canvas->drawLine(end, {end.fX + arrow.fY, end.fY - arrow.fX}, paint);
3998 }
Cary Clarkbc5697d2017-10-04 14:31:33 -04003999##
4000
Cary Clark154beea2017-10-26 07:58:48 -04004001#SeeAlso isFixedStepInX getType
Cary Clarkbc5697d2017-10-04 14:31:33 -04004002
4003##
4004
4005# ------------------------------------------------------------------------------
4006
4007#Method bool cheapEqualTo(const SkMatrix& m) const
4008
Cary Clarkab2621d2018-01-30 10:08:57 -05004009#Line # Compares Matrix pair using memcmp(). ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04004010Returns true if Matrix equals m, using an efficient comparison.
4011
Cary Clark154beea2017-10-26 07:58:48 -04004012Returns false when the sign of zero values is the different; when one
Cary Clarkbc5697d2017-10-04 14:31:33 -04004013matrix has positive zero value and the other has negative zero value.
4014
Cary Clark154beea2017-10-26 07:58:48 -04004015Returns true even when both Matrices contain NaN.
Cary Clarkbc5697d2017-10-04 14:31:33 -04004016
Cary Clark154beea2017-10-26 07:58:48 -04004017NaN never equals any value, including itself. To improve performance, NaN values
4018are treated as bit patterns that are equal if their bit patterns are equal.
Cary Clarkbc5697d2017-10-04 14:31:33 -04004019
Cary Clark154beea2017-10-26 07:58:48 -04004020#Param m Matrix to compare ##
4021
4022#Return true if m and Matrix are represented by identical bit patterns ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04004023
4024#Example
Cary Clark154beea2017-10-26 07:58:48 -04004025 auto debugster = [](const char* prefix, const SkMatrix& a, const SkMatrix& b) -> void {
4026 SkDebugf("%s: a %c= b a.cheapEqualTo(b): %s\n", prefix,
4027 a == b ? '=' : '!', a.cheapEqualTo(b) ? "true" : "false");
Cary Clarkbc5697d2017-10-04 14:31:33 -04004028 };
Cary Clark154beea2017-10-26 07:58:48 -04004029 SkMatrix a, b;
4030 a.setAll(1, 0, 0, 0, 1, 0, 0, 0, 1);
4031 b.setIdentity();
4032 debugster("identity", a, b);
4033 a.setAll(1, -0.0f, 0, 0, 1, 0, 0, 0, 1);
4034 debugster("neg zero", a, b);
4035 a.setAll(1, SK_ScalarNaN, 0, 0, 1, 0, 0, 0, 1);
4036 debugster(" one NaN", a, b);
4037 b.setAll(1, SK_ScalarNaN, 0, 0, 1, 0, 0, 0, 1);
4038 debugster("both NaN", a, b);
4039#StdOut
4040identity: a == b a.cheapEqualTo(b): true
4041neg zero: a == b a.cheapEqualTo(b): false
4042 one NaN: a != b a.cheapEqualTo(b): false
4043both NaN: a != b a.cheapEqualTo(b): true
4044##
Cary Clarkbc5697d2017-10-04 14:31:33 -04004045##
4046
Cary Clark154beea2017-10-26 07:58:48 -04004047#SeeAlso operator==(const SkMatrix& a, const SkMatrix& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -04004048
4049##
4050
4051# ------------------------------------------------------------------------------
4052
Cary Clark154beea2017-10-26 07:58:48 -04004053#Method bool operator==(const SkMatrix& a, const SkMatrix& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -04004054
Cary Clarkab2621d2018-01-30 10:08:57 -05004055#Line # Returns true if members are equal. ##
Cary Clark154beea2017-10-26 07:58:48 -04004056Compares a and b; returns true if a and b are numerically equal. Returns true
4057even if sign of zero values are different. Returns false if either Matrix
4058contains NaN, even if the other Matrix also contains NaN.
Cary Clarkbc5697d2017-10-04 14:31:33 -04004059
Cary Clark154beea2017-10-26 07:58:48 -04004060#Param a Matrix to compare ##
4061#Param b Matrix to compare ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04004062
Cary Clark154beea2017-10-26 07:58:48 -04004063#Return true if m and Matrix are numerically equal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04004064
4065#Example
Cary Clark154beea2017-10-26 07:58:48 -04004066 auto debugster = [](const char* prefix, const SkMatrix& a, const SkMatrix& b) -> void {
4067 SkDebugf("%s: a %c= b a.cheapEqualTo(b): %s\n", prefix,
4068 a == b ? '=' : '!', a.cheapEqualTo(b) ? "true" : "false");
4069 };
4070 SkMatrix a, b;
4071 a.setAll(1, 0, 0, 0, 1, 0, 0, 0, 1);
4072 b.setScale(2, 4);
4073 b.postScale(0.5f, 0.25f);
4074 debugster("identity", a, b);
4075#StdOut
4076identity: a == b a.cheapEqualTo(b): true
4077##
Cary Clarkbc5697d2017-10-04 14:31:33 -04004078##
4079
Cary Clark154beea2017-10-26 07:58:48 -04004080#SeeAlso cheapEqualTo operator!=(const SkMatrix& a, const SkMatrix& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -04004081
4082##
4083
4084# ------------------------------------------------------------------------------
4085
Cary Clark154beea2017-10-26 07:58:48 -04004086#Method bool operator!=(const SkMatrix& a, const SkMatrix& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -04004087
Cary Clarkab2621d2018-01-30 10:08:57 -05004088#Line # Returns true if members are unequal. ##
Cary Clark154beea2017-10-26 07:58:48 -04004089Compares a and b; returns true if a and b are not numerically equal. Returns false
4090even if sign of zero values are different. Returns true if either Matrix
4091contains NaN, even if the other Matrix also contains NaN.
Cary Clarkbc5697d2017-10-04 14:31:33 -04004092
Cary Clark154beea2017-10-26 07:58:48 -04004093#Param a Matrix to compare ##
4094#Param b Matrix to compare ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04004095
Cary Clark154beea2017-10-26 07:58:48 -04004096#Return true if m and Matrix are numerically not equal ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04004097
4098#Example
Cary Clark154beea2017-10-26 07:58:48 -04004099 auto debugster = [](const char* prefix, const SkMatrix& a, const SkMatrix& b) -> void {
4100 SkDebugf("%s: a %c= b a.cheapEqualTo(b): %s\n", prefix,
4101 a != b ? '!' : '=', a.cheapEqualTo(b) ? "true" : "false");
4102 };
4103 SkMatrix a, b;
4104 a.setAll(1, 0, 0, 0, 1, 0, 1, 0, 1);
4105 a.invert(&b);
4106 debugster("identity", a, b);
Cary Clarkbc5697d2017-10-04 14:31:33 -04004107##
4108
Cary Clark154beea2017-10-26 07:58:48 -04004109#SeeAlso cheapEqualTo operator==(const SkMatrix& a, const SkMatrix& b)
Cary Clarkbc5697d2017-10-04 14:31:33 -04004110
4111##
4112
4113# ------------------------------------------------------------------------------
4114
4115#Method void dump() const
4116
Cary Clarkab2621d2018-01-30 10:08:57 -05004117#Line # Sends text representation using floats to standard output. ##
Cary Clark154beea2017-10-26 07:58:48 -04004118Writes text representation of Matrix to standard output. Floating point values
4119are written with limited precision; it may not be possible to reconstruct
4120original Matrix from output.
4121
Cary Clarkbc5697d2017-10-04 14:31:33 -04004122#Example
Cary Clark154beea2017-10-26 07:58:48 -04004123 SkMatrix matrix;
4124 matrix.setRotate(45);
4125 matrix.dump();
4126 SkMatrix nearlyEqual;
4127 nearlyEqual.setAll(0.7071f, -0.7071f, 0, 0.7071f, 0.7071f, 0, 0, 0, 1);
4128 nearlyEqual.dump();
4129 SkDebugf("matrix %c= nearlyEqual\n", matrix == nearlyEqual ? '=' : '!');
4130#StdOut
4131[ 0.7071 -0.7071 0.0000][ 0.7071 0.7071 0.0000][ 0.0000 0.0000 1.0000]
4132[ 0.7071 -0.7071 0.0000][ 0.7071 0.7071 0.0000][ 0.0000 0.0000 1.0000]
4133matrix != nearlyEqual
4134##
Cary Clarkbc5697d2017-10-04 14:31:33 -04004135##
4136
Cary Clark154beea2017-10-26 07:58:48 -04004137#SeeAlso toString
Cary Clarkbc5697d2017-10-04 14:31:33 -04004138
4139##
4140
4141# ------------------------------------------------------------------------------
4142
4143#Method void toString(SkString* str) const
4144
Cary Clarkab2621d2018-01-30 10:08:57 -05004145#Line # Converts Matrix to machine readable form. ##
Cary Clark154beea2017-10-26 07:58:48 -04004146Creates string representation of Matrix. Floating point values
4147are written with limited precision; it may not be possible to reconstruct
4148original Matrix from output.
4149
4150#Param str storage for string representation of Matrix ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04004151
4152#Example
Cary Clark154beea2017-10-26 07:58:48 -04004153 SkMatrix matrix;
4154 matrix.setRotate(45);
4155 SkString mStr, neStr;
4156 matrix.toString(&mStr);
4157 SkMatrix nearlyEqual;
4158 nearlyEqual.setAll(0.7071f, -0.7071f, 0, 0.7071f, 0.7071f, 0, 0, 0, 1);
4159 nearlyEqual.toString(&neStr);
4160 SkDebugf("mStr %s\n", mStr.c_str());
4161 SkDebugf("neStr %s\n", neStr.c_str());
4162 SkDebugf("matrix %c= nearlyEqual\n", matrix == nearlyEqual ? '=' : '!');
4163#StdOut
4164mStr [ 0.7071 -0.7071 0.0000][ 0.7071 0.7071 0.0000][ 0.0000 0.0000 1.0000]
4165neStr [ 0.7071 -0.7071 0.0000][ 0.7071 0.7071 0.0000][ 0.0000 0.0000 1.0000]
4166matrix != nearlyEqual
4167##
Cary Clarkbc5697d2017-10-04 14:31:33 -04004168##
4169
Cary Clark154beea2017-10-26 07:58:48 -04004170#SeeAlso dump
Cary Clarkbc5697d2017-10-04 14:31:33 -04004171
4172##
4173
4174# ------------------------------------------------------------------------------
4175
4176#Method SkScalar getMinScale() const
4177
Cary Clarkab2621d2018-01-30 10:08:57 -05004178#Line # Returns minimum scaling, if possible. ##
Cary Clark154beea2017-10-26 07:58:48 -04004179Returns the minimum scaling factor of Matrix by decomposing the scaling and
4180skewing elements.
4181Returns -1 if scale factor overflows or Matrix contains perspective.
Cary Clarkbc5697d2017-10-04 14:31:33 -04004182
4183#Return minimum scale factor
4184##
4185
4186#Example
Cary Clark154beea2017-10-26 07:58:48 -04004187 SkMatrix matrix;
4188 matrix.setScale(42, 24);
4189 SkDebugf("matrix.getMinScale() %g\n", matrix.getMinScale());
4190#StdOut
4191matrix.getMinScale() 24
4192##
Cary Clarkbc5697d2017-10-04 14:31:33 -04004193##
4194
Cary Clark154beea2017-10-26 07:58:48 -04004195#SeeAlso getMaxScale getMinMaxScales
Cary Clarkbc5697d2017-10-04 14:31:33 -04004196
4197##
4198
4199# ------------------------------------------------------------------------------
4200
4201#Method SkScalar getMaxScale() const
4202
Cary Clarkab2621d2018-01-30 10:08:57 -05004203#Line # Returns maximum scaling, if possible. ##
Cary Clark154beea2017-10-26 07:58:48 -04004204Returns the maximum scaling factor of Matrix by decomposing the scaling and
4205skewing elements.
4206Returns -1 if scale factor overflows or Matrix contains perspective.
Cary Clarkbc5697d2017-10-04 14:31:33 -04004207
4208#Return maximum scale factor
4209##
4210
4211#Example
Cary Clark154beea2017-10-26 07:58:48 -04004212 SkMatrix matrix;
4213 matrix.setScale(42, 24);
4214 SkDebugf("matrix.getMaxScale() %g\n", matrix.getMaxScale());
4215#StdOut
4216matrix.getMaxScale() 42
4217##
Cary Clarkbc5697d2017-10-04 14:31:33 -04004218##
4219
Cary Clark154beea2017-10-26 07:58:48 -04004220#SeeAlso getMinScale getMinMaxScales
Cary Clarkbc5697d2017-10-04 14:31:33 -04004221
4222##
4223
4224# ------------------------------------------------------------------------------
4225
4226#Method bool SK_WARN_UNUSED_RESULT getMinMaxScales(SkScalar scaleFactors[2]) const
4227
Cary Clarkab2621d2018-01-30 10:08:57 -05004228#Line # Returns minimum and maximum scaling, if possible. ##
Cary Clark154beea2017-10-26 07:58:48 -04004229Sets scaleFactors[0] to the minimum scaling factor, and scaleFactors[1] to the
4230maximum scaling factor. Scaling factors are computed by decomposing
4231the Matrix scaling and skewing elements.
Cary Clarkbc5697d2017-10-04 14:31:33 -04004232
Cary Clark154beea2017-10-26 07:58:48 -04004233Returns true if scaleFactors are found; otherwise, returns false and sets
4234scaleFactors to undefined values.
Cary Clarkbc5697d2017-10-04 14:31:33 -04004235
Cary Clark154beea2017-10-26 07:58:48 -04004236#Param scaleFactors storage for minimum and maximum scale factors ##
4237
4238#Return true if scale factors were computed correctly ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04004239
4240#Example
Cary Clark154beea2017-10-26 07:58:48 -04004241 SkMatrix matrix;
4242 matrix.setAll(1, 0, 0, 0, 1, 0, 0, 0, 0);
4243 matrix.invert(&matrix);
4244 SkScalar factor[2] = {2, 2};
4245 bool result = matrix.getMinMaxScales(factor);
4246 SkDebugf("matrix.getMinMaxScales() %s %g %g\n", result ? "true" : "false", factor[0], factor[1]);
4247#StdOut
4248matrix.getMinMaxScales() false 2 2
4249##
Cary Clarkbc5697d2017-10-04 14:31:33 -04004250##
4251
Cary Clark154beea2017-10-26 07:58:48 -04004252#SeeAlso getMinScale getMaxScale
Cary Clarkbc5697d2017-10-04 14:31:33 -04004253
4254##
4255
4256# ------------------------------------------------------------------------------
4257
4258#Method bool decomposeScale(SkSize* scale, SkMatrix* remaining = nullptr) const
4259
Cary Clarkab2621d2018-01-30 10:08:57 -05004260#Line # Separates scale if possible. ##
Cary Clark154beea2017-10-26 07:58:48 -04004261Decomposes Matrix into scale components and whatever remains. Returns false if
4262Matrix could not be decomposed.
4263
4264Sets scale to portion of Matrix that scales in x and y. Sets remaining to Matrix
4265with x and y scaling factored out. remaining may be passed as nullptr
4266to determine if Matrix can be decomposed without computing remainder.
4267
4268Returns true if scale components are found. scale and remaining are
4269unchanged if Matrix contains perspective; scale factors are not finite, or
4270are nearly zero.
4271
4272On success
4273
Cary Clarkbc5697d2017-10-04 14:31:33 -04004274#Formula
Cary Clark154beea2017-10-26 07:58:48 -04004275Matrix = scale * Remaining
Cary Clarkbc5697d2017-10-04 14:31:33 -04004276##
Cary Clarkbc5697d2017-10-04 14:31:33 -04004277
Cary Clark154beea2017-10-26 07:58:48 -04004278#Param scale x and y scaling factors; may be nullptr ##
4279#Param remaining Matrix without scaling; may be nullptr ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04004280
Cary Clark154beea2017-10-26 07:58:48 -04004281#Return true if scale can be computed ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04004282
4283#Example
Cary Clark154beea2017-10-26 07:58:48 -04004284 SkMatrix matrix;
4285 matrix.setRotate(90 * SK_Scalar1);
4286 matrix.postScale(1.f / 4, 1.f / 2);
4287 matrix.dump();
4288 SkSize scale = {SK_ScalarNaN, SK_ScalarNaN};
4289 SkMatrix remaining;
4290 remaining.reset();
4291 bool success = matrix.decomposeScale(&scale, &remaining);
4292 SkDebugf("success: %s ", success ? "true" : "false");
4293 SkDebugf("scale: %g, %g\n", scale.width(), scale.height());
4294 remaining.dump();
4295 SkMatrix scaleMatrix = SkMatrix::MakeScale(scale.width(), scale.height());
4296 SkMatrix combined = SkMatrix::Concat(scaleMatrix, remaining);
4297 combined.dump();
4298#StdOut
4299[ 0.0000 -0.2500 0.0000][ 0.5000 0.0000 0.0000][ 0.0000 0.0000 1.0000]
4300success: true scale: 0.5, 0.25
4301[ 0.0000 -0.5000 0.0000][ 2.0000 0.0000 0.0000][ 0.0000 0.0000 1.0000]
4302[ 0.0000 -0.2500 0.0000][ 0.5000 0.0000 0.0000][ 0.0000 0.0000 1.0000]
4303##
Cary Clarkbc5697d2017-10-04 14:31:33 -04004304##
4305
Cary Clark154beea2017-10-26 07:58:48 -04004306#SeeAlso setScale MakeScale
Cary Clarkbc5697d2017-10-04 14:31:33 -04004307
4308##
4309
4310# ------------------------------------------------------------------------------
4311
4312#Method static const SkMatrix& I()
4313
Cary Clarkab2621d2018-01-30 10:08:57 -05004314#Line # Returns a reference to a const identity Matrix. ##
Cary Clark154beea2017-10-26 07:58:48 -04004315Returns reference to const identity Matrix. Returned Matrix is set to:
Cary Clarkbc5697d2017-10-04 14:31:33 -04004316
Cary Clark154beea2017-10-26 07:58:48 -04004317#Code
4318#Literal
4319| 1 0 0 |
4320| 0 1 0 |
4321| 0 0 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -04004322##
4323
Cary Clark154beea2017-10-26 07:58:48 -04004324#Return const identity Matrix ##
4325
4326#Example
4327 SkMatrix m1, m2, m3;
4328 m1.reset();
4329 m2.setIdentity();
4330 m3 = SkMatrix::I();
4331 SkDebugf("m1 %c= m2\n", m1 == m2 ? '=' : '!');
4332 SkDebugf("m2 %c= m3\n", m1 == m2 ? '=' : '!');
4333#StdOut
4334m1 == m2
4335m2 == m3
4336##
4337##
4338
4339#SeeAlso reset() setIdentity
Cary Clarkbc5697d2017-10-04 14:31:33 -04004340
4341##
4342
4343# ------------------------------------------------------------------------------
4344
4345#Method static const SkMatrix& InvalidMatrix()
4346
Cary Clarkab2621d2018-01-30 10:08:57 -05004347#Line # Returns a reference to a const invalid Matrix. ##
Cary Clark154beea2017-10-26 07:58:48 -04004348Returns reference to a const Matrix with invalid values. Returned Matrix is set
4349to:
Cary Clarkbc5697d2017-10-04 14:31:33 -04004350
Cary Clark154beea2017-10-26 07:58:48 -04004351#Code
4352#Literal
4353| SK_ScalarMax SK_ScalarMax SK_ScalarMax |
4354| SK_ScalarMax SK_ScalarMax SK_ScalarMax |
4355| SK_ScalarMax SK_ScalarMax SK_ScalarMax |
Cary Clarkbc5697d2017-10-04 14:31:33 -04004356##
4357
Cary Clark154beea2017-10-26 07:58:48 -04004358#Return const invalid Matrix ##
4359
4360#Example
4361 SkDebugf("scaleX %g\n", SkMatrix::InvalidMatrix().getScaleX());
4362#StdOut
4363scaleX 3.40282e+38
4364##
4365##
4366
4367#SeeAlso SeeAlso getType
Cary Clarkbc5697d2017-10-04 14:31:33 -04004368
4369##
4370
4371# ------------------------------------------------------------------------------
4372
4373#Method static SkMatrix Concat(const SkMatrix& a, const SkMatrix& b)
4374
Cary Clarkab2621d2018-01-30 10:08:57 -05004375#Line # Returns the concatenation of Matrix pair. ##
Cary Clark154beea2017-10-26 07:58:48 -04004376Returns Matrix a multiplied by Matrix b.
Cary Clarkbc5697d2017-10-04 14:31:33 -04004377
Cary Clark154beea2017-10-26 07:58:48 -04004378Given:
Cary Clarkbc5697d2017-10-04 14:31:33 -04004379
Cary Clark154beea2017-10-26 07:58:48 -04004380#Code
4381#Literal
4382 | A B C | | J K L |
4383a = | D E F |, b = | M N O |
4384 | G H I | | P Q R |
Cary Clarkbc5697d2017-10-04 14:31:33 -04004385##
4386
Cary Clark154beea2017-10-26 07:58:48 -04004387sets Matrix to:
4388
4389#Code
4390#Literal
4391 | A B C | | J K L | | AJ+BM+CP AK+BN+CQ AL+BO+CR |
4392a * b = | D E F | * | M N O | = | DJ+EM+FP DK+EN+FQ DL+EO+FR |
4393 | G H I | | P Q R | | GJ+HM+IP GK+HN+IQ GL+HO+IR |
4394##
4395
4396#Param a Matrix on left side of multiply expression ##
4397#Param b Matrix on right side of multiply expression ##
4398
4399#Return Matrix computed from a times b ##
4400
4401#Example
4402#Height 64
4403#Image 4
4404#Description
4405setPolyToPoly creates perspective matrices, one the inverse of the other.
4406Multiplying the matrix by its inverse turns into an identity matrix.
4407##
4408SkMatrix matrix, matrix2;
4409SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}};
4410SkRect::Make(source.bounds()).toQuad(bitmapBounds);
4411matrix.setPolyToPoly(bitmapBounds, perspect, 4);
4412matrix2.setPolyToPoly(perspect, bitmapBounds, 4);
4413SkMatrix concat = SkMatrix::Concat(matrix, matrix2);
4414canvas->concat(concat);
4415canvas->drawBitmap(source, 0, 0);
4416##
4417
4418#SeeAlso preConcat postConcat
Cary Clarkbc5697d2017-10-04 14:31:33 -04004419
4420##
4421
4422# ------------------------------------------------------------------------------
4423
4424#Method void dirtyMatrixTypeCache()
4425
Cary Clarkab2621d2018-01-30 10:08:57 -05004426#Line # Sets internal cache to unknown state. ##
Cary Clark154beea2017-10-26 07:58:48 -04004427Sets internal cache to unknown state. Use to force update after repeated
4428modifications to Matrix element reference returned by operator[](int index).
Cary Clarkbc5697d2017-10-04 14:31:33 -04004429
4430#Example
Cary Clark154beea2017-10-26 07:58:48 -04004431SkMatrix matrix;
4432matrix.setIdentity();
4433SkDebugf("with identity matrix: x = %g\n", matrix.mapXY(24, 42).fX);
4434SkScalar& skewRef = matrix[SkMatrix::kMSkewX];
4435skewRef = 0;
4436SkDebugf("after skew x mod: x = %g\n", matrix.mapXY(24, 42).fX);
4437skewRef = 1;
4438SkDebugf("after 2nd skew x mod: x = %g\n", matrix.mapXY(24, 42).fX);
4439matrix.dirtyMatrixTypeCache();
4440SkDebugf("after dirty cache: x = %g\n", matrix.mapXY(24, 42).fX);
4441#StdOut
4442with identity matrix: x = 24
4443after skew x mod: x = 24
4444after 2nd skew x mod: x = 24
4445after dirty cache: x = 66
4446##
Cary Clarkbc5697d2017-10-04 14:31:33 -04004447##
4448
Cary Clark154beea2017-10-26 07:58:48 -04004449#SeeAlso operator[](int index) getType
Cary Clarkbc5697d2017-10-04 14:31:33 -04004450
4451##
4452
4453# ------------------------------------------------------------------------------
4454
4455#Method void setScaleTranslate(SkScalar sx, SkScalar sy, SkScalar tx, SkScalar ty)
4456
Cary Clarkab2621d2018-01-30 10:08:57 -05004457#Line # Sets to scale and translate. ##
Cary Clark154beea2017-10-26 07:58:48 -04004458Initializes Matrix with scale and translate elements.
Cary Clarkbc5697d2017-10-04 14:31:33 -04004459
Cary Clark154beea2017-10-26 07:58:48 -04004460#Code
4461#Literal
4462| sx 0 tx |
4463| 0 sy ty |
4464| 0 0 1 |
Cary Clarkbc5697d2017-10-04 14:31:33 -04004465##
4466
Cary Clark154beea2017-10-26 07:58:48 -04004467#Param sx horizontal scale factor to store ##
4468#Param sy vertical scale factor to store ##
4469#Param tx horizontal translation to store ##
4470#Param ty vertical translation to store ##
4471
4472#Example
4473SkMatrix matrix;
4474matrix.setScaleTranslate(1, 2, 3, 4);
4475matrix.dump();
4476#StdOut
4477[ 1.0000 0.0000 3.0000][ 0.0000 2.0000 4.0000][ 0.0000 0.0000 1.0000]
4478##
4479##
4480
4481#SeeAlso setScale preTranslate postTranslate
Cary Clarkbc5697d2017-10-04 14:31:33 -04004482
4483##
4484
4485# ------------------------------------------------------------------------------
4486
4487#Method bool isFinite() const
4488
Cary Clarkab2621d2018-01-30 10:08:57 -05004489#Line # Returns if all Matrix values are not infinity, NaN. ##
Cary Clark154beea2017-10-26 07:58:48 -04004490Returns true if all elements of the matrix are finite. Returns false if any
4491element is infinity, or NaN.
Cary Clarkbc5697d2017-10-04 14:31:33 -04004492
Cary Clark154beea2017-10-26 07:58:48 -04004493#Return true if matrix has only finite elements ##
Cary Clarkbc5697d2017-10-04 14:31:33 -04004494
4495#Example
Cary Clark154beea2017-10-26 07:58:48 -04004496SkMatrix matrix = SkMatrix::MakeTrans(SK_ScalarNaN, 0);
4497matrix.dump();
4498SkDebugf("matrix is finite: %s\n", matrix.isFinite() ? "true" : "false");
4499SkDebugf("matrix %c= matrix\n", matrix == matrix ? '=' : '!');
4500#StdOut
4501[ 1.0000 0.0000 nan][ 0.0000 1.0000 0.0000][ 0.0000 0.0000 1.0000]
4502matrix is finite: false
4503matrix != matrix
4504##
Cary Clarkbc5697d2017-10-04 14:31:33 -04004505##
4506
Cary Clark154beea2017-10-26 07:58:48 -04004507#SeeAlso operator==
Cary Clarkbc5697d2017-10-04 14:31:33 -04004508
4509##
4510
4511#Class SkMatrix ##
4512
4513#Topic Matrix ##