OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #ifndef SkRect_DEFINED | 10 #ifndef SkRect_DEFINED |
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 sides are moved inwards, making the rectangle narrower. The same holds | 644 sides are moved inwards, making the rectangle narrower. The same holds |
645 true for dy and the top and bottom. | 645 true for dy and the top and bottom. |
646 */ | 646 */ |
647 void outset(SkScalar dx, SkScalar dy) { this->inset(-dx, -dy); } | 647 void outset(SkScalar dx, SkScalar dy) { this->inset(-dx, -dy); } |
648 | 648 |
649 /** If this rectangle intersects r, return true and set this rectangle to th
at | 649 /** If this rectangle intersects r, return true and set this rectangle to th
at |
650 intersection, otherwise return false and do not change this rectangle. | 650 intersection, otherwise return false and do not change this rectangle. |
651 If either rectangle is empty, do nothing and return false. | 651 If either rectangle is empty, do nothing and return false. |
652 */ | 652 */ |
653 bool intersect(const SkRect& r); | 653 bool intersect(const SkRect& r); |
654 bool intersect2(const SkRect& r); | |
655 | 654 |
656 /** If this rectangle intersects the rectangle specified by left, top, right
, bottom, | 655 /** If this rectangle intersects the rectangle specified by left, top, right
, bottom, |
657 return true and set this rectangle to that intersection, otherwise retur
n false | 656 return true and set this rectangle to that intersection, otherwise retur
n false |
658 and do not change this rectangle. | 657 and do not change this rectangle. |
659 If either rectangle is empty, do nothing and return false. | 658 If either rectangle is empty, do nothing and return false. |
660 */ | 659 */ |
661 bool intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
; | 660 bool intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
; |
662 | 661 |
663 /** | 662 /** |
| 663 * If rectangles a and b intersect, return true and set this rectangle to |
| 664 * that intersection, otherwise return false and do not change this |
| 665 * rectangle. If either rectangle is empty, do nothing and return false. |
| 666 */ |
| 667 bool intersect(const SkRect& a, const SkRect& b); |
| 668 |
| 669 |
| 670 private: |
| 671 static bool Intersects(SkScalar al, SkScalar at, SkScalar ar, SkScalar ab, |
| 672 SkScalar bl, SkScalar bt, SkScalar br, SkScalar bb) { |
| 673 SkScalar L = SkMaxScalar(al, bl); |
| 674 SkScalar R = SkMinScalar(ar, br); |
| 675 SkScalar T = SkMaxScalar(at, bt); |
| 676 SkScalar B = SkMinScalar(ab, bb); |
| 677 return L < R && T < B; |
| 678 } |
| 679 |
| 680 public: |
| 681 /** |
664 * Return true if this rectangle is not empty, and the specified sides of | 682 * Return true if this rectangle is not empty, and the specified sides of |
665 * a rectangle are not empty, and they intersect. | 683 * a rectangle are not empty, and they intersect. |
666 */ | 684 */ |
667 bool intersects(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom
) const { | 685 bool intersects(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom
) const { |
668 return // first check that both are not empty | 686 return Intersects(fLeft, fTop, fRight, fBottom, left, top, right, bottom
); |
669 left < right && top < bottom && | |
670 fLeft < fRight && fTop < fBottom && | |
671 // now check for intersection | |
672 fLeft < right && left < fRight && | |
673 fTop < bottom && top < fBottom; | |
674 } | 687 } |
675 | 688 |
676 /** If rectangles a and b intersect, return true and set this rectangle to | |
677 * that intersection, otherwise return false and do not change this | |
678 * rectangle. If either rectangle is empty, do nothing and return false. | |
679 */ | |
680 bool intersect(const SkRect& a, const SkRect& b); | |
681 | |
682 /** | 689 /** |
683 * Return true if rectangles a and b are not empty and intersect. | 690 * Return true if rectangles a and b are not empty and intersect. |
684 */ | 691 */ |
685 static bool Intersects(const SkRect& a, const SkRect& b) { | 692 static bool Intersects(const SkRect& a, const SkRect& b) { |
686 return !a.isEmpty() && !b.isEmpty() && | 693 return Intersects(a.fLeft, a.fTop, a.fRight, a.fBottom, |
687 a.fLeft < b.fRight && b.fLeft < a.fRight && | 694 b.fLeft, b.fTop, b.fRight, b.fBottom); |
688 a.fTop < b.fBottom && b.fTop < a.fBottom; | |
689 } | 695 } |
690 | 696 |
691 /** | 697 /** |
692 * Update this rectangle to enclose itself and the specified rectangle. | 698 * Update this rectangle to enclose itself and the specified rectangle. |
693 * If this rectangle is empty, just set it to the specified rectangle. | 699 * If this rectangle is empty, just set it to the specified rectangle. |
694 * If the specified rectangle is empty, do nothing. | 700 * If the specified rectangle is empty, do nothing. |
695 */ | 701 */ |
696 void join(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom); | 702 void join(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom); |
697 | 703 |
698 /** Update this rectangle to enclose itself and the specified rectangle. | 704 /** Update this rectangle to enclose itself and the specified rectangle. |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 * rely on the existence of this function or the formatting of its output. | 855 * rely on the existence of this function or the formatting of its output. |
850 */ | 856 */ |
851 void dump() const { | 857 void dump() const { |
852 SkDebugf("{ l: %f, t: %f, r: %f, b: %f }", fLeft, fTop, fRight, fBottom)
; | 858 SkDebugf("{ l: %f, t: %f, r: %f, b: %f }", fLeft, fTop, fRight, fBottom)
; |
853 } | 859 } |
854 #endif | 860 #endif |
855 | 861 |
856 }; | 862 }; |
857 | 863 |
858 #endif | 864 #endif |
OLD | NEW |