Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1 | #Topic Matrix |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2 | #Alias Matrices |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3 | #Alias Matrix_Reference |
| 4 | |
| 5 | #Class SkMatrix |
| 6 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 7 | Matrix holds a 3x3 matrix for transforming coordinates. This allows mapping |
| 8 | Points and Vectors with translation, scaling, skewing, rotation, and |
| 9 | perspective. |
Cary Clark | 884dd7d | 2017-10-11 10:37:52 -0400 | [diff] [blame] | 10 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 11 | Matrix elements are in row major order. Matrix does not have a constructor, |
| 12 | so it must be explicitly initialized. setIdentity initializes Matrix |
| 13 | so it has no effect. setTranslate, setScale, setSkew, setRotate, set9 and setAll |
| 14 | initializes all Matrix elements with the corresponding mapping. |
Cary Clark | 884dd7d | 2017-10-11 10:37:52 -0400 | [diff] [blame] | 15 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 16 | Matrix includes a hidden variable that classifies the type of matrix to |
| 17 | improve performance. Matrix is not thread safe unless getType is called first. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 18 | |
| 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 Clark | 5081eed | 2018-01-22 07:55:48 -0500 | [diff] [blame] | 30 | #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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 42 | #Subtopic Operators |
| 43 | #Table |
| 44 | #Legend |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 45 | # function # description ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 46 | #Legend ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 47 | # 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 Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 49 | # operator[](int index) # Returns writable reference to Matrix value. ## |
Cary Clark | 5081eed | 2018-01-22 07:55:48 -0500 | [diff] [blame] | 50 | # operator[](int index)_const # Returns Matrix value. ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 51 | #Table ## |
| 52 | #Subtopic ## |
| 53 | |
| 54 | #Subtopic Member_Functions |
| 55 | #Table |
| 56 | #Legend |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 57 | # function # description ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 58 | #Legend ## |
Cary Clark | 884dd7d | 2017-10-11 10:37:52 -0400 | [diff] [blame] | 59 | # Concat # Returns the concatenation of Matrix pair. ## |
Cary Clark | 884dd7d | 2017-10-11 10:37:52 -0400 | [diff] [blame] | 60 | # I # Returns a reference to a const identity Matrix. ## |
| 61 | # InvalidMatrix # Returns a reference to a const invalid Matrix. ## |
Cary Clark | bef063a | 2017-10-31 15:44:45 -0400 | [diff] [blame] | 62 | # MakeAll # Constructs all nine values. ## |
Cary Clark | 884dd7d | 2017-10-11 10:37:52 -0400 | [diff] [blame] | 63 | # 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 Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 66 | # SetAffineIdentity # Sets 3x2 array to identity. ## |
| 67 | # asAffine # Copies to 3x2 array. ## |
Cary Clark | 884dd7d | 2017-10-11 10:37:52 -0400 | [diff] [blame] | 68 | # cheapEqualTo # Compares Matrix pair using memcmp(). ## |
| 69 | # decomposeScale # Separates scale if possible. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 70 | # dirtyMatrixTypeCache # Sets internal cache to unknown state. ## |
| 71 | # dump() # Sends text representation using floats to standard output. ## |
Cary Clark | 884dd7d | 2017-10-11 10:37:52 -0400 | [diff] [blame] | 72 | # fixedStepInX # Returns step in x for a position in y. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 73 | # get() # Returns one of nine Matrix values. ## |
Cary Clark | 884dd7d | 2017-10-11 10:37:52 -0400 | [diff] [blame] | 74 | # get9 # Returns all nine Matrix values. ## |
Cary Clark | 884dd7d | 2017-10-11 10:37:52 -0400 | [diff] [blame] | 75 | # getMaxScale # Returns maximum scaling, if possible. ## |
| 76 | # getMinMaxScales # Returns minimum and maximum scaling, if possible. ## |
| 77 | # getMinScale # Returns minimum scaling, if possible. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 78 | # getPerspX # Returns input x perspective factor. ## |
| 79 | # getPerspY # Returns input y perspective factor. ## |
Cary Clark | 884dd7d | 2017-10-11 10:37:52 -0400 | [diff] [blame] | 80 | # getScaleX # Returns horizontal scale factor. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 81 | # getScaleY # Returns vertical scale factor. ## |
Cary Clark | 884dd7d | 2017-10-11 10:37:52 -0400 | [diff] [blame] | 82 | # getSkewX # Returns horizontal skew factor. ## |
| 83 | # getSkewY # Returns vertical skew factor. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 84 | # getTranslateX # Returns horizontal translation. ## |
| 85 | # getTranslateY # Returns vertical translation. ## |
Cary Clark | 884dd7d | 2017-10-11 10:37:52 -0400 | [diff] [blame] | 86 | # getType # Returns transform complexity. ## |
| 87 | # hasPerspective # Returns if transform includes perspective. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 88 | # invert() # Returns inverse, if possible. ## |
Cary Clark | 884dd7d | 2017-10-11 10:37:52 -0400 | [diff] [blame] | 89 | # 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 Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 95 | # mapHomogeneousPoints # Maps Point3 array. ## |
| 96 | # mapPoints # Maps Point array. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 97 | # 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 143 | #Table ## |
| 144 | #Subtopic ## |
| 145 | |
| 146 | #Topic ## |
| 147 | |
| 148 | # ------------------------------------------------------------------------------ |
| 149 | |
| 150 | #Method static SkMatrix SK_WARN_UNUSED_RESULT MakeScale(SkScalar sx, SkScalar sy) |
| 151 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 152 | #Line # Constructs from scale in x and y. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 153 | Sets Matrix to scale by (sx, sy). Returned matrix is: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 154 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 155 | #Code |
| 156 | #Literal |
| 157 | | sx 0 0 | |
| 158 | | 0 sy 0 | |
| 159 | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 160 | ## |
| 161 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 162 | #Param sx horizontal scale factor ## |
| 163 | #Param sy vertical scale factor ## |
| 164 | |
| 165 | #Return Matrix with scale ## |
| 166 | |
| 167 | #Example |
| 168 | #Image 4 |
| 169 | canvas->concat(SkMatrix::MakeScale(4, 3)); |
| 170 | canvas->drawBitmap(source, 0, 0); |
| 171 | ## |
| 172 | |
| 173 | #SeeAlso setScale postScale preScale |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 174 | |
| 175 | ## |
| 176 | |
| 177 | # ------------------------------------------------------------------------------ |
| 178 | |
| 179 | #Method static SkMatrix SK_WARN_UNUSED_RESULT MakeScale(SkScalar scale) |
| 180 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 181 | Sets Matrix to scale by (scale, scale). Returned matrix is: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 182 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 183 | #Code |
| 184 | #Literal |
| 185 | | scale 0 0 | |
| 186 | | 0 scale 0 | |
| 187 | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 188 | ## |
| 189 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 190 | #Param scale horizontal and vertical scale factor ## |
| 191 | |
| 192 | #Return Matrix with scale ## |
| 193 | |
| 194 | #Example |
| 195 | #Image 4 |
| 196 | canvas->concat(SkMatrix::MakeScale(4)); |
| 197 | canvas->drawBitmap(source, 0, 0); |
| 198 | ## |
| 199 | |
| 200 | #SeeAlso setScale postScale preScale |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 201 | |
| 202 | ## |
| 203 | |
| 204 | # ------------------------------------------------------------------------------ |
| 205 | |
| 206 | #Method static SkMatrix SK_WARN_UNUSED_RESULT MakeTrans(SkScalar dx, SkScalar dy) |
| 207 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 208 | #Line # Constructs from translate in x and y. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 209 | Sets Matrix to translate by (dx, dy). Returned matrix is: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 210 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 211 | #Code |
| 212 | #Literal |
Cary Clark | cfee6ec | 2017-10-26 10:34:05 -0400 | [diff] [blame] | 213 | | 1 0 dx | |
| 214 | | 0 1 dy | |
| 215 | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 216 | ## |
| 217 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 218 | #Param dx horizontal translation ## |
| 219 | #Param dy vertical translation ## |
| 220 | |
| 221 | #Return Matrix with translation ## |
| 222 | |
| 223 | #Example |
| 224 | #Image 4 |
| 225 | SkMatrix matrix = SkMatrix::MakeTrans(64, 48); |
| 226 | for (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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 233 | |
| 234 | ## |
| 235 | |
| 236 | # ------------------------------------------------------------------------------ |
| 237 | |
Cary Clark | bef063a | 2017-10-31 15:44:45 -0400 | [diff] [blame] | 238 | #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 Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 241 | #Line # Constructs all nine values. ## |
Cary Clark | bef063a | 2017-10-31 15:44:45 -0400 | [diff] [blame] | 242 | |
| 243 | |
| 244 | Sets 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 286 | #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 Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 298 | Enum of bit fields for mask returned by getType. |
| 299 | Used to identify the complexity of Matrix, to optimize performance. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 300 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 301 | #Const kIdentity_Mask 0 |
| 302 | all bits clear if Matrix is identity |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 303 | ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 304 | #Const kTranslate_Mask 1 |
| 305 | set if Matrix has translation |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 306 | ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 307 | #Const kScale_Mask 2 |
| 308 | set if Matrix has x or y scale |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 309 | ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 310 | #Const kAffine_Mask 4 |
| 311 | set if Matrix skews or rotates |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 312 | ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 313 | #Const kPerspective_Mask 8 |
| 314 | set if Matrix has perspective |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 315 | ## |
| 316 | |
| 317 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 318 | 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 | }; |
| 327 | SkMatrix matrix; |
| 328 | matrix.reset(); |
| 329 | debugster("reset", matrix); |
| 330 | matrix.postTranslate(1, 0); |
| 331 | debugster("postTranslate", matrix); |
| 332 | matrix.postScale(2, 1); |
| 333 | debugster("postScale", matrix); |
| 334 | matrix.postRotate(45); |
| 335 | debugster("postScale", matrix); |
| 336 | SkPoint polys[][4] = {{{0, 0}, {0, 1}, {1, 1}, {1, 0}}, {{0, 0}, {0, 1}, {2, 1}, {1, 0}}}; |
| 337 | matrix.setPolyToPoly(polys[0], polys[1], 4); |
| 338 | debugster("setPolyToPoly", matrix); |
| 339 | #StdOut |
| 340 | after reset: kIdentity_Mask |
| 341 | after postTranslate: kTranslate_Mask |
| 342 | after postScale: kTranslate_Mask kScale_Mask |
| 343 | after postScale: kTranslate_Mask kScale_Mask kAffine_Mask |
| 344 | after setPolyToPoly: kTranslate_Mask kScale_Mask kAffine_Mask kPerspective_Mask |
| 345 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 346 | ## |
| 347 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 348 | #SeeAlso getType |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 349 | |
| 350 | ## |
| 351 | |
| 352 | # ------------------------------------------------------------------------------ |
| 353 | |
| 354 | #Method TypeMask getType() const |
| 355 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 356 | #Line # Returns transform complexity. ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 357 | Returns a bit field describing the transformations the matrix may |
| 358 | perform. The bit field is computed conservatively, so it may include |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 359 | false positives. For example, when kPerspective_Mask is set, all |
| 360 | other bits are set. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 361 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 362 | #Return kIdentity_Mask, or combinations of: kTranslate_Mask, kScale_Mask, |
| 363 | kAffine_Mask, kPerspective_Mask |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 364 | ## |
| 365 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 366 | #Example |
| 367 | SkMatrix matrix; |
| 368 | matrix.setAll(1, 0, 0, 0, 1, 0, 0, 0, 1); |
| 369 | SkDebugf("identity flags hex: %0x decimal: %d\n", matrix.getType(), matrix.getType()); |
| 370 | matrix.setAll(1, 0, 0, 0, 1, 0, 0, 0, .5f); |
| 371 | SkDebugf("set all flags hex: %0x decimal: %d\n", matrix.getType(), matrix.getType()); |
| 372 | #StdOut |
| 373 | identity flags hex: 0 decimal: 0 |
| 374 | set all flags hex: f decimal: 15 |
| 375 | ## |
| 376 | ## |
| 377 | |
| 378 | #SeeAlso TypeMask |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 379 | |
| 380 | ## |
| 381 | |
| 382 | # ------------------------------------------------------------------------------ |
| 383 | |
| 384 | #Method bool isIdentity() const |
| 385 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 386 | #Line # Returns if matrix equals the identity Matrix . ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 387 | Returns true if Matrix is identity. Identity matrix is: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 388 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 389 | #Code |
| 390 | #Literal |
| 391 | | 1 0 0 | |
| 392 | | 0 1 0 | |
| 393 | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 394 | ## |
| 395 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 396 | #Return true if Matrix has no effect ## |
| 397 | |
| 398 | #Example |
| 399 | SkMatrix matrix; |
| 400 | matrix.setAll(1, 0, 0, 0, 1, 0, 0, 0, 1); |
| 401 | SkDebugf("is identity: %s\n", matrix.isIdentity() ? "true" : "false"); |
| 402 | matrix.setAll(1, 0, 0, 0, 1, 0, 0, 0, 2); |
| 403 | SkDebugf("is identity: %s\n", matrix.isIdentity() ? "true" : "false"); |
| 404 | #StdOut |
| 405 | is identity: true |
| 406 | is identity: false |
| 407 | ## |
| 408 | ## |
| 409 | |
| 410 | #SeeAlso reset() setIdentity getType |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 411 | |
| 412 | ## |
| 413 | |
| 414 | # ------------------------------------------------------------------------------ |
| 415 | |
| 416 | #Method bool isScaleTranslate() const |
| 417 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 418 | #Line # Returns if transform is limited to scale and translate. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 419 | Returns true if Matrix at most scales and translates. Matrix may be identity, |
| 420 | contain only scale elements, only translate elements, or both. Matrix form is: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 421 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 422 | #Code |
| 423 | #Literal |
| 424 | | scale-x 0 translate-x | |
| 425 | | 0 scale-y translate-y | |
| 426 | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 427 | ## |
| 428 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 429 | #Return true if Matrix is identity; or scales, translates, or both ## |
| 430 | |
| 431 | #Example |
| 432 | SkMatrix matrix; |
| 433 | for (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 |
| 440 | is scale-translate: true |
| 441 | is scale-translate: true |
| 442 | is scale-translate: true |
| 443 | is scale-translate: true |
| 444 | ## |
| 445 | ## |
| 446 | |
| 447 | #SeeAlso setScale isTranslate setTranslate getType |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 448 | |
| 449 | ## |
| 450 | |
| 451 | # ------------------------------------------------------------------------------ |
| 452 | |
| 453 | #Method bool isTranslate() const |
| 454 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 455 | #Line # Returns if transform is limited to translate. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 456 | Returns true if Matrix is identity, or translates. Matrix form is: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 457 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 458 | #Code |
| 459 | #Literal |
| 460 | | 1 0 translate-x | |
| 461 | | 0 1 translate-y | |
| 462 | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 463 | ## |
| 464 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 465 | #Return true if Matrix is identity, or translates ## |
| 466 | |
| 467 | #Example |
| 468 | SkMatrix matrix; |
| 469 | for (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 |
| 476 | is translate: true |
| 477 | is translate: true |
| 478 | is translate: false |
| 479 | is translate: false |
| 480 | ## |
| 481 | ## |
| 482 | |
| 483 | #SeeAlso setTranslate getType |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 484 | |
| 485 | ## |
| 486 | |
| 487 | # ------------------------------------------------------------------------------ |
| 488 | |
| 489 | #Method bool rectStaysRect() const |
| 490 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 491 | #Line # Returns if mapped Rect can be represented by another Rect. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 492 | Returns true Matrix maps Rect to another Rect. If true, Matrix is identity, |
| 493 | or scales, or rotates a multiple of 90 degrees, or mirrors in x or y. In all |
| 494 | cases, Matrix may also have translation. Matrix form is either: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 495 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 496 | #Code |
| 497 | #Literal |
| 498 | | scale-x 0 translate-x | |
| 499 | | 0 scale-y translate-y | |
| 500 | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 501 | ## |
| 502 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 503 | or |
| 504 | |
| 505 | #Code |
| 506 | #Literal |
| 507 | | 0 rotate-x translate-x | |
| 508 | | rotate-y 0 translate-y | |
| 509 | | 0 0 1 | |
| 510 | ## |
| 511 | |
| 512 | for non-zero values of scale-x, scale-y, rotate-x, and rotate-y. |
| 513 | |
| 514 | Also called preservesAxisAlignment; use the one that provides better inline |
| 515 | documentation. |
| 516 | |
| 517 | #Return true if Matrix maps one Rect into another ## |
| 518 | |
| 519 | #Example |
| 520 | SkMatrix matrix; |
| 521 | for (SkScalar angle: { 0, 90, 180, 270 } ) { |
| 522 | matrix.setRotate(angle); |
| 523 | SkDebugf("rectStaysRect: %s\n", matrix.rectStaysRect() ? "true" : "false"); |
| 524 | } |
| 525 | #StdOut |
| 526 | rectStaysRect: true |
| 527 | rectStaysRect: true |
| 528 | rectStaysRect: true |
| 529 | rectStaysRect: true |
| 530 | ## |
| 531 | ## |
| 532 | |
| 533 | #SeeAlso preservesAxisAlignment preservesRightAngles |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 534 | |
| 535 | ## |
| 536 | |
| 537 | # ------------------------------------------------------------------------------ |
| 538 | |
| 539 | #Method bool preservesAxisAlignment() const |
| 540 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 541 | #Line # Returns if mapping restricts to 90 degree multiples and mirroring. ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 542 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 543 | Returns true Matrix maps Rect to another Rect. If true, Matrix is identity, |
| 544 | or scales, or rotates a multiple of 90 degrees, or mirrors in x or y. In all |
| 545 | cases, Matrix may also have translation. Matrix form is either: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 546 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 547 | #Code |
| 548 | #Literal |
| 549 | | scale-x 0 translate-x | |
| 550 | | 0 scale-y translate-y | |
| 551 | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 552 | ## |
| 553 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 554 | or |
| 555 | |
| 556 | #Code |
| 557 | #Literal |
| 558 | | 0 rotate-x translate-x | |
| 559 | | rotate-y 0 translate-y | |
| 560 | | 0 0 1 | |
| 561 | ## |
| 562 | |
| 563 | for non-zero values of scale-x, scale-y, rotate-x, and rotate-y. |
| 564 | |
| 565 | Also called rectStaysRect; use the one that provides better inline |
| 566 | documentation. |
| 567 | |
| 568 | #Return true if Matrix maps one Rect into another ## |
| 569 | |
| 570 | #Example |
| 571 | SkMatrix matrix; |
| 572 | for (SkScalar angle: { 0, 90, 180, 270 } ) { |
| 573 | matrix.setRotate(angle); |
| 574 | SkDebugf("preservesAxisAlignment: %s\n", matrix.preservesAxisAlignment() ? "true" : "false"); |
| 575 | } |
| 576 | #StdOut |
| 577 | preservesAxisAlignment: true |
| 578 | preservesAxisAlignment: true |
| 579 | preservesAxisAlignment: true |
| 580 | preservesAxisAlignment: true |
| 581 | ## |
| 582 | ## |
| 583 | |
| 584 | #SeeAlso rectStaysRect preservesRightAngles |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 585 | |
| 586 | ## |
| 587 | |
| 588 | # ------------------------------------------------------------------------------ |
| 589 | |
| 590 | #Method bool hasPerspective() const |
| 591 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 592 | #Line # Returns if transform includes perspective. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 593 | Returns true if the matrix contains perspective elements. Matrix form is: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 594 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 595 | #Code |
| 596 | #Literal |
| 597 | | -- -- -- | |
| 598 | | -- -- -- | |
| 599 | | perspective-x perspective-y perspective-scale | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 600 | ## |
| 601 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 602 | where perspective-x or perspective-y is non-zero, or perspective-scale is |
| 603 | not 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 |
| 609 | SkMatrix matrix; |
| 610 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 611 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 612 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 613 | canvas->concat(matrix); |
| 614 | SkString string; |
| 615 | string.printf("hasPerspective %s", matrix.hasPerspective() ? "true" : "false"); |
| 616 | canvas->drawBitmap(source, 0, 0); |
| 617 | SkPaint paint; |
| 618 | paint.setAntiAlias(true); |
| 619 | paint.setTextSize(48); |
| 620 | canvas->drawString(string, 0, source.bounds().height() + 48, paint); |
| 621 | ## |
| 622 | |
Cary Clark | bef063a | 2017-10-31 15:44:45 -0400 | [diff] [blame] | 623 | #SeeAlso setAll set9 MakeAll |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 624 | |
| 625 | ## |
| 626 | |
| 627 | # ------------------------------------------------------------------------------ |
| 628 | |
| 629 | #Method bool isSimilarity(SkScalar tol = SK_ScalarNearlyZero) const |
| 630 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 631 | #Line # Returns if transform is limited to square scale and rotation. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 632 | Returns true if Matrix contains only translation, rotation, reflection, and |
| 633 | uniform scale. |
| 634 | Returns false if Matrix contains different scales, skewing, perspective, or |
| 635 | degenerate forms that collapse to a line or point. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 636 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 637 | Describes that the Matrix makes rendering with and without the matrix are |
| 638 | visually alike; a transformed circle remains a circle. Mathematically, this is |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 639 | referred to as similarity of a Euclidean_Space, or a similarity transformation. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 640 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 641 | Preserves 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 646 | |
| 647 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 648 | #Description |
| 649 | String is drawn four times through but only two are visible. Drawing the pair |
| 650 | with 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 673 | ## |
| 674 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 675 | #SeeAlso isScaleTranslate preservesRightAngles rectStaysRect isFixedStepInX |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 676 | |
| 677 | ## |
| 678 | |
| 679 | # ------------------------------------------------------------------------------ |
| 680 | |
| 681 | #Method bool preservesRightAngles(SkScalar tol = SK_ScalarNearlyZero) const |
| 682 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 683 | #Line # Returns if mapped 90 angle remains 90 degrees. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 684 | Returns true if Matrix contains only translation, rotation, reflection, and |
| 685 | scale. Scale may differ along rotated axes. |
| 686 | Returns false if Matrix skewing, perspective, or degenerate forms that collapse |
| 687 | to a line or point. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 688 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 689 | Preserves right angles, but not requiring that the arms of the angle |
| 690 | retain equal lengths. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 691 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 692 | #Param tol to be deprecated ## |
| 693 | |
| 694 | #Return true if Matrix only rotates, scales, translates ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 695 | |
| 696 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 697 | #Height 128 |
| 698 | #Description |
| 699 | Equal scale is both similar and preserves right angles. |
| 700 | Unequal scale is not similar but preserves right angles. |
| 701 | Skews are not similar and do not preserve right angles. |
| 702 | ## |
| 703 | SkPaint p; |
| 704 | p.setAntiAlias(true); |
| 705 | SkMatrix m; |
| 706 | int pos = 0; |
| 707 | for (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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 721 | ## |
| 722 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 723 | #SeeAlso isScaleTranslate isSimilarity rectStaysRect isFixedStepInX |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 724 | |
| 725 | ## |
| 726 | |
| 727 | # ------------------------------------------------------------------------------ |
| 728 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 729 | #Enum |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 730 | |
| 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 Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 745 | Matrix organizes its values in row order. These members correspond to |
| 746 | each value in Matrix. |
| 747 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 748 | #Const kMScaleX 0 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 749 | horizontal scale factor |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 750 | ## |
| 751 | #Const kMSkewX 1 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 752 | horizontal skew factor |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 753 | ## |
| 754 | #Const kMTransX 2 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 755 | horizontal translation |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 756 | ## |
| 757 | #Const kMSkewY 3 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 758 | vertical skew factor |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 759 | ## |
| 760 | #Const kMScaleY 4 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 761 | vertical scale factor |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 762 | ## |
| 763 | #Const kMTransY 5 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 764 | vertical translation |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 765 | ## |
| 766 | #Const kMPersp0 6 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 767 | input x perspective factor |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 768 | ## |
| 769 | #Const kMPersp1 7 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 770 | input y perspective factor |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 771 | ## |
| 772 | #Const kMPersp2 8 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 773 | perspective bias |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 774 | ## |
| 775 | |
| 776 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 777 | SkPaint black; |
| 778 | black.setAntiAlias(true); |
| 779 | black.setTextSize(48); |
| 780 | SkPaint gray = black; |
| 781 | gray.setColor(0xFF9f9f9f); |
| 782 | SkScalar offset[] = { 1.5f, 1.5f, 20, 1.5f, 1.5f, 20, .03f, .01f, 2 }; |
| 783 | for (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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 795 | ## |
| 796 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 797 | #SeeAlso get() set() |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 798 | |
| 799 | ## |
| 800 | |
| 801 | # ------------------------------------------------------------------------------ |
| 802 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 803 | #Enum |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 804 | |
| 805 | #Code |
| 806 | enum { |
| 807 | kAScaleX, |
| 808 | kASkewY, |
| 809 | kASkewX, |
| 810 | kAScaleY, |
| 811 | kATransX, |
| 812 | kATransY, |
| 813 | }; |
| 814 | ## |
| 815 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 816 | Affine arrays are in column major order to match the matrix used by |
| 817 | PDF and XPS. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 818 | |
| 819 | #Const kAScaleX 0 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 820 | horizontal scale factor |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 821 | ## |
| 822 | #Const kASkewY 1 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 823 | vertical skew factor |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 824 | ## |
| 825 | #Const kASkewX 2 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 826 | horizontal skew factor |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 827 | ## |
| 828 | #Const kAScaleY 3 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 829 | vertical scale factor |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 830 | ## |
| 831 | #Const kATransX 4 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 832 | horizontal translation |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 833 | ## |
| 834 | #Const kATransY 5 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 835 | vertical translation |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 836 | ## |
| 837 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 838 | #NoExample |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 839 | ## |
| 840 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 841 | #SeeAlso SetAffineIdentity asAffine setAffine |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 842 | |
| 843 | ## |
| 844 | |
| 845 | # ------------------------------------------------------------------------------ |
| 846 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 847 | #Method SkScalar operator[](int index)_const |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 848 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 849 | #Line # Returns Matrix value. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 850 | Returns one matrix value. Asserts if index is out of range and SK_DEBUG is |
| 851 | defined. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 852 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 853 | #Param index one of: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY, |
| 854 | kMPersp0, kMPersp1, kMPersp2 |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 855 | ## |
| 856 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 857 | #Return value corresponding to index ## |
| 858 | |
| 859 | #Example |
| 860 | SkMatrix matrix; |
| 861 | matrix.setScale(42, 24); |
| 862 | SkDebugf("matrix[SkMatrix::kMScaleX] %c= 42\n", matrix[SkMatrix::kMScaleX] == 42 ? '=' : '!'); |
| 863 | SkDebugf("matrix[SkMatrix::kMScaleY] %c= 24\n", matrix[SkMatrix::kMScaleY] == 24 ? '=' : '!'); |
| 864 | #StdOut |
| 865 | matrix[SkMatrix::kMScaleX] == 42 |
| 866 | matrix[SkMatrix::kMScaleY] == 24 |
| 867 | ## |
| 868 | ## |
| 869 | |
| 870 | #SeeAlso get set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 871 | |
| 872 | ## |
| 873 | |
| 874 | # ------------------------------------------------------------------------------ |
| 875 | |
| 876 | #Method SkScalar get(int index) const |
| 877 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 878 | #Line # Returns one of nine Matrix values. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 879 | Returns one matrix value. Asserts if index is out of range and SK_DEBUG is |
| 880 | defined. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 881 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 882 | #Param index one of: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY, |
| 883 | kMPersp0, kMPersp1, kMPersp2 |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 884 | ## |
| 885 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 886 | #Return value corresponding to index ## |
| 887 | |
| 888 | #Example |
| 889 | SkMatrix matrix; |
| 890 | matrix.setSkew(42, 24); |
| 891 | SkDebugf("matrix.get(SkMatrix::kMSkewX) %c= 42\n", |
| 892 | matrix.get(SkMatrix::kMSkewX) == 42 ? '=' : '!'); |
| 893 | SkDebugf("matrix.get(SkMatrix::kMSkewY) %c= 24\n", |
| 894 | matrix.get(SkMatrix::kMSkewY) == 24 ? '=' : '!'); |
| 895 | #StdOut |
| 896 | matrix.get(SkMatrix::kMSkewX) == 42 |
| 897 | matrix.get(SkMatrix::kMSkewY) == 24 |
| 898 | ## |
| 899 | ## |
| 900 | |
| 901 | #SeeAlso operator[](int index) set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 902 | |
| 903 | ## |
| 904 | |
| 905 | # ------------------------------------------------------------------------------ |
| 906 | |
| 907 | #Method SkScalar getScaleX() const |
| 908 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 909 | #Line # Returns horizontal scale factor. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 910 | Returns scale factor multiplied by x input, contributing to x output. |
| 911 | With mapPoints, scales Points along the x-axis. |
| 912 | |
| 913 | #Return horizontal scale factor ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 914 | |
| 915 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 916 | SkMatrix matrix; |
| 917 | matrix.setScale(42, 24); |
| 918 | SkDebugf("matrix.getScaleX() %c= 42\n", matrix.getScaleX() == 42 ? '=' : '!'); |
| 919 | #StdOut |
| 920 | matrix.getScaleX() == 42 |
| 921 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 922 | ## |
| 923 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 924 | #SeeAlso get getScaleY setScaleX setScale |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 925 | |
| 926 | ## |
| 927 | |
| 928 | # ------------------------------------------------------------------------------ |
| 929 | |
| 930 | #Method SkScalar getScaleY() const |
| 931 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 932 | #Line # Returns vertical scale factor. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 933 | Returns scale factor multiplied by y input, contributing to y output. |
| 934 | With mapPoints, scales Points along the y-axis. |
| 935 | |
| 936 | #Return vertical scale factor ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 937 | |
| 938 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 939 | SkMatrix matrix; |
| 940 | matrix.setScale(42, 24); |
| 941 | SkDebugf("matrix.getScaleY() %c= 24\n", matrix.getScaleY() == 24 ? '=' : '!'); |
| 942 | #StdOut |
| 943 | matrix.getScaleY() == 24 |
| 944 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 945 | ## |
| 946 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 947 | #SeeAlso get getScaleX setScaleY setScale |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 948 | |
| 949 | ## |
| 950 | |
| 951 | # ------------------------------------------------------------------------------ |
| 952 | |
| 953 | #Method SkScalar getSkewY() const |
| 954 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 955 | #Line # Returns vertical skew factor. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 956 | Returns scale factor multiplied by x input, contributing to y output. |
| 957 | With mapPoints, skews Points along the y-axis. |
| 958 | Skew x and y together can rotate Points. |
| 959 | |
| 960 | #Return vertical skew factor ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 961 | |
| 962 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 963 | SkMatrix matrix; |
| 964 | matrix.setSkew(42, 24); |
| 965 | SkDebugf("matrix.getSkewY() %c= 24\n", matrix.getSkewY() == 24 ? '=' : '!'); |
| 966 | #StdOut |
| 967 | matrix.getSkewY() == 24 |
| 968 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 969 | ## |
| 970 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 971 | #SeeAlso get getSkewX setSkewY setSkew |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 972 | |
| 973 | ## |
| 974 | |
| 975 | # ------------------------------------------------------------------------------ |
| 976 | |
| 977 | #Method SkScalar getSkewX() const |
| 978 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 979 | #Line # Returns horizontal skew factor. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 980 | Returns scale factor multiplied by y input, contributing to x output. |
| 981 | With mapPoints, skews Points along the x-axis. |
| 982 | Skew x and y together can rotate Points. |
| 983 | |
| 984 | #Return horizontal scale factor ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 985 | |
| 986 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 987 | SkMatrix matrix; |
| 988 | matrix.setSkew(42, 24); |
| 989 | SkDebugf("matrix.getSkewX() %c= 42\n", matrix.getSkewX() == 42 ? '=' : '!'); |
| 990 | #StdOut |
| 991 | matrix.getSkewX() == 42 |
| 992 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 993 | ## |
| 994 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 995 | #SeeAlso get getSkewY setSkewX setSkew |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 996 | |
| 997 | ## |
| 998 | |
| 999 | # ------------------------------------------------------------------------------ |
| 1000 | |
| 1001 | #Method SkScalar getTranslateX() const |
| 1002 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1003 | #Line # Returns horizontal translation. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1004 | Returns translation contributing to x output. |
| 1005 | With mapPoints, moves Points along the x-axis. |
| 1006 | |
| 1007 | #Return horizontal translation factor ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1008 | |
| 1009 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1010 | SkMatrix matrix; |
| 1011 | matrix.setTranslate(42, 24); |
| 1012 | SkDebugf("matrix.getTranslateX() %c= 42\n", matrix.getTranslateX() == 42 ? '=' : '!'); |
| 1013 | #StdOut |
| 1014 | matrix.getTranslateX() == 42 |
| 1015 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1016 | ## |
| 1017 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1018 | #SeeAlso get getTranslateY setTranslateX setTranslate |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1019 | |
| 1020 | ## |
| 1021 | |
| 1022 | # ------------------------------------------------------------------------------ |
| 1023 | |
| 1024 | #Method SkScalar getTranslateY() const |
| 1025 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1026 | #Line # Returns vertical translation. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1027 | Returns translation contributing to y output. |
| 1028 | With mapPoints, moves Points along the y-axis. |
| 1029 | |
| 1030 | #Return vertical translation factor ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1031 | |
| 1032 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1033 | SkMatrix matrix; |
| 1034 | matrix.setTranslate(42, 24); |
| 1035 | SkDebugf("matrix.getTranslateY() %c= 24\n", matrix.getTranslateY() == 24 ? '=' : '!'); |
| 1036 | #StdOut |
| 1037 | matrix.getTranslateY() == 24 |
| 1038 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1039 | ## |
| 1040 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1041 | #SeeAlso get getTranslateX setTranslateY setTranslate |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1042 | |
| 1043 | ## |
| 1044 | |
| 1045 | # ------------------------------------------------------------------------------ |
| 1046 | |
| 1047 | #Method SkScalar getPerspX() const |
| 1048 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1049 | #Line # Returns input x perspective factor. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1050 | Returns factor scaling input x relative to input y. |
| 1051 | |
| 1052 | #Return input x perspective factor ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1053 | |
| 1054 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1055 | 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1070 | ## |
| 1071 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1072 | #SeeAlso kMPersp0 getPerspY |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1073 | |
| 1074 | ## |
| 1075 | |
| 1076 | # ------------------------------------------------------------------------------ |
| 1077 | |
| 1078 | #Method SkScalar getPerspY() const |
| 1079 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1080 | #Line # Returns input y perspective factor. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1081 | |
| 1082 | Returns factor scaling input y relative to input x. |
| 1083 | |
| 1084 | #Return input y perspective factor ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1085 | |
| 1086 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1087 | 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1102 | ## |
| 1103 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1104 | #SeeAlso kMPersp1 getPerspX |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1105 | |
| 1106 | ## |
| 1107 | |
| 1108 | # ------------------------------------------------------------------------------ |
| 1109 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1110 | #Method SkScalar& operator[](int index) |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1111 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1112 | #Line # Returns writable reference to Matrix value. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1113 | Returns writable Matrix value. Asserts if index is out of range and SK_DEBUG is |
| 1114 | defined. Clears internal cache anticipating that caller will change Matrix value. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1115 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1116 | Next call to read Matrix state may recompute cache; subsequent writes to Matrix |
| 1117 | value must be followed by dirtyMatrixTypeCache. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1118 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1119 | #Param index one of: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY, |
| 1120 | kMPersp0, kMPersp1, kMPersp2 |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1121 | ## |
| 1122 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1123 | #Return writable value corresponding to index ## |
| 1124 | |
| 1125 | #Example |
| 1126 | SkMatrix matrix; |
| 1127 | matrix.setIdentity(); |
| 1128 | SkDebugf("with identity matrix: x = %g\n", matrix.mapXY(24, 42).fX); |
| 1129 | SkScalar& skewRef = matrix[SkMatrix::kMSkewX]; |
| 1130 | skewRef = 0; |
| 1131 | SkDebugf("after skew x mod: x = %g\n", matrix.mapXY(24, 42).fX); |
| 1132 | skewRef = 1; |
| 1133 | SkDebugf("after 2nd skew x mod: x = %g\n", matrix.mapXY(24, 42).fX); |
| 1134 | matrix.dirtyMatrixTypeCache(); |
| 1135 | SkDebugf("after dirty cache: x = %g\n", matrix.mapXY(24, 42).fX); |
| 1136 | #StdOut |
| 1137 | with identity matrix: x = 24 |
| 1138 | after skew x mod: x = 24 |
| 1139 | after 2nd skew x mod: x = 24 |
| 1140 | after dirty cache: x = 66 |
| 1141 | ## |
| 1142 | ## |
| 1143 | |
| 1144 | #SeeAlso get dirtyMatrixTypeCache set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1145 | |
| 1146 | ## |
| 1147 | |
| 1148 | # ------------------------------------------------------------------------------ |
| 1149 | |
| 1150 | #Method void set(int index, SkScalar value) |
| 1151 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1152 | #Line # Sets one value. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1153 | Sets Matrix value. Asserts if index is out of range and SK_DEBUG is |
| 1154 | defined. 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1160 | |
| 1161 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1162 | SkMatrix matrix; |
| 1163 | matrix.setIdentity(); |
| 1164 | SkDebugf("with identity matrix: x = %g\n", matrix.mapXY(24, 42).fX); |
| 1165 | matrix.set(SkMatrix::kMSkewX, 0); |
| 1166 | SkDebugf("after skew x mod: x = %g\n", matrix.mapXY(24, 42).fX); |
| 1167 | matrix.set(SkMatrix::kMSkewX, 1); |
| 1168 | SkDebugf("after 2nd skew x mod: x = %g\n", matrix.mapXY(24, 42).fX); |
| 1169 | #StdOut |
| 1170 | with identity matrix: x = 24 |
| 1171 | after skew x mod: x = 24 |
| 1172 | after 2nd skew x mod: x = 66 |
| 1173 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1174 | ## |
| 1175 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1176 | #SeeAlso operator[] get |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1177 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1178 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1179 | |
| 1180 | # ------------------------------------------------------------------------------ |
| 1181 | |
| 1182 | #Method void setScaleX(SkScalar v) |
| 1183 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1184 | #Line # Sets horizontal scale factor. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1185 | Sets horizontal scale factor. |
| 1186 | |
| 1187 | #Param v horizontal scale factor to store ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1188 | |
| 1189 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1190 | #Height 64 |
| 1191 | SkPaint paint; |
| 1192 | paint.setAntiAlias(true); |
| 1193 | paint.setTextSize(24); |
| 1194 | canvas->drawString("normal", 12, 24, paint); |
| 1195 | SkMatrix matrix; |
| 1196 | matrix.setIdentity(); |
| 1197 | matrix.setScaleX(3); |
| 1198 | canvas->concat(matrix); |
| 1199 | canvas->drawString("x scale", 0, 48, paint); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1200 | ## |
| 1201 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1202 | #SeeAlso set setScale setScaleY |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1203 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1204 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1205 | |
| 1206 | # ------------------------------------------------------------------------------ |
| 1207 | |
| 1208 | #Method void setScaleY(SkScalar v) |
| 1209 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1210 | #Line # Sets vertical scale factor ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1211 | Sets vertical scale factor. |
| 1212 | |
| 1213 | #Param v vertical scale factor to store ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1214 | |
| 1215 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1216 | #Height 192 |
| 1217 | SkPaint paint; |
| 1218 | paint.setAntiAlias(true); |
| 1219 | paint.setTextSize(24); |
| 1220 | canvas->drawString("normal", 12, 24, paint); |
| 1221 | SkMatrix matrix; |
| 1222 | matrix.setIdentity(); |
| 1223 | matrix.setScaleY(3); |
| 1224 | canvas->concat(matrix); |
| 1225 | canvas->drawString("y scale", 12, 48, paint); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1226 | ## |
| 1227 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1228 | #SeeAlso set setScale setScaleX |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1229 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1230 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1231 | |
| 1232 | # ------------------------------------------------------------------------------ |
| 1233 | |
| 1234 | #Method void setSkewY(SkScalar v) |
| 1235 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1236 | #Line # Sets vertical skew factor. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1237 | Sets vertical skew factor. |
| 1238 | |
| 1239 | #Param v vertical skew factor to store ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1240 | |
| 1241 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1242 | #Height 96 |
| 1243 | SkPaint paint; |
| 1244 | paint.setAntiAlias(true); |
| 1245 | paint.setTextSize(24); |
| 1246 | canvas->drawString("normal", 12, 24, paint); |
| 1247 | SkMatrix matrix; |
| 1248 | matrix.setIdentity(); |
| 1249 | matrix.setSkewY(.3f); |
| 1250 | canvas->concat(matrix); |
| 1251 | canvas->drawString("y skew", 12, 48, paint); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1252 | ## |
| 1253 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1254 | #SeeAlso set setSkew setSkewX |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1255 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1256 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1257 | |
| 1258 | # ------------------------------------------------------------------------------ |
| 1259 | |
| 1260 | #Method void setSkewX(SkScalar v) |
| 1261 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1262 | #Line # Sets horizontal skew factor. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1263 | Sets horizontal skew factor. |
| 1264 | |
| 1265 | #Param v horizontal skew factor to store ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1266 | |
| 1267 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1268 | #Height 64 |
| 1269 | SkPaint paint; |
| 1270 | paint.setAntiAlias(true); |
| 1271 | paint.setTextSize(24); |
| 1272 | canvas->drawString("normal", 12, 24, paint); |
| 1273 | SkMatrix matrix; |
| 1274 | matrix.setIdentity(); |
| 1275 | matrix.setSkewX(-.7f); |
| 1276 | canvas->concat(matrix); |
| 1277 | canvas->drawString("x skew", 36, 48, paint); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1278 | ## |
| 1279 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1280 | #SeeAlso set setSkew setSkewX |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1281 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1282 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1283 | |
| 1284 | # ------------------------------------------------------------------------------ |
| 1285 | |
| 1286 | #Method void setTranslateX(SkScalar v) |
| 1287 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1288 | #Line # Sets horizontal translation. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1289 | Sets horizontal translation. |
| 1290 | |
| 1291 | #Param v horizontal translation to store ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1292 | |
| 1293 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1294 | #Height 48 |
| 1295 | SkPaint paint; |
| 1296 | paint.setAntiAlias(true); |
| 1297 | paint.setTextSize(24); |
| 1298 | canvas->drawString("normal", 8, 24, paint); |
| 1299 | SkMatrix matrix; |
| 1300 | matrix.setIdentity(); |
| 1301 | matrix.setTranslateX(96); |
| 1302 | canvas->concat(matrix); |
| 1303 | canvas->drawString("x translate", 8, 24, paint); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1304 | ## |
| 1305 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1306 | #SeeAlso set setTranslate setTranslateY |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1307 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1308 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1309 | |
| 1310 | # ------------------------------------------------------------------------------ |
| 1311 | |
| 1312 | #Method void setTranslateY(SkScalar v) |
| 1313 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1314 | #Line # Sets vertical translation. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1315 | Sets vertical translation. |
| 1316 | |
| 1317 | #Param v vertical translation to store ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1318 | |
| 1319 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1320 | #Height 64 |
| 1321 | SkPaint paint; |
| 1322 | paint.setAntiAlias(true); |
| 1323 | paint.setTextSize(24); |
| 1324 | canvas->drawString("normal", 8, 24, paint); |
| 1325 | SkMatrix matrix; |
| 1326 | matrix.setIdentity(); |
| 1327 | matrix.setTranslateY(24); |
| 1328 | canvas->concat(matrix); |
| 1329 | canvas->drawString("y translate", 8, 24, paint); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1330 | ## |
| 1331 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1332 | #SeeAlso set setTranslate setTranslateX |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1333 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1334 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1335 | |
| 1336 | # ------------------------------------------------------------------------------ |
| 1337 | |
| 1338 | #Method void setPerspX(SkScalar v) |
| 1339 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1340 | #Line # Sets input x perspective factor. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1341 | Sets input x perspective factor, which causes mapXY to vary input x inversely |
| 1342 | proportional to input y. |
| 1343 | |
| 1344 | #Param v perspective factor ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1345 | |
| 1346 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1347 | #Image 4 |
| 1348 | for (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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1358 | ## |
| 1359 | |
Cary Clark | bef063a | 2017-10-31 15:44:45 -0400 | [diff] [blame] | 1360 | #SeeAlso getPerspX set setAll set9 MakeAll |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1361 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1362 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1363 | |
| 1364 | # ------------------------------------------------------------------------------ |
| 1365 | |
| 1366 | #Method void setPerspY(SkScalar v) |
| 1367 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1368 | #Line # Sets input y perspective factor. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1369 | Sets input y perspective factor, which causes mapXY to vary input y inversely |
| 1370 | proportional to input x. |
| 1371 | |
| 1372 | #Param v perspective factor ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1373 | |
| 1374 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1375 | #Image 4 |
| 1376 | for (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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1386 | ## |
| 1387 | |
Cary Clark | bef063a | 2017-10-31 15:44:45 -0400 | [diff] [blame] | 1388 | #SeeAlso getPerspY set setAll set9 MakeAll |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1389 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1390 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1391 | |
| 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 Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1397 | #Line # Sets all values from parameters. ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1398 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1399 | Sets 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1417 | |
| 1418 | #Example |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1419 | #Height 128 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1420 | 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 Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1427 | m.setAll(sx, 1, 128, 0, sy, 64, 0, 0, 1); |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1428 | canvas->concat(m); |
| 1429 | canvas->drawString("K", 0, 0, p); |
| 1430 | } |
| 1431 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1432 | ## |
| 1433 | |
Cary Clark | bef063a | 2017-10-31 15:44:45 -0400 | [diff] [blame] | 1434 | #SeeAlso set9 MakeAll |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1435 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1436 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1437 | |
| 1438 | # ------------------------------------------------------------------------------ |
| 1439 | |
| 1440 | #Method void get9(SkScalar buffer[9]) const |
| 1441 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1442 | #Line # Returns all nine Matrix values. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1443 | Copies nine Scalar values contained by Matrix into buffer, in member value |
| 1444 | ascending order: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY, |
| 1445 | kMPersp0, kMPersp1, kMPersp2. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1446 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1447 | #Param buffer storage for nine Scalar values ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1448 | |
| 1449 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1450 | SkMatrix matrix = SkMatrix::MakeRectToRect({0, 0, 1, 1}, {3, 4, 7, 9}, |
| 1451 | SkMatrix::kFill_ScaleToFit); |
| 1452 | SkScalar b[9]; |
| 1453 | matrix.get9(b); |
| 1454 | SkDebugf("{%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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1461 | ## |
| 1462 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1463 | #SeeAlso set9 |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1464 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1465 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1466 | |
| 1467 | # ------------------------------------------------------------------------------ |
| 1468 | |
| 1469 | #Method void set9(const SkScalar buffer[9]) |
| 1470 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1471 | #Line # Sets all values from Scalar array. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1472 | Sets Matrix to nine Scalar values in buffer, in member value ascending order: |
| 1473 | kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY, kMPersp0, kMPersp1, |
| 1474 | kMPersp2. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1475 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1476 | Sets matrix to: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1477 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1478 | #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 | |
| 1485 | In the future, set9 followed by get9 may not return the same values. Since Matrix |
| 1486 | maps non-homogeneous coordinates, scaling all nine values produces an equivalent |
| 1487 | transformation, possibly improving precision. |
| 1488 | |
| 1489 | #Param buffer nine Scalar values ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1490 | |
| 1491 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1492 | #Image 4 |
| 1493 | SkMatrix m; |
| 1494 | SkScalar buffer[9] = {4, 0, 3, 0, 5, 4, 0, 0, 1}; |
| 1495 | m.set9(buffer); |
| 1496 | canvas->concat(m); |
| 1497 | canvas->drawBitmap(source, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1498 | ## |
| 1499 | |
Cary Clark | bef063a | 2017-10-31 15:44:45 -0400 | [diff] [blame] | 1500 | #SeeAlso setAll get9 MakeAll |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1501 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1502 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1503 | |
| 1504 | # ------------------------------------------------------------------------------ |
| 1505 | |
| 1506 | #Method void reset() |
| 1507 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1508 | #Line # Sets Matrix to identity. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1509 | Sets 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 | |
| 1518 | Also called setIdentity(); use the one that provides better inline |
| 1519 | documentation. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1520 | |
| 1521 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1522 | SkMatrix m; |
| 1523 | m.reset(); |
| 1524 | SkDebugf("m.isIdentity(): %s\n", m.isIdentity() ? "true" : "false"); |
| 1525 | #StdOut |
| 1526 | m.isIdentity(): true |
| 1527 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1528 | ## |
| 1529 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1530 | #SeeAlso isIdentity setIdentity |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1531 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1532 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1533 | |
| 1534 | # ------------------------------------------------------------------------------ |
| 1535 | |
| 1536 | #Method void setIdentity() |
| 1537 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1538 | #Line # Sets Matrix to identity. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1539 | Sets 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 | |
| 1548 | Also called reset(); use the one that provides better inline |
| 1549 | documentation. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1550 | |
| 1551 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1552 | SkMatrix m; |
| 1553 | m.setIdentity(); |
| 1554 | SkDebugf("m.isIdentity(): %s\n", m.isIdentity() ? "true" : "false"); |
| 1555 | #StdOut |
| 1556 | m.isIdentity(): true |
| 1557 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1558 | ## |
| 1559 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1560 | #SeeAlso isIdentity reset |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1561 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1562 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1563 | |
| 1564 | # ------------------------------------------------------------------------------ |
| 1565 | |
| 1566 | #Method void setTranslate(SkScalar dx, SkScalar dy) |
| 1567 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1568 | #Line # Sets to translate in x and y. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1569 | Sets Matrix to translate by (dx, dy). |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1570 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1571 | #Param dx horizontal translation ## |
| 1572 | #Param dy vertical translation ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1573 | |
| 1574 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1575 | #Height 64 |
| 1576 | SkPaint paint; |
| 1577 | paint.setAntiAlias(true); |
| 1578 | paint.setTextSize(24); |
| 1579 | canvas->drawString("normal", 8, 24, paint); |
| 1580 | SkMatrix matrix; |
| 1581 | matrix.setTranslate(96, 24); |
| 1582 | canvas->concat(matrix); |
| 1583 | canvas->drawString("translate", 8, 24, paint); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1584 | ## |
| 1585 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1586 | #SeeAlso setTranslateX setTranslateY |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1587 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1588 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1589 | |
| 1590 | # ------------------------------------------------------------------------------ |
| 1591 | |
| 1592 | #Method void setTranslate(const SkVector& v) |
| 1593 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1594 | Sets Matrix to translate by (v.fX, v.fY). |
| 1595 | |
| 1596 | #Param v Vector containing horizontal and vertical translation ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1597 | |
| 1598 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1599 | #Height 64 |
| 1600 | SkPaint paint; |
| 1601 | paint.setAntiAlias(true); |
| 1602 | paint.setTextSize(24); |
| 1603 | canvas->drawString("normal", 8, 24, paint); |
| 1604 | SkMatrix matrix; |
| 1605 | matrix.setTranslate({96, 24}); |
| 1606 | canvas->concat(matrix); |
| 1607 | canvas->drawString("translate", 8, 24, paint); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1608 | ## |
| 1609 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1610 | #SeeAlso setTranslateX setTranslateY MakeTrans |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1611 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1612 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1613 | |
| 1614 | # ------------------------------------------------------------------------------ |
| 1615 | |
| 1616 | #Method void setScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py) |
| 1617 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1618 | #Line # Sets to scale about a point. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1619 | Sets Matrix to scale by sx and sy, about a pivot point at (px, py). |
| 1620 | The pivot point is unchanged when mapped with Matrix. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1621 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1622 | #Param sx horizontal scale factor ## |
| 1623 | #Param sy vertical scale factor ## |
| 1624 | #Param px pivot x ## |
| 1625 | #Param py pivot y ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1626 | |
| 1627 | #Example |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1628 | #Height 128 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1629 | 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 Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1636 | m.setScale(sx, sy, 128, 64); |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1637 | canvas->concat(m); |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1638 | canvas->drawString("%", 128, 64, p); |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1639 | } |
| 1640 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1641 | ## |
| 1642 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1643 | #SeeAlso setScaleX setScaleY MakeScale preScale postScale |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1644 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1645 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1646 | |
| 1647 | # ------------------------------------------------------------------------------ |
| 1648 | |
| 1649 | #Method void setScale(SkScalar sx, SkScalar sy) |
| 1650 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1651 | Sets Matrix to scale by sx and sy about at pivot point at (0, 0). |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1652 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1653 | #Param sx horizontal scale factor ## |
| 1654 | #Param sy vertical scale factor ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1655 | |
| 1656 | #Example |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1657 | #Height 128 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1658 | 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 Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1666 | m.postTranslate(128, 64); |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1667 | canvas->concat(m); |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1668 | canvas->drawString("@", 0, 0, p); |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1669 | } |
| 1670 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1671 | ## |
| 1672 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1673 | #SeeAlso setScaleX setScaleY MakeScale preScale postScale |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1674 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1675 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1676 | |
| 1677 | # ------------------------------------------------------------------------------ |
| 1678 | |
| 1679 | #Method void setRotate(SkScalar degrees, SkScalar px, SkScalar py) |
| 1680 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1681 | #Line # Sets to rotate about a point. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1682 | Sets Matrix to rotate by degrees about a pivot point at (px, py). |
| 1683 | The pivot point is unchanged when mapped with Matrix. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1684 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1685 | Positive 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1690 | |
| 1691 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1692 | #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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1703 | ## |
| 1704 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1705 | #SeeAlso setSinCos preRotate postRotate |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1706 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1707 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1708 | |
| 1709 | # ------------------------------------------------------------------------------ |
| 1710 | |
| 1711 | #Method void setRotate(SkScalar degrees) |
| 1712 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1713 | Sets Matrix to rotate by degrees about a pivot point at (0, 0). |
| 1714 | Positive degrees rotates clockwise. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1715 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1716 | #Param degrees angle of axes relative to upright axes ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1717 | |
| 1718 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1719 | #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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1732 | ## |
| 1733 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1734 | #SeeAlso setSinCos preRotate postRotate |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1735 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1736 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1737 | |
| 1738 | # ------------------------------------------------------------------------------ |
| 1739 | |
| 1740 | #Method void setSinCos(SkScalar sinValue, SkScalar cosValue, |
| 1741 | SkScalar px, SkScalar py) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1742 | #Line # Sets to rotate and scale about a point. ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1743 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1744 | Sets Matrix to rotate by sinValue and cosValue, about a pivot point at (px, py). |
| 1745 | The pivot point is unchanged when mapped with Matrix. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1746 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1747 | Vector (sinValue, cosValue) describes the angle of rotation relative to (0, 1). |
| 1748 | Vector 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1754 | |
| 1755 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1756 | #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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1767 | ## |
| 1768 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1769 | #SeeAlso setRotate setScale setRSXform |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1770 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1771 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1772 | |
| 1773 | # ------------------------------------------------------------------------------ |
| 1774 | |
| 1775 | #Method void setSinCos(SkScalar sinValue, SkScalar cosValue) |
| 1776 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1777 | Sets Matrix to rotate by sinValue and cosValue, about a pivot point at (0, 0). |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1778 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1779 | Vector (sinValue, cosValue) describes the angle of rotation relative to (0, 1). |
| 1780 | Vector length specifies scale. |
| 1781 | |
| 1782 | #Param sinValue rotation vector x component ## |
| 1783 | #Param cosValue rotation vector y component ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1784 | |
| 1785 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1786 | #Description |
| 1787 | Canvas 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1802 | ## |
| 1803 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1804 | #SeeAlso setRotate setScale setRSXform |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1805 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1806 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1807 | |
| 1808 | # ------------------------------------------------------------------------------ |
| 1809 | |
| 1810 | #Method SkMatrix& setRSXform(const SkRSXform& rsxForm) |
| 1811 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1812 | #Line # Sets to rotate, scale, and translate. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1813 | Sets Matrix to rotate, scale, and translate using a compressed matrix form. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1814 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1815 | Vector (rsxForm.fSSin, rsxForm.fSCos) describes the angle of rotation relative |
| 1816 | to (0, 1). Vector length specifies scale. Mapped point is rotated and scaled |
| 1817 | by Vector, then translated by (rsxForm.fTx, rsxForm.fTy). |
| 1818 | |
| 1819 | #Param rsxForm compressed RSXform matrix ## |
| 1820 | |
| 1821 | #Return reference to Matrix ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1822 | |
| 1823 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1824 | #Description |
| 1825 | Canvas 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1839 | ## |
| 1840 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1841 | #SeeAlso setSinCos setScale setTranslate |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1842 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1843 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1844 | |
| 1845 | # ------------------------------------------------------------------------------ |
| 1846 | |
| 1847 | #Method void setSkew(SkScalar kx, SkScalar ky, SkScalar px, SkScalar py) |
| 1848 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1849 | #Line # Sets to skew about a point. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1850 | Sets Matrix to skew by kx and ky, about a pivot point at (px, py). |
| 1851 | The pivot point is unchanged when mapped with Matrix. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1852 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1853 | #Param kx horizontal skew factor ## |
| 1854 | #Param ky vertical skew factor ## |
| 1855 | #Param px pivot x ## |
| 1856 | #Param py pivot y ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1857 | |
| 1858 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1859 | 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1871 | ## |
| 1872 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1873 | #SeeAlso setSkewX setSkewY preSkew postSkew |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1874 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1875 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1876 | |
| 1877 | # ------------------------------------------------------------------------------ |
| 1878 | |
| 1879 | #Method void setSkew(SkScalar kx, SkScalar ky) |
| 1880 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1881 | Sets Matrix to skew by kx and ky, about a pivot point at (0, 0). |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1882 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1883 | #Param kx horizontal skew factor ## |
| 1884 | #Param ky vertical skew factor ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1885 | |
| 1886 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1887 | 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1900 | ## |
| 1901 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1902 | #SeeAlso setSkewX setSkewY preSkew postSkew |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1903 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1904 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1905 | |
| 1906 | # ------------------------------------------------------------------------------ |
| 1907 | |
| 1908 | #Method void setConcat(const SkMatrix& a, const SkMatrix& b) |
| 1909 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1910 | #Line # Sets to Matrix parameter multiplied by Matrix parameter. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1911 | Sets Matrix to Matrix a multiplied by Matrix b. Either a or b may be this. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1912 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1913 | Given: |
| 1914 | |
| 1915 | #Code |
| 1916 | #Literal |
| 1917 | | A B C | | J K L | |
| 1918 | a = | D E F |, b = | M N O | |
| 1919 | | G H I | | P Q R | |
| 1920 | ## |
| 1921 | |
| 1922 | sets Matrix to: |
| 1923 | |
| 1924 | #Code |
| 1925 | #Literal |
| 1926 | | A B C | | J K L | | AJ+BM+CP AK+BN+CQ AL+BO+CR | |
| 1927 | a * 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1933 | |
| 1934 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1935 | #Image 3 |
| 1936 | #Description |
| 1937 | setPolyToPoly creates perspective matrices, one the inverse of the other. |
| 1938 | Multiplying the matrix by its inverse turns into an identity matrix. |
| 1939 | ## |
| 1940 | SkMatrix matrix, matrix2; |
| 1941 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 1942 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 1943 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 1944 | matrix2.setPolyToPoly(perspect, bitmapBounds, 4); |
| 1945 | matrix.setConcat(matrix, matrix2); |
| 1946 | canvas->concat(matrix); |
| 1947 | canvas->drawBitmap(source, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1948 | ## |
| 1949 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1950 | #SeeAlso Concat preConcat postConcat SkCanvas::concat |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1951 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1952 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1953 | |
| 1954 | # ------------------------------------------------------------------------------ |
| 1955 | |
| 1956 | #Method void preTranslate(SkScalar dx, SkScalar dy) |
| 1957 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1958 | #Line # Pre-multiplies Matrix by translation. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1959 | Sets Matrix to Matrix multiplied by Matrix constructed from translation (dx, dy). |
| 1960 | This can be thought of as moving the point to be mapped before applying Matrix. |
| 1961 | |
| 1962 | Given: |
| 1963 | |
| 1964 | #Code |
| 1965 | #Literal |
| 1966 | | A B C | | 1 0 dx | |
| 1967 | Matrix = | D E F |, T(dx, dy) = | 0 1 dy | |
| 1968 | | G H I | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1969 | ## |
| 1970 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1971 | sets Matrix to: |
| 1972 | |
| 1973 | #Code |
| 1974 | #Literal |
| 1975 | | A B C | | 1 0 dx | | A B A*dx+B*dy+C | |
| 1976 | Matrix * 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1982 | |
| 1983 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1984 | #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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2005 | ## |
| 2006 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2007 | #SeeAlso postTranslate setTranslate MakeTrans |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2008 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2009 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2010 | |
| 2011 | # ------------------------------------------------------------------------------ |
| 2012 | |
| 2013 | #Method void preScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py) |
| 2014 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2015 | #Line # Pre-multiplies Matrix by scale. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2016 | Sets Matrix to Matrix multiplied by Matrix constructed from scaling by (sx, sy) |
| 2017 | about pivot point (px, py). |
| 2018 | This can be thought of as scaling about a pivot point before applying Matrix. |
| 2019 | |
| 2020 | Given: |
| 2021 | |
| 2022 | #Code |
| 2023 | #Literal |
| 2024 | | A B C | | sx 0 dx | |
| 2025 | Matrix = | D E F |, S(sx, sy, px, py) = | 0 sy dy | |
| 2026 | | G H I | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2027 | ## |
| 2028 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2029 | where |
| 2030 | |
| 2031 | #Code |
| 2032 | #Literal |
| 2033 | dx = px - sx * px |
| 2034 | dy = py - sy * py |
| 2035 | ## |
| 2036 | |
| 2037 | sets Matrix to: |
| 2038 | |
| 2039 | #Code |
| 2040 | #Literal |
| 2041 | | A B C | | sx 0 dx | | A*sx B*sy A*dx+B*dy+C | |
| 2042 | Matrix * 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2050 | |
| 2051 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2052 | #Image 3 |
| 2053 | SkMatrix matrix; |
| 2054 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 2055 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 2056 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 2057 | matrix.preScale(.75f, 1.5f, source.width() / 2, source.height() / 2); |
| 2058 | canvas->concat(matrix); |
| 2059 | canvas->drawBitmap(source, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2060 | ## |
| 2061 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2062 | #SeeAlso postScale setScale MakeScale |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2063 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2064 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2065 | |
| 2066 | # ------------------------------------------------------------------------------ |
| 2067 | |
| 2068 | #Method void preScale(SkScalar sx, SkScalar sy) |
| 2069 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2070 | Sets Matrix to Matrix multiplied by Matrix constructed from scaling by (sx, sy) |
| 2071 | about pivot point (0, 0). |
| 2072 | This can be thought of as scaling about the origin before applying Matrix. |
| 2073 | |
| 2074 | Given: |
| 2075 | |
| 2076 | #Code |
| 2077 | #Literal |
| 2078 | | A B C | | sx 0 0 | |
| 2079 | Matrix = | D E F |, S(sx, sy) = | 0 sy 0 | |
| 2080 | | G H I | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2081 | ## |
| 2082 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2083 | sets Matrix to: |
| 2084 | |
| 2085 | #Code |
| 2086 | #Literal |
| 2087 | | A B C | | sx 0 0 | | A*sx B*sy C | |
| 2088 | Matrix * 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2094 | |
| 2095 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2096 | #Image 3 |
| 2097 | SkMatrix matrix; |
| 2098 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 2099 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 2100 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 2101 | matrix.preScale(.75f, 1.5f); |
| 2102 | canvas->concat(matrix); |
| 2103 | canvas->drawBitmap(source, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2104 | ## |
| 2105 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2106 | #SeeAlso postScale setScale MakeScale |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2107 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2108 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2109 | |
| 2110 | # ------------------------------------------------------------------------------ |
| 2111 | |
| 2112 | #Method void preRotate(SkScalar degrees, SkScalar px, SkScalar py) |
| 2113 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2114 | #Line # Pre-multiplies Matrix by rotation. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2115 | Sets Matrix to Matrix multiplied by Matrix constructed from rotating by degrees |
| 2116 | about pivot point (px, py). |
| 2117 | This can be thought of as rotating about a pivot point before applying Matrix. |
| 2118 | |
| 2119 | Positive degrees rotates clockwise. |
| 2120 | |
| 2121 | Given: |
| 2122 | |
| 2123 | #Code |
| 2124 | #Literal |
| 2125 | | A B C | | c -s dx | |
| 2126 | Matrix = | D E F |, R(degrees, px, py) = | s c dy | |
| 2127 | | G H I | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2128 | ## |
| 2129 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2130 | where |
| 2131 | |
| 2132 | #Code |
| 2133 | #Literal |
| 2134 | c = cos(degrees) |
| 2135 | s = sin(degrees) |
| 2136 | dx = s * py + (1 - c) * px |
| 2137 | dy = -s * px + (1 - c) * py |
| 2138 | ## |
| 2139 | |
| 2140 | sets Matrix to: |
| 2141 | |
| 2142 | #Code |
| 2143 | #Literal |
| 2144 | | A B C | | c -s dx | | Ac+Bs -As+Bc A*dx+B*dy+C | |
| 2145 | Matrix * 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2152 | |
| 2153 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2154 | #Image 3 |
| 2155 | SkMatrix matrix; |
| 2156 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 2157 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 2158 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 2159 | matrix.preRotate(45, source.width() / 2, source.height() / 2); |
| 2160 | canvas->concat(matrix); |
| 2161 | canvas->drawBitmap(source, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2162 | ## |
| 2163 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2164 | #SeeAlso postRotate setRotate |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2165 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2166 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2167 | |
| 2168 | # ------------------------------------------------------------------------------ |
| 2169 | |
| 2170 | #Method void preRotate(SkScalar degrees) |
| 2171 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2172 | Sets Matrix to Matrix multiplied by Matrix constructed from rotating by degrees |
| 2173 | about pivot point (0, 0). |
| 2174 | This can be thought of as rotating about the origin before applying Matrix. |
| 2175 | |
| 2176 | Positive degrees rotates clockwise. |
| 2177 | |
| 2178 | Given: |
| 2179 | |
| 2180 | #Code |
| 2181 | #Literal |
| 2182 | | A B C | | c -s 0 | |
| 2183 | Matrix = | D E F |, R(degrees, px, py) = | s c 0 | |
| 2184 | | G H I | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2185 | ## |
| 2186 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2187 | where |
| 2188 | |
| 2189 | #Code |
| 2190 | #Literal |
| 2191 | c = cos(degrees) |
| 2192 | s = sin(degrees) |
| 2193 | ## |
| 2194 | |
| 2195 | sets Matrix to: |
| 2196 | |
| 2197 | #Code |
| 2198 | #Literal |
| 2199 | | A B C | | c -s 0 | | Ac+Bs -As+Bc C | |
| 2200 | Matrix * 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2205 | |
| 2206 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2207 | #Image 3 |
| 2208 | SkMatrix matrix; |
| 2209 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 2210 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 2211 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 2212 | matrix.preRotate(45); |
| 2213 | canvas->concat(matrix); |
| 2214 | canvas->drawBitmap(source, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2215 | ## |
| 2216 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2217 | #SeeAlso postRotate setRotate |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2218 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2219 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2220 | |
| 2221 | # ------------------------------------------------------------------------------ |
| 2222 | |
| 2223 | #Method void preSkew(SkScalar kx, SkScalar ky, SkScalar px, SkScalar py) |
| 2224 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2225 | #Line # Pre-multiplies Matrix by skew. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2226 | Sets Matrix to Matrix multiplied by Matrix constructed from skewing by (kx, ky) |
| 2227 | about pivot point (px, py). |
| 2228 | This can be thought of as skewing about a pivot point before applying Matrix. |
| 2229 | |
| 2230 | Given: |
| 2231 | |
| 2232 | #Code |
| 2233 | #Literal |
| 2234 | | A B C | | 1 kx dx | |
| 2235 | Matrix = | D E F |, K(kx, ky, px, py) = | ky 1 dy | |
| 2236 | | G H I | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2237 | ## |
| 2238 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2239 | where |
| 2240 | |
| 2241 | #Code |
| 2242 | #Literal |
| 2243 | dx = -kx * py |
| 2244 | dy = -ky * px |
| 2245 | ## |
| 2246 | |
| 2247 | sets 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 | |
| 2252 | Matrix * 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2260 | |
| 2261 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2262 | #Image 3 |
| 2263 | SkMatrix matrix; |
| 2264 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 2265 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 2266 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 2267 | matrix.preSkew(.5f, 0, source.width() / 2, source.height() / 2); |
| 2268 | canvas->concat(matrix); |
| 2269 | canvas->drawBitmap(source, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2270 | ## |
| 2271 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2272 | #SeeAlso postSkew setSkew |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2273 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2274 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2275 | |
| 2276 | # ------------------------------------------------------------------------------ |
| 2277 | |
| 2278 | #Method void preSkew(SkScalar kx, SkScalar ky) |
| 2279 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2280 | Sets Matrix to Matrix multiplied by Matrix constructed from skewing by (kx, ky) |
| 2281 | about pivot point (0, 0). |
| 2282 | This can be thought of as skewing about the origin before applying Matrix. |
| 2283 | |
| 2284 | Given: |
| 2285 | |
| 2286 | #Code |
| 2287 | #Literal |
| 2288 | | A B C | | 1 kx 0 | |
| 2289 | Matrix = | D E F |, K(kx, ky) = | ky 1 0 | |
| 2290 | | G H I | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2291 | ## |
| 2292 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2293 | sets Matrix to: |
| 2294 | |
| 2295 | #Code |
| 2296 | #Literal |
| 2297 | | A B C | | 1 kx 0 | | A+B*ky A*kx+B C | |
| 2298 | Matrix * 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2304 | |
| 2305 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2306 | #Image 3 |
| 2307 | SkMatrix matrix; |
| 2308 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 2309 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 2310 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 2311 | matrix.preSkew(.5f, 0); |
| 2312 | canvas->concat(matrix); |
| 2313 | canvas->drawBitmap(source, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2314 | ## |
| 2315 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2316 | #SeeAlso postSkew setSkew |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2317 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2318 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2319 | |
| 2320 | # ------------------------------------------------------------------------------ |
| 2321 | |
| 2322 | #Method void preConcat(const SkMatrix& other) |
| 2323 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2324 | #Line # Pre-multiplies Matrix by Matrix parameter. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2325 | Sets Matrix to Matrix multiplied by Matrix other. |
| 2326 | This can be thought of mapping by other before applying Matrix. |
| 2327 | |
| 2328 | Given: |
| 2329 | |
| 2330 | #Code |
| 2331 | #Literal |
| 2332 | | A B C | | J K L | |
| 2333 | Matrix = | D E F |, other = | M N O | |
| 2334 | | G H I | | P Q R | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2335 | ## |
| 2336 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2337 | sets Matrix to: |
| 2338 | |
| 2339 | #Code |
| 2340 | #Literal |
| 2341 | | A B C | | J K L | | AJ+BM+CP AK+BN+CQ AL+BO+CR | |
| 2342 | Matrix * 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2347 | |
| 2348 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2349 | #Image 3 |
| 2350 | #Description |
| 2351 | setPolyToPoly creates perspective matrices, one the inverse of the other. |
| 2352 | Multiplying the matrix by its inverse turns into an identity matrix. |
| 2353 | ## |
| 2354 | SkMatrix matrix, matrix2; |
| 2355 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 2356 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 2357 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 2358 | matrix2.setPolyToPoly(perspect, bitmapBounds, 4); |
| 2359 | matrix.preConcat(matrix2); |
| 2360 | canvas->concat(matrix); |
| 2361 | canvas->drawBitmap(source, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2362 | ## |
| 2363 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2364 | #SeeAlso postConcat setConcat Concat |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2365 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2366 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2367 | |
| 2368 | # ------------------------------------------------------------------------------ |
| 2369 | |
| 2370 | #Method void postTranslate(SkScalar dx, SkScalar dy) |
| 2371 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2372 | #Line # Post-multiplies Matrix by translation. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2373 | Sets Matrix to Matrix constructed from translation (dx, dy) multiplied by Matrix. |
| 2374 | This can be thought of as moving the point to be mapped after applying Matrix. |
| 2375 | |
| 2376 | Given: |
| 2377 | |
| 2378 | #Code |
| 2379 | #Literal |
| 2380 | | J K L | | 1 0 dx | |
| 2381 | Matrix = | M N O |, T(dx, dy) = | 0 1 dy | |
| 2382 | | P Q R | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2383 | ## |
| 2384 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2385 | sets Matrix to: |
| 2386 | |
| 2387 | #Code |
| 2388 | #Literal |
| 2389 | | 1 0 dx | | J K L | | J+dx*P K+dx*Q L+dx*R | |
| 2390 | T(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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2396 | |
| 2397 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2398 | #Height 160 |
| 2399 | #Description |
| 2400 | Compare 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2422 | ## |
| 2423 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2424 | #SeeAlso preTranslate setTranslate MakeTrans |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2425 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2426 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2427 | |
| 2428 | # ------------------------------------------------------------------------------ |
| 2429 | |
| 2430 | #Method void postScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py) |
| 2431 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2432 | #Line # Post-multiplies Matrix by scale. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2433 | Sets Matrix to Matrix constructed from scaling by (sx, sy) about pivot point |
| 2434 | (px, py), multiplied by Matrix. |
| 2435 | This can be thought of as scaling about a pivot point after applying Matrix. |
| 2436 | |
| 2437 | Given: |
| 2438 | |
| 2439 | #Code |
| 2440 | #Literal |
| 2441 | | J K L | | sx 0 dx | |
| 2442 | Matrix = | M N O |, S(sx, sy, px, py) = | 0 sy dy | |
| 2443 | | P Q R | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2444 | ## |
| 2445 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2446 | where |
| 2447 | |
| 2448 | #Code |
| 2449 | #Literal |
| 2450 | dx = px - sx * px |
| 2451 | dy = py - sy * py |
| 2452 | ## |
| 2453 | |
| 2454 | sets 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 | |
| 2459 | S(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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2467 | |
| 2468 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2469 | #Image 3 |
| 2470 | SkMatrix matrix; |
| 2471 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 2472 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 2473 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 2474 | matrix.postScale(.75f, 1.5f, source.width() / 2, source.height() / 2); |
| 2475 | canvas->concat(matrix); |
| 2476 | canvas->drawBitmap(source, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2477 | ## |
| 2478 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2479 | #SeeAlso preScale setScale MakeScale |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2480 | |
| 2481 | ## |
| 2482 | |
| 2483 | # ------------------------------------------------------------------------------ |
| 2484 | |
| 2485 | #Method void postScale(SkScalar sx, SkScalar sy) |
| 2486 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2487 | Sets Matrix to Matrix constructed from scaling by (sx, sy) about pivot point |
| 2488 | (0, 0), multiplied by Matrix. |
| 2489 | This can be thought of as scaling about the origin after applying Matrix. |
| 2490 | |
| 2491 | Given: |
| 2492 | |
| 2493 | #Code |
| 2494 | #Literal |
| 2495 | | J K L | | sx 0 0 | |
| 2496 | Matrix = | M N O |, S(sx, sy) = | 0 sy 0 | |
| 2497 | | P Q R | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2498 | ## |
| 2499 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2500 | sets Matrix to: |
| 2501 | |
| 2502 | #Code |
| 2503 | #Literal |
| 2504 | | sx 0 0 | | J K L | | sx*J sx*K sx*L | |
| 2505 | S(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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2511 | |
| 2512 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2513 | #Image 3 |
| 2514 | SkMatrix matrix; |
| 2515 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 2516 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 2517 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 2518 | matrix.postScale(.75f, 1.5f); |
| 2519 | canvas->concat(matrix); |
| 2520 | canvas->drawBitmap(source, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2521 | ## |
| 2522 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2523 | #SeeAlso preScale setScale MakeScale |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2524 | |
| 2525 | ## |
| 2526 | |
| 2527 | # ------------------------------------------------------------------------------ |
| 2528 | |
| 2529 | #Method bool postIDiv(int divx, int divy) |
| 2530 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2531 | #Line # Post-multiplies Matrix by inverse scale. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2532 | Sets Matrix to Matrix constructed from scaling by |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2533 | #Formula |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2534 | (1/divx, 1/divy) |
| 2535 | ## |
| 2536 | about pivot point (px, py), multiplied by Matrix. |
| 2537 | |
| 2538 | Returns false if either divx or divy is zero. |
| 2539 | |
| 2540 | Given: |
| 2541 | |
| 2542 | #Code |
| 2543 | #Literal |
| 2544 | | J K L | | sx 0 0 | |
| 2545 | Matrix = | M N O |, I(divx, divy) = | 0 sy 0 | |
| 2546 | | P Q R | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2547 | ## |
| 2548 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2549 | where |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2550 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2551 | #Code |
| 2552 | #Literal |
| 2553 | sx = 1 / divx |
| 2554 | sy = 1 / divy |
| 2555 | ## |
| 2556 | |
| 2557 | sets Matrix to: |
| 2558 | |
| 2559 | #Code |
| 2560 | #Literal |
| 2561 | | sx 0 0 | | J K L | | sx*J sx*K sx*L | |
| 2562 | I(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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2570 | |
| 2571 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2572 | #Image 3 |
| 2573 | SkMatrix matrix, matrix2; |
| 2574 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 2575 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 2576 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 2577 | matrix.postIDiv(1, 2); |
| 2578 | canvas->concat(matrix); |
| 2579 | canvas->drawBitmap(source, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2580 | ## |
| 2581 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2582 | #SeeAlso postScale MakeScale |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2583 | |
| 2584 | ## |
| 2585 | |
| 2586 | # ------------------------------------------------------------------------------ |
| 2587 | |
| 2588 | #Method void postRotate(SkScalar degrees, SkScalar px, SkScalar py) |
| 2589 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2590 | #Line # Post-multiplies Matrix by rotation. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2591 | Sets Matrix to Matrix constructed from rotating by degrees about pivot point |
| 2592 | (px, py), multiplied by Matrix. |
| 2593 | This can be thought of as rotating about a pivot point after applying Matrix. |
| 2594 | |
| 2595 | Positive degrees rotates clockwise. |
| 2596 | |
| 2597 | Given: |
| 2598 | |
| 2599 | #Code |
| 2600 | #Literal |
| 2601 | | J K L | | c -s dx | |
| 2602 | Matrix = | M N O |, R(degrees, px, py) = | s c dy | |
| 2603 | | P Q R | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2604 | ## |
| 2605 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2606 | where |
| 2607 | |
| 2608 | #Code |
| 2609 | #Literal |
| 2610 | c = cos(degrees) |
| 2611 | s = sin(degrees) |
| 2612 | dx = s * py + (1 - c) * px |
| 2613 | dy = -s * px + (1 - c) * py |
| 2614 | ## |
| 2615 | |
| 2616 | sets 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| |
| 2621 | R(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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2628 | |
| 2629 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2630 | #Image 3 |
| 2631 | SkMatrix matrix; |
| 2632 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 2633 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 2634 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 2635 | matrix.postRotate(45, source.width() / 2, source.height() / 2); |
| 2636 | canvas->concat(matrix); |
| 2637 | canvas->drawBitmap(source, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2638 | ## |
| 2639 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2640 | #SeeAlso preRotate setRotate |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2641 | |
| 2642 | ## |
| 2643 | |
| 2644 | # ------------------------------------------------------------------------------ |
| 2645 | |
| 2646 | #Method void postRotate(SkScalar degrees) |
| 2647 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2648 | Sets Matrix to Matrix constructed from rotating by degrees about pivot point |
| 2649 | (0, 0), multiplied by Matrix. |
| 2650 | This can be thought of as rotating about the origin after applying Matrix. |
| 2651 | |
| 2652 | Positive degrees rotates clockwise. |
| 2653 | |
| 2654 | Given: |
| 2655 | |
| 2656 | #Code |
| 2657 | #Literal |
| 2658 | | J K L | | c -s 0 | |
| 2659 | Matrix = | M N O |, R(degrees, px, py) = | s c 0 | |
| 2660 | | P Q R | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2661 | ## |
| 2662 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2663 | where |
| 2664 | |
| 2665 | #Code |
| 2666 | #Literal |
| 2667 | c = cos(degrees) |
| 2668 | s = sin(degrees) |
| 2669 | ## |
| 2670 | |
| 2671 | sets Matrix to: |
| 2672 | |
| 2673 | #Code |
| 2674 | #Literal |
| 2675 | | c -s dx | | J K L | | cJ-sM cK-sN cL-sO | |
| 2676 | R(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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2681 | |
| 2682 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2683 | #Image 3 |
| 2684 | SkMatrix matrix; |
| 2685 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 2686 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 2687 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 2688 | matrix.postRotate(45); |
| 2689 | canvas->concat(matrix); |
| 2690 | canvas->drawBitmap(source, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2691 | ## |
| 2692 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2693 | #SeeAlso preRotate setRotate |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2694 | |
| 2695 | ## |
| 2696 | |
| 2697 | # ------------------------------------------------------------------------------ |
| 2698 | |
| 2699 | #Method void postSkew(SkScalar kx, SkScalar ky, SkScalar px, SkScalar py) |
| 2700 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2701 | #Line # Post-multiplies Matrix by skew. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2702 | Sets Matrix to Matrix constructed from skewing by (kx, ky) about pivot point |
| 2703 | (px, py), multiplied by Matrix. |
| 2704 | This can be thought of as skewing about a pivot point after applying Matrix. |
| 2705 | |
| 2706 | Given: |
| 2707 | |
| 2708 | #Code |
| 2709 | #Literal |
| 2710 | | J K L | | 1 kx dx | |
| 2711 | Matrix = | M N O |, K(kx, ky, px, py) = | ky 1 dy | |
| 2712 | | P Q R | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2713 | ## |
| 2714 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2715 | where |
| 2716 | |
| 2717 | #Code |
| 2718 | #Literal |
| 2719 | dx = -kx * py |
| 2720 | dy = -ky * px |
| 2721 | ## |
| 2722 | |
| 2723 | sets 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| |
| 2728 | K(kx, ky, px, py) * Matrix = |ky 1 dy| |M N O| = |ky*J+M+dy*P ky*K+N+dy*Q ky*L+O+dy*R| |
| 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2736 | |
| 2737 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2738 | #Image 3 |
| 2739 | SkMatrix matrix; |
| 2740 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 2741 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 2742 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 2743 | matrix.postSkew(.5f, 0, source.width() / 2, source.height() / 2); |
| 2744 | canvas->concat(matrix); |
| 2745 | canvas->drawBitmap(source, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2746 | ## |
| 2747 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2748 | #SeeAlso preSkew setSkew |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2749 | |
| 2750 | ## |
| 2751 | |
| 2752 | # ------------------------------------------------------------------------------ |
| 2753 | |
| 2754 | #Method void postSkew(SkScalar kx, SkScalar ky) |
| 2755 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2756 | Sets Matrix to Matrix constructed from skewing by (kx, ky) about pivot point |
| 2757 | (0, 0), multiplied by Matrix. |
| 2758 | This can be thought of as skewing about the origin after applying Matrix. |
| 2759 | |
| 2760 | Given: |
| 2761 | |
| 2762 | #Code |
| 2763 | #Literal |
| 2764 | | J K L | | 1 kx 0 | |
| 2765 | Matrix = | M N O |, K(kx, ky) = | ky 1 0 | |
| 2766 | | P Q R | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2767 | ## |
| 2768 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2769 | sets Matrix to: |
| 2770 | |
| 2771 | #Code |
| 2772 | #Literal |
| 2773 | | 1 kx 0 | | J K L | | J+kx*M K+kx*N L+kx*O | |
| 2774 | K(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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2780 | |
| 2781 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2782 | #Image 3 |
| 2783 | SkMatrix matrix; |
| 2784 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 2785 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 2786 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 2787 | matrix.postSkew(.5f, 0); |
| 2788 | canvas->concat(matrix); |
| 2789 | canvas->drawBitmap(source, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2790 | ## |
| 2791 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2792 | #SeeAlso preSkew setSkew |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2793 | |
| 2794 | ## |
| 2795 | |
| 2796 | # ------------------------------------------------------------------------------ |
| 2797 | |
| 2798 | #Method void postConcat(const SkMatrix& other) |
| 2799 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2800 | #Line # Post-multiplies Matrix by Matrix parameter. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2801 | Sets Matrix to Matrix other multiplied by Matrix. |
| 2802 | This can be thought of mapping by other after applying Matrix. |
| 2803 | |
| 2804 | Given: |
| 2805 | |
| 2806 | #Code |
| 2807 | #Literal |
| 2808 | | J K L | | A B C | |
| 2809 | Matrix = | M N O |, other = | D E F | |
| 2810 | | P Q R | | G H I | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2811 | ## |
| 2812 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2813 | sets Matrix to: |
| 2814 | |
| 2815 | #Code |
| 2816 | #Literal |
| 2817 | | A B C | | J K L | | AJ+BM+CP AK+BN+CQ AL+BO+CR | |
| 2818 | other * 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2823 | |
| 2824 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2825 | #Image 3 |
| 2826 | #Height 64 |
| 2827 | SkMatrix matrix, matrix2; |
| 2828 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 2829 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 2830 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 2831 | matrix.postConcat(matrix); |
| 2832 | canvas->concat(matrix); |
| 2833 | canvas->drawBitmap(source, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2834 | ## |
| 2835 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2836 | #SeeAlso preConcat setConcat Concat |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2837 | |
| 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 Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2853 | ScaleToFit describes how Matrix is constructed to map one Rect to another. |
| 2854 | ScaleToFit may allow Matrix to have unequal horizontal and vertical scaling, |
| 2855 | or may restrict Matrix to square scaling. If restricted, ScaleToFit specifies |
| 2856 | how 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2862 | ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2863 | #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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2867 | ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2868 | #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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2872 | ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2873 | #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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2877 | ## |
| 2878 | |
| 2879 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2880 | 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2901 | ## |
| 2902 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2903 | #SeeAlso setRectToRect MakeRectToRect setPolyToPoly |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2904 | |
| 2905 | ## |
| 2906 | |
| 2907 | # ------------------------------------------------------------------------------ |
| 2908 | |
| 2909 | #Method bool setRectToRect(const SkRect& src, const SkRect& dst, ScaleToFit stf) |
| 2910 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2911 | #Line # Sets to map one Rect to another. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2912 | Sets Matrix to scale and translate src Rect to dst Rect. stf selects whether |
| 2913 | mapping completely fills dst or preserves the aspect ratio, and how to align |
| 2914 | src within dst. Returns false if src is empty, and sets Matrix to identity. |
| 2915 | Returns true if dst is empty, and sets Matrix to: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2916 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2917 | #Code |
| 2918 | #Literal |
| 2919 | | 0 0 0 | |
| 2920 | | 0 0 0 | |
| 2921 | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2922 | ## |
| 2923 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2924 | #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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2928 | ## |
| 2929 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2930 | #Return true if Matrix can represent Rect mapping ## |
| 2931 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2932 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2933 | 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 |
| 2947 | src: 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] |
| 2949 | src: 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] |
| 2951 | src: 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] |
| 2953 | src: 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2956 | ## |
| 2957 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2958 | #SeeAlso MakeRectToRect ScaleToFit setPolyToPoly SkRect::isEmpty |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2959 | |
| 2960 | ## |
| 2961 | |
| 2962 | # ------------------------------------------------------------------------------ |
| 2963 | |
| 2964 | #Method static SkMatrix MakeRectToRect(const SkRect& src, const SkRect& dst, ScaleToFit stf) |
| 2965 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2966 | #Line # Constructs from source Rect to destination Rect. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2967 | Returns Matrix set to scale and translate src Rect to dst Rect. stf selects |
| 2968 | whether mapping completely fills dst or preserves the aspect ratio, and how to |
| 2969 | align src within dst. Returns the identity Matrix if src is empty. If dst is |
| 2970 | empty, returns Matrix set to: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2971 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2972 | #Code |
| 2973 | #Literal |
| 2974 | | 0 0 0 | |
| 2975 | | 0 0 0 | |
| 2976 | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2977 | ## |
| 2978 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2979 | #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 |
| 3000 | src: 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] |
| 3002 | src: 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] |
| 3004 | src: 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] |
| 3006 | src: 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3012 | |
| 3013 | ## |
| 3014 | |
| 3015 | # ------------------------------------------------------------------------------ |
| 3016 | |
| 3017 | #Method bool setPolyToPoly(const SkPoint src[], const SkPoint dst[], int count) |
| 3018 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3019 | #Line # Sets to map one to four points to an equal array of points. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3020 | Sets Matrix to map src to dst. count must be zero or greater, and four or less. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3021 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3022 | If count is zero, sets Matrix to identity and returns true. |
| 3023 | If count is one, sets Matrix to translate and returns true. |
| 3024 | If count is two or more, sets Matrix to map Points if possible; returns false |
| 3025 | if Matrix cannot be constructed. If count is four, Matrix may include |
| 3026 | perspective. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3027 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3028 | #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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3033 | ## |
| 3034 | |
| 3035 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3036 | 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3060 | ## |
| 3061 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3062 | #SeeAlso setRectToRect MakeRectToRect |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3063 | |
| 3064 | ## |
| 3065 | |
| 3066 | # ------------------------------------------------------------------------------ |
| 3067 | |
| 3068 | #Method bool SK_WARN_UNUSED_RESULT invert(SkMatrix* inverse) const |
| 3069 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3070 | #Line # Returns inverse, if possible. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3071 | Sets inverse to reciprocal matrix, returning true if Matrix can be inverted. |
| 3072 | Geometrically, if Matrix maps from source to destination, inverse Matrix |
| 3073 | maps from destination to source. If Matrix can not be inverted, inverse is |
| 3074 | unchanged. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3075 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3076 | #Param inverse storage for inverted Matrix; may be nullptr ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3077 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3078 | #Return true if Matrix can be inverted ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3079 | |
| 3080 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3081 | #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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3097 | ## |
| 3098 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3099 | #SeeAlso Concat |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3100 | |
| 3101 | ## |
| 3102 | |
| 3103 | # ------------------------------------------------------------------------------ |
| 3104 | |
| 3105 | #Method static void SetAffineIdentity(SkScalar affine[6]) |
| 3106 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3107 | #Line # Sets 3x2 array to identity. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3108 | Fills affine with identity values in column major order. |
| 3109 | Sets affine to: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3110 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3111 | #Code |
| 3112 | #Literal |
| 3113 | | 1 0 0 | |
| 3114 | | 0 1 0 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3115 | ## |
| 3116 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3117 | Affine 3x2 matrices in column major order are used by OpenGL and XPS. |
| 3118 | |
| 3119 | #Param affine storage for 3x2 affine matrix ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3120 | |
| 3121 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3122 | 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 |
| 3130 | ScaleX: 1 SkewY: 0 SkewX: 0 ScaleY: 1 TransX: 0 TransY: 0 |
| 3131 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3132 | ## |
| 3133 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3134 | #SeeAlso setAffine asAffine |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3135 | |
| 3136 | ## |
| 3137 | |
| 3138 | # ------------------------------------------------------------------------------ |
| 3139 | |
| 3140 | #Method bool SK_WARN_UNUSED_RESULT asAffine(SkScalar affine[6]) const |
| 3141 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3142 | #Line # Copies to 3x2 array. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3143 | Fills affine in column major order. Sets affine to: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3144 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3145 | #Code |
| 3146 | #Literal |
| 3147 | | scale-x skew-x translate-x | |
| 3148 | | skew-y scale-y translate-y | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3149 | ## |
| 3150 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3151 | If 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3156 | |
| 3157 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3158 | SkMatrix matrix; |
| 3159 | matrix.setAll(2, 3, 4, 5, 6, 7, 0, 0, 1); |
| 3160 | SkScalar affine[6]; |
| 3161 | matrix.asAffine(affine); |
| 3162 | const char* names[] = { "ScaleX", "SkewY", "SkewX", "ScaleY", "TransX", "TransY" }; |
| 3163 | for (int i = 0; i < 6; ++i) { |
| 3164 | SkDebugf("%s: %g ", names[i], affine[i]); |
| 3165 | } |
| 3166 | SkDebugf("\n"); |
| 3167 | #StdOut |
| 3168 | ScaleX: 2 SkewY: 5 SkewX: 3 ScaleY: 6 TransX: 4 TransY: 7 |
| 3169 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3170 | ## |
| 3171 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3172 | #SeeAlso setAffine SetAffineIdentity |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3173 | |
| 3174 | ## |
| 3175 | |
| 3176 | # ------------------------------------------------------------------------------ |
| 3177 | |
| 3178 | #Method void setAffine(const SkScalar affine[6]) |
| 3179 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3180 | #Line # Sets left two columns. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3181 | Sets Matrix to affine values, passed in column major order. Given affine, |
| 3182 | column, then row, as: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3183 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3184 | #Code |
| 3185 | #Literal |
| 3186 | | scale-x skew-x translate-x | |
| 3187 | | skew-y scale-y translate-y | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3188 | ## |
| 3189 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3190 | Matrix 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 |
| 3202 | SkMatrix matrix; |
| 3203 | matrix.setAll(2, 3, 4, 5, 6, 7, 0, 0, 1); |
| 3204 | SkScalar affine[6]; |
| 3205 | matrix.asAffine(affine); |
| 3206 | const char* names[] = { "ScaleX", "SkewY", "SkewX", "ScaleY", "TransX", "TransY" }; |
| 3207 | for (int i = 0; i < 6; ++i) { |
| 3208 | SkDebugf("%s: %g ", names[i], affine[i]); |
| 3209 | } |
| 3210 | SkDebugf("\n"); |
| 3211 | matrix.reset(); |
| 3212 | matrix.setAffine(affine); |
| 3213 | matrix.dump(); |
| 3214 | #StdOut |
| 3215 | ScaleX: 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3221 | |
| 3222 | ## |
| 3223 | |
| 3224 | # ------------------------------------------------------------------------------ |
| 3225 | |
| 3226 | #Method void mapPoints(SkPoint dst[], const SkPoint src[], int count) const |
| 3227 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3228 | #Line # Maps Point array. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3229 | Maps src Point array of length count to dst Point array of equal or greater |
| 3230 | length. Points are mapped by multiplying each Point by Matrix. Given: |
| 3231 | |
| 3232 | #Code |
| 3233 | #Literal |
| 3234 | | A B C | | x | |
| 3235 | Matrix = | D E F |, pt = | y | |
| 3236 | | G H I | | 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3237 | ## |
| 3238 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3239 | where |
| 3240 | |
| 3241 | #Code |
| 3242 | #Literal |
| 3243 | for (i = 0; i < count; ++i) { |
| 3244 | x = src[i].fX |
| 3245 | y = src[i].fY |
| 3246 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3247 | ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3248 | |
| 3249 | each dst Point is computed as: |
| 3250 | |
| 3251 | #Code |
| 3252 | #Literal |
| 3253 | |A B C| |x| Ax+By+C Dx+Ey+F |
| 3254 | Matrix * 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3256 | ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3257 | |
| 3258 | src 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3263 | |
| 3264 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3265 | 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3278 | ## |
| 3279 | |
Brian Salomon | fa3783f | 2018-01-05 13:49:07 -0500 | [diff] [blame] | 3280 | #SeeAlso mapXY mapHomogeneousPoints mapVectors |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3281 | |
| 3282 | ## |
| 3283 | |
| 3284 | # ------------------------------------------------------------------------------ |
| 3285 | |
| 3286 | #Method void mapPoints(SkPoint pts[], int count) const |
| 3287 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3288 | Maps pts Point array of length count in place. Points are mapped by multiplying |
| 3289 | each Point by Matrix. Given: |
| 3290 | |
| 3291 | #Code |
| 3292 | #Literal |
| 3293 | | A B C | | x | |
| 3294 | Matrix = | D E F |, pt = | y | |
| 3295 | | G H I | | 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3296 | ## |
| 3297 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3298 | where |
| 3299 | |
| 3300 | #Code |
| 3301 | #Literal |
| 3302 | for (i = 0; i < count; ++i) { |
| 3303 | x = pts[i].fX |
| 3304 | y = pts[i].fY |
| 3305 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3306 | ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3307 | |
| 3308 | each resulting pts Point is computed as: |
| 3309 | |
| 3310 | #Code |
| 3311 | #Literal |
| 3312 | |A B C| |x| Ax+By+C Dx+Ey+F |
| 3313 | Matrix * 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3315 | ## |
| 3316 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3317 | #Param pts storage for mapped Points ## |
| 3318 | #Param count number of Points to transform ## |
| 3319 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3320 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3321 | 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3332 | ## |
| 3333 | |
Brian Salomon | fa3783f | 2018-01-05 13:49:07 -0500 | [diff] [blame] | 3334 | #SeeAlso mapXY mapHomogeneousPoints mapVectors |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3335 | |
| 3336 | ## |
| 3337 | |
| 3338 | # ------------------------------------------------------------------------------ |
| 3339 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3340 | #Method void mapHomogeneousPoints(SkPoint3 dst[], const SkPoint3 src[], int count) const |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3341 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3342 | #Line # Maps Point3 array. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3343 | Maps src Point3 array of length count to dst Point3 array, which must of length count or |
| 3344 | greater. Point3 array is mapped by multiplying each Point3 by Matrix. Given: |
| 3345 | |
| 3346 | #Code |
| 3347 | #Literal |
| 3348 | | A B C | | x | |
| 3349 | Matrix = | D E F |, src = | y | |
| 3350 | | G H I | | z | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3351 | ## |
| 3352 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3353 | each resulting dst Point is computed as: |
| 3354 | |
| 3355 | #Code |
| 3356 | #Literal |
| 3357 | |A B C| |x| |
| 3358 | Matrix * src = |D E F| |y| = |Ax+By+Cz Dx+Ey+Fz Gx+Hy+Iz| |
| 3359 | |G H I| |z| |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3360 | ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3361 | |
| 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3365 | |
| 3366 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3367 | 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 Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 3388 | matrix.mapHomogeneousPoints(src, src, count); |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3389 | debugster(src); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3390 | ## |
| 3391 | |
Brian Salomon | fa3783f | 2018-01-05 13:49:07 -0500 | [diff] [blame] | 3392 | #SeeAlso mapPoints mapXY mapVectors |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3393 | |
| 3394 | ## |
| 3395 | |
| 3396 | # ------------------------------------------------------------------------------ |
| 3397 | |
| 3398 | #Method void mapXY(SkScalar x, SkScalar y, SkPoint* result) const |
| 3399 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3400 | #Line # Maps Point. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3401 | Maps Point (x, y) to result. Point is mapped by multiplying by Matrix. Given: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3402 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3403 | #Code |
| 3404 | #Literal |
| 3405 | | A B C | | x | |
| 3406 | Matrix = | D E F |, pt = | y | |
| 3407 | | G H I | | 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3408 | ## |
| 3409 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3410 | result is computed as: |
| 3411 | |
| 3412 | #Code |
| 3413 | #Literal |
| 3414 | |A B C| |x| Ax+By+C Dx+Ey+F |
| 3415 | Matrix * 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 Salomon | fa3783f | 2018-01-05 13:49:07 -0500 | [diff] [blame] | 3438 | #SeeAlso mapPoints mapVectors |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3439 | |
| 3440 | ## |
| 3441 | |
| 3442 | # ------------------------------------------------------------------------------ |
| 3443 | |
| 3444 | #Method SkPoint mapXY(SkScalar x, SkScalar y) const |
| 3445 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3446 | Returns Point (x, y) multiplied by Matrix. Given: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3447 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3448 | #Code |
| 3449 | #Literal |
| 3450 | | A B C | | x | |
| 3451 | Matrix = | D E F |, pt = | y | |
| 3452 | | G H I | | 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3453 | ## |
| 3454 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3455 | result is computed as: |
| 3456 | |
| 3457 | #Code |
| 3458 | #Literal |
| 3459 | |A B C| |x| Ax+By+C Dx+Ey+F |
| 3460 | Matrix * 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 |
| 3471 | SkMatrix matrix; |
| 3472 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {30, 206}}; |
| 3473 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 3474 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 3475 | SkPaint paint; |
| 3476 | paint.setAntiAlias(true); |
| 3477 | paint.setStrokeWidth(3); |
| 3478 | for (int x : { 0, source.width() } ) { |
| 3479 | for (int y : { 0, source.height() } ) { |
| 3480 | canvas->drawPoint(matrix.mapXY(x, y), paint); |
| 3481 | } |
| 3482 | } |
| 3483 | canvas->concat(matrix); |
| 3484 | canvas->drawBitmap(source, 0, 0); |
| 3485 | ## |
| 3486 | |
Brian Salomon | fa3783f | 2018-01-05 13:49:07 -0500 | [diff] [blame] | 3487 | #SeeAlso mapPoints mapVectors |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3488 | |
| 3489 | ## |
| 3490 | |
| 3491 | # ------------------------------------------------------------------------------ |
| 3492 | |
| 3493 | #Method void mapVectors(SkVector dst[], const SkVector src[], int count) const |
| 3494 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3495 | #Line # Maps Vector array. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3496 | Maps src Vector array of length count to Vector Point array of equal or greater |
| 3497 | length. Vectors are mapped by multiplying each Vector by Matrix, treating |
| 3498 | Matrix translation as zero. Given: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3499 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3500 | #Code |
| 3501 | #Literal |
| 3502 | | A B 0 | | x | |
| 3503 | Matrix = | D E 0 |, src = | y | |
| 3504 | | G H I | | 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3505 | ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3506 | |
| 3507 | where |
| 3508 | |
| 3509 | #Code |
| 3510 | #Literal |
| 3511 | for (i = 0; i < count; ++i) { |
| 3512 | x = src[i].fX |
| 3513 | y = src[i].fY |
| 3514 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3515 | ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3516 | |
| 3517 | each dst Vector is computed as: |
| 3518 | |
| 3519 | #Code |
| 3520 | #Literal |
| 3521 | |A B 0| |x| Ax+By Dx+Ey |
| 3522 | Matrix * src = |D E 0| |y| = |Ax+By Dx+Ey Gx+Hy+I| = ------- , ------- |
| 3523 | |G H I| |1| Gx+Hy+I Gx+Hy+I |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3524 | ## |
| 3525 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3526 | src 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3532 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3533 | 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3548 | ## |
| 3549 | |
Brian Salomon | fa3783f | 2018-01-05 13:49:07 -0500 | [diff] [blame] | 3550 | #SeeAlso mapVector mapPoints mapXY |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3551 | |
| 3552 | ## |
| 3553 | |
| 3554 | # ------------------------------------------------------------------------------ |
| 3555 | |
| 3556 | #Method void mapVectors(SkVector vecs[], int count) const |
| 3557 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3558 | Maps vecs Vector array of length count in place, multiplying each Vector by |
| 3559 | Matrix, treating Matrix translation as zero. Given: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3560 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3561 | #Code |
| 3562 | #Literal |
| 3563 | | A B 0 | | x | |
| 3564 | Matrix = | D E 0 |, vec = | y | |
| 3565 | | G H I | | 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3566 | ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3567 | |
| 3568 | where |
| 3569 | |
| 3570 | #Code |
| 3571 | #Literal |
| 3572 | for (i = 0; i < count; ++i) { |
| 3573 | x = vecs[i].fX |
| 3574 | y = vecs[i].fY |
| 3575 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3576 | ## |
| 3577 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3578 | each result Vector is computed as: |
| 3579 | |
| 3580 | #Code |
| 3581 | #Literal |
| 3582 | |A B 0| |x| Ax+By Dx+Ey |
| 3583 | Matrix * 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3590 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3591 | 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3604 | ## |
| 3605 | |
Brian Salomon | fa3783f | 2018-01-05 13:49:07 -0500 | [diff] [blame] | 3606 | #SeeAlso mapVector mapPoints mapXY |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3607 | |
| 3608 | ## |
| 3609 | |
| 3610 | # ------------------------------------------------------------------------------ |
| 3611 | |
| 3612 | #Method void mapVector(SkScalar dx, SkScalar dy, SkVector* result) const |
| 3613 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3614 | #Line # Maps Vector. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3615 | Maps Vector (x, y) to result. Vector is mapped by multiplying by Matrix, |
| 3616 | treating Matrix translation as zero. Given: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3617 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3618 | #Code |
| 3619 | #Literal |
| 3620 | | A B 0 | | dx | |
| 3621 | Matrix = | D E 0 |, vec = | dy | |
| 3622 | | G H I | | 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3623 | ## |
| 3624 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3625 | each 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 |
| 3631 | Matrix * 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 Salomon | fa3783f | 2018-01-05 13:49:07 -0500 | [diff] [blame] | 3656 | #SeeAlso mapVectors mapPoints mapXY |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3657 | |
| 3658 | ## |
| 3659 | |
| 3660 | # ------------------------------------------------------------------------------ |
| 3661 | |
| 3662 | #Method SkVector mapVector(SkScalar dx, SkScalar dy) const |
| 3663 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3664 | Returns Vector (x, y) multiplied by Matrix, treating Matrix translation as zero. |
| 3665 | Given: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3666 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3667 | #Code |
| 3668 | #Literal |
| 3669 | | A B 0 | | dx | |
| 3670 | Matrix = | D E 0 |, vec = | dy | |
| 3671 | | G H I | | 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3672 | ## |
| 3673 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3674 | each 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 |
| 3680 | Matrix * 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 Salomon | fa3783f | 2018-01-05 13:49:07 -0500 | [diff] [blame] | 3706 | #SeeAlso mapVectors mapPoints mapXY |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3707 | |
| 3708 | ## |
| 3709 | |
| 3710 | # ------------------------------------------------------------------------------ |
| 3711 | |
| 3712 | #Method bool mapRect(SkRect* dst, const SkRect& src) const |
| 3713 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3714 | #Line # Returns bounds of mapped Rect. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3715 | Sets dst to bounds of src corners mapped by Matrix. |
| 3716 | Returns true if mapped corners are dst corners. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3717 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3718 | Returned value is the same as calling rectStaysRect. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3719 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3720 | #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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3724 | |
| 3725 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3726 | 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3737 | ## |
| 3738 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3739 | #SeeAlso mapPoints rectStaysRect |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3740 | |
| 3741 | ## |
| 3742 | |
| 3743 | # ------------------------------------------------------------------------------ |
| 3744 | |
| 3745 | #Method bool mapRect(SkRect* rect) const |
| 3746 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3747 | Sets rect to bounds of rect corners mapped by Matrix. |
| 3748 | Returns true if mapped corners are computed rect corners. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3749 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3750 | Returned value is the same as calling rectStaysRect. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3751 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3752 | #Param rect rectangle to map, and storage for bounds of mapped corners ## |
| 3753 | |
| 3754 | #Return true if result is equivalent to mapped src ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3755 | |
| 3756 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3757 | 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3768 | ## |
| 3769 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3770 | #SeeAlso mapRectScaleTranslate mapPoints rectStaysRect |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3771 | |
| 3772 | ## |
| 3773 | |
| 3774 | # ------------------------------------------------------------------------------ |
| 3775 | |
| 3776 | #Method void mapRectToQuad(SkPoint dst[4], const SkRect& rect) const |
| 3777 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3778 | #Line # Maps Rect to Point array. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3779 | Maps four corners of rect to dst. Points are mapped by multiplying each |
| 3780 | rect 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3783 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3784 | rect may be empty: rect.fLeft may be greater than or equal to rect.fRight; |
| 3785 | rect.fTop may be greater than or equal to rect.fBottom. |
| 3786 | |
| 3787 | Given: |
| 3788 | |
| 3789 | #Code |
| 3790 | #Literal |
| 3791 | | A B C | | x | |
| 3792 | Matrix = | D E F |, pt = | y | |
| 3793 | | G H I | | 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3794 | ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3795 | |
| 3796 | where pt is initialized from each of (rect.fLeft, rect.fTop), |
| 3797 | (rect.fRight, rect.fTop), (rect.fRight, rect.fBottom), (rect.fLeft, rect.fBottom), |
| 3798 | each dst Point is computed as: |
| 3799 | |
| 3800 | #Code |
| 3801 | #Literal |
| 3802 | |A B C| |x| Ax+By+C Dx+Ey+F |
| 3803 | Matrix * 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3805 | ## |
| 3806 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3807 | #Param dst storage for mapped corner Points ## |
| 3808 | #Param rect Rect to map ## |
| 3809 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3810 | #Example |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3811 | #Height 192 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3812 | 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3825 | ## |
| 3826 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3827 | #SeeAlso mapRect mapRectScaleTranslate |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3828 | |
| 3829 | ## |
| 3830 | |
| 3831 | # ------------------------------------------------------------------------------ |
| 3832 | |
| 3833 | #Method void mapRectScaleTranslate(SkRect* dst, const SkRect& src) const |
| 3834 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3835 | #Line # Returns bounds of mapped Rect. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3836 | Sets dst to bounds of src corners mapped by Matrix. If matrix contains |
| 3837 | elements other than scale or translate: asserts if SK_DEBUG is defined; |
| 3838 | otherwise, results are undefined. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3839 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3840 | #Param dst storage for bounds of mapped Points ## |
| 3841 | #Param src Rect to map ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3842 | |
| 3843 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3844 | 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3854 | ## |
| 3855 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3856 | #SeeAlso mapRect mapRectToQuad isScaleTranslate rectStaysRect |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3857 | |
| 3858 | ## |
| 3859 | |
| 3860 | # ------------------------------------------------------------------------------ |
| 3861 | |
| 3862 | #Method SkScalar mapRadius(SkScalar radius) const |
| 3863 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3864 | #Line # Returns mean radius of mapped Circle. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3865 | Returns geometric mean radius of ellipse formed by constructing Circle of |
| 3866 | size radius, and mapping constructed Circle with Matrix. The result squared is |
| 3867 | equal to the major axis length times the minor axis length. |
| 3868 | Result is not meaningful if Matrix contains perspective elements. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3869 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3870 | #Param radius Circle size to map ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3871 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3872 | #Return average mapped radius ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3873 | |
| 3874 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3875 | #Description |
| 3876 | The area enclosed by a square with sides equal to mappedRadius is the same as |
| 3877 | the 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3910 | ## |
| 3911 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3912 | #SeeAlso mapVector |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3913 | |
| 3914 | ## |
| 3915 | |
| 3916 | # ------------------------------------------------------------------------------ |
| 3917 | |
| 3918 | #Method bool isFixedStepInX() const |
| 3919 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3920 | #Line # Returns if transformation supports fixed step in x. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3921 | Returns true if a unit step in x at some y mapped through Matrix can be |
| 3922 | represented by a constant Vector. Returns true if getType returns kIdentity_Mask, |
| 3923 | or combinations of: kTranslate_Mask, kScale_Mask, and kAffine_Mask. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3924 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3925 | May return true if getType returns kPerspective_Mask, but only when Matrix |
| 3926 | does not include rotation or skewing along the y-axis. |
| 3927 | |
| 3928 | #Return true if Matrix does not have complex perspective ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3929 | |
| 3930 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3931 | 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] |
| 3943 | isFixedStepInX: true |
| 3944 | [ 1.0000 0.0000 0.0000][ 0.0000 2.0000 0.0000][ 0.0000 0.0000 1.0000] |
| 3945 | isFixedStepInX: true |
| 3946 | [ 1.0000 0.0000 0.0000][ 0.0000 1.0000 0.0000][ 0.0000 0.1000 1.0000] |
| 3947 | isFixedStepInX: true |
| 3948 | [ 1.0000 0.0000 0.0000][ 0.0000 2.0000 0.0000][ 0.0000 0.1000 1.0000] |
| 3949 | isFixedStepInX: true |
| 3950 | [ 1.0000 0.0000 0.0000][ 0.0000 1.0000 0.0000][ 0.1000 0.0000 1.0000] |
| 3951 | isFixedStepInX: false |
| 3952 | [ 1.0000 0.0000 0.0000][ 0.0000 2.0000 0.0000][ 0.1000 0.0000 1.0000] |
| 3953 | isFixedStepInX: false |
| 3954 | [ 1.0000 0.0000 0.0000][ 0.0000 1.0000 0.0000][ 0.1000 0.1000 1.0000] |
| 3955 | isFixedStepInX: false |
| 3956 | [ 1.0000 0.0000 0.0000][ 0.0000 2.0000 0.0000][ 0.1000 0.1000 1.0000] |
| 3957 | isFixedStepInX: false |
| 3958 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3959 | ## |
| 3960 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3961 | #SeeAlso fixedStepInX getType |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3962 | |
| 3963 | ## |
| 3964 | |
| 3965 | # ------------------------------------------------------------------------------ |
| 3966 | |
| 3967 | #Method SkVector fixedStepInX(SkScalar y) const |
| 3968 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3969 | #Line # Returns step in x for a position in y. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3970 | Returns Vector representing a unit step in x at y mapped through Matrix. |
| 3971 | If isFixedStepInX is false, returned value is undefined. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3972 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3973 | #Param y position of line parallel to x-axis ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3974 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3975 | #Return Vector advance of mapped unit step in x ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3976 | |
| 3977 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3978 | #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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3999 | ## |
| 4000 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4001 | #SeeAlso isFixedStepInX getType |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4002 | |
| 4003 | ## |
| 4004 | |
| 4005 | # ------------------------------------------------------------------------------ |
| 4006 | |
| 4007 | #Method bool cheapEqualTo(const SkMatrix& m) const |
| 4008 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4009 | #Line # Compares Matrix pair using memcmp(). ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4010 | Returns true if Matrix equals m, using an efficient comparison. |
| 4011 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4012 | Returns false when the sign of zero values is the different; when one |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4013 | matrix has positive zero value and the other has negative zero value. |
| 4014 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4015 | Returns true even when both Matrices contain NaN. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4016 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4017 | NaN never equals any value, including itself. To improve performance, NaN values |
| 4018 | are treated as bit patterns that are equal if their bit patterns are equal. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4019 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4020 | #Param m Matrix to compare ## |
| 4021 | |
| 4022 | #Return true if m and Matrix are represented by identical bit patterns ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4023 | |
| 4024 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4025 | 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4028 | }; |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4029 | 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 |
| 4040 | identity: a == b a.cheapEqualTo(b): true |
| 4041 | neg zero: a == b a.cheapEqualTo(b): false |
| 4042 | one NaN: a != b a.cheapEqualTo(b): false |
| 4043 | both NaN: a != b a.cheapEqualTo(b): true |
| 4044 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4045 | ## |
| 4046 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4047 | #SeeAlso operator==(const SkMatrix& a, const SkMatrix& b) |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4048 | |
| 4049 | ## |
| 4050 | |
| 4051 | # ------------------------------------------------------------------------------ |
| 4052 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4053 | #Method bool operator==(const SkMatrix& a, const SkMatrix& b) |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4054 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4055 | #Line # Returns true if members are equal. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4056 | Compares a and b; returns true if a and b are numerically equal. Returns true |
| 4057 | even if sign of zero values are different. Returns false if either Matrix |
| 4058 | contains NaN, even if the other Matrix also contains NaN. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4059 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4060 | #Param a Matrix to compare ## |
| 4061 | #Param b Matrix to compare ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4062 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4063 | #Return true if m and Matrix are numerically equal ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4064 | |
| 4065 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4066 | 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 |
| 4076 | identity: a == b a.cheapEqualTo(b): true |
| 4077 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4078 | ## |
| 4079 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4080 | #SeeAlso cheapEqualTo operator!=(const SkMatrix& a, const SkMatrix& b) |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4081 | |
| 4082 | ## |
| 4083 | |
| 4084 | # ------------------------------------------------------------------------------ |
| 4085 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4086 | #Method bool operator!=(const SkMatrix& a, const SkMatrix& b) |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4087 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4088 | #Line # Returns true if members are unequal. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4089 | Compares a and b; returns true if a and b are not numerically equal. Returns false |
| 4090 | even if sign of zero values are different. Returns true if either Matrix |
| 4091 | contains NaN, even if the other Matrix also contains NaN. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4092 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4093 | #Param a Matrix to compare ## |
| 4094 | #Param b Matrix to compare ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4095 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4096 | #Return true if m and Matrix are numerically not equal ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4097 | |
| 4098 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4099 | 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4107 | ## |
| 4108 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4109 | #SeeAlso cheapEqualTo operator==(const SkMatrix& a, const SkMatrix& b) |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4110 | |
| 4111 | ## |
| 4112 | |
| 4113 | # ------------------------------------------------------------------------------ |
| 4114 | |
| 4115 | #Method void dump() const |
| 4116 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4117 | #Line # Sends text representation using floats to standard output. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4118 | Writes text representation of Matrix to standard output. Floating point values |
| 4119 | are written with limited precision; it may not be possible to reconstruct |
| 4120 | original Matrix from output. |
| 4121 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4122 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4123 | 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] |
| 4133 | matrix != nearlyEqual |
| 4134 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4135 | ## |
| 4136 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4137 | #SeeAlso toString |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4138 | |
| 4139 | ## |
| 4140 | |
| 4141 | # ------------------------------------------------------------------------------ |
| 4142 | |
| 4143 | #Method void toString(SkString* str) const |
| 4144 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4145 | #Line # Converts Matrix to machine readable form. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4146 | Creates string representation of Matrix. Floating point values |
| 4147 | are written with limited precision; it may not be possible to reconstruct |
| 4148 | original Matrix from output. |
| 4149 | |
| 4150 | #Param str storage for string representation of Matrix ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4151 | |
| 4152 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4153 | 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 |
| 4164 | mStr [ 0.7071 -0.7071 0.0000][ 0.7071 0.7071 0.0000][ 0.0000 0.0000 1.0000] |
| 4165 | neStr [ 0.7071 -0.7071 0.0000][ 0.7071 0.7071 0.0000][ 0.0000 0.0000 1.0000] |
| 4166 | matrix != nearlyEqual |
| 4167 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4168 | ## |
| 4169 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4170 | #SeeAlso dump |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4171 | |
| 4172 | ## |
| 4173 | |
| 4174 | # ------------------------------------------------------------------------------ |
| 4175 | |
| 4176 | #Method SkScalar getMinScale() const |
| 4177 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4178 | #Line # Returns minimum scaling, if possible. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4179 | Returns the minimum scaling factor of Matrix by decomposing the scaling and |
| 4180 | skewing elements. |
| 4181 | Returns -1 if scale factor overflows or Matrix contains perspective. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4182 | |
| 4183 | #Return minimum scale factor |
| 4184 | ## |
| 4185 | |
| 4186 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4187 | SkMatrix matrix; |
| 4188 | matrix.setScale(42, 24); |
| 4189 | SkDebugf("matrix.getMinScale() %g\n", matrix.getMinScale()); |
| 4190 | #StdOut |
| 4191 | matrix.getMinScale() 24 |
| 4192 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4193 | ## |
| 4194 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4195 | #SeeAlso getMaxScale getMinMaxScales |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4196 | |
| 4197 | ## |
| 4198 | |
| 4199 | # ------------------------------------------------------------------------------ |
| 4200 | |
| 4201 | #Method SkScalar getMaxScale() const |
| 4202 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4203 | #Line # Returns maximum scaling, if possible. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4204 | Returns the maximum scaling factor of Matrix by decomposing the scaling and |
| 4205 | skewing elements. |
| 4206 | Returns -1 if scale factor overflows or Matrix contains perspective. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4207 | |
| 4208 | #Return maximum scale factor |
| 4209 | ## |
| 4210 | |
| 4211 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4212 | SkMatrix matrix; |
| 4213 | matrix.setScale(42, 24); |
| 4214 | SkDebugf("matrix.getMaxScale() %g\n", matrix.getMaxScale()); |
| 4215 | #StdOut |
| 4216 | matrix.getMaxScale() 42 |
| 4217 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4218 | ## |
| 4219 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4220 | #SeeAlso getMinScale getMinMaxScales |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4221 | |
| 4222 | ## |
| 4223 | |
| 4224 | # ------------------------------------------------------------------------------ |
| 4225 | |
| 4226 | #Method bool SK_WARN_UNUSED_RESULT getMinMaxScales(SkScalar scaleFactors[2]) const |
| 4227 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4228 | #Line # Returns minimum and maximum scaling, if possible. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4229 | Sets scaleFactors[0] to the minimum scaling factor, and scaleFactors[1] to the |
| 4230 | maximum scaling factor. Scaling factors are computed by decomposing |
| 4231 | the Matrix scaling and skewing elements. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4232 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4233 | Returns true if scaleFactors are found; otherwise, returns false and sets |
| 4234 | scaleFactors to undefined values. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4235 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4236 | #Param scaleFactors storage for minimum and maximum scale factors ## |
| 4237 | |
| 4238 | #Return true if scale factors were computed correctly ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4239 | |
| 4240 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4241 | 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 |
| 4248 | matrix.getMinMaxScales() false 2 2 |
| 4249 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4250 | ## |
| 4251 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4252 | #SeeAlso getMinScale getMaxScale |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4253 | |
| 4254 | ## |
| 4255 | |
| 4256 | # ------------------------------------------------------------------------------ |
| 4257 | |
| 4258 | #Method bool decomposeScale(SkSize* scale, SkMatrix* remaining = nullptr) const |
| 4259 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4260 | #Line # Separates scale if possible. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4261 | Decomposes Matrix into scale components and whatever remains. Returns false if |
| 4262 | Matrix could not be decomposed. |
| 4263 | |
| 4264 | Sets scale to portion of Matrix that scales in x and y. Sets remaining to Matrix |
| 4265 | with x and y scaling factored out. remaining may be passed as nullptr |
| 4266 | to determine if Matrix can be decomposed without computing remainder. |
| 4267 | |
| 4268 | Returns true if scale components are found. scale and remaining are |
| 4269 | unchanged if Matrix contains perspective; scale factors are not finite, or |
| 4270 | are nearly zero. |
| 4271 | |
| 4272 | On success |
| 4273 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4274 | #Formula |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4275 | Matrix = scale * Remaining |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4276 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4277 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4278 | #Param scale x and y scaling factors; may be nullptr ## |
| 4279 | #Param remaining Matrix without scaling; may be nullptr ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4280 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4281 | #Return true if scale can be computed ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4282 | |
| 4283 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4284 | 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] |
| 4300 | success: 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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4304 | ## |
| 4305 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4306 | #SeeAlso setScale MakeScale |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4307 | |
| 4308 | ## |
| 4309 | |
| 4310 | # ------------------------------------------------------------------------------ |
| 4311 | |
| 4312 | #Method static const SkMatrix& I() |
| 4313 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4314 | #Line # Returns a reference to a const identity Matrix. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4315 | Returns reference to const identity Matrix. Returned Matrix is set to: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4316 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4317 | #Code |
| 4318 | #Literal |
| 4319 | | 1 0 0 | |
| 4320 | | 0 1 0 | |
| 4321 | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4322 | ## |
| 4323 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4324 | #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 |
| 4334 | m1 == m2 |
| 4335 | m2 == m3 |
| 4336 | ## |
| 4337 | ## |
| 4338 | |
| 4339 | #SeeAlso reset() setIdentity |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4340 | |
| 4341 | ## |
| 4342 | |
| 4343 | # ------------------------------------------------------------------------------ |
| 4344 | |
| 4345 | #Method static const SkMatrix& InvalidMatrix() |
| 4346 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4347 | #Line # Returns a reference to a const invalid Matrix. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4348 | Returns reference to a const Matrix with invalid values. Returned Matrix is set |
| 4349 | to: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4350 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4351 | #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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4356 | ## |
| 4357 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4358 | #Return const invalid Matrix ## |
| 4359 | |
| 4360 | #Example |
| 4361 | SkDebugf("scaleX %g\n", SkMatrix::InvalidMatrix().getScaleX()); |
| 4362 | #StdOut |
| 4363 | scaleX 3.40282e+38 |
| 4364 | ## |
| 4365 | ## |
| 4366 | |
| 4367 | #SeeAlso SeeAlso getType |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4368 | |
| 4369 | ## |
| 4370 | |
| 4371 | # ------------------------------------------------------------------------------ |
| 4372 | |
| 4373 | #Method static SkMatrix Concat(const SkMatrix& a, const SkMatrix& b) |
| 4374 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4375 | #Line # Returns the concatenation of Matrix pair. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4376 | Returns Matrix a multiplied by Matrix b. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4377 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4378 | Given: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4379 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4380 | #Code |
| 4381 | #Literal |
| 4382 | | A B C | | J K L | |
| 4383 | a = | D E F |, b = | M N O | |
| 4384 | | G H I | | P Q R | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4385 | ## |
| 4386 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4387 | sets Matrix to: |
| 4388 | |
| 4389 | #Code |
| 4390 | #Literal |
| 4391 | | A B C | | J K L | | AJ+BM+CP AK+BN+CQ AL+BO+CR | |
| 4392 | a * 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 |
| 4405 | setPolyToPoly creates perspective matrices, one the inverse of the other. |
| 4406 | Multiplying the matrix by its inverse turns into an identity matrix. |
| 4407 | ## |
| 4408 | SkMatrix matrix, matrix2; |
| 4409 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 4410 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 4411 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 4412 | matrix2.setPolyToPoly(perspect, bitmapBounds, 4); |
| 4413 | SkMatrix concat = SkMatrix::Concat(matrix, matrix2); |
| 4414 | canvas->concat(concat); |
| 4415 | canvas->drawBitmap(source, 0, 0); |
| 4416 | ## |
| 4417 | |
| 4418 | #SeeAlso preConcat postConcat |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4419 | |
| 4420 | ## |
| 4421 | |
| 4422 | # ------------------------------------------------------------------------------ |
| 4423 | |
| 4424 | #Method void dirtyMatrixTypeCache() |
| 4425 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4426 | #Line # Sets internal cache to unknown state. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4427 | Sets internal cache to unknown state. Use to force update after repeated |
| 4428 | modifications to Matrix element reference returned by operator[](int index). |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4429 | |
| 4430 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4431 | SkMatrix matrix; |
| 4432 | matrix.setIdentity(); |
| 4433 | SkDebugf("with identity matrix: x = %g\n", matrix.mapXY(24, 42).fX); |
| 4434 | SkScalar& skewRef = matrix[SkMatrix::kMSkewX]; |
| 4435 | skewRef = 0; |
| 4436 | SkDebugf("after skew x mod: x = %g\n", matrix.mapXY(24, 42).fX); |
| 4437 | skewRef = 1; |
| 4438 | SkDebugf("after 2nd skew x mod: x = %g\n", matrix.mapXY(24, 42).fX); |
| 4439 | matrix.dirtyMatrixTypeCache(); |
| 4440 | SkDebugf("after dirty cache: x = %g\n", matrix.mapXY(24, 42).fX); |
| 4441 | #StdOut |
| 4442 | with identity matrix: x = 24 |
| 4443 | after skew x mod: x = 24 |
| 4444 | after 2nd skew x mod: x = 24 |
| 4445 | after dirty cache: x = 66 |
| 4446 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4447 | ## |
| 4448 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4449 | #SeeAlso operator[](int index) getType |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4450 | |
| 4451 | ## |
| 4452 | |
| 4453 | # ------------------------------------------------------------------------------ |
| 4454 | |
| 4455 | #Method void setScaleTranslate(SkScalar sx, SkScalar sy, SkScalar tx, SkScalar ty) |
| 4456 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4457 | #Line # Sets to scale and translate. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4458 | Initializes Matrix with scale and translate elements. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4459 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4460 | #Code |
| 4461 | #Literal |
| 4462 | | sx 0 tx | |
| 4463 | | 0 sy ty | |
| 4464 | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4465 | ## |
| 4466 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4467 | #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 |
| 4473 | SkMatrix matrix; |
| 4474 | matrix.setScaleTranslate(1, 2, 3, 4); |
| 4475 | matrix.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 Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4482 | |
| 4483 | ## |
| 4484 | |
| 4485 | # ------------------------------------------------------------------------------ |
| 4486 | |
| 4487 | #Method bool isFinite() const |
| 4488 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4489 | #Line # Returns if all Matrix values are not infinity, NaN. ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4490 | Returns true if all elements of the matrix are finite. Returns false if any |
| 4491 | element is infinity, or NaN. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4492 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4493 | #Return true if matrix has only finite elements ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4494 | |
| 4495 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4496 | SkMatrix matrix = SkMatrix::MakeTrans(SK_ScalarNaN, 0); |
| 4497 | matrix.dump(); |
| 4498 | SkDebugf("matrix is finite: %s\n", matrix.isFinite() ? "true" : "false"); |
| 4499 | SkDebugf("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] |
| 4502 | matrix is finite: false |
| 4503 | matrix != matrix |
| 4504 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4505 | ## |
| 4506 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4507 | #SeeAlso operator== |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4508 | |
| 4509 | ## |
| 4510 | |
| 4511 | #Class SkMatrix ## |
| 4512 | |
| 4513 | #Topic Matrix ## |