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