Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 1 | #Topic IRect |
| 2 | #Alias IRect_Reference |
| 3 | |
| 4 | #Struct SkIRect |
| 5 | |
| 6 | SkIRect holds four 32 bit integer coordinates describing the upper and |
| 7 | lower bounds of a rectangle. SkIRect may be created from outer bounds or |
| 8 | from position, width, and height. SkIRect describes an area; if its right |
| 9 | is less than or equal to its left, or if its bottom is less than or equal to |
| 10 | its top, it is considered empty. |
| 11 | |
| 12 | #Topic Overview |
| 13 | |
| 14 | #Subtopic Subtopics |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 15 | #Table |
| 16 | #Legend |
Cary Clark | 5081eed | 2018-01-22 07:55:48 -0500 | [diff] [blame] | 17 | # name # description ## |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 18 | #Legend ## |
Cary Clark | 5081eed | 2018-01-22 07:55:48 -0500 | [diff] [blame] | 19 | # Constructors # list of functions that construct SkPath ## |
| 20 | # Member_Functions # list of static functions and member methods ## |
| 21 | # Operators # operator overloading methods ## |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 22 | #Table ## |
| 23 | ## |
| 24 | |
Cary Clark | 5081eed | 2018-01-22 07:55:48 -0500 | [diff] [blame] | 25 | #Subtopic Constructors |
| 26 | #Table |
| 27 | #Legend |
| 28 | # name # description ## |
| 29 | #Legend ## |
| 30 | # MakeEmpty # returns bounds of (0, 0, 0, 0) ## |
| 31 | # MakeLTRB # constructs from int left, top, right, bottom ## |
| 32 | # MakeLargest # deprecated ## |
| 33 | # MakeSize # constructs from ISize returning (0, 0, width, height) ## |
| 34 | # MakeWH # constructs from int input returning (0, 0, width, height) ## |
| 35 | # MakeXYWH # constructs from int input returning (x, y, width, height) ## |
| 36 | # makeInset # constructs from sides moved symmetrically about the center ## |
| 37 | # makeOffset # constructs from translated sides ## |
| 38 | # makeOutset # constructs from sides moved symmetrically about the center ## |
| 39 | # makeSorted # constructs, ordering sides from smaller to larger ## |
| 40 | #Table ## |
| 41 | #Subtopic ## |
| 42 | |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 43 | #Subtopic Operators |
| 44 | #Table |
| 45 | #Legend |
Cary Clark | 5081eed | 2018-01-22 07:55:48 -0500 | [diff] [blame] | 46 | # name # description ## |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 47 | #Legend ## |
Cary Clark | 5081eed | 2018-01-22 07:55:48 -0500 | [diff] [blame] | 48 | # bool operator!=(const SkIRect& a, const SkIRect& b) # returns true if members are unequal ## |
| 49 | # bool operator==(const SkIRect& a, const SkIRect& b) # returns true if members are equal ## |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 50 | #Table ## |
| 51 | #Subtopic ## |
| 52 | |
| 53 | #Subtopic Member_Functions |
| 54 | #Table |
| 55 | #Legend |
Cary Clark | 5081eed | 2018-01-22 07:55:48 -0500 | [diff] [blame] | 56 | # name # description ## |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 57 | #Legend ## |
Cary Clark | 5081eed | 2018-01-22 07:55:48 -0500 | [diff] [blame] | 58 | # EmptyIRect # returns immutable bounds of (0, 0, 0, 0) ## |
| 59 | # Intersects # returns true if areas overlap ## |
| 60 | # IntersectsNoEmptyCheck # returns true if areas overlap skips empty check ## |
| 61 | # MakeEmpty # returns bounds of (0, 0, 0, 0) ## |
| 62 | # MakeLTRB # constructs from int left, top, right, bottom ## |
| 63 | # MakeLargest # deprecated ## |
| 64 | # MakeSize # constructs from ISize returning (0, 0, width, height) ## |
| 65 | # MakeWH # constructs from int input returning (0, 0, width, height) ## |
| 66 | # MakeXYWH # constructs from int input returning (x, y, width, height) ## |
| 67 | # bottom() # returns larger bounds in y, if sorted ## |
| 68 | # centerX # returns midpoint in x ## |
| 69 | # centerY # returns midpoint in y ## |
| 70 | # contains() # returns true if points are equal or inside ## |
| 71 | # containsNoEmptyCheck # returns true if points are equal or inside skips empty check ## |
| 72 | # height() # returns span in y ## |
| 73 | # height64 # returns span in y as int64_t ## |
| 74 | # inset() # moves the sides symmetrically about the center ## |
| 75 | # intersect # sets to shared area; returns true if not empty ## |
| 76 | # intersectNoEmptyCheck # sets to shared area; returns true if not empty skips empty check ## |
| 77 | # is16Bit # returns true if members fit in 16-bit word ## |
| 78 | # isEmpty # returns true if width or height are zero or negative or they exceed int32_t ## |
| 79 | # isEmpty64 # returns true if width or height are zero or negative ## |
| 80 | # join() # sets to union of bounds ## |
| 81 | # left() # returns smaller bounds in x, if sorted ## |
| 82 | # makeInset # constructs from sides moved symmetrically about the center ## |
| 83 | # makeOffset # constructs from translated sides ## |
| 84 | # makeOutset # constructs from sides moved symmetrically about the center ## |
| 85 | # makeSorted # constructs, ordering sides from smaller to larger ## |
| 86 | # offset() # translates sides without changing width and height ## |
| 87 | # offsetTo # translates to (x, y) without changing width and height ## |
| 88 | # outset() # moves the sides symmetrically about the center ## |
| 89 | # quickReject # returns true if rectangles do not intersect ## |
| 90 | # right() # returns larger bounds in x, if sorted ## |
| 91 | # set() # sets to (left, top, right, bottom) ## |
| 92 | # setEmpty # sets to (0, 0, 0, 0) ## |
| 93 | # setLTRB # sets to SkScalar input (left, top, right, bottom) ## |
| 94 | # setXYWH # sets to (x, y, width, height) ## |
| 95 | # size() # returns ISize (width, height) ## |
| 96 | # sort() # orders sides from smaller to larger ## |
| 97 | # top() # returns smaller bounds in y, if sorted ## |
| 98 | # width() # returns span in x ## |
| 99 | # width64 # returns span in y as int64_t ## |
| 100 | # x() # returns bounds left ## |
| 101 | # y() # returns bounds top ## |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 102 | #Table ## |
| 103 | #Subtopic ## |
| 104 | |
| 105 | #Topic ## |
| 106 | |
| 107 | #Member int32_t fLeft |
| 108 | May contain any value. The smaller of the horizontal values when sorted. |
| 109 | When equal to or greater than fRight, IRect is empty. |
| 110 | ## |
| 111 | |
| 112 | #Member int32_t fTop |
| 113 | May contain any value. The smaller of the horizontal values when sorted. |
| 114 | When equal to or greater than fBottom, IRect is empty. |
| 115 | ## |
| 116 | |
| 117 | #Member int32_t fRight |
| 118 | May contain any value. The larger of the vertical values when sorted. |
| 119 | When equal to or less than fLeft, IRect is empty. |
| 120 | ## |
| 121 | |
| 122 | #Member int32_t fBottom |
| 123 | May contain any value. The larger of the vertical values when sorted. |
| 124 | When equal to or less than fTop, IRect is empty. |
| 125 | ## |
| 126 | |
| 127 | # ------------------------------------------------------------------------------ |
| 128 | |
| 129 | #Method static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeEmpty() |
| 130 | |
| 131 | Returns constructed IRect set to (0, 0, 0, 0). |
| 132 | Many other rectangles are empty; if left is equal to or greater than right, |
| 133 | or if top is equal to or greater than bottom. Setting all members to zero |
| 134 | is a convenience, but does not designate a special empty rectangle. |
| 135 | |
| 136 | #Return bounds (0, 0, 0, 0) ## |
| 137 | |
| 138 | #Example |
| 139 | SkIRect rect = SkIRect::MakeEmpty(); |
| 140 | SkDebugf("MakeEmpty isEmpty: %s\n", rect.isEmpty() ? "true" : "false"); |
| 141 | rect.offset(10, 10); |
| 142 | SkDebugf("offset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false"); |
| 143 | rect.inset(10, 10); |
| 144 | SkDebugf("inset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false"); |
| 145 | rect.outset(20, 20); |
| 146 | SkDebugf("outset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false"); |
| 147 | #StdOut |
| 148 | MakeEmpty isEmpty: true |
| 149 | offset rect isEmpty: true |
| 150 | inset rect isEmpty: true |
| 151 | outset rect isEmpty: false |
| 152 | ## |
| 153 | ## |
| 154 | |
Mike Reed | 274218e | 2018-01-08 15:05:02 -0500 | [diff] [blame] | 155 | #SeeAlso EmptyIRect isEmpty setEmpty SkRect::MakeEmpty |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 156 | |
| 157 | ## |
| 158 | |
| 159 | # ------------------------------------------------------------------------------ |
| 160 | |
| 161 | #Method static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeWH(int32_t w, int32_t h) |
| 162 | |
| 163 | Returns constructed IRect set to (0, 0, w, h). Does not validate input; w or h |
| 164 | may be negative. |
| 165 | |
| 166 | #Param w width of constructed Rect ## |
| 167 | #Param h height of constructed Rect ## |
| 168 | |
| 169 | #Return bounds (0, 0, w, h) ## |
| 170 | |
| 171 | #Example |
| 172 | SkIRect rect1 = SkIRect::MakeWH(25, 35); |
| 173 | SkIRect rect2 = SkIRect::MakeSize({25, 35}); |
| 174 | SkIRect rect3 = SkIRect::MakeXYWH(0, 0, 25, 35); |
| 175 | SkIRect rect4 = SkIRect::MakeLTRB(0, 0, 25, 35); |
| 176 | SkDebugf("all %s" "equal\n", rect1 == rect2 && rect2 == rect3 && rect3 == rect4 ? |
| 177 | "" : "not "); |
| 178 | #StdOut |
| 179 | all equal |
| 180 | ## |
| 181 | ## |
| 182 | |
| 183 | #SeeAlso MakeSize MakeXYWH SkRect::MakeWH SkRect::MakeIWH |
| 184 | |
| 185 | ## |
| 186 | |
| 187 | # ------------------------------------------------------------------------------ |
| 188 | |
| 189 | #Method static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeSize(const SkISize& size) |
| 190 | |
| 191 | Returns constructed IRect set to (0, 0, size.width(), size.height()). |
| 192 | Does not validate input; size.width() or size.height() may be negative. |
| 193 | |
| 194 | #Param size values for Rect width and height ## |
| 195 | |
| 196 | #Return bounds (0, 0, size.width(), size.height()) ## |
| 197 | |
| 198 | #Example |
| 199 | SkSize size = {25.5f, 35.5f}; |
| 200 | SkIRect rect = SkIRect::MakeSize(size.toRound()); |
| 201 | SkDebugf("round width: %d height: %d\n", rect.width(), rect.height()); |
| 202 | rect = SkIRect::MakeSize(size.toFloor()); |
| 203 | SkDebugf("floor width: %d height: %d\n", rect.width(), rect.height()); |
| 204 | #StdOut |
| 205 | round width: 26 height: 36 |
| 206 | floor width: 25 height: 35 |
| 207 | ## |
| 208 | ## |
| 209 | |
| 210 | #SeeAlso MakeWH MakeXYWH SkRect::Make SkRect::MakeIWH |
| 211 | |
| 212 | ## |
| 213 | |
| 214 | # ------------------------------------------------------------------------------ |
| 215 | |
| 216 | #Method static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b) |
| 217 | |
| 218 | Returns constructed IRect set to (l, t, r, b). Does not sort input; Rect may |
| 219 | result in fLeft greater than fRight, or fTop greater than fBottom. |
| 220 | |
| 221 | #Param l integer stored in fLeft ## |
| 222 | #Param t integer stored in fTop ## |
| 223 | #Param r integer stored in fRight ## |
| 224 | #Param b integer stored in fBottom ## |
| 225 | |
| 226 | #Return bounds (l, t, r, b) ## |
| 227 | |
| 228 | #Example |
| 229 | SkIRect rect = SkIRect::MakeLTRB(5, 35, 15, 25); |
| 230 | SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), |
| 231 | rect.bottom(), rect.isEmpty() ? "true" : "false"); |
| 232 | rect.sort(); |
| 233 | SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), |
| 234 | rect.bottom(), rect.isEmpty() ? "true" : "false"); |
| 235 | #StdOut |
| 236 | rect: 5, 35, 15, 25 isEmpty: true |
| 237 | rect: 5, 25, 15, 35 isEmpty: false |
| 238 | ## |
| 239 | ## |
| 240 | |
| 241 | #SeeAlso MakeXYWH SkRect::MakeLTRB |
| 242 | |
| 243 | ## |
| 244 | |
| 245 | # ------------------------------------------------------------------------------ |
| 246 | |
| 247 | #Method static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h) |
| 248 | |
| 249 | Returns constructed IRect set to: |
| 250 | #Formula |
| 251 | (x, y, x + w, y + h) |
| 252 | ## |
| 253 | . Does not validate input; |
| 254 | w or h may be negative. |
| 255 | |
| 256 | #Param x stored in fLeft ## |
| 257 | #Param y stored in fTop ## |
| 258 | #Param w added to x and stored in fRight ## |
| 259 | #Param h added to y and stored in fBottom ## |
| 260 | |
| 261 | #Return bounds at (x, y) with width w and height h ## |
| 262 | |
| 263 | #Example |
| 264 | SkIRect rect = SkIRect::MakeXYWH(5, 35, -15, 25); |
| 265 | SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), |
| 266 | rect.bottom(), rect.isEmpty() ? "true" : "false"); |
| 267 | rect.sort(); |
| 268 | SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), |
| 269 | rect.bottom(), rect.isEmpty() ? "true" : "false"); |
| 270 | #StdOut |
| 271 | rect: 5, 35, -10, 60 isEmpty: true |
| 272 | rect: -10, 35, 5, 60 isEmpty: false |
| 273 | ## |
| 274 | ## |
| 275 | |
| 276 | #SeeAlso MakeLTRB SkRect::MakeXYWH |
| 277 | |
| 278 | ## |
| 279 | |
| 280 | # ------------------------------------------------------------------------------ |
| 281 | |
Cary Clark | 6def720 | 2018-01-04 08:13:35 -0500 | [diff] [blame] | 282 | #Method int32_t left() const |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 283 | |
| 284 | Returns left edge of IRect, if sorted. |
| 285 | Call sort() to reverse fLeft and fRight if needed. |
| 286 | |
| 287 | #Return fLeft ## |
| 288 | |
| 289 | #Example |
| 290 | SkIRect unsorted = { 15, 5, 10, 25 }; |
| 291 | SkDebugf("unsorted.fLeft: %d unsorted.left(): %d\n", unsorted.fLeft, unsorted.left()); |
| 292 | SkIRect sorted = unsorted.makeSorted(); |
| 293 | SkDebugf("sorted.fLeft: %d sorted.left(): %d\n", sorted.fLeft, sorted.left()); |
| 294 | #StdOut |
| 295 | unsorted.fLeft: 15 unsorted.left(): 15 |
| 296 | sorted.fLeft: 10 sorted.left(): 10 |
| 297 | ## |
| 298 | ## |
| 299 | |
| 300 | #SeeAlso fLeft x() SkRect::left() |
| 301 | |
| 302 | ## |
| 303 | |
| 304 | # ------------------------------------------------------------------------------ |
| 305 | |
Cary Clark | 6def720 | 2018-01-04 08:13:35 -0500 | [diff] [blame] | 306 | #Method int32_t top() const |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 307 | |
| 308 | Returns top edge of IRect, if sorted. Call isEmpty to see if IRect may be invalid, |
| 309 | and sort() to reverse fTop and fBottom if needed. |
| 310 | |
| 311 | #Return fTop ## |
| 312 | |
| 313 | #Example |
| 314 | SkIRect unsorted = { 15, 25, 10, 5 }; |
| 315 | SkDebugf("unsorted.fTop: %d unsorted.top(): %d\n", unsorted.fTop, unsorted.top()); |
| 316 | SkIRect sorted = unsorted.makeSorted(); |
| 317 | SkDebugf("sorted.fTop: %d sorted.top(): %d\n", sorted.fTop, sorted.top()); |
| 318 | #StdOut |
| 319 | unsorted.fTop: 25 unsorted.top(): 25 |
| 320 | sorted.fTop: 5 sorted.top(): 5 |
| 321 | ## |
| 322 | ## |
| 323 | |
| 324 | #SeeAlso fTop y() SkRect::top() |
| 325 | |
| 326 | ## |
| 327 | |
| 328 | # ------------------------------------------------------------------------------ |
| 329 | |
Cary Clark | 6def720 | 2018-01-04 08:13:35 -0500 | [diff] [blame] | 330 | #Method int32_t right() const |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 331 | |
| 332 | Returns right edge of IRect, if sorted. |
| 333 | Call sort() to reverse fLeft and fRight if needed. |
| 334 | |
| 335 | #Return fRight ## |
| 336 | |
| 337 | #Example |
| 338 | SkIRect unsorted = { 15, 25, 10, 5 }; |
| 339 | SkDebugf("unsorted.fRight: %d unsorted.right(): %d\n", unsorted.fRight, unsorted.right()); |
| 340 | SkIRect sorted = unsorted.makeSorted(); |
| 341 | SkDebugf("sorted.fRight: %d sorted.right(): %d\n", sorted.fRight, sorted.right()); |
| 342 | #StdOut |
| 343 | unsorted.fRight: 10 unsorted.right(): 10 |
| 344 | sorted.fRight: 15 sorted.right(): 15 |
| 345 | ## |
| 346 | ## |
| 347 | |
| 348 | #SeeAlso fRight SkRect::right() |
| 349 | |
| 350 | ## |
| 351 | |
| 352 | # ------------------------------------------------------------------------------ |
| 353 | |
Cary Clark | 6def720 | 2018-01-04 08:13:35 -0500 | [diff] [blame] | 354 | #Method int32_t bottom() const |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 355 | |
| 356 | Returns bottom edge of IRect, if sorted. Call isEmpty to see if IRect may be invalid, |
| 357 | and sort() to reverse fTop and fBottom if needed. |
| 358 | |
| 359 | #Return fBottom ## |
| 360 | |
| 361 | #Example |
| 362 | SkIRect unsorted = { 15, 25, 10, 5 }; |
| 363 | SkDebugf("unsorted.fBottom: %d unsorted.bottom(): %d\n", unsorted.fBottom, unsorted.bottom()); |
| 364 | SkIRect sorted = unsorted.makeSorted(); |
| 365 | SkDebugf("sorted.fBottom: %d sorted.bottom(): %d\n", sorted.fBottom, sorted.bottom()); |
| 366 | #StdOut |
| 367 | unsorted.fBottom: 5 unsorted.bottom(): 5 |
| 368 | sorted.fBottom: 25 sorted.bottom(): 25 |
| 369 | ## |
| 370 | ## |
| 371 | |
| 372 | #SeeAlso fBottom SkRect::bottom() |
| 373 | |
| 374 | ## |
| 375 | |
| 376 | # ------------------------------------------------------------------------------ |
| 377 | |
Cary Clark | 6def720 | 2018-01-04 08:13:35 -0500 | [diff] [blame] | 378 | #Method int32_t x() const |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 379 | |
| 380 | Returns left edge of IRect, if sorted. Call isEmpty to see if IRect may be invalid, |
| 381 | and sort() to reverse fLeft and fRight if needed. |
| 382 | |
| 383 | #Return fLeft ## |
| 384 | |
| 385 | #Example |
| 386 | SkIRect unsorted = { 15, 5, 10, 25 }; |
| 387 | SkDebugf("unsorted.fLeft: %d unsorted.x(): %d\n", unsorted.fLeft, unsorted.x()); |
| 388 | SkIRect sorted = unsorted.makeSorted(); |
| 389 | SkDebugf("sorted.fLeft: %d sorted.x(): %d\n", sorted.fLeft, sorted.x()); |
| 390 | #StdOut |
| 391 | unsorted.fLeft: 15 unsorted.x(): 15 |
| 392 | sorted.fLeft: 10 sorted.x(): 10 |
| 393 | ## |
| 394 | ## |
| 395 | |
| 396 | #SeeAlso fLeft left() y() SkRect::x() |
| 397 | |
| 398 | ## |
| 399 | |
| 400 | # ------------------------------------------------------------------------------ |
| 401 | |
Cary Clark | 6def720 | 2018-01-04 08:13:35 -0500 | [diff] [blame] | 402 | #Method int32_t y() const |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 403 | |
| 404 | Returns top edge of IRect, if sorted. Call isEmpty to see if IRect may be invalid, |
| 405 | and sort() to reverse fTop and fBottom if needed. |
| 406 | |
| 407 | #Return fTop ## |
| 408 | |
| 409 | #Example |
| 410 | SkIRect unsorted = { 15, 25, 10, 5 }; |
| 411 | SkDebugf("unsorted.fTop: %d unsorted.y(): %d\n", unsorted.fTop, unsorted.y()); |
| 412 | SkIRect sorted = unsorted.makeSorted(); |
| 413 | SkDebugf("sorted.fTop: %d sorted.y(): %d\n", sorted.fTop, sorted.y()); |
| 414 | #StdOut |
| 415 | unsorted.fTop: 25 unsorted.y(): 25 |
| 416 | sorted.fTop: 5 sorted.y(): 5 |
| 417 | ## |
| 418 | ## |
| 419 | |
| 420 | #SeeAlso fTop top() x() SkRect::y() |
| 421 | |
| 422 | ## |
| 423 | |
| 424 | # ------------------------------------------------------------------------------ |
| 425 | |
Cary Clark | 6def720 | 2018-01-04 08:13:35 -0500 | [diff] [blame] | 426 | #Method int32_t width() const |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 427 | |
| 428 | Returns span on the x-axis. This does not check if IRect is sorted, or if |
| 429 | result fits in 32-bit signed integer; result may be negative. |
| 430 | |
| 431 | #Return fRight minus fLeft ## |
| 432 | |
| 433 | #Example |
| 434 | SkIRect unsorted = { 15, 25, 10, 5 }; |
| 435 | SkDebugf("unsorted width: %d\n", unsorted.width()); |
| 436 | SkIRect large = { -2147483647, 1, 2147483644, 2 }; |
| 437 | SkDebugf("large width: %d\n", large.width()); |
| 438 | #StdOut |
| 439 | unsorted width: -5 |
| 440 | large width: -5 |
| 441 | ## |
| 442 | ## |
| 443 | |
Mike Reed | a766ca9 | 2018-01-09 11:31:53 -0500 | [diff] [blame] | 444 | #SeeAlso height() width64() height64() SkRect::width() |
| 445 | |
| 446 | ## |
| 447 | |
| 448 | # ------------------------------------------------------------------------------ |
| 449 | |
| 450 | #Method int64_t width64() const |
| 451 | |
| 452 | Returns span on the x-axis. This does not check if IRect is sorted, so the |
| 453 | result may be negative. This is safer than calling width() since width() might |
| 454 | overflow in its calculation. |
| 455 | |
| 456 | #Return fRight minus fLeft cast to int64_t ## |
| 457 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 458 | #Bug 7489 ## |
| 459 | # width64 is not yet visible to fiddle |
| 460 | #NoExample |
Mike Reed | a766ca9 | 2018-01-09 11:31:53 -0500 | [diff] [blame] | 461 | SkIRect large = { -2147483647, 1, 2147483644, 2 }; |
| 462 | SkDebugf("width: %d wdith64: %lld\n", large.width(), large.width64()); |
| 463 | #StdOut |
| 464 | width: -5 width64: 4294967291 |
| 465 | ## |
| 466 | ## |
| 467 | |
| 468 | #SeeAlso width() height() height64() SkRect::width() |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 469 | |
| 470 | ## |
| 471 | |
| 472 | # ------------------------------------------------------------------------------ |
| 473 | |
Cary Clark | 6def720 | 2018-01-04 08:13:35 -0500 | [diff] [blame] | 474 | #Method int32_t height() const |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 475 | |
| 476 | Returns span on the y-axis. This does not check if IRect is sorted, or if |
| 477 | result fits in 32-bit signed integer; result may be negative. |
| 478 | |
| 479 | #Return fBottom minus fTop ## |
| 480 | |
| 481 | #Example |
| 482 | SkIRect unsorted = { 15, 25, 10, 20 }; |
| 483 | SkDebugf("unsorted height: %d\n", unsorted.height()); |
| 484 | SkIRect large = { 1, -2147483647, 2, 2147483644 }; |
| 485 | SkDebugf("large height: %d\n", large.height()); |
| 486 | #StdOut |
| 487 | unsorted height: -5 |
| 488 | large height: -5 |
| 489 | ## |
| 490 | ## |
| 491 | |
| 492 | #SeeAlso width() SkRect::height() |
| 493 | |
| 494 | ## |
| 495 | |
| 496 | # ------------------------------------------------------------------------------ |
| 497 | |
Mike Reed | a766ca9 | 2018-01-09 11:31:53 -0500 | [diff] [blame] | 498 | #Method int64_t height64() const |
| 499 | |
| 500 | Returns span on the y-axis. This does not check if IRect is sorted, so the |
| 501 | result may be negative. This is safer than calling height() since height() might |
| 502 | overflow in its calculation. |
| 503 | |
| 504 | #Return fBottom minus fTop cast to int64_t ## |
| 505 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 506 | #Bug 7489 ## |
| 507 | # height64 not yet visible to fiddle |
| 508 | #NoExample |
Mike Reed | a766ca9 | 2018-01-09 11:31:53 -0500 | [diff] [blame] | 509 | SkIRect large = { 1, -2147483647, 2, 2147483644 }; |
| 510 | SkDebugf("height: %d height64: %lld\n", large.height(), large.height64()); |
| 511 | #StdOut |
| 512 | height: -5 height64: 4294967291 |
| 513 | ## |
| 514 | ## |
| 515 | |
| 516 | #SeeAlso width() height() width64() SkRect::height() |
| 517 | |
| 518 | ## |
| 519 | |
| 520 | # ------------------------------------------------------------------------------ |
| 521 | |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 522 | #Method SkISize size() const |
| 523 | |
| 524 | Returns spans on the x-axis and y-axis. This does not check if IRect is sorted, |
| 525 | or if result fits in 32-bit signed integer; result may be negative. |
| 526 | |
| 527 | #Return ISize (width, height) ## |
| 528 | |
| 529 | #Example |
| 530 | auto debugster = [](const char* prefix, const SkIRect& rect) -> void { |
| 531 | SkISize size = rect.size(); |
| 532 | SkDebugf("%s ", prefix); |
| 533 | SkDebugf("rect: %d, %d, %d, %d ", rect.left(), rect.top(), rect.right(), rect.bottom()); |
| 534 | SkDebugf("size: %d, %d\n", size.width(), size.height()); |
| 535 | }; |
| 536 | SkIRect rect = {20, 30, 40, 50}; |
| 537 | debugster("original", rect); |
| 538 | rect.offset(20, 20); |
| 539 | debugster(" offset", rect); |
| 540 | rect.outset(20, 20); |
| 541 | debugster(" outset", rect); |
| 542 | #StdOut |
| 543 | original rect: 20, 30, 40, 50 size: 20, 20 |
| 544 | offset rect: 40, 50, 60, 70 size: 20, 20 |
| 545 | outset rect: 20, 30, 80, 90 size: 60, 60 |
| 546 | ## |
| 547 | ## |
| 548 | |
| 549 | #SeeAlso height() width() MakeSize |
| 550 | |
| 551 | ## |
| 552 | |
| 553 | # ------------------------------------------------------------------------------ |
| 554 | |
Cary Clark | 6def720 | 2018-01-04 08:13:35 -0500 | [diff] [blame] | 555 | #Method int32_t centerX() const |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 556 | |
| 557 | Returns average of left edge and right edge. Result does not change if Rect |
| 558 | is sorted. Result may be incorrect if Rect is far from the origin. |
| 559 | |
| 560 | Result is rounded down. |
| 561 | |
| 562 | #Return midpoint in x ## |
| 563 | |
| 564 | #Example |
| 565 | #Description |
| 566 | Dividing by two rounds towards zero. centerX uses a bit shift and rounds down. |
| 567 | ## |
| 568 | SkIRect tests[] = {{20, 30, 41, 51}, {-20, -30, -41, -51}, {-10, -10, 11, 11}}; |
| 569 | for (auto rect : tests) { |
| 570 | SkDebugf("left: %3d right: %3d centerX: %3d ", rect.left(), rect.right(), rect.centerX()); |
| 571 | SkDebugf("div2: %3d\n", (rect.left() + rect.right()) / 2); |
| 572 | } |
| 573 | #StdOut |
| 574 | left: 20 right: 41 centerX: 30 div2: 30 |
| 575 | left: -20 right: -41 centerX: -31 div2: -30 |
| 576 | left: -10 right: 11 centerX: 0 div2: 0 |
| 577 | ## |
| 578 | ## |
| 579 | |
| 580 | #SeeAlso centerY SkRect::centerX |
| 581 | |
| 582 | ## |
| 583 | |
| 584 | # ------------------------------------------------------------------------------ |
| 585 | |
Cary Clark | 6def720 | 2018-01-04 08:13:35 -0500 | [diff] [blame] | 586 | #Method int32_t centerY() const |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 587 | |
| 588 | Returns average of top edge and bottom edge. Result does not change if Rect |
| 589 | is sorted. Result may be incorrect if Rect is far from the origin. |
| 590 | |
| 591 | Result is rounded down. |
| 592 | |
| 593 | #Return midpoint in y ## |
| 594 | |
| 595 | #Example |
| 596 | SkIRect rect = { 0, 0, 2, 2 }; |
| 597 | rect.offset(0x40000000, 0x40000000); |
| 598 | SkDebugf("left: %d right: %d centerX: %d ", rect.left(), rect.right(), rect.centerX()); |
| 599 | SkDebugf("safe mid x: %d\n", rect.left() / 2 + rect.right() / 2); |
| 600 | #StdOut |
| 601 | left: 1073741824 right: 1073741826 centerX: -1073741823 safe mid x: 1073741825 |
| 602 | ## |
| 603 | ## |
| 604 | |
| 605 | #SeeAlso centerX SkRect::centerY |
| 606 | |
| 607 | ## |
| 608 | |
| 609 | # ------------------------------------------------------------------------------ |
| 610 | |
| 611 | #Method bool isEmpty() const |
| 612 | |
Mike Reed | d284949 | 2018-01-10 14:31:18 -0500 | [diff] [blame] | 613 | Returns true if width() or height() . |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 614 | |
| 615 | #Return true if width() or height() are zero or negative ## |
| 616 | |
| 617 | #Example |
| 618 | SkIRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}}; |
| 619 | for (auto rect : tests) { |
| 620 | SkDebugf("rect: {%d, %d, %d, %d} is" "%s empty\n", rect.left(), rect.top(), rect.right(), |
| 621 | rect.bottom(), rect.isEmpty() ? "" : " not"); |
| 622 | rect.sort(); |
| 623 | SkDebugf("sorted: {%d, %d, %d, %d} is" "%s empty\n", rect.left(), rect.top(), rect.right(), |
| 624 | rect.bottom(), rect.isEmpty() ? "" : " not"); |
| 625 | } |
| 626 | #StdOut |
| 627 | rect: {20, 40, 10, 50} is empty |
| 628 | sorted: {10, 40, 20, 50} is not empty |
| 629 | rect: {20, 40, 20, 50} is empty |
| 630 | sorted: {20, 40, 20, 50} is empty |
| 631 | ## |
| 632 | ## |
| 633 | |
| 634 | #SeeAlso EmptyIRect MakeEmpty sort SkRect::isEmpty |
| 635 | |
| 636 | ## |
| 637 | |
| 638 | # ------------------------------------------------------------------------------ |
| 639 | |
Mike Reed | d284949 | 2018-01-10 14:31:18 -0500 | [diff] [blame] | 640 | #Method bool isEmpty64() const |
| 641 | |
| 642 | Returns true if fLeft is equal to or greater than fRight, or if fTop is equal |
| 643 | to or greater than fBottom. Call sort() to reverse rectangles with negative |
| 644 | width64() or height64(). |
| 645 | |
| 646 | #Return true if width64() or height64() are zero or negative ## |
| 647 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 648 | #Bug 7489 ## |
| 649 | # isEmpty64 not yet visible to fiddle |
| 650 | #NoExample |
Mike Reed | d284949 | 2018-01-10 14:31:18 -0500 | [diff] [blame] | 651 | SkIRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}}; |
| 652 | for (auto rect : tests) { |
| 653 | SkDebugf("rect: {%d, %d, %d, %d} is" "%s empty\n", rect.left(), rect.top(), rect.right(), |
| 654 | rect.bottom(), isEmpty64() ? "" : " not"); |
| 655 | rect.sort(); |
| 656 | SkDebugf("sorted: {%d, %d, %d, %d} is" "%s empty\n", rect.left(), rect.top(), rect.right(), |
| 657 | rect.bottom(), isEmpty64() ? "" : " not"); |
| 658 | } |
| 659 | #StdOut |
| 660 | rect: {20, 40, 10, 50} is empty |
| 661 | sorted: {10, 40, 20, 50} is not empty |
| 662 | rect: {20, 40, 20, 50} is empty |
| 663 | sorted: {20, 40, 20, 50} is empty |
| 664 | ## |
| 665 | ## |
| 666 | |
| 667 | #SeeAlso EmptyIRect MakeEmpty sort SkRect::isEmpty |
| 668 | |
| 669 | ## |
| 670 | |
| 671 | # ------------------------------------------------------------------------------ |
| 672 | |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 673 | #Method bool operator==(const SkIRect& a, const SkIRect& b) |
| 674 | |
| 675 | Returns true if all members in a: fLeft, fTop, fRight, and fBottom; are |
| 676 | identical to corresponding members in b. |
| 677 | |
| 678 | #Param a IRect to compare ## |
| 679 | #Param b IRect to compare ## |
| 680 | |
| 681 | #Return true if members are equal ## |
| 682 | |
| 683 | #Example |
| 684 | SkIRect test = {0, 0, 2, 2}; |
| 685 | SkIRect sorted = test.makeSorted(); |
| 686 | SkDebugf("test %c= sorted\n", test == sorted ? '=' : '!'); |
| 687 | #StdOut |
| 688 | test == sorted |
| 689 | ## |
| 690 | ## |
| 691 | |
| 692 | #SeeAlso operator!=(const SkIRect& a, const SkIRect& b) |
| 693 | |
| 694 | ## |
| 695 | |
| 696 | # ------------------------------------------------------------------------------ |
| 697 | |
| 698 | #Method bool operator!=(const SkIRect& a, const SkIRect& b) |
| 699 | |
| 700 | Returns true if any member in a: fLeft, fTop, fRight, and fBottom; is not |
| 701 | identical to the corresponding member in b. |
| 702 | |
| 703 | #Param a IRect to compare ## |
| 704 | #Param b IRect to compare ## |
| 705 | |
| 706 | #Return true if members are not equal ## |
| 707 | |
| 708 | #Example |
| 709 | SkIRect test = {2, 2, 0, 0}; |
| 710 | SkIRect sorted = test.makeSorted(); |
| 711 | SkDebugf("test %c= sorted\n", test != sorted ? '!' : '='); |
| 712 | #StdOut |
| 713 | test != sorted |
| 714 | ## |
| 715 | ## |
| 716 | |
| 717 | #SeeAlso operator==(const SkIRect& a, const SkIRect& b) |
| 718 | |
| 719 | ## |
| 720 | |
| 721 | # ------------------------------------------------------------------------------ |
| 722 | |
| 723 | #Method bool is16Bit() const |
| 724 | |
| 725 | Returns true if all members: fLeft, fTop, fRight, and fBottom; values are |
| 726 | equal to or larger than -32768 and equal to or smaller than 32767. |
| 727 | |
| 728 | #Return true if members fit in 16-bit word ## |
| 729 | |
| 730 | #Example |
| 731 | SkIRect tests[] = {{-32768, -32768, 32767, 32767}, {-32768, -32768, 32768, 32768}}; |
| 732 | for (auto rect : tests) { |
| 733 | SkDebugf("{%d, %d, %d, %d} %s in 16 bits\n", rect.fLeft, rect.fTop, rect.fRight, |
| 734 | rect.fBottom, rect.is16Bit() ? "fits" : "does not fit"); |
| 735 | } |
| 736 | #StdOut |
| 737 | {-32768, -32768, 32767, 32767} fits in 16 bits |
| 738 | {-32768, -32768, 32768, 32768} does not fit in 16 bits |
| 739 | ## |
| 740 | ## |
| 741 | |
| 742 | #SeeAlso SkTFitsIn |
| 743 | |
| 744 | ## |
| 745 | |
| 746 | # ------------------------------------------------------------------------------ |
| 747 | |
| 748 | #Method void setEmpty() |
| 749 | |
| 750 | Sets IRect to (0, 0, 0, 0). |
| 751 | |
| 752 | Many other rectangles are empty; if left is equal to or greater than right, |
| 753 | or if top is equal to or greater than bottom. Setting all members to zero |
| 754 | is a convenience, but does not designate a special empty rectangle. |
| 755 | |
| 756 | #Example |
| 757 | SkIRect rect = {3, 4, 1, 2}; |
| 758 | for (int i = 0; i < 2; ++i) { |
| 759 | SkDebugf("rect: {%d, %d, %d, %d} is %s" "empty\n", rect.fLeft, rect.fTop, |
| 760 | rect.fRight, rect.fBottom, rect.isEmpty() ? "" : "not "); |
| 761 | rect.setEmpty(); |
| 762 | } |
| 763 | #StdOut |
| 764 | rect: {3, 4, 1, 2} is empty |
| 765 | rect: {0, 0, 0, 0} is empty |
| 766 | ## |
| 767 | ## |
| 768 | |
| 769 | #SeeAlso MakeEmpty SkRect::setEmpty |
| 770 | |
| 771 | ## |
| 772 | |
| 773 | # ------------------------------------------------------------------------------ |
| 774 | |
| 775 | #Method void set(int32_t left, int32_t top, int32_t right, int32_t bottom) |
| 776 | |
| 777 | Sets IRect to (left, top, right, bottom). |
| 778 | left and right are not sorted; left is not necessarily less than right. |
| 779 | top and bottom are not sorted; top is not necessarily less than bottom. |
| 780 | |
| 781 | #Param left assigned to fLeft ## |
| 782 | #Param top assigned to fTop ## |
| 783 | #Param right assigned to fRight ## |
| 784 | #Param bottom assigned to fBottom ## |
| 785 | |
| 786 | #Example |
| 787 | SkIRect rect1 = {3, 4, 1, 2}; |
| 788 | SkDebugf("rect1: {%d, %d, %d, %d}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom); |
| 789 | SkIRect rect2; |
| 790 | rect2.set(3, 4, 1, 2); |
| 791 | SkDebugf("rect2: {%d, %d, %d, %d}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom); |
| 792 | #StdOut |
| 793 | rect1: {3, 4, 1, 2} |
| 794 | rect2: {3, 4, 1, 2} |
| 795 | ## |
| 796 | ## |
| 797 | |
| 798 | #SeeAlso setLTRB setXYWH SkRect::set |
| 799 | |
| 800 | ## |
| 801 | |
| 802 | # ------------------------------------------------------------------------------ |
| 803 | |
| 804 | #Method void setLTRB(int32_t left, int32_t top, int32_t right, int32_t bottom) |
| 805 | |
| 806 | Sets IRect to (left, top, right, bottom). |
| 807 | left and right are not sorted; left is not necessarily less than right. |
| 808 | top and bottom are not sorted; top is not necessarily less than bottom. |
| 809 | |
| 810 | #Param left stored in fLeft ## |
| 811 | #Param top stored in fTop ## |
| 812 | #Param right stored in fRight ## |
| 813 | #Param bottom stored in fBottom ## |
| 814 | |
| 815 | #Example |
| 816 | SkIRect rect1 = {3, 4, 1, 2}; |
| 817 | SkDebugf("rect1: {%d, %d, %d, %d}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom); |
| 818 | SkIRect rect2; |
| 819 | rect2.setLTRB(3, 4, 1, 2); |
| 820 | SkDebugf("rect2: {%d, %d, %d, %d}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom); |
| 821 | #StdOut |
| 822 | rect1: {3, 4, 1, 2} |
| 823 | rect2: {3, 4, 1, 2} |
| 824 | ## |
| 825 | ## |
| 826 | |
| 827 | #SeeAlso set setXYWH SkRect::setLTRB |
| 828 | |
| 829 | ## |
| 830 | |
| 831 | # ------------------------------------------------------------------------------ |
| 832 | |
| 833 | #Method void setXYWH(int32_t x, int32_t y, int32_t width, int32_t height) |
| 834 | |
| 835 | Sets IRect to: |
| 836 | #Formula |
| 837 | (x, y, x + width, y + height) |
| 838 | ## |
| 839 | . Does not validate input; |
| 840 | width or height may be negative. |
| 841 | |
| 842 | #Param x stored in fLeft ## |
| 843 | #Param y stored in fTop ## |
| 844 | #Param width added to x and stored in fRight ## |
| 845 | #Param height added to y and stored in fBottom ## |
| 846 | |
| 847 | #Example |
| 848 | SkIRect rect; |
| 849 | rect.setXYWH(5, 35, -15, 25); |
| 850 | SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), |
| 851 | rect.bottom(), rect.isEmpty() ? "true" : "false"); |
| 852 | rect.sort(); |
| 853 | SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), |
| 854 | rect.bottom(), rect.isEmpty() ? "true" : "false"); |
| 855 | #StdOut |
| 856 | rect: 5, 35, -10, 60 isEmpty: true |
| 857 | rect: -10, 35, 5, 60 isEmpty: false |
| 858 | ## |
| 859 | ## |
| 860 | |
| 861 | #SeeAlso MakeXYWH setLTRB set SkRect::setXYWH |
| 862 | |
| 863 | ## |
| 864 | |
| 865 | # ------------------------------------------------------------------------------ |
| 866 | |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 867 | #Method SkIRect makeOffset(int32_t dx, int32_t dy) const |
| 868 | |
| 869 | Returns IRect offset by (dx, dy). |
| 870 | |
| 871 | If dx is negative, IRect returned is moved to the left. |
| 872 | If dx is positive, IRect returned is moved to the right. |
| 873 | If dy is negative, IRect returned is moved upward. |
| 874 | If dy is positive, IRect returned is moved downward. |
| 875 | |
| 876 | #Param dx offset added to fLeft and fRight ## |
| 877 | #Param dy offset added to fTop and fBottom ## |
| 878 | |
| 879 | #Return Rect offset in x or y, with original width and height ## |
| 880 | |
| 881 | #Example |
| 882 | SkIRect rect = { 10, 50, 20, 60 }; |
| 883 | SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), |
| 884 | rect.bottom(), rect.isEmpty() ? "true" : "false"); |
| 885 | rect = rect.makeOffset(15, 32); |
| 886 | SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), |
| 887 | rect.bottom(), rect.isEmpty() ? "true" : "false"); |
| 888 | #StdOut |
| 889 | rect: 10, 50, 20, 60 isEmpty: false |
| 890 | rect: 25, 82, 35, 92 isEmpty: false |
| 891 | ## |
| 892 | ## |
| 893 | |
| 894 | #SeeAlso offset() makeInset makeOutset SkRect::makeOffset |
| 895 | |
| 896 | ## |
| 897 | |
| 898 | # ------------------------------------------------------------------------------ |
| 899 | |
| 900 | #Method SkIRect makeInset(int32_t dx, int32_t dy) const |
| 901 | |
| 902 | Returns IRect, inset by (dx, dy). |
| 903 | |
| 904 | If dx is negative, IRect returned is wider. |
| 905 | If dx is positive, IRect returned is narrower. |
| 906 | If dy is negative, IRect returned is taller. |
| 907 | If dy is positive, IRect returned is shorter. |
| 908 | |
| 909 | #Param dx offset added to fLeft and subtracted from fRight ## |
| 910 | #Param dy offset added to fTop and subtracted from fBottom ## |
| 911 | |
| 912 | #Return Rect inset symmetrically left and right, top and bottom ## |
| 913 | |
| 914 | #Example |
| 915 | SkIRect rect = { 10, 50, 20, 60 }; |
| 916 | SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), |
| 917 | rect.bottom(), rect.isEmpty() ? "true" : "false"); |
| 918 | rect = rect.makeInset(15, 32); |
| 919 | SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), |
| 920 | rect.bottom(), rect.isEmpty() ? "true" : "false"); |
| 921 | #StdOut |
| 922 | rect: 10, 50, 20, 60 isEmpty: false |
| 923 | rect: 25, 82, 5, 28 isEmpty: true |
| 924 | ## |
| 925 | ## |
| 926 | |
| 927 | #SeeAlso inset() makeOffset makeOutset SkRect::makeInset |
| 928 | |
| 929 | ## |
| 930 | |
| 931 | # ------------------------------------------------------------------------------ |
| 932 | |
| 933 | #Method SkIRect makeOutset(int32_t dx, int32_t dy) const |
| 934 | |
| 935 | Returns IRect, outset by (dx, dy). |
| 936 | |
| 937 | If dx is negative, IRect returned is narrower. |
| 938 | If dx is positive, IRect returned is wider. |
| 939 | If dy is negative, IRect returned is shorter. |
| 940 | If dy is positive, IRect returned is taller. |
| 941 | |
| 942 | #Param dx offset subtracted to fLeft and added from fRight ## |
| 943 | #Param dy offset subtracted to fTop and added from fBottom ## |
| 944 | |
| 945 | #Return Rect outset symmetrically left and right, top and bottom ## |
| 946 | |
| 947 | #Example |
| 948 | SkIRect rect = { 10, 50, 20, 60 }; |
| 949 | SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), |
| 950 | rect.bottom(), rect.isEmpty() ? "true" : "false"); |
| 951 | rect = rect.makeOutset(15, 32); |
| 952 | SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), |
| 953 | rect.bottom(), rect.isEmpty() ? "true" : "false"); |
| 954 | #StdOut |
| 955 | rect: 10, 50, 20, 60 isEmpty: false |
| 956 | rect: -5, 18, 35, 92 isEmpty: false |
| 957 | ## |
| 958 | ## |
| 959 | |
| 960 | #SeeAlso outset() makeOffset makeInset SkRect::makeOutset |
| 961 | |
| 962 | ## |
| 963 | |
| 964 | # ------------------------------------------------------------------------------ |
| 965 | |
| 966 | #Method void offset(int32_t dx, int32_t dy) |
| 967 | |
| 968 | Offsets IRect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom. |
| 969 | |
| 970 | If dx is negative, moves IRect returned to the left. |
| 971 | If dx is positive, moves IRect returned to the right. |
| 972 | If dy is negative, moves IRect returned upward. |
| 973 | If dy is positive, moves IRect returned downward. |
| 974 | |
| 975 | #Param dx offset added to fLeft and fRight ## |
| 976 | #Param dy offset added to fTop and fBottom ## |
| 977 | |
| 978 | #Example |
| 979 | SkIRect rect = { 10, 14, 50, 73 }; |
| 980 | rect.offset(5, 13); |
| 981 | SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); |
| 982 | #StdOut |
| 983 | rect: 15, 27, 55, 86 |
| 984 | ## |
| 985 | ## |
| 986 | |
| 987 | #SeeAlso offsetTo makeOffset SkRect::offset |
| 988 | |
| 989 | ## |
| 990 | |
| 991 | # ------------------------------------------------------------------------------ |
| 992 | |
| 993 | #Method void offset(const SkIPoint& delta) |
| 994 | |
| 995 | Offsets IRect by adding delta.fX to fLeft, fRight; and by adding delta.fY to |
| 996 | fTop, fBottom. |
| 997 | |
| 998 | If delta.fX is negative, moves IRect returned to the left. |
| 999 | If delta.fX is positive, moves IRect returned to the right. |
| 1000 | If delta.fY is negative, moves IRect returned upward. |
| 1001 | If delta.fY is positive, moves IRect returned downward. |
| 1002 | |
| 1003 | #Param delta offset added to IRect ## |
| 1004 | |
| 1005 | #Example |
| 1006 | SkIRect rect = { 10, 14, 50, 73 }; |
| 1007 | rect.offset({5, 13}); |
| 1008 | SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); |
| 1009 | #StdOut |
| 1010 | rect: 15, 27, 55, 86 |
| 1011 | ## |
| 1012 | ## |
| 1013 | |
| 1014 | #SeeAlso offsetTo makeOffset SkRect::offset |
| 1015 | |
| 1016 | ## |
| 1017 | |
| 1018 | # ------------------------------------------------------------------------------ |
| 1019 | |
| 1020 | #Method void offsetTo(int32_t newX, int32_t newY) |
| 1021 | |
| 1022 | Offsets IRect so that fLeft equals newX, and fTop equals newY. width and height |
| 1023 | are unchanged. |
| 1024 | |
| 1025 | #Param newX stored in fLeft, preserving width() ## |
| 1026 | #Param newY stored in fTop, preserving height() ## |
| 1027 | |
| 1028 | #Example |
| 1029 | SkIRect rect = { 10, 14, 50, 73 }; |
| 1030 | rect.offsetTo(15, 27); |
| 1031 | SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); |
| 1032 | #StdOut |
| 1033 | rect: 15, 27, 55, 86 |
| 1034 | ## |
| 1035 | ## |
| 1036 | |
| 1037 | #SeeAlso offset makeOffset setXYWH SkRect::offsetTo |
| 1038 | |
| 1039 | ## |
| 1040 | |
| 1041 | # ------------------------------------------------------------------------------ |
| 1042 | |
| 1043 | #Method void inset(int32_t dx, int32_t dy) |
| 1044 | |
| 1045 | Insets IRect by (dx,dy). |
| 1046 | |
| 1047 | If dx is positive, makes IRect narrower. |
| 1048 | If dx is negative, makes IRect wider. |
| 1049 | If dy is positive, makes IRect shorter. |
| 1050 | If dy is negative, makes IRect taller. |
| 1051 | |
| 1052 | #Param dx offset added to fLeft and subtracted from fRight ## |
| 1053 | #Param dy offset added to fTop and subtracted from fBottom ## |
| 1054 | |
| 1055 | #Example |
| 1056 | SkIRect rect = { 10, 14, 50, 73 }; |
| 1057 | rect.inset(5, 13); |
| 1058 | SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); |
| 1059 | #StdOut |
| 1060 | rect: 15, 27, 45, 60 |
| 1061 | ## |
| 1062 | ## |
| 1063 | |
| 1064 | #SeeAlso outset makeInset SkRect::inset |
| 1065 | |
| 1066 | ## |
| 1067 | |
| 1068 | # ------------------------------------------------------------------------------ |
| 1069 | |
| 1070 | #Method void outset(int32_t dx, int32_t dy) |
| 1071 | |
| 1072 | Outsets IRect by (dx, dy). |
| 1073 | |
| 1074 | If dx is positive, makes Rect wider. |
| 1075 | If dx is negative, makes Rect narrower. |
| 1076 | If dy is positive, makes Rect taller. |
| 1077 | If dy is negative, makes Rect shorter. |
| 1078 | |
| 1079 | #Param dx subtracted to fLeft and added from fRight ## |
| 1080 | #Param dy subtracted to fTop and added from fBottom ## |
| 1081 | |
| 1082 | #Example |
| 1083 | SkIRect rect = { 10, 14, 50, 73 }; |
| 1084 | rect.outset(5, 13); |
| 1085 | SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); |
| 1086 | #StdOut |
| 1087 | rect: 5, 1, 55, 86 |
| 1088 | ## |
| 1089 | ## |
| 1090 | |
| 1091 | #SeeAlso inset makeOutset SkRect::outset |
| 1092 | |
| 1093 | ## |
| 1094 | |
| 1095 | # ------------------------------------------------------------------------------ |
| 1096 | |
| 1097 | #Method bool quickReject(int l, int t, int r, int b) const |
| 1098 | |
| 1099 | Constructs IRect (l, t, r, b) and returns true if constructed IRect does not |
| 1100 | intersect IRect. Does not check to see if construction or IRect is empty. |
| 1101 | |
| 1102 | Is implemented with short circuit logic so that true can be returned after |
| 1103 | a single compare. |
| 1104 | |
| 1105 | #Param l x minimum of constructed Rect ## |
| 1106 | #Param t y minimum of constructed Rect ## |
| 1107 | #Param r x maximum of constructed Rect ## |
| 1108 | #Param b y maximum of constructed Rect ## |
| 1109 | |
| 1110 | #Return true if construction and IRect have no area in common ## |
| 1111 | |
| 1112 | #Example |
| 1113 | #Description |
| 1114 | quickReject is the complement of Intersects. |
| 1115 | ## |
| 1116 | const SkIRect rect = {7, 11, 13, 17}; |
| 1117 | const int32_t* r = &rect.fLeft; |
| 1118 | const SkIRect tests[] = { {13, 11, 15, 17}, { 7, 7, 13, 11 }, { 12, 16, 14, 18 } }; |
| 1119 | for (auto& test : tests) { |
| 1120 | const int32_t* t = &test.fLeft; |
| 1121 | SkDebugf("rect (%d, %d, %d, %d) test(%d, %d, %d, %d) quickReject %s; intersects %s\n", |
| 1122 | r[0], r[1], r[2], r[3], t[0], t[1], t[2], t[3], |
| 1123 | rect.quickReject(t[0], t[1], t[2], t[3]) ? "true" : "false", |
| 1124 | SkIRect::Intersects(rect, test) ? "true" : "false"); |
| 1125 | } |
| 1126 | #StdOut |
| 1127 | rect (7, 11, 13, 17) test(13, 11, 15, 17) quickReject true; intersects false |
| 1128 | rect (7, 11, 13, 17) test(7, 7, 13, 11) quickReject true; intersects false |
| 1129 | rect (7, 11, 13, 17) test(12, 16, 14, 18) quickReject false; intersects true |
| 1130 | ## |
| 1131 | ## |
| 1132 | |
| 1133 | #SeeAlso Intersects |
| 1134 | |
| 1135 | ## |
| 1136 | |
| 1137 | # ------------------------------------------------------------------------------ |
| 1138 | |
| 1139 | #Method bool contains(int32_t x, int32_t y) const |
| 1140 | |
| 1141 | Returns true if: |
| 1142 | #Formula |
| 1143 | fLeft <= x < fRight && fTop <= y < fBottom |
| 1144 | ## |
| 1145 | . |
| 1146 | Returns false if Rect is empty. |
| 1147 | |
| 1148 | Considers input to describe constructed IRect: |
| 1149 | #Formula |
| 1150 | (x, y, x + 1, y + 1) |
| 1151 | ## |
| 1152 | and |
| 1153 | returns true if constructed area is completely enclosed by IRect area. |
| 1154 | |
| 1155 | #Param x test Point x-coordinate ## |
| 1156 | #Param y test Point y-coordinate ## |
| 1157 | |
| 1158 | #Return true if (x, y) is inside IRect ## |
| 1159 | |
| 1160 | #Example |
| 1161 | SkIRect rect = { 30, 50, 40, 60 }; |
| 1162 | SkIPoint pts[] = { { 30, 50}, { 40, 50}, { 30, 60} }; |
| 1163 | for (auto pt : pts) { |
| 1164 | SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d)\n", |
| 1165 | rect.left(), rect.top(), rect.right(), rect.bottom(), |
| 1166 | rect.contains(pt.x(), pt.y()) ? "contains" : "does not contain", pt.x(), pt.y()); |
| 1167 | } |
| 1168 | #StdOut |
| 1169 | rect: (30, 50, 40, 60) contains (30, 50) |
| 1170 | rect: (30, 50, 40, 60) does not contain (40, 50) |
| 1171 | rect: (30, 50, 40, 60) does not contain (30, 60) |
| 1172 | ## |
| 1173 | ## |
| 1174 | |
| 1175 | #SeeAlso containsNoEmptyCheck SkRect::contains |
| 1176 | |
| 1177 | ## |
| 1178 | |
| 1179 | # ------------------------------------------------------------------------------ |
| 1180 | |
| 1181 | #Method bool contains(int32_t left, int32_t top, int32_t right, int32_t bottom) const |
| 1182 | |
| 1183 | Constructs Rect to intersect from (left, top, right, bottom). Does not sort |
| 1184 | construction. |
| 1185 | |
| 1186 | Returns true if Rect contains construction. |
| 1187 | Returns false if Rect is empty or construction is empty. |
| 1188 | |
| 1189 | #Param left x minimum of constructed Rect ## |
| 1190 | #Param top y minimum of constructed Rect ## |
| 1191 | #Param right x maximum of constructed Rect ## |
| 1192 | #Param bottom y maximum of constructed Rect ## |
| 1193 | |
| 1194 | #Return true if all sides of IRect are outside construction ## |
| 1195 | |
| 1196 | #Example |
| 1197 | SkIRect rect = { 30, 50, 40, 60 }; |
| 1198 | SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} }; |
| 1199 | for (auto contained : tests) { |
| 1200 | bool success = rect.contains( |
| 1201 | contained.left(), contained.top(), contained.right(), contained.bottom()); |
| 1202 | SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n", |
| 1203 | rect.left(), rect.top(), rect.right(), rect.bottom(), |
| 1204 | success ? "contains" : "does not contain", |
| 1205 | contained.left(), contained.top(), contained.right(), contained.bottom()); |
| 1206 | } |
| 1207 | #StdOut |
| 1208 | rect: (30, 50, 40, 60) contains (30, 50, 31, 51) |
| 1209 | rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50) |
| 1210 | rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60) |
| 1211 | ## |
| 1212 | ## |
| 1213 | |
| 1214 | #SeeAlso containsNoEmptyCheck SkRect::contains |
| 1215 | |
| 1216 | ## |
| 1217 | |
| 1218 | # ------------------------------------------------------------------------------ |
| 1219 | |
| 1220 | #Method bool contains(const SkIRect& r) const |
| 1221 | |
| 1222 | Returns true if Rect contains r. |
| 1223 | Returns false if Rect is empty or r is empty. |
| 1224 | |
| 1225 | Rect contains r when Rect area completely includes r area. |
| 1226 | |
| 1227 | #Param r IRect contained ## |
| 1228 | |
| 1229 | #Return true if all sides of IRect are outside r ## |
| 1230 | |
| 1231 | #Example |
| 1232 | SkIRect rect = { 30, 50, 40, 60 }; |
| 1233 | SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} }; |
| 1234 | for (auto contained : tests) { |
| 1235 | SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n", |
| 1236 | rect.left(), rect.top(), rect.right(), rect.bottom(), |
| 1237 | rect.contains(contained) ? "contains" : "does not contain", |
| 1238 | contained.left(), contained.top(), contained.right(), contained.bottom()); |
| 1239 | } |
| 1240 | #StdOut |
| 1241 | rect: (30, 50, 40, 60) contains (30, 50, 31, 51) |
| 1242 | rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50) |
| 1243 | rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60) |
| 1244 | ## |
| 1245 | ## |
| 1246 | |
| 1247 | #SeeAlso containsNoEmptyCheck SkRect::contains |
| 1248 | |
| 1249 | ## |
| 1250 | |
| 1251 | # ------------------------------------------------------------------------------ |
| 1252 | |
| 1253 | #Method bool contains(const SkRect& r) const |
| 1254 | |
| 1255 | Returns true if Rect contains r. |
| 1256 | Returns false if Rect is empty or r is empty. |
| 1257 | |
| 1258 | Rect contains r when Rect area completely includes r area. |
| 1259 | |
| 1260 | #Param r Rect contained ## |
| 1261 | |
| 1262 | #Return true if all sides of IRect are outside r ## |
| 1263 | |
| 1264 | #Example |
| 1265 | SkIRect rect = { 30, 50, 40, 60 }; |
| 1266 | SkRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} }; |
| 1267 | for (auto contained : tests) { |
| 1268 | SkDebugf("rect: (%d, %d, %d, %d) %s (%g, %g, %g, %g)\n", |
| 1269 | rect.left(), rect.top(), rect.right(), rect.bottom(), |
| 1270 | rect.contains(contained) ? "contains" : "does not contain", |
| 1271 | contained.left(), contained.top(), contained.right(), contained.bottom()); |
| 1272 | } |
| 1273 | #StdOut |
| 1274 | rect: (30, 50, 40, 60) contains (30, 50, 31, 51) |
| 1275 | rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50) |
| 1276 | rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60) |
| 1277 | ## |
| 1278 | ## |
| 1279 | |
| 1280 | #SeeAlso containsNoEmptyCheck SkRect::contains |
| 1281 | |
| 1282 | ## |
| 1283 | |
| 1284 | # ------------------------------------------------------------------------------ |
| 1285 | |
| 1286 | #Method bool containsNoEmptyCheck(int32_t left, int32_t top, |
| 1287 | int32_t right, int32_t bottom) const |
| 1288 | |
| 1289 | Constructs IRect from (left, top, right, bottom). Does not sort |
| 1290 | construction. |
| 1291 | |
| 1292 | Returns true if Rect contains construction. |
| 1293 | Asserts if IRect is empty or construction is empty, and if SK_DEBUG is defined. |
| 1294 | |
| 1295 | Return is undefined if Rect is empty or construction is empty. |
| 1296 | |
| 1297 | #Param left x minimum of constructed Rect ## |
| 1298 | #Param top y minimum of constructed Rect ## |
| 1299 | #Param right x maximum of constructed Rect ## |
| 1300 | #Param bottom y maximum of constructed Rect ## |
| 1301 | |
| 1302 | #Return true if all sides of IRect are outside construction ## |
| 1303 | |
| 1304 | #Example |
| 1305 | SkIRect rect = { 30, 50, 40, 60 }; |
| 1306 | SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} }; |
| 1307 | for (auto contained : tests) { |
| 1308 | bool success = rect.containsNoEmptyCheck( |
| 1309 | contained.left(), contained.top(), contained.right(), contained.bottom()); |
| 1310 | SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n", |
| 1311 | rect.left(), rect.top(), rect.right(), rect.bottom(), |
| 1312 | success ? "contains" : "does not contain", |
| 1313 | contained.left(), contained.top(), contained.right(), contained.bottom()); |
| 1314 | } |
| 1315 | #StdOut |
| 1316 | rect: (30, 50, 40, 60) contains (30, 50, 31, 51) |
| 1317 | rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50) |
| 1318 | rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60) |
| 1319 | ## |
| 1320 | ## |
| 1321 | |
| 1322 | #SeeAlso contains SkRect::contains |
| 1323 | |
| 1324 | ## |
| 1325 | |
| 1326 | # ------------------------------------------------------------------------------ |
| 1327 | |
| 1328 | #Method bool containsNoEmptyCheck(const SkIRect& r) const |
| 1329 | |
| 1330 | Returns true if Rect contains construction. |
| 1331 | Asserts if IRect is empty or construction is empty, and if SK_DEBUG is defined. |
| 1332 | |
| 1333 | Return is undefined if Rect is empty or construction is empty. |
| 1334 | |
| 1335 | #Param r Rect contained ## |
| 1336 | |
| 1337 | #Return true if all sides of IRect are outside r ## |
| 1338 | |
| 1339 | #Example |
| 1340 | SkIRect rect = { 30, 50, 40, 60 }; |
| 1341 | SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} }; |
| 1342 | for (auto contained : tests) { |
| 1343 | SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n", |
| 1344 | rect.left(), rect.top(), rect.right(), rect.bottom(), |
| 1345 | rect.containsNoEmptyCheck(contained) ? "contains" : "does not contain", |
| 1346 | contained.left(), contained.top(), contained.right(), contained.bottom()); |
| 1347 | } |
| 1348 | #StdOut |
| 1349 | rect: (30, 50, 40, 60) contains (30, 50, 31, 51) |
| 1350 | rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50) |
| 1351 | rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60) |
| 1352 | ## |
| 1353 | ## |
| 1354 | |
| 1355 | #SeeAlso contains SkRect::contains |
| 1356 | |
| 1357 | ## |
| 1358 | |
| 1359 | #Topic Intersection |
| 1360 | |
| 1361 | IRects intersect when they enclose a common area. To intersect, each of the pair |
| 1362 | must describe area; fLeft is less than fRight, and fTop is less than fBottom; |
| 1363 | empty() returns false. The intersection of IRect pair can be described by: |
| 1364 | #Formula |
| 1365 | (max(a.fLeft, b.fLeft), max(a.fTop, b.fTop), |
| 1366 | min(a.fRight, b.fRight), min(a.fBottom, b.fBottom)) |
| 1367 | ## |
| 1368 | The intersection is only meaningful if the resulting IRect is not empty and |
| 1369 | describes an area: fLeft is less than fRight, and fTop is less than fBottom. |
| 1370 | |
| 1371 | # ------------------------------------------------------------------------------ |
| 1372 | |
| 1373 | #Method bool intersect(const SkIRect& r) |
| 1374 | |
| 1375 | Returns true if IRect intersects r, and sets IRect to intersection. |
| 1376 | Returns false if IRect does not intersect r, and leaves IRect unchanged. |
| 1377 | |
| 1378 | Returns false if either r or IRect is empty, leaving IRect unchanged. |
| 1379 | |
| 1380 | #Param r limit of result ## |
| 1381 | |
| 1382 | #Return true if r and Rect have area in common ## |
| 1383 | |
| 1384 | #Example |
| 1385 | #Description |
| 1386 | Two SkDebugf calls are required. If the calls are combined, their arguments |
| 1387 | may not be evaluated in left to right order: the printed intersection may |
| 1388 | be before or after the call to intersect. |
| 1389 | ## |
| 1390 | SkIRect leftRect = { 10, 40, 50, 80 }; |
| 1391 | SkIRect rightRect = { 30, 60, 70, 90 }; |
| 1392 | SkDebugf("%s intersection: ", leftRect.intersect(rightRect) ? "" : "no "); |
| 1393 | SkDebugf("%d, %d, %d, %d\n", leftRect.left(), leftRect.top(), |
| 1394 | leftRect.right(), leftRect.bottom()); |
| 1395 | #StdOut |
| 1396 | intersection: 30, 60, 50, 80 |
| 1397 | ## |
| 1398 | ## |
| 1399 | |
| 1400 | #SeeAlso Intersects intersectNoEmptyCheck join SkRect::intersect |
| 1401 | |
| 1402 | ## |
| 1403 | |
| 1404 | # ------------------------------------------------------------------------------ |
| 1405 | |
| 1406 | #Method bool SK_WARN_UNUSED_RESULT intersect(const SkIRect& a, const SkIRect& b) |
| 1407 | |
| 1408 | Returns true if a intersects b, and sets IRect to intersection. |
| 1409 | Returns false if a does not intersect b, and leaves IRect unchanged. |
| 1410 | |
| 1411 | Returns false if either a or b is empty, leaving IRect unchanged. |
| 1412 | |
| 1413 | #Param a IRect to intersect ## |
| 1414 | #Param b IRect to intersect ## |
| 1415 | |
| 1416 | #Return true if a and b have area in common ## |
| 1417 | |
| 1418 | #Example |
| 1419 | SkIRect result; |
| 1420 | bool intersected = result.intersect({ 10, 40, 50, 80 }, { 30, 60, 70, 90 }); |
| 1421 | SkDebugf("%s intersection: %d, %d, %d, %d\n", intersected ? "" : "no ", |
| 1422 | result.left(), result.top(), result.right(), result.bottom()); |
| 1423 | #StdOut |
| 1424 | intersection: 30, 60, 50, 80 |
| 1425 | ## |
| 1426 | ## |
| 1427 | |
| 1428 | #SeeAlso Intersects intersectNoEmptyCheck join SkRect::intersect |
| 1429 | |
| 1430 | ## |
| 1431 | |
| 1432 | # ------------------------------------------------------------------------------ |
| 1433 | |
| 1434 | #Method bool SK_WARN_UNUSED_RESULT intersectNoEmptyCheck(const SkIRect& a, const SkIRect& b) |
| 1435 | |
| 1436 | Returns true if a intersects b, and sets IRect to intersection. |
| 1437 | Returns false if a does not intersect b, and leaves IRect unchanged. |
| 1438 | |
| 1439 | Asserts if either a or b is empty, and if SK_DEBUG is defined. |
| 1440 | |
| 1441 | #Param a IRect to intersect ## |
| 1442 | #Param b IRect to intersect ## |
| 1443 | |
| 1444 | #Return true if a and b have area in common ## |
| 1445 | |
| 1446 | #Example |
| 1447 | SkIRect result; |
| 1448 | bool intersected = result.intersectNoEmptyCheck({ 10, 40, 50, 80 }, { 30, 60, 70, 90 }); |
| 1449 | SkDebugf("intersection: %d, %d, %d, %d\n", |
| 1450 | result.left(), result.top(), result.right(), result.bottom()); |
| 1451 | #StdOut |
| 1452 | intersection: 30, 60, 50, 80 |
| 1453 | ## |
| 1454 | ## |
| 1455 | |
| 1456 | #SeeAlso Intersects intersect join SkRect::intersect |
| 1457 | |
| 1458 | ## |
| 1459 | |
| 1460 | # ------------------------------------------------------------------------------ |
| 1461 | |
| 1462 | #Method bool intersect(int32_t left, int32_t top, int32_t right, int32_t bottom) |
| 1463 | |
| 1464 | Constructs IRect to intersect from (left, top, right, bottom). Does not sort |
| 1465 | construction. |
| 1466 | |
| 1467 | Returns true if IRect intersects construction, and sets IRect to intersection. |
| 1468 | Returns false if IRect does not intersect construction, and leaves IRect unchanged. |
| 1469 | |
| 1470 | Returns false if either construction or IRect is empty, leaving IRect unchanged. |
| 1471 | |
| 1472 | #Param left x minimum of constructed IRect ## |
| 1473 | #Param top y minimum of constructed IRect ## |
| 1474 | #Param right x maximum of constructed IRect ## |
| 1475 | #Param bottom y maximum of constructed IRect ## |
| 1476 | |
| 1477 | #Return true if construction and IRect have area in common ## |
| 1478 | |
| 1479 | #Example |
| 1480 | #Description |
| 1481 | Two SkDebugf calls are required. If the calls are combined, their arguments |
| 1482 | may not be evaluated in left to right order: the printed intersection may |
| 1483 | be before or after the call to intersect. |
| 1484 | ## |
| 1485 | SkIRect leftRect = { 10, 40, 50, 80 }; |
| 1486 | SkDebugf("%s intersection: ", leftRect.intersect(30, 60, 70, 90) ? "" : "no "); |
| 1487 | SkDebugf("%d, %d, %d, %d\n", leftRect.left(), leftRect.top(), |
| 1488 | leftRect.right(), leftRect.bottom()); |
| 1489 | #StdOut |
| 1490 | intersection: 30, 60, 50, 80 |
| 1491 | ## |
| 1492 | ## |
| 1493 | |
| 1494 | #SeeAlso intersectNoEmptyCheck Intersects join SkRect::intersect |
| 1495 | |
| 1496 | ## |
| 1497 | |
| 1498 | # ------------------------------------------------------------------------------ |
| 1499 | |
| 1500 | #Method static bool Intersects(const SkIRect& a, const SkIRect& b) |
| 1501 | |
| 1502 | Returns true if a intersects b. |
| 1503 | Returns false if either a or b is empty, or do not intersect. |
| 1504 | |
| 1505 | #Param a IRect to intersect ## |
| 1506 | #Param b IRect to intersect ## |
| 1507 | |
| 1508 | #Return true if a and b have area in common ## |
| 1509 | |
| 1510 | #Example |
| 1511 | SkDebugf("%s intersection", SkIRect::Intersects({10, 40, 50, 80}, {30, 60, 70, 90}) ? "" : "no "); |
| 1512 | #StdOut |
| 1513 | intersection |
| 1514 | ## |
| 1515 | ## |
| 1516 | |
| 1517 | #SeeAlso IntersectsNoEmptyCheck intersect SkRect::intersect |
| 1518 | |
| 1519 | ## |
| 1520 | |
| 1521 | # ------------------------------------------------------------------------------ |
| 1522 | |
| 1523 | #Method static bool IntersectsNoEmptyCheck(const SkIRect& a, const SkIRect& b) |
| 1524 | |
| 1525 | Returns true if a intersects b. |
| 1526 | Asserts if either a or b is empty, and if SK_DEBUG is defined. |
| 1527 | |
| 1528 | #Param a IRect to intersect ## |
| 1529 | #Param b IRect to intersect ## |
| 1530 | |
| 1531 | #Return true if a and b have area in common ## |
| 1532 | |
| 1533 | #Example |
| 1534 | SkDebugf("%s intersection", SkIRect::IntersectsNoEmptyCheck( |
| 1535 | {10, 40, 50, 80}, {30, 60, 70, 90}) ? "" : "no "); |
| 1536 | #StdOut |
| 1537 | intersection |
| 1538 | ## |
| 1539 | ## |
| 1540 | |
| 1541 | #SeeAlso Intersects intersect SkRect::intersect |
| 1542 | |
| 1543 | ## |
| 1544 | |
| 1545 | #Topic Intersection ## |
| 1546 | |
| 1547 | # ------------------------------------------------------------------------------ |
| 1548 | |
| 1549 | #Method void join(int32_t left, int32_t top, int32_t right, int32_t bottom) |
| 1550 | |
| 1551 | Constructs Rect to intersect from (left, top, right, bottom). Does not sort |
| 1552 | construction. |
| 1553 | |
| 1554 | Sets Rect to the union of itself and the construction. |
| 1555 | |
| 1556 | Has no effect if construction is empty. Otherwise, if Rect is empty, sets |
| 1557 | Rect to construction. |
| 1558 | |
| 1559 | #Param left x minimum of constructed Rect ## |
| 1560 | #Param top y minimum of constructed Rect ## |
| 1561 | #Param right x maximum of constructed Rect ## |
| 1562 | #Param bottom y maximum of constructed Rect ## |
| 1563 | |
| 1564 | #Example |
| 1565 | SkIRect rect = { 10, 20, 15, 25}; |
| 1566 | rect.join(50, 60, 55, 65); |
| 1567 | SkDebugf("join: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); |
| 1568 | #StdOut |
| 1569 | join: 10, 20, 55, 65 |
| 1570 | ## |
| 1571 | ## |
| 1572 | |
| 1573 | #SeeAlso set SkRect::join |
| 1574 | |
| 1575 | ## |
| 1576 | |
| 1577 | # ------------------------------------------------------------------------------ |
| 1578 | |
| 1579 | #Method void join(const SkIRect& r) |
| 1580 | |
| 1581 | Sets Rect to the union of itself and r. |
| 1582 | |
| 1583 | Has no effect if r is empty. Otherwise, if Rect is empty, sets Rect to r. |
| 1584 | |
| 1585 | #Param r expansion Rect ## |
| 1586 | |
| 1587 | #Example |
| 1588 | SkIRect rect = { 10, 20, 15, 25}; |
| 1589 | rect.join({50, 60, 55, 65}); |
| 1590 | SkDebugf("join: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); |
| 1591 | #StdOut |
| 1592 | join: 10, 20, 55, 65 |
| 1593 | ## |
| 1594 | ## |
| 1595 | |
| 1596 | #SeeAlso set SkRect::join |
| 1597 | |
| 1598 | ## |
| 1599 | |
| 1600 | # ------------------------------------------------------------------------------ |
| 1601 | |
| 1602 | #Method void sort() |
| 1603 | |
| 1604 | Swaps fLeft and fRight if fLeft is greater than fRight; and swaps |
| 1605 | fTop and fBottom if fTop is greater than fBottom. Result may be empty, |
| 1606 | and width() and height() will be zero or positive. |
| 1607 | |
| 1608 | #Example |
| 1609 | SkIRect rect = { 30, 50, 20, 10 }; |
| 1610 | SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); |
| 1611 | rect.sort(); |
| 1612 | SkDebugf("sorted: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); |
| 1613 | #StdOut |
| 1614 | rect: 30, 50, 20, 10 |
| 1615 | sorted: 20, 10, 30, 50 |
| 1616 | ## |
| 1617 | ## |
| 1618 | |
| 1619 | #SeeAlso makeSorted SkRect::sort |
| 1620 | |
| 1621 | ## |
| 1622 | |
| 1623 | # ------------------------------------------------------------------------------ |
| 1624 | |
| 1625 | #Method SkIRect makeSorted() const |
| 1626 | |
| 1627 | Returns Rect with fLeft and fRight swapped if fLeft is greater than fRight; and |
| 1628 | with fTop and fBottom swapped if fTop is greater than fBottom. Result may be empty; |
| 1629 | and width() and height() will be zero or positive. |
| 1630 | |
| 1631 | #Return sorted IRect ## |
| 1632 | |
| 1633 | #Example |
| 1634 | SkIRect rect = { 30, 50, 20, 10 }; |
| 1635 | SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); |
| 1636 | SkIRect sort = rect.makeSorted(); |
| 1637 | SkDebugf("sorted: %d, %d, %d, %d\n", sort.fLeft, sort.fTop, sort.fRight, sort.fBottom); |
| 1638 | #StdOut |
| 1639 | rect: 30, 50, 20, 10 |
| 1640 | sorted: 20, 10, 30, 50 |
| 1641 | ## |
| 1642 | ## |
| 1643 | |
| 1644 | #SeeAlso sort SkRect::makeSorted |
| 1645 | |
| 1646 | ## |
| 1647 | |
| 1648 | # ------------------------------------------------------------------------------ |
| 1649 | |
| 1650 | #Method static const SkIRect& SK_WARN_UNUSED_RESULT EmptyIRect() |
| 1651 | |
| 1652 | Returns a reference to immutable empty IRect, set to (0, 0, 0, 0). |
| 1653 | |
| 1654 | #Return global IRect set to all zeroes ## |
| 1655 | |
| 1656 | #Example |
| 1657 | const SkIRect& rect = SkIRect::EmptyIRect(); |
| 1658 | SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); |
| 1659 | #StdOut |
| 1660 | rect: 0, 0, 0, 0 |
| 1661 | ## |
| 1662 | ## |
| 1663 | |
| 1664 | #SeeAlso MakeEmpty |
| 1665 | |
| 1666 | ## |
| 1667 | |
Cary Clark | 0c95aab | 2018-01-08 16:20:59 -0500 | [diff] [blame] | 1668 | #Method static SkIRect SK_WARN_UNUSED_RESULT MakeLargest() |
| 1669 | |
| 1670 | #Deprecated |
| 1671 | ## |
| 1672 | |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1673 | Returns constructed SkIRect setting left and top to most negative value, and |
| 1674 | setting right and bottom to most positive value. |
| 1675 | |
| 1676 | #Return bounds (SK_MinS32, SK_MinS32, SK_MaxS32, SK_MaxS32) ## |
| 1677 | |
Cary Clark | 0c95aab | 2018-01-08 16:20:59 -0500 | [diff] [blame] | 1678 | ## |
| 1679 | |
Cary Clark | 0c5f546 | 2017-12-15 11:21:51 -0500 | [diff] [blame] | 1680 | #Struct SkIRect ## |
| 1681 | |
| 1682 | #Topic IRect ## |