| 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 #include "cc/math/int_rect.h" |
| 6 |
| 7 #include <algorithm> |
| 8 |
| 9 using std::min; |
| 10 using std::max; |
| 11 |
| 12 namespace ccmath { |
| 13 |
| 14 bool IntRect::Contains(IntRect other) const { |
| 15 return |
| 16 x() <= other.x() && max_x() >= other.max_x() && |
| 17 y() <= other.y() && max_y() >= other.max_y(); |
| 18 } |
| 19 |
| 20 bool IntRect::IsEmpty() const { |
| 21 return m_size.IsEmpty(); |
| 22 } |
| 23 |
| 24 void IntRect::InflateX(float amount) { |
| 25 set_x(x() + amount); |
| 26 } |
| 27 |
| 28 void IntRect::InflateY(float amount) { |
| 29 set_y(y() + amount); |
| 30 } |
| 31 |
| 32 void IntRect::InflateWidth(float amount) { |
| 33 set_width(width() + amount); |
| 34 } |
| 35 |
| 36 void IntRect::InflateHeight(float amount) { |
| 37 set_height(height() + amount); |
| 38 } |
| 39 |
| 40 void IntRect::Intersect(IntRect other) { |
| 41 int min_x = max(x(), other.x()); |
| 42 int min_y = max(y(), other.y()); |
| 43 int max_x = min(this->max_x(), other.max_x()); |
| 44 int max_y = min(this->max_y(), other.max_y()); |
| 45 |
| 46 set_x(min_x); |
| 47 set_y(min_y); |
| 48 set_width(max_x - min_x); |
| 49 set_height(max_y - min_y); |
| 50 m_size.ClampToNonNegative(); |
| 51 } |
| 52 |
| 53 void IntRect::Unite(IntRect other) { |
| 54 int min_x = min(x(), other.x()); |
| 55 int min_y = min(y(), other.y()); |
| 56 int max_x = max(this->max_x(), other.max_x()); |
| 57 int max_y = max(this->max_y(), other.max_y()); |
| 58 |
| 59 set_x(min_x); |
| 60 set_y(min_y); |
| 61 set_width(max_x - min_x); |
| 62 set_height(max_y - min_y); |
| 63 } |
| 64 |
| 65 IntRect IntRect::Intersection(IntRect a, IntRect b) { |
| 66 IntRect result = a; |
| 67 result.Intersect(b); |
| 68 return result; |
| 69 } |
| 70 |
| 71 IntRect IntRect::Union(IntRect a, IntRect b) { |
| 72 IntRect result = a; |
| 73 result.Unite(b); |
| 74 return result; |
| 75 } |
| 76 |
| 77 } // namespace ccmath |
| OLD | NEW |