Chromium Code Reviews| 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 // This is the minimum size of a float rect dimension for use to include it | |
| 16 // in the enclosing int rect. | |
| 17 static const float kEmptyDimension = 0.1f; | |
|
Peter Mayo
2017/03/20 18:53:50
That is too big - it causes unittests to fail. (oc
| |
| 15 Rect ToEnclosingRect(const RectF& rect) { | 18 Rect ToEnclosingRect(const RectF& rect) { |
| 16 int min_x = ToFlooredInt(rect.x()); | 19 int min_x = ToFlooredInt(rect.x()); |
| 17 int min_y = ToFlooredInt(rect.y()); | 20 int min_y = ToFlooredInt(rect.y()); |
| 18 float max_x = rect.right(); | 21 float max_x = rect.right(); |
| 19 float max_y = rect.bottom(); | 22 float max_y = rect.bottom(); |
| 20 int width = | 23 int width = |
| 21 rect.width() == 0 | 24 rect.width() < kEmptyDimension |
| 22 ? 0 | 25 ? 0 |
| 23 : std::max( | 26 : std::max( |
| 24 ToCeiledInt(static_cast<double>(ToCeiledInt(max_x)) - min_x), | 27 ToCeiledInt(static_cast<double>(ToCeiledInt(max_x)) - min_x), |
| 25 0); | 28 0); |
| 26 int height = | 29 int height = |
| 27 rect.height() == 0 | 30 rect.height() < kEmptyDimension |
| 28 ? 0 | 31 ? 0 |
| 29 : std::max( | 32 : std::max( |
| 30 ToCeiledInt(static_cast<double>(ToCeiledInt(max_y)) - min_y), | 33 ToCeiledInt(static_cast<double>(ToCeiledInt(max_y)) - min_y), |
| 31 0); | 34 0); |
| 32 return Rect(min_x, min_y, width, height); | 35 return Rect(min_x, min_y, width, height); |
| 33 } | 36 } |
| 34 | 37 |
| 35 Rect ToEnclosedRect(const RectF& rect) { | 38 Rect ToEnclosedRect(const RectF& rect) { |
| 36 int min_x = ToCeiledInt(rect.x()); | 39 int min_x = ToCeiledInt(rect.x()); |
| 37 int min_y = ToCeiledInt(rect.y()); | 40 int min_y = ToCeiledInt(rect.y()); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 | 88 |
| 86 Rect ToFlooredRectDeprecated(const RectF& rect) { | 89 Rect ToFlooredRectDeprecated(const RectF& rect) { |
| 87 return Rect(ToFlooredInt(rect.x()), | 90 return Rect(ToFlooredInt(rect.x()), |
| 88 ToFlooredInt(rect.y()), | 91 ToFlooredInt(rect.y()), |
| 89 ToFlooredInt(rect.width()), | 92 ToFlooredInt(rect.width()), |
| 90 ToFlooredInt(rect.height())); | 93 ToFlooredInt(rect.height())); |
| 91 } | 94 } |
| 92 | 95 |
| 93 } // namespace gfx | 96 } // namespace gfx |
| 94 | 97 |
| OLD | NEW |