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

Side by Side Diff: cc/base/math_util_unittest.cc

Issue 495873002: cc: Stop converting Rect to QuadF to map to an enclosed rect. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: enclosed: . Created 6 years, 4 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 | « cc/base/math_util.cc ('k') | cc/trees/occlusion_tracker.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 "cc/base/math_util.h" 5 #include "cc/base/math_util.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "cc/test/geometry_test_utils.h" 9 #include "cc/test/geometry_test_utils.h"
10 #include "testing/gmock/include/gmock/gmock.h" 10 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 113
114 // Finally check than an arbitrary vector projected to another one gives a 114 // Finally check than an arbitrary vector projected to another one gives a
115 // vector parallel to the second vector. 115 // vector parallel to the second vector.
116 gfx::Vector2dF target_vector(0.5, 0.2f); 116 gfx::Vector2dF target_vector(0.5, 0.2f);
117 gfx::Vector2dF projected_vector = 117 gfx::Vector2dF projected_vector =
118 MathUtil::ProjectVector(test_vector, target_vector); 118 MathUtil::ProjectVector(test_vector, target_vector);
119 EXPECT_EQ(projected_vector.x() / target_vector.x(), 119 EXPECT_EQ(projected_vector.x() / target_vector.x(),
120 projected_vector.y() / target_vector.y()); 120 projected_vector.y() / target_vector.y());
121 } 121 }
122 122
123 TEST(MathUtilTest, MapEnclosedRectWith2dAxisAlignedTransform) {
124 gfx::Rect input(1, 2, 3, 4);
125 gfx::Rect output;
126 gfx::Transform transform;
127
128 // Identity.
129 output =
130 MathUtil::MapEnclosedRectWith2dAxisAlignedTransform(transform, input);
131 EXPECT_EQ(input, output);
132
133 // Integer translate.
134 transform.Translate(2.0, 3.0);
135 output =
136 MathUtil::MapEnclosedRectWith2dAxisAlignedTransform(transform, input);
137 EXPECT_EQ(gfx::Rect(3, 5, 3, 4), output);
138
139 // Non-integer translate.
140 transform.Translate(0.5, 0.5);
141 output =
142 MathUtil::MapEnclosedRectWith2dAxisAlignedTransform(transform, input);
143 EXPECT_EQ(gfx::Rect(4, 6, 2, 3), output);
144
145 // Scale.
146 transform = gfx::Transform();
147 transform.Scale(2.0, 3.0);
148 output =
149 MathUtil::MapEnclosedRectWith2dAxisAlignedTransform(transform, input);
150 EXPECT_EQ(gfx::Rect(2, 6, 6, 12), output);
151
152 // Rotate Z.
153 transform = gfx::Transform();
154 transform.Translate(1.0, 2.0);
155 transform.RotateAboutZAxis(90.0);
156 transform.Translate(-1.0, -2.0);
157 output =
158 MathUtil::MapEnclosedRectWith2dAxisAlignedTransform(transform, input);
159 EXPECT_EQ(gfx::Rect(-3, 2, 4, 3), output);
160
161 // Rotate X.
162 transform = gfx::Transform();
163 transform.RotateAboutXAxis(90.0);
164 output =
165 MathUtil::MapEnclosedRectWith2dAxisAlignedTransform(transform, input);
166 EXPECT_TRUE(output.IsEmpty());
167
168 transform = gfx::Transform();
169 transform.RotateAboutXAxis(180.0);
170 output =
171 MathUtil::MapEnclosedRectWith2dAxisAlignedTransform(transform, input);
172 EXPECT_EQ(gfx::Rect(1, -6, 3, 4), output);
173
174 // Rotate Y.
175 transform = gfx::Transform();
176 transform.RotateAboutYAxis(90.0);
177 output =
178 MathUtil::MapEnclosedRectWith2dAxisAlignedTransform(transform, input);
179 EXPECT_TRUE(output.IsEmpty());
180
181 transform = gfx::Transform();
182 transform.RotateAboutYAxis(180.0);
183 output =
184 MathUtil::MapEnclosedRectWith2dAxisAlignedTransform(transform, input);
185 EXPECT_EQ(gfx::Rect(-4, 2, 3, 4), output);
186
187 // Translate Z.
188 transform = gfx::Transform();
189 transform.ApplyPerspectiveDepth(10.0);
190 transform.Translate3d(0.0, 0.0, 5.0);
191 output =
192 MathUtil::MapEnclosedRectWith2dAxisAlignedTransform(transform, input);
193 EXPECT_EQ(gfx::Rect(2, 4, 6, 8), output);
194 }
195
123 } // namespace 196 } // namespace
124 } // namespace cc 197 } // namespace cc
OLDNEW
« no previous file with comments | « cc/base/math_util.cc ('k') | cc/trees/occlusion_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698