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

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: Add a test and fixed comments by vollick@. 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..51bca573008c4bfeadb121a67a6c14fb9b86c21b 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,51 @@ TEST(TransformUtilTest, GetScaleTransform) {
}
}
+TEST(TransformUtilTest, SnapRotation) {
+ gfx::Transform transform;
+ transform.RotateAboutZAxis(89.99);
+
+ DecomposedTransform decomposed, result;
+
+ DecomposeTransform(&decomposed, transform);
+
+ RectF viewport(1920.0, 1200.0);
+ bool snapped = SnapRotation(&result, decomposed, transform, viewport);
+
+ EXPECT_TRUE(snapped) << "Viewport should snap for this rotation.";
+}
+
+TEST(TransformUtilTest, SnapDistantRotation) {
+ const int kOffset = 5000;
+ gfx::Transform transform;
+
+ transform.RotateAboutZAxis(89.99);
+
+ DecomposedTransform decomposed, result;
+
+ DecomposeTransform(&decomposed, transform);
+
+ RectF viewport(1920.0 + kOffset, 1200.0 + kOffset);
+ bool snapped = SnapRotation(&result, decomposed, transform, viewport);
+
+ EXPECT_FALSE(snapped) << "Distant viewport shouldn't snap by more than 1px.";
+}
+
+TEST(TransformUtilTest, NoSnapRotation) {
+ gfx::Transform transform;
+ const int kOffset = 5000;
+
+ transform.RotateAboutZAxis(89.9);
+
+ DecomposedTransform decomposed, result;
+
+ DecomposeTransform(&decomposed, transform);
+
+ RectF viewport(1920.0 + kOffset, 1200.0 + kOffset);
+ bool snapped = SnapRotation(&result, decomposed, transform, viewport);
+
+ EXPECT_FALSE(snapped) << "Viewport should not snap for this rotation.";
+}
+
} // 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