Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
|
vmpstr
2016/09/19 18:01:11
What do you think about just using gfx::Rect inste
prashant.n
2016/09/20 02:04:58
Yes. This is almost same with following difference
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CC_BASE_INDEX_RECT_H_ | |
| 6 #define CC_BASE_INDEX_RECT_H_ | |
| 7 | |
| 8 #include "base/logging.h" | |
| 9 #include "cc/base/cc_export.h" | |
| 10 | |
| 11 namespace cc { | |
| 12 | |
| 13 class CC_EXPORT IndexRect { | |
|
vmpstr
2016/09/19 18:01:11
Add a comment about what this class is, please.
| |
| 14 public: | |
| 15 constexpr IndexRect(int left, int right, int top, int bottom) | |
| 16 : left_(left), right_(right), top_(top), bottom_(bottom) {} | |
| 17 | |
| 18 ~IndexRect() = default; | |
| 19 | |
| 20 constexpr int left() const { return left_; } | |
| 21 constexpr int right() const { return right_; } | |
| 22 constexpr int top() const { return top_; } | |
| 23 constexpr int bottom() const { return bottom_; } | |
| 24 | |
| 25 // Returns the number of indices from left to right, including both. | |
| 26 constexpr int width() const { return right_ - left_ + 1; } | |
| 27 // Returns the number of indices from top to bottom, including both. | |
| 28 constexpr int height() const { return bottom_ - top_ + 1; } | |
| 29 | |
| 30 // Returns true if the index rect has valid indices. | |
| 31 constexpr bool is_valid() const { return left_ <= right_ && top_ <= bottom_; } | |
| 32 | |
| 33 // Returns true if the index identified by index_x is valid column. | |
| 34 bool valid_column(int index_x) const { | |
| 35 return index_x >= left() && index_x <= right(); | |
| 36 } | |
| 37 // Returns true if the index identified by index_y is a valid row. | |
| 38 bool valid_row(int index_y) const { | |
| 39 return index_y >= top() && index_y <= bottom(); | |
| 40 } | |
| 41 | |
| 42 // Clamp indices to the given IndexRect indices. For non-intersecting rects, | |
| 43 // it makes this index rect invalid. | |
| 44 void ClampTo(const IndexRect& other); | |
| 45 | |
| 46 // Returns true if the given index identified by index_x and index_y falls | |
| 47 // inside this index rectangle, including edge indices. | |
| 48 bool Contains(int index_x, int index_y) const; | |
| 49 | |
| 50 std::string ToString() const; | |
| 51 | |
| 52 private: | |
| 53 int left_; | |
| 54 int right_; | |
| 55 int top_; | |
| 56 int bottom_; | |
| 57 }; | |
| 58 | |
| 59 inline bool operator==(const IndexRect& lhs, const IndexRect& rhs) { | |
| 60 return lhs.left() == rhs.left() && lhs.right() == rhs.right() && | |
| 61 lhs.top() == rhs.top() && lhs.bottom() == rhs.bottom(); | |
| 62 } | |
| 63 | |
| 64 inline bool operator!=(const IndexRect& lhs, const IndexRect& rhs) { | |
| 65 return !(lhs == rhs); | |
| 66 } | |
| 67 | |
| 68 } // namespace cc | |
| 69 | |
| 70 #endif // CC_BASE_INDEX_RECT_H_ | |
| OLD | NEW |