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