| 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> |
| 11 #include <ostream> | 11 #include <ostream> |
| 12 #include <limits> | 12 #include <limits> |
| 13 | 13 |
| 14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "ui/gfx/box_f.h" |
| 17 #include "ui/gfx/point.h" | 18 #include "ui/gfx/point.h" |
| 18 #include "ui/gfx/point3_f.h" | 19 #include "ui/gfx/point3_f.h" |
| 19 #include "ui/gfx/quad_f.h" | 20 #include "ui/gfx/quad_f.h" |
| 20 #include "ui/gfx/transform_util.h" | 21 #include "ui/gfx/transform_util.h" |
| 21 #include "ui/gfx/vector3d_f.h" | 22 #include "ui/gfx/vector3d_f.h" |
| 22 | 23 |
| 23 namespace gfx { | 24 namespace gfx { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| (...skipping 2480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2507 TEST(XFormTest, To2dTranslation) { | 2508 TEST(XFormTest, To2dTranslation) { |
| 2508 Vector2dF translation(3.f, 7.f); | 2509 Vector2dF translation(3.f, 7.f); |
| 2509 Transform transform; | 2510 Transform transform; |
| 2510 transform.Translate(translation.x(), translation.y() + 1); | 2511 transform.Translate(translation.x(), translation.y() + 1); |
| 2511 EXPECT_NE(translation.ToString(), transform.To2dTranslation().ToString()); | 2512 EXPECT_NE(translation.ToString(), transform.To2dTranslation().ToString()); |
| 2512 transform.MakeIdentity(); | 2513 transform.MakeIdentity(); |
| 2513 transform.Translate(translation.x(), translation.y()); | 2514 transform.Translate(translation.x(), translation.y()); |
| 2514 EXPECT_EQ(translation.ToString(), transform.To2dTranslation().ToString()); | 2515 EXPECT_EQ(translation.ToString(), transform.To2dTranslation().ToString()); |
| 2515 } | 2516 } |
| 2516 | 2517 |
| 2518 TEST(XFormTest, TransformRect) { |
| 2519 Transform translation; |
| 2520 translation.Translate(3.f, 7.f); |
| 2521 RectF rect(1.f, 2.f, 3.f, 4.f); |
| 2522 RectF expected(4.f, 9.f, 3.f, 4.f); |
| 2523 translation.TransformRect(&rect); |
| 2524 EXPECT_EQ(expected.ToString(), rect.ToString()); |
| 2525 } |
| 2526 |
| 2527 TEST(XFormTest, TransformRectReverse) { |
| 2528 Transform translation; |
| 2529 translation.Translate(3.f, 7.f); |
| 2530 RectF rect(1.f, 2.f, 3.f, 4.f); |
| 2531 RectF expected(-2.f, -5.f, 3.f, 4.f); |
| 2532 EXPECT_TRUE(translation.TransformRectReverse(&rect)); |
| 2533 EXPECT_EQ(expected.ToString(), rect.ToString()); |
| 2534 |
| 2535 Transform singular; |
| 2536 singular.Scale3d(0.f, 0.f, 0.f); |
| 2537 EXPECT_FALSE(singular.TransformRectReverse(&rect)); |
| 2538 } |
| 2539 |
| 2540 TEST(XFormTest, TransformBox) { |
| 2541 Transform translation; |
| 2542 translation.Translate3d(3.f, 7.f, 6.f); |
| 2543 BoxF box(1.f, 2.f, 3.f, 4.f, 5.f, 6.f); |
| 2544 BoxF expected(4.f, 9.f, 9.f, 4.f, 5.f, 6.f); |
| 2545 translation.TransformBox(&box); |
| 2546 EXPECT_EQ(expected.ToString(), box.ToString()); |
| 2547 } |
| 2548 |
| 2549 TEST(XFormTest, TransformBoxReverse) { |
| 2550 Transform translation; |
| 2551 translation.Translate3d(3.f, 7.f, 6.f); |
| 2552 BoxF box(1.f, 2.f, 3.f, 4.f, 5.f, 6.f); |
| 2553 BoxF expected(-2.f, -5.f, -3.f, 4.f, 5.f, 6.f); |
| 2554 EXPECT_TRUE(translation.TransformBoxReverse(&box)); |
| 2555 EXPECT_EQ(expected.ToString(), box.ToString()); |
| 2556 |
| 2557 Transform singular; |
| 2558 singular.Scale3d(0.f, 0.f, 0.f); |
| 2559 EXPECT_FALSE(singular.TransformBoxReverse(&box)); |
| 2560 } |
| 2561 |
| 2517 } // namespace | 2562 } // namespace |
| 2518 | 2563 |
| 2519 } // namespace gfx | 2564 } // namespace gfx |
| OLD | NEW |