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 "ui/gfx/transform_util.h" | 5 #include "ui/gfx/transform_util.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "ui/gfx/point.h" | 8 #include "ui/gfx/point.h" |
9 #include "ui/gfx/point3_f.h" | |
10 #include "ui/gfx/rect_f.h" | |
9 | 11 |
10 namespace gfx { | 12 namespace gfx { |
11 namespace { | 13 namespace { |
12 | 14 |
13 TEST(TransformUtilTest, GetScaleTransform) { | 15 TEST(TransformUtilTest, GetScaleTransform) { |
14 const Point kAnchor(20, 40); | 16 const Point kAnchor(20, 40); |
15 const float kScale = 0.5f; | 17 const float kScale = 0.5f; |
16 | 18 |
17 Transform scale = GetScaleTransform(kAnchor, kScale); | 19 Transform scale = GetScaleTransform(kAnchor, kScale); |
18 | 20 |
19 const int kOffset = 10; | 21 const int kOffset = 10; |
20 for (int sign_x = -1; sign_x <= 1; ++sign_x) { | 22 for (int sign_x = -1; sign_x <= 1; ++sign_x) { |
21 for (int sign_y = -1; sign_y <= 1; ++sign_y) { | 23 for (int sign_y = -1; sign_y <= 1; ++sign_y) { |
22 Point test(kAnchor.x() + sign_x * kOffset, | 24 Point test(kAnchor.x() + sign_x * kOffset, |
23 kAnchor.y() + sign_y * kOffset); | 25 kAnchor.y() + sign_y * kOffset); |
24 scale.TransformPoint(&test); | 26 scale.TransformPoint(&test); |
25 | 27 |
26 EXPECT_EQ(Point(kAnchor.x() + sign_x * kOffset * kScale, | 28 EXPECT_EQ(Point(kAnchor.x() + sign_x * kOffset * kScale, |
27 kAnchor.y() + sign_y * kOffset * kScale), | 29 kAnchor.y() + sign_y * kOffset * kScale), |
28 test); | 30 test); |
29 } | 31 } |
30 } | 32 } |
31 } | 33 } |
32 | 34 |
35 TEST(TransformUtilTest, SnapRotation) { | |
36 gfx::Transform transform; | |
37 | |
38 // Translation must be a multiple of scale or else the back mapping will not | |
39 // be an integer. | |
40 transform.Translate(20.0, -30.0); | |
41 transform.Scale(2.0, 2.0); | |
42 transform.RotateAboutZAxis(89.99); | |
43 | |
44 DecomposedTransform decomposed, result; | |
45 | |
46 DecomposeTransform(&decomposed, transform); | |
47 | |
48 RectF viewport(1920.0, 1200.0); | |
49 bool snapped = SnapRotation(&result, decomposed, viewport); | |
50 | |
51 EXPECT_TRUE(snapped) << "Viewport should snap for this rotation."; | |
52 } | |
53 | |
54 TEST(TransformUtilTest, NoSnapRotation) { | |
55 gfx::Transform transform; | |
56 | |
57 // Translation must be a multiple of scale or else the back mapping will not | |
58 // be an integer. | |
59 transform.Translate(102.0, -96.0); | |
60 transform.Scale(2.0, 2.0); | |
61 transform.RotateAboutZAxis(89.9); | |
62 | |
63 DecomposedTransform decomposed, result; | |
64 | |
65 DecomposeTransform(&decomposed, transform); | |
66 | |
67 RectF viewport(1920.0, 1200.0); | |
68 bool snapped = SnapRotation(&result, decomposed, viewport); | |
69 | |
70 EXPECT_FALSE(snapped) << "Viewport should not snap for this rotation."; | |
71 } | |
Ian Vollick
2013/09/11 12:19:48
Please add tests for a viewport that's far away fr
avallee
2013/09/14 01:32:25
Done.
| |
72 | |
33 } // namespace | 73 } // namespace |
34 } // namespace gfx | 74 } // namespace gfx |
OLD | NEW |