| 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 = |
| 21 rect.width() == 0 | 21 rect.width() == 0 |
| 22 ? 0 | 22 ? 0 |
| 23 : std::max( | 23 : std::max( |
| 24 ToCeiledInt(static_cast<float>(ToCeiledInt(max_x)) - min_x), 0); | 24 ToCeiledInt(static_cast<double>(ToCeiledInt(max_x)) - min_x), |
| 25 0); |
| 25 int height = | 26 int height = |
| 26 rect.height() == 0 | 27 rect.height() == 0 |
| 27 ? 0 | 28 ? 0 |
| 28 : std::max( | 29 : std::max( |
| 29 ToCeiledInt(static_cast<float>(ToCeiledInt(max_y)) - min_y), 0); | 30 ToCeiledInt(static_cast<double>(ToCeiledInt(max_y)) - min_y), |
| 31 0); |
| 30 return Rect(min_x, min_y, width, height); | 32 return Rect(min_x, min_y, width, height); |
| 31 } | 33 } |
| 32 | 34 |
| 33 Rect ToEnclosedRect(const RectF& rect) { | 35 Rect ToEnclosedRect(const RectF& rect) { |
| 34 int min_x = ToCeiledInt(rect.x()); | 36 int min_x = ToCeiledInt(rect.x()); |
| 35 int min_y = ToCeiledInt(rect.y()); | 37 int min_y = ToCeiledInt(rect.y()); |
| 36 float max_x = rect.right(); | 38 float max_x = rect.right(); |
| 37 float max_y = rect.bottom(); | 39 float max_y = rect.bottom(); |
| 38 int width = std::max( | 40 int width = std::max( |
| 39 ToFlooredInt(static_cast<float>(ToFlooredInt(max_x)) - min_x), 0); | 41 ToFlooredInt(static_cast<float>(ToFlooredInt(max_x)) - min_x), 0); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 | 85 |
| 84 Rect ToFlooredRectDeprecated(const RectF& rect) { | 86 Rect ToFlooredRectDeprecated(const RectF& rect) { |
| 85 return Rect(ToFlooredInt(rect.x()), | 87 return Rect(ToFlooredInt(rect.x()), |
| 86 ToFlooredInt(rect.y()), | 88 ToFlooredInt(rect.y()), |
| 87 ToFlooredInt(rect.width()), | 89 ToFlooredInt(rect.width()), |
| 88 ToFlooredInt(rect.height())); | 90 ToFlooredInt(rect.height())); |
| 89 } | 91 } |
| 90 | 92 |
| 91 } // namespace gfx | 93 } // namespace gfx |
| 92 | 94 |
| OLD | NEW |