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

Unified Diff: ui/gfx/point_unittest.cc

Issue 11269022: Add Vector2d classes that represent offsets, instead of using Point. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: RenderText fixup 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
Index: ui/gfx/point_unittest.cc
diff --git a/ui/gfx/point_unittest.cc b/ui/gfx/point_unittest.cc
index cae21660f31481d2fe9cd8a59a180fb70575c109..ea42b53f1faa03b4468776e65199da19ff5203a0 100644
--- a/ui/gfx/point_unittest.cc
+++ b/ui/gfx/point_unittest.cc
@@ -4,6 +4,7 @@
#include "ui/gfx/point_base.h"
+#include "base/basictypes.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/point.h"
#include "ui/gfx/point_f.h"
@@ -47,4 +48,36 @@ TEST(PointTest, IsOrigin) {
EXPECT_TRUE(gfx::PointF(0, 0).IsOrigin());
}
+TEST(PointTest, VectorArithmetic) {
+ gfx::Point a(1, 5);
+ gfx::Vector2d v1(3, -3);
+ gfx::Vector2d v2(-8, 1);
+
+ static const struct {
+ gfx::Point expected;
+ gfx::Point actual;
+ } tests[] = {
+ { gfx::Point(4, 2), a + v1 },
+ { gfx::Point(-2, 8), a - v1 },
+ { a, a - v1 + v1 },
+ { a, a + v1 - v1 },
+ { a, a + gfx::Vector2d() },
+ { gfx::Point(12, 1), a + v1 - v2 },
+ { gfx::Point(-10, 9), a - v1 + v2 }
+ };
+
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i)
+ EXPECT_EQ(tests[i].expected.ToString(),
+ tests[i].actual.ToString());
+}
+
+TEST(PointTest, OffsetFromPoint) {
+ gfx::Point a(1, 5);
+ gfx::Point b(-20, 8);
+ EXPECT_EQ(gfx::Vector2d(-20 - 1, 8 - 5).ToString(),
+ b.OffsetFrom(a).ToString());
+ EXPECT_EQ(gfx::Vector2d(-20 - 1, 8 - 5).ToString(),
+ (b - a).ToString());
+}
+
} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698