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

Unified 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: Fix test case to back-map correctly. Address danajk@ comments. 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 side-by-side diff with in-line comments
Download patch
« ui/gfx/transform_util.cc ('K') | « ui/gfx/transform_util.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/transform_util_unittest.cc
diff --git a/ui/gfx/transform_util_unittest.cc b/ui/gfx/transform_util_unittest.cc
index 94195c29bb92f90641e8eecdfb87ae3bcb966b27..2d9ac044ceb1b7e8339bdd3f6b2080bc29964665 100644
--- a/ui/gfx/transform_util_unittest.cc
+++ b/ui/gfx/transform_util_unittest.cc
@@ -6,6 +6,8 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/point.h"
+#include "ui/gfx/point3_f.h"
+#include "ui/gfx/rect_f.h"
namespace gfx {
namespace {
@@ -30,5 +32,43 @@ TEST(TransformUtilTest, GetScaleTransform) {
}
}
+TEST(TransformUtilTest, SnapRotation) {
+ gfx::Transform transform;
+
+ // Translation must be a multiple of scale or else the back mapping will not
+ // be an integer.
+ transform.Translate(20.0, -30.0);
+ transform.Scale(2.0, 2.0);
+ transform.RotateAboutZAxis(89.99);
+
+ DecomposedTransform decomposed, result;
+
+ DecomposeTransform(&decomposed, transform);
+
+ RectF viewport(1920.0, 1200.0);
+ bool snapped = SnapRotation(&result, decomposed, viewport);
+
+ EXPECT_TRUE(snapped) << "Viewport should snap for this rotation.";
+}
+
+TEST(TransformUtilTest, NoSnapRotation) {
+ gfx::Transform transform;
+
+ // Translation must be a multiple of scale or else the back mapping will not
+ // be an integer.
+ transform.Translate(102.0, -96.0);
+ transform.Scale(2.0, 2.0);
+ transform.RotateAboutZAxis(89.9);
+
+ DecomposedTransform decomposed, result;
+
+ DecomposeTransform(&decomposed, transform);
+
+ RectF viewport(1920.0, 1200.0);
+ bool snapped = SnapRotation(&result, decomposed, viewport);
+
+ EXPECT_FALSE(snapped) << "Viewport should not snap for this rotation.";
+}
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.
+
} // namespace
} // namespace gfx
« 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