Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(537)

Side by Side Diff: ui/gfx/transform_util_unittest.cc

Issue 23444049: Implement transform snapping for gfx::Transforms. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« ui/gfx/transform_util.cc ('K') | « ui/gfx/transform_util.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 transform.Translate(103.0, -97.0);
39 transform.Scale(2.0, 3.0);
40 transform.RotateAboutZAxis(89.99);
41
42 DecomposedTransform decomposed, result;
43
44 DecomposeTransform(&decomposed, transform);
45
46 RectF viewport(1920.0, 1200.0);
47 bool snapped = SnapRotation(&result, decomposed, viewport);
48
49 EXPECT_TRUE(snapped) << "Viewport should snap for this rotation.";
50 }
51
52 TEST(TransformUtilTest, NoSnapRotation) {
53 gfx::Transform transform;
54
55 transform.Translate(103.0, -97.0);
56 transform.Scale(2.0, 3.0);
57 transform.RotateAboutZAxis(89.9);
58
59 DecomposedTransform decomposed, result;
60
61 DecomposeTransform(&decomposed, transform);
62
63 RectF viewport(1920.0, 1200.0);
64 bool snapped = SnapRotation(&result, decomposed, viewport);
65
66 EXPECT_FALSE(snapped) << "Viewport should not snap for this rotation.";
67 }
68
33 } // namespace 69 } // namespace
34 } // namespace gfx 70 } // namespace gfx
OLDNEW
« ui/gfx/transform_util.cc ('K') | « ui/gfx/transform_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698