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 13 matching lines...) Expand all Loading... |
24 IsExpressibleAsInt(width()) && IsExpressibleAsInt(height()) && | 24 IsExpressibleAsInt(width()) && IsExpressibleAsInt(height()) && |
25 IsExpressibleAsInt(right()) && IsExpressibleAsInt(bottom()); | 25 IsExpressibleAsInt(right()) && IsExpressibleAsInt(bottom()); |
26 } | 26 } |
27 | 27 |
28 std::string RectF::ToString() const { | 28 std::string RectF::ToString() const { |
29 return base::StringPrintf("%s %s", | 29 return base::StringPrintf("%s %s", |
30 origin().ToString().c_str(), | 30 origin().ToString().c_str(), |
31 size().ToString().c_str()); | 31 size().ToString().c_str()); |
32 } | 32 } |
33 | 33 |
34 RectF operator+(const RectF& lhs, const Vector2dF& rhs) { | |
35 RectF result(lhs); | |
36 result += rhs; | |
37 return result; | |
38 } | |
39 | |
40 RectF operator-(const RectF& lhs, const Vector2dF& rhs) { | |
41 RectF result(lhs); | |
42 result -= rhs; | |
43 return result; | |
44 } | |
45 | |
46 RectF IntersectRects(const RectF& a, const RectF& b) { | 34 RectF IntersectRects(const RectF& a, const RectF& b) { |
47 RectF result = a; | 35 RectF result = a; |
48 result.Intersect(b); | 36 result.Intersect(b); |
49 return result; | 37 return result; |
50 } | 38 } |
51 | 39 |
52 RectF UnionRects(const RectF& a, const RectF& b) { | 40 RectF UnionRects(const RectF& a, const RectF& b) { |
53 RectF result = a; | 41 RectF result = a; |
54 result.Union(b); | 42 result.Union(b); |
55 return result; | 43 return result; |
56 } | 44 } |
57 | 45 |
58 RectF SubtractRects(const RectF& a, const RectF& b) { | 46 RectF SubtractRects(const RectF& a, const RectF& b) { |
59 RectF result = a; | 47 RectF result = a; |
60 result.Subtract(b); | 48 result.Subtract(b); |
61 return result; | 49 return result; |
62 } | 50 } |
63 | 51 |
64 RectF ScaleRect(const RectF& r, float x_scale, float y_scale) { | |
65 RectF result = r; | |
66 result.Scale(x_scale, y_scale); | |
67 return result; | |
68 } | |
69 | |
70 RectF BoundingRect(const PointF& p1, const PointF& p2) { | 52 RectF BoundingRect(const PointF& p1, const PointF& p2) { |
71 float rx = std::min(p1.x(), p2.x()); | 53 float rx = std::min(p1.x(), p2.x()); |
72 float ry = std::min(p1.y(), p2.y()); | 54 float ry = std::min(p1.y(), p2.y()); |
73 float rr = std::max(p1.x(), p2.x()); | 55 float rr = std::max(p1.x(), p2.x()); |
74 float rb = std::max(p1.y(), p2.y()); | 56 float rb = std::max(p1.y(), p2.y()); |
75 return RectF(rx, ry, rr - rx, rb - ry); | 57 return RectF(rx, ry, rr - rx, rb - ry); |
76 } | 58 } |
77 | 59 |
78 } // namespace gfx | 60 } // namespace gfx |
OLD | NEW |