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 | |
| 21 | struct curve* testSet[] = { |
| 22 | test1 |
| 23 | }; |
| 24 | |
| 25 | size_t testSet_count = sizeof(testSet) / sizeof(testSet[0]); |
| 26 | |
| 27 | static void construct() { |
| 28 | for (size_t idx = 0; idx < testSet_count; ++idx) { |
| 29 | const curve* test = testSet[idx]; |
| 30 | SkPath path; |
| 31 | bool pathComplete = false; |
| 32 | bool first = true; |
| 33 | do { |
| 34 | if (first) { |
| 35 | path.moveTo(test->pts[0].fX, test->pts[0].fY); |
| 36 | first = false; |
| 37 | } else if (test->verb != SkPath::kDone_Verb) { |
| 38 | path.lineTo(test->pts[0].fX, test->pts[0].fY); |
| 39 | } |
| 40 | switch (test->verb) { |
| 41 | case SkPath::kDone_Verb: |
| 42 | pathComplete = true; |
| 43 | break; |
| 44 | case SkPath::kLine_Verb: |
| 45 | path.lineTo(test->pts[1].fX, test->pts[1].fY); |
| 46 | break; |
| 47 | case SkPath::kQuad_Verb: |
| 48 | path.quadTo(test->pts[1].fX, test->pts[1].fY, test->pts[2].fX, test->pts[2].fY); |
| 49 | break; |
| 50 | case SkPath::kCubic_Verb: |
| 51 | 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); |
| 52 | break; |
| 53 | } |
| 54 | test++; |
| 55 | } while (!pathComplete); |
| 56 | path.close(); |
| 57 | if (gShowOriginal) { |
| 58 | showPath(path, NULL); |
| 59 | SkDebugf("simplified:\n"); |
| 60 | } |
| 61 | testSimplifyx(path); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | static void (*tests[])() = { |
| 66 | construct, |
| 67 | }; |
| 68 | |
| 69 | static const size_t testCount = sizeof(tests) / sizeof(tests[0]); |
| 70 | |
| 71 | static void (*firstTest)() = 0; |
| 72 | static bool skipAll = false; |
| 73 | |
| 74 | void MiniSimplify_Test() { |
| 75 | if (skipAll) { |
| 76 | return; |
| 77 | } |
| 78 | size_t index = 0; |
| 79 | if (firstTest) { |
| 80 | while (index < testCount && tests[index] != firstTest) { |
| 81 | ++index; |
| 82 | } |
| 83 | } |
| 84 | bool firstTestComplete = false; |
| 85 | for ( ; index < testCount; ++index) { |
| 86 | (*tests[index])(); |
| 87 | firstTestComplete = true; |
| 88 | } |
| 89 | } |