Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(378)

Unified Diff: ui/gfx/rect_unittest.cc

Issue 11065050: The center of a rect is x+width/2, y+height/2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/rect_base_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/rect_unittest.cc
diff --git a/ui/gfx/rect_unittest.cc b/ui/gfx/rect_unittest.cc
index abc94c1bdd8f68edf50df33bc97871bba7847af5..0305b21277d2a62489a0659d3df26242308dfd1f 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));
sky 2012/10/09 15:55:50 Use EXPECT_EQ("10,10", center) for these. Doing so
+
+ // 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);
« no previous file with comments | « ui/gfx/rect_base_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698