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/geometry/rect_conversions.h" | 5 #include "ui/gfx/geometry/rect_conversions.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "ui/gfx/geometry/safe_integer_conversions.h" | 11 #include "ui/gfx/geometry/safe_integer_conversions.h" |
12 | 12 |
13 namespace gfx { | 13 namespace gfx { |
14 | 14 |
15 Rect ToEnclosingRect(const RectF& rect) { | 15 Rect ToEnclosingRect(const RectF& rect) { |
16 int min_x = ToFlooredInt(rect.x()); | 16 int min_x = ToFlooredInt(rect.x()); |
17 int min_y = ToFlooredInt(rect.y()); | 17 int min_y = ToFlooredInt(rect.y()); |
18 float max_x = rect.right(); | 18 float max_x = rect.right(); |
19 float max_y = rect.bottom(); | 19 float max_y = rect.bottom(); |
20 int width = | 20 int width = rect.width() |
21 rect.width() == 0 | 21 ? ToCeiledInt(static_cast<double>(ToCeiledInt(max_x)) - min_x) |
22 ? 0 | 22 : 0; |
23 : std::max( | |
24 ToCeiledInt(static_cast<double>(ToCeiledInt(max_x)) - min_x), | |
25 0); | |
26 int height = | 23 int height = |
27 rect.height() == 0 | 24 rect.height() |
28 ? 0 | 25 ? ToCeiledInt(static_cast<double>(ToCeiledInt(max_y)) - min_y) |
29 : std::max( | 26 : 0; |
30 ToCeiledInt(static_cast<double>(ToCeiledInt(max_y)) - min_y), | |
31 0); | |
32 return Rect(min_x, min_y, width, height); | 27 return Rect(min_x, min_y, width, height); |
33 } | 28 } |
34 | 29 |
35 Rect ToEnclosedRect(const RectF& rect) { | 30 Rect ToEnclosedRect(const RectF& rect) { |
36 int min_x = ToCeiledInt(rect.x()); | 31 int min_x = ToCeiledInt(rect.x()); |
37 int min_y = ToCeiledInt(rect.y()); | 32 int min_y = ToCeiledInt(rect.y()); |
38 float max_x = rect.right(); | 33 float max_x = rect.right(); |
39 float max_y = rect.bottom(); | 34 float max_y = rect.bottom(); |
40 int width = std::max( | 35 int width = std::max( |
41 ToFlooredInt(static_cast<float>(ToFlooredInt(max_x)) - min_x), 0); | 36 ToFlooredInt(static_cast<float>(ToFlooredInt(max_x)) - min_x), 0); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 } | 79 } |
85 | 80 |
86 Rect ToFlooredRectDeprecated(const RectF& rect) { | 81 Rect ToFlooredRectDeprecated(const RectF& rect) { |
87 return Rect(ToFlooredInt(rect.x()), | 82 return Rect(ToFlooredInt(rect.x()), |
88 ToFlooredInt(rect.y()), | 83 ToFlooredInt(rect.y()), |
89 ToFlooredInt(rect.width()), | 84 ToFlooredInt(rect.width()), |
90 ToFlooredInt(rect.height())); | 85 ToFlooredInt(rect.height())); |
91 } | 86 } |
92 | 87 |
93 } // namespace gfx | 88 } // namespace gfx |
94 | |
OLD | NEW |