| Index: ui/gfx/safe_integer_conversions.cc
|
| diff --git a/ui/gfx/safe_floor_ceil.cc b/ui/gfx/safe_integer_conversions.cc
|
| similarity index 64%
|
| rename from ui/gfx/safe_floor_ceil.cc
|
| rename to ui/gfx/safe_integer_conversions.cc
|
| index c8ac9e1c9e524e8508fcdb0ac3f0bc4a50e5cd14..e3543533e48d4e86a66bd094f907db26b211c875 100644
|
| --- a/ui/gfx/safe_floor_ceil.cc
|
| +++ b/ui/gfx/safe_integer_conversions.cc
|
| @@ -2,6 +2,8 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +#include "ui/gfx/safe_integer_conversions.h"
|
| +
|
| #include <cmath>
|
| #include <limits>
|
|
|
| @@ -10,9 +12,9 @@ namespace gfx {
|
| int ClampToInt(float value) {
|
| if (value != value)
|
| return 0; // no int NaN.
|
| - if (value > std::numeric_limits<int>::max())
|
| + if (value >= std::numeric_limits<int>::max())
|
| return std::numeric_limits<int>::max();
|
| - if (value < std::numeric_limits<int>::min())
|
| + if (value <= std::numeric_limits<int>::min())
|
| return std::numeric_limits<int>::min();
|
| return static_cast<int>(value);
|
| }
|
| @@ -25,5 +27,13 @@ int ToCeiledInt(float value) {
|
| return ClampToInt(std::ceil(value));
|
| }
|
|
|
| -} // namespace gfx
|
| +int ToRoundedInt(float value) {
|
| + float rounded;
|
| + if (value >= 0.0f)
|
| + rounded = std::floor(value + 0.5f);
|
| + else
|
| + rounded = std::ceil(value - 0.5f);
|
| + return ClampToInt(rounded);
|
| +}
|
|
|
| +} // namespace gfx
|
|
|