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_conversions.h" | 5 #include "ui/gfx/rect_conversions.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "ui/gfx/safe_integer_conversions.h" | 10 #include "ui/gfx/safe_integer_conversions.h" |
11 | 11 |
12 namespace gfx { | 12 namespace gfx { |
13 | 13 |
14 Rect ToEnclosingRect(const RectF& rect) { | 14 Rect ToEnclosingRect(const RectF& rect) { |
15 int min_x = ToFlooredInt(rect.x()); | 15 int min_x = ToFlooredInt(rect.x()); |
16 int min_y = ToFlooredInt(rect.y()); | 16 int min_y = ToFlooredInt(rect.y()); |
17 float max_x = rect.right(); | 17 float max_x = rect.right(); |
18 float max_y = rect.bottom(); | 18 float max_y = rect.bottom(); |
19 int width = std::max(ToCeiledInt(max_x) - min_x, 0); | 19 int width = rect.width() == 0 ? 0 : std::max(ToCeiledInt(max_x) - min_x, 0); |
20 int height = std::max(ToCeiledInt(max_y) - min_y, 0); | 20 int height = rect.height() == 0 ? 0 : std::max(ToCeiledInt(max_y) - min_y, 0); |
21 return Rect(min_x, min_y, width, height); | 21 return Rect(min_x, min_y, width, height); |
22 } | 22 } |
23 | 23 |
24 Rect ToEnclosedRect(const RectF& rect) { | 24 Rect ToEnclosedRect(const RectF& rect) { |
25 int min_x = ToCeiledInt(rect.x()); | 25 int min_x = ToCeiledInt(rect.x()); |
26 int min_y = ToCeiledInt(rect.y()); | 26 int min_y = ToCeiledInt(rect.y()); |
27 float max_x = rect.right(); | 27 float max_x = rect.right(); |
28 float max_y = rect.bottom(); | 28 float max_y = rect.bottom(); |
29 int width = std::max(ToFlooredInt(max_x) - min_x, 0); | 29 int width = std::max(ToFlooredInt(max_x) - min_x, 0); |
30 int height = std::max(ToFlooredInt(max_y) - min_y, 0); | 30 int height = std::max(ToFlooredInt(max_y) - min_y, 0); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 72 |
73 Rect ToFlooredRectDeprecated(const RectF& rect) { | 73 Rect ToFlooredRectDeprecated(const RectF& rect) { |
74 return Rect(ToFlooredInt(rect.x()), | 74 return Rect(ToFlooredInt(rect.x()), |
75 ToFlooredInt(rect.y()), | 75 ToFlooredInt(rect.y()), |
76 ToFlooredInt(rect.width()), | 76 ToFlooredInt(rect.width()), |
77 ToFlooredInt(rect.height())); | 77 ToFlooredInt(rect.height())); |
78 } | 78 } |
79 | 79 |
80 } // namespace gfx | 80 } // namespace gfx |
81 | 81 |
OLD | NEW |