OLD | NEW |
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 <cmath> |
| 6 #include <limits> |
| 7 |
5 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
7 #include "ui/gfx/vector3d_f.h" | 10 #include "ui/gfx/vector3d_f.h" |
8 | 11 |
9 #include <cmath> | |
10 #include <limits> | |
11 | |
12 namespace gfx { | 12 namespace gfx { |
13 | 13 |
14 TEST(Vector3dTest, IsZero) { | 14 TEST(Vector3dTest, IsZero) { |
15 gfx::Vector3dF float_zero(0, 0, 0); | 15 gfx::Vector3dF float_zero(0, 0, 0); |
16 gfx::Vector3dF float_nonzero(0.1f, -0.1f, 0.1f); | 16 gfx::Vector3dF float_nonzero(0.1f, -0.1f, 0.1f); |
17 | 17 |
18 EXPECT_TRUE(float_zero.IsZero()); | 18 EXPECT_TRUE(float_zero.IsZero()); |
19 EXPECT_FALSE(float_nonzero.IsZero()); | 19 EXPECT_FALSE(float_nonzero.IsZero()); |
20 } | 20 } |
21 | 21 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(float_values); ++i) { | 164 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(float_values); ++i) { |
165 double v0 = float_values[i][0]; | 165 double v0 = float_values[i][0]; |
166 double v1 = float_values[i][1]; | 166 double v1 = float_values[i][1]; |
167 double v2 = float_values[i][2]; | 167 double v2 = float_values[i][2]; |
168 double length_squared = | 168 double length_squared = |
169 static_cast<double>(v0) * v0 + | 169 static_cast<double>(v0) * v0 + |
170 static_cast<double>(v1) * v1 + | 170 static_cast<double>(v1) * v1 + |
171 static_cast<double>(v2) * v2; | 171 static_cast<double>(v2) * v2; |
172 double length = std::sqrt(length_squared); | 172 double length = std::sqrt(length_squared); |
173 gfx::Vector3dF vector(v0, v1, v2); | 173 gfx::Vector3dF vector(v0, v1, v2); |
174 EXPECT_EQ(length_squared, vector.LengthSquared()); | 174 EXPECT_DOUBLE_EQ(length_squared, vector.LengthSquared()); |
175 EXPECT_EQ(static_cast<float>(length), vector.Length()); | 175 EXPECT_FLOAT_EQ(static_cast<float>(length), vector.Length()); |
176 } | 176 } |
177 } | 177 } |
178 | 178 |
179 TEST(Vector3dTest, DotProduct) { | 179 TEST(Vector3dTest, DotProduct) { |
180 const struct { | 180 const struct { |
181 float expected; | 181 float expected; |
182 gfx::Vector3dF input1; | 182 gfx::Vector3dF input1; |
183 gfx::Vector3dF input2; | 183 gfx::Vector3dF input2; |
184 } tests[] = { | 184 } tests[] = { |
185 { 0, gfx::Vector3dF(1, 0, 0), gfx::Vector3dF(0, 1, 1) }, | 185 { 0, gfx::Vector3dF(1, 0, 0), gfx::Vector3dF(0, 1, 1) }, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 | 220 |
221 { Vector3dF(-1, 1, 0), Vector3dF(0, 0, 1), Vector3dF(1, 1, 1) }, | 221 { Vector3dF(-1, 1, 0), Vector3dF(0, 0, 1), Vector3dF(1, 1, 1) }, |
222 { Vector3dF(1, 0, -1), Vector3dF(0, 1, 0), Vector3dF(1, 1, 1) }, | 222 { Vector3dF(1, 0, -1), Vector3dF(0, 1, 0), Vector3dF(1, 1, 1) }, |
223 { Vector3dF(0, -1, 1), Vector3dF(1, 0, 0), Vector3dF(1, 1, 1) } | 223 { Vector3dF(0, -1, 1), Vector3dF(1, 0, 0), Vector3dF(1, 1, 1) } |
224 }; | 224 }; |
225 | 225 |
226 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 226 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
227 Vector3dF actual = gfx::CrossProduct(tests[i].input1, tests[i].input2); | 227 Vector3dF actual = gfx::CrossProduct(tests[i].input1, tests[i].input2); |
228 EXPECT_EQ(tests[i].expected.ToString(), actual.ToString()); | 228 EXPECT_EQ(tests[i].expected.ToString(), actual.ToString()); |
229 } | 229 } |
230 | |
231 } | 230 } |
232 | 231 |
233 TEST(Vector3dFTest, ClampVector3dF) { | 232 TEST(Vector3dFTest, ClampVector3dF) { |
234 Vector3dF a; | 233 Vector3dF a; |
235 | 234 |
236 a = Vector3dF(3.5f, 5.5f, 7.5f); | 235 a = Vector3dF(3.5f, 5.5f, 7.5f); |
237 EXPECT_EQ(Vector3dF(3.5f, 5.5f, 7.5f).ToString(), a.ToString()); | 236 EXPECT_EQ(Vector3dF(3.5f, 5.5f, 7.5f).ToString(), a.ToString()); |
238 a.ClampToMin(Vector3dF(2, 4.5f, 6.5f)); | 237 a.ClampToMin(Vector3dF(2, 4.5f, 6.5f)); |
239 EXPECT_EQ(Vector3dF(3.5f, 5.5f, 7.5f).ToString(), a.ToString()); | 238 EXPECT_EQ(Vector3dF(3.5f, 5.5f, 7.5f).ToString(), a.ToString()); |
240 a.ClampToMin(Vector3dF(3.5f, 5.5f, 7.5f)); | 239 a.ClampToMin(Vector3dF(3.5f, 5.5f, 7.5f)); |
(...skipping 15 matching lines...) Expand all Loading... |
256 EXPECT_EQ(Vector3dF(7.5f, 10.5f, 12.5f).ToString(), a.ToString()); | 255 EXPECT_EQ(Vector3dF(7.5f, 10.5f, 12.5f).ToString(), a.ToString()); |
257 a.ClampToMax(Vector3dF(9.5f, 9.5f, 13.5f)); | 256 a.ClampToMax(Vector3dF(9.5f, 9.5f, 13.5f)); |
258 EXPECT_EQ(Vector3dF(7.5f, 9.5f, 12.5f).ToString(), a.ToString()); | 257 EXPECT_EQ(Vector3dF(7.5f, 9.5f, 12.5f).ToString(), a.ToString()); |
259 a.ClampToMax(Vector3dF(9.5f, 11.5f, 11.5f)); | 258 a.ClampToMax(Vector3dF(9.5f, 11.5f, 11.5f)); |
260 EXPECT_EQ(Vector3dF(7.5f, 9.5f, 11.5f).ToString(), a.ToString()); | 259 EXPECT_EQ(Vector3dF(7.5f, 9.5f, 11.5f).ToString(), a.ToString()); |
261 a.ClampToMax(Vector3dF(3.5f, 5.5f, 7.5f)); | 260 a.ClampToMax(Vector3dF(3.5f, 5.5f, 7.5f)); |
262 EXPECT_EQ(Vector3dF(3.5f, 5.5f, 7.5f).ToString(), a.ToString()); | 261 EXPECT_EQ(Vector3dF(3.5f, 5.5f, 7.5f).ToString(), a.ToString()); |
263 } | 262 } |
264 | 263 |
265 } // namespace gfx | 264 } // namespace gfx |
OLD | NEW |