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" |
11 #include "ui/gfx/insets_f.h" | 11 #include "ui/gfx/insets_f.h" |
12 #include "ui/gfx/rect_base_impl.h" | 12 #include "ui/gfx/rect_base_impl.h" |
| 13 #include "ui/gfx/safe_integer_conversions.h" |
13 | 14 |
14 namespace gfx { | 15 namespace gfx { |
15 | 16 |
16 template class RectBase<RectF, PointF, SizeF, InsetsF, Vector2dF, float>; | 17 template class RectBase<RectF, PointF, SizeF, InsetsF, Vector2dF, float>; |
17 | 18 |
18 typedef class RectBase<RectF, PointF, SizeF, InsetsF, Vector2dF, | 19 typedef class RectBase<RectF, PointF, SizeF, InsetsF, Vector2dF, |
19 float> RectBaseT; | 20 float> RectBaseT; |
20 | 21 |
21 RectF::RectF() : RectBaseT(gfx::SizeF()) { | 22 RectF::RectF() : RectBaseT(gfx::SizeF()) { |
22 } | 23 } |
23 | 24 |
24 RectF::RectF(float width, float height) | 25 RectF::RectF(float width, float height) |
25 : RectBaseT(gfx::SizeF(width, height)) { | 26 : RectBaseT(gfx::SizeF(width, height)) { |
26 } | 27 } |
27 | 28 |
28 RectF::RectF(float x, float y, float width, float height) | 29 RectF::RectF(float x, float y, float width, float height) |
29 : RectBaseT(gfx::PointF(x, y), gfx::SizeF(width, height)) { | 30 : RectBaseT(gfx::PointF(x, y), gfx::SizeF(width, height)) { |
30 } | 31 } |
31 | 32 |
32 RectF::RectF(const gfx::SizeF& size) | 33 RectF::RectF(const gfx::SizeF& size) |
33 : RectBaseT(size) { | 34 : RectBaseT(size) { |
34 } | 35 } |
35 | 36 |
36 RectF::RectF(const gfx::PointF& origin, const gfx::SizeF& size) | 37 RectF::RectF(const gfx::PointF& origin, const gfx::SizeF& size) |
37 : RectBaseT(origin, size) { | 38 : RectBaseT(origin, size) { |
38 } | 39 } |
39 | 40 |
40 RectF::~RectF() {} | 41 RectF::~RectF() {} |
41 | 42 |
| 43 bool RectF::IsExpressibleAsRect() const { |
| 44 return IsExpressibleAsInt(x()) && IsExpressibleAsInt(y()) && |
| 45 IsExpressibleAsInt(width()) && IsExpressibleAsInt(height()) && |
| 46 IsExpressibleAsInt(right()) && IsExpressibleAsInt(bottom()); |
| 47 } |
| 48 |
42 std::string RectF::ToString() const { | 49 std::string RectF::ToString() const { |
43 return base::StringPrintf("%s %s", | 50 return base::StringPrintf("%s %s", |
44 origin().ToString().c_str(), | 51 origin().ToString().c_str(), |
45 size().ToString().c_str()); | 52 size().ToString().c_str()); |
46 } | 53 } |
47 | 54 |
48 RectF IntersectRects(const RectF& a, const RectF& b) { | 55 RectF IntersectRects(const RectF& a, const RectF& b) { |
49 RectF result = a; | 56 RectF result = a; |
50 result.Intersect(b); | 57 result.Intersect(b); |
51 return result; | 58 return result; |
(...skipping 19 matching lines...) Expand all Loading... |
71 | 78 |
72 RectF BoundingRect(const PointF& p1, const PointF& p2) { | 79 RectF BoundingRect(const PointF& p1, const PointF& p2) { |
73 float rx = std::min(p1.x(), p2.x()); | 80 float rx = std::min(p1.x(), p2.x()); |
74 float ry = std::min(p1.y(), p2.y()); | 81 float ry = std::min(p1.y(), p2.y()); |
75 float rr = std::max(p1.x(), p2.x()); | 82 float rr = std::max(p1.x(), p2.x()); |
76 float rb = std::max(p1.y(), p2.y()); | 83 float rb = std::max(p1.y(), p2.y()); |
77 return RectF(rx, ry, rr - rx, rb - ry); | 84 return RectF(rx, ry, rr - rx, rb - ry); |
78 } | 85 } |
79 | 86 |
80 } // namespace gfx | 87 } // namespace gfx |
OLD | NEW |