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

Unified Diff: ui/gfx/vector2d_unittest.cc

Issue 11361186: ui: Add methods to clamp Sizes, Points, and Vectors from above or below. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 1 month 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/vector2d_f.h ('k') | ui/gfx/vector3d_f.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/vector2d_unittest.cc
diff --git a/ui/gfx/vector2d_unittest.cc b/ui/gfx/vector2d_unittest.cc
index ccb6059e2420793540cd4bafb82b14fd17f86597..a5994940b8ea80550d32d64658ede423ce7e8bcb 100644
--- a/ui/gfx/vector2d_unittest.cc
+++ b/ui/gfx/vector2d_unittest.cc
@@ -183,4 +183,56 @@ TEST(Vector2dTest, Length) {
}
}
+TEST(Vector2dTest, ClampVector2d) {
+ Vector2d a;
+
+ a = Vector2d(3, 5);
+ EXPECT_EQ(Vector2d(3, 5).ToString(), a.ToString());
+ a.ClampToMin(Vector2d(2, 4));
+ EXPECT_EQ(Vector2d(3, 5).ToString(), a.ToString());
+ a.ClampToMin(Vector2d(3, 5));
+ EXPECT_EQ(Vector2d(3, 5).ToString(), a.ToString());
+ a.ClampToMin(Vector2d(4, 2));
+ EXPECT_EQ(Vector2d(4, 5).ToString(), a.ToString());
+ a.ClampToMin(Vector2d(8, 10));
+ EXPECT_EQ(Vector2d(8, 10).ToString(), a.ToString());
+
+ a.ClampToMax(Vector2d(9, 11));
+ EXPECT_EQ(Vector2d(8, 10).ToString(), a.ToString());
+ a.ClampToMax(Vector2d(8, 10));
+ EXPECT_EQ(Vector2d(8, 10).ToString(), a.ToString());
+ a.ClampToMax(Vector2d(11, 9));
+ EXPECT_EQ(Vector2d(8, 9).ToString(), a.ToString());
+ a.ClampToMax(Vector2d(7, 11));
+ EXPECT_EQ(Vector2d(7, 9).ToString(), a.ToString());
+ a.ClampToMax(Vector2d(3, 5));
+ EXPECT_EQ(Vector2d(3, 5).ToString(), a.ToString());
+}
+
+TEST(Vector2dTest, ClampVector2dF) {
+ Vector2dF a;
+
+ a = Vector2dF(3.5f, 5.5f);
+ EXPECT_EQ(Vector2dF(3.5f, 5.5f).ToString(), a.ToString());
+ a.ClampToMin(Vector2dF(2.5f, 4.5f));
+ EXPECT_EQ(Vector2dF(3.5f, 5.5f).ToString(), a.ToString());
+ a.ClampToMin(Vector2dF(3.5f, 5.5f));
+ EXPECT_EQ(Vector2dF(3.5f, 5.5f).ToString(), a.ToString());
+ a.ClampToMin(Vector2dF(4.5f, 2.5f));
+ EXPECT_EQ(Vector2dF(4.5f, 5.5f).ToString(), a.ToString());
+ a.ClampToMin(Vector2dF(8.5f, 10.5f));
+ EXPECT_EQ(Vector2dF(8.5f, 10.5f).ToString(), a.ToString());
+
+ a.ClampToMax(Vector2dF(9.5f, 11.5f));
+ EXPECT_EQ(Vector2dF(8.5f, 10.5f).ToString(), a.ToString());
+ a.ClampToMax(Vector2dF(8.5f, 10.5f));
+ EXPECT_EQ(Vector2dF(8.5f, 10.5f).ToString(), a.ToString());
+ a.ClampToMax(Vector2dF(11.5f, 9.5f));
+ EXPECT_EQ(Vector2dF(8.5f, 9.5f).ToString(), a.ToString());
+ a.ClampToMax(Vector2dF(7.5f, 11.5f));
+ EXPECT_EQ(Vector2dF(7.5f, 9.5f).ToString(), a.ToString());
+ a.ClampToMax(Vector2dF(3.5f, 5.5f));
+ EXPECT_EQ(Vector2dF(3.5f, 5.5f).ToString(), a.ToString());
+}
+
} // namespace gfx
« no previous file with comments | « ui/gfx/vector2d_f.h ('k') | ui/gfx/vector3d_f.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698