1#Topic IRect 2#Alias IRects ## 3#Alias IRect_Reference ## 4 5#Struct SkIRect 6 7#Code 8#Populate 9## 10 11SkIRect holds four 32-bit integer coordinates describing the upper and 12lower bounds of a rectangle. SkIRect may be created from outer bounds or 13from position, width, and height. SkIRect describes an area; if its right 14is less than or equal to its left, or if its bottom is less than or equal to 15its top, it is considered empty. 16 17#Member int32_t fLeft 18#Line # smaller x-axis bounds ## 19May contain any value. The smaller of the horizontal values when sorted. 20When equal to or greater than fRight, IRect is empty. 21## 22 23#Member int32_t fTop 24#Line # smaller y-axis bounds ## 25May contain any value. The smaller of the horizontal values when sorted. 26When equal to or greater than fBottom, IRect is empty. 27## 28 29#Member int32_t fRight 30#Line # larger x-axis bounds ## 31May contain any value. The larger of the vertical values when sorted. 32When equal to or less than fLeft, IRect is empty. 33## 34 35#Member int32_t fBottom 36#Line # larger y-axis bounds ## 37May contain any value. The larger of the vertical values when sorted. 38When equal to or less than fTop, IRect is empty. 39## 40 41# ------------------------------------------------------------------------------ 42 43#Method static constexpr SkIRect MakeEmpty() 44 45#In Constructors 46#Line # returns bounds of (0, 0, 0, 0) ## 47#Populate 48 49#Example 50 SkIRect rect = SkIRect::MakeEmpty(); 51 SkDebugf("MakeEmpty isEmpty: %s\n", rect.isEmpty() ? "true" : "false"); 52 rect.offset(10, 10); 53 SkDebugf("offset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false"); 54 rect.inset(10, 10); 55 SkDebugf("inset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false"); 56 rect.outset(20, 20); 57 SkDebugf("outset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false"); 58#StdOut 59MakeEmpty isEmpty: true 60offset rect isEmpty: true 61inset rect isEmpty: true 62outset rect isEmpty: false 63## 64## 65 66#SeeAlso EmptyIRect isEmpty setEmpty SkRect::MakeEmpty 67 68## 69 70# ------------------------------------------------------------------------------ 71 72#Method static constexpr SkIRect MakeWH(int32_t w, int32_t h) 73 74#In Constructors 75#Line # constructs from int input returning (0, 0, width, height) ## 76#Populate 77 78#Example 79 SkIRect rect1 = SkIRect::MakeWH(25, 35); 80 SkIRect rect2 = SkIRect::MakeSize({25, 35}); 81 SkIRect rect3 = SkIRect::MakeXYWH(0, 0, 25, 35); 82 SkIRect rect4 = SkIRect::MakeLTRB(0, 0, 25, 35); 83 SkDebugf("all %s" "equal\n", rect1 == rect2 && rect2 == rect3 && rect3 == rect4 ? 84 "" : "not "); 85#StdOut 86all equal 87## 88## 89 90#SeeAlso MakeSize MakeXYWH SkRect::MakeWH SkRect::MakeIWH 91 92## 93 94# ------------------------------------------------------------------------------ 95 96#Method static constexpr SkIRect MakeSize(const SkISize& size) 97 98#In Constructors 99#Line # constructs from ISize returning (0, 0, width, height) ## 100#Populate 101 102#Example 103 SkSize size = {25.5f, 35.5f}; 104 SkIRect rect = SkIRect::MakeSize(size.toRound()); 105 SkDebugf("round width: %d height: %d\n", rect.width(), rect.height()); 106 rect = SkIRect::MakeSize(size.toFloor()); 107 SkDebugf("floor width: %d height: %d\n", rect.width(), rect.height()); 108#StdOut 109round width: 26 height: 36 110floor width: 25 height: 35 111## 112## 113 114#SeeAlso MakeWH MakeXYWH SkRect::Make SkRect::MakeIWH 115 116## 117 118# ------------------------------------------------------------------------------ 119 120#Method static constexpr SkIRect MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b) 121 122#In Constructors 123#Line # constructs from int left, top, right, bottom ## 124#Populate 125 126#Example 127 SkIRect rect = SkIRect::MakeLTRB(5, 35, 15, 25); 128 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), 129 rect.bottom(), rect.isEmpty() ? "true" : "false"); 130 rect.sort(); 131 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), 132 rect.bottom(), rect.isEmpty() ? "true" : "false"); 133#StdOut 134rect: 5, 35, 15, 25 isEmpty: true 135rect: 5, 25, 15, 35 isEmpty: false 136## 137## 138 139#SeeAlso MakeXYWH SkRect::MakeLTRB 140 141## 142 143# ------------------------------------------------------------------------------ 144 145#Method static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h) 146 147#In Constructors 148#Line # constructs from int input returning (x, y, width, height) ## 149 150#Populate 151 152#Example 153 SkIRect rect = SkIRect::MakeXYWH(5, 35, -15, 25); 154 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), 155 rect.bottom(), rect.isEmpty() ? "true" : "false"); 156 rect.sort(); 157 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), 158 rect.bottom(), rect.isEmpty() ? "true" : "false"); 159#StdOut 160rect: 5, 35, -10, 60 isEmpty: true 161rect: -10, 35, 5, 60 isEmpty: false 162## 163## 164 165#SeeAlso MakeLTRB SkRect::MakeXYWH 166 167## 168 169#Subtopic Property 170#Line # member values, center, validity ## 171## 172 173# ------------------------------------------------------------------------------ 174 175#Method int32_t left() const 176 177#In Property 178#Line # returns smaller bounds in x, if sorted ## 179#Populate 180 181#Example 182 SkIRect unsorted = { 15, 5, 10, 25 }; 183 SkDebugf("unsorted.fLeft: %d unsorted.left(): %d\n", unsorted.fLeft, unsorted.left()); 184 SkIRect sorted = unsorted.makeSorted(); 185 SkDebugf("sorted.fLeft: %d sorted.left(): %d\n", sorted.fLeft, sorted.left()); 186#StdOut 187unsorted.fLeft: 15 unsorted.left(): 15 188sorted.fLeft: 10 sorted.left(): 10 189## 190## 191 192#SeeAlso fLeft x() SkRect::left() 193 194## 195 196# ------------------------------------------------------------------------------ 197 198#Method int32_t top() const 199 200#In Property 201#Line # returns smaller bounds in y, if sorted ## 202#Populate 203 204#Example 205 SkIRect unsorted = { 15, 25, 10, 5 }; 206 SkDebugf("unsorted.fTop: %d unsorted.top(): %d\n", unsorted.fTop, unsorted.top()); 207 SkIRect sorted = unsorted.makeSorted(); 208 SkDebugf("sorted.fTop: %d sorted.top(): %d\n", sorted.fTop, sorted.top()); 209#StdOut 210unsorted.fTop: 25 unsorted.top(): 25 211sorted.fTop: 5 sorted.top(): 5 212## 213## 214 215#SeeAlso fTop y() SkRect::top() 216 217## 218 219# ------------------------------------------------------------------------------ 220 221#Method int32_t right() const 222 223#In Property 224#Line # returns larger bounds in x, if sorted ## 225#Populate 226 227#Example 228 SkIRect unsorted = { 15, 25, 10, 5 }; 229 SkDebugf("unsorted.fRight: %d unsorted.right(): %d\n", unsorted.fRight, unsorted.right()); 230 SkIRect sorted = unsorted.makeSorted(); 231 SkDebugf("sorted.fRight: %d sorted.right(): %d\n", sorted.fRight, sorted.right()); 232#StdOut 233unsorted.fRight: 10 unsorted.right(): 10 234sorted.fRight: 15 sorted.right(): 15 235## 236## 237 238#SeeAlso fRight SkRect::right() 239 240## 241 242# ------------------------------------------------------------------------------ 243 244#Method int32_t bottom() const 245 246#In Property 247#Line # returns larger bounds in y, if sorted ## 248#Populate 249 250#Example 251 SkIRect unsorted = { 15, 25, 10, 5 }; 252 SkDebugf("unsorted.fBottom: %d unsorted.bottom(): %d\n", unsorted.fBottom, unsorted.bottom()); 253 SkIRect sorted = unsorted.makeSorted(); 254 SkDebugf("sorted.fBottom: %d sorted.bottom(): %d\n", sorted.fBottom, sorted.bottom()); 255#StdOut 256unsorted.fBottom: 5 unsorted.bottom(): 5 257sorted.fBottom: 25 sorted.bottom(): 25 258## 259## 260 261#SeeAlso fBottom SkRect::bottom() 262 263## 264 265# ------------------------------------------------------------------------------ 266 267#Method int32_t x() const 268 269#In Property 270#Line # returns bounds left ## 271#Populate 272 273#Example 274 SkIRect unsorted = { 15, 5, 10, 25 }; 275 SkDebugf("unsorted.fLeft: %d unsorted.x(): %d\n", unsorted.fLeft, unsorted.x()); 276 SkIRect sorted = unsorted.makeSorted(); 277 SkDebugf("sorted.fLeft: %d sorted.x(): %d\n", sorted.fLeft, sorted.x()); 278#StdOut 279unsorted.fLeft: 15 unsorted.x(): 15 280sorted.fLeft: 10 sorted.x(): 10 281## 282## 283 284#SeeAlso fLeft left() y() SkRect::x() 285 286## 287 288# ------------------------------------------------------------------------------ 289 290#Method int32_t y() const 291 292#In Property 293#Line # returns bounds top ## 294#Populate 295 296#Example 297 SkIRect unsorted = { 15, 25, 10, 5 }; 298 SkDebugf("unsorted.fTop: %d unsorted.y(): %d\n", unsorted.fTop, unsorted.y()); 299 SkIRect sorted = unsorted.makeSorted(); 300 SkDebugf("sorted.fTop: %d sorted.y(): %d\n", sorted.fTop, sorted.y()); 301#StdOut 302unsorted.fTop: 25 unsorted.y(): 25 303sorted.fTop: 5 sorted.y(): 5 304## 305## 306 307#SeeAlso fTop top() x() SkRect::y() 308 309## 310 311# ------------------------------------------------------------------------------ 312 313#Method int32_t width() const 314 315#In Property 316#Line # returns span in x ## 317#Populate 318 319#Example 320 SkIRect unsorted = { 15, 25, 10, 5 }; 321 SkDebugf("unsorted width: %d\n", unsorted.width()); 322 SkIRect large = { -2147483647, 1, 2147483644, 2 }; 323 SkDebugf("large width: %d\n", large.width()); 324#StdOut 325unsorted width: -5 326large width: -5 327## 328## 329 330#SeeAlso height() width64() height64() SkRect::width() 331 332## 333 334# ------------------------------------------------------------------------------ 335 336#Method int64_t width64() const 337 338#In Property 339#Line # returns span in y as int64_t ## 340#Populate 341 342#Example 343SkIRect large = { -2147483647, 1, 2147483644, 2 }; 344SkDebugf("width: %d width64: %lld\n", large.width(), large.width64()); 345#StdOut 346width: -5 width64: 4294967291 347## 348## 349 350#SeeAlso width() height() height64() SkRect::width() 351 352## 353 354# ------------------------------------------------------------------------------ 355 356#Method int32_t height() const 357 358#In Property 359#Line # returns span in y ## 360#Populate 361 362#Example 363 SkIRect unsorted = { 15, 25, 10, 20 }; 364 SkDebugf("unsorted height: %d\n", unsorted.height()); 365 SkIRect large = { 1, -2147483647, 2, 2147483644 }; 366 SkDebugf("large height: %d\n", large.height()); 367#StdOut 368unsorted height: -5 369large height: -5 370## 371## 372 373#SeeAlso width() SkRect::height() 374 375## 376 377# ------------------------------------------------------------------------------ 378 379#Method int64_t height64() const 380 381#In Property 382#Line # returns span in y as int64_t ## 383#Populate 384 385#Example 386SkIRect large = { 1, -2147483647, 2, 2147483644 }; 387SkDebugf("height: %d height64: %lld\n", large.height(), large.height64()); 388#StdOut 389height: -5 height64: 4294967291 390## 391## 392 393#SeeAlso width() height() width64() SkRect::height() 394 395## 396 397# ------------------------------------------------------------------------------ 398 399#Method SkISize size() const 400 401#In Property 402#Line # returns ISize (width, height) ## 403#Populate 404 405#Example 406 auto debugster = [](const char* prefix, const SkIRect& rect) -> void { 407 SkISize size = rect.size(); 408 SkDebugf("%s ", prefix); 409 SkDebugf("rect: %d, %d, %d, %d ", rect.left(), rect.top(), rect.right(), rect.bottom()); 410 SkDebugf("size: %d, %d\n", size.width(), size.height()); 411 }; 412 SkIRect rect = {20, 30, 40, 50}; 413 debugster("original", rect); 414 rect.offset(20, 20); 415 debugster(" offset", rect); 416 rect.outset(20, 20); 417 debugster(" outset", rect); 418#StdOut 419original rect: 20, 30, 40, 50 size: 20, 20 420 offset rect: 40, 50, 60, 70 size: 20, 20 421 outset rect: 20, 30, 80, 90 size: 60, 60 422## 423## 424 425#SeeAlso height() width() MakeSize 426 427## 428 429# ------------------------------------------------------------------------------ 430 431#Method bool isEmpty() const 432 433#In Property 434#Line # returns true if width or height are zero or negative or they exceed int32_t ## 435#Populate 436 437#Example 438 SkIRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}}; 439 for (auto rect : tests) { 440 SkDebugf("rect: {%d, %d, %d, %d} is" "%s empty\n", rect.left(), rect.top(), rect.right(), 441 rect.bottom(), rect.isEmpty() ? "" : " not"); 442 rect.sort(); 443 SkDebugf("sorted: {%d, %d, %d, %d} is" "%s empty\n", rect.left(), rect.top(), rect.right(), 444 rect.bottom(), rect.isEmpty() ? "" : " not"); 445 } 446#StdOut 447rect: {20, 40, 10, 50} is empty 448sorted: {10, 40, 20, 50} is not empty 449rect: {20, 40, 20, 50} is empty 450sorted: {20, 40, 20, 50} is empty 451## 452## 453 454#SeeAlso EmptyIRect MakeEmpty sort SkRect::isEmpty 455 456## 457 458# ------------------------------------------------------------------------------ 459 460#Method bool isEmpty64() const 461 462#In Property 463#Line # returns true if width or height are zero or negative ## 464#Populate 465 466#Example 467SkIRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}}; 468for (auto rect : tests) { 469 SkDebugf("rect: {%d, %d, %d, %d} is" "%s empty\n", rect.left(), rect.top(), rect.right(), 470 rect.bottom(), rect.isEmpty64() ? "" : " not"); 471 rect.sort(); 472 SkDebugf("sorted: {%d, %d, %d, %d} is" "%s empty\n", rect.left(), rect.top(), rect.right(), 473 rect.bottom(), rect.isEmpty64() ? "" : " not"); 474} 475#StdOut 476rect: {20, 40, 10, 50} is empty 477sorted: {10, 40, 20, 50} is not empty 478rect: {20, 40, 20, 50} is empty 479sorted: {20, 40, 20, 50} is empty 480## 481## 482 483#SeeAlso EmptyIRect MakeEmpty sort SkRect::isEmpty 484 485## 486 487#Subtopic Operators 488 489# ------------------------------------------------------------------------------ 490 491#Method bool operator==(const SkIRect& a, const SkIRect& b) 492 493#In Operators 494#Line # returns true if members are equal ## 495#Populate 496 497#Example 498 SkIRect test = {0, 0, 2, 2}; 499 SkIRect sorted = test.makeSorted(); 500 SkDebugf("test %c= sorted\n", test == sorted ? '=' : '!'); 501#StdOut 502test == sorted 503## 504## 505 506#SeeAlso operator!=(const SkIRect& a, const SkIRect& b) 507 508## 509 510# ------------------------------------------------------------------------------ 511 512#Method bool operator!=(const SkIRect& a, const SkIRect& b) 513 514#In Operators 515#Line # returns true if members are unequal ## 516#Populate 517 518#Example 519 SkIRect test = {2, 2, 0, 0}; 520 SkIRect sorted = test.makeSorted(); 521 SkDebugf("test %c= sorted\n", test != sorted ? '!' : '='); 522#StdOut 523test != sorted 524## 525## 526 527#SeeAlso operator==(const SkIRect& a, const SkIRect& b) 528 529## 530 531#Subtopic Operators ## 532 533# ------------------------------------------------------------------------------ 534 535#Subtopic Set 536#Line # replaces all values ## 537## 538 539#Method void setEmpty() 540 541#In Set 542#Line # sets to (0, 0, 0, 0) ## 543#Populate 544 545#Example 546 SkIRect rect = {3, 4, 1, 2}; 547 for (int i = 0; i < 2; ++i) { 548 SkDebugf("rect: {%d, %d, %d, %d} is %s" "empty\n", rect.fLeft, rect.fTop, 549 rect.fRight, rect.fBottom, rect.isEmpty() ? "" : "not "); 550 rect.setEmpty(); 551 } 552#StdOut 553rect: {3, 4, 1, 2} is empty 554rect: {0, 0, 0, 0} is empty 555## 556## 557 558#SeeAlso MakeEmpty SkRect::setEmpty 559 560## 561 562# ------------------------------------------------------------------------------ 563 564#Method void set(int32_t left, int32_t top, int32_t right, int32_t bottom) 565 566#In Set 567#Line # sets to (left, top, right, bottom) ## 568#Populate 569 570#Example 571 SkIRect rect1 = {3, 4, 1, 2}; 572 SkDebugf("rect1: {%d, %d, %d, %d}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom); 573 SkIRect rect2; 574 rect2.set(3, 4, 1, 2); 575 SkDebugf("rect2: {%d, %d, %d, %d}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom); 576#StdOut 577rect1: {3, 4, 1, 2} 578rect2: {3, 4, 1, 2} 579## 580## 581 582#SeeAlso setLTRB setXYWH SkRect::set 583 584## 585 586# ------------------------------------------------------------------------------ 587 588#Method void setLTRB(int32_t left, int32_t top, int32_t right, int32_t bottom) 589 590#In Set 591#Line # sets to SkScalar input (left, top, right, bottom) ## 592#Populate 593 594#Example 595 SkIRect rect1 = {3, 4, 1, 2}; 596 SkDebugf("rect1: {%d, %d, %d, %d}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom); 597 SkIRect rect2; 598 rect2.setLTRB(3, 4, 1, 2); 599 SkDebugf("rect2: {%d, %d, %d, %d}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom); 600#StdOut 601rect1: {3, 4, 1, 2} 602rect2: {3, 4, 1, 2} 603## 604## 605 606#SeeAlso set setXYWH SkRect::setLTRB 607 608## 609 610# ------------------------------------------------------------------------------ 611 612#Method void setXYWH(int32_t x, int32_t y, int32_t width, int32_t height) 613 614#In Set 615#Line # sets to (x, y, width, height) ## 616Sets IRect to: #Formula # (x, y, x + width, y + height) ##. 617Does not validate input; width or height may be negative. 618 619#Param x stored in fLeft ## 620#Param y stored in fTop ## 621#Param width added to x and stored in fRight ## 622#Param height added to y and stored in fBottom ## 623 624#Example 625 SkIRect rect; 626 rect.setXYWH(5, 35, -15, 25); 627 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), 628 rect.bottom(), rect.isEmpty() ? "true" : "false"); 629 rect.sort(); 630 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), 631 rect.bottom(), rect.isEmpty() ? "true" : "false"); 632#StdOut 633rect: 5, 35, -10, 60 isEmpty: true 634rect: -10, 35, 5, 60 isEmpty: false 635## 636## 637 638#SeeAlso MakeXYWH setLTRB set SkRect::setXYWH 639 640## 641 642#Subtopic Inset_Outset_Offset 643#Line # moves sides ## 644 645# ------------------------------------------------------------------------------ 646 647#Method SkIRect makeOffset(int32_t dx, int32_t dy) const 648 649#In Inset_Outset_Offset 650#Line # constructs from translated sides ## 651#Populate 652 653#Example 654 SkIRect rect = { 10, 50, 20, 60 }; 655 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), 656 rect.bottom(), rect.isEmpty() ? "true" : "false"); 657 rect = rect.makeOffset(15, 32); 658 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), 659 rect.bottom(), rect.isEmpty() ? "true" : "false"); 660#StdOut 661rect: 10, 50, 20, 60 isEmpty: false 662rect: 25, 82, 35, 92 isEmpty: false 663## 664## 665 666#SeeAlso offset() makeInset makeOutset SkRect::makeOffset 667 668## 669 670# ------------------------------------------------------------------------------ 671 672#Method SkIRect makeInset(int32_t dx, int32_t dy) const 673 674#In Inset_Outset_Offset 675#Line # constructs from sides moved symmetrically about the center ## 676#Populate 677 678#Example 679 SkIRect rect = { 10, 50, 20, 60 }; 680 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), 681 rect.bottom(), rect.isEmpty() ? "true" : "false"); 682 rect = rect.makeInset(15, 32); 683 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), 684 rect.bottom(), rect.isEmpty() ? "true" : "false"); 685#StdOut 686rect: 10, 50, 20, 60 isEmpty: false 687rect: 25, 82, 5, 28 isEmpty: true 688## 689## 690 691#SeeAlso inset() makeOffset makeOutset SkRect::makeInset 692 693## 694 695# ------------------------------------------------------------------------------ 696 697#Method SkIRect makeOutset(int32_t dx, int32_t dy) const 698 699#In Inset_Outset_Offset 700#Line # constructs from sides moved symmetrically about the center ## 701#Populate 702 703#Example 704 SkIRect rect = { 10, 50, 20, 60 }; 705 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), 706 rect.bottom(), rect.isEmpty() ? "true" : "false"); 707 rect = rect.makeOutset(15, 32); 708 SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), 709 rect.bottom(), rect.isEmpty() ? "true" : "false"); 710#StdOut 711rect: 10, 50, 20, 60 isEmpty: false 712rect: -5, 18, 35, 92 isEmpty: false 713## 714## 715 716#SeeAlso outset() makeOffset makeInset SkRect::makeOutset 717 718## 719 720# ------------------------------------------------------------------------------ 721 722#Method void offset(int32_t dx, int32_t dy) 723 724#In Inset_Outset_Offset 725#Line # translates sides without changing width and height ## 726#Populate 727 728#Example 729 SkIRect rect = { 10, 14, 50, 73 }; 730 rect.offset(5, 13); 731 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); 732#StdOut 733rect: 15, 27, 55, 86 734## 735## 736 737#SeeAlso offsetTo makeOffset SkRect::offset 738 739## 740 741# ------------------------------------------------------------------------------ 742 743#Method void offset(const SkIPoint& delta) 744 745#In Inset_Outset_Offset 746#Populate 747 748#Example 749 SkIRect rect = { 10, 14, 50, 73 }; 750 rect.offset({5, 13}); 751 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); 752#StdOut 753rect: 15, 27, 55, 86 754## 755## 756 757#SeeAlso offsetTo makeOffset SkRect::offset 758 759## 760 761# ------------------------------------------------------------------------------ 762 763#Method void offsetTo(int32_t newX, int32_t newY) 764 765#In Inset_Outset_Offset 766#Line # translates to (x, y) without changing width and height ## 767#Populate 768 769#Example 770 SkIRect rect = { 10, 14, 50, 73 }; 771 rect.offsetTo(15, 27); 772 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); 773#StdOut 774rect: 15, 27, 55, 86 775## 776## 777 778#SeeAlso offset makeOffset setXYWH SkRect::offsetTo 779 780## 781 782# ------------------------------------------------------------------------------ 783 784#Method void inset(int32_t dx, int32_t dy) 785 786#In Inset_Outset_Offset 787#Line # moves the sides symmetrically about the center ## 788#Populate 789 790#Example 791 SkIRect rect = { 10, 14, 50, 73 }; 792 rect.inset(5, 13); 793 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); 794#StdOut 795rect: 15, 27, 45, 60 796## 797## 798 799#SeeAlso outset makeInset SkRect::inset 800 801## 802 803# ------------------------------------------------------------------------------ 804 805#Method void outset(int32_t dx, int32_t dy) 806 807#In Inset_Outset_Offset 808#Line # moves the sides symmetrically about the center ## 809#Populate 810 811#Example 812 SkIRect rect = { 10, 14, 50, 73 }; 813 rect.outset(5, 13); 814 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); 815#StdOut 816rect: 5, 1, 55, 86 817## 818## 819 820#SeeAlso inset makeOutset SkRect::outset 821 822## 823 824#Subtopic Inset_Outset_Offset ## 825 826#Subtopic Intersection 827#Line # sets to shared bounds ## 828 829IRects intersect when they enclose a common area. To intersect, each of the pair 830must describe area; fLeft is less than fRight, and fTop is less than fBottom; 831SkIRect::isEmpty() returns false. The intersection of IRect pair can be described by: 832#Formula # (max(a.fLeft, b.fLeft), max(a.fTop, b.fTop), 833 min(a.fRight, b.fRight), min(a.fBottom, b.fBottom)) ##. 834 835The intersection is only meaningful if the resulting IRect is not empty and 836describes an area: fLeft is less than fRight, and fTop is less than fBottom. 837 838# ------------------------------------------------------------------------------ 839 840#Method void adjust(int32_t dL, int32_t dT, int32_t dR, int32_t dB) 841 842#In Inset_Outset_Offset 843#Line # moves the sides independently relative to their original locations ## 844#Populate 845 846#Example 847 SkIRect rect = { 8, 11, 19, 22 }; 848 rect.adjust(2, -1, 1, -2); 849 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); 850#StdOut 851rect: 10, 10, 20, 20 852## 853## 854 855#SeeAlso inset outset 856 857## 858 859# ------------------------------------------------------------------------------ 860 861#Method bool contains(int32_t x, int32_t y) const 862 863#In Intersection 864#Line # returns true if IPoint (x, y) is equal or inside ## 865Returns true if: #Formula # fLeft <= x < fRight && fTop <= y < fBottom ##. 866Returns false if IRect is empty. 867 868Considers input to describe constructed IRect: #Formula # (x, y, x + 1, y + 1) ## and 869returns true if constructed area is completely enclosed by IRect area. 870 871#Param x test IPoint x-coordinate ## 872#Param y test IPoint y-coordinate ## 873 874#Return true if (x, y) is inside IRect ## 875 876#Example 877 SkIRect rect = { 30, 50, 40, 60 }; 878 SkIPoint pts[] = { { 30, 50}, { 40, 50}, { 30, 60} }; 879 for (auto pt : pts) { 880 SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d)\n", 881 rect.left(), rect.top(), rect.right(), rect.bottom(), 882 rect.contains(pt.x(), pt.y()) ? "contains" : "does not contain", pt.x(), pt.y()); 883 } 884#StdOut 885rect: (30, 50, 40, 60) contains (30, 50) 886rect: (30, 50, 40, 60) does not contain (40, 50) 887rect: (30, 50, 40, 60) does not contain (30, 60) 888## 889## 890 891#SeeAlso containsNoEmptyCheck SkRect::contains 892 893## 894 895# ------------------------------------------------------------------------------ 896 897#Method bool contains(int32_t left, int32_t top, int32_t right, int32_t bottom) const 898 899#In Intersection 900#Populate 901 902#Example 903 SkIRect rect = { 30, 50, 40, 60 }; 904 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} }; 905 for (auto contained : tests) { 906 bool success = rect.contains( 907 contained.left(), contained.top(), contained.right(), contained.bottom()); 908 SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n", 909 rect.left(), rect.top(), rect.right(), rect.bottom(), 910 success ? "contains" : "does not contain", 911 contained.left(), contained.top(), contained.right(), contained.bottom()); 912 } 913#StdOut 914rect: (30, 50, 40, 60) contains (30, 50, 31, 51) 915rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50) 916rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60) 917## 918## 919 920#SeeAlso containsNoEmptyCheck SkRect::contains 921 922## 923 924# ------------------------------------------------------------------------------ 925 926#Method bool contains(const SkIRect& r) const 927 928#In Intersection 929#Populate 930 931#Example 932 SkIRect rect = { 30, 50, 40, 60 }; 933 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} }; 934 for (auto contained : tests) { 935 SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n", 936 rect.left(), rect.top(), rect.right(), rect.bottom(), 937 rect.contains(contained) ? "contains" : "does not contain", 938 contained.left(), contained.top(), contained.right(), contained.bottom()); 939 } 940#StdOut 941rect: (30, 50, 40, 60) contains (30, 50, 31, 51) 942rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50) 943rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60) 944## 945## 946 947#SeeAlso containsNoEmptyCheck SkRect::contains 948 949## 950 951# ------------------------------------------------------------------------------ 952 953#Method bool contains(const SkRect& r) const 954 955#In Intersection 956#Populate 957 958#Example 959 SkIRect rect = { 30, 50, 40, 60 }; 960 SkRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} }; 961 for (auto contained : tests) { 962 SkDebugf("rect: (%d, %d, %d, %d) %s (%g, %g, %g, %g)\n", 963 rect.left(), rect.top(), rect.right(), rect.bottom(), 964 rect.contains(contained) ? "contains" : "does not contain", 965 contained.left(), contained.top(), contained.right(), contained.bottom()); 966 } 967#StdOut 968rect: (30, 50, 40, 60) contains (30, 50, 31, 51) 969rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50) 970rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60) 971## 972## 973 974#SeeAlso containsNoEmptyCheck SkRect::contains 975 976## 977 978# ------------------------------------------------------------------------------ 979 980#Method bool containsNoEmptyCheck(int32_t left, int32_t top, 981 int32_t right, int32_t bottom) const 982#In Intersection 983#Line # returns true if contains unsorted IRect ## 984#Populate 985 986#Example 987 SkIRect rect = { 30, 50, 40, 60 }; 988 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} }; 989 for (auto contained : tests) { 990 bool success = rect.containsNoEmptyCheck( 991 contained.left(), contained.top(), contained.right(), contained.bottom()); 992 SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n", 993 rect.left(), rect.top(), rect.right(), rect.bottom(), 994 success ? "contains" : "does not contain", 995 contained.left(), contained.top(), contained.right(), contained.bottom()); 996 } 997#StdOut 998rect: (30, 50, 40, 60) contains (30, 50, 31, 51) 999rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50) 1000rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60) 1001## 1002## 1003 1004#SeeAlso contains SkRect::contains 1005 1006## 1007 1008# ------------------------------------------------------------------------------ 1009 1010#Method bool containsNoEmptyCheck(const SkIRect& r) const 1011 1012#In Intersection 1013#Populate 1014 1015#Example 1016 SkIRect rect = { 30, 50, 40, 60 }; 1017 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} }; 1018 for (auto contained : tests) { 1019 SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n", 1020 rect.left(), rect.top(), rect.right(), rect.bottom(), 1021 rect.containsNoEmptyCheck(contained) ? "contains" : "does not contain", 1022 contained.left(), contained.top(), contained.right(), contained.bottom()); 1023 } 1024#StdOut 1025rect: (30, 50, 40, 60) contains (30, 50, 31, 51) 1026rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50) 1027rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60) 1028## 1029## 1030 1031#SeeAlso contains SkRect::contains 1032 1033## 1034 1035# ------------------------------------------------------------------------------ 1036 1037#Method bool intersect(const SkIRect& r) 1038 1039#In Intersection 1040#Line # sets to shared area; returns true if not empty ## 1041#Populate 1042 1043#Example 1044#Description 1045Two SkDebugf calls are required. If the calls are combined, their arguments 1046may not be evaluated in left to right order: the printed intersection may 1047be before or after the call to intersect. 1048## 1049 SkIRect leftRect = { 10, 40, 50, 80 }; 1050 SkIRect rightRect = { 30, 60, 70, 90 }; 1051 SkDebugf("%s intersection: ", leftRect.intersect(rightRect) ? "" : "no "); 1052 SkDebugf("%d, %d, %d, %d\n", leftRect.left(), leftRect.top(), 1053 leftRect.right(), leftRect.bottom()); 1054#StdOut 1055 intersection: 30, 60, 50, 80 1056## 1057## 1058 1059#SeeAlso Intersects intersectNoEmptyCheck join SkRect::intersect 1060 1061## 1062 1063# ------------------------------------------------------------------------------ 1064 1065#Method bool intersect(const SkIRect& a, const SkIRect& b) 1066 1067#In Intersection 1068#Populate 1069 1070#Example 1071 SkIRect result; 1072 bool intersected = result.intersect({ 10, 40, 50, 80 }, { 30, 60, 70, 90 }); 1073 SkDebugf("%s intersection: %d, %d, %d, %d\n", intersected ? "" : "no ", 1074 result.left(), result.top(), result.right(), result.bottom()); 1075#StdOut 1076 intersection: 30, 60, 50, 80 1077## 1078## 1079 1080#SeeAlso Intersects intersectNoEmptyCheck join SkRect::intersect 1081 1082## 1083 1084# ------------------------------------------------------------------------------ 1085 1086#Method bool intersectNoEmptyCheck(const SkIRect& a, const SkIRect& b) 1087 1088#In Intersection 1089#Line # sets to shared area; returns true if not empty skips empty check ## 1090#Populate 1091 1092#Example 1093 SkIRect result; 1094 if (result.intersectNoEmptyCheck({ 10, 40, 50, 80 }, { 30, 60, 70, 90 })) { 1095 SkDebugf("intersection: %d, %d, %d, %d\n", 1096 result.left(), result.top(), result.right(), result.bottom()); 1097 } 1098#StdOut 1099 intersection: 30, 60, 50, 80 1100## 1101## 1102 1103#SeeAlso Intersects intersect join SkRect::intersect 1104 1105## 1106 1107# ------------------------------------------------------------------------------ 1108 1109#Method bool intersect(int32_t left, int32_t top, int32_t right, int32_t bottom) 1110 1111#In Intersection 1112#Populate 1113 1114#Example 1115#Description 1116Two SkDebugf calls are required. If the calls are combined, their arguments 1117may not be evaluated in left to right order: the printed intersection may 1118be before or after the call to intersect. 1119## 1120 SkIRect leftRect = { 10, 40, 50, 80 }; 1121 SkDebugf("%s intersection: ", leftRect.intersect(30, 60, 70, 90) ? "" : "no "); 1122 SkDebugf("%d, %d, %d, %d\n", leftRect.left(), leftRect.top(), 1123 leftRect.right(), leftRect.bottom()); 1124#StdOut 1125 intersection: 30, 60, 50, 80 1126## 1127## 1128 1129#SeeAlso intersectNoEmptyCheck Intersects join SkRect::intersect 1130 1131## 1132 1133# ------------------------------------------------------------------------------ 1134 1135#Method static bool Intersects(const SkIRect& a, const SkIRect& b) 1136 1137#In Intersection 1138#Line # returns true if areas overlap ## 1139#Populate 1140 1141#Example 1142 SkDebugf("%s intersection", SkIRect::Intersects({10, 40, 50, 80}, {30, 60, 70, 90}) ? "" : "no "); 1143#StdOut 1144 intersection 1145## 1146## 1147 1148#SeeAlso IntersectsNoEmptyCheck intersect SkRect::intersect 1149 1150## 1151 1152# ------------------------------------------------------------------------------ 1153 1154#Method static bool IntersectsNoEmptyCheck(const SkIRect& a, const SkIRect& b) 1155 1156#In Intersection 1157#Line # returns true if areas overlap skips empty check ## 1158#Populate 1159 1160#Example 1161 SkDebugf("%s intersection", SkIRect::IntersectsNoEmptyCheck( 1162 {10, 40, 50, 80}, {30, 60, 70, 90}) ? "" : "no "); 1163#StdOut 1164 intersection 1165## 1166## 1167 1168#SeeAlso Intersects intersect SkRect::intersect 1169 1170## 1171 1172#Subtopic Intersection ## 1173 1174# ------------------------------------------------------------------------------ 1175 1176#Subtopic Join 1177#Line # sets to union of bounds ## 1178## 1179 1180#Method void join(int32_t left, int32_t top, int32_t right, int32_t bottom) 1181 1182#In Join 1183#Line # sets to union of bounds ## 1184#Populate 1185 1186#Example 1187 SkIRect rect = { 10, 20, 15, 25}; 1188 rect.join(50, 60, 55, 65); 1189 SkDebugf("join: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); 1190#StdOut 1191 join: 10, 20, 55, 65 1192## 1193## 1194 1195#SeeAlso set SkRect::join 1196 1197## 1198 1199# ------------------------------------------------------------------------------ 1200 1201#Method void join(const SkIRect& r) 1202 1203#In Join 1204#Populate 1205 1206#Example 1207 SkIRect rect = { 10, 20, 15, 25}; 1208 rect.join({50, 60, 55, 65}); 1209 SkDebugf("join: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); 1210#StdOut 1211 join: 10, 20, 55, 65 1212## 1213## 1214 1215#SeeAlso set SkRect::join 1216 1217## 1218 1219# ------------------------------------------------------------------------------ 1220 1221#Subtopic Sorting 1222#Line # orders sides ## 1223## 1224 1225#Method void sort() 1226 1227#In Sorting 1228#Line # orders sides from smaller to larger ## 1229#Populate 1230 1231#Example 1232 SkIRect rect = { 30, 50, 20, 10 }; 1233 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); 1234 rect.sort(); 1235 SkDebugf("sorted: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); 1236#StdOut 1237rect: 30, 50, 20, 10 1238sorted: 20, 10, 30, 50 1239## 1240## 1241 1242#SeeAlso makeSorted SkRect::sort 1243 1244## 1245 1246# ------------------------------------------------------------------------------ 1247 1248#Method SkIRect makeSorted() const 1249 1250#In Sorting 1251#In Constructors 1252#Line # constructs IRect, ordering sides from smaller to larger ## 1253#Populate 1254 1255#Example 1256 SkIRect rect = { 30, 50, 20, 10 }; 1257 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); 1258 SkIRect sort = rect.makeSorted(); 1259 SkDebugf("sorted: %d, %d, %d, %d\n", sort.fLeft, sort.fTop, sort.fRight, sort.fBottom); 1260#StdOut 1261rect: 30, 50, 20, 10 1262sorted: 20, 10, 30, 50 1263## 1264## 1265 1266#SeeAlso sort SkRect::makeSorted 1267 1268## 1269 1270# ------------------------------------------------------------------------------ 1271 1272#Method static const SkIRect& EmptyIRect() 1273 1274#In Constructors 1275#Line # returns immutable bounds of (0, 0, 0, 0) ## 1276#Populate 1277 1278#Example 1279 const SkIRect& rect = SkIRect::EmptyIRect(); 1280 SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); 1281#StdOut 1282rect: 0, 0, 0, 0 1283## 1284## 1285 1286#SeeAlso MakeEmpty 1287 1288## 1289 1290#Struct SkIRect ## 1291 1292#Topic IRect ## 1293