| 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/float_rect.h" |
| 6 |
| 7 #include <algorithm> |
| 8 |
| 9 using std::min; |
| 10 using std::max; |
| 11 |
| 12 namespace ccmath { |
| 13 |
| 14 bool FloatRect::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 FloatRect::IsEmpty() const { |
| 21 return m_size.IsEmpty(); |
| 22 } |
| 23 |
| 24 IntRect FloatRect::EnclosingIntRect() const { |
| 25 FloatPoint min_xy = m_location; |
| 26 FloatPoint max_xy = FloatPoint(max_x(), max_y()); |
| 27 |
| 28 IntPoint floored_min_xy = min_xy.FlooredIntPoint(); |
| 29 IntPoint ceiled_max_xy = max_xy.CeiledIntPoint(); |
| 30 |
| 31 IntSize size(ceiled_max_xy.x() - floored_min_xy.x(), |
| 32 ceiled_max_xy.y() - floored_min_xy.y()); |
| 33 |
| 34 return IntRect(floored_min_xy, size); |
| 35 } |
| 36 |
| 37 IntRect FloatRect::EnclosedIntRect() const { |
| 38 FloatPoint min_xy = m_location; |
| 39 FloatPoint max_xy = FloatPoint(max_x(), max_y()); |
| 40 |
| 41 IntPoint ceiled_min_xy = min_xy.CeiledIntPoint(); |
| 42 IntPoint floored_max_xy = max_xy.FlooredIntPoint(); |
| 43 |
| 44 IntSize size(floored_max_xy.x() - ceiled_min_xy.x(), |
| 45 floored_max_xy.y() - ceiled_min_xy.y()); |
| 46 size.ClampToNonNegative(); |
| 47 |
| 48 return IntRect(ceiled_min_xy, size); |
| 49 } |
| 50 |
| 51 void FloatRect::InflateX(float amount) { |
| 52 set_x(x() + amount); |
| 53 } |
| 54 |
| 55 void FloatRect::InflateY(float amount) { |
| 56 set_y(y() + amount); |
| 57 } |
| 58 |
| 59 void FloatRect::InflateWidth(float amount) { |
| 60 set_width(width() + amount); |
| 61 } |
| 62 |
| 63 void FloatRect::InflateHeight(float amount) { |
| 64 set_height(height() + amount); |
| 65 } |
| 66 |
| 67 void FloatRect::Intersect(FloatRect other) { |
| 68 float min_x = max(x(), other.x()); |
| 69 float min_y = max(y(), other.y()); |
| 70 float max_x = min(this->max_x(), other.max_x()); |
| 71 float max_y = min(this->max_y(), other.max_y()); |
| 72 |
| 73 set_x(min_x); |
| 74 set_y(min_y); |
| 75 set_width(max_x - min_x); |
| 76 set_height(max_y - min_y); |
| 77 m_size.ClampToNonNegative(); |
| 78 } |
| 79 |
| 80 void FloatRect::Scale(float scale_x, float scale_y) { |
| 81 set_x(x() * scale_x); |
| 82 set_y(y() * scale_y); |
| 83 set_width(width() * scale_x); |
| 84 set_height(height() * scale_y); |
| 85 } |
| 86 |
| 87 void FloatRect::Unite(FloatRect other) { |
| 88 float min_x = min(x(), other.x()); |
| 89 float min_y = min(y(), other.y()); |
| 90 float max_x = max(this->max_x(), other.max_x()); |
| 91 float max_y = max(this->max_y(), other.max_y()); |
| 92 |
| 93 set_x(min_x); |
| 94 set_y(min_y); |
| 95 set_width(max_x - min_x); |
| 96 set_height(max_y - min_y); |
| 97 } |
| 98 |
| 99 FloatRect FloatRect::Intersection(FloatRect a, FloatRect b) { |
| 100 FloatRect result = a; |
| 101 result.Intersect(b); |
| 102 return result; |
| 103 } |
| 104 |
| 105 FloatRect FloatRect::Union(FloatRect a, FloatRect b) { |
| 106 FloatRect result = a; |
| 107 result.Unite(b); |
| 108 return result; |
| 109 } |
| 110 |
| 111 } // namespace ccmath |
| OLD | NEW |