aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-04-30 13:37:48 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-04-30 13:37:48 +0000
commit91fc81c972c5ac4090f106d3b3fd9b26a3235ce1 (patch)
tree977d8c67df4ec1096a30bc08ddc09763342d4cc5
parenta90c6803865766d28e92091f56f718f5e41fe80f (diff)
fix cubic/line intersection; add skp tests
BUG=skia:2488 TBR=reed Author: caryclark@google.com Review URL: https://codereview.chromium.org/252243003 git-svn-id: http://skia.googlecode.com/svn/trunk@14458 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--src/pathops/SkDCubicLineIntersection.cpp11
-rw-r--r--tests/PathOpsCubicLineIntersectionTest.cpp47
-rw-r--r--tests/PathOpsExtendedTest.cpp3
-rw-r--r--tests/PathOpsOpTest.cpp20
-rwxr-xr-xtests/PathOpsSkpTest.cpp48
5 files changed, 124 insertions, 5 deletions
diff --git a/src/pathops/SkDCubicLineIntersection.cpp b/src/pathops/SkDCubicLineIntersection.cpp
index abbc4e32b2..be38ddbfcf 100644
--- a/src/pathops/SkDCubicLineIntersection.cpp
+++ b/src/pathops/SkDCubicLineIntersection.cpp
@@ -302,10 +302,17 @@ public:
}
double cT = *cubicT = SkPinT(*cubicT);
double lT = *lineT = SkPinT(*lineT);
+ SkDPoint lPt = fLine.ptAtT(lT);
+ SkDPoint cPt = fCubic.ptAtT(cT);
+ if (!lPt.moreRoughlyEqual(cPt)) {
+ return false;
+ }
+ // FIXME: if points are roughly equal but not approximately equal, need to do
+ // a binary search like quad/quad intersection to find more precise t values
if (lT == 0 || lT == 1 || (ptSet == kPointUninitialized && cT != 0 && cT != 1)) {
- *pt = fLine.ptAtT(lT);
+ *pt = lPt;
} else if (ptSet == kPointUninitialized) {
- *pt = fCubic.ptAtT(cT);
+ *pt = cPt;
}
SkPoint gridPt = pt->asSkPoint();
if (gridPt == fLine[0].asSkPoint()) {
diff --git a/tests/PathOpsCubicLineIntersectionTest.cpp b/tests/PathOpsCubicLineIntersectionTest.cpp
index 8ded198e74..1a2e188589 100644
--- a/tests/PathOpsCubicLineIntersectionTest.cpp
+++ b/tests/PathOpsCubicLineIntersectionTest.cpp
@@ -11,10 +11,45 @@
#include "SkReduceOrder.h"
#include "Test.h"
-static struct lineCubic {
+struct lineCubic {
SkDCubic cubic;
SkDLine line;
-} lineCubicTests[] = {
+};
+
+static lineCubic failLineCubicTests[] = {
+ {{{{37.5273438,-1.44140625}, {37.8736992,-1.69921875}, {38.1640625,-2.140625},
+ {38.3984375,-2.765625}}},
+ {{{40.625,-5.7890625}, {37.7109375,1.3515625}}}},
+};
+
+static const size_t failLineCubicTests_count = SK_ARRAY_COUNT(failLineCubicTests);
+
+static void testFail(skiatest::Reporter* reporter, int iIndex) {
+ const SkDCubic& cubic = failLineCubicTests[iIndex].cubic;
+ SkASSERT(ValidCubic(cubic));
+ const SkDLine& line = failLineCubicTests[iIndex].line;
+ SkASSERT(ValidLine(line));
+ SkReduceOrder reduce1;
+ SkReduceOrder reduce2;
+ int order1 = reduce1.reduce(cubic, SkReduceOrder::kNo_Quadratics);
+ int order2 = reduce2.reduce(line);
+ if (order1 < 4) {
+ SkDebugf("[%d] cubic order=%d\n", iIndex, order1);
+ REPORTER_ASSERT(reporter, 0);
+ }
+ if (order2 < 2) {
+ SkDebugf("[%d] line order=%d\n", iIndex, order2);
+ REPORTER_ASSERT(reporter, 0);
+ }
+ if (order1 == 4 && order2 == 2) {
+ SkIntersections i;
+ int roots = i.intersect(cubic, line);
+ REPORTER_ASSERT(reporter, roots == 0);
+ }
+}
+
+static lineCubic lineCubicTests[] = {
+
{{{{421, 378}, {421, 380.209137f}, {418.761414f, 382}, {416, 382}}},
{{{320, 378}, {421, 378.000031f}}}},
@@ -97,6 +132,14 @@ static void testOne(skiatest::Reporter* reporter, int iIndex) {
}
}
+DEF_TEST(PathOpsFailCubicLineIntersection, reporter) {
+ for (size_t index = 0; index < failLineCubicTests_count; ++index) {
+ int iIndex = static_cast<int>(index);
+ testFail(reporter, iIndex);
+ reporter->bumpTestCount();
+ }
+}
+
DEF_TEST(PathOpsCubicLineIntersection, reporter) {
for (size_t index = 0; index < lineCubicTests_count; ++index) {
int iIndex = static_cast<int>(index);
diff --git a/tests/PathOpsExtendedTest.cpp b/tests/PathOpsExtendedTest.cpp
index 08954327e9..280307a775 100644
--- a/tests/PathOpsExtendedTest.cpp
+++ b/tests/PathOpsExtendedTest.cpp
@@ -410,12 +410,13 @@ static void showPathOpPath(const char* testName, const SkPath& one, const SkPath
SkDebugf("static void %s(skiatest::Reporter* reporter, const char* filename) {\n", testName);
*gTestOp.append() = shapeOp;
++gTestNo;
+ SkDebugf("\n*** this test fails ***\n");
SkDebugf(" SkPath path, pathB;\n");
showPath(a, "path", false);
showPath(b, "pathB", false);
SkDebugf(" testPathOp(reporter, path, pathB, %s, filename);\n", opStrs[shapeOp]);
SkDebugf("}\n");
- drawAsciiPaths(scaledOne, scaledTwo, false);
+ drawAsciiPaths(scaledOne, scaledTwo, true);
}
void ShowTestArray() {
diff --git a/tests/PathOpsOpTest.cpp b/tests/PathOpsOpTest.cpp
index 7a1cbab5e3..86baea423c 100644
--- a/tests/PathOpsOpTest.cpp
+++ b/tests/PathOpsOpTest.cpp
@@ -3310,10 +3310,30 @@ static void quadOp10i(skiatest::Reporter* reporter, const char* filename) {
testPathOp(reporter, path, pathB, kIntersect_PathOp, filename);
}
+static void kari1(skiatest::Reporter* reporter, const char* filename) {
+ SkPath path1;
+ path1.moveTo(39.9375, -5.8359375);
+ path1.lineTo(40.625, -5.7890625);
+ path1.lineTo(37.7109375, 1.3515625);
+ path1.lineTo(37.203125, 0.9609375);
+ path1.close();
+
+ SkPath path2;
+ path2.moveTo(37.52734375f, -1.44140625f);
+ path2.cubicTo(37.8736991882324f, -1.69921875f, 38.1640625f, -2.140625f, 38.3984375f, -2.765625f);
+ path2.lineTo(38.640625f, -2.609375f);
+ path2.cubicTo(38.53125f, -1.89583337306976f, 38.0664443969727f, -0.154893040657043f, 38.0664443969727f, -0.154893040657043f);
+ path2.cubicTo(38.0664443969727f, -0.154893040657043f, 37.1809883117676f, -1.18359375f, 37.52734375, -1.44140625f);
+ path2.close();
+
+ testPathOp(reporter, path1, path2, kDifference_PathOp, filename);
+}
+
static void (*firstTest)(skiatest::Reporter* , const char* filename) = 0;
static void (*stopTest)(skiatest::Reporter* , const char* filename) = 0;
static struct TestDesc tests[] = {
+ TEST(kari1),
TEST(quadOp10i),
#if 0 // FIXME: serpentine curve is ordered the wrong way
TEST(cubicOp114),
diff --git a/tests/PathOpsSkpTest.cpp b/tests/PathOpsSkpTest.cpp
index 290b19ac39..5b10a1f736 100755
--- a/tests/PathOpsSkpTest.cpp
+++ b/tests/PathOpsSkpTest.cpp
@@ -2962,9 +2962,57 @@ static void skpwww_defense_studies_blogspot_com_64(skiatest::Reporter* reporter,
testPathOp(reporter, path, pathB, kIntersect_PathOp, filename);
}
+// checkSmall / addTPair / addT assert
+#if TRY_NEW_TESTS
+static void skpwww_uniquefx_net_442(skiatest::Reporter* reporter, const char* filename) {
+ SkPath path;
+ path.setFillType(SkPath::kEvenOdd_FillType);
+ path.moveTo(960, 306);
+ path.lineTo(960, 305);
+ path.lineTo(1000, 305);
+ path.lineTo(1000, 306.708527f);
+ path.lineTo(960, 306);
+ path.close();
+ SkPath pathB;
+ pathB.setFillType(SkPath::kWinding_FillType);
+ pathB.moveTo(960, 305);
+ pathB.lineTo(958.997253f, 306.002747f);
+ pathB.lineTo(1017, 307);
+ pathB.lineTo(1019, 305);
+ testPathOp(reporter, path, pathB, kIntersect_PathOp, filename);
+}
+#endif
+
+// rightAngleWinding
+#if TRY_NEW_TESTS
+static void skpwww_kitcheninspirations_wordpress_com_32(skiatest::Reporter* reporter, const char* filename) {
+ SkPath path;
+ path.setFillType(SkPath::kEvenOdd_FillType);
+ path.moveTo(47.1666679f, 19651.334f);
+ path.lineTo(65.8333359f, 19651.332f);
+ path.lineTo(65.8333359f, 19651.5f);
+ path.lineTo(47.1666679f, 19651.5f);
+ path.lineTo(47.1666679f, 19651.334f);
+ path.close();
+ SkPath pathB;
+ pathB.setFillType(SkPath::kWinding_FillType);
+ pathB.moveTo(47.1666679f, 19651.5f);
+ pathB.lineTo(47.1666679f, 19651.332f);
+ pathB.lineTo(65.8333359f, 19651.334f);
+ pathB.lineTo(65.8333359f, 19651.5f);
+ testPathOp(reporter, path, pathB, kIntersect_PathOp, filename);
+}
+#endif
+
static void (*firstTest)(skiatest::Reporter* , const char* filename) = 0;
static struct TestDesc tests[] = {
+#if TRY_NEW_TESTS
+ TEST(skpwww_kitcheninspirations_wordpress_com_32), // rightanglewinding
+#endif
+#if TRY_NEW_TESTS
+ TEST(skpwww_uniquefx_net_442), // checkSmall / addTPair / addT assert
+#endif
TEST(skpwww_defense_studies_blogspot_com_64),
TEST(skpwww_kenlevine_blogspot_com_28),
TEST(skpwww_fashionscandal_com_94),