diff options
author | Kevin Lubick <kjlubick@google.com> | 2023-01-03 10:34:27 -0500 |
---|---|---|
committer | Kevin Lubick <kjlubick@google.com> | 2023-01-03 16:16:36 +0000 |
commit | c31623792b89e119ce1ae7f636f3ed82155535f6 (patch) | |
tree | 512895a89534db8baf09439dcdd9225816e8d41c /tests/PathOpsDVectorTest.cpp | |
parent | 7167b1e2894de6455f563014d4c044898aac8b72 (diff) | |
download | skia-c31623792b89e119ce1ae7f636f3ed82155535f6.tar.gz |
Use skvx instead of SkDVector in Path/PathBuilder
We would like to remove the dependency of SkPath on SkPathops.
Remaining dependencies:
- SkGeometry.cpp
- SkGlyph.cpp
While working on this, I broke something and the Paths tests
started to fail. I found those hard to understand and debug,
so I ported some of the failing ones over to PathBuilder
(which does not have as comprehensive of tests). I figured out
what I was doing wrong and what those failing tests were for.
See the additional documentation in SkPath.cpp and SkPathBuilder.cpp
This adds some new static methods to skvx, along with unit tests
for them.
Because I was comparing functionality between skvx and SkDVector,
I added some tests to the latter for an apples to apple comparison.
Change-Id: I8aa43ed021949ccf1015b2dedf26a52b59d15860
Bug: skia:13983
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/621198
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Diffstat (limited to 'tests/PathOpsDVectorTest.cpp')
-rw-r--r-- | tests/PathOpsDVectorTest.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/PathOpsDVectorTest.cpp b/tests/PathOpsDVectorTest.cpp index 2312507048..529c57fcf3 100644 --- a/tests/PathOpsDVectorTest.cpp +++ b/tests/PathOpsDVectorTest.cpp @@ -5,6 +5,7 @@ * found in the LICENSE file. */ #include "include/core/SkPoint.h" +#include "include/core/SkScalar.h" #include "include/core/SkTypes.h" #include "src/pathops/SkPathOpsPoint.h" #include "src/pathops/SkPathOpsTypes.h" @@ -14,6 +15,7 @@ #include <array> #include <cmath> #include <cstddef> +#include <limits> static const SkDPoint tests[] = { {0, 0}, @@ -53,3 +55,38 @@ DEF_TEST(PathOpsDVector, reporter) { REPORTER_ASSERT(reporter, v1Cross == 0); } } + +DEF_TEST(SkDVector_normalize, reporter) { + // See also SkVx_normalize + auto assertDoublesEqual = [&](double left, double right) { + REPORTER_ASSERT(reporter, SkScalarNearlyEqual(left, right), "%f != %f", left, right); + }; + SkDVector first{1.2, 3.4}; + first.normalize(); + REPORTER_ASSERT(reporter, first.isFinite()); + assertDoublesEqual(first.fX, 0.332820); + assertDoublesEqual(first.fY, 0.942990); + + SkDVector second{2.3, -4.5}; + second.normalize(); + REPORTER_ASSERT(reporter, second.isFinite()); + assertDoublesEqual(second.fX, 0.455111); + assertDoublesEqual(second.fY, -0.890435); +} + +DEF_TEST(SkDVector_normalize_infinity_and_nan, reporter) { + // See also SkVx_normalize_infinity_and_nan + SkDVector first{0, 0}; + first.normalize(); + REPORTER_ASSERT(reporter, !first.isFinite()); + REPORTER_ASSERT(reporter, std::isnan(first.fX), "%f is not nan", first.fX); + REPORTER_ASSERT(reporter, std::isnan(first.fY), "%f is not nan", first.fY); + + SkDVector second{std::numeric_limits<double>::max(), + std::numeric_limits<double>::max()}; + second.normalize(); + REPORTER_ASSERT(reporter, second.isFinite()); + REPORTER_ASSERT(reporter, second.fX == 0, "%f != 0", second.fX); + REPORTER_ASSERT(reporter, second.fY == 0, "%f != 0", second.fY); +} + |