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