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 "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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 double v1 = float_values[i][1]; | 176 double v1 = float_values[i][1]; |
177 double length_squared = | 177 double length_squared = |
178 static_cast<double>(v0) * v0 + static_cast<double>(v1) * v1; | 178 static_cast<double>(v0) * v0 + static_cast<double>(v1) * v1; |
179 double length = std::sqrt(length_squared); | 179 double length = std::sqrt(length_squared); |
180 Vector2dF vector(v0, v1); | 180 Vector2dF vector(v0, v1); |
181 EXPECT_EQ(length_squared, vector.LengthSquared()); | 181 EXPECT_EQ(length_squared, vector.LengthSquared()); |
182 EXPECT_EQ(static_cast<float>(length), vector.Length()); | 182 EXPECT_EQ(static_cast<float>(length), vector.Length()); |
183 } | 183 } |
184 } | 184 } |
185 | 185 |
| 186 TEST(Vector2dTest, ClampVector2d) { |
| 187 Vector2d a; |
| 188 |
| 189 a = Vector2d(3, 5); |
| 190 EXPECT_EQ(Vector2d(3, 5).ToString(), a.ToString()); |
| 191 a.ClampToMin(Vector2d(2, 4)); |
| 192 EXPECT_EQ(Vector2d(3, 5).ToString(), a.ToString()); |
| 193 a.ClampToMin(Vector2d(3, 5)); |
| 194 EXPECT_EQ(Vector2d(3, 5).ToString(), a.ToString()); |
| 195 a.ClampToMin(Vector2d(4, 2)); |
| 196 EXPECT_EQ(Vector2d(4, 5).ToString(), a.ToString()); |
| 197 a.ClampToMin(Vector2d(8, 10)); |
| 198 EXPECT_EQ(Vector2d(8, 10).ToString(), a.ToString()); |
| 199 |
| 200 a.ClampToMax(Vector2d(9, 11)); |
| 201 EXPECT_EQ(Vector2d(8, 10).ToString(), a.ToString()); |
| 202 a.ClampToMax(Vector2d(8, 10)); |
| 203 EXPECT_EQ(Vector2d(8, 10).ToString(), a.ToString()); |
| 204 a.ClampToMax(Vector2d(11, 9)); |
| 205 EXPECT_EQ(Vector2d(8, 9).ToString(), a.ToString()); |
| 206 a.ClampToMax(Vector2d(7, 11)); |
| 207 EXPECT_EQ(Vector2d(7, 9).ToString(), a.ToString()); |
| 208 a.ClampToMax(Vector2d(3, 5)); |
| 209 EXPECT_EQ(Vector2d(3, 5).ToString(), a.ToString()); |
| 210 } |
| 211 |
| 212 TEST(Vector2dTest, ClampVector2dF) { |
| 213 Vector2dF a; |
| 214 |
| 215 a = Vector2dF(3.5f, 5.5f); |
| 216 EXPECT_EQ(Vector2dF(3.5f, 5.5f).ToString(), a.ToString()); |
| 217 a.ClampToMin(Vector2dF(2.5f, 4.5f)); |
| 218 EXPECT_EQ(Vector2dF(3.5f, 5.5f).ToString(), a.ToString()); |
| 219 a.ClampToMin(Vector2dF(3.5f, 5.5f)); |
| 220 EXPECT_EQ(Vector2dF(3.5f, 5.5f).ToString(), a.ToString()); |
| 221 a.ClampToMin(Vector2dF(4.5f, 2.5f)); |
| 222 EXPECT_EQ(Vector2dF(4.5f, 5.5f).ToString(), a.ToString()); |
| 223 a.ClampToMin(Vector2dF(8.5f, 10.5f)); |
| 224 EXPECT_EQ(Vector2dF(8.5f, 10.5f).ToString(), a.ToString()); |
| 225 |
| 226 a.ClampToMax(Vector2dF(9.5f, 11.5f)); |
| 227 EXPECT_EQ(Vector2dF(8.5f, 10.5f).ToString(), a.ToString()); |
| 228 a.ClampToMax(Vector2dF(8.5f, 10.5f)); |
| 229 EXPECT_EQ(Vector2dF(8.5f, 10.5f).ToString(), a.ToString()); |
| 230 a.ClampToMax(Vector2dF(11.5f, 9.5f)); |
| 231 EXPECT_EQ(Vector2dF(8.5f, 9.5f).ToString(), a.ToString()); |
| 232 a.ClampToMax(Vector2dF(7.5f, 11.5f)); |
| 233 EXPECT_EQ(Vector2dF(7.5f, 9.5f).ToString(), a.ToString()); |
| 234 a.ClampToMax(Vector2dF(3.5f, 5.5f)); |
| 235 EXPECT_EQ(Vector2dF(3.5f, 5.5f).ToString(), a.ToString()); |
| 236 } |
| 237 |
186 } // namespace gfx | 238 } // namespace gfx |
OLD | NEW |