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

Side by Side 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, 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/point_base.h" 5 #include "ui/gfx/point_base.h"
6 6
7 #include "base/basictypes.h"
7 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/gfx/point.h" 9 #include "ui/gfx/point.h"
9 #include "ui/gfx/point_f.h" 10 #include "ui/gfx/point_f.h"
10 11
11 namespace ui { 12 namespace ui {
12 13
13 namespace { 14 namespace {
14 15
15 int TestPointF(const gfx::PointF& p) { 16 int TestPointF(const gfx::PointF& p) {
16 return p.x(); 17 return p.x();
(...skipping 23 matching lines...) Expand all
40 41
41 EXPECT_FALSE(gfx::PointF(0.1f, 0).IsOrigin()); 42 EXPECT_FALSE(gfx::PointF(0.1f, 0).IsOrigin());
42 EXPECT_FALSE(gfx::PointF(0, 0.1f).IsOrigin()); 43 EXPECT_FALSE(gfx::PointF(0, 0.1f).IsOrigin());
43 EXPECT_FALSE(gfx::PointF(0.1f, 2).IsOrigin()); 44 EXPECT_FALSE(gfx::PointF(0.1f, 2).IsOrigin());
44 EXPECT_FALSE(gfx::PointF(-0.1f, 0).IsOrigin()); 45 EXPECT_FALSE(gfx::PointF(-0.1f, 0).IsOrigin());
45 EXPECT_FALSE(gfx::PointF(0, -0.1f).IsOrigin()); 46 EXPECT_FALSE(gfx::PointF(0, -0.1f).IsOrigin());
46 EXPECT_FALSE(gfx::PointF(-0.1f, -2).IsOrigin()); 47 EXPECT_FALSE(gfx::PointF(-0.1f, -2).IsOrigin());
47 EXPECT_TRUE(gfx::PointF(0, 0).IsOrigin()); 48 EXPECT_TRUE(gfx::PointF(0, 0).IsOrigin());
48 } 49 }
49 50
51 TEST(PointTest, VectorArithmetic) {
52 gfx::Point a(1, 5);
53 gfx::Vector2d v1(3, -3);
54 gfx::Vector2d v2(-8, 1);
55
56 static const struct {
57 gfx::Point expected;
58 gfx::Point actual;
59 } tests[] = {
60 { gfx::Point(4, 2), a + v1 },
61 { gfx::Point(-2, 8), a - v1 },
62 { a, a - v1 + v1 },
63 { a, a + v1 - v1 },
64 { a, a + gfx::Vector2d() },
65 { gfx::Point(12, 1), a + v1 - v2 },
66 { gfx::Point(-10, 9), a - v1 + v2 }
67 };
68
69 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i)
70 EXPECT_EQ(tests[i].expected.ToString(),
71 tests[i].actual.ToString());
72 }
73
74 TEST(PointTest, OffsetFromPoint) {
75 gfx::Point a(1, 5);
76 gfx::Point b(-20, 8);
77 EXPECT_EQ(gfx::Vector2d(-20 - 1, 8 - 5).ToString(),
78 b.OffsetFrom(a).ToString());
79 EXPECT_EQ(gfx::Vector2d(-20 - 1, 8 - 5).ToString(),
80 (b - a).ToString());
81 }
82
50 } // namespace ui 83 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698