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 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 5 | #Subtopic Overview |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 6 | #Subtopic Subtopic |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 7 | #Populate |
| 8 | ## |
| 9 | ## |
| 10 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 11 | #Class SkMatrix |
| 12 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 13 | Matrix holds a 3x3 matrix for transforming coordinates. This allows mapping |
| 14 | Points and Vectors with translation, scaling, skewing, rotation, and |
| 15 | perspective. |
Cary Clark | 884dd7d | 2017-10-11 10:37:52 -0400 | [diff] [blame] | 16 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 17 | Matrix elements are in row major order. Matrix does not have a constructor, |
| 18 | so it must be explicitly initialized. setIdentity initializes Matrix |
| 19 | so it has no effect. setTranslate, setScale, setSkew, setRotate, set9 and setAll |
| 20 | initializes all Matrix elements with the corresponding mapping. |
Cary Clark | 884dd7d | 2017-10-11 10:37:52 -0400 | [diff] [blame] | 21 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 22 | Matrix includes a hidden variable that classifies the type of matrix to |
| 23 | improve performance. Matrix is not thread safe unless getType is called first. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 24 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 25 | #Subtopic Member_Function |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 26 | #Populate |
| 27 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 28 | |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 29 | #Subtopic Related_Function |
| 30 | #Populate |
| 31 | ## |
| 32 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 33 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 34 | #Subtopic Constructor |
| 35 | #Populate |
| 36 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 37 | |
| 38 | #Method static SkMatrix SK_WARN_UNUSED_RESULT MakeScale(SkScalar sx, SkScalar sy) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 39 | #In Constructor |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 40 | #Line # constructs from scale in x and y ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 41 | Sets Matrix to scale by (sx, sy). Returned matrix is: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 42 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 43 | #Code |
| 44 | #Literal |
| 45 | | sx 0 0 | |
| 46 | | 0 sy 0 | |
| 47 | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 48 | ## |
| 49 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 50 | #Param sx horizontal scale factor ## |
| 51 | #Param sy vertical scale factor ## |
| 52 | |
| 53 | #Return Matrix with scale ## |
| 54 | |
| 55 | #Example |
| 56 | #Image 4 |
| 57 | canvas->concat(SkMatrix::MakeScale(4, 3)); |
| 58 | canvas->drawBitmap(source, 0, 0); |
| 59 | ## |
| 60 | |
| 61 | #SeeAlso setScale postScale preScale |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 62 | |
| 63 | ## |
| 64 | |
| 65 | # ------------------------------------------------------------------------------ |
| 66 | |
| 67 | #Method static SkMatrix SK_WARN_UNUSED_RESULT MakeScale(SkScalar scale) |
| 68 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 69 | Sets Matrix to scale by (scale, scale). Returned matrix is: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 70 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 71 | #Code |
| 72 | #Literal |
| 73 | | scale 0 0 | |
| 74 | | 0 scale 0 | |
| 75 | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 76 | ## |
| 77 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 78 | #Param scale horizontal and vertical scale factor ## |
| 79 | |
| 80 | #Return Matrix with scale ## |
| 81 | |
| 82 | #Example |
| 83 | #Image 4 |
| 84 | canvas->concat(SkMatrix::MakeScale(4)); |
| 85 | canvas->drawBitmap(source, 0, 0); |
| 86 | ## |
| 87 | |
| 88 | #SeeAlso setScale postScale preScale |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 89 | |
| 90 | ## |
| 91 | |
| 92 | # ------------------------------------------------------------------------------ |
| 93 | |
| 94 | #Method static SkMatrix SK_WARN_UNUSED_RESULT MakeTrans(SkScalar dx, SkScalar dy) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 95 | #In Constructor |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 96 | #Line # constructs from translate in x and y ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 97 | Sets Matrix to translate by (dx, dy). Returned matrix is: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 98 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 99 | #Code |
| 100 | #Literal |
Cary Clark | cfee6ec | 2017-10-26 10:34:05 -0400 | [diff] [blame] | 101 | | 1 0 dx | |
| 102 | | 0 1 dy | |
| 103 | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 104 | ## |
| 105 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 106 | #Param dx horizontal translation ## |
| 107 | #Param dy vertical translation ## |
| 108 | |
| 109 | #Return Matrix with translation ## |
| 110 | |
| 111 | #Example |
| 112 | #Image 4 |
| 113 | SkMatrix matrix = SkMatrix::MakeTrans(64, 48); |
| 114 | for (int i = 0; i < 4; ++i) { |
| 115 | canvas->drawBitmap(source, 0, 0); |
| 116 | canvas->concat(matrix); |
| 117 | } |
| 118 | ## |
| 119 | |
| 120 | #SeeAlso setTranslate postTranslate preTranslate |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 121 | |
| 122 | ## |
| 123 | |
| 124 | # ------------------------------------------------------------------------------ |
| 125 | |
Cary Clark | bef063a | 2017-10-31 15:44:45 -0400 | [diff] [blame] | 126 | #Method static SkMatrix SK_WARN_UNUSED_RESULT MakeAll(SkScalar scaleX, SkScalar skewX, SkScalar transX, |
| 127 | SkScalar skewY, SkScalar scaleY, SkScalar transY, |
| 128 | SkScalar pers0, SkScalar pers1, SkScalar pers2) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 129 | #In Constructor |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 130 | #Line # constructs all nine values ## |
Cary Clark | bef063a | 2017-10-31 15:44:45 -0400 | [diff] [blame] | 131 | |
| 132 | |
| 133 | Sets Matrix to: |
| 134 | |
| 135 | #Code |
| 136 | #Literal |
| 137 | | scaleX skewX transX | |
| 138 | | skewY scaleY transY | |
| 139 | | pers0 pers1 pers2 | |
| 140 | ## |
| 141 | |
| 142 | #Param scaleX horizontal scale factor ## |
| 143 | #Param skewX horizontal skew factor ## |
| 144 | #Param transX horizontal translation ## |
| 145 | #Param skewY vertical skew factor ## |
| 146 | #Param scaleY vertical scale factor ## |
| 147 | #Param transY vertical translation ## |
| 148 | #Param pers0 input x perspective factor ## |
| 149 | #Param pers1 input y perspective factor ## |
| 150 | #Param pers2 perspective scale factor ## |
| 151 | |
| 152 | #Return Matrix constructed from parameters ## |
| 153 | |
| 154 | #Example |
| 155 | SkPaint p; |
| 156 | p.setAntiAlias(true); |
| 157 | p.setTextSize(64); |
| 158 | for (SkScalar sx : { -1, 1 } ) { |
| 159 | for (SkScalar sy : { -1, 1 } ) { |
| 160 | SkAutoCanvasRestore autoRestore(canvas, true); |
| 161 | SkMatrix m = SkMatrix::MakeAll(sx, 1, 128, 0, sy, 128, 0, 0, 1); |
| 162 | canvas->concat(m); |
| 163 | canvas->drawString("K", 0, 0, p); |
| 164 | } |
| 165 | } |
| 166 | ## |
| 167 | |
| 168 | #SeeAlso setAll set9 postConcat preConcat |
| 169 | |
| 170 | ## |
| 171 | |
| 172 | |
| 173 | # ------------------------------------------------------------------------------ |
| 174 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 175 | #Enum TypeMask |
| 176 | |
| 177 | #Code |
| 178 | enum TypeMask { |
| 179 | kIdentity_Mask = 0, |
| 180 | kTranslate_Mask = 0x01, |
| 181 | kScale_Mask = 0x02, |
| 182 | kAffine_Mask = 0x04, |
| 183 | kPerspective_Mask = 0x08, |
| 184 | }; |
| 185 | ## |
| 186 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 187 | Enum of bit fields for mask returned by getType. |
| 188 | Used to identify the complexity of Matrix, to optimize performance. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 189 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 190 | #Const kIdentity_Mask 0 |
| 191 | all bits clear if Matrix is identity |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 192 | ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 193 | #Const kTranslate_Mask 1 |
| 194 | set if Matrix has translation |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 195 | ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 196 | #Const kScale_Mask 2 |
| 197 | set if Matrix has x or y scale |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 198 | ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 199 | #Const kAffine_Mask 4 |
| 200 | set if Matrix skews or rotates |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 201 | ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 202 | #Const kPerspective_Mask 8 |
| 203 | set if Matrix has perspective |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 204 | ## |
| 205 | |
| 206 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 207 | auto debugster = [](const char* prefix, const SkMatrix& matrix) -> void { |
| 208 | SkString typeMask; |
| 209 | typeMask += SkMatrix::kIdentity_Mask == matrix.getType() ? "kIdentity_Mask " : ""; |
| 210 | typeMask += SkMatrix::kTranslate_Mask & matrix.getType() ? "kTranslate_Mask " : ""; |
| 211 | typeMask += SkMatrix::kScale_Mask & matrix.getType() ? "kScale_Mask " : ""; |
| 212 | typeMask += SkMatrix::kAffine_Mask & matrix.getType() ? "kAffine_Mask " : ""; |
| 213 | typeMask += SkMatrix::kPerspective_Mask & matrix.getType() ? "kPerspective_Mask" : ""; |
| 214 | SkDebugf("after %s: %s\n", prefix, typeMask.c_str()); |
| 215 | }; |
| 216 | SkMatrix matrix; |
| 217 | matrix.reset(); |
| 218 | debugster("reset", matrix); |
| 219 | matrix.postTranslate(1, 0); |
| 220 | debugster("postTranslate", matrix); |
| 221 | matrix.postScale(2, 1); |
| 222 | debugster("postScale", matrix); |
| 223 | matrix.postRotate(45); |
| 224 | debugster("postScale", matrix); |
| 225 | SkPoint polys[][4] = {{{0, 0}, {0, 1}, {1, 1}, {1, 0}}, {{0, 0}, {0, 1}, {2, 1}, {1, 0}}}; |
| 226 | matrix.setPolyToPoly(polys[0], polys[1], 4); |
| 227 | debugster("setPolyToPoly", matrix); |
| 228 | #StdOut |
| 229 | after reset: kIdentity_Mask |
| 230 | after postTranslate: kTranslate_Mask |
| 231 | after postScale: kTranslate_Mask kScale_Mask |
| 232 | after postScale: kTranslate_Mask kScale_Mask kAffine_Mask |
| 233 | after setPolyToPoly: kTranslate_Mask kScale_Mask kAffine_Mask kPerspective_Mask |
| 234 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 235 | ## |
| 236 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 237 | #SeeAlso getType |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 238 | |
| 239 | ## |
| 240 | |
| 241 | # ------------------------------------------------------------------------------ |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 242 | #Subtopic Property |
| 243 | #Populate |
| 244 | #Line # values and attributes ## |
| 245 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 246 | |
| 247 | #Method TypeMask getType() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 248 | #In Property |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 249 | #Line # returns transform complexity ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 250 | Returns a bit field describing the transformations the matrix may |
| 251 | perform. The bit field is computed conservatively, so it may include |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 252 | false positives. For example, when kPerspective_Mask is set, all |
| 253 | other bits are set. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 254 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 255 | #Return kIdentity_Mask, or combinations of: kTranslate_Mask, kScale_Mask, |
| 256 | kAffine_Mask, kPerspective_Mask |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 257 | ## |
| 258 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 259 | #Example |
| 260 | SkMatrix matrix; |
| 261 | matrix.setAll(1, 0, 0, 0, 1, 0, 0, 0, 1); |
| 262 | SkDebugf("identity flags hex: %0x decimal: %d\n", matrix.getType(), matrix.getType()); |
| 263 | matrix.setAll(1, 0, 0, 0, 1, 0, 0, 0, .5f); |
| 264 | SkDebugf("set all flags hex: %0x decimal: %d\n", matrix.getType(), matrix.getType()); |
| 265 | #StdOut |
| 266 | identity flags hex: 0 decimal: 0 |
| 267 | set all flags hex: f decimal: 15 |
| 268 | ## |
| 269 | ## |
| 270 | |
| 271 | #SeeAlso TypeMask |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 272 | |
| 273 | ## |
| 274 | |
| 275 | # ------------------------------------------------------------------------------ |
| 276 | |
| 277 | #Method bool isIdentity() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 278 | #In Property |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 279 | #Line # returns if matrix equals the identity Matrix ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 280 | Returns true if Matrix is identity. Identity matrix is: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 281 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 282 | #Code |
| 283 | #Literal |
| 284 | | 1 0 0 | |
| 285 | | 0 1 0 | |
| 286 | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 287 | ## |
| 288 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 289 | #Return true if Matrix has no effect ## |
| 290 | |
| 291 | #Example |
| 292 | SkMatrix matrix; |
| 293 | matrix.setAll(1, 0, 0, 0, 1, 0, 0, 0, 1); |
| 294 | SkDebugf("is identity: %s\n", matrix.isIdentity() ? "true" : "false"); |
| 295 | matrix.setAll(1, 0, 0, 0, 1, 0, 0, 0, 2); |
| 296 | SkDebugf("is identity: %s\n", matrix.isIdentity() ? "true" : "false"); |
| 297 | #StdOut |
| 298 | is identity: true |
| 299 | is identity: false |
| 300 | ## |
| 301 | ## |
| 302 | |
| 303 | #SeeAlso reset() setIdentity getType |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 304 | |
| 305 | ## |
| 306 | |
| 307 | # ------------------------------------------------------------------------------ |
| 308 | |
| 309 | #Method bool isScaleTranslate() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 310 | #In Property |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 311 | #Line # returns if transform is limited to scale and translate ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 312 | Returns true if Matrix at most scales and translates. Matrix may be identity, |
| 313 | contain only scale elements, only translate elements, or both. Matrix form is: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 314 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 315 | #Code |
| 316 | #Literal |
| 317 | | scale-x 0 translate-x | |
| 318 | | 0 scale-y translate-y | |
| 319 | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 320 | ## |
| 321 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 322 | #Return true if Matrix is identity; or scales, translates, or both ## |
| 323 | |
| 324 | #Example |
| 325 | SkMatrix matrix; |
| 326 | for (SkScalar scaleX : { 1, 2 } ) { |
| 327 | for (SkScalar translateX : { 0, 20 } ) { |
| 328 | matrix.setAll(scaleX, 0, translateX, 0, 1, 0, 0, 0, 1); |
| 329 | SkDebugf("is scale-translate: %s\n", matrix.isScaleTranslate() ? "true" : "false"); |
| 330 | } |
| 331 | } |
| 332 | #StdOut |
| 333 | is scale-translate: true |
| 334 | is scale-translate: true |
| 335 | is scale-translate: true |
| 336 | is scale-translate: true |
| 337 | ## |
| 338 | ## |
| 339 | |
| 340 | #SeeAlso setScale isTranslate setTranslate getType |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 341 | |
| 342 | ## |
| 343 | |
| 344 | # ------------------------------------------------------------------------------ |
| 345 | |
| 346 | #Method bool isTranslate() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 347 | #In Property |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 348 | #Line # returns if transform is limited to translate ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 349 | Returns true if Matrix is identity, or translates. Matrix form is: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 350 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 351 | #Code |
| 352 | #Literal |
| 353 | | 1 0 translate-x | |
| 354 | | 0 1 translate-y | |
| 355 | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 356 | ## |
| 357 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 358 | #Return true if Matrix is identity, or translates ## |
| 359 | |
| 360 | #Example |
| 361 | SkMatrix matrix; |
| 362 | for (SkScalar scaleX : { 1, 2 } ) { |
| 363 | for (SkScalar translateX : { 0, 20 } ) { |
| 364 | matrix.setAll(scaleX, 0, translateX, 0, 1, 0, 0, 0, 1); |
| 365 | SkDebugf("is translate: %s\n", matrix.isTranslate() ? "true" : "false"); |
| 366 | } |
| 367 | } |
| 368 | #StdOut |
| 369 | is translate: true |
| 370 | is translate: true |
| 371 | is translate: false |
| 372 | is translate: false |
| 373 | ## |
| 374 | ## |
| 375 | |
| 376 | #SeeAlso setTranslate getType |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 377 | |
| 378 | ## |
| 379 | |
| 380 | # ------------------------------------------------------------------------------ |
| 381 | |
| 382 | #Method bool rectStaysRect() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 383 | #In Property |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 384 | #Line # returns if mapped Rect can be represented by another Rect ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 385 | Returns true Matrix maps Rect to another Rect. If true, Matrix is identity, |
| 386 | or scales, or rotates a multiple of 90 degrees, or mirrors in x or y. In all |
| 387 | cases, Matrix may also have translation. Matrix form is either: |
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 | | scale-x 0 translate-x | |
| 392 | | 0 scale-y translate-y | |
| 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 | or |
| 397 | |
| 398 | #Code |
| 399 | #Literal |
| 400 | | 0 rotate-x translate-x | |
| 401 | | rotate-y 0 translate-y | |
| 402 | | 0 0 1 | |
| 403 | ## |
| 404 | |
| 405 | for non-zero values of scale-x, scale-y, rotate-x, and rotate-y. |
| 406 | |
| 407 | Also called preservesAxisAlignment; use the one that provides better inline |
| 408 | documentation. |
| 409 | |
| 410 | #Return true if Matrix maps one Rect into another ## |
| 411 | |
| 412 | #Example |
| 413 | SkMatrix matrix; |
| 414 | for (SkScalar angle: { 0, 90, 180, 270 } ) { |
| 415 | matrix.setRotate(angle); |
| 416 | SkDebugf("rectStaysRect: %s\n", matrix.rectStaysRect() ? "true" : "false"); |
| 417 | } |
| 418 | #StdOut |
| 419 | rectStaysRect: true |
| 420 | rectStaysRect: true |
| 421 | rectStaysRect: true |
| 422 | rectStaysRect: true |
| 423 | ## |
| 424 | ## |
| 425 | |
| 426 | #SeeAlso preservesAxisAlignment preservesRightAngles |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 427 | |
| 428 | ## |
| 429 | |
| 430 | # ------------------------------------------------------------------------------ |
| 431 | |
| 432 | #Method bool preservesAxisAlignment() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 433 | #In Property |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 434 | #Line # returns if mapping restricts to 90 degree multiples and mirroring ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 435 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 436 | Returns true Matrix maps Rect to another Rect. If true, Matrix is identity, |
| 437 | or scales, or rotates a multiple of 90 degrees, or mirrors in x or y. In all |
| 438 | cases, Matrix may also have translation. Matrix form is either: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 439 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 440 | #Code |
| 441 | #Literal |
| 442 | | scale-x 0 translate-x | |
| 443 | | 0 scale-y translate-y | |
| 444 | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 445 | ## |
| 446 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 447 | or |
| 448 | |
| 449 | #Code |
| 450 | #Literal |
| 451 | | 0 rotate-x translate-x | |
| 452 | | rotate-y 0 translate-y | |
| 453 | | 0 0 1 | |
| 454 | ## |
| 455 | |
| 456 | for non-zero values of scale-x, scale-y, rotate-x, and rotate-y. |
| 457 | |
| 458 | Also called rectStaysRect; use the one that provides better inline |
| 459 | documentation. |
| 460 | |
| 461 | #Return true if Matrix maps one Rect into another ## |
| 462 | |
| 463 | #Example |
| 464 | SkMatrix matrix; |
| 465 | for (SkScalar angle: { 0, 90, 180, 270 } ) { |
| 466 | matrix.setRotate(angle); |
| 467 | SkDebugf("preservesAxisAlignment: %s\n", matrix.preservesAxisAlignment() ? "true" : "false"); |
| 468 | } |
| 469 | #StdOut |
| 470 | preservesAxisAlignment: true |
| 471 | preservesAxisAlignment: true |
| 472 | preservesAxisAlignment: true |
| 473 | preservesAxisAlignment: true |
| 474 | ## |
| 475 | ## |
| 476 | |
| 477 | #SeeAlso rectStaysRect preservesRightAngles |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 478 | |
| 479 | ## |
| 480 | |
| 481 | # ------------------------------------------------------------------------------ |
| 482 | |
| 483 | #Method bool hasPerspective() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 484 | #In Property |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 485 | #Line # returns if transform includes perspective ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 486 | Returns true if the matrix contains perspective elements. Matrix form is: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 487 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 488 | #Code |
| 489 | #Literal |
| 490 | | -- -- -- | |
| 491 | | -- -- -- | |
| 492 | | perspective-x perspective-y perspective-scale | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 493 | ## |
| 494 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 495 | where perspective-x or perspective-y is non-zero, or perspective-scale is |
| 496 | not one. All other elements may have any value. |
| 497 | |
| 498 | #Return true if Matrix is in most general form ## |
| 499 | |
| 500 | #Example |
| 501 | #Image 4 |
| 502 | SkMatrix matrix; |
| 503 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 504 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 505 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 506 | canvas->concat(matrix); |
| 507 | SkString string; |
| 508 | string.printf("hasPerspective %s", matrix.hasPerspective() ? "true" : "false"); |
| 509 | canvas->drawBitmap(source, 0, 0); |
| 510 | SkPaint paint; |
| 511 | paint.setAntiAlias(true); |
| 512 | paint.setTextSize(48); |
| 513 | canvas->drawString(string, 0, source.bounds().height() + 48, paint); |
| 514 | ## |
| 515 | |
Cary Clark | bef063a | 2017-10-31 15:44:45 -0400 | [diff] [blame] | 516 | #SeeAlso setAll set9 MakeAll |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 517 | |
| 518 | ## |
| 519 | |
| 520 | # ------------------------------------------------------------------------------ |
| 521 | |
| 522 | #Method bool isSimilarity(SkScalar tol = SK_ScalarNearlyZero) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 523 | #In Property |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 524 | #Line # returns if transform is limited to square scale and rotation ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 525 | Returns true if Matrix contains only translation, rotation, reflection, and |
| 526 | uniform scale. |
| 527 | Returns false if Matrix contains different scales, skewing, perspective, or |
| 528 | degenerate forms that collapse to a line or point. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 529 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 530 | Describes that the Matrix makes rendering with and without the matrix are |
| 531 | visually alike; a transformed circle remains a circle. Mathematically, this is |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 532 | referred to as similarity of a Euclidean_Space, or a similarity transformation. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 533 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 534 | Preserves right angles, keeping the arms of the angle equal lengths. |
| 535 | |
| 536 | #Param tol to be deprecated ## |
| 537 | |
| 538 | #Return true if Matrix only rotates, uniformly scales, translates ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 539 | |
| 540 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 541 | #Description |
| 542 | String is drawn four times through but only two are visible. Drawing the pair |
| 543 | with isSimilarity false reveals the pair not visible through the matrix. |
| 544 | ## |
| 545 | SkPaint p; |
| 546 | p.setAntiAlias(true); |
| 547 | SkMatrix m; |
| 548 | int below = 175; |
| 549 | for (SkScalar sx : { -1, 1 } ) { |
| 550 | for (SkScalar sy : { -1, 1 } ) { |
| 551 | m.setAll(sx, 1, 128, 1, sy, 32, 0, 0, 1); |
| 552 | bool isSimilarity = m.isSimilarity(); |
| 553 | SkString str; |
| 554 | str.printf("sx: %g sy: %g sim: %s", sx, sy, isSimilarity ? "true" : "false"); |
| 555 | { |
| 556 | SkAutoCanvasRestore autoRestore(canvas, true); |
| 557 | canvas->concat(m); |
| 558 | canvas->drawString(str, 0, 0, p); |
| 559 | } |
| 560 | if (!isSimilarity) { |
| 561 | canvas->drawString(str, 40, below, p); |
| 562 | below += 20; |
| 563 | } |
| 564 | } |
| 565 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 566 | ## |
| 567 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 568 | #SeeAlso isScaleTranslate preservesRightAngles rectStaysRect isFixedStepInX |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 569 | |
| 570 | ## |
| 571 | |
| 572 | # ------------------------------------------------------------------------------ |
| 573 | |
| 574 | #Method bool preservesRightAngles(SkScalar tol = SK_ScalarNearlyZero) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 575 | #In Property |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 576 | #Line # returns if mapped 90 angle remains 90 degrees ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 577 | Returns true if Matrix contains only translation, rotation, reflection, and |
| 578 | scale. Scale may differ along rotated axes. |
| 579 | Returns false if Matrix skewing, perspective, or degenerate forms that collapse |
| 580 | to a line or point. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 581 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 582 | Preserves right angles, but not requiring that the arms of the angle |
| 583 | retain equal lengths. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 584 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 585 | #Param tol to be deprecated ## |
| 586 | |
| 587 | #Return true if Matrix only rotates, scales, translates ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 588 | |
| 589 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 590 | #Height 128 |
| 591 | #Description |
| 592 | Equal scale is both similar and preserves right angles. |
| 593 | Unequal scale is not similar but preserves right angles. |
| 594 | Skews are not similar and do not preserve right angles. |
| 595 | ## |
| 596 | SkPaint p; |
| 597 | p.setAntiAlias(true); |
| 598 | SkMatrix m; |
| 599 | int pos = 0; |
| 600 | for (SkScalar sx : { 1, 2 } ) { |
| 601 | for (SkScalar kx : { 0, 1 } ) { |
| 602 | m.setAll(sx, kx, 16, 0, 1, 32, 0, 0, 1); |
| 603 | bool isSimilarity = m.isSimilarity(); |
| 604 | bool preservesRightAngles = m.preservesRightAngles(); |
| 605 | SkString str; |
| 606 | str.printf("sx: %g kx: %g %s %s", sx, kx, isSimilarity ? "sim" : "", |
| 607 | preservesRightAngles ? "right" : ""); |
| 608 | SkAutoCanvasRestore autoRestore(canvas, true); |
| 609 | canvas->concat(m); |
| 610 | canvas->drawString(str, 0, pos, p); |
| 611 | pos += 20; |
| 612 | } |
| 613 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 614 | ## |
| 615 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 616 | #SeeAlso isScaleTranslate isSimilarity rectStaysRect isFixedStepInX |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 617 | |
| 618 | ## |
| 619 | |
| 620 | # ------------------------------------------------------------------------------ |
| 621 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 622 | #Enum |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 623 | |
| 624 | #Code |
| 625 | enum { |
| 626 | kMScaleX, |
| 627 | kMSkewX, |
| 628 | kMTransX, |
| 629 | kMSkewY, |
| 630 | kMScaleY, |
| 631 | kMTransY, |
| 632 | kMPersp0, |
| 633 | kMPersp1, |
| 634 | kMPersp2, |
| 635 | }; |
| 636 | ## |
| 637 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 638 | Matrix organizes its values in row order. These members correspond to |
| 639 | each value in Matrix. |
| 640 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 641 | #Const kMScaleX 0 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 642 | horizontal scale factor |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 643 | ## |
| 644 | #Const kMSkewX 1 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 645 | horizontal skew factor |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 646 | ## |
| 647 | #Const kMTransX 2 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 648 | horizontal translation |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 649 | ## |
| 650 | #Const kMSkewY 3 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 651 | vertical skew factor |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 652 | ## |
| 653 | #Const kMScaleY 4 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 654 | vertical scale factor |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 655 | ## |
| 656 | #Const kMTransY 5 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 657 | vertical translation |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 658 | ## |
| 659 | #Const kMPersp0 6 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 660 | input x perspective factor |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 661 | ## |
| 662 | #Const kMPersp1 7 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 663 | input y perspective factor |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 664 | ## |
| 665 | #Const kMPersp2 8 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 666 | perspective bias |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 667 | ## |
| 668 | |
| 669 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 670 | SkPaint black; |
| 671 | black.setAntiAlias(true); |
| 672 | black.setTextSize(48); |
| 673 | SkPaint gray = black; |
| 674 | gray.setColor(0xFF9f9f9f); |
| 675 | SkScalar offset[] = { 1.5f, 1.5f, 20, 1.5f, 1.5f, 20, .03f, .01f, 2 }; |
| 676 | for (int i : { SkMatrix::kMScaleX, SkMatrix::kMSkewX, SkMatrix::kMTransX, |
| 677 | SkMatrix::kMSkewY, SkMatrix::kMScaleY, SkMatrix::kMTransY, |
| 678 | SkMatrix::kMPersp0, SkMatrix::kMPersp1, SkMatrix::kMPersp2 } ) { |
| 679 | SkMatrix m; |
| 680 | m.setIdentity(); |
| 681 | m.set(i, offset[i]); |
| 682 | SkAutoCanvasRestore autoRestore(canvas, true); |
| 683 | canvas->translate(22 + (i % 3) * 88, 44 + (i / 3) * 88); |
| 684 | canvas->drawString("&", 0, 0, gray); |
| 685 | canvas->concat(m); |
| 686 | canvas->drawString("&", 0, 0, black); |
| 687 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 688 | ## |
| 689 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 690 | #SeeAlso get() set() |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 691 | |
| 692 | ## |
| 693 | |
| 694 | # ------------------------------------------------------------------------------ |
| 695 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 696 | #Enum |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 697 | |
| 698 | #Code |
| 699 | enum { |
| 700 | kAScaleX, |
| 701 | kASkewY, |
| 702 | kASkewX, |
| 703 | kAScaleY, |
| 704 | kATransX, |
| 705 | kATransY, |
| 706 | }; |
| 707 | ## |
| 708 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 709 | Affine arrays are in column major order to match the matrix used by |
| 710 | PDF and XPS. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 711 | |
| 712 | #Const kAScaleX 0 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 713 | horizontal scale factor |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 714 | ## |
| 715 | #Const kASkewY 1 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 716 | vertical skew factor |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 717 | ## |
| 718 | #Const kASkewX 2 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 719 | horizontal skew factor |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 720 | ## |
| 721 | #Const kAScaleY 3 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 722 | vertical scale factor |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 723 | ## |
| 724 | #Const kATransX 4 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 725 | horizontal translation |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 726 | ## |
| 727 | #Const kATransY 5 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 728 | vertical translation |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 729 | ## |
| 730 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 731 | #NoExample |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 732 | ## |
| 733 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 734 | #SeeAlso SetAffineIdentity asAffine setAffine |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 735 | |
| 736 | ## |
| 737 | |
| 738 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 739 | #Subtopic Operator |
| 740 | #Populate |
| 741 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 742 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 743 | #Method SkScalar operator[](int index)_const |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 744 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 745 | #Line # returns Matrix value ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 746 | Returns one matrix value. Asserts if index is out of range and SK_DEBUG is |
| 747 | defined. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 748 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 749 | #Param index one of: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY, |
| 750 | kMPersp0, kMPersp1, kMPersp2 |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 751 | ## |
| 752 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 753 | #Return value corresponding to index ## |
| 754 | |
| 755 | #Example |
| 756 | SkMatrix matrix; |
| 757 | matrix.setScale(42, 24); |
| 758 | SkDebugf("matrix[SkMatrix::kMScaleX] %c= 42\n", matrix[SkMatrix::kMScaleX] == 42 ? '=' : '!'); |
| 759 | SkDebugf("matrix[SkMatrix::kMScaleY] %c= 24\n", matrix[SkMatrix::kMScaleY] == 24 ? '=' : '!'); |
| 760 | #StdOut |
| 761 | matrix[SkMatrix::kMScaleX] == 42 |
| 762 | matrix[SkMatrix::kMScaleY] == 24 |
| 763 | ## |
| 764 | ## |
| 765 | |
| 766 | #SeeAlso get set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 767 | |
| 768 | ## |
| 769 | |
| 770 | # ------------------------------------------------------------------------------ |
| 771 | |
| 772 | #Method SkScalar get(int index) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 773 | #In Property |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 774 | #Line # returns one of nine Matrix values ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 775 | Returns one matrix value. Asserts if index is out of range and SK_DEBUG is |
| 776 | defined. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 777 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 778 | #Param index one of: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY, |
| 779 | kMPersp0, kMPersp1, kMPersp2 |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 780 | ## |
| 781 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 782 | #Return value corresponding to index ## |
| 783 | |
| 784 | #Example |
| 785 | SkMatrix matrix; |
| 786 | matrix.setSkew(42, 24); |
| 787 | SkDebugf("matrix.get(SkMatrix::kMSkewX) %c= 42\n", |
| 788 | matrix.get(SkMatrix::kMSkewX) == 42 ? '=' : '!'); |
| 789 | SkDebugf("matrix.get(SkMatrix::kMSkewY) %c= 24\n", |
| 790 | matrix.get(SkMatrix::kMSkewY) == 24 ? '=' : '!'); |
| 791 | #StdOut |
| 792 | matrix.get(SkMatrix::kMSkewX) == 42 |
| 793 | matrix.get(SkMatrix::kMSkewY) == 24 |
| 794 | ## |
| 795 | ## |
| 796 | |
| 797 | #SeeAlso operator[](int index) set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 798 | |
| 799 | ## |
| 800 | |
| 801 | # ------------------------------------------------------------------------------ |
| 802 | |
| 803 | #Method SkScalar getScaleX() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 804 | #In Property |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 805 | #Line # returns horizontal scale factor ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 806 | Returns scale factor multiplied by x input, contributing to x output. |
| 807 | With mapPoints, scales Points along the x-axis. |
| 808 | |
| 809 | #Return horizontal scale factor ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 810 | |
| 811 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 812 | SkMatrix matrix; |
| 813 | matrix.setScale(42, 24); |
| 814 | SkDebugf("matrix.getScaleX() %c= 42\n", matrix.getScaleX() == 42 ? '=' : '!'); |
| 815 | #StdOut |
| 816 | matrix.getScaleX() == 42 |
| 817 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 818 | ## |
| 819 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 820 | #SeeAlso get getScaleY setScaleX setScale |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 821 | |
| 822 | ## |
| 823 | |
| 824 | # ------------------------------------------------------------------------------ |
| 825 | |
| 826 | #Method SkScalar getScaleY() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 827 | #In Property |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 828 | #Line # returns vertical scale factor ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 829 | Returns scale factor multiplied by y input, contributing to y output. |
| 830 | With mapPoints, scales Points along the y-axis. |
| 831 | |
| 832 | #Return vertical scale factor ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 833 | |
| 834 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 835 | SkMatrix matrix; |
| 836 | matrix.setScale(42, 24); |
| 837 | SkDebugf("matrix.getScaleY() %c= 24\n", matrix.getScaleY() == 24 ? '=' : '!'); |
| 838 | #StdOut |
| 839 | matrix.getScaleY() == 24 |
| 840 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 841 | ## |
| 842 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 843 | #SeeAlso get getScaleX setScaleY setScale |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 844 | |
| 845 | ## |
| 846 | |
| 847 | # ------------------------------------------------------------------------------ |
| 848 | |
| 849 | #Method SkScalar getSkewY() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 850 | #In Property |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 851 | #Line # returns vertical skew factor ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 852 | Returns scale factor multiplied by x input, contributing to y output. |
| 853 | With mapPoints, skews Points along the y-axis. |
| 854 | Skew x and y together can rotate Points. |
| 855 | |
| 856 | #Return vertical skew factor ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 857 | |
| 858 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 859 | SkMatrix matrix; |
| 860 | matrix.setSkew(42, 24); |
| 861 | SkDebugf("matrix.getSkewY() %c= 24\n", matrix.getSkewY() == 24 ? '=' : '!'); |
| 862 | #StdOut |
| 863 | matrix.getSkewY() == 24 |
| 864 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 865 | ## |
| 866 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 867 | #SeeAlso get getSkewX setSkewY setSkew |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 868 | |
| 869 | ## |
| 870 | |
| 871 | # ------------------------------------------------------------------------------ |
| 872 | |
| 873 | #Method SkScalar getSkewX() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 874 | #In Property |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 875 | #Line # returns horizontal skew factor ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 876 | Returns scale factor multiplied by y input, contributing to x output. |
| 877 | With mapPoints, skews Points along the x-axis. |
| 878 | Skew x and y together can rotate Points. |
| 879 | |
| 880 | #Return horizontal scale factor ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 881 | |
| 882 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 883 | SkMatrix matrix; |
| 884 | matrix.setSkew(42, 24); |
| 885 | SkDebugf("matrix.getSkewX() %c= 42\n", matrix.getSkewX() == 42 ? '=' : '!'); |
| 886 | #StdOut |
| 887 | matrix.getSkewX() == 42 |
| 888 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 889 | ## |
| 890 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 891 | #SeeAlso get getSkewY setSkewX setSkew |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 892 | |
| 893 | ## |
| 894 | |
| 895 | # ------------------------------------------------------------------------------ |
| 896 | |
| 897 | #Method SkScalar getTranslateX() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 898 | #In Property |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 899 | #Line # returns horizontal translation ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 900 | Returns translation contributing to x output. |
| 901 | With mapPoints, moves Points along the x-axis. |
| 902 | |
| 903 | #Return horizontal translation factor ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 904 | |
| 905 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 906 | SkMatrix matrix; |
| 907 | matrix.setTranslate(42, 24); |
| 908 | SkDebugf("matrix.getTranslateX() %c= 42\n", matrix.getTranslateX() == 42 ? '=' : '!'); |
| 909 | #StdOut |
| 910 | matrix.getTranslateX() == 42 |
| 911 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 912 | ## |
| 913 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 914 | #SeeAlso get getTranslateY setTranslateX setTranslate |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 915 | |
| 916 | ## |
| 917 | |
| 918 | # ------------------------------------------------------------------------------ |
| 919 | |
| 920 | #Method SkScalar getTranslateY() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 921 | #In Property |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 922 | #Line # returns vertical translation ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 923 | Returns translation contributing to y output. |
| 924 | With mapPoints, moves Points along the y-axis. |
| 925 | |
| 926 | #Return vertical translation factor ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 927 | |
| 928 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 929 | SkMatrix matrix; |
| 930 | matrix.setTranslate(42, 24); |
| 931 | SkDebugf("matrix.getTranslateY() %c= 24\n", matrix.getTranslateY() == 24 ? '=' : '!'); |
| 932 | #StdOut |
| 933 | matrix.getTranslateY() == 24 |
| 934 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 935 | ## |
| 936 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 937 | #SeeAlso get getTranslateX setTranslateY setTranslate |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 938 | |
| 939 | ## |
| 940 | |
| 941 | # ------------------------------------------------------------------------------ |
| 942 | |
| 943 | #Method SkScalar getPerspX() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 944 | #In Property |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 945 | #Line # returns input x perspective factor ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 946 | Returns factor scaling input x relative to input y. |
| 947 | |
| 948 | #Return input x perspective factor ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 949 | |
| 950 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 951 | SkMatrix m; |
| 952 | m.setIdentity(); |
| 953 | m.set(SkMatrix::kMPersp0, -0.004f); |
| 954 | SkAutoCanvasRestore autoRestore(canvas, true); |
| 955 | canvas->translate(22, 144); |
| 956 | SkPaint black; |
| 957 | black.setAntiAlias(true); |
| 958 | black.setTextSize(24); |
| 959 | SkPaint gray = black; |
| 960 | gray.setColor(0xFF9f9f9f); |
| 961 | SkString string; |
| 962 | string.appendScalar(m.getPerspX()); |
| 963 | canvas->drawString(string, 0, -72, gray); |
| 964 | canvas->concat(m); |
| 965 | canvas->drawString(string, 0, 0, black); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 966 | ## |
| 967 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 968 | #SeeAlso kMPersp0 getPerspY |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 969 | |
| 970 | ## |
| 971 | |
| 972 | # ------------------------------------------------------------------------------ |
| 973 | |
| 974 | #Method SkScalar getPerspY() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 975 | #In Property |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 976 | #Line # returns input y perspective factor ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 977 | |
| 978 | Returns factor scaling input y relative to input x. |
| 979 | |
| 980 | #Return input y perspective factor ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 981 | |
| 982 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 983 | SkMatrix m; |
| 984 | m.setIdentity(); |
| 985 | m.set(SkMatrix::kMPersp1, -0.004f); |
| 986 | SkAutoCanvasRestore autoRestore(canvas, true); |
| 987 | canvas->translate(22, 144); |
| 988 | SkPaint black; |
| 989 | black.setAntiAlias(true); |
| 990 | black.setTextSize(24); |
| 991 | SkPaint gray = black; |
| 992 | gray.setColor(0xFF9f9f9f); |
| 993 | SkString string; |
| 994 | string.appendScalar(m.getPerspY()); |
| 995 | canvas->drawString(string, 0, -72, gray); |
| 996 | canvas->concat(m); |
| 997 | canvas->drawString(string, 0, 0, black); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 998 | ## |
| 999 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1000 | #SeeAlso kMPersp1 getPerspX |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1001 | |
| 1002 | ## |
| 1003 | |
| 1004 | # ------------------------------------------------------------------------------ |
| 1005 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1006 | #Method SkScalar& operator[](int index) |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1007 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1008 | #Line # returns writable reference to Matrix value ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1009 | Returns writable Matrix value. Asserts if index is out of range and SK_DEBUG is |
| 1010 | defined. Clears internal cache anticipating that caller will change Matrix value. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1011 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1012 | Next call to read Matrix state may recompute cache; subsequent writes to Matrix |
| 1013 | value must be followed by dirtyMatrixTypeCache. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1014 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1015 | #Param index one of: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY, |
| 1016 | kMPersp0, kMPersp1, kMPersp2 |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1017 | ## |
| 1018 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1019 | #Return writable value corresponding to index ## |
| 1020 | |
| 1021 | #Example |
| 1022 | SkMatrix matrix; |
| 1023 | matrix.setIdentity(); |
| 1024 | SkDebugf("with identity matrix: x = %g\n", matrix.mapXY(24, 42).fX); |
| 1025 | SkScalar& skewRef = matrix[SkMatrix::kMSkewX]; |
| 1026 | skewRef = 0; |
| 1027 | SkDebugf("after skew x mod: x = %g\n", matrix.mapXY(24, 42).fX); |
| 1028 | skewRef = 1; |
| 1029 | SkDebugf("after 2nd skew x mod: x = %g\n", matrix.mapXY(24, 42).fX); |
| 1030 | matrix.dirtyMatrixTypeCache(); |
| 1031 | SkDebugf("after dirty cache: x = %g\n", matrix.mapXY(24, 42).fX); |
| 1032 | #StdOut |
| 1033 | with identity matrix: x = 24 |
| 1034 | after skew x mod: x = 24 |
| 1035 | after 2nd skew x mod: x = 24 |
| 1036 | after dirty cache: x = 66 |
| 1037 | ## |
| 1038 | ## |
| 1039 | |
| 1040 | #SeeAlso get dirtyMatrixTypeCache set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1041 | |
| 1042 | ## |
| 1043 | |
| 1044 | # ------------------------------------------------------------------------------ |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1045 | #Subtopic Set |
| 1046 | #Populate |
| 1047 | #Line # set one or more matrix values ## |
| 1048 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1049 | |
| 1050 | #Method void set(int index, SkScalar value) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1051 | #In Set |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1052 | #Line # sets one value ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1053 | Sets Matrix value. Asserts if index is out of range and SK_DEBUG is |
| 1054 | defined. Safer than operator[]; internal cache is always maintained. |
| 1055 | |
| 1056 | #Param index one of: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY, |
| 1057 | kMPersp0, kMPersp1, kMPersp2 |
| 1058 | ## |
| 1059 | #Param value Scalar to store in Matrix ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1060 | |
| 1061 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1062 | SkMatrix matrix; |
| 1063 | matrix.setIdentity(); |
| 1064 | SkDebugf("with identity matrix: x = %g\n", matrix.mapXY(24, 42).fX); |
| 1065 | matrix.set(SkMatrix::kMSkewX, 0); |
| 1066 | SkDebugf("after skew x mod: x = %g\n", matrix.mapXY(24, 42).fX); |
| 1067 | matrix.set(SkMatrix::kMSkewX, 1); |
| 1068 | SkDebugf("after 2nd skew x mod: x = %g\n", matrix.mapXY(24, 42).fX); |
| 1069 | #StdOut |
| 1070 | with identity matrix: x = 24 |
| 1071 | after skew x mod: x = 24 |
| 1072 | after 2nd skew x mod: x = 66 |
| 1073 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1074 | ## |
| 1075 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1076 | #SeeAlso operator[] get |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1077 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1078 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1079 | |
| 1080 | # ------------------------------------------------------------------------------ |
| 1081 | |
| 1082 | #Method void setScaleX(SkScalar v) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1083 | #In Set |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1084 | #Line # sets horizontal scale factor ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1085 | Sets horizontal scale factor. |
| 1086 | |
| 1087 | #Param v horizontal scale factor to store ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1088 | |
| 1089 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1090 | #Height 64 |
| 1091 | SkPaint paint; |
| 1092 | paint.setAntiAlias(true); |
| 1093 | paint.setTextSize(24); |
| 1094 | canvas->drawString("normal", 12, 24, paint); |
| 1095 | SkMatrix matrix; |
| 1096 | matrix.setIdentity(); |
| 1097 | matrix.setScaleX(3); |
| 1098 | canvas->concat(matrix); |
| 1099 | canvas->drawString("x scale", 0, 48, paint); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1100 | ## |
| 1101 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1102 | #SeeAlso set setScale setScaleY |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1103 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1104 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1105 | |
| 1106 | # ------------------------------------------------------------------------------ |
| 1107 | |
| 1108 | #Method void setScaleY(SkScalar v) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1109 | #In Set |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1110 | #Line # sets vertical scale factor ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1111 | Sets vertical scale factor. |
| 1112 | |
| 1113 | #Param v vertical scale factor to store ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1114 | |
| 1115 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1116 | #Height 192 |
| 1117 | SkPaint paint; |
| 1118 | paint.setAntiAlias(true); |
| 1119 | paint.setTextSize(24); |
| 1120 | canvas->drawString("normal", 12, 24, paint); |
| 1121 | SkMatrix matrix; |
| 1122 | matrix.setIdentity(); |
| 1123 | matrix.setScaleY(3); |
| 1124 | canvas->concat(matrix); |
| 1125 | canvas->drawString("y scale", 12, 48, paint); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1126 | ## |
| 1127 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1128 | #SeeAlso set setScale setScaleX |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1129 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1130 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1131 | |
| 1132 | # ------------------------------------------------------------------------------ |
| 1133 | |
| 1134 | #Method void setSkewY(SkScalar v) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1135 | #In Set |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1136 | #Line # sets vertical skew factor ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1137 | Sets vertical skew factor. |
| 1138 | |
| 1139 | #Param v vertical skew factor to store ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1140 | |
| 1141 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1142 | #Height 96 |
| 1143 | SkPaint paint; |
| 1144 | paint.setAntiAlias(true); |
| 1145 | paint.setTextSize(24); |
| 1146 | canvas->drawString("normal", 12, 24, paint); |
| 1147 | SkMatrix matrix; |
| 1148 | matrix.setIdentity(); |
| 1149 | matrix.setSkewY(.3f); |
| 1150 | canvas->concat(matrix); |
| 1151 | canvas->drawString("y skew", 12, 48, paint); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1152 | ## |
| 1153 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1154 | #SeeAlso set setSkew setSkewX |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1155 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1156 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1157 | |
| 1158 | # ------------------------------------------------------------------------------ |
| 1159 | |
| 1160 | #Method void setSkewX(SkScalar v) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1161 | #In Set |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1162 | #Line # sets horizontal skew factor ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1163 | Sets horizontal skew factor. |
| 1164 | |
| 1165 | #Param v horizontal skew factor to store ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1166 | |
| 1167 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1168 | #Height 64 |
| 1169 | SkPaint paint; |
| 1170 | paint.setAntiAlias(true); |
| 1171 | paint.setTextSize(24); |
| 1172 | canvas->drawString("normal", 12, 24, paint); |
| 1173 | SkMatrix matrix; |
| 1174 | matrix.setIdentity(); |
| 1175 | matrix.setSkewX(-.7f); |
| 1176 | canvas->concat(matrix); |
| 1177 | canvas->drawString("x skew", 36, 48, paint); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1178 | ## |
| 1179 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1180 | #SeeAlso set setSkew setSkewX |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1181 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1182 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1183 | |
| 1184 | # ------------------------------------------------------------------------------ |
| 1185 | |
| 1186 | #Method void setTranslateX(SkScalar v) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1187 | #In Set |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1188 | #Line # sets horizontal translation ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1189 | Sets horizontal translation. |
| 1190 | |
| 1191 | #Param v horizontal translation to store ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1192 | |
| 1193 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1194 | #Height 48 |
| 1195 | SkPaint paint; |
| 1196 | paint.setAntiAlias(true); |
| 1197 | paint.setTextSize(24); |
| 1198 | canvas->drawString("normal", 8, 24, paint); |
| 1199 | SkMatrix matrix; |
| 1200 | matrix.setIdentity(); |
| 1201 | matrix.setTranslateX(96); |
| 1202 | canvas->concat(matrix); |
| 1203 | canvas->drawString("x translate", 8, 24, paint); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1204 | ## |
| 1205 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1206 | #SeeAlso set setTranslate setTranslateY |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1207 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1208 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1209 | |
| 1210 | # ------------------------------------------------------------------------------ |
| 1211 | |
| 1212 | #Method void setTranslateY(SkScalar v) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1213 | #In Set |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1214 | #Line # sets vertical translation ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1215 | Sets vertical translation. |
| 1216 | |
| 1217 | #Param v vertical translation to store ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1218 | |
| 1219 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1220 | #Height 64 |
| 1221 | SkPaint paint; |
| 1222 | paint.setAntiAlias(true); |
| 1223 | paint.setTextSize(24); |
| 1224 | canvas->drawString("normal", 8, 24, paint); |
| 1225 | SkMatrix matrix; |
| 1226 | matrix.setIdentity(); |
| 1227 | matrix.setTranslateY(24); |
| 1228 | canvas->concat(matrix); |
| 1229 | canvas->drawString("y translate", 8, 24, paint); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1230 | ## |
| 1231 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1232 | #SeeAlso set setTranslate setTranslateX |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1233 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1234 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1235 | |
| 1236 | # ------------------------------------------------------------------------------ |
| 1237 | |
| 1238 | #Method void setPerspX(SkScalar v) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1239 | #In Set |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1240 | #Line # sets input x perspective factor ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1241 | Sets input x perspective factor, which causes mapXY to vary input x inversely |
| 1242 | proportional to input y. |
| 1243 | |
| 1244 | #Param v perspective factor ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1245 | |
| 1246 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1247 | #Image 4 |
| 1248 | for (SkScalar perspX : { -.003f, 0.f, .003f, .012f } ) { |
| 1249 | SkMatrix matrix; |
| 1250 | matrix.setIdentity(); |
| 1251 | matrix.setPerspX(perspX); |
| 1252 | canvas->save(); |
| 1253 | canvas->concat(matrix); |
| 1254 | canvas->drawBitmap(source, 0, 0); |
| 1255 | canvas->restore(); |
| 1256 | canvas->translate(64, 64); |
| 1257 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1258 | ## |
| 1259 | |
Cary Clark | bef063a | 2017-10-31 15:44:45 -0400 | [diff] [blame] | 1260 | #SeeAlso getPerspX set setAll set9 MakeAll |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1261 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1262 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1263 | |
| 1264 | # ------------------------------------------------------------------------------ |
| 1265 | |
| 1266 | #Method void setPerspY(SkScalar v) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1267 | #In Set |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1268 | #Line # sets input y perspective factor ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1269 | Sets input y perspective factor, which causes mapXY to vary input y inversely |
| 1270 | proportional to input x. |
| 1271 | |
| 1272 | #Param v perspective factor ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1273 | |
| 1274 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1275 | #Image 4 |
| 1276 | for (SkScalar perspX : { -.003f, 0.f, .003f, .012f } ) { |
| 1277 | SkMatrix matrix; |
| 1278 | matrix.setIdentity(); |
| 1279 | matrix.setPerspY(perspX); |
| 1280 | canvas->save(); |
| 1281 | canvas->concat(matrix); |
| 1282 | canvas->drawBitmap(source, 0, 0); |
| 1283 | canvas->restore(); |
| 1284 | canvas->translate(64, 64); |
| 1285 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1286 | ## |
| 1287 | |
Cary Clark | bef063a | 2017-10-31 15:44:45 -0400 | [diff] [blame] | 1288 | #SeeAlso getPerspY set setAll set9 MakeAll |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1289 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1290 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1291 | |
| 1292 | # ------------------------------------------------------------------------------ |
| 1293 | |
| 1294 | #Method void setAll(SkScalar scaleX, SkScalar skewX, SkScalar transX, |
| 1295 | SkScalar skewY, SkScalar scaleY, SkScalar transY, |
| 1296 | SkScalar persp0, SkScalar persp1, SkScalar persp2) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1297 | #In Set |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1298 | #Line # sets all values from parameters ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1299 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1300 | Sets all values from parameters. Sets matrix to: |
| 1301 | |
| 1302 | #Code |
| 1303 | #Literal |
| 1304 | | scaleX skewX transX | |
| 1305 | | skewY scaleY transY | |
| 1306 | | persp0 persp1 persp2 | |
| 1307 | ## |
| 1308 | |
| 1309 | #Param scaleX horizontal scale factor to store ## |
| 1310 | #Param skewX horizontal skew factor to store ## |
| 1311 | #Param transX horizontal translation to store ## |
| 1312 | #Param skewY vertical skew factor to store ## |
| 1313 | #Param scaleY vertical scale factor to store ## |
| 1314 | #Param transY vertical translation to store ## |
| 1315 | #Param persp0 input x perspective factor to store ## |
| 1316 | #Param persp1 input y perspective factor to store ## |
| 1317 | #Param persp2 perspective scale factor to store ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1318 | |
| 1319 | #Example |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1320 | #Height 128 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1321 | SkPaint p; |
| 1322 | p.setAntiAlias(true); |
| 1323 | p.setTextSize(64); |
| 1324 | SkMatrix m; |
| 1325 | for (SkScalar sx : { -1, 1 } ) { |
| 1326 | for (SkScalar sy : { -1, 1 } ) { |
| 1327 | SkAutoCanvasRestore autoRestore(canvas, true); |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1328 | m.setAll(sx, 1, 128, 0, sy, 64, 0, 0, 1); |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1329 | canvas->concat(m); |
| 1330 | canvas->drawString("K", 0, 0, p); |
| 1331 | } |
| 1332 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1333 | ## |
| 1334 | |
Cary Clark | bef063a | 2017-10-31 15:44:45 -0400 | [diff] [blame] | 1335 | #SeeAlso set9 MakeAll |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1336 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1337 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1338 | |
| 1339 | # ------------------------------------------------------------------------------ |
| 1340 | |
| 1341 | #Method void get9(SkScalar buffer[9]) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1342 | #In Property |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1343 | #Line # returns all nine Matrix values ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1344 | Copies nine Scalar values contained by Matrix into buffer, in member value |
| 1345 | ascending order: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY, |
| 1346 | kMPersp0, kMPersp1, kMPersp2. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1347 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1348 | #Param buffer storage for nine Scalar values ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1349 | |
| 1350 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1351 | SkMatrix matrix = SkMatrix::MakeRectToRect({0, 0, 1, 1}, {3, 4, 7, 9}, |
| 1352 | SkMatrix::kFill_ScaleToFit); |
| 1353 | SkScalar b[9]; |
| 1354 | matrix.get9(b); |
| 1355 | SkDebugf("{%g, %g, %g},\n{%g, %g, %g},\n{%g, %g, %g}\n", b[0], b[1], b[2], |
| 1356 | b[3], b[4], b[5], b[6], b[7], b[8]); |
| 1357 | #StdOut |
| 1358 | {4, 0, 3}, |
| 1359 | {0, 5, 4}, |
| 1360 | {0, 0, 1} |
| 1361 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1362 | ## |
| 1363 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1364 | #SeeAlso set9 |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1365 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1366 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1367 | |
| 1368 | # ------------------------------------------------------------------------------ |
| 1369 | |
| 1370 | #Method void set9(const SkScalar buffer[9]) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1371 | #In Set |
| 1372 | #In Constructor |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1373 | #Line # sets all values from Scalar array ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1374 | Sets Matrix to nine Scalar values in buffer, in member value ascending order: |
| 1375 | kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY, kMPersp0, kMPersp1, |
| 1376 | kMPersp2. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1377 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1378 | Sets matrix to: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1379 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1380 | #Code |
| 1381 | #Literal |
| 1382 | | buffer[0] buffer[1] buffer[2] | |
| 1383 | | buffer[3] buffer[4] buffer[5] | |
| 1384 | | buffer[6] buffer[7] buffer[8] | |
| 1385 | ## |
| 1386 | |
| 1387 | In the future, set9 followed by get9 may not return the same values. Since Matrix |
| 1388 | maps non-homogeneous coordinates, scaling all nine values produces an equivalent |
| 1389 | transformation, possibly improving precision. |
| 1390 | |
| 1391 | #Param buffer nine Scalar values ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1392 | |
| 1393 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1394 | #Image 4 |
| 1395 | SkMatrix m; |
| 1396 | SkScalar buffer[9] = {4, 0, 3, 0, 5, 4, 0, 0, 1}; |
| 1397 | m.set9(buffer); |
| 1398 | canvas->concat(m); |
| 1399 | canvas->drawBitmap(source, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1400 | ## |
| 1401 | |
Cary Clark | bef063a | 2017-10-31 15:44:45 -0400 | [diff] [blame] | 1402 | #SeeAlso setAll get9 MakeAll |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1403 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1404 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1405 | |
| 1406 | # ------------------------------------------------------------------------------ |
| 1407 | |
| 1408 | #Method void reset() |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1409 | #In Constructor |
| 1410 | #In Set |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1411 | #Line # sets Matrix to identity ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1412 | Sets Matrix to identity; which has no effect on mapped Points. Sets Matrix to: |
| 1413 | |
| 1414 | #Code |
| 1415 | #Literal |
| 1416 | | 1 0 0 | |
| 1417 | | 0 1 0 | |
| 1418 | | 0 0 1 | |
| 1419 | ## |
| 1420 | |
| 1421 | Also called setIdentity(); use the one that provides better inline |
| 1422 | documentation. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1423 | |
| 1424 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1425 | SkMatrix m; |
| 1426 | m.reset(); |
| 1427 | SkDebugf("m.isIdentity(): %s\n", m.isIdentity() ? "true" : "false"); |
| 1428 | #StdOut |
| 1429 | m.isIdentity(): true |
| 1430 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1431 | ## |
| 1432 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1433 | #SeeAlso isIdentity setIdentity |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1434 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1435 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1436 | |
| 1437 | # ------------------------------------------------------------------------------ |
| 1438 | |
| 1439 | #Method void setIdentity() |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1440 | #In Constructor |
| 1441 | #In Set |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1442 | #Line # sets Matrix to identity ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1443 | Sets Matrix to identity; which has no effect on mapped Points. Sets Matrix to: |
| 1444 | |
| 1445 | #Code |
| 1446 | #Literal |
| 1447 | | 1 0 0 | |
| 1448 | | 0 1 0 | |
| 1449 | | 0 0 1 | |
| 1450 | ## |
| 1451 | |
| 1452 | Also called reset(); use the one that provides better inline |
| 1453 | documentation. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1454 | |
| 1455 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1456 | SkMatrix m; |
| 1457 | m.setIdentity(); |
| 1458 | SkDebugf("m.isIdentity(): %s\n", m.isIdentity() ? "true" : "false"); |
| 1459 | #StdOut |
| 1460 | m.isIdentity(): true |
| 1461 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1462 | ## |
| 1463 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1464 | #SeeAlso isIdentity reset |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1465 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1466 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1467 | |
| 1468 | # ------------------------------------------------------------------------------ |
| 1469 | |
| 1470 | #Method void setTranslate(SkScalar dx, SkScalar dy) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1471 | #In Constructor |
| 1472 | #In Set |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1473 | #Line # sets to translate in x and y ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1474 | Sets Matrix to translate by (dx, dy). |
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 | #Param dx horizontal translation ## |
| 1477 | #Param dy vertical translation ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1478 | |
| 1479 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1480 | #Height 64 |
| 1481 | SkPaint paint; |
| 1482 | paint.setAntiAlias(true); |
| 1483 | paint.setTextSize(24); |
| 1484 | canvas->drawString("normal", 8, 24, paint); |
| 1485 | SkMatrix matrix; |
| 1486 | matrix.setTranslate(96, 24); |
| 1487 | canvas->concat(matrix); |
| 1488 | canvas->drawString("translate", 8, 24, paint); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1489 | ## |
| 1490 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1491 | #SeeAlso setTranslateX setTranslateY |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1492 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1493 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1494 | |
| 1495 | # ------------------------------------------------------------------------------ |
| 1496 | |
| 1497 | #Method void setTranslate(const SkVector& v) |
| 1498 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1499 | Sets Matrix to translate by (v.fX, v.fY). |
| 1500 | |
| 1501 | #Param v Vector containing horizontal and vertical translation ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1502 | |
| 1503 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1504 | #Height 64 |
| 1505 | SkPaint paint; |
| 1506 | paint.setAntiAlias(true); |
| 1507 | paint.setTextSize(24); |
| 1508 | canvas->drawString("normal", 8, 24, paint); |
| 1509 | SkMatrix matrix; |
| 1510 | matrix.setTranslate({96, 24}); |
| 1511 | canvas->concat(matrix); |
| 1512 | canvas->drawString("translate", 8, 24, paint); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1513 | ## |
| 1514 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1515 | #SeeAlso setTranslateX setTranslateY MakeTrans |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1516 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1517 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1518 | |
| 1519 | # ------------------------------------------------------------------------------ |
| 1520 | |
| 1521 | #Method void setScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1522 | #In Constructor |
| 1523 | #In Set |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1524 | #Line # sets to scale about a point ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1525 | Sets Matrix to scale by sx and sy, about a pivot point at (px, py). |
| 1526 | The pivot point is unchanged when mapped with Matrix. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1527 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1528 | #Param sx horizontal scale factor ## |
| 1529 | #Param sy vertical scale factor ## |
| 1530 | #Param px pivot x ## |
| 1531 | #Param py pivot y ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1532 | |
| 1533 | #Example |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1534 | #Height 128 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1535 | SkPaint p; |
| 1536 | p.setAntiAlias(true); |
| 1537 | p.setTextSize(64); |
| 1538 | SkMatrix m; |
| 1539 | for (SkScalar sx : { -1, 1 } ) { |
| 1540 | for (SkScalar sy : { -1, 1 } ) { |
| 1541 | SkAutoCanvasRestore autoRestore(canvas, true); |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1542 | m.setScale(sx, sy, 128, 64); |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1543 | canvas->concat(m); |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1544 | canvas->drawString("%", 128, 64, p); |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1545 | } |
| 1546 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1547 | ## |
| 1548 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1549 | #SeeAlso setScaleX setScaleY MakeScale preScale postScale |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1550 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1551 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1552 | |
| 1553 | # ------------------------------------------------------------------------------ |
| 1554 | |
| 1555 | #Method void setScale(SkScalar sx, SkScalar sy) |
| 1556 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1557 | 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] | 1558 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1559 | #Param sx horizontal scale factor ## |
| 1560 | #Param sy vertical scale factor ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1561 | |
| 1562 | #Example |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1563 | #Height 128 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1564 | SkPaint p; |
| 1565 | p.setAntiAlias(true); |
| 1566 | p.setTextSize(64); |
| 1567 | SkMatrix m; |
| 1568 | for (SkScalar sx : { -1, 1 } ) { |
| 1569 | for (SkScalar sy : { -1, 1 } ) { |
| 1570 | SkAutoCanvasRestore autoRestore(canvas, true); |
| 1571 | m.setScale(sx, sy); |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1572 | m.postTranslate(128, 64); |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1573 | canvas->concat(m); |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1574 | canvas->drawString("@", 0, 0, p); |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1575 | } |
| 1576 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1577 | ## |
| 1578 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1579 | #SeeAlso setScaleX setScaleY MakeScale preScale postScale |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1580 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1581 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1582 | |
| 1583 | # ------------------------------------------------------------------------------ |
| 1584 | |
| 1585 | #Method void setRotate(SkScalar degrees, SkScalar px, SkScalar py) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1586 | #In Constructor |
| 1587 | #In Set |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1588 | #Line # sets to rotate about a point ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1589 | Sets Matrix to rotate by degrees about a pivot point at (px, py). |
| 1590 | The pivot point is unchanged when mapped with Matrix. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1591 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1592 | Positive degrees rotates clockwise. |
| 1593 | |
| 1594 | #Param degrees angle of axes relative to upright axes ## |
| 1595 | #Param px pivot x ## |
| 1596 | #Param py pivot y ## |
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 128 |
| 1600 | SkPaint paint; |
| 1601 | paint.setColor(SK_ColorGRAY); |
| 1602 | paint.setAntiAlias(true); |
| 1603 | SkRect rect = {20, 20, 100, 100}; |
| 1604 | canvas->drawRect(rect, paint); |
| 1605 | paint.setColor(SK_ColorRED); |
| 1606 | SkMatrix matrix; |
| 1607 | matrix.setRotate(25, rect.centerX(), rect.centerY()); |
| 1608 | canvas->concat(matrix); |
| 1609 | canvas->drawRect(rect, paint); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1610 | ## |
| 1611 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1612 | #SeeAlso setSinCos preRotate postRotate |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1613 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1614 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1615 | |
| 1616 | # ------------------------------------------------------------------------------ |
| 1617 | |
| 1618 | #Method void setRotate(SkScalar degrees) |
| 1619 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1620 | Sets Matrix to rotate by degrees about a pivot point at (0, 0). |
| 1621 | Positive degrees rotates clockwise. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1622 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1623 | #Param degrees angle of axes relative to upright axes ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1624 | |
| 1625 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1626 | #Height 128 |
| 1627 | SkPaint paint; |
| 1628 | paint.setColor(SK_ColorGRAY); |
| 1629 | paint.setAntiAlias(true); |
| 1630 | SkRect rect = {20, 20, 100, 100}; |
| 1631 | canvas->drawRect(rect, paint); |
| 1632 | paint.setColor(SK_ColorRED); |
| 1633 | SkMatrix matrix; |
| 1634 | matrix.setRotate(25); |
| 1635 | canvas->translate(rect.centerX(), rect.centerY()); |
| 1636 | canvas->concat(matrix); |
| 1637 | canvas->translate(-rect.centerX(), -rect.centerY()); |
| 1638 | canvas->drawRect(rect, paint); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1639 | ## |
| 1640 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1641 | #SeeAlso setSinCos preRotate postRotate |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1642 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1643 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1644 | |
| 1645 | # ------------------------------------------------------------------------------ |
| 1646 | |
| 1647 | #Method void setSinCos(SkScalar sinValue, SkScalar cosValue, |
| 1648 | SkScalar px, SkScalar py) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1649 | #In Constructor |
| 1650 | #In Set |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1651 | #Line # sets to rotate and scale about a point ## |
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 | Sets Matrix to rotate by sinValue and cosValue, about a pivot point at (px, py). |
| 1654 | The pivot point is unchanged when mapped with Matrix. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1655 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1656 | Vector (sinValue, cosValue) describes the angle of rotation relative to (0, 1). |
| 1657 | Vector length specifies scale. |
| 1658 | |
| 1659 | #Param sinValue rotation vector x component ## |
| 1660 | #Param cosValue rotation vector y component ## |
| 1661 | #Param px pivot x ## |
| 1662 | #Param py pivot y ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1663 | |
| 1664 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1665 | #Height 128 |
| 1666 | SkPaint paint; |
| 1667 | paint.setColor(SK_ColorGRAY); |
| 1668 | paint.setAntiAlias(true); |
| 1669 | SkRect rect = {20, 20, 100, 100}; |
| 1670 | canvas->drawRect(rect, paint); |
| 1671 | paint.setColor(SK_ColorRED); |
| 1672 | SkMatrix matrix; |
| 1673 | matrix.setSinCos(.25f, .85f, rect.centerX(), rect.centerY()); |
| 1674 | canvas->concat(matrix); |
| 1675 | canvas->drawRect(rect, paint); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1676 | ## |
| 1677 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1678 | #SeeAlso setRotate setScale setRSXform |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1679 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1680 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1681 | |
| 1682 | # ------------------------------------------------------------------------------ |
| 1683 | |
| 1684 | #Method void setSinCos(SkScalar sinValue, SkScalar cosValue) |
| 1685 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1686 | 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] | 1687 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1688 | Vector (sinValue, cosValue) describes the angle of rotation relative to (0, 1). |
| 1689 | Vector length specifies scale. |
| 1690 | |
| 1691 | #Param sinValue rotation vector x component ## |
| 1692 | #Param cosValue rotation vector y component ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1693 | |
| 1694 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1695 | #Description |
| 1696 | Canvas needs offset after applying Matrix to pivot about Rect center. |
| 1697 | ## |
| 1698 | #Height 128 |
| 1699 | SkPaint paint; |
| 1700 | paint.setColor(SK_ColorGRAY); |
| 1701 | paint.setAntiAlias(true); |
| 1702 | SkRect rect = {20, 20, 100, 100}; |
| 1703 | canvas->drawRect(rect, paint); |
| 1704 | paint.setColor(SK_ColorRED); |
| 1705 | SkMatrix matrix; |
| 1706 | matrix.setSinCos(.25f, .85f); |
| 1707 | matrix.postTranslate(rect.centerX(), rect.centerY()); |
| 1708 | canvas->concat(matrix); |
| 1709 | canvas->translate(-rect.centerX(), -rect.centerY()); |
| 1710 | canvas->drawRect(rect, paint); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1711 | ## |
| 1712 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1713 | #SeeAlso setRotate setScale setRSXform |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1714 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1715 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1716 | |
| 1717 | # ------------------------------------------------------------------------------ |
| 1718 | |
| 1719 | #Method SkMatrix& setRSXform(const SkRSXform& rsxForm) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1720 | #In Constructor |
| 1721 | #In Set |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1722 | #Line # sets to rotate, scale, and translate ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1723 | Sets Matrix to rotate, scale, and translate using a compressed matrix form. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1724 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1725 | Vector (rsxForm.fSSin, rsxForm.fSCos) describes the angle of rotation relative |
| 1726 | to (0, 1). Vector length specifies scale. Mapped point is rotated and scaled |
| 1727 | by Vector, then translated by (rsxForm.fTx, rsxForm.fTy). |
| 1728 | |
| 1729 | #Param rsxForm compressed RSXform matrix ## |
| 1730 | |
| 1731 | #Return reference to Matrix ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1732 | |
| 1733 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1734 | #Description |
| 1735 | Canvas needs offset after applying Matrix to pivot about Rect center. |
| 1736 | ## |
| 1737 | #Height 128 |
| 1738 | SkPaint paint; |
| 1739 | paint.setColor(SK_ColorGRAY); |
| 1740 | paint.setAntiAlias(true); |
| 1741 | SkRect rect = {20, 20, 100, 100}; |
| 1742 | canvas->drawRect(rect, paint); |
| 1743 | paint.setColor(SK_ColorRED); |
| 1744 | SkMatrix matrix; |
| 1745 | matrix.setRSXform(SkRSXform::Make(.85f, .25f, rect.centerX(), rect.centerY())); |
| 1746 | canvas->concat(matrix); |
| 1747 | canvas->translate(-rect.centerX(), -rect.centerY()); |
| 1748 | canvas->drawRect(rect, paint); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1749 | ## |
| 1750 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1751 | #SeeAlso setSinCos setScale setTranslate |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1752 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1753 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1754 | |
| 1755 | # ------------------------------------------------------------------------------ |
| 1756 | |
| 1757 | #Method void setSkew(SkScalar kx, SkScalar ky, SkScalar px, SkScalar py) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1758 | #In Constructor |
| 1759 | #In Set |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1760 | #Line # sets to skew about a point ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1761 | Sets Matrix to skew by kx and ky, about a pivot point at (px, py). |
| 1762 | The pivot point is unchanged when mapped with Matrix. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1763 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1764 | #Param kx horizontal skew factor ## |
| 1765 | #Param ky vertical skew factor ## |
| 1766 | #Param px pivot x ## |
| 1767 | #Param py pivot y ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1768 | |
| 1769 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1770 | SkPaint p; |
| 1771 | p.setAntiAlias(true); |
| 1772 | p.setTextSize(48); |
| 1773 | SkMatrix m; |
| 1774 | for (SkScalar sx : { -1, 0, 1 } ) { |
| 1775 | for (SkScalar sy : { -1, 0, 1 } ) { |
| 1776 | SkAutoCanvasRestore autoRestore(canvas, true); |
| 1777 | m.setSkew(sx, sy, 96 + 64 * sx, 128 + 48 * sy); |
| 1778 | canvas->concat(m); |
| 1779 | canvas->drawString("K", 96 + 64 * sx, 128 + 48 * sy, p); |
| 1780 | } |
| 1781 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1782 | ## |
| 1783 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1784 | #SeeAlso setSkewX setSkewY preSkew postSkew |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1785 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1786 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1787 | |
| 1788 | # ------------------------------------------------------------------------------ |
| 1789 | |
| 1790 | #Method void setSkew(SkScalar kx, SkScalar ky) |
| 1791 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1792 | 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] | 1793 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1794 | #Param kx horizontal skew factor ## |
| 1795 | #Param ky vertical skew factor ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1796 | |
| 1797 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1798 | SkPaint p; |
| 1799 | p.setAntiAlias(true); |
| 1800 | p.setTextSize(48); |
| 1801 | SkMatrix m; |
| 1802 | for (SkScalar sx : { -1, 0, 1 } ) { |
| 1803 | for (SkScalar sy : { -1, 0, 1 } ) { |
| 1804 | SkAutoCanvasRestore autoRestore(canvas, true); |
| 1805 | m.setSkew(sx, sy); |
| 1806 | m.postTranslate(96 + 64 * sx, 128 + 48 * sy); |
| 1807 | canvas->concat(m); |
| 1808 | canvas->drawString("K", 0, 0, p); |
| 1809 | } |
| 1810 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1811 | ## |
| 1812 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1813 | #SeeAlso setSkewX setSkewY preSkew postSkew |
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 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1816 | |
| 1817 | # ------------------------------------------------------------------------------ |
| 1818 | |
| 1819 | #Method void setConcat(const SkMatrix& a, const SkMatrix& b) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1820 | #In Constructor |
| 1821 | #In Set |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1822 | #Line # sets to Matrix parameter multiplied by Matrix parameter ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1823 | 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] | 1824 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1825 | Given: |
| 1826 | |
| 1827 | #Code |
| 1828 | #Literal |
| 1829 | | A B C | | J K L | |
| 1830 | a = | D E F |, b = | M N O | |
| 1831 | | G H I | | P Q R | |
| 1832 | ## |
| 1833 | |
| 1834 | sets Matrix to: |
| 1835 | |
| 1836 | #Code |
| 1837 | #Literal |
| 1838 | | A B C | | J K L | | AJ+BM+CP AK+BN+CQ AL+BO+CR | |
| 1839 | a * b = | D E F | * | M N O | = | DJ+EM+FP DK+EN+FQ DL+EO+FR | |
| 1840 | | G H I | | P Q R | | GJ+HM+IP GK+HN+IQ GL+HO+IR | |
| 1841 | ## |
| 1842 | |
| 1843 | #Param a Matrix on left side of multiply expression ## |
| 1844 | #Param b Matrix on right side of multiply expression ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1845 | |
| 1846 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1847 | #Image 3 |
| 1848 | #Description |
| 1849 | setPolyToPoly creates perspective matrices, one the inverse of the other. |
| 1850 | Multiplying the matrix by its inverse turns into an identity matrix. |
| 1851 | ## |
| 1852 | SkMatrix matrix, matrix2; |
| 1853 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 1854 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 1855 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 1856 | matrix2.setPolyToPoly(perspect, bitmapBounds, 4); |
| 1857 | matrix.setConcat(matrix, matrix2); |
| 1858 | canvas->concat(matrix); |
| 1859 | canvas->drawBitmap(source, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1860 | ## |
| 1861 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1862 | #SeeAlso Concat preConcat postConcat SkCanvas::concat |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1863 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1864 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1865 | |
| 1866 | # ------------------------------------------------------------------------------ |
| 1867 | |
| 1868 | #Method void preTranslate(SkScalar dx, SkScalar dy) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1869 | #In Set |
| 1870 | #In Operator |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1871 | #Line # pre-multiplies Matrix by translation ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1872 | Sets Matrix to Matrix multiplied by Matrix constructed from translation (dx, dy). |
| 1873 | This can be thought of as moving the point to be mapped before applying Matrix. |
| 1874 | |
| 1875 | Given: |
| 1876 | |
| 1877 | #Code |
| 1878 | #Literal |
| 1879 | | A B C | | 1 0 dx | |
| 1880 | Matrix = | D E F |, T(dx, dy) = | 0 1 dy | |
| 1881 | | G H I | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1882 | ## |
| 1883 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1884 | sets Matrix to: |
| 1885 | |
| 1886 | #Code |
| 1887 | #Literal |
| 1888 | | A B C | | 1 0 dx | | A B A*dx+B*dy+C | |
| 1889 | Matrix * T(dx, dy) = | D E F | | 0 1 dy | = | D E D*dx+E*dy+F | |
| 1890 | | G H I | | 0 0 1 | | G H G*dx+H*dy+I | |
| 1891 | ## |
| 1892 | |
| 1893 | #Param dx x translation before applying Matrix ## |
| 1894 | #Param dy y translation before applying Matrix ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1895 | |
| 1896 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1897 | #Height 160 |
| 1898 | SkPaint paint; |
| 1899 | paint.setAntiAlias(true); |
| 1900 | SkRect rect = {20, 20, 100, 100}; |
| 1901 | for (int i = 0; i < 2; ++i ) { |
| 1902 | SkMatrix matrix; |
| 1903 | i == 0 ? matrix.reset(): matrix.setRotate(25, rect.centerX(), 320); |
| 1904 | { |
| 1905 | SkAutoCanvasRestore acr(canvas, true); |
| 1906 | canvas->concat(matrix); |
| 1907 | paint.setColor(SK_ColorGRAY); |
| 1908 | canvas->drawRect(rect, paint); |
| 1909 | } |
| 1910 | paint.setColor(SK_ColorRED); |
| 1911 | for (int j = 0; j < 2; ++j ) { |
| 1912 | SkAutoCanvasRestore acr(canvas, true); |
| 1913 | matrix.preTranslate(40, 40); |
| 1914 | canvas->concat(matrix); |
| 1915 | canvas->drawCircle(0, 0, 3, paint); |
| 1916 | } |
| 1917 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1918 | ## |
| 1919 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1920 | #SeeAlso postTranslate setTranslate MakeTrans |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1921 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1922 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1923 | |
| 1924 | # ------------------------------------------------------------------------------ |
| 1925 | |
| 1926 | #Method void preScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1927 | #In Set |
| 1928 | #In Operator |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1929 | #Line # pre-multiplies Matrix by scale ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1930 | Sets Matrix to Matrix multiplied by Matrix constructed from scaling by (sx, sy) |
| 1931 | about pivot point (px, py). |
| 1932 | This can be thought of as scaling about a pivot point before applying Matrix. |
| 1933 | |
| 1934 | Given: |
| 1935 | |
| 1936 | #Code |
| 1937 | #Literal |
| 1938 | | A B C | | sx 0 dx | |
| 1939 | Matrix = | D E F |, S(sx, sy, px, py) = | 0 sy dy | |
| 1940 | | G H I | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1941 | ## |
| 1942 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1943 | where |
| 1944 | |
| 1945 | #Code |
| 1946 | #Literal |
| 1947 | dx = px - sx * px |
| 1948 | dy = py - sy * py |
| 1949 | ## |
| 1950 | |
| 1951 | sets Matrix to: |
| 1952 | |
| 1953 | #Code |
| 1954 | #Literal |
| 1955 | | A B C | | sx 0 dx | | A*sx B*sy A*dx+B*dy+C | |
| 1956 | Matrix * S(sx, sy, px, py) = | D E F | | 0 sy dy | = | D*sx E*sy D*dx+E*dy+F | |
| 1957 | | G H I | | 0 0 1 | | G*sx H*sy G*dx+H*dy+I | |
| 1958 | ## |
| 1959 | |
| 1960 | #Param sx horizontal scale factor ## |
| 1961 | #Param sy vertical scale factor ## |
| 1962 | #Param px pivot x ## |
| 1963 | #Param py pivot y ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1964 | |
| 1965 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1966 | #Image 3 |
| 1967 | SkMatrix matrix; |
| 1968 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 1969 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 1970 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 1971 | matrix.preScale(.75f, 1.5f, source.width() / 2, source.height() / 2); |
| 1972 | canvas->concat(matrix); |
| 1973 | canvas->drawBitmap(source, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1974 | ## |
| 1975 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1976 | #SeeAlso postScale setScale MakeScale |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1977 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1978 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1979 | |
| 1980 | # ------------------------------------------------------------------------------ |
| 1981 | |
| 1982 | #Method void preScale(SkScalar sx, SkScalar sy) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1983 | #In Set |
| 1984 | #In Operator |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1985 | Sets Matrix to Matrix multiplied by Matrix constructed from scaling by (sx, sy) |
| 1986 | about pivot point (0, 0). |
| 1987 | This can be thought of as scaling about the origin before applying Matrix. |
| 1988 | |
| 1989 | Given: |
| 1990 | |
| 1991 | #Code |
| 1992 | #Literal |
| 1993 | | A B C | | sx 0 0 | |
| 1994 | Matrix = | D E F |, S(sx, sy) = | 0 sy 0 | |
| 1995 | | G H I | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1996 | ## |
| 1997 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1998 | sets Matrix to: |
| 1999 | |
| 2000 | #Code |
| 2001 | #Literal |
| 2002 | | A B C | | sx 0 0 | | A*sx B*sy C | |
| 2003 | Matrix * S(sx, sy) = | D E F | | 0 sy 0 | = | D*sx E*sy F | |
| 2004 | | G H I | | 0 0 1 | | G*sx H*sy I | |
| 2005 | ## |
| 2006 | |
| 2007 | #Param sx horizontal scale factor ## |
| 2008 | #Param sy vertical scale factor ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2009 | |
| 2010 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2011 | #Image 3 |
| 2012 | SkMatrix matrix; |
| 2013 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 2014 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 2015 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 2016 | matrix.preScale(.75f, 1.5f); |
| 2017 | canvas->concat(matrix); |
| 2018 | canvas->drawBitmap(source, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2019 | ## |
| 2020 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2021 | #SeeAlso postScale setScale MakeScale |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2022 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2023 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2024 | |
| 2025 | # ------------------------------------------------------------------------------ |
| 2026 | |
| 2027 | #Method void preRotate(SkScalar degrees, SkScalar px, SkScalar py) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2028 | #In Set |
| 2029 | #In Operator |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2030 | #Line # pre-multiplies Matrix by rotation ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2031 | Sets Matrix to Matrix multiplied by Matrix constructed from rotating by degrees |
| 2032 | about pivot point (px, py). |
| 2033 | This can be thought of as rotating about a pivot point before applying Matrix. |
| 2034 | |
| 2035 | Positive degrees rotates clockwise. |
| 2036 | |
| 2037 | Given: |
| 2038 | |
| 2039 | #Code |
| 2040 | #Literal |
| 2041 | | A B C | | c -s dx | |
| 2042 | Matrix = | D E F |, R(degrees, px, py) = | s c dy | |
| 2043 | | G H I | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2044 | ## |
| 2045 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2046 | where |
| 2047 | |
| 2048 | #Code |
| 2049 | #Literal |
| 2050 | c = cos(degrees) |
| 2051 | s = sin(degrees) |
| 2052 | dx = s * py + (1 - c) * px |
| 2053 | dy = -s * px + (1 - c) * py |
| 2054 | ## |
| 2055 | |
| 2056 | sets Matrix to: |
| 2057 | |
| 2058 | #Code |
| 2059 | #Literal |
| 2060 | | A B C | | c -s dx | | Ac+Bs -As+Bc A*dx+B*dy+C | |
| 2061 | Matrix * R(degrees, px, py) = | D E F | | s c dy | = | Dc+Es -Ds+Ec D*dx+E*dy+F | |
| 2062 | | G H I | | 0 0 1 | | Gc+Hs -Gs+Hc G*dx+H*dy+I | |
| 2063 | ## |
| 2064 | |
| 2065 | #Param degrees angle of axes relative to upright axes ## |
| 2066 | #Param px pivot x ## |
| 2067 | #Param py pivot y ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2068 | |
| 2069 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2070 | #Image 3 |
| 2071 | SkMatrix matrix; |
| 2072 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 2073 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 2074 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 2075 | matrix.preRotate(45, source.width() / 2, source.height() / 2); |
| 2076 | canvas->concat(matrix); |
| 2077 | canvas->drawBitmap(source, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2078 | ## |
| 2079 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2080 | #SeeAlso postRotate setRotate |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2081 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2082 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2083 | |
| 2084 | # ------------------------------------------------------------------------------ |
| 2085 | |
| 2086 | #Method void preRotate(SkScalar degrees) |
| 2087 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2088 | Sets Matrix to Matrix multiplied by Matrix constructed from rotating by degrees |
| 2089 | about pivot point (0, 0). |
| 2090 | This can be thought of as rotating about the origin before applying Matrix. |
| 2091 | |
| 2092 | Positive degrees rotates clockwise. |
| 2093 | |
| 2094 | Given: |
| 2095 | |
| 2096 | #Code |
| 2097 | #Literal |
| 2098 | | A B C | | c -s 0 | |
| 2099 | Matrix = | D E F |, R(degrees, px, py) = | s c 0 | |
| 2100 | | G H I | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2101 | ## |
| 2102 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2103 | where |
| 2104 | |
| 2105 | #Code |
| 2106 | #Literal |
| 2107 | c = cos(degrees) |
| 2108 | s = sin(degrees) |
| 2109 | ## |
| 2110 | |
| 2111 | sets Matrix to: |
| 2112 | |
| 2113 | #Code |
| 2114 | #Literal |
| 2115 | | A B C | | c -s 0 | | Ac+Bs -As+Bc C | |
| 2116 | Matrix * R(degrees, px, py) = | D E F | | s c 0 | = | Dc+Es -Ds+Ec F | |
| 2117 | | G H I | | 0 0 1 | | Gc+Hs -Gs+Hc I | |
| 2118 | ## |
| 2119 | |
| 2120 | #Param degrees angle of axes relative to upright axes ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2121 | |
| 2122 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2123 | #Image 3 |
| 2124 | SkMatrix matrix; |
| 2125 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 2126 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 2127 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 2128 | matrix.preRotate(45); |
| 2129 | canvas->concat(matrix); |
| 2130 | canvas->drawBitmap(source, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2131 | ## |
| 2132 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2133 | #SeeAlso postRotate setRotate |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2134 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2135 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2136 | |
| 2137 | # ------------------------------------------------------------------------------ |
| 2138 | |
| 2139 | #Method void preSkew(SkScalar kx, SkScalar ky, SkScalar px, SkScalar py) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2140 | #In Set |
| 2141 | #In Operator |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2142 | #Line # pre-multiplies Matrix by skew ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2143 | Sets Matrix to Matrix multiplied by Matrix constructed from skewing by (kx, ky) |
| 2144 | about pivot point (px, py). |
| 2145 | This can be thought of as skewing about a pivot point before applying Matrix. |
| 2146 | |
| 2147 | Given: |
| 2148 | |
| 2149 | #Code |
| 2150 | #Literal |
| 2151 | | A B C | | 1 kx dx | |
| 2152 | Matrix = | D E F |, K(kx, ky, px, py) = | ky 1 dy | |
| 2153 | | G H I | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2154 | ## |
| 2155 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2156 | where |
| 2157 | |
| 2158 | #Code |
| 2159 | #Literal |
| 2160 | dx = -kx * py |
| 2161 | dy = -ky * px |
| 2162 | ## |
| 2163 | |
| 2164 | sets Matrix to: |
| 2165 | |
| 2166 | #Code |
| 2167 | #Literal |
| 2168 | | A B C | | 1 kx dx | | A+B*ky A*kx+B A*dx+B*dy+C | |
| 2169 | Matrix * K(kx, ky, px, py) = | D E F | | ky 1 dy | = | D+E*ky D*kx+E D*dx+E*dy+F | |
| 2170 | | G H I | | 0 0 1 | | G+H*ky G*kx+H G*dx+H*dy+I | |
| 2171 | ## |
| 2172 | |
| 2173 | #Param kx horizontal skew factor ## |
| 2174 | #Param ky vertical skew factor ## |
| 2175 | #Param px pivot x ## |
| 2176 | #Param py pivot y ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2177 | |
| 2178 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2179 | #Image 3 |
| 2180 | SkMatrix matrix; |
| 2181 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 2182 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 2183 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 2184 | matrix.preSkew(.5f, 0, source.width() / 2, source.height() / 2); |
| 2185 | canvas->concat(matrix); |
| 2186 | canvas->drawBitmap(source, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2187 | ## |
| 2188 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2189 | #SeeAlso postSkew setSkew |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2190 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2191 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2192 | |
| 2193 | # ------------------------------------------------------------------------------ |
| 2194 | |
| 2195 | #Method void preSkew(SkScalar kx, SkScalar ky) |
| 2196 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2197 | Sets Matrix to Matrix multiplied by Matrix constructed from skewing by (kx, ky) |
| 2198 | about pivot point (0, 0). |
| 2199 | This can be thought of as skewing about the origin before applying Matrix. |
| 2200 | |
| 2201 | Given: |
| 2202 | |
| 2203 | #Code |
| 2204 | #Literal |
| 2205 | | A B C | | 1 kx 0 | |
| 2206 | Matrix = | D E F |, K(kx, ky) = | ky 1 0 | |
| 2207 | | G H I | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2208 | ## |
| 2209 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2210 | sets Matrix to: |
| 2211 | |
| 2212 | #Code |
| 2213 | #Literal |
| 2214 | | A B C | | 1 kx 0 | | A+B*ky A*kx+B C | |
| 2215 | Matrix * K(kx, ky) = | D E F | | ky 1 0 | = | D+E*ky D*kx+E F | |
| 2216 | | G H I | | 0 0 1 | | G+H*ky G*kx+H I | |
| 2217 | ## |
| 2218 | |
| 2219 | #Param kx horizontal skew factor ## |
| 2220 | #Param ky vertical skew factor ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2221 | |
| 2222 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2223 | #Image 3 |
| 2224 | SkMatrix matrix; |
| 2225 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 2226 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 2227 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 2228 | matrix.preSkew(.5f, 0); |
| 2229 | canvas->concat(matrix); |
| 2230 | canvas->drawBitmap(source, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2231 | ## |
| 2232 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2233 | #SeeAlso postSkew setSkew |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2234 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2235 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2236 | |
| 2237 | # ------------------------------------------------------------------------------ |
| 2238 | |
| 2239 | #Method void preConcat(const SkMatrix& other) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2240 | #In Set |
| 2241 | #In Operator |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2242 | #Line # pre-multiplies Matrix by Matrix parameter ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2243 | Sets Matrix to Matrix multiplied by Matrix other. |
| 2244 | This can be thought of mapping by other before applying Matrix. |
| 2245 | |
| 2246 | Given: |
| 2247 | |
| 2248 | #Code |
| 2249 | #Literal |
| 2250 | | A B C | | J K L | |
| 2251 | Matrix = | D E F |, other = | M N O | |
| 2252 | | G H I | | P Q R | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2253 | ## |
| 2254 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2255 | sets Matrix to: |
| 2256 | |
| 2257 | #Code |
| 2258 | #Literal |
| 2259 | | A B C | | J K L | | AJ+BM+CP AK+BN+CQ AL+BO+CR | |
| 2260 | Matrix * other = | D E F | * | M N O | = | DJ+EM+FP DK+EN+FQ DL+EO+FR | |
| 2261 | | G H I | | P Q R | | GJ+HM+IP GK+HN+IQ GL+HO+IR | |
| 2262 | ## |
| 2263 | |
| 2264 | #Param other Matrix on right side of multiply expression ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2265 | |
| 2266 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2267 | #Image 3 |
| 2268 | #Description |
| 2269 | setPolyToPoly creates perspective matrices, one the inverse of the other. |
| 2270 | Multiplying the matrix by its inverse turns into an identity matrix. |
| 2271 | ## |
| 2272 | SkMatrix matrix, matrix2; |
| 2273 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 2274 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 2275 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 2276 | matrix2.setPolyToPoly(perspect, bitmapBounds, 4); |
| 2277 | matrix.preConcat(matrix2); |
| 2278 | canvas->concat(matrix); |
| 2279 | canvas->drawBitmap(source, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2280 | ## |
| 2281 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2282 | #SeeAlso postConcat setConcat Concat |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2283 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2284 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2285 | |
| 2286 | # ------------------------------------------------------------------------------ |
| 2287 | |
| 2288 | #Method void postTranslate(SkScalar dx, SkScalar dy) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2289 | #In Set |
| 2290 | #In Operator |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2291 | #Line # post-multiplies Matrix by translation ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2292 | Sets Matrix to Matrix constructed from translation (dx, dy) multiplied by Matrix. |
| 2293 | This can be thought of as moving the point to be mapped after applying Matrix. |
| 2294 | |
| 2295 | Given: |
| 2296 | |
| 2297 | #Code |
| 2298 | #Literal |
| 2299 | | J K L | | 1 0 dx | |
| 2300 | Matrix = | M N O |, T(dx, dy) = | 0 1 dy | |
| 2301 | | P Q R | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2302 | ## |
| 2303 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2304 | sets Matrix to: |
| 2305 | |
| 2306 | #Code |
| 2307 | #Literal |
| 2308 | | 1 0 dx | | J K L | | J+dx*P K+dx*Q L+dx*R | |
| 2309 | T(dx, dy) * Matrix = | 0 1 dy | | M N O | = | M+dy*P N+dy*Q O+dy*R | |
| 2310 | | 0 0 1 | | P Q R | | P Q R | |
| 2311 | ## |
| 2312 | |
| 2313 | #Param dx x translation after applying Matrix ## |
| 2314 | #Param dy y translation after applying Matrix ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2315 | |
| 2316 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2317 | #Height 160 |
| 2318 | #Description |
| 2319 | Compare with preTranslate example. |
| 2320 | ## |
| 2321 | SkPaint paint; |
| 2322 | paint.setAntiAlias(true); |
| 2323 | SkRect rect = {20, 20, 100, 100}; |
| 2324 | for (int i = 0; i < 2; ++i ) { |
| 2325 | SkMatrix matrix; |
| 2326 | i == 0 ? matrix.reset(): matrix.setRotate(25, rect.centerX(), 320); |
| 2327 | { |
| 2328 | SkAutoCanvasRestore acr(canvas, true); |
| 2329 | canvas->concat(matrix); |
| 2330 | paint.setColor(SK_ColorGRAY); |
| 2331 | canvas->drawRect(rect, paint); |
| 2332 | } |
| 2333 | paint.setColor(SK_ColorRED); |
| 2334 | for (int j = 0; j < 2; ++j ) { |
| 2335 | SkAutoCanvasRestore acr(canvas, true); |
| 2336 | matrix.postTranslate(40, 40); |
| 2337 | canvas->concat(matrix); |
| 2338 | canvas->drawCircle(0, 0, 3, paint); |
| 2339 | } |
| 2340 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2341 | ## |
| 2342 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2343 | #SeeAlso preTranslate setTranslate MakeTrans |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2344 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2345 | #Method ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2346 | |
| 2347 | # ------------------------------------------------------------------------------ |
| 2348 | |
| 2349 | #Method void postScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2350 | #In Set |
| 2351 | #In Operator |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2352 | #Line # post-multiplies Matrix by scale ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2353 | Sets Matrix to Matrix constructed from scaling by (sx, sy) about pivot point |
| 2354 | (px, py), multiplied by Matrix. |
| 2355 | This can be thought of as scaling about a pivot point after applying Matrix. |
| 2356 | |
| 2357 | Given: |
| 2358 | |
| 2359 | #Code |
| 2360 | #Literal |
| 2361 | | J K L | | sx 0 dx | |
| 2362 | Matrix = | M N O |, S(sx, sy, px, py) = | 0 sy dy | |
| 2363 | | P Q R | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2364 | ## |
| 2365 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2366 | where |
| 2367 | |
| 2368 | #Code |
| 2369 | #Literal |
| 2370 | dx = px - sx * px |
| 2371 | dy = py - sy * py |
| 2372 | ## |
| 2373 | |
| 2374 | sets Matrix to: |
| 2375 | |
| 2376 | #Code |
| 2377 | #Literal |
| 2378 | | sx 0 dx | | J K L | | sx*J+dx*P sx*K+dx*Q sx*L+dx+R | |
| 2379 | S(sx, sy, px, py) * Matrix = | 0 sy dy | | M N O | = | sy*M+dy*P sy*N+dy*Q sy*O+dy*R | |
| 2380 | | 0 0 1 | | P Q R | | P Q R | |
| 2381 | ## |
| 2382 | |
| 2383 | #Param sx horizontal scale factor ## |
| 2384 | #Param sy vertical scale factor ## |
| 2385 | #Param px pivot x ## |
| 2386 | #Param py pivot y ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2387 | |
| 2388 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2389 | #Image 3 |
| 2390 | SkMatrix matrix; |
| 2391 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 2392 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 2393 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 2394 | matrix.postScale(.75f, 1.5f, source.width() / 2, source.height() / 2); |
| 2395 | canvas->concat(matrix); |
| 2396 | canvas->drawBitmap(source, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2397 | ## |
| 2398 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2399 | #SeeAlso preScale setScale MakeScale |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2400 | |
| 2401 | ## |
| 2402 | |
| 2403 | # ------------------------------------------------------------------------------ |
| 2404 | |
| 2405 | #Method void postScale(SkScalar sx, SkScalar sy) |
| 2406 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2407 | Sets Matrix to Matrix constructed from scaling by (sx, sy) about pivot point |
| 2408 | (0, 0), multiplied by Matrix. |
| 2409 | This can be thought of as scaling about the origin after applying Matrix. |
| 2410 | |
| 2411 | Given: |
| 2412 | |
| 2413 | #Code |
| 2414 | #Literal |
| 2415 | | J K L | | sx 0 0 | |
| 2416 | Matrix = | M N O |, S(sx, sy) = | 0 sy 0 | |
| 2417 | | P Q R | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2418 | ## |
| 2419 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2420 | sets Matrix to: |
| 2421 | |
| 2422 | #Code |
| 2423 | #Literal |
| 2424 | | sx 0 0 | | J K L | | sx*J sx*K sx*L | |
| 2425 | S(sx, sy) * Matrix = | 0 sy 0 | | M N O | = | sy*M sy*N sy*O | |
| 2426 | | 0 0 1 | | P Q R | | P Q R | |
| 2427 | ## |
| 2428 | |
| 2429 | #Param sx horizontal scale factor ## |
| 2430 | #Param sy vertical scale factor ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2431 | |
| 2432 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2433 | #Image 3 |
| 2434 | SkMatrix matrix; |
| 2435 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 2436 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 2437 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 2438 | matrix.postScale(.75f, 1.5f); |
| 2439 | canvas->concat(matrix); |
| 2440 | canvas->drawBitmap(source, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2441 | ## |
| 2442 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2443 | #SeeAlso preScale setScale MakeScale |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2444 | |
| 2445 | ## |
| 2446 | |
| 2447 | # ------------------------------------------------------------------------------ |
| 2448 | |
| 2449 | #Method bool postIDiv(int divx, int divy) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2450 | #In Set |
| 2451 | #In Operator |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2452 | #Line # post-multiplies Matrix by inverse scale ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2453 | Sets Matrix to Matrix constructed from scaling by |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2454 | #Formula |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2455 | (1/divx, 1/divy) |
| 2456 | ## |
| 2457 | about pivot point (px, py), multiplied by Matrix. |
| 2458 | |
| 2459 | Returns false if either divx or divy is zero. |
| 2460 | |
| 2461 | Given: |
| 2462 | |
| 2463 | #Code |
| 2464 | #Literal |
| 2465 | | J K L | | sx 0 0 | |
| 2466 | Matrix = | M N O |, I(divx, divy) = | 0 sy 0 | |
| 2467 | | P Q R | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2468 | ## |
| 2469 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2470 | where |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2471 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2472 | #Code |
| 2473 | #Literal |
| 2474 | sx = 1 / divx |
| 2475 | sy = 1 / divy |
| 2476 | ## |
| 2477 | |
| 2478 | sets Matrix to: |
| 2479 | |
| 2480 | #Code |
| 2481 | #Literal |
| 2482 | | sx 0 0 | | J K L | | sx*J sx*K sx*L | |
| 2483 | I(divx, divy) * Matrix = | 0 sy 0 | | M N O | = | sy*M sy*N sy*O | |
| 2484 | | 0 0 1 | | P Q R | | P Q R | |
| 2485 | ## |
| 2486 | |
| 2487 | #Param divx integer divisor for inverse scale in x ## |
| 2488 | #Param divy integer divisor for inverse scale in y ## |
| 2489 | |
| 2490 | #Return true on successful scale ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2491 | |
| 2492 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2493 | #Image 3 |
| 2494 | SkMatrix matrix, matrix2; |
| 2495 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 2496 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 2497 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 2498 | matrix.postIDiv(1, 2); |
| 2499 | canvas->concat(matrix); |
| 2500 | canvas->drawBitmap(source, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2501 | ## |
| 2502 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2503 | #SeeAlso postScale MakeScale |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2504 | |
| 2505 | ## |
| 2506 | |
| 2507 | # ------------------------------------------------------------------------------ |
| 2508 | |
| 2509 | #Method void postRotate(SkScalar degrees, SkScalar px, SkScalar py) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2510 | #In Set |
| 2511 | #In Operator |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2512 | #Line # post-multiplies Matrix by rotation ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2513 | Sets Matrix to Matrix constructed from rotating by degrees about pivot point |
| 2514 | (px, py), multiplied by Matrix. |
| 2515 | This can be thought of as rotating about a pivot point after applying Matrix. |
| 2516 | |
| 2517 | Positive degrees rotates clockwise. |
| 2518 | |
| 2519 | Given: |
| 2520 | |
| 2521 | #Code |
| 2522 | #Literal |
| 2523 | | J K L | | c -s dx | |
| 2524 | Matrix = | M N O |, R(degrees, px, py) = | s c dy | |
| 2525 | | P Q R | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2526 | ## |
| 2527 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2528 | where |
| 2529 | |
| 2530 | #Code |
| 2531 | #Literal |
| 2532 | c = cos(degrees) |
| 2533 | s = sin(degrees) |
| 2534 | dx = s * py + (1 - c) * px |
| 2535 | dy = -s * px + (1 - c) * py |
| 2536 | ## |
| 2537 | |
| 2538 | sets Matrix to: |
| 2539 | |
| 2540 | #Code |
| 2541 | #Literal |
| 2542 | |c -s dx| |J K L| |cJ-sM+dx*P cK-sN+dx*Q cL-sO+dx+R| |
| 2543 | R(degrees, px, py) * Matrix = |s c dy| |M N O| = |sJ+cM+dy*P sK+cN+dy*Q sL+cO+dy*R| |
| 2544 | |0 0 1| |P Q R| | P Q R| |
| 2545 | ## |
| 2546 | |
| 2547 | #Param degrees angle of axes relative to upright axes ## |
| 2548 | #Param px pivot x ## |
| 2549 | #Param py pivot y ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2550 | |
| 2551 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2552 | #Image 3 |
| 2553 | SkMatrix matrix; |
| 2554 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 2555 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 2556 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 2557 | matrix.postRotate(45, source.width() / 2, source.height() / 2); |
| 2558 | canvas->concat(matrix); |
| 2559 | canvas->drawBitmap(source, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2560 | ## |
| 2561 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2562 | #SeeAlso preRotate setRotate |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2563 | |
| 2564 | ## |
| 2565 | |
| 2566 | # ------------------------------------------------------------------------------ |
| 2567 | |
| 2568 | #Method void postRotate(SkScalar degrees) |
| 2569 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2570 | Sets Matrix to Matrix constructed from rotating by degrees about pivot point |
| 2571 | (0, 0), multiplied by Matrix. |
| 2572 | This can be thought of as rotating about the origin after applying Matrix. |
| 2573 | |
| 2574 | Positive degrees rotates clockwise. |
| 2575 | |
| 2576 | Given: |
| 2577 | |
| 2578 | #Code |
| 2579 | #Literal |
| 2580 | | J K L | | c -s 0 | |
| 2581 | Matrix = | M N O |, R(degrees, px, py) = | s c 0 | |
| 2582 | | P Q R | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2583 | ## |
| 2584 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2585 | where |
| 2586 | |
| 2587 | #Code |
| 2588 | #Literal |
| 2589 | c = cos(degrees) |
| 2590 | s = sin(degrees) |
| 2591 | ## |
| 2592 | |
| 2593 | sets Matrix to: |
| 2594 | |
| 2595 | #Code |
| 2596 | #Literal |
| 2597 | | c -s dx | | J K L | | cJ-sM cK-sN cL-sO | |
| 2598 | R(degrees, px, py) * Matrix = | s c dy | | M N O | = | sJ+cM sK+cN sL+cO | |
| 2599 | | 0 0 1 | | P Q R | | P Q R | |
| 2600 | ## |
| 2601 | |
| 2602 | #Param degrees angle of axes relative to upright axes ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2603 | |
| 2604 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2605 | #Image 3 |
| 2606 | SkMatrix matrix; |
| 2607 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 2608 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 2609 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 2610 | matrix.postRotate(45); |
| 2611 | canvas->concat(matrix); |
| 2612 | canvas->drawBitmap(source, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2613 | ## |
| 2614 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2615 | #SeeAlso preRotate setRotate |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2616 | |
| 2617 | ## |
| 2618 | |
| 2619 | # ------------------------------------------------------------------------------ |
| 2620 | |
| 2621 | #Method void postSkew(SkScalar kx, SkScalar ky, SkScalar px, SkScalar py) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2622 | #In Set |
| 2623 | #In Operator |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2624 | #Line # post-multiplies Matrix by skew ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2625 | Sets Matrix to Matrix constructed from skewing by (kx, ky) about pivot point |
| 2626 | (px, py), multiplied by Matrix. |
| 2627 | This can be thought of as skewing about a pivot point after applying Matrix. |
| 2628 | |
| 2629 | Given: |
| 2630 | |
| 2631 | #Code |
| 2632 | #Literal |
| 2633 | | J K L | | 1 kx dx | |
| 2634 | Matrix = | M N O |, K(kx, ky, px, py) = | ky 1 dy | |
| 2635 | | P Q R | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2636 | ## |
| 2637 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2638 | where |
| 2639 | |
| 2640 | #Code |
| 2641 | #Literal |
| 2642 | dx = -kx * py |
| 2643 | dy = -ky * px |
| 2644 | ## |
| 2645 | |
| 2646 | sets Matrix to: |
| 2647 | |
| 2648 | #Code |
| 2649 | #Literal |
| 2650 | | 1 kx dx| |J K L| |J+kx*M+dx*P K+kx*N+dx*Q L+kx*O+dx+R| |
| 2651 | 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| |
| 2652 | | 0 0 1| |P Q R| | P Q R| |
| 2653 | ## |
| 2654 | |
| 2655 | #Param kx horizontal skew factor ## |
| 2656 | #Param ky vertical skew factor ## |
| 2657 | #Param px pivot x ## |
| 2658 | #Param py pivot y ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2659 | |
| 2660 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2661 | #Image 3 |
| 2662 | SkMatrix matrix; |
| 2663 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 2664 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 2665 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 2666 | matrix.postSkew(.5f, 0, source.width() / 2, source.height() / 2); |
| 2667 | canvas->concat(matrix); |
| 2668 | canvas->drawBitmap(source, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2669 | ## |
| 2670 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2671 | #SeeAlso preSkew setSkew |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2672 | |
| 2673 | ## |
| 2674 | |
| 2675 | # ------------------------------------------------------------------------------ |
| 2676 | |
| 2677 | #Method void postSkew(SkScalar kx, SkScalar ky) |
| 2678 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2679 | Sets Matrix to Matrix constructed from skewing by (kx, ky) about pivot point |
| 2680 | (0, 0), multiplied by Matrix. |
| 2681 | This can be thought of as skewing about the origin after applying Matrix. |
| 2682 | |
| 2683 | Given: |
| 2684 | |
| 2685 | #Code |
| 2686 | #Literal |
| 2687 | | J K L | | 1 kx 0 | |
| 2688 | Matrix = | M N O |, K(kx, ky) = | ky 1 0 | |
| 2689 | | P Q R | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2690 | ## |
| 2691 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2692 | sets Matrix to: |
| 2693 | |
| 2694 | #Code |
| 2695 | #Literal |
| 2696 | | 1 kx 0 | | J K L | | J+kx*M K+kx*N L+kx*O | |
| 2697 | K(kx, ky) * Matrix = | ky 1 0 | | M N O | = | ky*J+M ky*K+N ky*L+O | |
| 2698 | | 0 0 1 | | P Q R | | P Q R | |
| 2699 | ## |
| 2700 | |
| 2701 | #Param kx horizontal skew factor ## |
| 2702 | #Param ky vertical skew factor ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2703 | |
| 2704 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2705 | #Image 3 |
| 2706 | SkMatrix matrix; |
| 2707 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 2708 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 2709 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 2710 | matrix.postSkew(.5f, 0); |
| 2711 | canvas->concat(matrix); |
| 2712 | canvas->drawBitmap(source, 0, 0); |
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 | #SeeAlso preSkew setSkew |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2716 | |
| 2717 | ## |
| 2718 | |
| 2719 | # ------------------------------------------------------------------------------ |
| 2720 | |
| 2721 | #Method void postConcat(const SkMatrix& other) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2722 | #In Set |
| 2723 | #In Operator |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2724 | #Line # post-multiplies Matrix by Matrix parameter ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2725 | Sets Matrix to Matrix other multiplied by Matrix. |
| 2726 | This can be thought of mapping by other after applying Matrix. |
| 2727 | |
| 2728 | Given: |
| 2729 | |
| 2730 | #Code |
| 2731 | #Literal |
| 2732 | | J K L | | A B C | |
| 2733 | Matrix = | M N O |, other = | D E F | |
| 2734 | | P Q R | | G H I | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2735 | ## |
| 2736 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2737 | sets Matrix to: |
| 2738 | |
| 2739 | #Code |
| 2740 | #Literal |
| 2741 | | A B C | | J K L | | AJ+BM+CP AK+BN+CQ AL+BO+CR | |
| 2742 | other * Matrix = | D E F | * | M N O | = | DJ+EM+FP DK+EN+FQ DL+EO+FR | |
| 2743 | | G H I | | P Q R | | GJ+HM+IP GK+HN+IQ GL+HO+IR | |
| 2744 | ## |
| 2745 | |
| 2746 | #Param other Matrix on left side of multiply expression ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2747 | |
| 2748 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2749 | #Image 3 |
| 2750 | #Height 64 |
| 2751 | SkMatrix matrix, matrix2; |
| 2752 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 2753 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 2754 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 2755 | matrix.postConcat(matrix); |
| 2756 | canvas->concat(matrix); |
| 2757 | canvas->drawBitmap(source, 0, 0); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2758 | ## |
| 2759 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2760 | #SeeAlso preConcat setConcat Concat |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2761 | |
| 2762 | ## |
| 2763 | |
| 2764 | # ------------------------------------------------------------------------------ |
| 2765 | |
| 2766 | #Enum ScaleToFit |
| 2767 | |
| 2768 | #Code |
| 2769 | enum ScaleToFit { |
| 2770 | kFill_ScaleToFit, |
| 2771 | kStart_ScaleToFit, |
| 2772 | kCenter_ScaleToFit, |
| 2773 | kEnd_ScaleToFit, |
| 2774 | }; |
| 2775 | ## |
| 2776 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2777 | ScaleToFit describes how Matrix is constructed to map one Rect to another. |
| 2778 | ScaleToFit may allow Matrix to have unequal horizontal and vertical scaling, |
| 2779 | or may restrict Matrix to square scaling. If restricted, ScaleToFit specifies |
| 2780 | how Matrix maps to the side or center of the destination Rect. |
| 2781 | |
| 2782 | #Const kFill_ScaleToFit 0 |
| 2783 | Computes Matrix that scales in x and y independently, so that source Rect is |
| 2784 | mapped to completely fill destination Rect. The aspect ratio of source Rect |
| 2785 | may change. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2786 | ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2787 | #Const kStart_ScaleToFit 1 |
| 2788 | Computes Matrix that maintains source Rect aspect ratio, mapping source Rect |
| 2789 | width or height to destination Rect. Aligns mapping to left and top edges |
| 2790 | of destination Rect. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2791 | ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2792 | #Const kCenter_ScaleToFit 2 |
| 2793 | Computes Matrix that maintains source Rect aspect ratio, mapping source Rect |
| 2794 | width or height to destination Rect. Aligns mapping to center of destination |
| 2795 | Rect. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2796 | ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2797 | #Const kEnd_ScaleToFit 3 |
| 2798 | Computes Matrix that maintains source Rect aspect ratio, mapping source Rect |
| 2799 | width or height to destination Rect. Aligns mapping to right and bottom |
| 2800 | edges of destination Rect. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2801 | ## |
| 2802 | |
| 2803 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2804 | const char* labels[] = { "Fill", "Start", "Center", "End" }; |
| 2805 | SkRect rects[] = {{5, 5, 59, 59}, {5, 74, 59, 108}, {10, 123, 44, 172}, {10, 187, 54, 231}}; |
| 2806 | SkRect bounds; |
| 2807 | source.getBounds(&bounds); |
| 2808 | SkPaint paint; |
| 2809 | paint.setAntiAlias(true); |
| 2810 | for (auto fit : { SkMatrix::kFill_ScaleToFit, SkMatrix::kStart_ScaleToFit, |
| 2811 | SkMatrix::kCenter_ScaleToFit, SkMatrix::kEnd_ScaleToFit } ) { |
| 2812 | for (auto rect : rects ) { |
| 2813 | canvas->drawRect(rect, paint); |
| 2814 | SkMatrix matrix; |
| 2815 | if (!matrix.setRectToRect(bounds, rect, fit)) { |
| 2816 | continue; |
| 2817 | } |
| 2818 | SkAutoCanvasRestore acr(canvas, true); |
| 2819 | canvas->concat(matrix); |
| 2820 | canvas->drawBitmap(source, 0, 0); |
| 2821 | } |
| 2822 | canvas->drawString(labels[fit], 10, 255, paint); |
| 2823 | canvas->translate(64, 0); |
| 2824 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2825 | ## |
| 2826 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2827 | #SeeAlso setRectToRect MakeRectToRect setPolyToPoly |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2828 | |
| 2829 | ## |
| 2830 | |
| 2831 | # ------------------------------------------------------------------------------ |
| 2832 | |
| 2833 | #Method bool setRectToRect(const SkRect& src, const SkRect& dst, ScaleToFit stf) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2834 | #In Set |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2835 | #Line # sets to map one Rect to another ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2836 | Sets Matrix to scale and translate src Rect to dst Rect. stf selects whether |
| 2837 | mapping completely fills dst or preserves the aspect ratio, and how to align |
| 2838 | src within dst. Returns false if src is empty, and sets Matrix to identity. |
| 2839 | Returns true if dst is empty, and sets Matrix to: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2840 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2841 | #Code |
| 2842 | #Literal |
| 2843 | | 0 0 0 | |
| 2844 | | 0 0 0 | |
| 2845 | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2846 | ## |
| 2847 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2848 | #Param src Rect to map from ## |
| 2849 | #Param dst Rect to map to ## |
| 2850 | #Param stf one of: kFill_ScaleToFit, kStart_ScaleToFit, |
| 2851 | kCenter_ScaleToFit, kEnd_ScaleToFit |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2852 | ## |
| 2853 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2854 | #Return true if Matrix can represent Rect mapping ## |
| 2855 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2856 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2857 | const SkRect srcs[] = { {0, 0, 0, 0}, {1, 2, 3, 4} }; |
| 2858 | const SkRect dsts[] = { {0, 0, 0, 0}, {5, 6, 8, 9} }; |
| 2859 | for (auto src : srcs) { |
| 2860 | for (auto dst : dsts) { |
| 2861 | SkMatrix matrix; |
| 2862 | matrix.setAll(-1, -1, -1, -1, -1, -1, -1, -1, -1); |
| 2863 | bool success = matrix.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit); |
| 2864 | SkDebugf("src: %g, %g, %g, %g dst: %g, %g, %g, %g success: %s\n", |
| 2865 | src.fLeft, src.fTop, src.fRight, src.fBottom, |
| 2866 | dst.fLeft, dst.fTop, dst.fRight, dst.fBottom, success ? "true" : "false"); |
| 2867 | matrix.dump(); |
| 2868 | } |
| 2869 | } |
| 2870 | #StdOut |
| 2871 | src: 0, 0, 0, 0 dst: 0, 0, 0, 0 success: false |
| 2872 | [ 1.0000 0.0000 0.0000][ 0.0000 1.0000 0.0000][ 0.0000 0.0000 1.0000] |
| 2873 | src: 0, 0, 0, 0 dst: 5, 6, 8, 9 success: false |
| 2874 | [ 1.0000 0.0000 0.0000][ 0.0000 1.0000 0.0000][ 0.0000 0.0000 1.0000] |
| 2875 | src: 1, 2, 3, 4 dst: 0, 0, 0, 0 success: true |
| 2876 | [ 0.0000 0.0000 0.0000][ 0.0000 0.0000 0.0000][ 0.0000 0.0000 1.0000] |
| 2877 | src: 1, 2, 3, 4 dst: 5, 6, 8, 9 success: true |
| 2878 | [ 1.5000 0.0000 3.5000][ 0.0000 1.5000 3.0000][ 0.0000 0.0000 1.0000] |
| 2879 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2880 | ## |
| 2881 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2882 | #SeeAlso MakeRectToRect ScaleToFit setPolyToPoly SkRect::isEmpty |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2883 | |
| 2884 | ## |
| 2885 | |
| 2886 | # ------------------------------------------------------------------------------ |
| 2887 | |
| 2888 | #Method static SkMatrix MakeRectToRect(const SkRect& src, const SkRect& dst, ScaleToFit stf) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2889 | #In Constructor |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2890 | #Line # constructs from source Rect to destination Rect ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2891 | Returns Matrix set to scale and translate src Rect to dst Rect. stf selects |
| 2892 | whether mapping completely fills dst or preserves the aspect ratio, and how to |
| 2893 | align src within dst. Returns the identity Matrix if src is empty. If dst is |
| 2894 | empty, returns Matrix set to: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2895 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2896 | #Code |
| 2897 | #Literal |
| 2898 | | 0 0 0 | |
| 2899 | | 0 0 0 | |
| 2900 | | 0 0 1 | |
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 | #Param src Rect to map from ## |
| 2904 | #Param dst Rect to map to ## |
| 2905 | #Param stf one of: kFill_ScaleToFit, kStart_ScaleToFit, |
| 2906 | kCenter_ScaleToFit, kEnd_ScaleToFit |
| 2907 | ## |
| 2908 | |
| 2909 | #Return Matrix mapping src to dst ## |
| 2910 | |
| 2911 | #Example |
| 2912 | const SkRect srcs[] = { {0, 0, 0, 0}, {1, 2, 3, 4} }; |
| 2913 | const SkRect dsts[] = { {0, 0, 0, 0}, {5, 6, 8, 9} }; |
| 2914 | for (auto src : srcs) { |
| 2915 | for (auto dst : dsts) { |
| 2916 | SkMatrix matrix = SkMatrix::MakeRectToRect(src, dst, SkMatrix::kFill_ScaleToFit); |
| 2917 | SkDebugf("src: %g, %g, %g, %g dst: %g, %g, %g, %g\n", |
| 2918 | src.fLeft, src.fTop, src.fRight, src.fBottom, |
| 2919 | dst.fLeft, dst.fTop, dst.fRight, dst.fBottom); |
| 2920 | matrix.dump(); |
| 2921 | } |
| 2922 | } |
| 2923 | #StdOut |
| 2924 | src: 0, 0, 0, 0 dst: 0, 0, 0, 0 |
| 2925 | [ 1.0000 0.0000 0.0000][ 0.0000 1.0000 0.0000][ 0.0000 0.0000 1.0000] |
| 2926 | src: 0, 0, 0, 0 dst: 5, 6, 8, 9 |
| 2927 | [ 1.0000 0.0000 0.0000][ 0.0000 1.0000 0.0000][ 0.0000 0.0000 1.0000] |
| 2928 | src: 1, 2, 3, 4 dst: 0, 0, 0, 0 |
| 2929 | [ 0.0000 0.0000 0.0000][ 0.0000 0.0000 0.0000][ 0.0000 0.0000 1.0000] |
| 2930 | src: 1, 2, 3, 4 dst: 5, 6, 8, 9 |
| 2931 | [ 1.5000 0.0000 3.5000][ 0.0000 1.5000 3.0000][ 0.0000 0.0000 1.0000] |
| 2932 | ## |
| 2933 | ## |
| 2934 | |
| 2935 | #SeeAlso setRectToRect ScaleToFit setPolyToPoly SkRect::isEmpty |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2936 | |
| 2937 | ## |
| 2938 | |
| 2939 | # ------------------------------------------------------------------------------ |
| 2940 | |
| 2941 | #Method bool setPolyToPoly(const SkPoint src[], const SkPoint dst[], int count) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2942 | #In Set |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2943 | #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] | 2944 | 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] | 2945 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2946 | If count is zero, sets Matrix to identity and returns true. |
| 2947 | If count is one, sets Matrix to translate and returns true. |
| 2948 | If count is two or more, sets Matrix to map Points if possible; returns false |
| 2949 | if Matrix cannot be constructed. If count is four, Matrix may include |
| 2950 | perspective. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2951 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2952 | #Param src Points to map from ## |
| 2953 | #Param dst Points to map to ## |
| 2954 | #Param count number of Points in src and dst ## |
| 2955 | |
| 2956 | #Return true if Matrix was constructed successfully |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2957 | ## |
| 2958 | |
| 2959 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2960 | const SkPoint src[] = { { 0, 0}, {30, 0}, {30, -30}, { 0, -30} }; |
| 2961 | const SkPoint dst[] = { {50, 0}, {80, -10}, {90, -30}, {60, -40} }; |
| 2962 | SkPaint blackPaint; |
| 2963 | blackPaint.setAntiAlias(true); |
| 2964 | blackPaint.setTextSize(42); |
| 2965 | SkPaint redPaint = blackPaint; |
| 2966 | redPaint.setColor(SK_ColorRED); |
| 2967 | for (int count : { 1, 2, 3, 4 } ) { |
| 2968 | canvas->translate(35, 55); |
| 2969 | for (int index = 0; index < count; ++index) { |
| 2970 | canvas->drawCircle(src[index], 3, blackPaint); |
| 2971 | canvas->drawCircle(dst[index], 3, blackPaint); |
| 2972 | if (index > 0) { |
| 2973 | canvas->drawLine(src[index], src[index - 1], blackPaint); |
| 2974 | canvas->drawLine(dst[index], dst[index - 1], blackPaint); |
| 2975 | } |
| 2976 | } |
| 2977 | SkMatrix matrix; |
| 2978 | matrix.setPolyToPoly(src, dst, count); |
| 2979 | canvas->drawString("A", src[0].fX, src[0].fY, redPaint); |
| 2980 | SkAutoCanvasRestore acr(canvas, true); |
| 2981 | canvas->concat(matrix); |
| 2982 | canvas->drawString("A", src[0].fX, src[0].fY, redPaint); |
| 2983 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2984 | ## |
| 2985 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2986 | #SeeAlso setRectToRect MakeRectToRect |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2987 | |
| 2988 | ## |
| 2989 | |
| 2990 | # ------------------------------------------------------------------------------ |
| 2991 | |
| 2992 | #Method bool SK_WARN_UNUSED_RESULT invert(SkMatrix* inverse) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2993 | #In Operator |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2994 | #Line # returns inverse, if possible ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 2995 | Sets inverse to reciprocal matrix, returning true if Matrix can be inverted. |
| 2996 | Geometrically, if Matrix maps from source to destination, inverse Matrix |
| 2997 | maps from destination to source. If Matrix can not be inverted, inverse is |
| 2998 | unchanged. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2999 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3000 | #Param inverse storage for inverted Matrix; may be nullptr ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3001 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3002 | #Return true if Matrix can be inverted ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3003 | |
| 3004 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3005 | #Height 128 |
| 3006 | const SkPoint src[] = { { 10, 120}, {120, 120}, {120, 10}, { 10, 10} }; |
| 3007 | const SkPoint dst[] = { {150, 120}, {200, 100}, {240, 30}, { 130, 40} }; |
| 3008 | SkPaint paint; |
| 3009 | paint.setAntiAlias(true); |
| 3010 | SkMatrix matrix; |
| 3011 | matrix.setPolyToPoly(src, dst, 4); |
| 3012 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, 4, src, paint); |
| 3013 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, 4, dst, paint); |
| 3014 | paint.setColor(SK_ColorBLUE); |
| 3015 | paint.setStrokeWidth(3); |
| 3016 | paint.setStrokeCap(SkPaint::kRound_Cap); |
| 3017 | canvas->drawPoints(SkCanvas::kPoints_PointMode, 4, dst, paint); |
| 3018 | matrix.invert(&matrix); |
| 3019 | canvas->concat(matrix); |
| 3020 | canvas->drawPoints(SkCanvas::kPoints_PointMode, 4, dst, paint); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3021 | ## |
| 3022 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3023 | #SeeAlso Concat |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3024 | |
| 3025 | ## |
| 3026 | |
| 3027 | # ------------------------------------------------------------------------------ |
| 3028 | |
| 3029 | #Method static void SetAffineIdentity(SkScalar affine[6]) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 3030 | #In Constructor |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3031 | #Line # sets 3x2 array to identity ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3032 | Fills affine with identity values in column major order. |
| 3033 | Sets affine to: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3034 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3035 | #Code |
| 3036 | #Literal |
| 3037 | | 1 0 0 | |
| 3038 | | 0 1 0 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3039 | ## |
| 3040 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3041 | Affine 3x2 matrices in column major order are used by OpenGL and XPS. |
| 3042 | |
| 3043 | #Param affine storage for 3x2 affine matrix ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3044 | |
| 3045 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3046 | SkScalar affine[6]; |
| 3047 | SkMatrix::SetAffineIdentity(affine); |
| 3048 | const char* names[] = { "ScaleX", "SkewY", "SkewX", "ScaleY", "TransX", "TransY" }; |
| 3049 | for (int i = 0; i < 6; ++i) { |
| 3050 | SkDebugf("%s: %g ", names[i], affine[i]); |
| 3051 | } |
| 3052 | SkDebugf("\n"); |
| 3053 | #StdOut |
| 3054 | ScaleX: 1 SkewY: 0 SkewX: 0 ScaleY: 1 TransX: 0 TransY: 0 |
| 3055 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3056 | ## |
| 3057 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3058 | #SeeAlso setAffine asAffine |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3059 | |
| 3060 | ## |
| 3061 | |
| 3062 | # ------------------------------------------------------------------------------ |
| 3063 | |
| 3064 | #Method bool SK_WARN_UNUSED_RESULT asAffine(SkScalar affine[6]) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 3065 | #In Constructor |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3066 | #Line # copies to 3x2 array ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3067 | Fills affine in column major order. Sets affine to: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3068 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3069 | #Code |
| 3070 | #Literal |
| 3071 | | scale-x skew-x translate-x | |
| 3072 | | skew-y scale-y translate-y | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3073 | ## |
| 3074 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3075 | If Matrix contains perspective, returns false and leaves affine unchanged. |
| 3076 | |
| 3077 | #Param affine storage for 3x2 affine matrix; may be nullptr ## |
| 3078 | |
| 3079 | #Return true if Matrix does not contain perspective ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3080 | |
| 3081 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3082 | SkMatrix matrix; |
| 3083 | matrix.setAll(2, 3, 4, 5, 6, 7, 0, 0, 1); |
| 3084 | SkScalar affine[6]; |
| 3085 | matrix.asAffine(affine); |
| 3086 | const char* names[] = { "ScaleX", "SkewY", "SkewX", "ScaleY", "TransX", "TransY" }; |
| 3087 | for (int i = 0; i < 6; ++i) { |
| 3088 | SkDebugf("%s: %g ", names[i], affine[i]); |
| 3089 | } |
| 3090 | SkDebugf("\n"); |
| 3091 | #StdOut |
| 3092 | ScaleX: 2 SkewY: 5 SkewX: 3 ScaleY: 6 TransX: 4 TransY: 7 |
| 3093 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3094 | ## |
| 3095 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3096 | #SeeAlso setAffine SetAffineIdentity |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3097 | |
| 3098 | ## |
| 3099 | |
| 3100 | # ------------------------------------------------------------------------------ |
| 3101 | |
| 3102 | #Method void setAffine(const SkScalar affine[6]) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 3103 | #In Constructor |
| 3104 | #In Set |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3105 | #Line # sets left two columns ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3106 | Sets Matrix to affine values, passed in column major order. Given affine, |
| 3107 | column, then row, as: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3108 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3109 | #Code |
| 3110 | #Literal |
| 3111 | | scale-x skew-x translate-x | |
| 3112 | | skew-y scale-y translate-y | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3113 | ## |
| 3114 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3115 | Matrix is set, row, then column, to: |
| 3116 | |
| 3117 | #Code |
| 3118 | #Literal |
| 3119 | | scale-x skew-x translate-x | |
| 3120 | | skew-y scale-y translate-y | |
| 3121 | | 0 0 1 | |
| 3122 | ## |
| 3123 | |
| 3124 | #Param affine 3x2 affine matrix ## |
| 3125 | |
| 3126 | #Example |
| 3127 | SkMatrix matrix; |
| 3128 | matrix.setAll(2, 3, 4, 5, 6, 7, 0, 0, 1); |
| 3129 | SkScalar affine[6]; |
| 3130 | matrix.asAffine(affine); |
| 3131 | const char* names[] = { "ScaleX", "SkewY", "SkewX", "ScaleY", "TransX", "TransY" }; |
| 3132 | for (int i = 0; i < 6; ++i) { |
| 3133 | SkDebugf("%s: %g ", names[i], affine[i]); |
| 3134 | } |
| 3135 | SkDebugf("\n"); |
| 3136 | matrix.reset(); |
| 3137 | matrix.setAffine(affine); |
| 3138 | matrix.dump(); |
| 3139 | #StdOut |
| 3140 | ScaleX: 2 SkewY: 5 SkewX: 3 ScaleY: 6 TransX: 4 TransY: 7 |
| 3141 | [ 2.0000 3.0000 4.0000][ 5.0000 6.0000 7.0000][ 0.0000 0.0000 1.0000] |
| 3142 | ## |
| 3143 | ## |
| 3144 | |
| 3145 | #SeeAlso asAffine SetAffineIdentity |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3146 | |
| 3147 | ## |
| 3148 | |
| 3149 | # ------------------------------------------------------------------------------ |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 3150 | #Subtopic Transform |
| 3151 | #Populate |
| 3152 | #Line # map points with Matrix ## |
| 3153 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3154 | |
| 3155 | #Method void mapPoints(SkPoint dst[], const SkPoint src[], int count) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 3156 | #In Transform |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3157 | #Line # maps Point array ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3158 | Maps src Point array of length count to dst Point array of equal or greater |
| 3159 | length. Points are mapped by multiplying each Point by Matrix. Given: |
| 3160 | |
| 3161 | #Code |
| 3162 | #Literal |
| 3163 | | A B C | | x | |
| 3164 | Matrix = | D E F |, pt = | y | |
| 3165 | | G H I | | 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3166 | ## |
| 3167 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3168 | where |
| 3169 | |
| 3170 | #Code |
| 3171 | #Literal |
| 3172 | for (i = 0; i < count; ++i) { |
| 3173 | x = src[i].fX |
| 3174 | y = src[i].fY |
| 3175 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3176 | ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3177 | |
| 3178 | each dst Point is computed as: |
| 3179 | |
| 3180 | #Code |
| 3181 | #Literal |
| 3182 | |A B C| |x| Ax+By+C Dx+Ey+F |
| 3183 | Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , ------- |
| 3184 | |G H I| |1| Gx+Hy+I Gx+Hy+I |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3185 | ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3186 | |
| 3187 | src and dst may point to the same storage. |
| 3188 | |
| 3189 | #Param dst storage for mapped Points ## |
| 3190 | #Param src Points to transform ## |
| 3191 | #Param count number of Points to transform ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3192 | |
| 3193 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3194 | SkMatrix matrix; |
| 3195 | matrix.reset(); |
| 3196 | const int count = 4; |
| 3197 | SkPoint src[count]; |
| 3198 | matrix.mapRectToQuad(src, {40, 70, 180, 220} ); |
| 3199 | SkPaint paint; |
| 3200 | paint.setARGB(77, 23, 99, 154); |
| 3201 | for (int i = 0; i < 5; ++i) { |
| 3202 | SkPoint dst[count]; |
| 3203 | matrix.mapPoints(dst, src, count); |
| 3204 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, count, dst, paint); |
| 3205 | matrix.preRotate(35, 128, 128); |
| 3206 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3207 | ## |
| 3208 | |
Brian Salomon | fa3783f | 2018-01-05 13:49:07 -0500 | [diff] [blame] | 3209 | #SeeAlso mapXY mapHomogeneousPoints mapVectors |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3210 | |
| 3211 | ## |
| 3212 | |
| 3213 | # ------------------------------------------------------------------------------ |
| 3214 | |
| 3215 | #Method void mapPoints(SkPoint pts[], int count) const |
| 3216 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3217 | Maps pts Point array of length count in place. Points are mapped by multiplying |
| 3218 | each Point by Matrix. Given: |
| 3219 | |
| 3220 | #Code |
| 3221 | #Literal |
| 3222 | | A B C | | x | |
| 3223 | Matrix = | D E F |, pt = | y | |
| 3224 | | G H I | | 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3225 | ## |
| 3226 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3227 | where |
| 3228 | |
| 3229 | #Code |
| 3230 | #Literal |
| 3231 | for (i = 0; i < count; ++i) { |
| 3232 | x = pts[i].fX |
| 3233 | y = pts[i].fY |
| 3234 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3235 | ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3236 | |
| 3237 | each resulting pts Point is computed as: |
| 3238 | |
| 3239 | #Code |
| 3240 | #Literal |
| 3241 | |A B C| |x| Ax+By+C Dx+Ey+F |
| 3242 | Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , ------- |
| 3243 | |G H I| |1| Gx+Hy+I Gx+Hy+I |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3244 | ## |
| 3245 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3246 | #Param pts storage for mapped Points ## |
| 3247 | #Param count number of Points to transform ## |
| 3248 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3249 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3250 | SkMatrix matrix; |
| 3251 | matrix.setRotate(35, 128, 128); |
| 3252 | const int count = 4; |
| 3253 | SkPoint pts[count]; |
| 3254 | matrix.mapRectToQuad(pts, {40, 70, 180, 220} ); |
| 3255 | SkPaint paint; |
| 3256 | paint.setARGB(77, 23, 99, 154); |
| 3257 | for (int i = 0; i < 5; ++i) { |
| 3258 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, count, pts, paint); |
| 3259 | matrix.mapPoints(pts, count); |
| 3260 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3261 | ## |
| 3262 | |
Brian Salomon | fa3783f | 2018-01-05 13:49:07 -0500 | [diff] [blame] | 3263 | #SeeAlso mapXY mapHomogeneousPoints mapVectors |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3264 | |
| 3265 | ## |
| 3266 | |
| 3267 | # ------------------------------------------------------------------------------ |
| 3268 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3269 | #Method void mapHomogeneousPoints(SkPoint3 dst[], const SkPoint3 src[], int count) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 3270 | #In Transform |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3271 | #Line # maps Point3 array ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3272 | Maps src Point3 array of length count to dst Point3 array, which must of length count or |
| 3273 | greater. Point3 array is mapped by multiplying each Point3 by Matrix. Given: |
| 3274 | |
| 3275 | #Code |
| 3276 | #Literal |
| 3277 | | A B C | | x | |
| 3278 | Matrix = | D E F |, src = | y | |
| 3279 | | G H I | | z | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3280 | ## |
| 3281 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3282 | each resulting dst Point is computed as: |
| 3283 | |
| 3284 | #Code |
| 3285 | #Literal |
| 3286 | |A B C| |x| |
| 3287 | Matrix * src = |D E F| |y| = |Ax+By+Cz Dx+Ey+Fz Gx+Hy+Iz| |
| 3288 | |G H I| |z| |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3289 | ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3290 | |
| 3291 | #Param dst storage for mapped Point3 array ## |
| 3292 | #Param src Point3 array to transform ## |
| 3293 | #Param count items in Point3 array to transform ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3294 | |
| 3295 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3296 | SkPoint3 src[] = {{3, 3, 1}, {8, 2, 2}, {5, 0, 4}, {0, 1, 3}, |
| 3297 | {3, 7, 1}, {8, 6, 2}, {5, 4, 4}, {0, 5, 3}}; |
| 3298 | 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 }; |
| 3299 | constexpr int count = SK_ARRAY_COUNT(src); |
| 3300 | auto debugster = [=](SkPoint3 src[]) -> void { |
| 3301 | for (size_t i = 0; i < SK_ARRAY_COUNT(lines); i += 2) { |
| 3302 | const SkPoint3& s = src[lines[i]]; |
| 3303 | const SkPoint3& e = src[lines[i + 1]]; |
| 3304 | SkPaint paint; |
| 3305 | paint.setARGB(77, 23, 99, 154); |
| 3306 | canvas->drawLine(s.fX / s.fZ, s.fY / s.fZ, e.fX / e.fZ, e.fY / e.fZ, paint); |
| 3307 | } |
| 3308 | }; |
| 3309 | canvas->save(); |
| 3310 | canvas->translate(5, 5); |
| 3311 | canvas->scale(15, 15); |
| 3312 | debugster(src); |
| 3313 | canvas->restore(); |
| 3314 | canvas->translate(128, 128); |
| 3315 | SkMatrix matrix; |
| 3316 | 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] | 3317 | matrix.mapHomogeneousPoints(src, src, count); |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3318 | debugster(src); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3319 | ## |
| 3320 | |
Brian Salomon | fa3783f | 2018-01-05 13:49:07 -0500 | [diff] [blame] | 3321 | #SeeAlso mapPoints mapXY mapVectors |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3322 | |
| 3323 | ## |
| 3324 | |
| 3325 | # ------------------------------------------------------------------------------ |
| 3326 | |
| 3327 | #Method void mapXY(SkScalar x, SkScalar y, SkPoint* result) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 3328 | #In Transform |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3329 | #Line # maps Point ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3330 | 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] | 3331 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3332 | #Code |
| 3333 | #Literal |
| 3334 | | A B C | | x | |
| 3335 | Matrix = | D E F |, pt = | y | |
| 3336 | | G H I | | 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3337 | ## |
| 3338 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3339 | result is computed as: |
| 3340 | |
| 3341 | #Code |
| 3342 | #Literal |
| 3343 | |A B C| |x| Ax+By+C Dx+Ey+F |
| 3344 | Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , ------- |
| 3345 | |G H I| |1| Gx+Hy+I Gx+Hy+I |
| 3346 | ## |
| 3347 | |
| 3348 | #Param x x-coordinate of Point to map ## |
| 3349 | #Param y y-coordinate of Point to map ## |
| 3350 | #Param result storage for mapped Point ## |
| 3351 | |
| 3352 | #Example |
| 3353 | SkPaint paint; |
| 3354 | paint.setAntiAlias(true); |
| 3355 | SkMatrix matrix; |
| 3356 | matrix.setRotate(60, 128, 128); |
| 3357 | SkPoint lines[] = {{50, 50}, {150, 50}, {150, 150}}; |
| 3358 | for (size_t i = 0; i < SK_ARRAY_COUNT(lines); ++i) { |
| 3359 | SkPoint pt; |
| 3360 | matrix.mapXY(lines[i].fX, lines[i].fY, &pt); |
| 3361 | canvas->drawCircle(pt.fX, pt.fY, 3, paint); |
| 3362 | } |
| 3363 | canvas->concat(matrix); |
| 3364 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(lines), lines, paint); |
| 3365 | ## |
| 3366 | |
Brian Salomon | fa3783f | 2018-01-05 13:49:07 -0500 | [diff] [blame] | 3367 | #SeeAlso mapPoints mapVectors |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3368 | |
| 3369 | ## |
| 3370 | |
| 3371 | # ------------------------------------------------------------------------------ |
| 3372 | |
| 3373 | #Method SkPoint mapXY(SkScalar x, SkScalar y) const |
| 3374 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3375 | Returns Point (x, y) multiplied by Matrix. Given: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3376 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3377 | #Code |
| 3378 | #Literal |
| 3379 | | A B C | | x | |
| 3380 | Matrix = | D E F |, pt = | y | |
| 3381 | | G H I | | 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3382 | ## |
| 3383 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3384 | result is computed as: |
| 3385 | |
| 3386 | #Code |
| 3387 | #Literal |
| 3388 | |A B C| |x| Ax+By+C Dx+Ey+F |
| 3389 | Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , ------- |
| 3390 | |G H I| |1| Gx+Hy+I Gx+Hy+I |
| 3391 | ## |
| 3392 | |
| 3393 | #Param x x-coordinate of Point to map ## |
| 3394 | #Param y y-coordinate of Point to map ## |
| 3395 | |
| 3396 | #Return mapped Point ## |
| 3397 | |
| 3398 | #Example |
| 3399 | #Image 4 |
| 3400 | SkMatrix matrix; |
| 3401 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {30, 206}}; |
| 3402 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 3403 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 3404 | SkPaint paint; |
| 3405 | paint.setAntiAlias(true); |
| 3406 | paint.setStrokeWidth(3); |
| 3407 | for (int x : { 0, source.width() } ) { |
| 3408 | for (int y : { 0, source.height() } ) { |
| 3409 | canvas->drawPoint(matrix.mapXY(x, y), paint); |
| 3410 | } |
| 3411 | } |
| 3412 | canvas->concat(matrix); |
| 3413 | canvas->drawBitmap(source, 0, 0); |
| 3414 | ## |
| 3415 | |
Brian Salomon | fa3783f | 2018-01-05 13:49:07 -0500 | [diff] [blame] | 3416 | #SeeAlso mapPoints mapVectors |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3417 | |
| 3418 | ## |
| 3419 | |
| 3420 | # ------------------------------------------------------------------------------ |
| 3421 | |
| 3422 | #Method void mapVectors(SkVector dst[], const SkVector src[], int count) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 3423 | #In Transform |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3424 | #Line # maps Vector array ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3425 | Maps src Vector array of length count to Vector Point array of equal or greater |
| 3426 | length. Vectors are mapped by multiplying each Vector by Matrix, treating |
| 3427 | Matrix translation as zero. Given: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3428 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3429 | #Code |
| 3430 | #Literal |
| 3431 | | A B 0 | | x | |
| 3432 | Matrix = | D E 0 |, src = | y | |
| 3433 | | G H I | | 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3434 | ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3435 | |
| 3436 | where |
| 3437 | |
| 3438 | #Code |
| 3439 | #Literal |
| 3440 | for (i = 0; i < count; ++i) { |
| 3441 | x = src[i].fX |
| 3442 | y = src[i].fY |
| 3443 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3444 | ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3445 | |
| 3446 | each dst Vector is computed as: |
| 3447 | |
| 3448 | #Code |
| 3449 | #Literal |
| 3450 | |A B 0| |x| Ax+By Dx+Ey |
| 3451 | Matrix * src = |D E 0| |y| = |Ax+By Dx+Ey Gx+Hy+I| = ------- , ------- |
| 3452 | |G H I| |1| Gx+Hy+I Gx+Hy+I |
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 | src and dst may point to the same storage. |
| 3456 | |
| 3457 | #Param dst storage for mapped Vectors ## |
| 3458 | #Param src Vectors to transform ## |
| 3459 | #Param count number of Vectors to transform ## |
| 3460 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3461 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3462 | SkPaint paint; |
| 3463 | paint.setAntiAlias(true); |
| 3464 | paint.setStyle(SkPaint::kStroke_Style); |
| 3465 | SkMatrix matrix; |
| 3466 | matrix.reset(); |
| 3467 | const SkVector radii[] = {{8, 4}, {9, 1}, {6, 2}, {7, 3}}; |
| 3468 | for (int i = 0; i < 4; ++i) { |
| 3469 | SkVector rScaled[4]; |
| 3470 | matrix.preScale(1.5f, 2.f); |
| 3471 | matrix.mapVectors(rScaled, radii, SK_ARRAY_COUNT(radii)); |
| 3472 | SkRRect rrect; |
| 3473 | rrect.setRectRadii({20, 20, 180, 70}, rScaled); |
| 3474 | canvas->drawRRect(rrect, paint); |
| 3475 | canvas->translate(0, 60); |
| 3476 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3477 | ## |
| 3478 | |
Brian Salomon | fa3783f | 2018-01-05 13:49:07 -0500 | [diff] [blame] | 3479 | #SeeAlso mapVector mapPoints mapXY |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3480 | |
| 3481 | ## |
| 3482 | |
| 3483 | # ------------------------------------------------------------------------------ |
| 3484 | |
| 3485 | #Method void mapVectors(SkVector vecs[], int count) const |
| 3486 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3487 | Maps vecs Vector array of length count in place, multiplying each Vector by |
| 3488 | Matrix, treating Matrix translation as zero. Given: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3489 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3490 | #Code |
| 3491 | #Literal |
| 3492 | | A B 0 | | x | |
| 3493 | Matrix = | D E 0 |, vec = | y | |
| 3494 | | G H I | | 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3495 | ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3496 | |
| 3497 | where |
| 3498 | |
| 3499 | #Code |
| 3500 | #Literal |
| 3501 | for (i = 0; i < count; ++i) { |
| 3502 | x = vecs[i].fX |
| 3503 | y = vecs[i].fY |
| 3504 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3505 | ## |
| 3506 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3507 | each result Vector is computed as: |
| 3508 | |
| 3509 | #Code |
| 3510 | #Literal |
| 3511 | |A B 0| |x| Ax+By Dx+Ey |
| 3512 | Matrix * vec = |D E 0| |y| = |Ax+By Dx+Ey Gx+Hy+I| = ------- , ------- |
| 3513 | |G H I| |1| Gx+Hy+I Gx+Hy+I |
| 3514 | ## |
| 3515 | |
| 3516 | #Param vecs Vectors to transform, and storage for mapped Vectors ## |
| 3517 | #Param count number of Vectors to transform ## |
| 3518 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3519 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3520 | SkPaint paint; |
| 3521 | paint.setAntiAlias(true); |
| 3522 | paint.setStyle(SkPaint::kStroke_Style); |
| 3523 | SkMatrix matrix; |
| 3524 | matrix.setScale(2, 3); |
| 3525 | SkVector radii[] = {{7, 7}, {3, 3}, {2, 2}, {4, 0}}; |
| 3526 | for (int i = 0; i < 4; ++i) { |
| 3527 | SkRRect rrect; |
| 3528 | rrect.setRectRadii({20, 20, 180, 70}, radii); |
| 3529 | canvas->drawRRect(rrect, paint); |
| 3530 | canvas->translate(0, 60); |
| 3531 | matrix.mapVectors(radii, SK_ARRAY_COUNT(radii)); |
| 3532 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3533 | ## |
| 3534 | |
Brian Salomon | fa3783f | 2018-01-05 13:49:07 -0500 | [diff] [blame] | 3535 | #SeeAlso mapVector mapPoints mapXY |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3536 | |
| 3537 | ## |
| 3538 | |
| 3539 | # ------------------------------------------------------------------------------ |
| 3540 | |
| 3541 | #Method void mapVector(SkScalar dx, SkScalar dy, SkVector* result) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 3542 | #In Transform |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3543 | #Line # maps Vector ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3544 | Maps Vector (x, y) to result. Vector is mapped by multiplying by Matrix, |
| 3545 | treating Matrix translation as zero. Given: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3546 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3547 | #Code |
| 3548 | #Literal |
| 3549 | | A B 0 | | dx | |
| 3550 | Matrix = | D E 0 |, vec = | dy | |
| 3551 | | G H I | | 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3552 | ## |
| 3553 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3554 | each result Vector is computed as: |
| 3555 | |
| 3556 | #Code |
| 3557 | #Literal |
| 3558 | #Outdent |
| 3559 | |A B 0| |dx| A*dx+B*dy D*dx+E*dy |
| 3560 | Matrix * vec = |D E 0| |dy| = |A*dx+B*dy D*dx+E*dy G*dx+H*dy+I| = ----------- , ----------- |
| 3561 | |G H I| | 1| G*dx+H*dy+I G*dx+*dHy+I |
| 3562 | ## |
| 3563 | |
| 3564 | #Param dx x-coordinate of Vector to map ## |
| 3565 | #Param dy y-coordinate of Vector to map ## |
| 3566 | #Param result storage for mapped Vector ## |
| 3567 | |
| 3568 | #Example |
| 3569 | SkPaint paint; |
| 3570 | paint.setColor(SK_ColorGREEN); |
| 3571 | paint.setAntiAlias(true); |
| 3572 | paint.setTextSize(48); |
| 3573 | SkMatrix matrix; |
| 3574 | matrix.setRotate(90); |
| 3575 | SkVector offset = { 7, 7 }; |
| 3576 | for (int i = 0; i < 4; ++i) { |
| 3577 | paint.setImageFilter(SkDropShadowImageFilter::Make(offset.fX, offset.fY, 3, 3, |
| 3578 | SK_ColorBLUE, SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, nullptr)); |
| 3579 | matrix.mapVector(offset.fX, offset.fY, &offset); |
| 3580 | canvas->translate(0, 60); |
| 3581 | canvas->drawString("Text", 50, 0, paint); |
| 3582 | } |
| 3583 | ## |
| 3584 | |
Brian Salomon | fa3783f | 2018-01-05 13:49:07 -0500 | [diff] [blame] | 3585 | #SeeAlso mapVectors mapPoints mapXY |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3586 | |
| 3587 | ## |
| 3588 | |
| 3589 | # ------------------------------------------------------------------------------ |
| 3590 | |
| 3591 | #Method SkVector mapVector(SkScalar dx, SkScalar dy) const |
| 3592 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3593 | Returns Vector (x, y) multiplied by Matrix, treating Matrix translation as zero. |
| 3594 | Given: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3595 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3596 | #Code |
| 3597 | #Literal |
| 3598 | | A B 0 | | dx | |
| 3599 | Matrix = | D E 0 |, vec = | dy | |
| 3600 | | G H I | | 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3601 | ## |
| 3602 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3603 | each result Vector is computed as: |
| 3604 | |
| 3605 | #Code |
| 3606 | #Literal |
| 3607 | #Outdent |
| 3608 | |A B 0| |dx| A*dx+B*dy D*dx+E*dy |
| 3609 | Matrix * vec = |D E 0| |dy| = |A*dx+B*dy D*dx+E*dy G*dx+H*dy+I| = ----------- , ----------- |
| 3610 | |G H I| | 1| G*dx+H*dy+I G*dx+*dHy+I |
| 3611 | ## |
| 3612 | |
| 3613 | #Param dx x-coordinate of Vector to map ## |
| 3614 | #Param dy y-coordinate of Vector to map ## |
| 3615 | |
| 3616 | #Return mapped Vector ## |
| 3617 | |
| 3618 | #Example |
| 3619 | SkPaint paint; |
| 3620 | paint.setColor(SK_ColorGREEN); |
| 3621 | paint.setAntiAlias(true); |
| 3622 | paint.setTextSize(48); |
| 3623 | SkMatrix matrix; |
| 3624 | matrix.setRotate(90); |
| 3625 | SkVector offset = { 7, 7 }; |
| 3626 | for (int i = 0; i < 4; ++i) { |
| 3627 | paint.setImageFilter(SkDropShadowImageFilter::Make(offset.fX, offset.fY, 3, 3, |
| 3628 | SK_ColorBLUE, SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, nullptr)); |
| 3629 | offset = matrix.mapVector(offset.fX, offset.fY); |
| 3630 | canvas->translate(0, 60); |
| 3631 | canvas->drawString("Text", 50, 0, paint); |
| 3632 | } |
| 3633 | ## |
| 3634 | |
Brian Salomon | fa3783f | 2018-01-05 13:49:07 -0500 | [diff] [blame] | 3635 | #SeeAlso mapVectors mapPoints mapXY |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3636 | |
| 3637 | ## |
| 3638 | |
| 3639 | # ------------------------------------------------------------------------------ |
| 3640 | |
| 3641 | #Method bool mapRect(SkRect* dst, const SkRect& src) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 3642 | #In Transform |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3643 | #Line # returns bounds of mapped Rect ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3644 | Sets dst to bounds of src corners mapped by Matrix. |
| 3645 | Returns true if mapped corners are dst corners. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3646 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3647 | Returned value is the same as calling rectStaysRect. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3648 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3649 | #Param dst storage for bounds of mapped Points ## |
| 3650 | #Param src Rect to map ## |
| 3651 | |
| 3652 | #Return true if dst is equivalent to mapped src ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3653 | |
| 3654 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3655 | SkPaint paint; |
| 3656 | paint.setAntiAlias(true); |
| 3657 | SkMatrix matrix; |
| 3658 | matrix.setRotate(45, 128, 128); |
| 3659 | SkRect rotatedBounds, bounds = {40, 50, 190, 200}; |
| 3660 | matrix.mapRect(&rotatedBounds, bounds ); |
| 3661 | paint.setColor(SK_ColorGRAY); |
| 3662 | canvas->drawRect(rotatedBounds, paint); |
| 3663 | canvas->concat(matrix); |
| 3664 | paint.setColor(SK_ColorRED); |
| 3665 | canvas->drawRect(bounds, paint); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3666 | ## |
| 3667 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3668 | #SeeAlso mapPoints rectStaysRect |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3669 | |
| 3670 | ## |
| 3671 | |
| 3672 | # ------------------------------------------------------------------------------ |
| 3673 | |
| 3674 | #Method bool mapRect(SkRect* rect) const |
| 3675 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3676 | Sets rect to bounds of rect corners mapped by Matrix. |
| 3677 | Returns true if mapped corners are computed rect corners. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3678 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3679 | Returned value is the same as calling rectStaysRect. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3680 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3681 | #Param rect rectangle to map, and storage for bounds of mapped corners ## |
| 3682 | |
| 3683 | #Return true if result is equivalent to mapped src ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3684 | |
| 3685 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3686 | SkPaint paint; |
| 3687 | paint.setAntiAlias(true); |
| 3688 | SkMatrix matrix; |
| 3689 | matrix.setRotate(45, 128, 128); |
| 3690 | SkRect bounds = {40, 50, 190, 200}; |
| 3691 | matrix.mapRect(&bounds); |
| 3692 | paint.setColor(SK_ColorGRAY); |
| 3693 | canvas->drawRect(bounds, paint); |
| 3694 | canvas->concat(matrix); |
| 3695 | paint.setColor(SK_ColorRED); |
| 3696 | canvas->drawRect({40, 50, 190, 200}, paint); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3697 | ## |
| 3698 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3699 | #SeeAlso mapRectScaleTranslate mapPoints rectStaysRect |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3700 | |
| 3701 | ## |
| 3702 | |
| 3703 | # ------------------------------------------------------------------------------ |
| 3704 | |
| 3705 | #Method void mapRectToQuad(SkPoint dst[4], const SkRect& rect) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 3706 | #In Transform |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3707 | #Line # maps Rect to Point array ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3708 | Maps four corners of rect to dst. Points are mapped by multiplying each |
| 3709 | rect corner by Matrix. rect corner is processed in this order: |
| 3710 | (rect.fLeft, rect.fTop), (rect.fRight, rect.fTop), (rect.fRight, rect.fBottom), |
| 3711 | (rect.fLeft, rect.fBottom). |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3712 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3713 | rect may be empty: rect.fLeft may be greater than or equal to rect.fRight; |
| 3714 | rect.fTop may be greater than or equal to rect.fBottom. |
| 3715 | |
| 3716 | Given: |
| 3717 | |
| 3718 | #Code |
| 3719 | #Literal |
| 3720 | | A B C | | x | |
| 3721 | Matrix = | D E F |, pt = | y | |
| 3722 | | G H I | | 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3723 | ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3724 | |
| 3725 | where pt is initialized from each of (rect.fLeft, rect.fTop), |
| 3726 | (rect.fRight, rect.fTop), (rect.fRight, rect.fBottom), (rect.fLeft, rect.fBottom), |
| 3727 | each dst Point is computed as: |
| 3728 | |
| 3729 | #Code |
| 3730 | #Literal |
| 3731 | |A B C| |x| Ax+By+C Dx+Ey+F |
| 3732 | Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , ------- |
| 3733 | |G H I| |1| Gx+Hy+I Gx+Hy+I |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3734 | ## |
| 3735 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3736 | #Param dst storage for mapped corner Points ## |
| 3737 | #Param rect Rect to map ## |
| 3738 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3739 | #Example |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3740 | #Height 192 |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3741 | SkPaint paint; |
| 3742 | paint.setAntiAlias(true); |
| 3743 | SkMatrix matrix; |
| 3744 | matrix.setRotate(60, 128, 128); |
| 3745 | SkRect rect = {50, 50, 150, 150}; |
| 3746 | SkPoint pts[4]; |
| 3747 | matrix.mapRectToQuad(pts, rect); |
| 3748 | for (int i = 0; i < 4; ++i) { |
| 3749 | canvas->drawCircle(pts[i].fX, pts[i].fY, 3, paint); |
| 3750 | } |
| 3751 | canvas->concat(matrix); |
| 3752 | paint.setStyle(SkPaint::kStroke_Style); |
| 3753 | canvas->drawRect(rect, paint); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3754 | ## |
| 3755 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3756 | #SeeAlso mapRect mapRectScaleTranslate |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3757 | |
| 3758 | ## |
| 3759 | |
| 3760 | # ------------------------------------------------------------------------------ |
| 3761 | |
| 3762 | #Method void mapRectScaleTranslate(SkRect* dst, const SkRect& src) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 3763 | #In Transform |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3764 | #Line # returns bounds of mapped Rect ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3765 | Sets dst to bounds of src corners mapped by Matrix. If matrix contains |
| 3766 | elements other than scale or translate: asserts if SK_DEBUG is defined; |
| 3767 | otherwise, results are undefined. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3768 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3769 | #Param dst storage for bounds of mapped Points ## |
| 3770 | #Param src Rect to map ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3771 | |
| 3772 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3773 | SkPaint paint; |
| 3774 | SkMatrix matrix; |
| 3775 | SkRect rect = {100, 50, 150, 180}; |
| 3776 | matrix.setScale(2, .5f, rect.centerX(), rect.centerY()); |
| 3777 | SkRect rotated; |
| 3778 | matrix.mapRectScaleTranslate(&rotated, rect); |
| 3779 | paint.setStyle(SkPaint::kStroke_Style); |
| 3780 | canvas->drawRect(rect, paint); |
| 3781 | paint.setColor(SK_ColorRED); |
| 3782 | canvas->drawRect(rotated, paint); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3783 | ## |
| 3784 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3785 | #SeeAlso mapRect mapRectToQuad isScaleTranslate rectStaysRect |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3786 | |
| 3787 | ## |
| 3788 | |
| 3789 | # ------------------------------------------------------------------------------ |
| 3790 | |
| 3791 | #Method SkScalar mapRadius(SkScalar radius) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 3792 | #In Transform |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3793 | #Line # returns mean radius of mapped Circle ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3794 | Returns geometric mean radius of ellipse formed by constructing Circle of |
| 3795 | size radius, and mapping constructed Circle with Matrix. The result squared is |
| 3796 | equal to the major axis length times the minor axis length. |
| 3797 | Result is not meaningful if Matrix contains perspective elements. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3798 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3799 | #Param radius Circle size to map ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3800 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3801 | #Return average mapped radius ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3802 | |
| 3803 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3804 | #Description |
| 3805 | The area enclosed by a square with sides equal to mappedRadius is the same as |
| 3806 | the area enclosed by the ellipse major and minor axes. |
| 3807 | ## |
| 3808 | SkPaint paint; |
| 3809 | paint.setAntiAlias(true); |
| 3810 | SkMatrix matrix; |
| 3811 | const SkPoint center = {108, 93}; |
| 3812 | matrix.setScale(2, .5f, center.fX, center.fY); |
| 3813 | matrix.postRotate(45, center.fX, center.fY); |
| 3814 | const SkScalar circleRadius = 50; |
| 3815 | SkScalar mappedRadius = matrix.mapRadius(circleRadius); |
| 3816 | SkVector minorAxis, majorAxis; |
| 3817 | matrix.mapVector(0, circleRadius, &minorAxis); |
| 3818 | matrix.mapVector(circleRadius, 0, &majorAxis); |
| 3819 | SkString mappedArea; |
| 3820 | mappedArea.printf("area = %g", mappedRadius * mappedRadius); |
| 3821 | canvas->drawString(mappedArea, 145, 250, paint); |
| 3822 | canvas->drawString("mappedRadius", center.fX + mappedRadius + 3, center.fY, paint); |
| 3823 | paint.setColor(SK_ColorRED); |
| 3824 | SkString axArea; |
| 3825 | axArea.printf("area = %g", majorAxis.length() * minorAxis.length()); |
| 3826 | paint.setStyle(SkPaint::kFill_Style); |
| 3827 | canvas->drawString(axArea, 15, 250, paint); |
| 3828 | paint.setStyle(SkPaint::kStroke_Style); |
| 3829 | canvas->drawRect({10, 200, 10 + majorAxis.length(), 200 + minorAxis.length()}, paint); |
| 3830 | paint.setColor(SK_ColorBLACK); |
| 3831 | canvas->drawLine(center.fX, center.fY, center.fX + mappedRadius, center.fY, paint); |
| 3832 | canvas->drawLine(center.fX, center.fY, center.fX, center.fY + mappedRadius, paint); |
| 3833 | canvas->drawRect({140, 180, 140 + mappedRadius, 180 + mappedRadius}, paint); |
| 3834 | canvas->concat(matrix); |
| 3835 | canvas->drawCircle(center.fX, center.fY, circleRadius, paint); |
| 3836 | paint.setColor(SK_ColorRED); |
| 3837 | canvas->drawLine(center.fX, center.fY, center.fX + circleRadius, center.fY, paint); |
| 3838 | canvas->drawLine(center.fX, center.fY, center.fX, center.fY + circleRadius, paint); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3839 | ## |
| 3840 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3841 | #SeeAlso mapVector |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3842 | |
| 3843 | ## |
| 3844 | |
| 3845 | # ------------------------------------------------------------------------------ |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3846 | #Method bool isFixedStepInX() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 3847 | #In Property |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3848 | #Line # returns if transformation supports fixed step in x ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3849 | Returns true if a unit step in x at some y mapped through Matrix can be |
| 3850 | represented by a constant Vector. Returns true if getType returns kIdentity_Mask, |
| 3851 | or combinations of: kTranslate_Mask, kScale_Mask, and kAffine_Mask. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3852 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3853 | May return true if getType returns kPerspective_Mask, but only when Matrix |
| 3854 | does not include rotation or skewing along the y-axis. |
| 3855 | |
| 3856 | #Return true if Matrix does not have complex perspective ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3857 | |
| 3858 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3859 | SkMatrix matrix; |
| 3860 | for (SkScalar px : { 0.0f, 0.1f } ) { |
| 3861 | for (SkScalar py : { 0.0f, 0.1f } ) { |
| 3862 | for (SkScalar sy : { 1, 2 } ) { |
| 3863 | matrix.setAll(1, 0, 0, 0, sy, 0, px, py, 1); |
| 3864 | matrix.dump(); |
| 3865 | SkDebugf("isFixedStepInX: %s\n", matrix.isFixedStepInX() ? "true" : "false"); |
| 3866 | } |
| 3867 | } |
| 3868 | } |
| 3869 | #StdOut |
| 3870 | [ 1.0000 0.0000 0.0000][ 0.0000 1.0000 0.0000][ 0.0000 0.0000 1.0000] |
| 3871 | isFixedStepInX: true |
| 3872 | [ 1.0000 0.0000 0.0000][ 0.0000 2.0000 0.0000][ 0.0000 0.0000 1.0000] |
| 3873 | isFixedStepInX: true |
| 3874 | [ 1.0000 0.0000 0.0000][ 0.0000 1.0000 0.0000][ 0.0000 0.1000 1.0000] |
| 3875 | isFixedStepInX: true |
| 3876 | [ 1.0000 0.0000 0.0000][ 0.0000 2.0000 0.0000][ 0.0000 0.1000 1.0000] |
| 3877 | isFixedStepInX: true |
| 3878 | [ 1.0000 0.0000 0.0000][ 0.0000 1.0000 0.0000][ 0.1000 0.0000 1.0000] |
| 3879 | isFixedStepInX: false |
| 3880 | [ 1.0000 0.0000 0.0000][ 0.0000 2.0000 0.0000][ 0.1000 0.0000 1.0000] |
| 3881 | isFixedStepInX: false |
| 3882 | [ 1.0000 0.0000 0.0000][ 0.0000 1.0000 0.0000][ 0.1000 0.1000 1.0000] |
| 3883 | isFixedStepInX: false |
| 3884 | [ 1.0000 0.0000 0.0000][ 0.0000 2.0000 0.0000][ 0.1000 0.1000 1.0000] |
| 3885 | isFixedStepInX: false |
| 3886 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3887 | ## |
| 3888 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3889 | #SeeAlso fixedStepInX getType |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3890 | |
| 3891 | ## |
| 3892 | |
| 3893 | # ------------------------------------------------------------------------------ |
| 3894 | |
| 3895 | #Method SkVector fixedStepInX(SkScalar y) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 3896 | #In Property |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3897 | #Line # returns step in x for a position in y ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3898 | Returns Vector representing a unit step in x at y mapped through Matrix. |
| 3899 | If isFixedStepInX is false, returned value is undefined. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3900 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3901 | #Param y position of line parallel to x-axis ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3902 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3903 | #Return Vector advance of mapped unit step in x ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3904 | |
| 3905 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3906 | #Image 3 |
| 3907 | SkMatrix matrix; |
| 3908 | const SkPoint center = { 128, 128 }; |
| 3909 | matrix.setScale(20, 25, center.fX, center.fY); |
| 3910 | matrix.postRotate(75, center.fX, center.fY); |
| 3911 | { |
| 3912 | SkAutoCanvasRestore acr(canvas, true); |
| 3913 | canvas->concat(matrix); |
| 3914 | canvas->drawBitmap(source, 0, 0); |
| 3915 | } |
| 3916 | if (matrix.isFixedStepInX()) { |
| 3917 | SkPaint paint; |
| 3918 | paint.setAntiAlias(true); |
| 3919 | SkVector step = matrix.fixedStepInX(128); |
| 3920 | SkVector end = center + step; |
| 3921 | canvas->drawLine(center, end, paint); |
| 3922 | SkVector arrow = { step.fX + step.fY, step.fY - step.fX}; |
| 3923 | arrow = arrow * .25f; |
| 3924 | canvas->drawLine(end, end - arrow, paint); |
| 3925 | canvas->drawLine(end, {end.fX + arrow.fY, end.fY - arrow.fX}, paint); |
| 3926 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3927 | ## |
| 3928 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3929 | #SeeAlso isFixedStepInX getType |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3930 | |
| 3931 | ## |
| 3932 | |
| 3933 | # ------------------------------------------------------------------------------ |
| 3934 | |
| 3935 | #Method bool cheapEqualTo(const SkMatrix& m) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 3936 | #In Operator |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3937 | #Line # compares Matrix pair using memcmp() ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3938 | Returns true if Matrix equals m, using an efficient comparison. |
| 3939 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3940 | 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] | 3941 | matrix has positive zero value and the other has negative zero value. |
| 3942 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3943 | Returns true even when both Matrices contain NaN. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3944 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3945 | NaN never equals any value, including itself. To improve performance, NaN values |
| 3946 | 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] | 3947 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3948 | #Param m Matrix to compare ## |
| 3949 | |
| 3950 | #Return true if m and Matrix are represented by identical bit patterns ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3951 | |
| 3952 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3953 | auto debugster = [](const char* prefix, const SkMatrix& a, const SkMatrix& b) -> void { |
| 3954 | SkDebugf("%s: a %c= b a.cheapEqualTo(b): %s\n", prefix, |
| 3955 | a == b ? '=' : '!', a.cheapEqualTo(b) ? "true" : "false"); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3956 | }; |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3957 | SkMatrix a, b; |
| 3958 | a.setAll(1, 0, 0, 0, 1, 0, 0, 0, 1); |
| 3959 | b.setIdentity(); |
| 3960 | debugster("identity", a, b); |
| 3961 | a.setAll(1, -0.0f, 0, 0, 1, 0, 0, 0, 1); |
| 3962 | debugster("neg zero", a, b); |
| 3963 | a.setAll(1, SK_ScalarNaN, 0, 0, 1, 0, 0, 0, 1); |
| 3964 | debugster(" one NaN", a, b); |
| 3965 | b.setAll(1, SK_ScalarNaN, 0, 0, 1, 0, 0, 0, 1); |
| 3966 | debugster("both NaN", a, b); |
| 3967 | #StdOut |
| 3968 | identity: a == b a.cheapEqualTo(b): true |
| 3969 | neg zero: a == b a.cheapEqualTo(b): false |
| 3970 | one NaN: a != b a.cheapEqualTo(b): false |
| 3971 | both NaN: a != b a.cheapEqualTo(b): true |
| 3972 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3973 | ## |
| 3974 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3975 | #SeeAlso operator==(const SkMatrix& a, const SkMatrix& b) |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3976 | |
| 3977 | ## |
| 3978 | |
| 3979 | # ------------------------------------------------------------------------------ |
| 3980 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3981 | #Method bool operator==(const SkMatrix& a, const SkMatrix& b) |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3982 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3983 | #Line # returns true if members are equal ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3984 | Compares a and b; returns true if a and b are numerically equal. Returns true |
| 3985 | even if sign of zero values are different. Returns false if either Matrix |
| 3986 | contains NaN, even if the other Matrix also contains NaN. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3987 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3988 | #Param a Matrix to compare ## |
| 3989 | #Param b Matrix to compare ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3990 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 3991 | #Return true if Matrix a and Matrix b are numerically equal ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3992 | |
| 3993 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 3994 | auto debugster = [](const char* prefix, const SkMatrix& a, const SkMatrix& b) -> void { |
| 3995 | SkDebugf("%s: a %c= b a.cheapEqualTo(b): %s\n", prefix, |
| 3996 | a == b ? '=' : '!', a.cheapEqualTo(b) ? "true" : "false"); |
| 3997 | }; |
| 3998 | SkMatrix a, b; |
| 3999 | a.setAll(1, 0, 0, 0, 1, 0, 0, 0, 1); |
| 4000 | b.setScale(2, 4); |
| 4001 | b.postScale(0.5f, 0.25f); |
| 4002 | debugster("identity", a, b); |
| 4003 | #StdOut |
| 4004 | identity: a == b a.cheapEqualTo(b): true |
| 4005 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4006 | ## |
| 4007 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4008 | #SeeAlso cheapEqualTo operator!=(const SkMatrix& a, const SkMatrix& b) |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4009 | |
| 4010 | ## |
| 4011 | |
| 4012 | # ------------------------------------------------------------------------------ |
| 4013 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4014 | #Method bool operator!=(const SkMatrix& a, const SkMatrix& b) |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4015 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 4016 | #Line # returns true if members are unequal ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4017 | Compares a and b; returns true if a and b are not numerically equal. Returns false |
| 4018 | even if sign of zero values are different. Returns true if either Matrix |
| 4019 | contains NaN, even if the other Matrix also contains NaN. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4020 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4021 | #Param a Matrix to compare ## |
| 4022 | #Param b Matrix to compare ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4023 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 4024 | #Return true if Matrix a and Matrix b are numerically not equal ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4025 | |
| 4026 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4027 | auto debugster = [](const char* prefix, const SkMatrix& a, const SkMatrix& b) -> void { |
| 4028 | SkDebugf("%s: a %c= b a.cheapEqualTo(b): %s\n", prefix, |
| 4029 | a != b ? '!' : '=', a.cheapEqualTo(b) ? "true" : "false"); |
| 4030 | }; |
| 4031 | SkMatrix a, b; |
| 4032 | a.setAll(1, 0, 0, 0, 1, 0, 1, 0, 1); |
| 4033 | a.invert(&b); |
| 4034 | debugster("identity", a, b); |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4035 | ## |
| 4036 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4037 | #SeeAlso cheapEqualTo operator==(const SkMatrix& a, const SkMatrix& b) |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4038 | |
| 4039 | ## |
| 4040 | |
| 4041 | # ------------------------------------------------------------------------------ |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 4042 | #Subtopic Utility |
| 4043 | #Populate |
| 4044 | #Line # rarely called management functions ## |
| 4045 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4046 | |
| 4047 | #Method void dump() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 4048 | #In Utility |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 4049 | #Line # sends text representation using floats to standard output ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4050 | Writes text representation of Matrix to standard output. Floating point values |
| 4051 | are written with limited precision; it may not be possible to reconstruct |
| 4052 | original Matrix from output. |
| 4053 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4054 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4055 | SkMatrix matrix; |
| 4056 | matrix.setRotate(45); |
| 4057 | matrix.dump(); |
| 4058 | SkMatrix nearlyEqual; |
| 4059 | nearlyEqual.setAll(0.7071f, -0.7071f, 0, 0.7071f, 0.7071f, 0, 0, 0, 1); |
| 4060 | nearlyEqual.dump(); |
| 4061 | SkDebugf("matrix %c= nearlyEqual\n", matrix == nearlyEqual ? '=' : '!'); |
| 4062 | #StdOut |
| 4063 | [ 0.7071 -0.7071 0.0000][ 0.7071 0.7071 0.0000][ 0.0000 0.0000 1.0000] |
| 4064 | [ 0.7071 -0.7071 0.0000][ 0.7071 0.7071 0.0000][ 0.0000 0.0000 1.0000] |
| 4065 | matrix != nearlyEqual |
| 4066 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4067 | ## |
| 4068 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4069 | #SeeAlso toString |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4070 | |
| 4071 | ## |
| 4072 | |
| 4073 | # ------------------------------------------------------------------------------ |
| 4074 | |
| 4075 | #Method void toString(SkString* str) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 4076 | #In Utility |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 4077 | #Line # converts Matrix to machine readable form ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4078 | Creates string representation of Matrix. Floating point values |
| 4079 | are written with limited precision; it may not be possible to reconstruct |
| 4080 | original Matrix from output. |
| 4081 | |
| 4082 | #Param str storage for string representation of Matrix ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4083 | |
| 4084 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4085 | SkMatrix matrix; |
| 4086 | matrix.setRotate(45); |
| 4087 | SkString mStr, neStr; |
| 4088 | matrix.toString(&mStr); |
| 4089 | SkMatrix nearlyEqual; |
| 4090 | nearlyEqual.setAll(0.7071f, -0.7071f, 0, 0.7071f, 0.7071f, 0, 0, 0, 1); |
| 4091 | nearlyEqual.toString(&neStr); |
| 4092 | SkDebugf("mStr %s\n", mStr.c_str()); |
| 4093 | SkDebugf("neStr %s\n", neStr.c_str()); |
| 4094 | SkDebugf("matrix %c= nearlyEqual\n", matrix == nearlyEqual ? '=' : '!'); |
| 4095 | #StdOut |
| 4096 | mStr [ 0.7071 -0.7071 0.0000][ 0.7071 0.7071 0.0000][ 0.0000 0.0000 1.0000] |
| 4097 | neStr [ 0.7071 -0.7071 0.0000][ 0.7071 0.7071 0.0000][ 0.0000 0.0000 1.0000] |
| 4098 | matrix != nearlyEqual |
| 4099 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4100 | ## |
| 4101 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4102 | #SeeAlso dump |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4103 | |
| 4104 | ## |
| 4105 | |
| 4106 | # ------------------------------------------------------------------------------ |
| 4107 | |
| 4108 | #Method SkScalar getMinScale() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 4109 | #In Property |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 4110 | #Line # returns minimum scaling, if possible ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4111 | Returns the minimum scaling factor of Matrix by decomposing the scaling and |
| 4112 | skewing elements. |
| 4113 | Returns -1 if scale factor overflows or Matrix contains perspective. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4114 | |
| 4115 | #Return minimum scale factor |
| 4116 | ## |
| 4117 | |
| 4118 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4119 | SkMatrix matrix; |
| 4120 | matrix.setScale(42, 24); |
| 4121 | SkDebugf("matrix.getMinScale() %g\n", matrix.getMinScale()); |
| 4122 | #StdOut |
| 4123 | matrix.getMinScale() 24 |
| 4124 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4125 | ## |
| 4126 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4127 | #SeeAlso getMaxScale getMinMaxScales |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4128 | |
| 4129 | ## |
| 4130 | |
| 4131 | # ------------------------------------------------------------------------------ |
| 4132 | |
| 4133 | #Method SkScalar getMaxScale() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 4134 | #In Property |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 4135 | #Line # returns maximum scaling, if possible ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4136 | Returns the maximum scaling factor of Matrix by decomposing the scaling and |
| 4137 | skewing elements. |
| 4138 | Returns -1 if scale factor overflows or Matrix contains perspective. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4139 | |
| 4140 | #Return maximum scale factor |
| 4141 | ## |
| 4142 | |
| 4143 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4144 | SkMatrix matrix; |
| 4145 | matrix.setScale(42, 24); |
| 4146 | SkDebugf("matrix.getMaxScale() %g\n", matrix.getMaxScale()); |
| 4147 | #StdOut |
| 4148 | matrix.getMaxScale() 42 |
| 4149 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4150 | ## |
| 4151 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4152 | #SeeAlso getMinScale getMinMaxScales |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4153 | |
| 4154 | ## |
| 4155 | |
| 4156 | # ------------------------------------------------------------------------------ |
| 4157 | |
| 4158 | #Method bool SK_WARN_UNUSED_RESULT getMinMaxScales(SkScalar scaleFactors[2]) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 4159 | #In Property |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 4160 | #Line # returns minimum and maximum scaling, if possible ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4161 | Sets scaleFactors[0] to the minimum scaling factor, and scaleFactors[1] to the |
| 4162 | maximum scaling factor. Scaling factors are computed by decomposing |
| 4163 | the Matrix scaling and skewing elements. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4164 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4165 | Returns true if scaleFactors are found; otherwise, returns false and sets |
| 4166 | scaleFactors to undefined values. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4167 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4168 | #Param scaleFactors storage for minimum and maximum scale factors ## |
| 4169 | |
| 4170 | #Return true if scale factors were computed correctly ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4171 | |
| 4172 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4173 | SkMatrix matrix; |
| 4174 | matrix.setAll(1, 0, 0, 0, 1, 0, 0, 0, 0); |
| 4175 | matrix.invert(&matrix); |
| 4176 | SkScalar factor[2] = {2, 2}; |
| 4177 | bool result = matrix.getMinMaxScales(factor); |
| 4178 | SkDebugf("matrix.getMinMaxScales() %s %g %g\n", result ? "true" : "false", factor[0], factor[1]); |
| 4179 | #StdOut |
| 4180 | matrix.getMinMaxScales() false 2 2 |
| 4181 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4182 | ## |
| 4183 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4184 | #SeeAlso getMinScale getMaxScale |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4185 | |
| 4186 | ## |
| 4187 | |
| 4188 | # ------------------------------------------------------------------------------ |
| 4189 | |
| 4190 | #Method bool decomposeScale(SkSize* scale, SkMatrix* remaining = nullptr) const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 4191 | #In Property |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 4192 | #Line # separates scale if possible ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4193 | Decomposes Matrix into scale components and whatever remains. Returns false if |
| 4194 | Matrix could not be decomposed. |
| 4195 | |
| 4196 | Sets scale to portion of Matrix that scales in x and y. Sets remaining to Matrix |
| 4197 | with x and y scaling factored out. remaining may be passed as nullptr |
| 4198 | to determine if Matrix can be decomposed without computing remainder. |
| 4199 | |
| 4200 | Returns true if scale components are found. scale and remaining are |
| 4201 | unchanged if Matrix contains perspective; scale factors are not finite, or |
| 4202 | are nearly zero. |
| 4203 | |
| 4204 | On success |
| 4205 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4206 | #Formula |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4207 | Matrix = scale * Remaining |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4208 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4209 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4210 | #Param scale x and y scaling factors; may be nullptr ## |
| 4211 | #Param remaining Matrix without scaling; may be nullptr ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4212 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4213 | #Return true if scale can be computed ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4214 | |
| 4215 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4216 | SkMatrix matrix; |
| 4217 | matrix.setRotate(90 * SK_Scalar1); |
| 4218 | matrix.postScale(1.f / 4, 1.f / 2); |
| 4219 | matrix.dump(); |
| 4220 | SkSize scale = {SK_ScalarNaN, SK_ScalarNaN}; |
| 4221 | SkMatrix remaining; |
| 4222 | remaining.reset(); |
| 4223 | bool success = matrix.decomposeScale(&scale, &remaining); |
| 4224 | SkDebugf("success: %s ", success ? "true" : "false"); |
| 4225 | SkDebugf("scale: %g, %g\n", scale.width(), scale.height()); |
| 4226 | remaining.dump(); |
| 4227 | SkMatrix scaleMatrix = SkMatrix::MakeScale(scale.width(), scale.height()); |
| 4228 | SkMatrix combined = SkMatrix::Concat(scaleMatrix, remaining); |
| 4229 | combined.dump(); |
| 4230 | #StdOut |
| 4231 | [ 0.0000 -0.2500 0.0000][ 0.5000 0.0000 0.0000][ 0.0000 0.0000 1.0000] |
| 4232 | success: true scale: 0.5, 0.25 |
| 4233 | [ 0.0000 -0.5000 0.0000][ 2.0000 0.0000 0.0000][ 0.0000 0.0000 1.0000] |
| 4234 | [ 0.0000 -0.2500 0.0000][ 0.5000 0.0000 0.0000][ 0.0000 0.0000 1.0000] |
| 4235 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4236 | ## |
| 4237 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4238 | #SeeAlso setScale MakeScale |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4239 | |
| 4240 | ## |
| 4241 | |
| 4242 | # ------------------------------------------------------------------------------ |
| 4243 | |
| 4244 | #Method static const SkMatrix& I() |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 4245 | #In Constructor |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 4246 | #Line # returns a reference to a const identity Matrix ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4247 | Returns reference to const identity Matrix. Returned Matrix is set to: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4248 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4249 | #Code |
| 4250 | #Literal |
| 4251 | | 1 0 0 | |
| 4252 | | 0 1 0 | |
| 4253 | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4254 | ## |
| 4255 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4256 | #Return const identity Matrix ## |
| 4257 | |
| 4258 | #Example |
| 4259 | SkMatrix m1, m2, m3; |
| 4260 | m1.reset(); |
| 4261 | m2.setIdentity(); |
| 4262 | m3 = SkMatrix::I(); |
| 4263 | SkDebugf("m1 %c= m2\n", m1 == m2 ? '=' : '!'); |
| 4264 | SkDebugf("m2 %c= m3\n", m1 == m2 ? '=' : '!'); |
| 4265 | #StdOut |
| 4266 | m1 == m2 |
| 4267 | m2 == m3 |
| 4268 | ## |
| 4269 | ## |
| 4270 | |
| 4271 | #SeeAlso reset() setIdentity |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4272 | |
| 4273 | ## |
| 4274 | |
| 4275 | # ------------------------------------------------------------------------------ |
| 4276 | |
| 4277 | #Method static const SkMatrix& InvalidMatrix() |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 4278 | #In Constructor |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 4279 | #Line # returns a reference to a const invalid Matrix ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4280 | Returns reference to a const Matrix with invalid values. Returned Matrix is set |
| 4281 | to: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4282 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4283 | #Code |
| 4284 | #Literal |
| 4285 | | SK_ScalarMax SK_ScalarMax SK_ScalarMax | |
| 4286 | | SK_ScalarMax SK_ScalarMax SK_ScalarMax | |
| 4287 | | SK_ScalarMax SK_ScalarMax SK_ScalarMax | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4288 | ## |
| 4289 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4290 | #Return const invalid Matrix ## |
| 4291 | |
| 4292 | #Example |
| 4293 | SkDebugf("scaleX %g\n", SkMatrix::InvalidMatrix().getScaleX()); |
| 4294 | #StdOut |
| 4295 | scaleX 3.40282e+38 |
| 4296 | ## |
| 4297 | ## |
| 4298 | |
| 4299 | #SeeAlso SeeAlso getType |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4300 | |
| 4301 | ## |
| 4302 | |
| 4303 | # ------------------------------------------------------------------------------ |
| 4304 | |
| 4305 | #Method static SkMatrix Concat(const SkMatrix& a, const SkMatrix& b) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 4306 | #In Operator |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 4307 | #Line # returns the concatenation of Matrix pair ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4308 | Returns Matrix a multiplied by Matrix b. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4309 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4310 | Given: |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4311 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4312 | #Code |
| 4313 | #Literal |
| 4314 | | A B C | | J K L | |
| 4315 | a = | D E F |, b = | M N O | |
| 4316 | | G H I | | P Q R | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4317 | ## |
| 4318 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4319 | sets Matrix to: |
| 4320 | |
| 4321 | #Code |
| 4322 | #Literal |
| 4323 | | A B C | | J K L | | AJ+BM+CP AK+BN+CQ AL+BO+CR | |
| 4324 | a * b = | D E F | * | M N O | = | DJ+EM+FP DK+EN+FQ DL+EO+FR | |
| 4325 | | G H I | | P Q R | | GJ+HM+IP GK+HN+IQ GL+HO+IR | |
| 4326 | ## |
| 4327 | |
| 4328 | #Param a Matrix on left side of multiply expression ## |
| 4329 | #Param b Matrix on right side of multiply expression ## |
| 4330 | |
| 4331 | #Return Matrix computed from a times b ## |
| 4332 | |
| 4333 | #Example |
| 4334 | #Height 64 |
| 4335 | #Image 4 |
| 4336 | #Description |
| 4337 | setPolyToPoly creates perspective matrices, one the inverse of the other. |
| 4338 | Multiplying the matrix by its inverse turns into an identity matrix. |
| 4339 | ## |
| 4340 | SkMatrix matrix, matrix2; |
| 4341 | SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; |
| 4342 | SkRect::Make(source.bounds()).toQuad(bitmapBounds); |
| 4343 | matrix.setPolyToPoly(bitmapBounds, perspect, 4); |
| 4344 | matrix2.setPolyToPoly(perspect, bitmapBounds, 4); |
| 4345 | SkMatrix concat = SkMatrix::Concat(matrix, matrix2); |
| 4346 | canvas->concat(concat); |
| 4347 | canvas->drawBitmap(source, 0, 0); |
| 4348 | ## |
| 4349 | |
| 4350 | #SeeAlso preConcat postConcat |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4351 | |
| 4352 | ## |
| 4353 | |
| 4354 | # ------------------------------------------------------------------------------ |
| 4355 | |
| 4356 | #Method void dirtyMatrixTypeCache() |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 4357 | #In Utility |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 4358 | #Line # sets internal cache to unknown state ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4359 | Sets internal cache to unknown state. Use to force update after repeated |
| 4360 | modifications to Matrix element reference returned by operator[](int index). |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4361 | |
| 4362 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4363 | SkMatrix matrix; |
| 4364 | matrix.setIdentity(); |
| 4365 | SkDebugf("with identity matrix: x = %g\n", matrix.mapXY(24, 42).fX); |
| 4366 | SkScalar& skewRef = matrix[SkMatrix::kMSkewX]; |
| 4367 | skewRef = 0; |
| 4368 | SkDebugf("after skew x mod: x = %g\n", matrix.mapXY(24, 42).fX); |
| 4369 | skewRef = 1; |
| 4370 | SkDebugf("after 2nd skew x mod: x = %g\n", matrix.mapXY(24, 42).fX); |
| 4371 | matrix.dirtyMatrixTypeCache(); |
| 4372 | SkDebugf("after dirty cache: x = %g\n", matrix.mapXY(24, 42).fX); |
| 4373 | #StdOut |
| 4374 | with identity matrix: x = 24 |
| 4375 | after skew x mod: x = 24 |
| 4376 | after 2nd skew x mod: x = 24 |
| 4377 | after dirty cache: x = 66 |
| 4378 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4379 | ## |
| 4380 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4381 | #SeeAlso operator[](int index) getType |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4382 | |
| 4383 | ## |
| 4384 | |
| 4385 | # ------------------------------------------------------------------------------ |
| 4386 | |
| 4387 | #Method void setScaleTranslate(SkScalar sx, SkScalar sy, SkScalar tx, SkScalar ty) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 4388 | #In Constructor |
| 4389 | #In Set |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 4390 | #Line # sets to scale and translate ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4391 | Initializes Matrix with scale and translate elements. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4392 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4393 | #Code |
| 4394 | #Literal |
| 4395 | | sx 0 tx | |
| 4396 | | 0 sy ty | |
| 4397 | | 0 0 1 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4398 | ## |
| 4399 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4400 | #Param sx horizontal scale factor to store ## |
| 4401 | #Param sy vertical scale factor to store ## |
| 4402 | #Param tx horizontal translation to store ## |
| 4403 | #Param ty vertical translation to store ## |
| 4404 | |
| 4405 | #Example |
| 4406 | SkMatrix matrix; |
| 4407 | matrix.setScaleTranslate(1, 2, 3, 4); |
| 4408 | matrix.dump(); |
| 4409 | #StdOut |
| 4410 | [ 1.0000 0.0000 3.0000][ 0.0000 2.0000 4.0000][ 0.0000 0.0000 1.0000] |
| 4411 | ## |
| 4412 | ## |
| 4413 | |
| 4414 | #SeeAlso setScale preTranslate postTranslate |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4415 | |
| 4416 | ## |
| 4417 | |
| 4418 | # ------------------------------------------------------------------------------ |
| 4419 | |
| 4420 | #Method bool isFinite() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 4421 | #In Property |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 4422 | #Line # returns if all Matrix values are not infinity, NaN ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4423 | Returns true if all elements of the matrix are finite. Returns false if any |
| 4424 | element is infinity, or NaN. |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4425 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4426 | #Return true if matrix has only finite elements ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4427 | |
| 4428 | #Example |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4429 | SkMatrix matrix = SkMatrix::MakeTrans(SK_ScalarNaN, 0); |
| 4430 | matrix.dump(); |
| 4431 | SkDebugf("matrix is finite: %s\n", matrix.isFinite() ? "true" : "false"); |
| 4432 | SkDebugf("matrix %c= matrix\n", matrix == matrix ? '=' : '!'); |
| 4433 | #StdOut |
| 4434 | [ 1.0000 0.0000 nan][ 0.0000 1.0000 0.0000][ 0.0000 0.0000 1.0000] |
| 4435 | matrix is finite: false |
| 4436 | matrix != matrix |
| 4437 | ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4438 | ## |
| 4439 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4440 | #SeeAlso operator== |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4441 | |
| 4442 | ## |
| 4443 | |
| 4444 | #Class SkMatrix ## |
| 4445 | |
| 4446 | #Topic Matrix ## |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 4447 | |