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

Unified Diff: cc/base/math_util_unittest.cc

Issue 27223008: Provide approximate type functions for SkMatrix44. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Re-upload. 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 side-by-side diff with in-line comments
Download patch
Index: cc/base/math_util_unittest.cc
diff --git a/cc/base/math_util_unittest.cc b/cc/base/math_util_unittest.cc
index 6e276c25d64736057f975c17ce1b4ee6c08f7c46..0ba9cc1af605d4a17167ab923916f5a8da16808e 100644
--- a/cc/base/math_util_unittest.cc
+++ b/cc/base/math_util_unittest.cc
@@ -5,6 +5,7 @@
#include "cc/base/math_util.h"
#include <cmath>
+#include <limits>
#include "cc/test/geometry_test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -16,6 +17,32 @@
namespace cc {
namespace {
+const SkMScalar kApproxZero =
+ SkFloatToMScalar(std::numeric_limits<float>::epsilon());
+const SkMScalar kApproxOne = 1 - kApproxZero;
+
+void SetApproxIdentity(SkMatrix44* matrix) {
+ matrix->set(0, 0, kApproxOne);
+ matrix->set(0, 1, kApproxZero);
+ matrix->set(0, 2, kApproxZero);
+ matrix->set(0, 3, kApproxZero);
+
+ matrix->set(1, 0, kApproxZero);
+ matrix->set(1, 1, kApproxOne);
+ matrix->set(1, 2, kApproxZero);
+ matrix->set(1, 3, kApproxZero);
+
+ matrix->set(2, 0, kApproxZero);
+ matrix->set(2, 1, kApproxZero);
+ matrix->set(2, 2, kApproxOne);
+ matrix->set(2, 3, kApproxZero);
+
+ matrix->set(3, 0, kApproxZero);
+ matrix->set(3, 1, kApproxZero);
+ matrix->set(3, 2, kApproxZero);
+ matrix->set(3, 3, kApproxOne);
+}
+
TEST(MathUtilTest, ProjectionOfPerpendicularPlane) {
// In this case, the m33() element of the transform becomes zero, which could
// cause a divide-by-zero when projecting points/quads.
@@ -120,5 +147,56 @@ TEST(MathUtilTest, VectorProjection) {
projected_vector.y() / target_vector.y());
}
+TEST(MathUtilTest, ExactPureTranslationMatrix) {
+ SkMatrix44 matrix(SkMatrix44::kIdentity_Constructor);
+
+ // set translate values to values other than 0 or 1
+ matrix.set(0, 3, 3.4);
+ matrix.set(1, 3, 4.4);
+ matrix.set(2, 3, 5.6);
+
+ EXPECT_TRUE(MathUtil::IsMatrixApproximatelyPureTranslation(matrix, 0));
+ EXPECT_TRUE(
+ MathUtil::IsMatrixApproximatelyPureTranslation(matrix, kApproxZero));
+}
+
+TEST(MathUtilTest, ApproximatelyPureTranslationMatrix) {
+ SkMatrix44 matrix(SkMatrix44::kUninitialized_Constructor);
+ SetApproxIdentity(&matrix);
+ // Some values must be exact
+ matrix.set(3, 0, 0);
+ matrix.set(3, 1, 0);
+ matrix.set(3, 2, 0);
+ matrix.set(3, 3, 1);
+
+ // set translate values to values other than 0 or 1
+ matrix.set(0, 3, 3.4);
+ matrix.set(1, 3, 4.4);
+ matrix.set(2, 3, 5.6);
+
+ EXPECT_FALSE(MathUtil::IsMatrixApproximatelyPureTranslation(matrix, 0));
shawnsingh 2013/10/16 19:05:37 nice way to check that we are not accidentally an
+ EXPECT_TRUE(
+ MathUtil::IsMatrixApproximatelyPureTranslation(matrix, kApproxZero));
+}
+
+TEST(MathUtilTest, NotApproximatelyPureTranslationMatrix) {
+ SkMatrix44 matrix(SkMatrix44::kUninitialized_Constructor);
+ SetApproxIdentity(&matrix);
+ // Some values must be exact
+ matrix.set(3, 0, 0);
+ matrix.set(3, 1, 0);
+ matrix.set(3, 2, 0);
+ matrix.set(3, 3, 1);
+
+ // set some values (not translate values) to values other than 0 or 1
+ matrix.set(0, 1, 3.4);
+ matrix.set(3, 2, 4.4);
+ matrix.set(2, 0, 5.6);
+
+ EXPECT_FALSE(MathUtil::IsMatrixApproximatelyPureTranslation(matrix, 0));
+ EXPECT_FALSE(
+ MathUtil::IsMatrixApproximatelyPureTranslation(matrix, kApproxZero));
+}
+
} // namespace
} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698