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