diff options
author | Robert Phillips <robertphillips@google.com> | 2018-07-10 10:11:01 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-07-10 15:01:11 +0000 |
commit | c100d48e4241ecc7be0fd7fd79eae13e13f255c0 (patch) | |
tree | 9964c8f11311271d21748fd69ed04cc3f11542a7 /tests | |
parent | 45e27c8eed8f1673efebcb6cb2c03b8644c9c7a5 (diff) |
Expand testing of SkMatrix::decomposeScale
Bug: skia:7211
Change-Id: If03ad1d364b33e174d91010ca250cd6c2d2f67c2
Reviewed-on: https://skia-review.googlesource.com/140185
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/MatrixTest.cpp | 56 |
1 files changed, 51 insertions, 5 deletions
diff --git a/tests/MatrixTest.cpp b/tests/MatrixTest.cpp index 03661dc437..fccbf6d8f5 100644 --- a/tests/MatrixTest.cpp +++ b/tests/MatrixTest.cpp @@ -20,7 +20,7 @@ static bool nearly_equal_scalar(SkScalar a, SkScalar b) { static bool nearly_equal(const SkMatrix& a, const SkMatrix& b) { for (int i = 0; i < 9; i++) { if (!nearly_equal_scalar(a[i], b[i])) { - SkDebugf("not equal %g %g\n", (float)a[i], (float)b[i]); + SkDebugf("matrices not equal [%d] %g %g\n", i, (float)a[i], (float)b[i]); return false; } } @@ -804,18 +804,56 @@ static void test_matrix_homogeneous(skiatest::Reporter* reporter) { } -static bool check_decompScale(const SkMatrix& matrix) { +static bool check_decompScale(const SkMatrix& original) { SkSize scale; SkMatrix remaining; - if (!matrix.decomposeScale(&scale, &remaining)) { + if (!original.decomposeScale(&scale, &remaining)) { return false; } if (scale.width() <= 0 || scale.height() <= 0) { return false; } - remaining.preScale(scale.width(), scale.height()); - return nearly_equal(matrix, remaining); + + // First ensure that the decomposition reconstitutes back to the original + { + SkMatrix reconstituted = remaining; + + // This should be 'preScale' but, due to skbug.com/7211, it is reversed! + reconstituted.postScale(scale.width(), scale.height()); + if (!nearly_equal(original, reconstituted)) { + return false; + } + } + + // Then push some points through both paths and make sure they are the same. + static const int kNumPoints = 5; + const SkPoint testPts[kNumPoints] = { + { 0.0f, 0.0f }, + { 1.0f, 1.0f }, + { 1.0f, 0.5f }, + { -1.0f, -0.5f }, + { -1.0f, 2.0f } + }; + + SkPoint v1[kNumPoints]; + original.mapPoints(v1, testPts, kNumPoints); + + SkPoint v2[kNumPoints]; + SkMatrix scaleMat = SkMatrix::MakeScale(scale.width(), scale.height()); + + // Note, we intend the decomposition to be applied in the order scale and then remainder but, + // due to skbug.com/7211, the order is reversed! + remaining.mapPoints(v2, testPts, kNumPoints); + scaleMat.mapPoints(v2, kNumPoints); + + for (int i = 0; i < kNumPoints; ++i) { + if (!SkPointPriv::EqualsWithinTolerance(v1[i], v2[i], 0.00001f)) { + return false; + } + } + + return true; } static void test_decompScale(skiatest::Reporter* reporter) { @@ -830,6 +868,14 @@ static void test_decompScale(skiatest::Reporter* reporter) { m.setScale(1, 0); REPORTER_ASSERT(reporter, !check_decompScale(m)); + + m.setRotate(35, 0, 0); + m.preScale(2, 3); + REPORTER_ASSERT(reporter, check_decompScale(m)); + + m.setRotate(35, 0, 0); + m.postScale(2, 3); + REPORTER_ASSERT(reporter, check_decompScale(m)); } DEF_TEST(Matrix, reporter) { |