From 7307ecdb60d6a4e8e575bbc2e2f8949cfb8d09f8 Mon Sep 17 00:00:00 2001 From: "danakj@chromium.org" Date: Wed, 31 Oct 2012 23:44:19 +0000 Subject: 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 --- ui/gfx/point_unittest.cc | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'ui/gfx/point_unittest.cc') 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 -- cgit v1.1