diff options
author | Cary Clark <caryclark@skia.org> | 2018-05-16 21:28:55 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-05-17 14:02:43 +0000 |
commit | c06754b0466e14e1611fa3144bf337289e6ca82f (patch) | |
tree | 287a31a09b4556003569103655a855f8eefd43a6 /tests | |
parent | bd74e6a02ae0e7b031aa1d1cd73062dba2c93daf (diff) |
mapRect should not fiddle with nonfinite values.
Docs-Preview: https://skia.org/?cl=128682
Bug: skia:7967
Change-Id: Ic43387b7705ee8385b8df2430886484ff856077c
Reviewed-on: https://skia-review.googlesource.com/128682
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/MatrixTest.cpp | 18 | ||||
-rw-r--r-- | tests/RectTest.cpp | 26 |
2 files changed, 43 insertions, 1 deletions
diff --git a/tests/MatrixTest.cpp b/tests/MatrixTest.cpp index ce1254e720..5dfe2ca936 100644 --- a/tests/MatrixTest.cpp +++ b/tests/MatrixTest.cpp @@ -987,14 +987,30 @@ DEF_TEST(Matrix_maprects, r) { rand.nextSScalar1() * scale, rand.nextSScalar1() * scale, rand.nextSScalar1() * scale); - SkRect dst[3]; + SkRect dst[4]; mat.mapPoints((SkPoint*)&dst[0].fLeft, (SkPoint*)&src.fLeft, 2); dst[0].sort(); mat.mapRect(&dst[1], src); mat.mapRectScaleTranslate(&dst[2], src); + dst[3] = mat.mapRect(src); REPORTER_ASSERT(r, dst[0] == dst[1]); REPORTER_ASSERT(r, dst[0] == dst[2]); + REPORTER_ASSERT(r, dst[0] == dst[3]); + } + + // We should report nonfinite-ness after a mapping + { + // We have special-cases in mapRect for different matrix types + SkMatrix m0 = SkMatrix::MakeScale(1e20f, 1e20f); + SkMatrix m1; m1.setRotate(30); m1.postScale(1e20f, 1e20f); + + for (const auto& m : { m0, m1 }) { + SkRect rect = { 0, 0, 1e20f, 1e20f }; + REPORTER_ASSERT(r, rect.isFinite()); + rect = m.mapRect(rect); + REPORTER_ASSERT(r, !rect.isFinite()); + } } } diff --git a/tests/RectTest.cpp b/tests/RectTest.cpp index d34214d6d3..7d2601a8be 100644 --- a/tests/RectTest.cpp +++ b/tests/RectTest.cpp @@ -113,3 +113,29 @@ DEF_TEST(Rect_largest, reporter) { REPORTER_ASSERT(reporter, SkRectPriv::MakeLargestInverted().isEmpty()); } +/* + * Test the setBounds always handles non-finite values correctly: + * - setBoundsCheck should return false, and set the rect to all zeros + * - setBoundsNoCheck should ensure that rect.isFinite() is false (definitely NOT all zeros) + */ +DEF_TEST(Rect_setbounds, reporter) { + const SkPoint p0[] = { { SK_ScalarInfinity, 0 }, { 1, 1 }, { 2, 2 }, { 3, 3 } }; + const SkPoint p1[] = { { 0, SK_ScalarInfinity }, { 1, 1 }, { 2, 2 }, { 3, 3 } }; + const SkPoint p2[] = { { SK_ScalarNaN, 0 }, { 1, 1 }, { 2, 2 }, { 3, 3 } }; + const SkPoint p3[] = { { 0, SK_ScalarNaN }, { 1, 1 }, { 2, 2 }, { 3, 3 } }; + + SkRect r; + const SkRect zeror = { 0, 0, 0, 0 }; + for (const SkPoint* pts : { p0, p1, p2, p3 }) { + for (int n = 1; n <= 4; ++n) { + bool isfinite = r.setBoundsCheck(pts, n); + REPORTER_ASSERT(reporter, !isfinite); + REPORTER_ASSERT(reporter, r == zeror); + + r.setBoundsNoCheck(pts, n); + if (r.isFinite()) + r.setBoundsNoCheck(pts, n); + REPORTER_ASSERT(reporter, !r.isFinite()); + } + } +} |