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.h" | 5 #include "ui/gfx/rect.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
10 #include <windows.h> | 10 #include <windows.h> |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 return r; | 83 return r; |
84 } | 84 } |
85 #endif | 85 #endif |
86 | 86 |
87 std::string Rect::ToString() const { | 87 std::string Rect::ToString() const { |
88 return base::StringPrintf("%s %s", | 88 return base::StringPrintf("%s %s", |
89 origin().ToString().c_str(), | 89 origin().ToString().c_str(), |
90 size().ToString().c_str()); | 90 size().ToString().c_str()); |
91 } | 91 } |
92 | 92 |
| 93 Rect operator+(const Rect& lhs, const Vector2d& rhs) { |
| 94 Rect result(lhs); |
| 95 result += rhs; |
| 96 return result; |
| 97 } |
| 98 |
| 99 Rect operator-(const Rect& lhs, const Vector2d& rhs) { |
| 100 Rect result(lhs); |
| 101 result -= rhs; |
| 102 return result; |
| 103 } |
| 104 |
93 Rect IntersectRects(const Rect& a, const Rect& b) { | 105 Rect IntersectRects(const Rect& a, const Rect& b) { |
94 Rect result = a; | 106 Rect result = a; |
95 result.Intersect(b); | 107 result.Intersect(b); |
96 return result; | 108 return result; |
97 } | 109 } |
98 | 110 |
99 Rect UnionRects(const Rect& a, const Rect& b) { | 111 Rect UnionRects(const Rect& a, const Rect& b) { |
100 Rect result = a; | 112 Rect result = a; |
101 result.Union(b); | 113 result.Union(b); |
102 return result; | 114 return result; |
103 } | 115 } |
104 | 116 |
105 Rect SubtractRects(const Rect& a, const Rect& b) { | 117 Rect SubtractRects(const Rect& a, const Rect& b) { |
106 Rect result = a; | 118 Rect result = a; |
107 result.Subtract(b); | 119 result.Subtract(b); |
108 return result; | 120 return result; |
109 } | 121 } |
110 | 122 |
111 Rect BoundingRect(const Point& p1, const Point& p2) { | 123 Rect BoundingRect(const Point& p1, const Point& p2) { |
112 int rx = std::min(p1.x(), p2.x()); | 124 int rx = std::min(p1.x(), p2.x()); |
113 int ry = std::min(p1.y(), p2.y()); | 125 int ry = std::min(p1.y(), p2.y()); |
114 int rr = std::max(p1.x(), p2.x()); | 126 int rr = std::max(p1.x(), p2.x()); |
115 int rb = std::max(p1.y(), p2.y()); | 127 int rb = std::max(p1.y(), p2.y()); |
116 return Rect(rx, ry, rr - rx, rb - ry); | 128 return Rect(rx, ry, rr - rx, rb - ry); |
117 } | 129 } |
118 | 130 |
119 } // namespace gfx | 131 } // namespace gfx |
OLD | NEW |