diff options
author | danakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-31 23:44:19 +0000 |
---|---|---|
committer | danakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-31 23:44:19 +0000 |
commit | 7307ecdb60d6a4e8e575bbc2e2f8949cfb8d09f8 (patch) | |
tree | 3dda28c09d55f076505854857cd446f0659afe1c /ui/gfx | |
parent | 4fd37058660780f82ea76292efaa96673c5c0479 (diff) | |
download | chromium_src-7307ecdb60d6a4e8e575bbc2e2f8949cfb8d09f8.zip chromium_src-7307ecdb60d6a4e8e575bbc2e2f8949cfb8d09f8.tar.gz chromium_src-7307ecdb60d6a4e8e575bbc2e2f8949cfb8d09f8.tar.bz2 |
ui: Add gfx::ToRoundedPoint() method.
This acts like ToRoundedSize, it returns a Point from a PointF, where each
component is rounded to the nearest integer.
Tests:
ui_unittests:PointTest.ToRoundedPoint
BUG=147395
R=sky
Review URL: https://codereview.chromium.org/11369013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@165261 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx')
-rw-r--r-- | ui/gfx/point_conversions.cc | 6 | ||||
-rw-r--r-- | ui/gfx/point_conversions.h | 3 | ||||
-rw-r--r-- | ui/gfx/point_unittest.cc | 36 |
3 files changed, 45 insertions, 0 deletions
diff --git a/ui/gfx/point_conversions.cc b/ui/gfx/point_conversions.cc index 7f85571..f7845a0 100644 --- a/ui/gfx/point_conversions.cc +++ b/ui/gfx/point_conversions.cc @@ -20,5 +20,11 @@ Point ToCeiledPoint(const PointF& point) { return Point(x, y); } +Point ToRoundedPoint(const PointF& point) { + int x = ToRoundedInt(point.x()); + int y = ToRoundedInt(point.y()); + return Point(x, y); +} + } // namespace gfx diff --git a/ui/gfx/point_conversions.h b/ui/gfx/point_conversions.h index 5c43610..9467a92 100644 --- a/ui/gfx/point_conversions.h +++ b/ui/gfx/point_conversions.h @@ -16,6 +16,9 @@ UI_EXPORT Point ToFlooredPoint(const PointF& point); // Returns a Point with each component from the input PointF ceiled. UI_EXPORT Point ToCeiledPoint(const PointF& point); +// Returns a Point with each component from the input PointF rounded. +UI_EXPORT Point ToRoundedPoint(const PointF& point); + } // namespace gfx #endif // UI_GFX_POINT_CONVERSIONS_H_ diff --git a/ui/gfx/point_unittest.cc b/ui/gfx/point_unittest.cc index ea42b53..a95b6cf 100644 --- a/ui/gfx/point_unittest.cc +++ b/ui/gfx/point_unittest.cc @@ -7,6 +7,7 @@ #include "base/basictypes.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/gfx/point.h" +#include "ui/gfx/point_conversions.h" #include "ui/gfx/point_f.h" namespace ui { @@ -80,4 +81,39 @@ TEST(PointTest, OffsetFromPoint) { (b - a).ToString()); } +TEST(PointTest, ToRoundedPoint) { + EXPECT_EQ(gfx::Point(0, 0), + gfx::ToRoundedPoint(gfx::PointF(0, 0))); + EXPECT_EQ(gfx::Point(0, 0), + gfx::ToRoundedPoint(gfx::PointF(0.0001f, 0.0001f))); + EXPECT_EQ(gfx::Point(0, 0), + gfx::ToRoundedPoint(gfx::PointF(0.4999f, 0.4999f))); + EXPECT_EQ(gfx::Point(1, 1), + gfx::ToRoundedPoint(gfx::PointF(0.5f, 0.5f))); + EXPECT_EQ(gfx::Point(1, 1), + gfx::ToRoundedPoint(gfx::PointF(0.9999f, 0.9999f))); + + EXPECT_EQ(gfx::Point(10, 10), + gfx::ToRoundedPoint(gfx::PointF(10, 10))); + EXPECT_EQ(gfx::Point(10, 10), + gfx::ToRoundedPoint(gfx::PointF(10.0001f, 10.0001f))); + EXPECT_EQ(gfx::Point(10, 10), + gfx::ToRoundedPoint(gfx::PointF(10.4999f, 10.4999f))); + EXPECT_EQ(gfx::Point(11, 11), + gfx::ToRoundedPoint(gfx::PointF(10.5f, 10.5f))); + EXPECT_EQ(gfx::Point(11, 11), + gfx::ToRoundedPoint(gfx::PointF(10.9999f, 10.9999f))); + + EXPECT_EQ(gfx::Point(-10, -10), + gfx::ToRoundedPoint(gfx::PointF(-10, -10))); + EXPECT_EQ(gfx::Point(-10, -10), + gfx::ToRoundedPoint(gfx::PointF(-10.0001f, -10.0001f))); + EXPECT_EQ(gfx::Point(-10, -10), + gfx::ToRoundedPoint(gfx::PointF(-10.4999f, -10.4999f))); + EXPECT_EQ(gfx::Point(-11, -11), + gfx::ToRoundedPoint(gfx::PointF(-10.5f, -10.5f))); + EXPECT_EQ(gfx::Point(-11, -11), + gfx::ToRoundedPoint(gfx::PointF(-10.9999f, -10.9999f))); +} + } // namespace ui |