OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // MSVC++ requires this to be set before any other includes to get M_PI. | 5 // MSVC++ requires this to be set before any other includes to get M_PI. |
6 #define _USE_MATH_DEFINES | 6 #define _USE_MATH_DEFINES |
7 | 7 |
8 #include "ui/gfx/transform.h" | 8 #include "ui/gfx/transform.h" |
9 | 9 |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 2402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2413 Transform A; | 2413 Transform A; |
2414 InitializeTestMatrix(&A); | 2414 InitializeTestMatrix(&A); |
2415 | 2415 |
2416 A.FlattenTo2d(); | 2416 A.FlattenTo2d(); |
2417 EXPECT_ROW1_EQ(10.0f, 14.0f, 0.0f, 22.0f, A); | 2417 EXPECT_ROW1_EQ(10.0f, 14.0f, 0.0f, 22.0f, A); |
2418 EXPECT_ROW2_EQ(11.0f, 15.0f, 0.0f, 23.0f, A); | 2418 EXPECT_ROW2_EQ(11.0f, 15.0f, 0.0f, 23.0f, A); |
2419 EXPECT_ROW3_EQ(0.0f, 0.0f, 1.0f, 0.0f, A); | 2419 EXPECT_ROW3_EQ(0.0f, 0.0f, 1.0f, 0.0f, A); |
2420 EXPECT_ROW4_EQ(13.0f, 17.0f, 0.0f, 25.0f, A); | 2420 EXPECT_ROW4_EQ(13.0f, 17.0f, 0.0f, 25.0f, A); |
2421 } | 2421 } |
2422 | 2422 |
| 2423 TEST(XFormTest, IsFlat) { |
| 2424 Transform transform; |
| 2425 InitializeTestMatrix(&transform); |
| 2426 |
| 2427 // A transform with all entries non-zero isn't flat. |
| 2428 EXPECT_FALSE(transform.IsFlat()); |
| 2429 |
| 2430 transform.matrix().set(0, 2, 0.f); |
| 2431 transform.matrix().set(1, 2, 0.f); |
| 2432 transform.matrix().set(2, 2, 1.f); |
| 2433 transform.matrix().set(3, 2, 0.f); |
| 2434 |
| 2435 EXPECT_FALSE(transform.IsFlat()); |
| 2436 |
| 2437 transform.matrix().set(2, 0, 0.f); |
| 2438 transform.matrix().set(2, 1, 0.f); |
| 2439 transform.matrix().set(2, 3, 0.f); |
| 2440 |
| 2441 // Since the third column and row are both (0, 0, 1, 0), the transform is |
| 2442 // flat. |
| 2443 EXPECT_TRUE(transform.IsFlat()); |
| 2444 } |
| 2445 |
2423 // Another implementation of Preserves2dAxisAlignment that isn't as fast, | 2446 // Another implementation of Preserves2dAxisAlignment that isn't as fast, |
2424 // good for testing the faster implementation. | 2447 // good for testing the faster implementation. |
2425 static bool EmpiricallyPreserves2dAxisAlignment(const Transform& transform) { | 2448 static bool EmpiricallyPreserves2dAxisAlignment(const Transform& transform) { |
2426 Point3F p1(5.0f, 5.0f, 0.0f); | 2449 Point3F p1(5.0f, 5.0f, 0.0f); |
2427 Point3F p2(10.0f, 5.0f, 0.0f); | 2450 Point3F p2(10.0f, 5.0f, 0.0f); |
2428 Point3F p3(10.0f, 20.0f, 0.0f); | 2451 Point3F p3(10.0f, 20.0f, 0.0f); |
2429 Point3F p4(5.0f, 20.0f, 0.0f); | 2452 Point3F p4(5.0f, 20.0f, 0.0f); |
2430 | 2453 |
2431 QuadF test_quad(PointF(p1.x(), p1.y()), | 2454 QuadF test_quad(PointF(p1.x(), p1.y()), |
2432 PointF(p2.x(), p2.y()), | 2455 PointF(p2.x(), p2.y()), |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2685 EXPECT_EQ(expected.ToString(), box.ToString()); | 2708 EXPECT_EQ(expected.ToString(), box.ToString()); |
2686 | 2709 |
2687 Transform singular; | 2710 Transform singular; |
2688 singular.Scale3d(0.f, 0.f, 0.f); | 2711 singular.Scale3d(0.f, 0.f, 0.f); |
2689 EXPECT_FALSE(singular.TransformBoxReverse(&box)); | 2712 EXPECT_FALSE(singular.TransformBoxReverse(&box)); |
2690 } | 2713 } |
2691 | 2714 |
2692 } // namespace | 2715 } // namespace |
2693 | 2716 |
2694 } // namespace gfx | 2717 } // namespace gfx |
OLD | NEW |