diff options
author | danakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-09 23:22:09 +0000 |
---|---|---|
committer | danakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-09 23:22:09 +0000 |
commit | 909afe39bf16d03f7b42740747fa4c15c27c67cc (patch) | |
tree | 13e749aca7dae865497984fb1f7856bd30653732 /ui/gfx/rect_unittest.cc | |
parent | 3683adf58bcf7041346f00014c8f12405ae5ef9f (diff) | |
download | chromium_src-909afe39bf16d03f7b42740747fa4c15c27c67cc.zip chromium_src-909afe39bf16d03f7b42740747fa4c15c27c67cc.tar.gz chromium_src-909afe39bf16d03f7b42740747fa4c15c27c67cc.tar.bz2 |
The center of a rect is x+width/2, y+height/2
If a rect is (0, 0, 5, 5) the center should be 2.5, 2.5, not 2, 2.
Tests:
ui_unittests:RectTest.CenterPoint
ui_unittests:RectTest.CenterPointF
BUG=147395
Review URL: https://chromiumcodereview.appspot.com/11065050
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@160976 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/rect_unittest.cc')
-rw-r--r-- | ui/gfx/rect_unittest.cc | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/ui/gfx/rect_unittest.cc b/ui/gfx/rect_unittest.cc index ff0c171..6233765 100644 --- a/ui/gfx/rect_unittest.cc +++ b/ui/gfx/rect_unittest.cc @@ -307,6 +307,66 @@ TEST(RectTest, SplitVertically) { EXPECT_TRUE(right_half.Equals(gfx::Rect(12, 10, 3, 10))); } +TEST(RectTest, CenterPoint) { + gfx::Point center; + + // When origin is (0, 0). + center = gfx::Rect(0, 0, 20, 20).CenterPoint(); + EXPECT_TRUE(center == gfx::Point(10, 10)); + + // When origin is even. + center = gfx::Rect(10, 10, 20, 20).CenterPoint(); + EXPECT_TRUE(center == gfx::Point(20, 20)); + + // When origin is odd. + center = gfx::Rect(11, 11, 20, 20).CenterPoint(); + EXPECT_TRUE(center == gfx::Point(21, 21)); + + // When 0 width or height. + center = gfx::Rect(10, 10, 0, 20).CenterPoint(); + EXPECT_TRUE(center == gfx::Point(10, 20)); + center = gfx::Rect(10, 10, 20, 0).CenterPoint(); + EXPECT_TRUE(center == gfx::Point(20, 10)); + + // When an odd size. + center = gfx::Rect(10, 10, 21, 21).CenterPoint(); + EXPECT_TRUE(center == gfx::Point(20, 20)); + + // When an odd size and position. + center = gfx::Rect(11, 11, 21, 21).CenterPoint(); + EXPECT_TRUE(center == gfx::Point(21, 21)); +} + +TEST(RectTest, CenterPointF) { + gfx::PointF center; + + // When origin is (0, 0). + center = gfx::RectF(0, 0, 20, 20).CenterPoint(); + EXPECT_TRUE(center == gfx::PointF(10, 10)); + + // When origin is even. + center = gfx::RectF(10, 10, 20, 20).CenterPoint(); + EXPECT_TRUE(center == gfx::PointF(20, 20)); + + // When origin is odd. + center = gfx::RectF(11, 11, 20, 20).CenterPoint(); + EXPECT_TRUE(center == gfx::PointF(21, 21)); + + // When 0 width or height. + center = gfx::RectF(10, 10, 0, 20).CenterPoint(); + EXPECT_TRUE(center == gfx::PointF(10, 20)); + center = gfx::RectF(10, 10, 20, 0).CenterPoint(); + EXPECT_TRUE(center == gfx::PointF(20, 10)); + + // When an odd size. + center = gfx::RectF(10, 10, 21, 21).CenterPoint(); + EXPECT_TRUE(center == gfx::PointF(20.5f, 20.5f)); + + // When an odd size and position. + center = gfx::RectF(11, 11, 21, 21).CenterPoint(); + EXPECT_TRUE(center == gfx::PointF(21.5f, 21.5f)); +} + TEST(RectTest, SharesEdgeWith) { gfx::Rect r(2, 3, 4, 5); |