diff options
author | 2014-09-02 13:15:40 -0700 | |
---|---|---|
committer | 2014-09-02 13:15:41 -0700 | |
commit | 17a845f76094eb3b5ac464556fced2a60dd0f088 (patch) | |
tree | 4e9908315386d1f3c5d9997336d5e3c2e9c21382 /tests | |
parent | 7f91c3359fe6d7d9deb3aee5efb163e0bd7112d4 (diff) |
Fix matrix similarity test on arm64
Addresses precision issue by using a simpler test.
Also fixes issues with IvMatrix::preservesRightAngles, and adds unit tests.
BUG=skia:2405
R=robertphillips@google.com, egdaniel@google.com, djsollen@google.com, reed@google.com
Author: jvanverth@google.com
Review URL: https://codereview.chromium.org/520123002
Diffstat (limited to 'tests')
-rw-r--r-- | tests/MatrixTest.cpp | 48 |
1 files changed, 39 insertions, 9 deletions
diff --git a/tests/MatrixTest.cpp b/tests/MatrixTest.cpp index cbec021b40..fc7ac42a99 100644 --- a/tests/MatrixTest.cpp +++ b/tests/MatrixTest.cpp @@ -245,88 +245,96 @@ static void test_matrix_min_max_scale(skiatest::Reporter* reporter) { } } -static void test_matrix_is_similarity(skiatest::Reporter* reporter) { +static void test_matrix_preserve_shape(skiatest::Reporter* reporter) { SkMatrix mat; // identity mat.setIdentity(); REPORTER_ASSERT(reporter, mat.isSimilarity()); + REPORTER_ASSERT(reporter, mat.preservesRightAngles()); // translation only mat.reset(); mat.setTranslate(SkIntToScalar(100), SkIntToScalar(100)); REPORTER_ASSERT(reporter, mat.isSimilarity()); + REPORTER_ASSERT(reporter, mat.preservesRightAngles()); // scale with same size mat.reset(); mat.setScale(SkIntToScalar(15), SkIntToScalar(15)); REPORTER_ASSERT(reporter, mat.isSimilarity()); + REPORTER_ASSERT(reporter, mat.preservesRightAngles()); // scale with one negative mat.reset(); mat.setScale(SkIntToScalar(-15), SkIntToScalar(15)); REPORTER_ASSERT(reporter, mat.isSimilarity()); + REPORTER_ASSERT(reporter, mat.preservesRightAngles()); // scale with different size mat.reset(); mat.setScale(SkIntToScalar(15), SkIntToScalar(20)); REPORTER_ASSERT(reporter, !mat.isSimilarity()); + REPORTER_ASSERT(reporter, mat.preservesRightAngles()); // scale with same size at a pivot point mat.reset(); mat.setScale(SkIntToScalar(15), SkIntToScalar(15), SkIntToScalar(2), SkIntToScalar(2)); REPORTER_ASSERT(reporter, mat.isSimilarity()); + REPORTER_ASSERT(reporter, mat.preservesRightAngles()); // scale with different size at a pivot point mat.reset(); mat.setScale(SkIntToScalar(15), SkIntToScalar(20), SkIntToScalar(2), SkIntToScalar(2)); REPORTER_ASSERT(reporter, !mat.isSimilarity()); + REPORTER_ASSERT(reporter, mat.preservesRightAngles()); // skew with same size mat.reset(); mat.setSkew(SkIntToScalar(15), SkIntToScalar(15)); REPORTER_ASSERT(reporter, !mat.isSimilarity()); + REPORTER_ASSERT(reporter, !mat.preservesRightAngles()); // skew with different size mat.reset(); mat.setSkew(SkIntToScalar(15), SkIntToScalar(20)); REPORTER_ASSERT(reporter, !mat.isSimilarity()); + REPORTER_ASSERT(reporter, !mat.preservesRightAngles()); // skew with same size at a pivot point mat.reset(); mat.setSkew(SkIntToScalar(15), SkIntToScalar(15), SkIntToScalar(2), SkIntToScalar(2)); REPORTER_ASSERT(reporter, !mat.isSimilarity()); + REPORTER_ASSERT(reporter, !mat.preservesRightAngles()); // skew with different size at a pivot point mat.reset(); mat.setSkew(SkIntToScalar(15), SkIntToScalar(20), SkIntToScalar(2), SkIntToScalar(2)); REPORTER_ASSERT(reporter, !mat.isSimilarity()); + REPORTER_ASSERT(reporter, !mat.preservesRightAngles()); // perspective x mat.reset(); mat.setPerspX(SkScalarToPersp(SK_Scalar1 / 2)); REPORTER_ASSERT(reporter, !mat.isSimilarity()); + REPORTER_ASSERT(reporter, !mat.preservesRightAngles()); // perspective y mat.reset(); mat.setPerspY(SkScalarToPersp(SK_Scalar1 / 2)); REPORTER_ASSERT(reporter, !mat.isSimilarity()); + REPORTER_ASSERT(reporter, !mat.preservesRightAngles()); // rotate for (int angle = 0; angle < 360; ++angle) { mat.reset(); mat.setRotate(SkIntToScalar(angle)); -#ifndef SK_CPU_ARM64 REPORTER_ASSERT(reporter, mat.isSimilarity()); -#else - // 64-bit ARM devices built with -O2 and -ffp-contract=fast have a loss - // of precision and require that we have a higher tolerance - REPORTER_ASSERT(reporter, mat.isSimilarity(SK_ScalarNearlyZero + 0.00010113f)); -#endif + REPORTER_ASSERT(reporter, mat.preservesRightAngles()); } // see if there are any accumulated precision issues @@ -335,38 +343,60 @@ static void test_matrix_is_similarity(skiatest::Reporter* reporter) { mat.postRotate(SkIntToScalar(1)); } REPORTER_ASSERT(reporter, mat.isSimilarity()); + REPORTER_ASSERT(reporter, mat.preservesRightAngles()); // rotate + translate mat.reset(); mat.setRotate(SkIntToScalar(30)); mat.postTranslate(SkIntToScalar(10), SkIntToScalar(20)); REPORTER_ASSERT(reporter, mat.isSimilarity()); + REPORTER_ASSERT(reporter, mat.preservesRightAngles()); // rotate + uniform scale mat.reset(); mat.setRotate(SkIntToScalar(30)); mat.postScale(SkIntToScalar(2), SkIntToScalar(2)); REPORTER_ASSERT(reporter, mat.isSimilarity()); + REPORTER_ASSERT(reporter, mat.preservesRightAngles()); // rotate + non-uniform scale mat.reset(); mat.setRotate(SkIntToScalar(30)); mat.postScale(SkIntToScalar(3), SkIntToScalar(2)); REPORTER_ASSERT(reporter, !mat.isSimilarity()); + REPORTER_ASSERT(reporter, !mat.preservesRightAngles()); + + // non-uniform scale + rotate + mat.reset(); + mat.setScale(SkIntToScalar(3), SkIntToScalar(2)); + mat.postRotate(SkIntToScalar(30)); + REPORTER_ASSERT(reporter, !mat.isSimilarity()); + REPORTER_ASSERT(reporter, mat.preservesRightAngles()); // all zero mat.setAll(0, 0, 0, 0, 0, 0, 0, 0, 0); REPORTER_ASSERT(reporter, !mat.isSimilarity()); + REPORTER_ASSERT(reporter, !mat.preservesRightAngles()); // all zero except perspective + mat.reset(); mat.setAll(0, 0, 0, 0, 0, 0, 0, 0, SK_Scalar1); REPORTER_ASSERT(reporter, !mat.isSimilarity()); + REPORTER_ASSERT(reporter, !mat.preservesRightAngles()); + + // scales zero, only skews (rotation) + mat.setAll(0, SK_Scalar1, 0, + -SK_Scalar1, 0, 0, + 0, 0, SkMatrix::I()[8]); + REPORTER_ASSERT(reporter, mat.isSimilarity()); + REPORTER_ASSERT(reporter, mat.preservesRightAngles()); - // scales zero, only skews + // scales zero, only skews (reflection) mat.setAll(0, SK_Scalar1, 0, SK_Scalar1, 0, 0, 0, 0, SkMatrix::I()[8]); REPORTER_ASSERT(reporter, mat.isSimilarity()); + REPORTER_ASSERT(reporter, mat.preservesRightAngles()); } // For test_matrix_decomposition, below. @@ -815,7 +845,7 @@ DEF_TEST(Matrix, reporter) { REPORTER_ASSERT(reporter, !are_equal(reporter, mat, mat2)); test_matrix_min_max_scale(reporter); - test_matrix_is_similarity(reporter); + test_matrix_preserve_shape(reporter); test_matrix_recttorect(reporter); test_matrix_decomposition(reporter); test_matrix_homogeneous(reporter); |