aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental/Intersection/EdgeWalkerQuadralaterals_Test.cpp
blob: 6cb24171a4bcf17a9bb3425f091f5b32d0edb8c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include "EdgeWalker_Test.h"
#include "Intersection_Tests.h"

static void testSimplifyQuad1() {
    SkPath path, out;
    path.moveTo(0, 0);
    path.lineTo(1, 0);
    path.lineTo(3, 2);
    path.lineTo(3, 3);
    path.close();
    path.moveTo(1, 0);
    path.lineTo(1, 3);
    path.lineTo(1, 3);
    path.lineTo(1, 3);
    path.close();
    testSimplify(path, true, out);
}

static void testSimplifyQuad2() {
    SkPath path, out;
    path.moveTo(0, 0);
    path.lineTo(0, 0);
    path.lineTo(0, 0);
    path.lineTo(0, 2);
    path.close();
    path.moveTo(0, 1);
    path.lineTo(0, 1);
    path.lineTo(1, 1);
    path.lineTo(0, 2);
    path.close();
    testSimplify(path, true, out);
}

static void testSimplifyQuad3() {
    SkPath path, out;
    path.moveTo(0, 0);
    path.lineTo(0, 0);
    path.lineTo(1, 0);
    path.lineTo(1, 2);
    path.close();
    path.moveTo(0, 1);
    path.lineTo(1, 1);
    path.lineTo(2, 1);
    path.lineTo(0, 2);
    path.close();
    testSimplify(path, true, out);
}

static void testSimplifyQuad4() {
    SkPath path, out;
    path.moveTo(0, 0);
    path.lineTo(0, 0);
    path.lineTo(1, 0);
    path.lineTo(2, 2);
    path.close();
    path.moveTo(0, 0);
    path.lineTo(2, 1);
    path.lineTo(3, 1);
    path.lineTo(3, 3);
    path.close();
    testSimplify(path, true, out);
}

static void testSimplifyQuad5() {
    SkPath path, out;
    path.moveTo(0, 0);
    path.lineTo(0, 0);
    path.lineTo(1, 0);
    path.lineTo(3, 2);
    path.close();
    path.moveTo(0, 1);
    path.lineTo(1, 1);
    path.lineTo(2, 1);
    path.lineTo(0, 2);
    path.close();
    testSimplify(path, true, out);
}

static void testSimplifyQuad6() {
    SkPath path, out;
    path.moveTo(0, 0);
    path.lineTo(1, 0);
    path.lineTo(1, 1);
    path.lineTo(3, 3);
    path.close();
    path.moveTo(1, 1);
    path.lineTo(1, 1);
    path.lineTo(1, 1);
    path.lineTo(2, 2);
    path.close();
    testSimplify(path, true, out);
}

static void testSimplify4x4Quadralaterals() {
    char pathStr[1024];
    bzero(pathStr, sizeof(pathStr));
    for (int a = 0; a < 16; ++a) {
        int ax = a & 0x03;
        int ay = a >> 2;
        for (int b = a ; b < 16; ++b) {
            int bx = b & 0x03;
            int by = b >> 2;
            for (int c = b ; c < 16; ++c) {
                int cx = c & 0x03;
                int cy = c >> 2;
                for (int d = c; d < 16; ++d) {
                    int dx = d & 0x03;
                    int dy = d >> 2;
                    for (int e = 0 ; e < 16; ++e) {
                        int ex = e & 0x03;
                        int ey = e >> 2;
                        for (int f = e ; f < 16; ++f) {
                            int fx = f & 0x03;
                            int fy = f >> 2;
                            for (int g = f ; g < 16; ++g) {
                                int gx = g & 0x03;
                                int gy = g >> 2;
                                for (int h = g ; h < 16; ++h) {
                                    int hx = h & 0x03;
                                    int hy = h >> 2;
        SkPath path, out;
        path.setFillType(SkPath::kWinding_FillType);
        path.moveTo(ax, ay);
        path.lineTo(bx, by);
        path.lineTo(cx, cy);
        path.lineTo(dx, dy);
        path.close();
        path.moveTo(ex, ey);
        path.lineTo(fx, fy);
        path.lineTo(gx, gy);
        path.lineTo(hx, hy);
        path.close();
        if (1) {  // gdb: set print elements 400
            char* str = pathStr;
            str += sprintf(str, "    path.moveTo(%d, %d);\n", ax, ay);
            str += sprintf(str, "    path.lineTo(%d, %d);\n", bx, by);
            str += sprintf(str, "    path.lineTo(%d, %d);\n", cx, cy);
            str += sprintf(str, "    path.lineTo(%d, %d);\n", dx, dy);
            str += sprintf(str, "    path.close();\n");
            str += sprintf(str, "    path.moveTo(%d, %d);\n", ex, ey);
            str += sprintf(str, "    path.lineTo(%d, %d);\n", fx, fy);
            str += sprintf(str, "    path.lineTo(%d, %d);\n", gx, gy);
            str += sprintf(str, "    path.lineTo(%d, %d);\n", hx, hy);
            str += sprintf(str, "    path.close();");
        }
        if (!testSimplify(path, true, out)) {
            SkDebugf("*/\n{ SkPath::kWinding_FillType, %d, %d, %d, %d, %d, %d, %d, %d },\n/*\n",
                    a, b, c, d, e, f, g, h);
        }
        path.setFillType(SkPath::kEvenOdd_FillType);
        if (!testSimplify(path, true, out)) {
            SkDebugf("*/\n{ SkPath::kEvenOdd_FillType, %d, %d, %d, %d, %d, %d, %d, %d },\n/*\n",
                    a, b, c, d, e, f, g, h);
        }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}



static void (*simplifyTests[])() = {
    testSimplifyQuad6,
    testSimplifyQuad5,
    testSimplifyQuad4,
    testSimplifyQuad3,
    testSimplifyQuad2,
    testSimplifyQuad1,
    testSimplify4x4Quadralaterals,
};

static size_t simplifyTestsCount = sizeof(simplifyTests) / sizeof(simplifyTests[0]);

static void (*firstTest)() = 0;

void SimplifyQuadralateralPaths_Test() {
    size_t index = 0;
    if (firstTest) {
        while (index < simplifyTestsCount && simplifyTests[index] != firstTest) {
            ++index;
        }
    }
    for ( ; index < simplifyTestsCount; ++index) {
        (*simplifyTests[index])();
    }
}