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

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

Issue 11293193: ui: Add non-member Vector2dScale() and Vector3dScale() methods to create scaled vectors (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use it in cc/ 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 "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/vector2d.h" 7 #include "ui/gfx/vector2d.h"
8 #include "ui/gfx/vector2d_f.h" 8 #include "ui/gfx/vector2d_f.h"
9 9
10 #include <cmath> 10 #include <cmath>
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 { -4.5f, 1.2f, 3.3f, 0 }, 108 { -4.5f, 1.2f, 3.3f, 0 },
109 { 4.5f, 0, 3.3f, 5.6f }, 109 { 4.5f, 0, 3.3f, 5.6f },
110 { 0, 1.2f, 3.3f, 5.6f } 110 { 0, 1.2f, 3.3f, 5.6f }
111 }; 111 };
112 112
113 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(double_values); ++i) { 113 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(double_values); ++i) {
114 Vector2dF v(double_values[i][0], double_values[i][1]); 114 Vector2dF v(double_values[i][0], double_values[i][1]);
115 v.Scale(double_values[i][2], double_values[i][3]); 115 v.Scale(double_values[i][2], double_values[i][3]);
116 EXPECT_EQ(v.x(), double_values[i][0] * double_values[i][2]); 116 EXPECT_EQ(v.x(), double_values[i][0] * double_values[i][2]);
117 EXPECT_EQ(v.y(), double_values[i][1] * double_values[i][3]); 117 EXPECT_EQ(v.y(), double_values[i][1] * double_values[i][3]);
118
119 Vector2dF v2 = ScaleVector2d(
120 gfx::Vector2dF(double_values[i][0], double_values[i][1]),
121 double_values[i][2], double_values[i][3]);
122 EXPECT_EQ(v2.x(), double_values[i][0] * double_values[i][2]);
sky 2012/11/09 17:06:21 Your The order is wrong here. You want expected,ac
danakj 2012/11/09 18:21:47 Oops, thanks.
123 EXPECT_EQ(v2.y(), double_values[i][1] * double_values[i][3]);
118 } 124 }
119 125
120 float single_values[][3] = { 126 float single_values[][3] = {
121 { 4.5f, 1.2f, 3.3f }, 127 { 4.5f, 1.2f, 3.3f },
122 { 4.5f, -1.2f, 3.3f }, 128 { 4.5f, -1.2f, 3.3f },
123 { 4.5f, 1.2f, 3.3f }, 129 { 4.5f, 1.2f, 3.3f },
124 { 4.5f, 1.2f, -3.3f }, 130 { 4.5f, 1.2f, -3.3f },
125 { -4.5f, 1.2f, 3.3f }, 131 { -4.5f, 1.2f, 3.3f },
126 { -4.5f, 1.2f, 0 }, 132 { -4.5f, 1.2f, 0 },
127 { -4.5f, 1.2f, 3.3f }, 133 { -4.5f, 1.2f, 3.3f },
128 { 4.5f, 0, 3.3f }, 134 { 4.5f, 0, 3.3f },
129 { 0, 1.2f, 3.3f } 135 { 0, 1.2f, 3.3f }
130 }; 136 };
131 137
132 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(single_values); ++i) { 138 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(single_values); ++i) {
133 Vector2dF v(single_values[i][0], single_values[i][1]); 139 Vector2dF v(single_values[i][0], single_values[i][1]);
134 v.Scale(single_values[i][2]); 140 v.Scale(single_values[i][2]);
135 EXPECT_EQ(v.x(), single_values[i][0] * single_values[i][2]); 141 EXPECT_EQ(v.x(), single_values[i][0] * single_values[i][2]);
136 EXPECT_EQ(v.y(), single_values[i][1] * single_values[i][2]); 142 EXPECT_EQ(v.y(), single_values[i][1] * single_values[i][2]);
143
144 Vector2dF v2 = ScaleVector2d(
145 gfx::Vector2dF(double_values[i][0], double_values[i][1]),
146 double_values[i][2]);
147 EXPECT_EQ(v2.x(), single_values[i][0] * single_values[i][2]);
148 EXPECT_EQ(v2.y(), single_values[i][1] * single_values[i][2]);
137 } 149 }
138 } 150 }
139 151
140 TEST(Vector2dTest, Length) { 152 TEST(Vector2dTest, Length) {
141 int int_values[][2] = { 153 int int_values[][2] = {
142 { 0, 0 }, 154 { 0, 0 },
143 { 10, 20 }, 155 { 10, 20 },
144 { 20, 10 }, 156 { 20, 10 },
145 { -10, -20 }, 157 { -10, -20 },
146 { -20, 10 }, 158 { -20, 10 },
(...skipping 30 matching lines...) Expand all
177 double length_squared = 189 double length_squared =
178 static_cast<double>(v0) * v0 + static_cast<double>(v1) * v1; 190 static_cast<double>(v0) * v0 + static_cast<double>(v1) * v1;
179 double length = std::sqrt(length_squared); 191 double length = std::sqrt(length_squared);
180 Vector2dF vector(v0, v1); 192 Vector2dF vector(v0, v1);
181 EXPECT_EQ(length_squared, vector.LengthSquared()); 193 EXPECT_EQ(length_squared, vector.LengthSquared());
182 EXPECT_EQ(static_cast<float>(length), vector.Length()); 194 EXPECT_EQ(static_cast<float>(length), vector.Length());
183 } 195 }
184 } 196 }
185 197
186 } // namespace gfx 198 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698