OLD | NEW |
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/math_util.h" | 5 #include "cc/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 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 initializeTestMatrix(&A); | 318 initializeTestMatrix(&A); |
319 | 319 |
320 // Copy constructor should produce exact same elements as matrix A. | 320 // Copy constructor should produce exact same elements as matrix A. |
321 gfx::Transform B(A); | 321 gfx::Transform B(A); |
322 EXPECT_ROW1_EQ(10, 14, 18, 22, B); | 322 EXPECT_ROW1_EQ(10, 14, 18, 22, B); |
323 EXPECT_ROW2_EQ(11, 15, 19, 23, B); | 323 EXPECT_ROW2_EQ(11, 15, 19, 23, B); |
324 EXPECT_ROW3_EQ(12, 16, 20, 24, B); | 324 EXPECT_ROW3_EQ(12, 16, 20, 24, B); |
325 EXPECT_ROW4_EQ(13, 17, 21, 25, B); | 325 EXPECT_ROW4_EQ(13, 17, 21, 25, B); |
326 } | 326 } |
327 | 327 |
328 TEST(MathUtilGfxTransformTest, verifyMatrixInversion) | |
329 { | |
330 // Invert a translation | |
331 gfx::Transform translation; | |
332 translation.Translate3d(2, 3, 4); | |
333 EXPECT_TRUE(translation.IsInvertible()); | |
334 | |
335 gfx::Transform inverseTranslation = MathUtil::inverse(translation); | |
336 EXPECT_ROW1_EQ(1, 0, 0, -2, inverseTranslation); | |
337 EXPECT_ROW2_EQ(0, 1, 0, -3, inverseTranslation); | |
338 EXPECT_ROW3_EQ(0, 0, 1, -4, inverseTranslation); | |
339 EXPECT_ROW4_EQ(0, 0, 0, 1, inverseTranslation); | |
340 | |
341 // Note that inversion should not have changed the original matrix. | |
342 EXPECT_ROW1_EQ(1, 0, 0, 2, translation); | |
343 EXPECT_ROW2_EQ(0, 1, 0, 3, translation); | |
344 EXPECT_ROW3_EQ(0, 0, 1, 4, translation); | |
345 EXPECT_ROW4_EQ(0, 0, 0, 1, translation); | |
346 | |
347 // Invert a non-uniform scale | |
348 gfx::Transform scale; | |
349 scale.Scale3d(4, 10, 100); | |
350 EXPECT_TRUE(scale.IsInvertible()); | |
351 | |
352 gfx::Transform inverseScale = MathUtil::inverse(scale); | |
353 EXPECT_ROW1_EQ(0.25, 0, 0, 0, inverseScale); | |
354 EXPECT_ROW2_EQ(0, .1f, 0, 0, inverseScale); | |
355 EXPECT_ROW3_EQ(0, 0, .01f, 0, inverseScale); | |
356 EXPECT_ROW4_EQ(0, 0, 0, 1, inverseScale); | |
357 | |
358 // Try to invert a matrix that is not invertible. | |
359 // The inverse() function should simply return an identity matrix. | |
360 gfx::Transform notInvertible; | |
361 notInvertible.matrix().setDouble(0, 0, 0); | |
362 notInvertible.matrix().setDouble(1, 1, 0); | |
363 notInvertible.matrix().setDouble(2, 2, 0); | |
364 notInvertible.matrix().setDouble(3, 3, 0); | |
365 EXPECT_FALSE(notInvertible.IsInvertible()); | |
366 | |
367 gfx::Transform inverseOfNotInvertible; | |
368 initializeTestMatrix(&inverseOfNotInvertible); // initialize this to somethi
ng non-identity, to make sure that assignment below actually took place. | |
369 inverseOfNotInvertible = MathUtil::inverse(notInvertible); | |
370 EXPECT_TRUE(inverseOfNotInvertible.IsIdentity()); | |
371 } | |
372 | |
373 TEST(MathUtilGfxTransformTest, verifyTo2DTransform) | 328 TEST(MathUtilGfxTransformTest, verifyTo2DTransform) |
374 { | 329 { |
375 gfx::Transform A; | 330 gfx::Transform A; |
376 initializeTestMatrix(&A); | 331 initializeTestMatrix(&A); |
377 | 332 |
378 gfx::Transform B = MathUtil::to2dTransform(A); | 333 gfx::Transform B = MathUtil::to2dTransform(A); |
379 | 334 |
380 EXPECT_ROW1_EQ(10, 14, 0, 22, B); | 335 EXPECT_ROW1_EQ(10, 14, 0, 22, B); |
381 EXPECT_ROW2_EQ(11, 15, 0, 23, B); | 336 EXPECT_ROW2_EQ(11, 15, 0, 23, B); |
382 EXPECT_ROW3_EQ(0, 0, 1, 0, B); | 337 EXPECT_ROW3_EQ(0, 0, 1, 0, B); |
(...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1281 A.matrix().setDouble(2, 3, 2); | 1236 A.matrix().setDouble(2, 3, 2); |
1282 EXPECT_TRUE(A.IsScaleOrTranslation()); | 1237 EXPECT_TRUE(A.IsScaleOrTranslation()); |
1283 | 1238 |
1284 A.MakeIdentity(); | 1239 A.MakeIdentity(); |
1285 A.matrix().setDouble(3, 3, 2); | 1240 A.matrix().setDouble(3, 3, 2); |
1286 EXPECT_FALSE(A.IsScaleOrTranslation()); | 1241 EXPECT_FALSE(A.IsScaleOrTranslation()); |
1287 } | 1242 } |
1288 | 1243 |
1289 } // namespace | 1244 } // namespace |
1290 } // namespace cc | 1245 } // namespace cc |
OLD | NEW |