SkRect_Reference.bmh revision 78c110e2f0faefeecc8c8c19f6dcb00e738bffc7
1#Topic Rect 2#Alias Rects 3#Alias Rect_Reference 4 5#Subtopic Overview 6 #Subtopic Subtopic 7 #Populate 8 ## 9## 10 11#Struct SkRect 12 13SkRect holds four SkScalar coordinates describing the upper and 14lower bounds of a rectangle. SkRect may be created from outer bounds or 15from position, width, and height. SkRect describes an area; if its right 16is less than or equal to its left, or if its bottom is less than or equal to 17its top, it is considered empty. 18 19# move to topic about MakeIWH and friends 20SkRect can be constructed from int values to avoid compiler warnings that 21integer input cannot convert to SkScalar without loss of precision. 22 23#Subtopic Related_Function 24#Populate 25#Subtopic ## 26 27#Subtopic Member_Function 28#Populate 29## 30 31#Subtopic Member 32#Populate 33 34#Member SkScalar fLeft 35#Line # smaller x-axis bounds ## 36May contain any value, including infinities and NaN. The smaller of the 37horizontal values when sorted. When equal to or greater than fRight, Rect is empty. 38## 39 40#Member SkScalar fTop 41#Line # smaller y-axis bounds ## 42May contain any value, including infinities and NaN. The smaller of the 43vertical values when sorted. When equal to or greater than fBottom, Rect is empty. 44## 45 46#Member SkScalar fRight 47#Line # larger x-axis bounds ## 48May contain any value, including infinities and NaN. The larger of the 49horizontal values when sorted. When equal to or less than fLeft, Rect is empty. 50## 51 52#Member SkScalar fBottom 53#Line # larger y-axis bounds ## 54May contain any value, including infinities and NaN. The larger of the 55vertical values when sorted. When equal to or less than fTop, Rect is empty. 56## 57 58#Subtopic Member ## 59 60#Subtopic Constructor 61#Populate 62 63# ------------------------------------------------------------------------------ 64 65#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeEmpty() 66 67#In Constructor 68#Line # constructs from bounds of (0, 0, 0, 0) ## 69Returns constructed Rect set to (0, 0, 0, 0). 70Many other rectangles are empty; if left is equal to or greater than right, 71or if top is equal to or greater than bottom. Setting all members to zero 72is a convenience, but does not designate a special empty rectangle. 73 74#Return bounds (0, 0, 0, 0) ## 75 76#Example 77 SkRect rect = SkRect::MakeEmpty(); 78 SkDebugf("MakeEmpty isEmpty: %s\n", rect.isEmpty() ? "true" : "false"); 79 rect.offset(10, 10); 80 SkDebugf("offset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false"); 81 rect.inset(10, 10); 82 SkDebugf("inset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false"); 83 rect.outset(20, 20); 84 SkDebugf("outset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false"); 85#StdOut 86MakeEmpty isEmpty: true 87offset rect isEmpty: true 88inset rect isEmpty: true 89outset rect isEmpty: false 90## 91## 92 93#SeeAlso isEmpty setEmpty SkIRect::MakeEmpty 94 95## 96 97# ------------------------------------------------------------------------------ 98 99#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeWH(SkScalar w, SkScalar h) 100 101#In Constructor 102#Line # constructs from SkScalar input returning (0, 0, width, height) ## 103Returns constructed Rect set to SkScalar values (0, 0, w, h). Does not 104validate input; w or h may be negative. 105 106Passing integer values may generate a compiler warning since Rect cannot 107represent 32-bit integers exactly. Use SkIRect for an exact integer rectangle. 108 109#Param w SkScalar width of constructed Rect ## 110#Param h SkScalar height of constructed Rect ## 111 112#Return bounds (0, 0, w, h) ## 113 114#Example 115 SkRect rect1 = SkRect::MakeWH(25, 35); 116 SkRect rect2 = SkRect::MakeIWH(25, 35); 117 SkRect rect3 = SkRect::MakeXYWH(0, 0, 25, 35); 118 SkRect rect4 = SkRect::MakeLTRB(0, 0, 25, 35); 119 SkDebugf("all %s" "equal\n", rect1 == rect2 && rect2 == rect3 && rect3 == rect4 ? 120 "" : "not "); 121#StdOut 122all equal 123## 124## 125 126#SeeAlso MakeSize MakeXYWH MakeIWH setWH SkIRect::MakeWH 127 128## 129 130# ------------------------------------------------------------------------------ 131 132#Method static SkRect SK_WARN_UNUSED_RESULT MakeIWH(int w, int h) 133 134#In Constructor 135#Line # constructs from int input returning (0, 0, width, height) ## 136Returns constructed Rect set to integer values (0, 0, w, h). Does not validate 137input; w or h may be negative. 138 139Use to avoid a compiler warning that input may lose precision when stored. 140Use SkIRect for an exact integer rectangle. 141 142#Param w integer width of constructed Rect ## 143#Param h integer height of constructed Rect ## 144 145#Return bounds (0, 0, w, h) ## 146 147#Example 148 SkIRect i_rect = SkIRect::MakeWH(25, 35); 149 SkRect f_rect = SkRect::MakeIWH(25, 35); 150 SkDebugf("i_rect width: %d f_rect width:%g\n", i_rect.width(), f_rect.width()); 151 i_rect = SkIRect::MakeWH(125000111, 0); 152 f_rect = SkRect::MakeIWH(125000111, 0); 153 SkDebugf("i_rect width: %d f_rect width:%.0f\n", i_rect.width(), f_rect.width()); 154#StdOut 155i_rect width: 25 f_rect width:25 156i_rect width: 125000111 f_rect width:125000112 157## 158## 159 160#SeeAlso MakeXYWH MakeWH isetWH SkIRect::MakeWH 161 162## 163 164# ------------------------------------------------------------------------------ 165 166#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeSize(const SkSize& size) 167 168#In Constructor 169#Line # constructs from Size returning (0, 0, width, height) ## 170Returns constructed Rect set to (0, 0, size.width(), size.height()). Does not 171validate input; size.width() or size.height() may be negative. 172 173#Param size SkScalar values for Rect width and height ## 174 175#Return bounds (0, 0, size.width(), size.height()) ## 176 177#Example 178 SkSize size = {25.5f, 35.5f}; 179 SkRect rect = SkRect::MakeSize(size); 180 SkDebugf("rect width: %g height: %g\n", rect.width(), rect.height()); 181 SkISize floor = size.toFloor(); 182 rect = SkRect::MakeSize(SkSize::Make(floor)); 183 SkDebugf("floor width: %g height: %g\n", rect.width(), rect.height()); 184#StdOut 185rect width: 25.5 height: 35.5 186floor width: 25 height: 35 187## 188## 189 190#SeeAlso MakeWH MakeXYWH MakeIWH setWH SkIRect::MakeWH 191 192## 193 194# ------------------------------------------------------------------------------ 195 196#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeLTRB(SkScalar l, SkScalar t, SkScalar r, 197 SkScalar b) 198#In Constructor 199#Line # constructs from SkScalar left, top, right, bottom ## 200 201Returns constructed Rect set to (l, t, r, b). Does not sort input; Rect may 202result in fLeft greater than fRight, or fTop greater than fBottom. 203 204#Param l SkScalar stored in fLeft ## 205#Param t SkScalar stored in fTop ## 206#Param r SkScalar stored in fRight ## 207#Param b SkScalar stored in fBottom ## 208 209#Return bounds (l, t, r, b) ## 210 211#Example 212 SkRect rect = SkRect::MakeLTRB(5, 35, 15, 25); 213 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(), 214 rect.bottom(), rect.isEmpty() ? "true" : "false"); 215 rect.sort(); 216 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(), 217 rect.bottom(), rect.isEmpty() ? "true" : "false"); 218#StdOut 219rect: 5, 35, 15, 25 isEmpty: true 220rect: 5, 25, 15, 35 isEmpty: false 221## 222## 223 224#SeeAlso MakeXYWH SkIRect::MakeLTRB 225 226## 227 228# ------------------------------------------------------------------------------ 229 230#Method static constexpr SkRect SK_WARN_UNUSED_RESULT MakeXYWH(SkScalar x, SkScalar y, SkScalar w, SkScalar h) 231 232#In Constructor 233#Line # constructs from SkScalar input returning (x, y, width, height) ## 234Returns constructed Rect set to 235#Formula 236(x, y, x + w, y + h) 237## 238. Does not validate input; 239w or h may be negative. 240 241#Param x stored in fLeft ## 242#Param y stored in fTop ## 243#Param w added to x and stored in fRight ## 244#Param h added to y and stored in fBottom ## 245 246#Return bounds at (x, y) with width w and height h ## 247 248#Example 249 SkRect rect = SkRect::MakeXYWH(5, 35, -15, 25); 250 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(), 251 rect.bottom(), rect.isEmpty() ? "true" : "false"); 252 rect.sort(); 253 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(), 254 rect.bottom(), rect.isEmpty() ? "true" : "false"); 255#StdOut 256rect: 5, 35, -10, 60 isEmpty: true 257rect: -10, 35, 5, 60 isEmpty: false 258## 259## 260 261#SeeAlso MakeLTRB SkIRect::MakeXYWH 262 263## 264 265# ------------------------------------------------------------------------------ 266 267#Method static SkRect SK_WARN_UNUSED_RESULT MakeFromIRect(const SkIRect& irect) 268#Deprecated 269## 270 271# ------------------------------------------------------------------------------ 272 273#Method static SkRect Make(const SkISize& size) 274 275#In Constructor 276#Line # constructs from ISize returning (0, 0, width, height) ## 277Returns constructed IRect set to (0, 0, size.width(), size.height()). 278Does not validate input; size.width() or size.height() may be negative. 279 280#Param size integer values for Rect width and height ## 281 282#Return bounds (0, 0, size.width(), size.height()) ## 283 284#Example 285 SkRect rect1 = SkRect::MakeSize({2, 35}); 286 SkRect rect2 = SkRect::MakeIWH(2, 35); 287 SkDebugf("rect1 %c= rect2\n", rect1 == rect2 ? '=' : '!'); 288#StdOut 289rect1 == rect2 290## 291## 292 293#SeeAlso MakeWH MakeXYWH SkRect::MakeIWH SkIRect::MakeSize 294 295## 296 297# ------------------------------------------------------------------------------ 298 299#Method static SkRect SK_WARN_UNUSED_RESULT Make(const SkIRect& irect) 300 301#In Constructor 302Returns constructed IRect set to irect, promoting integers to Scalar. 303Does not validate input; fLeft may be greater than fRight, fTop may be greater 304than fBottom. 305 306#Param irect integer unsorted bounds ## 307 308#Return irect members converted to SkScalar ## 309 310#Example 311 SkIRect i_rect1 = {2, 35, 22, 53}; 312 SkRect f_rect = SkRect::Make(i_rect1); 313 f_rect.offset(0.49f, 0.49f); 314 SkIRect i_rect2; 315 f_rect.round(&i_rect2); 316 SkDebugf("i_rect1 %c= i_rect2\n", i_rect1 == i_rect2? '=' : '!'); 317## 318 319#SeeAlso MakeLTRB 320 321## 322 323#Subtopic Constructor ## 324 325#Subtopic Property 326#Line # member values, center, validity ## 327#Populate 328 329# ------------------------------------------------------------------------------ 330 331#Method bool isEmpty() const 332 333#In Property 334#Line # returns true if width or height are zero or negative ## 335Returns true if fLeft is equal to or greater than fRight, or if fTop is equal 336to or greater than fBottom. Call sort() to reverse rectangles with negative 337width() or height(). 338 339#Return true if width() or height() are zero or negative ## 340 341#Example 342 SkRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}}; 343 for (auto rect : tests) { 344 SkDebugf("rect: {%g, %g, %g, %g} is" "%s empty\n", rect.left(), rect.top(), rect.right(), 345 rect.bottom(), rect.isEmpty() ? "" : " not"); 346 rect.sort(); 347 SkDebugf("sorted: {%g, %g, %g, %g} is" "%s empty\n", rect.left(), rect.top(), rect.right(), 348 rect.bottom(), rect.isEmpty() ? "" : " not"); 349 } 350#StdOut 351rect: {20, 40, 10, 50} is empty 352sorted: {10, 40, 20, 50} is not empty 353rect: {20, 40, 20, 50} is empty 354sorted: {20, 40, 20, 50} is empty 355## 356## 357 358#SeeAlso MakeEmpty sort SkIRect::isEmpty 359 360## 361 362# ------------------------------------------------------------------------------ 363 364#Method bool isSorted() const 365 366#In Property 367#Line # returns true if width or height are zero or positive ## 368Returns true if fLeft is equal to or less than fRight, or if fTop is equal 369to or less than fBottom. Call sort() to reverse rectangles with negative 370width() or height(). 371 372#Return true if width() or height() are zero or positive ## 373 374#Example 375 SkRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}}; 376 for (auto rect : tests) { 377 SkDebugf("rect: {%g, %g, %g, %g} is" "%s sorted\n", rect.left(), rect.top(), rect.right(), 378 rect.bottom(), rect.isSorted() ? "" : " not"); 379 rect.sort(); 380 SkDebugf("sorted: {%g, %g, %g, %g} is" "%s sorted\n", rect.left(), rect.top(), rect.right(), 381 rect.bottom(), rect.isSorted() ? "" : " not"); 382 } 383#StdOut 384rect: {20, 40, 10, 50} is not sorted 385sorted: {10, 40, 20, 50} is sorted 386rect: {20, 40, 20, 50} is sorted 387sorted: {20, 40, 20, 50} is sorted 388## 389## 390 391#SeeAlso sort makeSorted isEmpty 392 393## 394 395# ------------------------------------------------------------------------------ 396 397#Method bool isFinite() const 398 399#In Property 400#Line # returns true if no member is infinite or NaN ## 401Returns true if all values in the rectangle are finite: SK_ScalarMin or larger, 402and SK_ScalarMax or smaller. 403 404#Return true if no member is infinite or NaN ## 405 406#Example 407SkRect largest = { SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax }; 408 SkDebugf("largest is finite: %s\n", largest.isFinite() ? "true" : "false"); 409 SkDebugf("large width %g\n", largest.width()); 410 SkRect widest = SkRect::MakeWH(largest.width(), largest.height()); 411 SkDebugf("widest is finite: %s\n", widest.isFinite() ? "true" : "false"); 412#StdOut 413largest is finite: true 414large width inf 415widest is finite: false 416## 417## 418 419#SeeAlso SkScalarIsFinite SkScalarIsNaN 420 421## 422 423# ------------------------------------------------------------------------------ 424 425#Method SkScalar x() const 426 427#In Property 428#Line # returns bounds left ## 429Returns left edge of Rect, if sorted. Call isSorted to see if Rect is valid. 430Call sort() to reverse fLeft and fRight if needed. 431 432#Return fLeft ## 433 434#Example 435 SkRect unsorted = { 15, 5, 10, 25 }; 436 SkDebugf("unsorted.fLeft: %g unsorted.x(): %g\n", unsorted.fLeft, unsorted.x()); 437 SkRect sorted = unsorted.makeSorted(); 438 SkDebugf("sorted.fLeft: %g sorted.x(): %g\n", sorted.fLeft, sorted.x()); 439#StdOut 440unsorted.fLeft: 15 unsorted.x(): 15 441sorted.fLeft: 10 sorted.x(): 10 442## 443## 444 445#SeeAlso fLeft left() y() SkIRect::x() 446 447## 448 449# ------------------------------------------------------------------------------ 450 451#Method SkScalar y() const 452 453#In Property 454#Line # returns bounds top ## 455Returns top edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid, 456and sort() to reverse fTop and fBottom if needed. 457 458#Return fTop ## 459 460#Example 461 SkRect unsorted = { 15, 25, 10, 5 }; 462 SkDebugf("unsorted.fTop: %g unsorted.y(): %g\n", unsorted.fTop, unsorted.y()); 463 SkRect sorted = unsorted.makeSorted(); 464 SkDebugf("sorted.fTop: %g sorted.y(): %g\n", sorted.fTop, sorted.y()); 465#StdOut 466unsorted.fTop: 25 unsorted.y(): 25 467sorted.fTop: 5 sorted.y(): 5 468## 469## 470 471#SeeAlso fTop top() x() SkIRect::y() 472 473## 474 475# ------------------------------------------------------------------------------ 476 477#Method SkScalar left() const 478 479#In Property 480#Line # returns smaller bounds in x, if sorted ## 481Returns left edge of Rect, if sorted. Call isSorted to see if Rect is valid. 482Call sort() to reverse fLeft and fRight if needed. 483 484#Return fLeft ## 485 486#Example 487 SkRect unsorted = { 15, 5, 10, 25 }; 488 SkDebugf("unsorted.fLeft: %g unsorted.left(): %g\n", unsorted.fLeft, unsorted.left()); 489 SkRect sorted = unsorted.makeSorted(); 490 SkDebugf("sorted.fLeft: %g sorted.left(): %g\n", sorted.fLeft, sorted.left()); 491#StdOut 492unsorted.fLeft: 15 unsorted.left(): 15 493sorted.fLeft: 10 sorted.left(): 10 494## 495## 496 497#SeeAlso fLeft x() SkIRect::left() 498 499## 500 501# ------------------------------------------------------------------------------ 502 503#Method SkScalar top() const 504 505#In Property 506#Line # returns smaller bounds in y, if sorted ## 507Returns top edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid, 508and sort() to reverse fTop and fBottom if needed. 509 510#Return fTop ## 511 512#Example 513 SkRect unsorted = { 15, 25, 10, 5 }; 514 SkDebugf("unsorted.fTop: %g unsorted.top(): %g\n", unsorted.fTop, unsorted.top()); 515 SkRect sorted = unsorted.makeSorted(); 516 SkDebugf("sorted.fTop: %g sorted.top(): %g\n", sorted.fTop, sorted.top()); 517#StdOut 518unsorted.fTop: 25 unsorted.top(): 25 519sorted.fTop: 5 sorted.top(): 5 520## 521## 522 523#SeeAlso fTop y() SkIRect::top() 524 525## 526 527# ------------------------------------------------------------------------------ 528 529#Method SkScalar right() const 530 531#In Property 532#Line # returns larger bounds in x, if sorted ## 533Returns right edge of Rect, if sorted. Call isSorted to see if Rect is valid. 534Call sort() to reverse fLeft and fRight if needed. 535 536#Return fRight ## 537 538#Example 539 SkRect unsorted = { 15, 25, 10, 5 }; 540 SkDebugf("unsorted.fRight: %g unsorted.right(): %g\n", unsorted.fRight, unsorted.right()); 541 SkRect sorted = unsorted.makeSorted(); 542 SkDebugf("sorted.fRight: %g sorted.right(): %g\n", sorted.fRight, sorted.right()); 543#StdOut 544unsorted.fRight: 10 unsorted.right(): 10 545sorted.fRight: 15 sorted.right(): 15 546## 547## 548 549#SeeAlso fRight SkIRect::right() 550 551## 552 553# ------------------------------------------------------------------------------ 554 555#Method SkScalar bottom() const 556 557#In Property 558#Line # returns larger bounds in y, if sorted ## 559Returns bottom edge of Rect, if sorted. Call isEmpty to see if Rect may be invalid, 560and sort() to reverse fTop and fBottom if needed. 561 562#Return fBottom ## 563 564#Example 565 SkRect unsorted = { 15, 25, 10, 5 }; 566 SkDebugf("unsorted.fBottom: %g unsorted.bottom(): %g\n", unsorted.fBottom, unsorted.bottom()); 567 SkRect sorted = unsorted.makeSorted(); 568 SkDebugf("sorted.fBottom: %g sorted.bottom(): %g\n", sorted.fBottom, sorted.bottom()); 569#StdOut 570unsorted.fBottom: 5 unsorted.bottom(): 5 571sorted.fBottom: 25 sorted.bottom(): 25 572## 573## 574 575#SeeAlso fBottom SkIRect::bottom() 576 577## 578 579# ------------------------------------------------------------------------------ 580 581#Method SkScalar width() const 582 583#In Property 584#Line # returns span in x ## 585Returns span on the x-axis. This does not check if Rect is sorted, or if 586result fits in 32-bit float; result may be negative or infinity. 587 588#Return fRight minus fLeft ## 589 590#Example 591#Description 592Compare with SkIRect::width() example. 593## 594 SkRect unsorted = { 15, 25, 10, 5 }; 595 SkDebugf("unsorted width: %g\n", unsorted.width()); 596 SkRect large = { -2147483647.f, 1, 2147483644.f, 2 }; 597 SkDebugf("large width: %.0f\n", large.width()); 598#StdOut 599unsorted width: -5 600large width: 4294967296 601## 602## 603 604#SeeAlso height() SkIRect::width() 605 606## 607 608# ------------------------------------------------------------------------------ 609 610#Method SkScalar height() const 611 612#In Property 613#Line # returns span in y ## 614Returns span on the y-axis. This does not check if IRect is sorted, or if 615result fits in 32-bit float; result may be negative or infinity. 616 617#Return fBottom minus fTop ## 618 619#Example 620#Description 621Compare with SkIRect::height() example. 622## 623 SkRect unsorted = { 15, 25, 10, 20 }; 624 SkDebugf("unsorted height: %g\n", unsorted.height()); 625 SkRect large = { 1, -2147483647.f, 2, 2147483644.f }; 626 SkDebugf("large height: %.0f\n", large.height()); 627#StdOut 628unsorted height: -5 629large height: 4294967296 630## 631## 632 633#SeeAlso width() SkIRect::height() 634 635## 636 637# ------------------------------------------------------------------------------ 638 639#Method SkScalar centerX() const 640 641#In Property 642#Line # returns midpoint in x ## 643Returns average of left edge and right edge. Result does not change if Rect 644is sorted. Result may overflow to infinity if Rect is far from the origin. 645 646#Return midpoint in x ## 647 648#Example 649 SkRect tests[] = {{20, 30, 41, 51}, {-20, -30, -41, -51}}; 650 for (auto rect : tests) { 651 SkDebugf("left: %3g right: %3g centerX: %3g\n", rect.left(), rect.right(), rect.centerX()); 652 rect.sort(); 653 SkDebugf("left: %3g right: %3g centerX: %3g\n", rect.left(), rect.right(), rect.centerX()); 654 } 655#StdOut 656left: 20 right: 41 centerX: 30.5 657left: 20 right: 41 centerX: 30.5 658left: -20 right: -41 centerX: -30.5 659left: -41 right: -20 centerX: -30.5 660## 661## 662 663#SeeAlso centerY SkIRect::centerX 664 665## 666 667# ------------------------------------------------------------------------------ 668 669#Method SkScalar centerY() const 670 671#In Property 672#Line # returns midpoint in y ## 673Returns average of top edge and bottom edge. Result does not change if Rect 674is sorted. Result may overflow to infinity if Rect is far from the origin. 675 676#Return midpoint in y ## 677 678#Example 679 SkRect rect = { 2e+38, 2e+38, 3e+38, 3e+38 }; 680 SkDebugf("left: %g right: %g centerX: %g ", rect.left(), rect.right(), rect.centerX()); 681 SkDebugf("safe mid x: %g\n", rect.left() / 2 + rect.right() / 2); 682#StdOut 683left: 2e+38 right: 3e+38 centerX: inf safe mid x: 2.5e+38 684## 685## 686 687#SeeAlso centerX SkIRect::centerY 688 689## 690 691#Subtopic Property ## 692 693#Subtopic Operator 694 695#Populate 696 697# ------------------------------------------------------------------------------ 698 699#Method bool operator==(const SkRect& a, const SkRect& b) 700 701#In Operator 702#Line # returns true if members are equal ## 703Returns true if all members in a: fLeft, fTop, fRight, and fBottom; are 704equal to the corresponding members in b. 705 706a and b are not equal if either contain NaN. a and b are equal if members 707contain zeroes width different signs. 708 709#Param a Rect to compare ## 710#Param b Rect to compare ## 711 712#Return true if members are equal ## 713 714#Example 715 auto debugster = [](const SkRect& test) -> void { 716 SkRect negZero = {-0.0f, -0.0f, 2, 2}; 717 SkDebugf("{%g, %g, %g, %g} %c= {%g, %g, %g, %g} %s numerically equal\n", 718 test.fLeft, test.fTop, test.fRight, test.fBottom, 719 negZero.fLeft, negZero.fTop, negZero.fRight, negZero.fBottom, 720 test == negZero ? '=' : '!', 721 test.fLeft == negZero.fLeft && test.fTop == negZero.fTop && 722 test.fRight == negZero.fRight && test.fBottom == negZero.fBottom ? 723 "and are" : "yet are not"); 724 }; 725 SkRect tests[] = {{0, 0, 2, 2}, {-0, -0, 2, 2}, {0.0f, 0.0f, 2, 2}}; 726 SkDebugf("tests are %s" "equal\n", tests[0] == tests[1] && tests[1] == tests[2] ? "" : "not "); 727 for (auto rect : tests) { 728 debugster(rect); 729 } 730#StdOut 731tests are equal 732{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal 733{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal 734{0, 0, 2, 2} == {-0, -0, 2, 2} and are numerically equal 735## 736## 737 738#SeeAlso operator!=(const SkRect& a, const SkRect& b) 739 740## 741 742# ------------------------------------------------------------------------------ 743 744#Method bool operator!=(const SkRect& a, const SkRect& b) 745 746#In Operator 747#Line # returns true if members are unequal ## 748Returns true if any in a: fLeft, fTop, fRight, and fBottom; does not 749equal the corresponding members in b. 750 751a and b are not equal if either contain NaN. a and b are equal if members 752contain zeroes width different signs. 753 754#Param a Rect to compare ## 755#Param b Rect to compare ## 756 757#Return true if members are not equal ## 758 759#Example 760 SkRect test = {0, 0, 2, SK_ScalarNaN}; 761 SkDebugf("test with NaN is %s" "equal to itself\n", test == test ? "" : "not "); 762#StdOut 763test with NaN is not equal to itself 764## 765## 766 767#SeeAlso operator==(const SkRect& a, const SkRect& b) 768 769## 770 771#Subtopic Operator ## 772 773#Subtopic As_Points 774#Line # conversion to and from Points ## 775 776#Populate 777 778# ------------------------------------------------------------------------------ 779 780#Method void toQuad(SkPoint quad[4]) const 781 782#In As_Points 783#Line # returns four corners as Point ## 784Returns four points in quad that enclose Rect ordered as: top-left, top-right, 785bottom-right, bottom-left. 786 787#Private 788Consider adding param to control whether quad is CW or CCW. 789## 790 791#Param quad storage for corners of Rect ## 792 793#Example 794 SkRect rect = {1, 2, 3, 4}; 795 SkPoint corners[4]; 796 rect.toQuad(corners); 797 SkDebugf("rect: {%g, %g, %g, %g}\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); 798 SkDebugf("corners:"); 799 for (auto corner : corners) { 800 SkDebugf(" {%g, %g}", corner.fX, corner.fY); 801 } 802 SkDebugf("\n"); 803#StdOut 804rect: {1, 2, 3, 4} 805corners: {1, 2} {3, 2} {3, 4} {1, 4} 806## 807## 808 809#SeeAlso SkPath::addRect 810 811## 812 813# ------------------------------------------------------------------------------ 814 815#Method void setBounds(const SkPoint pts[], int count) 816 817#In As_Points 818#Line # sets to upper and lower limits of Point array ## 819Sets to bounds of Point array with count entries. If count is zero or smaller, 820or if Point array contains an infinity or NaN, sets to (0, 0, 0, 0). 821 822Result is either empty or sorted: fLeft is less than or equal to fRight, and 823fTop is less than or equal to fBottom. 824 825#Param pts Point array ## 826#Param count entries in array ## 827 828#Example 829 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}}; 830 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) { 831 SkRect rect; 832 rect.setBounds(points, count); 833 if (count > 0) { 834 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY); 835 } else { 836 SkDebugf("%14s", " "); 837 } 838 SkDebugf("count: %d rect: %g, %g, %g, %g\n", count, 839 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); 840 } 841#StdOut 842 count: 0 rect: 0, 0, 0, 0 843added: 3, 4 count: 1 rect: 3, 4, 3, 4 844added: 1, 2 count: 2 rect: 1, 2, 3, 4 845added: 5, 6 count: 3 rect: 1, 2, 5, 6 846added: nan, 8 count: 4 rect: 0, 0, 0, 0 847## 848## 849 850#SeeAlso set setBoundsCheck SkPath::addPoly 851 852## 853 854# ------------------------------------------------------------------------------ 855 856#Method bool setBoundsCheck(const SkPoint pts[], int count) 857 858#In As_Points 859#Line # sets to upper and lower limits of Point array ## 860Sets to bounds of Point array with count entries. Returns false if count is 861zero or smaller, or if Point array contains an infinity or NaN; in these cases 862sets Rect to (0, 0, 0, 0). 863 864Result is either empty or sorted: fLeft is less than or equal to fRight, and 865fTop is less than or equal to fBottom. 866 867#Param pts Point array ## 868#Param count entries in array ## 869 870#Return true if all Point values are finite ## 871 872#Example 873 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}}; 874 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) { 875 SkRect rect; 876 bool success = rect.setBoundsCheck(points, count); 877 if (count > 0) { 878 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY); 879 } else { 880 SkDebugf("%14s", " "); 881 } 882 SkDebugf("count: %d rect: %g, %g, %g, %g success: %s\n", count, 883 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, success ? "true" : "false"); 884 } 885#StdOut 886 count: 0 rect: 0, 0, 0, 0 success: true 887added: 3, 4 count: 1 rect: 3, 4, 3, 4 success: true 888added: 1, 2 count: 2 rect: 1, 2, 3, 4 success: true 889added: 5, 6 count: 3 rect: 1, 2, 5, 6 success: true 890added: nan, 8 count: 4 rect: 0, 0, 0, 0 success: false 891## 892## 893 894#SeeAlso set setBounds SkPath::addPoly 895 896## 897 898#Subtopic As_Points ## 899 900#Subtopic Set 901#Line # replaces all values ## 902#Populate 903 904# ------------------------------------------------------------------------------ 905 906#Method void setEmpty() 907 908#In Set 909#Line # sets to (0, 0, 0, 0) ## 910Sets Rect to (0, 0, 0, 0). 911 912Many other rectangles are empty; if left is equal to or greater than right, 913or if top is equal to or greater than bottom. Setting all members to zero 914is a convenience, but does not designate a special empty rectangle. 915 916#Example 917 SkRect rect = {3, 4, 1, 2}; 918 for (int i = 0; i < 2; ++i) { 919 SkDebugf("rect: {%g, %g, %g, %g} is %s" "empty\n", rect.fLeft, rect.fTop, 920 rect.fRight, rect.fBottom, rect.isEmpty() ? "" : "not "); 921 rect.setEmpty(); 922 } 923#StdOut 924rect: {3, 4, 1, 2} is empty 925rect: {0, 0, 0, 0} is empty 926## 927## 928 929#SeeAlso MakeEmpty SkIRect::setEmpty 930 931## 932 933# ------------------------------------------------------------------------------ 934 935#Method void set(const SkIRect& src) 936 937#In Set 938#Line # sets to SkScalar input (left, top, right, bottom) and others ## 939Sets Rect to src, promoting src members from integer to Scalar. 940Very large values in src may lose precision. 941 942#Param src integer Rect ## 943 944#Example 945 SkIRect i_rect = {3, 4, 1, 2}; 946 SkDebugf("i_rect: {%d, %d, %d, %d}\n", i_rect.fLeft, i_rect.fTop, i_rect.fRight, i_rect.fBottom); 947 SkRect f_rect; 948 f_rect.set(i_rect); 949 SkDebugf("f_rect: {%g, %g, %g, %g}\n", f_rect.fLeft, f_rect.fTop, f_rect.fRight, f_rect.fBottom); 950#StdOut 951i_rect: {3, 4, 1, 2} 952f_rect: {3, 4, 1, 2} 953## 954## 955 956#SeeAlso setLTRB SkIntToScalar 957 958## 959 960# ------------------------------------------------------------------------------ 961 962#Method void set(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) 963 964#In Set 965Sets Rect to (left, top, right, bottom). 966left and right are not sorted; left is not necessarily less than right. 967top and bottom are not sorted; top is not necessarily less than bottom. 968 969#Param left stored in fLeft ## 970#Param top stored in fTop ## 971#Param right stored in fRight ## 972#Param bottom stored in fBottom ## 973 974#Example 975 SkRect rect1 = {3, 4, 1, 2}; 976 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom); 977 SkRect rect2; 978 rect2.set(3, 4, 1, 2); 979 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom); 980#StdOut 981rect1: {3, 4, 1, 2} 982rect2: {3, 4, 1, 2} 983## 984## 985 986#SeeAlso setLTRB setXYWH SkIRect::set 987 988## 989 990# ------------------------------------------------------------------------------ 991 992#Method void setLTRB(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) 993 994#In Set 995#Line # sets to SkScalar input (left, top, right, bottom) ## 996Sets Rect to (left, top, right, bottom). 997left and right are not sorted; left is not necessarily less than right. 998top and bottom are not sorted; top is not necessarily less than bottom. 999 1000#Param left stored in fLeft ## 1001#Param top stored in fTop ## 1002#Param right stored in fRight ## 1003#Param bottom stored in fBottom ## 1004 1005#Example 1006 SkRect rect1 = {3, 4, 1, 2}; 1007 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom); 1008 SkRect rect2; 1009 rect2.setLTRB(3, 4, 1, 2); 1010 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom); 1011#StdOut 1012rect1: {3, 4, 1, 2} 1013rect2: {3, 4, 1, 2} 1014## 1015## 1016 1017#SeeAlso set setXYWH SkIRect::set 1018 1019## 1020 1021# ------------------------------------------------------------------------------ 1022 1023#Method void set(const SkPoint pts[], int count) 1024 1025#In Set 1026Sets to bounds of Point array with count entries. If count is zero or smaller, 1027or if Point array contains an infinity or NaN, sets Rect to (0, 0, 0, 0). 1028 1029Result is either empty or sorted: fLeft is less than or equal to fRight, and 1030fTop is less than or equal to fBottom. 1031 1032#Param pts Point array ## 1033#Param count entries in array ## 1034 1035#Example 1036 SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}}; 1037 for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) { 1038 SkRect rect; 1039 rect.set(points, count); 1040 if (count > 0) { 1041 SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY); 1042 } else { 1043 SkDebugf("%14s", " "); 1044 } 1045 SkDebugf("count: %d rect: %g, %g, %g, %g\n", count, 1046 rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); 1047 } 1048#StdOut 1049 count: 0 rect: 0, 0, 0, 0 1050added: 3, 4 count: 1 rect: 3, 4, 3, 4 1051added: 1, 2 count: 2 rect: 1, 2, 3, 4 1052added: 5, 6 count: 3 rect: 1, 2, 5, 6 1053added: nan, 8 count: 4 rect: 0, 0, 0, 0 1054## 1055## 1056 1057#SeeAlso setBounds setBoundsCheck SkPath::addPoly 1058 1059## 1060 1061# ------------------------------------------------------------------------------ 1062 1063#Method void set(const SkPoint& p0, const SkPoint& p1) 1064 1065#In Set 1066Sets bounds to the smallest Rect enclosing Points p0 and p1. The result is 1067sorted and may be empty. Does not check to see if values are finite. 1068 1069#Param p0 corner to include ## 1070#Param p1 corner to include ## 1071 1072#Example 1073#Description 1074p0 and p1 may be swapped and have the same effect unless one contains NaN. 1075## 1076 SkPoint point1 = {SK_ScalarNaN, 8}; 1077 SkPoint point2 = {3, 4}; 1078 SkRect rect; 1079 rect.set(point1, point2); 1080 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); 1081 rect.set(point2, point1); 1082 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); 1083## 1084 1085#SeeAlso setBounds setBoundsCheck 1086 1087## 1088 1089# ------------------------------------------------------------------------------ 1090 1091#Method void setXYWH(SkScalar x, SkScalar y, SkScalar width, SkScalar height) 1092 1093#In Set 1094#Line # sets to SkScalar input (x, y, width, height) ## 1095Sets Rect to 1096#Formula 1097(x, y, x + width, y + height) 1098## 1099. Does not validate input; 1100width or height may be negative. 1101 1102#Param x stored in fLeft ## 1103#Param y stored in fTop ## 1104#Param width added to x and stored in fRight ## 1105#Param height added to y and stored in fBottom ## 1106 1107#Example 1108 SkRect rect; 1109 rect.setXYWH(5, 35, -15, 25); 1110 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(), 1111 rect.bottom(), rect.isEmpty() ? "true" : "false"); 1112 rect.sort(); 1113 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(), 1114 rect.bottom(), rect.isEmpty() ? "true" : "false"); 1115#StdOut 1116rect: 5, 35, -10, 60 isEmpty: true 1117rect: -10, 35, 5, 60 isEmpty: false 1118## 1119## 1120 1121#SeeAlso MakeXYWH setLTRB set SkIRect::setXYWH 1122 1123## 1124 1125# ------------------------------------------------------------------------------ 1126 1127#Method void setWH(SkScalar width, SkScalar height) 1128 1129#In Set 1130#Line # sets to SkScalar input (0, 0, width, height) ## 1131Sets Rect to (0, 0, width, height). Does not validate input; 1132width or height may be negative. 1133 1134#Param width stored in fRight ## 1135#Param height stored in fBottom ## 1136 1137#Example 1138 SkRect rect; 1139 rect.setWH(-15, 25); 1140 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(), 1141 rect.bottom(), rect.isEmpty() ? "true" : "false"); 1142 rect.sort(); 1143 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(), 1144 rect.bottom(), rect.isEmpty() ? "true" : "false"); 1145#StdOut 1146rect: 0, 0, -15, 25 isEmpty: true 1147rect: -15, 0, 0, 25 isEmpty: false 1148## 1149## 1150 1151#SeeAlso MakeWH setXYWH isetWH 1152 1153## 1154 1155#Subtopic Set ## 1156 1157#Subtopic From_Integers 1158#Line # set Scalar values from integer input ## 1159 1160#Populate 1161 1162# ------------------------------------------------------------------------------ 1163 1164#Method void iset(int left, int top, int right, int bottom) 1165 1166#In From_Integers 1167#Line # sets to int input (left, top, right, bottom) ## 1168Sets Rect to (left, top, right, bottom). 1169All parameters are promoted from integer to Scalar. 1170left and right are not sorted; left is not necessarily less than right. 1171top and bottom are not sorted; top is not necessarily less than bottom. 1172 1173#Param left promoted to SkScalar and stored in fLeft ## 1174#Param top promoted to SkScalar and stored in fTop ## 1175#Param right promoted to SkScalar and stored in fRight ## 1176#Param bottom promoted to SkScalar and stored in fBottom ## 1177 1178#Example 1179 SkRect rect1 = {3, 4, 1, 2}; 1180 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom); 1181 SkRect rect2; 1182 rect2.iset(3, 4, 1, 2); 1183 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom); 1184#StdOut 1185rect1: {3, 4, 1, 2} 1186rect2: {3, 4, 1, 2} 1187## 1188## 1189 1190#SeeAlso set setLTRB SkIRect::set SkIntToScalar 1191 1192## 1193 1194# ------------------------------------------------------------------------------ 1195 1196#Method void isetWH(int width, int height) 1197 1198#In From_Integers 1199#Line # sets to int input (0, 0, width, height) ## 1200Sets Rect to (0, 0, width, height). 1201width and height may be zero or negative. width and height are promoted from 1202integer to SkScalar, large values may lose precision. 1203 1204#Param width promoted to SkScalar and stored in fRight ## 1205#Param height promoted to SkScalar and stored in fBottom ## 1206 1207#Example 1208 SkRect rect1 = {0, 0, 1, 2}; 1209 SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom); 1210 SkRect rect2; 1211 rect2.isetWH(1, 2); 1212 SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom); 1213#StdOut 1214rect1: {0, 0, 1, 2} 1215rect2: {0, 0, 1, 2} 1216## 1217## 1218 1219#SeeAlso MakeWH MakeXYWH iset() SkIRect:MakeWH 1220 1221## 1222 1223#Subtopic From_Integers ## 1224 1225#Subtopic Inset_Outset_Offset 1226#Line # moves sides ## 1227 1228#Populate 1229 1230# ------------------------------------------------------------------------------ 1231 1232#Method SkRect makeOffset(SkScalar dx, SkScalar dy) const 1233 1234#In Inset_Outset_Offset 1235#Line # constructs from translated sides ## 1236Returns Rect offset by (dx, dy). 1237 1238If dx is negative, Rect returned is moved to the left. 1239If dx is positive, Rect returned is moved to the right. 1240If dy is negative, Rect returned is moved upward. 1241If dy is positive, Rect returned is moved downward. 1242 1243#Param dx added to fLeft and fRight ## 1244#Param dy added to fTop and fBottom ## 1245 1246#Return Rect offset in x or y, with original width and height ## 1247 1248#Example 1249 SkRect rect = { 10, 50, 20, 60 }; 1250 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(), 1251 rect.bottom(), rect.isEmpty() ? "true" : "false"); 1252 rect = rect.makeOffset(15, 32); 1253 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(), 1254 rect.bottom(), rect.isEmpty() ? "true" : "false"); 1255#StdOut 1256rect: 10, 50, 20, 60 isEmpty: false 1257rect: 25, 82, 35, 92 isEmpty: false 1258## 1259## 1260 1261#SeeAlso offset() makeInset makeOutset SkIRect::makeOffset 1262 1263## 1264 1265# ------------------------------------------------------------------------------ 1266 1267#Method SkRect makeInset(SkScalar dx, SkScalar dy) const 1268 1269#In Inset_Outset_Offset 1270#Line # constructs from sides moved symmetrically about the center ## 1271Returns Rect, inset by (dx, dy). 1272 1273If dx is negative, Rect returned is wider. 1274If dx is positive, Rect returned is narrower. 1275If dy is negative, Rect returned is taller. 1276If dy is positive, Rect returned is shorter. 1277 1278#Param dx added to fLeft and subtracted from fRight ## 1279#Param dy added to fTop and subtracted from fBottom ## 1280 1281#Return Rect inset symmetrically left and right, top and bottom ## 1282 1283#Example 1284 SkRect rect = { 10, 50, 20, 60 }; 1285 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(), 1286 rect.bottom(), rect.isEmpty() ? "true" : "false"); 1287 rect = rect.makeInset(15, 32); 1288 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(), 1289 rect.bottom(), rect.isEmpty() ? "true" : "false"); 1290#StdOut 1291rect: 10, 50, 20, 60 isEmpty: false 1292rect: 25, 82, 5, 28 isEmpty: true 1293## 1294## 1295 1296#SeeAlso inset() makeOffset makeOutset SkIRect::makeInset 1297 1298## 1299 1300# ------------------------------------------------------------------------------ 1301 1302#Method SkRect makeOutset(SkScalar dx, SkScalar dy) const 1303 1304#In Inset_Outset_Offset 1305#Line # constructs from sides moved symmetrically about the center ## 1306Returns Rect, outset by (dx, dy). 1307 1308If dx is negative, Rect returned is narrower. 1309If dx is positive, Rect returned is wider. 1310If dy is negative, Rect returned is shorter. 1311If dy is positive, Rect returned is taller. 1312 1313#Param dx subtracted to fLeft and added from fRight ## 1314#Param dy subtracted to fTop and added from fBottom ## 1315 1316#Return Rect outset symmetrically left and right, top and bottom ## 1317 1318#Example 1319 SkRect rect = { 10, 50, 20, 60 }; 1320 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(), 1321 rect.bottom(), rect.isEmpty() ? "true" : "false"); 1322 rect = rect.makeOutset(15, 32); 1323 SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(), 1324 rect.bottom(), rect.isEmpty() ? "true" : "false"); 1325#StdOut 1326rect: 10, 50, 20, 60 isEmpty: false 1327rect: -5, 18, 35, 92 isEmpty: false 1328## 1329## 1330 1331#SeeAlso outset() makeOffset makeInset SkIRect::makeOutset 1332 1333## 1334 1335# ------------------------------------------------------------------------------ 1336 1337#Method void offset(SkScalar dx, SkScalar dy) 1338 1339#In Inset_Outset_Offset 1340#Line # translates sides without changing width and height ## 1341Offsets Rect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom. 1342 1343If dx is negative, moves Rect to the left. 1344If dx is positive, moves Rect to the right. 1345If dy is negative, moves Rect upward. 1346If dy is positive, moves Rect downward. 1347 1348#Param dx offset added to fLeft and fRight ## 1349#Param dy offset added to fTop and fBottom ## 1350 1351#Example 1352 SkRect rect = { 10, 14, 50, 73 }; 1353 rect.offset(5, 13); 1354 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); 1355#StdOut 1356rect: 15, 27, 55, 86 1357## 1358## 1359 1360#SeeAlso offsetTo makeOffset SkIRect::offset 1361 1362## 1363 1364# ------------------------------------------------------------------------------ 1365 1366#Method void offset(const SkPoint& delta) 1367 1368#In Inset_Outset_Offset 1369Offsets Rect by adding delta.fX to fLeft, fRight; and by adding delta.fY to 1370fTop, fBottom. 1371 1372If delta.fX is negative, moves Rect to the left. 1373If delta.fX is positive, moves Rect to the right. 1374If delta.fY is negative, moves Rect upward. 1375If delta.fY is positive, moves Rect downward. 1376 1377#Param delta added to Rect ## 1378 1379#Example 1380 SkRect rect = { 10, 14, 50, 73 }; 1381 rect.offset({5, 13}); 1382 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); 1383#StdOut 1384rect: 15, 27, 55, 86 1385## 1386## 1387 1388#SeeAlso offsetTo makeOffset SkIRect::offset 1389 1390## 1391 1392# ------------------------------------------------------------------------------ 1393 1394#Method void offsetTo(SkScalar newX, SkScalar newY) 1395 1396#In Inset_Outset_Offset 1397#Line # translates to (x, y) without changing width and height ## 1398Offsets Rect so that fLeft equals newX, and fTop equals newY. width and height 1399are unchanged. 1400 1401#Param newX stored in fLeft, preserving width() ## 1402#Param newY stored in fTop, preserving height() ## 1403 1404#Example 1405 SkRect rect = { 10, 14, 50, 73 }; 1406 rect.offsetTo(15, 27); 1407 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); 1408#StdOut 1409rect: 15, 27, 55, 86 1410## 1411## 1412 1413#SeeAlso offset makeOffset setXYWH SkIRect::offsetTo 1414 1415## 1416 1417# ------------------------------------------------------------------------------ 1418 1419#Method void inset(SkScalar dx, SkScalar dy) 1420 1421#In Inset_Outset_Offset 1422#Line # moves the sides symmetrically about the center ## 1423Insets Rect by (dx, dy). 1424 1425If dx is positive, makes Rect narrower. 1426If dx is negative, makes Rect wider. 1427If dy is positive, makes Rect shorter. 1428If dy is negative, makes Rect taller. 1429 1430#Param dx added to fLeft and subtracted from fRight ## 1431#Param dy added to fTop and subtracted from fBottom ## 1432 1433#Example 1434 SkRect rect = { 10, 14, 50, 73 }; 1435 rect.inset(5, 13); 1436 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); 1437#StdOut 1438rect: 15, 27, 45, 60 1439## 1440## 1441 1442#SeeAlso outset makeInset SkIRect::inset 1443 1444## 1445 1446# ------------------------------------------------------------------------------ 1447 1448#Method void outset(SkScalar dx, SkScalar dy) 1449 1450#In Inset_Outset_Offset 1451#Line # moves the sides symmetrically about the center ## 1452Outsets Rect by (dx, dy). 1453 1454If dx is positive, makes Rect wider. 1455If dx is negative, makes Rect narrower. 1456If dy is positive, makes Rect taller. 1457If dy is negative, makes Rect shorter. 1458 1459#Param dx subtracted to fLeft and added from fRight ## 1460#Param dy subtracted to fTop and added from fBottom ## 1461 1462#Example 1463 SkRect rect = { 10, 14, 50, 73 }; 1464 rect.outset(5, 13); 1465 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); 1466#StdOut 1467rect: 5, 1, 55, 86 1468## 1469## 1470 1471#SeeAlso inset makeOutset SkIRect::outset 1472 1473## 1474 1475#Subtopic Inset_Outset_Offset ## 1476 1477#Subtopic Intersection 1478#Line # set to shared bounds ## 1479 1480Rects intersect when they enclose a common area. To intersect, each of the pair 1481must describe area; fLeft is less than fRight, and fTop is less than fBottom; 1482empty() returns false. The intersection of Rect pair can be described by: 1483 1484#Formula 1485(max(a.fLeft, b.fLeft), max(a.fTop, b.fTop), 1486 min(a.fRight, b.fRight), min(a.fBottom, b.fBottom)) 1487## 1488. 1489 1490The intersection is only meaningful if the resulting Rect is not empty and 1491describes an area: fLeft is less than fRight, and fTop is less than fBottom. 1492 1493#Populate 1494 1495# ------------------------------------------------------------------------------ 1496 1497#Method bool contains(const SkRect& r) const 1498 1499#In Intersection 1500#Line # returns true if points are equal or inside ## 1501Returns true if Rect contains r. 1502Returns false if Rect is empty or r is empty. 1503 1504Rect contains r when Rect area completely includes r area. 1505 1506#Param r Rect contained ## 1507 1508#Return true if all sides of Rect are outside r ## 1509 1510#Example 1511 SkRect rect = { 30, 50, 40, 60 }; 1512 SkRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} }; 1513 for (auto contained : tests) { 1514 SkDebugf("rect: (%g, %g, %g, %g) %s (%g, %g, %g, %g)\n", 1515 rect.left(), rect.top(), rect.right(), rect.bottom(), 1516 rect.contains(contained) ? "contains" : "does not contain", 1517 contained.left(), contained.top(), contained.right(), contained.bottom()); 1518 } 1519#StdOut 1520rect: (30, 50, 40, 60) contains (30, 50, 31, 51) 1521rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50) 1522rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60) 1523## 1524## 1525 1526#SeeAlso SkIRect::contains 1527 1528## 1529 1530# ------------------------------------------------------------------------------ 1531 1532#Method bool contains(const SkIRect& r) const 1533 1534#In Intersection 1535Returns true if Rect contains r. 1536Returns false if Rect is empty or r is empty. 1537 1538Rect contains r when Rect area completely includes r area. 1539 1540#Param r IRect contained ## 1541 1542#Return true if all sides of Rect are outside r ## 1543 1544#Example 1545 SkRect rect = { 30, 50, 40, 60 }; 1546 SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} }; 1547 for (auto contained : tests) { 1548 SkDebugf("rect: (%g, %g, %g, %g) %s (%d, %d, %d, %d)\n", 1549 rect.left(), rect.top(), rect.right(), rect.bottom(), 1550 rect.contains(contained) ? "contains" : "does not contain", 1551 contained.left(), contained.top(), contained.right(), contained.bottom()); 1552 } 1553#StdOut 1554rect: (30, 50, 40, 60) contains (30, 50, 31, 51) 1555rect: (30, 50, 40, 60) does not contain (39, 49, 40, 50) 1556rect: (30, 50, 40, 60) does not contain (29, 59, 30, 60) 1557## 1558## 1559 1560#SeeAlso SkIRect::contains 1561 1562## 1563 1564# ------------------------------------------------------------------------------ 1565 1566#Method bool intersect(const SkRect& r) 1567 1568#In Intersection 1569#Line # sets to shared area; returns true if not empty ## 1570Returns true if Rect intersects r, and sets Rect to intersection. 1571Returns false if Rect does not intersect r, and leaves Rect unchanged. 1572 1573Returns false if either r or Rect is empty, leaving Rect unchanged. 1574 1575#Param r limit of result ## 1576 1577#Return true if r and Rect have area in common ## 1578 1579#Example 1580#Description 1581Two SkDebugf calls are required. If the calls are combined, their arguments 1582may not be evaluated in left to right order: the printed intersection may 1583be before or after the call to intersect. 1584## 1585 SkRect leftRect = { 10, 40, 50, 80 }; 1586 SkRect rightRect = { 30, 60, 70, 90 }; 1587 SkDebugf("%s intersection: ", leftRect.intersect(rightRect) ? "" : "no "); 1588 SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(), 1589 leftRect.right(), leftRect.bottom()); 1590#StdOut 1591 intersection: 30, 60, 50, 80 1592## 1593## 1594 1595#SeeAlso intersects Intersects join SkIRect::intersect 1596 1597## 1598 1599# ------------------------------------------------------------------------------ 1600 1601#Method bool intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) 1602 1603#In Intersection 1604Constructs Rect to intersect from (left, top, right, bottom). Does not sort 1605construction. 1606 1607Returns true if Rect intersects construction, and sets Rect to intersection. 1608Returns false if Rect does not intersect construction, and leaves Rect unchanged. 1609 1610Returns false if either construction or Rect is empty, leaving Rect unchanged. 1611 1612#Param left x minimum of constructed Rect ## 1613#Param top y minimum of constructed Rect ## 1614#Param right x maximum of constructed Rect ## 1615#Param bottom y maximum of constructed Rect ## 1616 1617#Return true if construction and Rect have area in common ## 1618 1619#Example 1620#Description 1621Two SkDebugf calls are required. If the calls are combined, their arguments 1622may not be evaluated in left to right order: the printed intersection may 1623be before or after the call to intersect. 1624## 1625 SkRect leftRect = { 10, 40, 50, 80 }; 1626 SkDebugf("%s intersection: ", leftRect.intersect(30, 60, 70, 90) ? "" : "no "); 1627 SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(), 1628 leftRect.right(), leftRect.bottom()); 1629#StdOut 1630 intersection: 30, 60, 50, 80 1631## 1632## 1633 1634#SeeAlso intersects Intersects join SkIRect::intersect 1635 1636## 1637 1638# ------------------------------------------------------------------------------ 1639 1640#Method bool SK_WARN_UNUSED_RESULT intersect(const SkRect& a, const SkRect& b) 1641 1642#In Intersection 1643Returns true if a intersects b, and sets Rect to intersection. 1644Returns false if a does not intersect b, and leaves Rect unchanged. 1645 1646Returns false if either a or b is empty, leaving Rect unchanged. 1647 1648#Param a Rect to intersect ## 1649#Param b Rect to intersect ## 1650 1651#Return true if a and b have area in common ## 1652 1653#Example 1654 SkRect result; 1655 bool intersected = result.intersect({ 10, 40, 50, 80 }, { 30, 60, 70, 90 }); 1656 SkDebugf("%s intersection: %g, %g, %g, %g\n", intersected ? "" : "no ", 1657 result.left(), result.top(), result.right(), result.bottom()); 1658#StdOut 1659 intersection: 30, 60, 50, 80 1660## 1661## 1662 1663#SeeAlso intersects Intersects join SkIRect::intersect 1664 1665## 1666 1667# ------------------------------------------------------------------------------ 1668 1669#Method bool intersects(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) const 1670 1671#In Intersection 1672#Line # returns true if areas overlap ## 1673Constructs Rect to intersect from (left, top, right, bottom). Does not sort 1674construction. 1675 1676Returns true if Rect intersects construction. 1677Returns false if either construction or Rect is empty, or do not intersect. 1678 1679#Param left x minimum of constructed Rect ## 1680#Param top y minimum of constructed Rect ## 1681#Param right x maximum of constructed Rect ## 1682#Param bottom y maximum of constructed Rect ## 1683 1684#Return true if construction and Rect have area in common ## 1685 1686#Example 1687 SkRect rect = { 10, 40, 50, 80 }; 1688 SkDebugf("%s intersection", rect.intersects(30, 60, 70, 90) ? "" : "no "); 1689#StdOut 1690 intersection 1691## 1692## 1693 1694#SeeAlso intersect Intersects SkIRect::Intersects 1695 1696## 1697 1698# ------------------------------------------------------------------------------ 1699 1700#Method bool intersects(const SkRect& r) const 1701 1702#In Intersection 1703Returns true if Rect intersects r. 1704Returns false if either r or Rect is empty, or do not intersect. 1705 1706#Param r Rect to intersect ## 1707 1708#Return true if r and Rect have area in common ## 1709 1710#Example 1711 SkRect rect = { 10, 40, 50, 80 }; 1712 SkDebugf("%s intersection", rect.intersects({30, 60, 70, 90}) ? "" : "no "); 1713#StdOut 1714 intersection 1715## 1716## 1717 1718#SeeAlso intersect Intersects SkIRect::Intersects 1719 1720## 1721 1722# ------------------------------------------------------------------------------ 1723 1724#Method static bool Intersects(const SkRect& a, const SkRect& b) 1725 1726#In Intersection 1727#Line # returns true if areas overlap ## 1728Returns true if a intersects b. 1729Returns false if either a or b is empty, or do not intersect. 1730 1731#Param a Rect to intersect ## 1732#Param b Rect to intersect ## 1733 1734#Return true if a and b have area in common ## 1735 1736#Example 1737 SkDebugf("%s intersection", SkRect::Intersects({10, 40, 50, 80}, {30, 60, 70, 90}) ? "" : "no "); 1738#StdOut 1739 intersection 1740## 1741## 1742 1743#SeeAlso intersect intersects SkIRect::Intersects 1744 1745## 1746 1747#Subtopic Intersection ## 1748 1749#Subtopic Join 1750#Line # set to union of bounds ## 1751 1752#Populate 1753 1754# ------------------------------------------------------------------------------ 1755 1756#Method void join(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) 1757 1758#In Join 1759#Line # sets to union of bounds ## 1760Constructs Rect to intersect from (left, top, right, bottom). Does not sort 1761construction. 1762 1763Sets Rect to the union of itself and the construction. 1764 1765Has no effect if construction is empty. Otherwise, if Rect is empty, sets 1766Rect to construction. 1767 1768#Param left x minimum of constructed Rect ## 1769#Param top y minimum of constructed Rect ## 1770#Param right x maximum of constructed Rect ## 1771#Param bottom y maximum of constructed Rect ## 1772 1773#Example 1774 SkRect rect = { 10, 20, 15, 25}; 1775 rect.join(50, 60, 55, 65); 1776 SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); 1777#StdOut 1778 join: 10, 20, 55, 65 1779## 1780## 1781 1782#SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join 1783 1784## 1785 1786# ------------------------------------------------------------------------------ 1787 1788#Method void join(const SkRect& r) 1789 1790#In Join 1791Sets Rect to the union of itself and r. 1792 1793Has no effect if r is empty. Otherwise, if Rect is empty, sets 1794Rect to r. 1795 1796#Param r expansion Rect ## 1797 1798#Example 1799 SkRect rect = { 10, 20, 15, 25}; 1800 rect.join({50, 60, 55, 65}); 1801 SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); 1802#StdOut 1803 join: 10, 20, 55, 65 1804## 1805## 1806 1807#SeeAlso joinNonEmptyArg joinPossiblyEmptyRect SkIRect::join 1808 1809## 1810 1811# ------------------------------------------------------------------------------ 1812 1813#Method void joinNonEmptyArg(const SkRect& r) 1814 1815#In Join 1816#Line # sets to union of bounds, asserting that argument is not empty ## 1817Sets Rect to the union of itself and r. 1818 1819Asserts if r is empty and SK_DEBUG is defined. 1820If Rect is empty, sets Rect to r. 1821 1822May produce incorrect results if r is empty. 1823 1824#Param r expansion Rect ## 1825 1826#Example 1827#Description 1828Since Rect is not sorted, first result is copy of toJoin. 1829## 1830 SkRect rect = { 10, 100, 15, 0}; 1831 SkRect sorted = rect.makeSorted(); 1832 SkRect toJoin = { 50, 60, 55, 65 }; 1833 rect.joinNonEmptyArg(toJoin); 1834 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); 1835 sorted.joinNonEmptyArg(toJoin); 1836 SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom); 1837#StdOut 1838rect: 50, 60, 55, 65 1839sorted: 10, 0, 55, 100 1840## 1841## 1842 1843#SeeAlso join joinPossiblyEmptyRect SkIRect::join 1844 1845## 1846 1847# ------------------------------------------------------------------------------ 1848 1849#Method void joinPossiblyEmptyRect(const SkRect& r) 1850 1851#In Join 1852#Line # sets to union of bounds. Skips empty check for both ## 1853Sets Rect to the union of itself and the construction. 1854 1855May produce incorrect results if Rect or r is empty. 1856 1857#Param r expansion Rect ## 1858 1859#Example 1860#Description 1861Since Rect is not sorted, first result is not useful. 1862## 1863 SkRect rect = { 10, 100, 15, 0}; 1864 SkRect sorted = rect.makeSorted(); 1865 SkRect toJoin = { 50, 60, 55, 65 }; 1866 rect.joinPossiblyEmptyRect(toJoin); 1867 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); 1868 sorted.joinPossiblyEmptyRect(toJoin); 1869 SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom); 1870#StdOut 1871rect: 10, 60, 55, 65 1872sorted: 10, 0, 55, 100 1873## 1874## 1875 1876#SeeAlso joinNonEmptyArg join SkIRect::join 1877 1878## 1879 1880#Subtopic Join ## 1881 1882#Subtopic Rounding 1883#Line # adjust to integer bounds ## 1884 1885#Populate 1886 1887#Method void round(SkIRect* dst) const 1888 1889#In Rounding 1890#Line # sets members to nearest integer value ## 1891Sets IRect by adding 0.5 and discarding the fractional portion of Rect 1892members, using 1893#Formula 1894(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop), 1895 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom)) 1896## 1897. 1898 1899#Param dst storage for IRect ## 1900 1901#Example 1902 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f }; 1903 SkIRect round; 1904 rect.round(&round); 1905 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom); 1906#StdOut 1907round: 31, 51, 41, 61 1908## 1909## 1910 1911#SeeAlso roundIn roundOut SkScalarRoundToInt 1912 1913## 1914 1915# ------------------------------------------------------------------------------ 1916 1917#Method void roundOut(SkIRect* dst) const 1918 1919#In Rounding 1920#Line # sets members to nearest integer value away from opposite ## 1921Sets IRect by discarding the fractional portion of fLeft and fTop; and 1922rounding up fRight and fBottom, using 1923#Formula 1924(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop), 1925 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)) 1926## 1927. 1928 1929#Param dst storage for IRect ## 1930 1931#Example 1932 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f }; 1933 SkIRect round; 1934 rect.roundOut(&round); 1935 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom); 1936#StdOut 1937round: 30, 50, 41, 61 1938## 1939## 1940 1941#SeeAlso roundIn round SkScalarRoundToInt 1942 1943## 1944 1945# ------------------------------------------------------------------------------ 1946 1947#Method void roundOut(SkRect* dst) const 1948 1949#In Rounding 1950Sets Rect by discarding the fractional portion of fLeft and fTop; and 1951rounding up fRight and fBottom, using 1952#Formula 1953(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop), 1954 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)) 1955## 1956. 1957 1958#Param dst storage for Rect ## 1959 1960#Example 1961 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f }; 1962 SkRect round; 1963 rect.roundOut(&round); 1964 SkDebugf("round: %g, %g, %g, %g\n", round.fLeft, round.fTop, round.fRight, round.fBottom); 1965#StdOut 1966round: 30, 50, 41, 61 1967## 1968## 1969 1970#SeeAlso roundIn round SkScalarRoundToInt 1971 1972## 1973 1974# ------------------------------------------------------------------------------ 1975 1976#Method void roundIn(SkIRect* dst) const 1977 1978#In Rounding 1979#Line # sets members to nearest integer value towards opposite ## 1980Sets Rect by rounding up fLeft and fTop; and 1981discarding the fractional portion of fRight and fBottom, using 1982 1983#Formula 1984(SkScalarCeilToInt(fLeft), SkScalarCeilToInt(fTop), 1985 SkScalarFloorToInt(fRight), SkScalarFloorToInt(fBottom)) 1986## 1987. 1988 1989#Param dst storage for IRect ## 1990 1991#Example 1992 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f }; 1993 SkIRect round; 1994 rect.roundIn(&round); 1995 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom); 1996#StdOut 1997round: 31, 51, 40, 60 1998## 1999## 2000 2001#SeeAlso roundOut round SkScalarRoundToInt 2002 2003## 2004 2005# ------------------------------------------------------------------------------ 2006 2007#Method SkIRect round() const 2008 2009#In Rounding 2010Returns IRect by adding 0.5 and discarding the fractional portion of Rect 2011members, using 2012#Formula 2013(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop), 2014 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom)) 2015## 2016. 2017 2018#Return rounded IRect ## 2019 2020#Example 2021 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f }; 2022 SkIRect round = rect.round(); 2023 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom); 2024#StdOut 2025round: 31, 51, 41, 61 2026## 2027## 2028 2029#SeeAlso roundOut roundIn SkScalarRoundToInt 2030 2031## 2032 2033# ------------------------------------------------------------------------------ 2034 2035#Method SkIRect roundOut() const 2036 2037#In Rounding 2038Sets IRect by discarding the fractional portion of fLeft and fTop; and 2039rounding up fRight and fBottom, using 2040#Formula 2041(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop), 2042 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)) 2043## 2044. 2045 2046#Return rounded IRect ## 2047 2048#Example 2049 SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f }; 2050 SkIRect round = rect.roundOut(); 2051 SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom); 2052#StdOut 2053round: 30, 50, 41, 61 2054## 2055## 2056 2057#SeeAlso round roundIn SkScalarRoundToInt 2058 2059## 2060 2061#Subtopic Rounding ## 2062 2063#Subtopic Sorting 2064#Line # orders sides ## 2065 2066#Populate 2067 2068# ------------------------------------------------------------------------------ 2069 2070#Method void sort() 2071 2072#In Sorting 2073#Line # orders sides from smaller to larger ## 2074Swaps fLeft and fRight if fLeft is greater than fRight; and swaps 2075fTop and fBottom if fTop is greater than fBottom. Result may be empty; 2076and width() and height() will be zero or positive. 2077 2078#Example 2079 SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f }; 2080 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); 2081 rect.sort(); 2082 SkDebugf("sorted: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); 2083#StdOut 2084rect: 30.5, 50.5, 20.5, 10.5 2085sorted: 20.5, 10.5, 30.5, 50.5 2086## 2087## 2088 2089#SeeAlso makeSorted SkIRect::sort isSorted 2090 2091## 2092 2093# ------------------------------------------------------------------------------ 2094 2095#Method SkRect makeSorted() const 2096 2097#In Sorting 2098#In Constructor 2099#Line # constructs, ordering sides from smaller to larger ## 2100Returns Rect with fLeft and fRight swapped if fLeft is greater than fRight; and 2101with fTop and fBottom swapped if fTop is greater than fBottom. Result may be empty; 2102and width() and height() will be zero or positive. 2103 2104#Return sorted Rect ## 2105 2106#Example 2107 SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f }; 2108 SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); 2109 SkRect sort = rect.makeSorted(); 2110 SkDebugf("sorted: %g, %g, %g, %g\n", sort.fLeft, sort.fTop, sort.fRight, sort.fBottom); 2111#StdOut 2112rect: 30.5, 50.5, 20.5, 10.5 2113sorted: 20.5, 10.5, 30.5, 50.5 2114## 2115## 2116 2117#SeeAlso sort SkIRect::makeSorted isSorted 2118 2119## 2120 2121#Subtopic Sorting ## 2122 2123# ------------------------------------------------------------------------------ 2124 2125#Method const SkScalar* asScalars() const 2126#In Property 2127#Line # returns pointer to members as array ## 2128Returns pointer to first Scalar in Rect, to treat it as an array with four 2129entries. 2130 2131#Return pointer to fLeft ## 2132 2133#Example 2134 SkRect rect = {7, 11, 13, 17}; 2135SkDebugf("rect.asScalars() %c= &rect.fLeft\n", rect.asScalars() == &rect.fLeft? '=' : '!'); 2136#StdOut 2137rect.asScalars() == &rect.fLeft 2138## 2139## 2140 2141#SeeAlso toQuad 2142 2143## 2144 2145# ------------------------------------------------------------------------------ 2146 2147#Method void dump(bool asHex) const 2148#In Property 2149#Line # sends text representation to standard output using floats ## 2150Writes text representation of Rect to standard output. Set asHex to true to 2151generate exact binary representations of floating point numbers. 2152 2153#Param asHex true if SkScalar values are written as hexadecimal ## 2154 2155#Example 2156 SkRect rect = {20, 30, 40, 50}; 2157 for (bool dumpAsHex : { false, true } ) { 2158 rect.dump(dumpAsHex); 2159 SkDebugf("\n"); 2160 } 2161#StdOut 2162SkRect::MakeLTRB(20, 30, 40, 50); 2163 2164SkRect::MakeLTRB(SkBits2Float(0x41a00000), /* 20.000000 */ 2165 SkBits2Float(0x41f00000), /* 30.000000 */ 2166 SkBits2Float(0x42200000), /* 40.000000 */ 2167 SkBits2Float(0x42480000) /* 50.000000 */); 2168## 2169## 2170 2171#SeeAlso dumpHex 2172 2173## 2174 2175# ------------------------------------------------------------------------------ 2176 2177#Method void dump() const 2178 2179Writes text representation of Rect to standard output. The representation may be 2180directly compiled as C++ code. Floating point values are written 2181with limited precision; it may not be possible to reconstruct original Rect 2182from output. 2183 2184#Example 2185SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6}; 2186rect.dump(); 2187SkRect copy = SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7); 2188SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not "); 2189#StdOut 2190SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7); 2191rect is not equal to copy 2192## 2193## 2194 2195#SeeAlso dumpHex 2196 2197## 2198 2199# ------------------------------------------------------------------------------ 2200 2201#Method void dumpHex() const 2202#In Property 2203#Line # sends text representation to standard output using hexadecimal ## 2204Writes text representation of Rect to standard output. The representation may be 2205directly compiled as C++ code. Floating point values are written 2206in hexadecimal to preserve their exact bit pattern. The output reconstructs the 2207original Rect. 2208 2209Use instead of dump() when submitting 2210#A bug reports against Skia # http://bug.skia.org ## 2211. 2212 2213#Example 2214 SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6}; 2215rect.dumpHex(); 2216SkRect copy = SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */ 2217 SkBits2Float(0x3f2aaaab), /* 0.666667 */ 2218 SkBits2Float(0x40266666), /* 2.600000 */ 2219 SkBits2Float(0x40e00000) /* 7.000000 */); 2220SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not "); 2221#StdOut 2222SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */ 2223 SkBits2Float(0x3f2aaaab), /* 0.666667 */ 2224 SkBits2Float(0x40266666), /* 2.600000 */ 2225 SkBits2Float(0x40e00000) /* 7.000000 */); 2226rect is equal to copy 2227## 2228## 2229 2230#SeeAlso dump 2231 2232## 2233 2234#Method static SkRect SK_WARN_UNUSED_RESULT MakeLargest() 2235#Deprecated 2236## 2237 2238#Struct SkRect ## 2239 2240#Topic Rect ## 2241