diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/PathOpsAngleTest.cpp | 70 | ||||
-rw-r--r-- | tests/PathOpsCubicIntersectionTest.cpp | 5 | ||||
-rw-r--r-- | tests/PathOpsCubicQuadIntersectionTest.cpp | 71 | ||||
-rw-r--r-- | tests/PathOpsExtendedTest.cpp | 11 | ||||
-rw-r--r-- | tests/PathOpsLineIntersectionTest.cpp | 56 | ||||
-rw-r--r-- | tests/PathOpsOpTest.cpp | 245 | ||||
-rw-r--r-- | tests/PathOpsQuadLineIntersectionTest.cpp | 4 | ||||
-rw-r--r-- | tests/PathOpsSimplifyTest.cpp | 85 | ||||
-rw-r--r-- | tests/PathOpsSkpClipTest.cpp | 61 | ||||
-rw-r--r-- | tests/PathOpsThreadedCommon.cpp | 1 | ||||
-rw-r--r-- | tests/PathOpsThreadedCommon.h | 2 |
11 files changed, 525 insertions, 86 deletions
diff --git a/tests/PathOpsAngleTest.cpp b/tests/PathOpsAngleTest.cpp index 6714ca4609..e0331ec60f 100644 --- a/tests/PathOpsAngleTest.cpp +++ b/tests/PathOpsAngleTest.cpp @@ -8,11 +8,16 @@ #include "Test.h" static const SkPoint cubics[][4] = { - {{0, 1}, {2, 6}, {4, 2}, {5, 3}} + {{0, 1}, {2, 6}, {4, 2}, {5, 3}}, + {{10, 234}, {10, 229.581726f}, {13.5817204f, 226}, {18, 226}}, +}; + +static const SkPoint quads[][3] = { + {{12.3423996f, 228.342407f}, {10, 230.686295f}, {10, 234}}, }; static const SkPoint lines[][2] = { - {{6, 2}, {2, 4}} + {{6, 2}, {2, 4}}, }; struct SortSet { @@ -36,38 +41,61 @@ static const SortSet set2[] = { {lines[0], 2, 0.574074074, 0.9140625}, }; +static const SortSet set3[] = { + {cubics[1], 4, 0, 1}, + {quads[0], 3, 1, 0}, +}; + struct SortSetTests { const SortSet* set; size_t count; }; static const SortSetTests tests[] = { + { set3, SK_ARRAY_COUNT(set3) }, { set2, SK_ARRAY_COUNT(set2) }, - { set1, SK_ARRAY_COUNT(set1) } + { set1, SK_ARRAY_COUNT(set1) }, }; static void setup(const SortSet* set, const size_t idx, SkPoint const ** data, SkOpSegment* seg, int* ts) { SkPoint start, end; - if (set[idx].ptCount == 2) { - *data = set[idx].ptData; - seg->addLine(*data, false, false); - SkDLine dLine; - dLine.set(set[idx].ptData); - start = dLine.xyAtT(set[idx].tStart).asSkPoint(); - end = dLine.xyAtT(set[idx].tEnd).asSkPoint(); - } else if (set[idx].ptCount == 4) { - *data = set[idx].ptData; - seg->addCubic(*data, false, false); - SkDCubic dCubic; - dCubic.set(set[idx].ptData); - start = dCubic.xyAtT(set[idx].tStart).asSkPoint(); - end = dCubic.xyAtT(set[idx].tEnd).asSkPoint(); + *data = set[idx].ptData; + switch(set[idx].ptCount) { + case 2: { + seg->addLine(*data, false, false); + SkDLine dLine; + dLine.set(set[idx].ptData); + start = dLine.xyAtT(set[idx].tStart).asSkPoint(); + end = dLine.xyAtT(set[idx].tEnd).asSkPoint(); + } break; + case 3: { + seg->addQuad(*data, false, false); + SkDQuad dQuad; + dQuad.set(set[idx].ptData); + start = dQuad.xyAtT(set[idx].tStart).asSkPoint(); + end = dQuad.xyAtT(set[idx].tEnd).asSkPoint(); + } break; + case 4: { + seg->addCubic(*data, false, false); + SkDCubic dCubic; + dCubic.set(set[idx].ptData); + start = dCubic.xyAtT(set[idx].tStart).asSkPoint(); + end = dCubic.xyAtT(set[idx].tEnd).asSkPoint(); + } break; + } + double tStart = set[idx].tStart; + double tEnd = set[idx].tEnd; + seg->addT(NULL, start, tStart); + seg->addT(NULL, end, tEnd); + double tLeft = tStart < tEnd ? 0 : 1; + if (tStart != tLeft && tEnd != tLeft) { + seg->addT(NULL, set[idx].ptData[0], tLeft); + } + double tRight = tStart < tEnd ? 1 : 0; + if (tStart != tRight && tEnd != tRight) { + seg->addT(NULL, set[idx].ptData[set[idx].ptCount - 1], tRight); } - seg->addT(NULL, start, set[idx].tStart); - seg->addT(NULL, end, set[idx].tEnd); - seg->addT(NULL, set[idx].ptData[0], 0); - seg->addT(NULL, set[idx].ptData[set[idx].ptCount - 1], 1); int tIndex = 0; do { if (seg->t(tIndex) == set[idx].tStart) { diff --git a/tests/PathOpsCubicIntersectionTest.cpp b/tests/PathOpsCubicIntersectionTest.cpp index 6af76c2adb..58d7d98024 100644 --- a/tests/PathOpsCubicIntersectionTest.cpp +++ b/tests/PathOpsCubicIntersectionTest.cpp @@ -163,6 +163,9 @@ static const SkDCubic testSet[] = { const size_t testSetCount = SK_ARRAY_COUNT(testSet); static const SkDCubic newTestSet[] = { +{{{0, 1}, {2, 3}, {5, 1}, {4, 3}}}, +{{{1, 5}, {3, 4}, {1, 0}, {3, 2}}}, + {{{3, 5}, {1, 6}, {5, 0}, {3, 1}}}, {{{0, 5}, {1, 3}, {5, 3}, {6, 1}}}, @@ -286,8 +289,8 @@ static void newOneOff(skiatest::Reporter* reporter, int outer, int inner) { } static void oneOffTest(skiatest::Reporter* reporter) { - oneOff(reporter, 14, 16); newOneOff(reporter, 0, 1); + oneOff(reporter, 14, 16); } static void oneOffTests(skiatest::Reporter* reporter) { diff --git a/tests/PathOpsCubicQuadIntersectionTest.cpp b/tests/PathOpsCubicQuadIntersectionTest.cpp new file mode 100644 index 0000000000..8b47a8e60f --- /dev/null +++ b/tests/PathOpsCubicQuadIntersectionTest.cpp @@ -0,0 +1,71 @@ +/* + * Copyright 2013 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#include "SkIntersections.h" +#include "SkPathOpsCubic.h" +#include "SkPathOpsQuad.h" +#include "SkReduceOrder.h" +#include "Test.h" + +static struct lineCubic { + SkDCubic cubic; + SkDQuad quad; + int answerCount; + SkDPoint answers[2]; +} quadCubicTests[] = { + {{{{10,234}, {10,229.58172607421875}, {13.581720352172852,226}, {18,226}}},
+ {{{18,226}, {14.686291694641113,226}, {12.342399597167969,228.3424072265625}}}, 1,
+ {{18,226}, {0,0}}},
+ {{{{10,234}, {10,229.58172607421875}, {13.581720352172852,226}, {18,226}}},
+ {{{12.342399597167969,228.3424072265625}, {10,230.68629455566406}, {10,234}}}, 1,
+ {{10,234}, {0,0}}},
+}; + +static const size_t quadCubicTests_count = SK_ARRAY_COUNT(quadCubicTests); + +static void PathOpsCubicQuadIntersectionTest(skiatest::Reporter* reporter) { + for (size_t index = 0; index < quadCubicTests_count; ++index) { + int iIndex = static_cast<int>(index); + const SkDCubic& cubic = quadCubicTests[index].cubic; + const SkDQuad& quad = quadCubicTests[index].quad; + SkReduceOrder reduce1; + SkReduceOrder reduce2; + int order1 = reduce1.reduce(cubic, SkReduceOrder::kNo_Quadratics, + SkReduceOrder::kFill_Style); + int order2 = reduce2.reduce(quad, SkReduceOrder::kFill_Style); + if (order1 != 4) { + SkDebugf("[%d] cubic order=%d\n", iIndex, order1); + REPORTER_ASSERT(reporter, 0); + } + if (order2 != 3) { + SkDebugf("[%d] quad order=%d\n", iIndex, order2); + REPORTER_ASSERT(reporter, 0); + } + SkIntersections i; + int roots = i.intersect(cubic, quad); + SkASSERT(roots == quadCubicTests[index].answerCount); + for (int pt = 0; pt < roots; ++pt) { + double tt1 = i[0][pt]; + SkDPoint xy1 = cubic.xyAtT(tt1); + double tt2 = i[1][pt]; + SkDPoint xy2 = quad.xyAtT(tt2); + if (!xy1.approximatelyEqual(xy2)) { + SkDebugf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n", + __FUNCTION__, iIndex, pt, tt1, xy1.fX, xy1.fY, tt2, xy2.fX, xy2.fY); + } + REPORTER_ASSERT(reporter, xy1.approximatelyEqual(xy2)); + bool found = false; + for (int idx2 = 0; idx2 < quadCubicTests[index].answerCount; ++idx2) { + found |= quadCubicTests[index].answers[idx2].approximatelyEqual(xy1); + } + REPORTER_ASSERT(reporter, found); + } + reporter->bumpTestCount(); + } +} + +#include "TestClassDef.h" +DEFINE_TESTCLASS_SHORT(PathOpsCubicQuadIntersectionTest) diff --git a/tests/PathOpsExtendedTest.cpp b/tests/PathOpsExtendedTest.cpp index 8d7ca289b9..71631c110a 100644 --- a/tests/PathOpsExtendedTest.cpp +++ b/tests/PathOpsExtendedTest.cpp @@ -12,6 +12,7 @@ #include "SkMatrix.h" #include "SkPaint.h" #include "SkStream.h" +#include "SkThreadPool.h" #ifdef SK_BUILD_FOR_MAC #include <sys/sysctl.h> @@ -78,7 +79,7 @@ void showPath(const SkPath& path, const char* str) { showPath(path); } -const char* fillTypeStr[] = { +static const char* fillTypeStr[] = { "kWinding_FillType", "kEvenOdd_FillType", "kInverseWinding_FillType", @@ -478,7 +479,7 @@ bool testSimplify(SkPath& path, bool useXor, SkPath& out, PathOpsThreadState& st } bool testSimplify(skiatest::Reporter* reporter, const SkPath& path) { -#if FORCE_RELEASE == 0 +#if DEBUG_SHOW_TEST_NAME showPathData(path); #endif SkPath out; @@ -498,7 +499,7 @@ bool testSimplify(skiatest::Reporter* reporter, const SkPath& path) { bool testPathOp(skiatest::Reporter* reporter, const SkPath& a, const SkPath& b, const SkPathOp shapeOp) { -#if FORCE_RELEASE == 0 +#if DEBUG_SHOW_TEST_NAME showPathData(a); showOp(shapeOp); showPathData(b); @@ -595,7 +596,7 @@ void RunTestSet(skiatest::Reporter* reporter, TestDesc tests[], size_t count, while (index > 0 && tests[index].fun != firstTest) { --index; } -#if FORCE_RELEASE == 0 +#if DEBUG_SHOW_TEST_NAME SkDebugf("<div id=\"%s\">\n", tests[index].str); SkDebugf(" %s [%s]\n", __FUNCTION__, tests[index].str); #endif @@ -605,7 +606,7 @@ void RunTestSet(skiatest::Reporter* reporter, TestDesc tests[], size_t count, size_t last = reverse ? 0 : count - 1; do { if (tests[index].fun != firstTest) { - #if FORCE_RELEASE == 0 + #if DEBUG_SHOW_TEST_NAME SkDebugf("<div id=\"%s\">\n", tests[index].str); SkDebugf(" %s [%s]\n", __FUNCTION__, tests[index].str); #endif diff --git a/tests/PathOpsLineIntersectionTest.cpp b/tests/PathOpsLineIntersectionTest.cpp index 675ce9d9e8..b1bb66716b 100644 --- a/tests/PathOpsLineIntersectionTest.cpp +++ b/tests/PathOpsLineIntersectionTest.cpp @@ -10,6 +10,8 @@ // FIXME: add tests for intersecting, non-intersecting, degenerate, coincident static const SkDLine tests[][2] = { + {{{{192, 4}, {243, 4}}}, {{{246, 4}, {189, 4}}}}, + {{{{246, 4}, {189, 4}}}, {{{192, 4}, {243, 4}}}}, {{{{5, 0}, {0, 5}}}, {{{5, 4}, {1, 4}}}}, {{{{0, 0}, {1, 0}}}, {{{1, 0}, {0, 0}}}}, {{{{0, 0}, {0, 0}}}, {{{0, 0}, {1, 0}}}}, @@ -32,6 +34,20 @@ static const SkDLine noIntersect[][2] = { static const size_t noIntersect_count = SK_ARRAY_COUNT(noIntersect); +static void check_results(skiatest::Reporter* reporter, const SkDLine& line1, const SkDLine& line2, + const SkIntersections& ts) { + for (int i = 0; i < ts.used(); ++i) { + SkDPoint result1 = line1.xyAtT(ts[0][i]); + SkDPoint result2 = line2.xyAtT(ts[1][i]); + if (!result1.approximatelyEqual(result2)) { + REPORTER_ASSERT(reporter, ts.used() != 1); + result2 = line2.xyAtT(ts[1][i ^ 1]); + REPORTER_ASSERT(reporter, result1.approximatelyEqual(result2)); + REPORTER_ASSERT(reporter, result1.approximatelyEqual(ts.pt(i).asSkPoint())); + } + } +} + static void PathOpsLineIntersectionTest(skiatest::Reporter* reporter) { size_t index; for (index = 0; index < tests_count; ++index) { @@ -40,14 +56,34 @@ static void PathOpsLineIntersectionTest(skiatest::Reporter* reporter) { SkIntersections ts; int pts = ts.intersect(line1, line2); REPORTER_ASSERT(reporter, pts); - for (int i = 0; i < pts; ++i) { - SkDPoint result1 = line1.xyAtT(ts[0][i]); - SkDPoint result2 = line2.xyAtT(ts[1][i]); - if (!result1.approximatelyEqual(result2)) { - REPORTER_ASSERT(reporter, pts != 1); - result2 = line2.xyAtT(ts[1][i ^ 1]); - REPORTER_ASSERT(reporter, result1.approximatelyEqual(result2)); - } + REPORTER_ASSERT(reporter, pts == ts.used()); + check_results(reporter, line1, line2, ts); + if (line1[0] == line1[1] || line2[0] == line2[1]) { + continue; + } + if (line1[0].fY == line1[1].fY) { + double left = SkTMin(line1[0].fX, line1[1].fX); + double right = SkTMax(line1[0].fX, line1[1].fX); + ts.horizontal(line2, left, right, line1[0].fY, line1[0].fX != left); + check_results(reporter, line2, line1, ts); + } + if (line2[0].fY == line2[1].fY) { + double left = SkTMin(line2[0].fX, line2[1].fX); + double right = SkTMax(line2[0].fX, line2[1].fX); + ts.horizontal(line1, left, right, line2[0].fY, line2[0].fX != left); + check_results(reporter, line1, line2, ts); + } + if (line1[0].fX == line1[1].fX) { + double top = SkTMin(line1[0].fY, line1[1].fY); + double bottom = SkTMax(line1[0].fY, line1[1].fY); + ts.vertical(line2, top, bottom, line1[0].fX, line1[0].fY != top); + check_results(reporter, line2, line1, ts); + } + if (line2[0].fX == line2[1].fX) { + double top = SkTMin(line2[0].fY, line2[1].fY); + double bottom = SkTMax(line2[0].fY, line2[1].fY); + ts.vertical(line1, top, bottom, line2[0].fX, line2[0].fY != top); + check_results(reporter, line1, line2, ts); } } for (index = 0; index < noIntersect_count; ++index) { @@ -55,7 +91,9 @@ static void PathOpsLineIntersectionTest(skiatest::Reporter* reporter) { const SkDLine& line2 = noIntersect[index][1]; SkIntersections ts; int pts = ts.intersect(line1, line2); - REPORTER_ASSERT(reporter, !pts); } + REPORTER_ASSERT(reporter, !pts); + REPORTER_ASSERT(reporter, pts == ts.used()); + } } #include "TestClassDef.h" diff --git a/tests/PathOpsOpTest.cpp b/tests/PathOpsOpTest.cpp index 995bf16f53..08dff90c29 100644 --- a/tests/PathOpsOpTest.cpp +++ b/tests/PathOpsOpTest.cpp @@ -1153,43 +1153,206 @@ SkPathOp ops[] = { }; static void rRect1(skiatest::Reporter* reporter) { - SkScalar xA = SkFloatToScalar(0.65f); - SkScalar xB = SkFloatToScalar(10.65f); - SkScalar xC = SkFloatToScalar(20.65f); - SkScalar xD = SkFloatToScalar(30.65f); - SkScalar xE = SkFloatToScalar(40.65f); - SkScalar xF = SkFloatToScalar(50.65f); - - SkScalar yA = SkFloatToScalar(0.65f); - SkScalar yB = SkFloatToScalar(10.65f); - SkScalar yC = SkFloatToScalar(20.65f); - SkScalar yD = SkFloatToScalar(30.65f); - SkScalar yE = SkFloatToScalar(40.65f); - SkScalar yF = SkFloatToScalar(50.65f); - SkPath paths[5]; - SkRect rects[5]; - rects[0].set(xB, yB, xE, yE); - paths[0].addRoundRect(rects[0], SkIntToScalar(5), SkIntToScalar(5)); // red - rects[1].set(xA, yA, xD, yD); - paths[1].addRoundRect(rects[1], SkIntToScalar(5), SkIntToScalar(5)); // green - rects[2].set(xC, yA, xF, yD); - paths[2].addRoundRect(rects[2], SkIntToScalar(5), SkIntToScalar(5)); // blue - rects[3].set(xA, yC, xD, yF); - paths[3].addRoundRect(rects[3], SkIntToScalar(5), SkIntToScalar(5)); // yellow - rects[4].set(xC, yC, xF, yF); - paths[4].addRoundRect(rects[4], SkIntToScalar(5), SkIntToScalar(5)); // cyan - SkPath path; - path.setFillType(SkPath::kInverseEvenOdd_FillType); - for (int index = 0; index < 5; ++index) { - testPathOp(reporter, path, paths[index], ops[index]); - Op(path, paths[index], ops[index], &path); - } + SkScalar xA = SkFloatToScalar(0.65f); + SkScalar xB = SkFloatToScalar(10.65f); + SkScalar xC = SkFloatToScalar(20.65f); + SkScalar xD = SkFloatToScalar(30.65f); + SkScalar xE = SkFloatToScalar(40.65f); + SkScalar xF = SkFloatToScalar(50.65f); + + SkScalar yA = SkFloatToScalar(0.65f); + SkScalar yB = SkFloatToScalar(10.65f); + SkScalar yC = SkFloatToScalar(20.65f); + SkScalar yD = SkFloatToScalar(30.65f); + SkScalar yE = SkFloatToScalar(40.65f); + SkScalar yF = SkFloatToScalar(50.65f); + SkPath paths[5]; + SkRect rects[5]; + rects[0].set(xB, yB, xE, yE); + paths[0].addRoundRect(rects[0], SkIntToScalar(5), SkIntToScalar(5)); // red + rects[1].set(xA, yA, xD, yD); + paths[1].addRoundRect(rects[1], SkIntToScalar(5), SkIntToScalar(5)); // green + rects[2].set(xC, yA, xF, yD); + paths[2].addRoundRect(rects[2], SkIntToScalar(5), SkIntToScalar(5)); // blue + rects[3].set(xA, yC, xD, yF); + paths[3].addRoundRect(rects[3], SkIntToScalar(5), SkIntToScalar(5)); // yellow + rects[4].set(xC, yC, xF, yF); + paths[4].addRoundRect(rects[4], SkIntToScalar(5), SkIntToScalar(5)); // cyan + SkPath path; + path.setFillType(SkPath::kInverseEvenOdd_FillType); + for (int index = 0; index < 5; ++index) { + testPathOp(reporter, path, paths[index], ops[index]); + Op(path, paths[index], ops[index], &path); + } +} + +static void skp1(skiatest::Reporter* reporter) { + SkPath path; + path.setFillType(SkPath::kEvenOdd_FillType); + path.moveTo(189,7); + path.cubicTo(189,5.34314585f, 190.34314f,4, 192,4); + path.lineTo(243,4); + path.cubicTo(244.65686f,4, 246,5.34314585f, 246,7); + path.lineTo(246,21); + path.cubicTo(246,22.6568546f, 244.65686f,24, 243,24); + path.lineTo(192,24); + path.cubicTo(190.34314f,24, 189,22.6568546f, 189,21); + path.lineTo(189,7); + path.close(); + path.moveTo(191,8); + path.cubicTo(191,6.89543009f, 191.895432f,6, 193,6); + path.lineTo(242,6); + path.cubicTo(243.104568f,6, 244,6.89543009f, 244,8); + path.lineTo(244,20); + path.cubicTo(244,21.1045704f, 243.104568f,22, 242,22); + path.lineTo(193,22); + path.cubicTo(191.895432f,22, 191,21.1045704f, 191,20); + path.lineTo(191,8); + path.close(); + SkPath pathB; + pathB.setFillType(SkPath::kWinding_FillType); + pathB.moveTo(189,4); + pathB.lineTo(199,14); + pathB.lineTo(236,14); + pathB.lineTo(246,4); + pathB.lineTo(189,4); + pathB.close(); + testPathOp(reporter, path, pathB, kIntersect_PathOp); +} + +static void skp2(skiatest::Reporter* reporter) { + SkPath path; + path.setFillType(SkPath::kEvenOdd_FillType); + path.moveTo(253.000000f, 11757.0000f); + path.lineTo(253.000000f, 222.000000f); + path.lineTo(823.000000f, 222.000000f); + path.lineTo(823.000000f, 11757.0000f); + path.lineTo(253.000000f, 11757.0000f); + path.close(); + SkPath pathB; + pathB.setFillType(SkPath::kWinding_FillType); + pathB.moveTo(258.000000f, 1028.00000f); + pathB.lineTo(258.000000f, 1027.00000f); + pathB.lineTo(823.000000f, 1027.00000f); + pathB.lineTo(823.000000f, 1028.00000f); + pathB.lineTo(258.000000f, 1028.00000f); + pathB.close(); + testPathOp(reporter, path, pathB, kIntersect_PathOp); +} + +static void skp3(skiatest::Reporter* reporter) { + SkPath path; + path.setFillType(SkPath::kEvenOdd_FillType); + path.moveTo(717.000000f, 507.000000f); + path.lineTo(717.000000f, 425.000000f); + path.lineTo(973.000000f, 425.000000f); + path.lineTo(973.000000f, 507.000000f); + path.quadTo(973.000000f, 508.242645f, 972.121582f, 509.121613f); + path.quadTo(971.242615f, 510.000000f, 970.000000f, 510.000000f); + path.lineTo(720.000000f, 510.000000f); + path.quadTo(718.757385f, 510.000000f, 717.878418f, 509.121613f); + path.quadTo(717.000000f, 508.242645f, 717.000000f, 507.000000f); + path.close(); + path.moveTo(719.000000f, 426.000000f); + path.lineTo(971.000000f, 426.000000f); + path.lineTo(971.000000f, 506.000000f); + path.cubicTo(971.000000f, 507.104584f, 970.104553f, 508.000000f, 969.000000f, 508.000000f); + path.lineTo(721.000000f, 508.000000f); + path.cubicTo(719.895447f, 508.000000f, 719.000000f, 507.104584f, 719.000000f, 506.000000f); + path.lineTo(719.000000f, 426.000000f); + path.close(); + SkPath pathB; + pathB.setFillType(SkPath::kWinding_FillType); + pathB.moveTo(717.000000f, 510.000000f); + pathB.lineTo(760.000000f, 467.000000f); + pathB.lineTo(930.000000f, 467.000000f); + pathB.lineTo(973.000000f, 510.000000f); + pathB.lineTo(717.000000f, 510.000000f); + pathB.close(); + testPathOp(reporter, path, pathB, kIntersect_PathOp); +} + +static void skp4(skiatest::Reporter* reporter) { + SkPath path; + path.setFillType(SkPath::kEvenOdd_FillType); + path.moveTo(230.756805f, 591.756775f); + path.quadTo(232.514725f, 590.000000f, 235.000000f, 590.000000f); + path.lineTo(300.000000f, 590.000000f); + path.quadTo(302.485291f, 590.000000f, 304.243195f, 591.756775f); + path.quadTo(306.000000f, 593.514709f, 306.000000f, 596.000000f); + path.lineTo(306.000000f, 617.000000f); + path.lineTo(229.000000f, 617.000000f); + path.lineTo(229.000000f, 596.000000f); + path.quadTo(229.000000f, 593.514709f, 230.756805f, 591.756775f); + path.close(); + path.moveTo(231.000000f, 597.000000f); + path.cubicTo(231.000000f, 594.238586f, 233.238571f, 592.000000f, 236.000000f, 592.000000f); + path.lineTo(299.000000f, 592.000000f); + path.cubicTo(301.761414f, 592.000000f, 304.000000f, 594.238586f, 304.000000f, 597.000000f); + path.lineTo(304.000000f, 616.000000f); + path.lineTo(231.000000f, 616.000000f); + path.lineTo(231.000000f, 597.000000f); + path.close(); + SkPath pathB; + pathB.setFillType(SkPath::kWinding_FillType); + pathB.moveTo(306.000000f, 590.000000f); + pathB.lineTo(292.000000f, 604.000000f); + pathB.lineTo(305.000000f, 617.000000f); + pathB.lineTo(306.000000f, 617.000000f); + pathB.lineTo(306.000000f, 590.000000f); + pathB.close(); + testPathOp(reporter, path, pathB, kIntersect_PathOp); +} + +static void skp5(skiatest::Reporter* reporter) { + SkPath path; + path.setFillType(SkPath::kEvenOdd_FillType); + path.moveTo(18.0000000f, 226.000000f); + path.quadTo(14.6862917f, 226.000000f, 12.3423996f, 228.342407f); + path.quadTo(10.0000000f, 230.686295f, 10.0000000f, 234.000000f); + path.lineTo(10.0000000f, 253.000000f); + path.lineTo(1247.00000f, 253.000000f); + path.lineTo(1247.00000f, 234.000000f); + path.quadTo(1247.00000f, 230.686295f, 1244.65759f, 228.342407f); + path.quadTo(1242.31372f, 226.000000f, 1239.00000f, 226.000000f); + path.lineTo(18.0000000f, 226.000000f); + path.close(); + SkPath pathB; + pathB.setFillType(SkPath::kInverseWinding_FillType); + pathB.moveTo(18.0000000f, 226.000000f); + pathB.lineTo(1239.00000f, 226.000000f); + pathB.cubicTo(1243.41833f, 226.000000f, 1247.00000f, 229.581726f, 1247.00000f, 234.000000f); + pathB.lineTo(1247.00000f, 252.000000f); + pathB.lineTo(10.0000000f, 252.000000f); + pathB.lineTo(10.0000000f, 234.000000f); + pathB.cubicTo(10.0000000f, 229.581726f, 13.5817204f, 226.000000f, 18.0000000f, 226.000000f); + pathB.close(); + testPathOp(reporter, path, pathB, kIntersect_PathOp); +} + +static void cubicOp70d(skiatest::Reporter* reporter) { + SkPath path, pathB; + path.setFillType(SkPath::kWinding_FillType); + path.moveTo(0,1); + path.cubicTo(0,5, 4,0, 5,0); + path.close(); + pathB.setFillType(SkPath::kWinding_FillType); + pathB.moveTo(0,4); + pathB.cubicTo(0,5, 1,0, 5,0); + pathB.close(); + testPathOp(reporter, path, pathB, kDifference_PathOp); } static void (*firstTest)(skiatest::Reporter* ) = 0; static struct TestDesc tests[] = { + TEST(skp5), + TEST(skp4), + TEST(skp3), + TEST(skp2), + TEST(skp1), TEST(rRect1), + TEST(cubicOp70d), TEST(cubicOp69d), TEST(cubicOp68u), TEST(cubicOp67u), @@ -1288,21 +1451,11 @@ static struct TestDesc tests[] = { static const size_t testCount = SK_ARRAY_COUNT(tests); static struct TestDesc subTests[] = { - TEST(cubicOp43d), - TEST(quadOp9d), - TEST(cubicOp9d), - TEST(cubicOp1i), - TEST(cubicOp10d), - TEST(cubicOp11d), - TEST(cubicOp15d), - TEST(cubicOp18d), - TEST(cubicOp22d), - TEST(cubicOp23d), - TEST(cubicOp24d), - TEST(cubicOp28u), - TEST(cubicOp33i), - TEST(cubicOp36u), - TEST(cubicOp40d), + TEST(cubicOp6d), + TEST(cubicOp8d), + TEST(cubicOp70d), + TEST(cubicOp16d), + TEST(skp5), }; static const size_t subTestCount = SK_ARRAY_COUNT(subTests); diff --git a/tests/PathOpsQuadLineIntersectionTest.cpp b/tests/PathOpsQuadLineIntersectionTest.cpp index 37c8ef3268..16153404c4 100644 --- a/tests/PathOpsQuadLineIntersectionTest.cpp +++ b/tests/PathOpsQuadLineIntersectionTest.cpp @@ -58,6 +58,8 @@ static struct oneLineQuad { SkDQuad quad; SkDLine line; } oneOffs[] = { + {{{{973, 507}, {973, 508.24264526367187}, {972.12158203125, 509.12161254882812}}}, + {{{930, 467}, {973, 510}}}}, {{{{369.848602, 145.680267}, {382.360413, 121.298294}, {406.207703, 121.298294}}}, {{{406.207703, 121.298294}, {348.781738, 123.864815}}}} }; @@ -65,11 +67,11 @@ static struct oneLineQuad { static size_t oneOffs_count = SK_ARRAY_COUNT(oneOffs); static void testOneOffs(skiatest::Reporter* reporter) { - SkIntersections intersections; bool flipped = false; for (size_t index = 0; index < oneOffs_count; ++index) { const SkDQuad& quad = oneOffs[index].quad; const SkDLine& line = oneOffs[index].line; + SkIntersections intersections; int result = doIntersect(intersections, quad, line, flipped); for (int inner = 0; inner < result; ++inner) { double quadT = intersections[0][inner]; diff --git a/tests/PathOpsSimplifyTest.cpp b/tests/PathOpsSimplifyTest.cpp index c0d13c80e5..ce2c89bf7a 100644 --- a/tests/PathOpsSimplifyTest.cpp +++ b/tests/PathOpsSimplifyTest.cpp @@ -3695,9 +3695,92 @@ static void testAddTCoincident2(skiatest::Reporter* reporter) { testSimplify(reporter, path); } +static void testQuad2(skiatest::Reporter* reporter) { + SkPath path; + path.moveTo(1, 0); + path.quadTo(0, 1, 3, 2); + path.lineTo(2, 3); + path.close(); + path.moveTo(0, 0); + path.lineTo(1, 0); + path.quadTo(0, 1, 1, 1); + path.close(); +} + +static void testQuad3(skiatest::Reporter* reporter) { + SkPath path; + path.moveTo(1, 0); + path.quadTo(0, 1, 3, 2); + path.lineTo(3, 3); + path.close(); + path.moveTo(0, 0); + path.lineTo(1, 0); + path.quadTo(0, 1, 1, 1); + path.close(); + testSimplify(reporter, path); +} + +static void testQuad4(skiatest::Reporter* reporter) { + SkPath path; + path.moveTo(2, 0); + path.quadTo(0, 1, 1, 1); + path.lineTo(3, 3); + path.close(); + path.moveTo(0, 0); + path.lineTo(2, 0); + path.quadTo(0, 1, 2, 2); + path.close(); + testSimplify(reporter, path); +} + +static void testQuad5(skiatest::Reporter* reporter) { + SkPath path; + path.moveTo(2, 0); + path.quadTo(0, 1, 2, 2); + path.lineTo(1, 3); + path.close(); + path.moveTo(0, 0); + path.lineTo(2, 0); + path.quadTo(0, 1, 1, 1); + path.close(); + testSimplify(reporter, path); +} + +static void testQuad6(skiatest::Reporter* reporter) { + SkPath path; + path.moveTo(2, 0); + path.quadTo(0, 1, 2, 2); + path.lineTo(1, 3); + path.close(); + path.moveTo(1, 0); + path.lineTo(2, 0); + path.quadTo(0, 1, 1, 1); + path.close(); + testSimplify(reporter, path); +} + +static void testQuad7(skiatest::Reporter* reporter) { + SkPath path; + path.moveTo(3, 0); + path.quadTo(0, 1, 1, 1); + path.lineTo(1, 3); + path.close(); + path.moveTo(1, 0); + path.lineTo(3, 0); + path.quadTo(0, 1, 1, 2); + path.close(); + testSimplify(reporter, path); +} + static void (*firstTest)(skiatest::Reporter* ) = 0; static TestDesc tests[] = { + TEST(testQuad7), + TEST(testQuad6), + TEST(testQuad5), + TEST(testQuad4), + TEST(testQuad3), + TEST(testQuad2), TEST(testAddTCoincident2), TEST(testAddTCoincident1), TEST(testTriangles2), @@ -3707,7 +3790,7 @@ static TestDesc tests[] = { TEST(testQuadratic95), TEST(testQuadratic94), TEST(testQuadralateral2), - TEST(testQuad1), // FIXME: fails, need to investigate + TEST(testQuad1), TEST(testCubic2), TEST(testCubic1), TEST(testQuadralateral1), diff --git a/tests/PathOpsSkpClipTest.cpp b/tests/PathOpsSkpClipTest.cpp new file mode 100644 index 0000000000..595a91a99f --- /dev/null +++ b/tests/PathOpsSkpClipTest.cpp @@ -0,0 +1,61 @@ +#include "SkBitmap.h"
+#include "SkDevice.h"
+#include "SkCanvas.h"
+#include "SkImageEncoder.h"
+#include "SkStream.h"
+#include "SkOSFile.h"
+#include "SkPicture.h"
+#include "SkString.h"
+#include "Test.h"
+
+static void make_filepath(SkString* path, const char* dir, const SkString& name) {
+ size_t len = strlen(dir);
+ path->set(dir);
+ if (len > 0 && dir[len - 1] != '/') {
+ path->append("\\");
+ }
+ path->append(name);
+}
+
+static void PathOpsSkpClipTest(skiatest::Reporter* reporter) {
+const char pictDir[] = "C:\\Users\\caryclark\\skp";
+ const char outSkpClipDir[] = "C:\\Users\\caryclark\\skpClip";
+ const char outOldClipDir[] = "C:\\Users\\caryclark\\oldClip";
+ SkOSFile::Iter iter(pictDir, "skp");
+ SkString filename;
+ while (iter.next(&filename)) {
+#if 0
+ if (strcmp(filename.c_str(), "tabl_androidpolice.skp")) {
+ continue;
+ }
+#endif
+ SkString path;
+ make_filepath(&path, pictDir, filename);
+ SkFILEStream stream(path.c_str());
+ if (!stream.isValid()) {
+ continue;
+ }
+ SkPicture* pic = SkNEW_ARGS(SkPicture, (&stream));
+ int width = pic->width();
+ int height = pic->height();
+ SkBitmap bitmap;
+ bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
+ bitmap.allocPixels();
+ SkCanvas canvas(bitmap);
+ filename.remove(filename.size() - 3, 3);
+ filename.append("png");
+ for (int i = 0; i < 2; ++i) {
+ bool useOp = i ? true : false;
+ canvas.setAllowSimplifyClip(useOp);
+ pic->draw(&canvas);
+ SkString outFile;
+ make_filepath(&outFile, useOp ? outSkpClipDir : outOldClipDir, filename);
+ SkImageEncoder::EncodeFile(outFile.c_str(), bitmap, SkImageEncoder::kPNG_Type, 100);
+ }
+ SkDELETE(pic);
+ reporter->bumpTestCount();
+ }
+}
+
+#include "TestClassDef.h"
+DEFINE_TESTCLASS_SHORT(PathOpsSkpClipTest)
diff --git a/tests/PathOpsThreadedCommon.cpp b/tests/PathOpsThreadedCommon.cpp index 9b5240cc2d..0abf8166dd 100644 --- a/tests/PathOpsThreadedCommon.cpp +++ b/tests/PathOpsThreadedCommon.cpp @@ -7,6 +7,7 @@ #include "PathOpsExtendedTest.h" #include "PathOpsThreadedCommon.h" +#include "SkThreadPool.h" PathOpsThreadedTestRunner::~PathOpsThreadedTestRunner() { for (int index = 0; index < fRunnables.count(); index++) { diff --git a/tests/PathOpsThreadedCommon.h b/tests/PathOpsThreadedCommon.h index 7b9f482977..833f24fe5d 100644 --- a/tests/PathOpsThreadedCommon.h +++ b/tests/PathOpsThreadedCommon.h @@ -7,10 +7,8 @@ #ifndef PathOpsThreadedCommon_DEFINED #define PathOpsThreadedCommon_DEFINED -#include "SkCountdown.h" #include "SkRunnable.h" #include "SkTDArray.h" -#include "SkThreadPool.h" #define PATH_STR_SIZE 512 |