OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gfx/rect_f.h" | 5 #include "ui/gfx/rect_f.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 IsExpressibleAsInt(width()) && IsExpressibleAsInt(height()) && | 45 IsExpressibleAsInt(width()) && IsExpressibleAsInt(height()) && |
46 IsExpressibleAsInt(right()) && IsExpressibleAsInt(bottom()); | 46 IsExpressibleAsInt(right()) && IsExpressibleAsInt(bottom()); |
47 } | 47 } |
48 | 48 |
49 std::string RectF::ToString() const { | 49 std::string RectF::ToString() const { |
50 return base::StringPrintf("%s %s", | 50 return base::StringPrintf("%s %s", |
51 origin().ToString().c_str(), | 51 origin().ToString().c_str(), |
52 size().ToString().c_str()); | 52 size().ToString().c_str()); |
53 } | 53 } |
54 | 54 |
| 55 RectF operator+(const RectF& lhs, const Vector2dF& rhs) { |
| 56 RectF result(lhs); |
| 57 result += rhs; |
| 58 return result; |
| 59 } |
| 60 |
| 61 RectF operator-(const RectF& lhs, const Vector2dF& rhs) { |
| 62 RectF result(lhs); |
| 63 result -= rhs; |
| 64 return result; |
| 65 } |
| 66 |
55 RectF IntersectRects(const RectF& a, const RectF& b) { | 67 RectF IntersectRects(const RectF& a, const RectF& b) { |
56 RectF result = a; | 68 RectF result = a; |
57 result.Intersect(b); | 69 result.Intersect(b); |
58 return result; | 70 return result; |
59 } | 71 } |
60 | 72 |
61 RectF UnionRects(const RectF& a, const RectF& b) { | 73 RectF UnionRects(const RectF& a, const RectF& b) { |
62 RectF result = a; | 74 RectF result = a; |
63 result.Union(b); | 75 result.Union(b); |
64 return result; | 76 return result; |
(...skipping 13 matching lines...) Expand all Loading... |
78 | 90 |
79 RectF BoundingRect(const PointF& p1, const PointF& p2) { | 91 RectF BoundingRect(const PointF& p1, const PointF& p2) { |
80 float rx = std::min(p1.x(), p2.x()); | 92 float rx = std::min(p1.x(), p2.x()); |
81 float ry = std::min(p1.y(), p2.y()); | 93 float ry = std::min(p1.y(), p2.y()); |
82 float rr = std::max(p1.x(), p2.x()); | 94 float rr = std::max(p1.x(), p2.x()); |
83 float rb = std::max(p1.y(), p2.y()); | 95 float rb = std::max(p1.y(), p2.y()); |
84 return RectF(rx, ry, rr - rx, rb - ry); | 96 return RectF(rx, ry, rr - rx, rb - ry); |
85 } | 97 } |
86 | 98 |
87 } // namespace gfx | 99 } // namespace gfx |
OLD | NEW |