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

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: Address danakj@ comments. Created 7 years, 2 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
« no previous file with comments | « 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.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, SnapTransform) {
Ian Vollick 2013/10/21 18:36:30 Need tests for snapping scale and translation.
avallee 2013/10/23 14:48:23 Done.
36 gfx::Transform result(gfx::Transform::kSkipInitialization);
37 gfx::Transform transform;
38 transform.RotateAboutZAxis(89.99);
39
40 Rect viewport(1920, 1200);
41 bool snapped = SnapTransform(&result, transform, viewport);
42
43 EXPECT_TRUE(snapped) << "Viewport should snap for this rotation.";
44 }
45
46 TEST(TransformUtilTest, SnapTransformDistantViewport) {
47 const int kOffset = 5000;
48 gfx::Transform result(gfx::Transform::kSkipInitialization);
49 gfx::Transform transform;
50
51 transform.RotateAboutZAxis(89.99);
52
53 Rect viewport(1920 + kOffset, 1200 + kOffset);
54 bool snapped = SnapTransform(&result, transform, viewport);
55
56 EXPECT_FALSE(snapped) << "Distant viewport shouldn't snap by more than 1px.";
57 }
58
59 TEST(TransformUtilTest, NoSnapTransform) {
60 gfx::Transform result(gfx::Transform::kSkipInitialization);
61 gfx::Transform transform;
62 const int kOffset = 5000;
63
64 transform.RotateAboutZAxis(89.9);
65
66 Rect viewport(1920 + kOffset, 1200 + kOffset);
67 bool snapped = SnapTransform(&result, transform, viewport);
68
69 EXPECT_FALSE(snapped) << "Viewport should not snap for this rotation.";
70 }
71
33 } // namespace 72 } // namespace
34 } // namespace gfx 73 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/transform_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698