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