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