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

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
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, MapEnclosedNonClippedRect) {
124 gfx::Rect input(1, 2, 3, 4);
125 gfx::Rect output;
126 gfx::Transform transform;
127
128 // Identity.
129 output = MathUtil::MapEnclosedNonClippedRect(transform, input);
130 EXPECT_EQ(input, output);
131
132 // Integer translate.
133 transform.Translate(2.0, 3.0);
134 output = MathUtil::MapEnclosedNonClippedRect(transform, input);
135 EXPECT_EQ(gfx::Rect(3, 5, 3, 4), output);
136
137 // Non-integer translate.
138 transform.Translate(0.5, 0.5);
139 output = MathUtil::MapEnclosedNonClippedRect(transform, input);
140 EXPECT_EQ(gfx::Rect(4, 6, 2, 3), output);
141
142 // Scale.
143 transform = gfx::Transform();
144 transform.Scale(2.0, 3.0);
145 output = MathUtil::MapEnclosedNonClippedRect(transform, input);
146 EXPECT_EQ(gfx::Rect(2, 6, 6, 12), output);
147
148 // Rotate Z.
149 transform = gfx::Transform();
150 transform.Translate(1.0, 2.0);
151 transform.RotateAboutZAxis(90.0);
152 transform.Translate(-1.0, -2.0);
153 output = MathUtil::MapEnclosedNonClippedRect(transform, input);
154 EXPECT_EQ(gfx::Rect(-3, 2, 4, 3), output);
155
156 // Rotate X.
157 transform = gfx::Transform();
158 transform.RotateAboutXAxis(90.0);
159 output = MathUtil::MapEnclosedNonClippedRect(transform, input);
160 EXPECT_TRUE(output.IsEmpty());
161
162 transform = gfx::Transform();
163 transform.RotateAboutXAxis(180.0);
164 output = MathUtil::MapEnclosedNonClippedRect(transform, input);
165 EXPECT_EQ(gfx::Rect(1, -6, 3, 4), output);
166
167 // Rotate Y.
168 transform = gfx::Transform();
169 transform.RotateAboutYAxis(90.0);
170 output = MathUtil::MapEnclosedNonClippedRect(transform, input);
171 EXPECT_TRUE(output.IsEmpty());
172
173 transform = gfx::Transform();
174 transform.RotateAboutYAxis(180.0);
175 output = MathUtil::MapEnclosedNonClippedRect(transform, input);
176 EXPECT_EQ(gfx::Rect(-4, 2, 3, 4), output);
177
178 // Translate Z.
179 transform = gfx::Transform();
180 transform.ApplyPerspectiveDepth(10.0);
181 transform.Translate3d(0.0, 0.0, 5.0);
182 output = MathUtil::MapEnclosedNonClippedRect(transform, input);
183 EXPECT_EQ(gfx::Rect(2, 4, 6, 8), output);
184 }
185
123 } // namespace 186 } // namespace
124 } // namespace cc 187 } // namespace cc
OLDNEW
« cc/base/math_util.cc ('K') | « 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