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

Side by Side Diff: ui/gfx/box_unittest.cc

Issue 25518002: Add BoxF::ExpandTo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated comment. Created 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gfx/box_f.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "ui/gfx/box_f.h" 7 #include "ui/gfx/box_f.h"
8 8
9 namespace gfx { 9 namespace gfx {
10 10
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 EXPECT_EQ(BoxF(0.f, 0.f, 0.f, 9.f, 8.f, 5.f).ToString(), 71 EXPECT_EQ(BoxF(0.f, 0.f, 0.f, 9.f, 8.f, 5.f).ToString(),
72 UnionBoxes(box3, box1).ToString()); 72 UnionBoxes(box3, box1).ToString());
73 73
74 // box_2 and box_3 intersect, but neither contains the other 74 // box_2 and box_3 intersect, but neither contains the other
75 EXPECT_EQ(BoxF(0.f, 0.f, 0.f, 9.f, 8.f, 8.f).ToString(), 75 EXPECT_EQ(BoxF(0.f, 0.f, 0.f, 9.f, 8.f, 8.f).ToString(),
76 UnionBoxes(box2, box3).ToString()); 76 UnionBoxes(box2, box3).ToString());
77 EXPECT_EQ(BoxF(0.f, 0.f, 0.f, 9.f, 8.f, 8.f).ToString(), 77 EXPECT_EQ(BoxF(0.f, 0.f, 0.f, 9.f, 8.f, 8.f).ToString(),
78 UnionBoxes(box3, box2).ToString()); 78 UnionBoxes(box3, box2).ToString());
79 } 79 }
80 80
81 TEST(BoxTest, ExpandTo) {
82 BoxF box1;
83 BoxF box2(0.f, 0.f, 0.f, 1.f, 1.f, 1.f);
84 BoxF box3(1.f, 1.f, 1.f, 0.f, 0.f, 0.f);
85
86 Point3F point1(0.5f, 0.5f, 0.5f);
87 Point3F point2(-0.5f, -0.5f, -0.5f);
88
89 BoxF expected1_1(0.f, 0.f, 0.f, 0.5f, 0.5f, 0.5f);
90 BoxF expected1_2(-0.5f, -0.5f, -0.5f, 1.f, 1.f, 1.f);
91
92 BoxF expected2_1 = box2;
93 BoxF expected2_2(-0.5f, -0.5f, -0.5f, 1.5f, 1.5f, 1.5f);
94
95 BoxF expected3_1(0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f);
96 BoxF expected3_2(-0.5f, -0.5f, -0.5f, 1.5f, 1.5f, 1.5f);
97
98 box1.ExpandTo(point1);
99 EXPECT_EQ(expected1_1.ToString(), box1.ToString());
100 box1.ExpandTo(point2);
101 EXPECT_EQ(expected1_2.ToString(), box1.ToString());
102
103 box2.ExpandTo(point1);
104 EXPECT_EQ(expected2_1.ToString(), box2.ToString());
105 box2.ExpandTo(point2);
106 EXPECT_EQ(expected2_2.ToString(), box2.ToString());
107
108 box3.ExpandTo(point1);
109 EXPECT_EQ(expected3_1.ToString(), box3.ToString());
110 box3.ExpandTo(point2);
111 EXPECT_EQ(expected3_2.ToString(), box3.ToString());
112 }
113
81 TEST(BoxTest, Scale) { 114 TEST(BoxTest, Scale) {
82 BoxF box1(2.f, 3.f, 4.f, 5.f, 6.f, 7.f); 115 BoxF box1(2.f, 3.f, 4.f, 5.f, 6.f, 7.f);
83 116
84 EXPECT_EQ(BoxF().ToString(), ScaleBox(box1, 0.f).ToString()); 117 EXPECT_EQ(BoxF().ToString(), ScaleBox(box1, 0.f).ToString());
85 EXPECT_EQ(box1.ToString(), ScaleBox(box1, 1.f).ToString()); 118 EXPECT_EQ(box1.ToString(), ScaleBox(box1, 1.f).ToString());
86 EXPECT_EQ(BoxF(4.f, 12.f, 24.f, 10.f, 24.f, 42.f).ToString(), 119 EXPECT_EQ(BoxF(4.f, 12.f, 24.f, 10.f, 24.f, 42.f).ToString(),
87 ScaleBox(box1, 2.f, 4.f, 6.f).ToString()); 120 ScaleBox(box1, 2.f, 4.f, 6.f).ToString());
88 121
89 BoxF box2 = box1; 122 BoxF box2 = box1;
90 box2.Scale(0.f); 123 box2.Scale(0.f);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 BoxF box2 = box1; 167 BoxF box2 = box1;
135 box2 += Vector3dF(0.f, 0.f, 0.f); 168 box2 += Vector3dF(0.f, 0.f, 0.f);
136 EXPECT_EQ(box1.ToString(), box2.ToString()); 169 EXPECT_EQ(box1.ToString(), box2.ToString());
137 170
138 box2 += Vector3dF(1.f, -2.f, -4.f); 171 box2 += Vector3dF(1.f, -2.f, -4.f);
139 EXPECT_EQ(BoxF(3.f, 1.f, 0.f, 5.f, 6.f, 7.f).ToString(), 172 EXPECT_EQ(BoxF(3.f, 1.f, 0.f, 5.f, 6.f, 7.f).ToString(),
140 box2.ToString()); 173 box2.ToString());
141 } 174 }
142 175
143 } // namespace gfx 176 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/box_f.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698