| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 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_MATH_INT_RECT_H_ |
| 6 #define CC_MATH_INT_RECT_H_ |
| 7 |
| 8 #include "cc/math/int_point.h" |
| 9 #include "cc/math/int_size.h" |
| 10 |
| 11 namespace ccmath { |
| 12 |
| 13 class IntRect { |
| 14 public: |
| 15 IntRect() { } |
| 16 IntRect(int x, int y, int w, int h) |
| 17 : m_location(x, y), |
| 18 m_size(w, h) { |
| 19 } |
| 20 IntRect(IntPoint location, IntSize size) |
| 21 : m_location(location), |
| 22 m_size(size) { |
| 23 } |
| 24 IntRect(const IntRect& rect) |
| 25 : m_location(rect.m_location), |
| 26 m_size(rect.m_size) { |
| 27 } |
| 28 |
| 29 int x() const { return m_location.x(); } |
| 30 int y() const { return m_location.y(); } |
| 31 int width() const { return m_size.width(); } |
| 32 int height() const { return m_size.height(); } |
| 33 |
| 34 int max_x() const { return m_location.x() + m_size.width(); } |
| 35 int max_y() const { return m_location.y() + m_size.height(); } |
| 36 |
| 37 void set_x(int x) { m_location.set_x(x); } |
| 38 void set_y(int y) { m_location.set_y(y); } |
| 39 void set_width(int width) { m_size.set_width(width); } |
| 40 void set_height(int height) { m_size.set_height(height); } |
| 41 |
| 42 IntPoint location() const { return m_location; } |
| 43 IntSize size() const { return m_size; } |
| 44 |
| 45 void set_location(IntPoint location) { m_location = location; } |
| 46 void set_size(IntSize size) { m_size = size; } |
| 47 |
| 48 bool Contains(IntRect other) const; |
| 49 bool IsEmpty() const; |
| 50 |
| 51 void InflateX(float amount); |
| 52 void InflateY(float amount); |
| 53 void InflateWidth(float amount); |
| 54 void InflateHeight(float amount); |
| 55 |
| 56 void Intersect(IntRect other); |
| 57 void Unite(IntRect other); |
| 58 |
| 59 static IntRect Intersection(IntRect a, IntRect b); |
| 60 static IntRect Union(IntRect a, IntRect b); |
| 61 |
| 62 private: |
| 63 IntPoint m_location; |
| 64 IntSize m_size; |
| 65 }; |
| 66 |
| 67 inline bool operator==(const IntRect& a, const IntRect& b) { |
| 68 return a.location() == b.location() && a.size() == b.size(); |
| 69 } |
| 70 |
| 71 inline bool operator!=(const IntRect& a, const IntRect& b) { |
| 72 return !(a == b); |
| 73 } |
| 74 |
| 75 } // namespace ccmath |
| 76 |
| 77 #endif // CC_MATH_INT_RECT_H_ |
| OLD | NEW |