caryclark@google.com | a461ff0 | 2012-10-11 12:54:23 +0000 | [diff] [blame] | 1 | #include "EdgeWalker_Test.h" |
| 2 | #include "Intersection_Tests.h" |
| 3 | #include "ShapeOps.h" |
| 4 | |
| 5 | bool gShowOriginal = true; |
| 6 | |
| 7 | struct curve { |
| 8 | SkPath::Verb verb; |
| 9 | SkPoint pts[4]; |
| 10 | }; |
| 11 | |
| 12 | struct curve test1[] = { |
| 13 | {SkPath::kQuad_Verb, {{366.608826f, 151.196014f}, {378.803101f, 136.674606f}, {398.164948f, 136.674606f}}}, |
| 14 | {SkPath::kLine_Verb, {{354.009216f, 208.816208f}, {393.291473f, 102.232819f}}}, |
| 15 | {SkPath::kQuad_Verb, {{359.978058f, 136.581512f}, {378.315979f, 136.581512f}, {388.322723f, 149.613556f}}}, |
| 16 | {SkPath::kQuad_Verb, {{364.390686f, 157.898193f}, {375.281769f, 136.674606f}, {396.039917f, 136.674606f}}}, |
| 17 | {SkPath::kLine_Verb, {{396.039917f, 136.674606f}, {350, 120}}}, |
| 18 | {SkPath::kDone_Verb} |
| 19 | }; |
| 20 | |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 21 | struct curve test2[] = { |
| 22 | {SkPath::kQuad_Verb, {{366.608826f, 151.196014f}, {378.803101f, 136.674606f}, {398.164948f, 136.674606f}}}, |
| 23 | {SkPath::kQuad_Verb, {{359.978058f, 136.581512f}, {378.315979f, 136.581512f}, {388.322723f, 149.613556f}}}, |
| 24 | {SkPath::kQuad_Verb, {{364.390686f, 157.898193f}, {375.281769f, 136.674606f}, {396.039917f, 136.674606f}}}, |
| 25 | {SkPath::kDone_Verb} |
| 26 | }; |
| 27 | |
caryclark@google.com | a461ff0 | 2012-10-11 12:54:23 +0000 | [diff] [blame] | 28 | struct curve* testSet[] = { |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 29 | test2, |
caryclark@google.com | a461ff0 | 2012-10-11 12:54:23 +0000 | [diff] [blame] | 30 | test1 |
| 31 | }; |
| 32 | |
| 33 | size_t testSet_count = sizeof(testSet) / sizeof(testSet[0]); |
| 34 | |
| 35 | static void construct() { |
| 36 | for (size_t idx = 0; idx < testSet_count; ++idx) { |
| 37 | const curve* test = testSet[idx]; |
| 38 | SkPath path; |
| 39 | bool pathComplete = false; |
| 40 | bool first = true; |
| 41 | do { |
| 42 | if (first) { |
| 43 | path.moveTo(test->pts[0].fX, test->pts[0].fY); |
| 44 | first = false; |
| 45 | } else if (test->verb != SkPath::kDone_Verb) { |
| 46 | path.lineTo(test->pts[0].fX, test->pts[0].fY); |
| 47 | } |
| 48 | switch (test->verb) { |
| 49 | case SkPath::kDone_Verb: |
| 50 | pathComplete = true; |
| 51 | break; |
| 52 | case SkPath::kLine_Verb: |
| 53 | path.lineTo(test->pts[1].fX, test->pts[1].fY); |
| 54 | break; |
| 55 | case SkPath::kQuad_Verb: |
| 56 | path.quadTo(test->pts[1].fX, test->pts[1].fY, test->pts[2].fX, test->pts[2].fY); |
| 57 | break; |
| 58 | case SkPath::kCubic_Verb: |
| 59 | path.cubicTo(test->pts[1].fX, test->pts[1].fY, test->pts[2].fX, test->pts[2].fY, test->pts[3].fX, test->pts[3].fY); |
| 60 | break; |
caryclark@google.com | 9f3e9a5 | 2012-12-10 12:50:53 +0000 | [diff] [blame] | 61 | default: |
| 62 | SkASSERT(0); |
caryclark@google.com | a461ff0 | 2012-10-11 12:54:23 +0000 | [diff] [blame] | 63 | } |
| 64 | test++; |
| 65 | } while (!pathComplete); |
| 66 | path.close(); |
| 67 | if (gShowOriginal) { |
| 68 | showPath(path, NULL); |
| 69 | SkDebugf("simplified:\n"); |
| 70 | } |
| 71 | testSimplifyx(path); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | static void (*tests[])() = { |
| 76 | construct, |
| 77 | }; |
| 78 | |
| 79 | static const size_t testCount = sizeof(tests) / sizeof(tests[0]); |
| 80 | |
| 81 | static void (*firstTest)() = 0; |
| 82 | static bool skipAll = false; |
| 83 | |
| 84 | void MiniSimplify_Test() { |
| 85 | if (skipAll) { |
| 86 | return; |
| 87 | } |
| 88 | size_t index = 0; |
| 89 | if (firstTest) { |
| 90 | while (index < testCount && tests[index] != firstTest) { |
| 91 | ++index; |
| 92 | } |
| 93 | } |
| 94 | bool firstTestComplete = false; |
| 95 | for ( ; index < testCount; ++index) { |
| 96 | (*tests[index])(); |
| 97 | firstTestComplete = true; |
| 98 | } |
| 99 | } |