aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar caryclark <caryclark@google.com>2016-09-28 09:22:17 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-09-28 09:22:17 -0700
commite3a4e993ef79788d5ee807b10ff588e9c46bac6d (patch)
treeda042cd555a96f4fa5d8975e8fafeb20d7b75f26
parent33069255769246c703e1fbdbe14a752c31d0ad1e (diff)
fix cubic linear test
Check to see if the line between end points is degenerate before measuring control points. Also, add test case for a bug to see if it shows up on any platform. TBR=reed@google.com BUG=skia:5169, skia:5240 GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2375053002 Review-Url: https://codereview.chromium.org/2375053002
-rw-r--r--src/pathops/SkOpBuilder.cpp4
-rw-r--r--src/pathops/SkPathOpsCubic.cpp3
-rw-r--r--tests/PathOpsOpTest.cpp12
-rw-r--r--tests/PathOpsSimplifyFailTest.cpp6
-rw-r--r--tests/PathOpsSimplifyTest.cpp10
5 files changed, 30 insertions, 5 deletions
diff --git a/src/pathops/SkOpBuilder.cpp b/src/pathops/SkOpBuilder.cpp
index d0cb9c1de9..e4e7834392 100644
--- a/src/pathops/SkOpBuilder.cpp
+++ b/src/pathops/SkOpBuilder.cpp
@@ -53,7 +53,9 @@ bool FixWinding(SkPath* path) {
if (!contourHead.count()) {
return true;
}
- SkASSERT(contourHead.next());
+ if (!contourHead.next()) {
+ return false;
+ }
contourHead.joinAllSegments();
contourHead.resetReverse();
bool writePath = false;
diff --git a/src/pathops/SkPathOpsCubic.cpp b/src/pathops/SkPathOpsCubic.cpp
index 6fcb348e4f..bdae492de0 100644
--- a/src/pathops/SkPathOpsCubic.cpp
+++ b/src/pathops/SkPathOpsCubic.cpp
@@ -212,6 +212,9 @@ bool SkDCubic::hullIntersects(const SkDConic& conic, bool* isLinear) const {
}
bool SkDCubic::isLinear(int startIndex, int endIndex) const {
+ if (fPts[0].approximatelyDEqual(fPts[3])) {
+ return ((const SkDQuad *) this)->isLinear(0, 2);
+ }
SkLineParameters lineParameters;
lineParameters.cubicEndPoints(*this, startIndex, endIndex);
// FIXME: maybe it's possible to avoid this and compare non-normalized
diff --git a/tests/PathOpsOpTest.cpp b/tests/PathOpsOpTest.cpp
index 5cd0e75501..1cc9ac4226 100644
--- a/tests/PathOpsOpTest.cpp
+++ b/tests/PathOpsOpTest.cpp
@@ -5395,6 +5395,17 @@ static void circlesOp4(skiatest::Reporter* reporter, const char* filename) {
testPathOp(reporter, path, pathB, kDifference_SkPathOp, filename);
}
+static void bug5240(skiatest::Reporter* reporter, const char* filename) {
+ SkPath path;
+path.moveTo(815, 82);
+path.cubicTo(814.4794311523438f, 82.7868881225586f, 814.5330810546875f,
+82.6266555786133f, 814.5291137695312f, 82.6252212524414f);
+path.cubicTo(814.5229492187500f, 82.6230010986328f, 814.3790283203125f,
+83.0008087158203f, 813.8533935546875f, 82.7072601318359f);
+path.close();
+ testPathOp(reporter, path, path, kUnion_SkPathOp, filename);
+}
+
static void (*skipTest)(skiatest::Reporter* , const char* filename) = 0;
static void (*firstTest)(skiatest::Reporter* , const char* filename) = 0;
static void (*stopTest)(skiatest::Reporter* , const char* filename) = 0;
@@ -5402,6 +5413,7 @@ static void (*stopTest)(skiatest::Reporter* , const char* filename) = 0;
#define TEST(name) { name, #name }
static struct TestDesc tests[] = {
+ TEST(bug5240),
TEST(circlesOp4),
TEST(loop17),
TEST(cubicOp158),
diff --git a/tests/PathOpsSimplifyFailTest.cpp b/tests/PathOpsSimplifyFailTest.cpp
index 359b12592b..fa168d9520 100644
--- a/tests/PathOpsSimplifyFailTest.cpp
+++ b/tests/PathOpsSimplifyFailTest.cpp
@@ -87,10 +87,8 @@ static void dontFailOne(skiatest::Reporter* reporter, int index) {
SkPath result;
result.setFillType(SkPath::kWinding_FillType);
bool success = Simplify(path, &result);
- if (index != 17 && index != 31 && index != 38) { // cubic fails to chop in two without creating NaNs
- REPORTER_ASSERT(reporter, success);
- REPORTER_ASSERT(reporter, result.getFillType() != SkPath::kWinding_FillType);
- }
+ REPORTER_ASSERT(reporter, success);
+ REPORTER_ASSERT(reporter, result.getFillType() != SkPath::kWinding_FillType);
reporter->bumpTestCount();
}
diff --git a/tests/PathOpsSimplifyTest.cpp b/tests/PathOpsSimplifyTest.cpp
index 37e50cae36..5a2f012cfc 100644
--- a/tests/PathOpsSimplifyTest.cpp
+++ b/tests/PathOpsSimplifyTest.cpp
@@ -5542,11 +5542,21 @@ static void testQuads73(skiatest::Reporter* reporter, const char* filename) {
testSimplify(reporter, path, filename);
}
+static void bug5169(skiatest::Reporter* reporter, const char* filename) {
+ SkPath path;
+path.moveTo(SkBits2Float(0x00000000), SkBits2Float(0x4281c71c)); // 0, 64.8889f
+path.cubicTo(SkBits2Float(0x434e0000), SkBits2Float(0x4281c71c), SkBits2Float(0x00000000), SkBits2Float(0xc2a238e4), SkBits2Float(0x00000000), SkBits2Float(0x4281c71c)); // 206, 64.8889f, 0, -81.1111f, 0, 64.8889f
+path.moveTo(SkBits2Float(0x43300000), SkBits2Float(0x41971c72)); // 176, 18.8889f
+path.cubicTo(SkBits2Float(0xc29e0000), SkBits2Float(0xc25c71c7), SkBits2Float(0x42b20000), SkBits2Float(0x42fbc71c), SkBits2Float(0x43300000), SkBits2Float(0x41971c72)); // -79, -55.1111f, 89, 125.889f, 176, 18.8889f
+ testSimplify(reporter, path, filename);
+}
+
static void (*skipTest)(skiatest::Reporter* , const char* filename) = 0;
static void (*firstTest)(skiatest::Reporter* , const char* filename) = 0;
static void (*stopTest)(skiatest::Reporter* , const char* filename) = 0;
static TestDesc tests[] = {
+ TEST(bug5169),
TEST(testQuads73),
TEST(testQuads72),
TEST(testQuads71),