summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authoracolwell@chromium.org <acolwell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-10 20:05:50 +0000
committeracolwell@chromium.org <acolwell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-10 20:05:50 +0000
commit6fc49f5689315ec0cd9a05f0a6e4dea1cf9f9e55 (patch)
treea169994402b91887b479e9429b96cd28fd8dfd98 /ui
parentaa7797cc5959b3154cd4ae154a9316819ac5b74e (diff)
downloadchromium_src-6fc49f5689315ec0cd9a05f0a6e4dea1cf9f9e55.zip
chromium_src-6fc49f5689315ec0cd9a05f0a6e4dea1cf9f9e55.tar.gz
chromium_src-6fc49f5689315ec0cd9a05f0a6e4dea1cf9f9e55.tar.bz2
Revert 161137 - Add gfx::ToRoundedInt safe conversion method from float to int.
BUG=147395 R=sky@chromium.org Review URL: https://chromiumcodereview.appspot.com/11093031 TBR=danakj@chromium.org Review URL: https://codereview.chromium.org/11091049 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@161167 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/gfx/point_conversions.cc2
-rw-r--r--ui/gfx/rect_conversions.cc2
-rw-r--r--ui/gfx/safe_floor_ceil.cc (renamed from ui/gfx/safe_integer_conversions.cc)16
-rw-r--r--ui/gfx/safe_floor_ceil.h (renamed from ui/gfx/safe_integer_conversions.h)9
-rw-r--r--ui/gfx/safe_integer_conversions_unittest.cc109
-rw-r--r--ui/gfx/size_conversions.cc2
-rw-r--r--ui/ui.gyp4
-rw-r--r--ui/ui_unittests.gypi1
8 files changed, 11 insertions, 134 deletions
diff --git a/ui/gfx/point_conversions.cc b/ui/gfx/point_conversions.cc
index 7f85571..0788ef7 100644
--- a/ui/gfx/point_conversions.cc
+++ b/ui/gfx/point_conversions.cc
@@ -4,7 +4,7 @@
#include "ui/gfx/point_conversions.h"
-#include "ui/gfx/safe_integer_conversions.h"
+#include "ui/gfx/safe_floor_ceil.h"
namespace gfx {
diff --git a/ui/gfx/rect_conversions.cc b/ui/gfx/rect_conversions.cc
index 265915a..0d8fdb5 100644
--- a/ui/gfx/rect_conversions.cc
+++ b/ui/gfx/rect_conversions.cc
@@ -4,7 +4,7 @@
#include "ui/gfx/rect_conversions.h"
-#include "ui/gfx/safe_integer_conversions.h"
+#include "ui/gfx/safe_floor_ceil.h"
namespace gfx {
diff --git a/ui/gfx/safe_integer_conversions.cc b/ui/gfx/safe_floor_ceil.cc
index e354353..c8ac9e1 100644
--- a/ui/gfx/safe_integer_conversions.cc
+++ b/ui/gfx/safe_floor_ceil.cc
@@ -2,8 +2,6 @@
// 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>
@@ -12,9 +10,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);
}
@@ -27,13 +25,5 @@ int ToCeiledInt(float value) {
return ClampToInt(std::ceil(value));
}
-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
+
diff --git a/ui/gfx/safe_integer_conversions.h b/ui/gfx/safe_floor_ceil.h
index 1cbfb88..c2d80c6 100644
--- a/ui/gfx/safe_integer_conversions.h
+++ b/ui/gfx/safe_floor_ceil.h
@@ -2,18 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef UI_GFX_SAFE_INTEGER_CONVERSIONS_H_
-#define UI_GFX_SAFE_INTEGER_CONVERSIONS_H_
-
-#include "ui/base/ui_export.h"
+#ifndef UI_GFX_SAFE_FLOOR_CEIL_H_
+#define UI_GFX_SAFE_FLOOR_CEIL_H_
namespace gfx {
UI_EXPORT int ClampToInt(float value);
UI_EXPORT int ToFlooredInt(float value);
UI_EXPORT int ToCeiledInt(float value);
-UI_EXPORT int ToRoundedInt(float value);
} // namespace gfx
-#endif // UI_GFX_SAFE_INTEGER_CONVERSIONS_H_
+#endif // UI_GFX_SAFE_FLOOR_CEIL_H_
diff --git a/ui/gfx/safe_integer_conversions_unittest.cc b/ui/gfx/safe_integer_conversions_unittest.cc
deleted file mode 100644
index b7592be..0000000
--- a/ui/gfx/safe_integer_conversions_unittest.cc
+++ /dev/null
@@ -1,109 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// 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 <limits>
-
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace ui {
-
-TEST(SafeIntegerConversions, ClampToInt) {
- EXPECT_EQ(0, gfx::ClampToInt(std::numeric_limits<float>::quiet_NaN()));
-
- float max = std::numeric_limits<int>::max();
- float min = std::numeric_limits<int>::min();
-
- EXPECT_EQ(max, gfx::ClampToInt(std::numeric_limits<float>::infinity()));
- EXPECT_EQ(max, gfx::ClampToInt(max));
- EXPECT_EQ(max, gfx::ClampToInt(max + 1));
- EXPECT_EQ(max - 1, gfx::ClampToInt(max - 1));
-
- EXPECT_EQ(-100, gfx::ClampToInt(-100.5f));
- EXPECT_EQ(0, gfx::ClampToInt(0));
- EXPECT_EQ(100, gfx::ClampToInt(100.5f));
-
- EXPECT_EQ(min, gfx::ClampToInt(-std::numeric_limits<float>::infinity()));
- EXPECT_EQ(min, gfx::ClampToInt(min));
- EXPECT_EQ(min, gfx::ClampToInt(min - 1));
- EXPECT_EQ(min + 1, gfx::ClampToInt(min + 1));
-}
-
-TEST(SafeIntegerConversions, ToFlooredInt) {
- EXPECT_EQ(0, gfx::ToFlooredInt(std::numeric_limits<float>::quiet_NaN()));
-
- float max = std::numeric_limits<int>::max();
- float min = std::numeric_limits<int>::min();
-
- EXPECT_EQ(max, gfx::ToFlooredInt(std::numeric_limits<float>::infinity()));
- EXPECT_EQ(max, gfx::ToFlooredInt(max));
- EXPECT_EQ(max, gfx::ToFlooredInt(max + 0.5f));
- EXPECT_EQ(max - 1, gfx::ToFlooredInt(max - 0.5f));
-
- EXPECT_EQ(-101, gfx::ToFlooredInt(-100.5f));
- EXPECT_EQ(0, gfx::ToFlooredInt(0));
- EXPECT_EQ(100, gfx::ToFlooredInt(100.5f));
-
- EXPECT_EQ(min, gfx::ToFlooredInt(-std::numeric_limits<float>::infinity()));
- EXPECT_EQ(min, gfx::ToFlooredInt(min));
- EXPECT_EQ(min, gfx::ToFlooredInt(min - 0.5f));
- EXPECT_EQ(min, gfx::ToFlooredInt(min + 0.5f));
-}
-
-TEST(SafeIntegerConversions, ToCeiledInt) {
- EXPECT_EQ(0, gfx::ToCeiledInt(std::numeric_limits<float>::quiet_NaN()));
-
- float max = std::numeric_limits<int>::max();
- float min = std::numeric_limits<int>::min();
-
- EXPECT_EQ(max, gfx::ToCeiledInt(std::numeric_limits<float>::infinity()));
- EXPECT_EQ(max, gfx::ToCeiledInt(max));
- EXPECT_EQ(max, gfx::ToCeiledInt(max + 0.5f));
- EXPECT_EQ(max, gfx::ToCeiledInt(max - 0.5f));
-
- EXPECT_EQ(-100, gfx::ToCeiledInt(-100.5f));
- EXPECT_EQ(0, gfx::ToCeiledInt(0));
- EXPECT_EQ(101, gfx::ToCeiledInt(100.5f));
-
- EXPECT_EQ(min, gfx::ToCeiledInt(-std::numeric_limits<float>::infinity()));
- EXPECT_EQ(min, gfx::ToCeiledInt(min));
- EXPECT_EQ(min, gfx::ToCeiledInt(min - 0.5f));
- EXPECT_EQ(min + 1, gfx::ToCeiledInt(min + 0.5f));
-}
-
-TEST(SafeIntegerConversions, ToRoundedInt) {
- EXPECT_EQ(0, gfx::ToRoundedInt(std::numeric_limits<float>::quiet_NaN()));
-
- float max = std::numeric_limits<int>::max();
- float min = std::numeric_limits<int>::min();
-
- EXPECT_EQ(max, gfx::ToRoundedInt(std::numeric_limits<float>::infinity()));
- EXPECT_EQ(max, gfx::ToRoundedInt(max));
- EXPECT_EQ(max, gfx::ToRoundedInt(max + 0.1f));
- EXPECT_EQ(max, gfx::ToRoundedInt(max + 0.5f));
- EXPECT_EQ(max, gfx::ToRoundedInt(max + 0.9f));
- EXPECT_EQ(max, gfx::ToRoundedInt(max - 0.1f));
- EXPECT_EQ(max, gfx::ToRoundedInt(max - 0.5f));
- EXPECT_EQ(max - 1, gfx::ToRoundedInt(max - 0.9f));
-
- EXPECT_EQ(-100, gfx::ToRoundedInt(-100.1f));
- EXPECT_EQ(-101, gfx::ToRoundedInt(-100.5f));
- EXPECT_EQ(-101, gfx::ToRoundedInt(-100.9f));
- EXPECT_EQ(0, gfx::ToRoundedInt(0));
- EXPECT_EQ(100, gfx::ToRoundedInt(100.1f));
- EXPECT_EQ(101, gfx::ToRoundedInt(100.5f));
- EXPECT_EQ(101, gfx::ToRoundedInt(100.9f));
-
- EXPECT_EQ(min, gfx::ToRoundedInt(-std::numeric_limits<float>::infinity()));
- EXPECT_EQ(min, gfx::ToRoundedInt(min));
- EXPECT_EQ(min, gfx::ToRoundedInt(min - 0.1f));
- EXPECT_EQ(min, gfx::ToRoundedInt(min - 0.5f));
- EXPECT_EQ(min, gfx::ToRoundedInt(min - 0.9f));
- EXPECT_EQ(min, gfx::ToRoundedInt(min + 0.1f));
- EXPECT_EQ(min + 1, gfx::ToRoundedInt(min + 0.5f));
- EXPECT_EQ(min + 1, gfx::ToRoundedInt(min + 0.9f));
-}
-
-} // namespace ui
diff --git a/ui/gfx/size_conversions.cc b/ui/gfx/size_conversions.cc
index 7fb3d24..9668aaa 100644
--- a/ui/gfx/size_conversions.cc
+++ b/ui/gfx/size_conversions.cc
@@ -4,7 +4,7 @@
#include "ui/gfx/size_conversions.h"
-#include "ui/gfx/safe_integer_conversions.h"
+#include "ui/gfx/safe_floor_ceil.h"
namespace gfx {
diff --git a/ui/ui.gyp b/ui/ui.gyp
index b5e6871..9d99b41 100644
--- a/ui/ui.gyp
+++ b/ui/ui.gyp
@@ -152,8 +152,8 @@
'gfx/rect_conversions.h',
'gfx/rect_f.cc',
'gfx/rect_f.h',
- 'gfx/safe_integer_conversions.cc',
- 'gfx/safe_integer_conversions.h',
+ 'gfx/safe_floor_ceil.cc',
+ 'gfx/safe_floor_ceil.h',
'gfx/scoped_ui_graphics_push_context_ios.h',
'gfx/scoped_ui_graphics_push_context_ios.mm',
'gfx/screen.h',
diff --git a/ui/ui_unittests.gypi b/ui/ui_unittests.gypi
index c87279e..b29649a 100644
--- a/ui/ui_unittests.gypi
+++ b/ui/ui_unittests.gypi
@@ -81,7 +81,6 @@
'gfx/image/image_unittest_util_mac.mm',
'gfx/insets_unittest.cc',
'gfx/rect_unittest.cc',
- 'gfx/safe_integer_conversions_unittest.cc',
'gfx/screen_unittest.cc',
'gfx/shadow_value_unittest.cc',
'gfx/skbitmap_operations_unittest.cc',