blob: 41ddd9d7b692146060d84c3dbea320c46157bf27 [file] [log] [blame]
caryclark@google.com818b0cc2013-04-08 11:50:46 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7#include "PathOpsExtendedTest.h"
8
9static THREAD_TYPE testSimplifyDegeneratesMain(void* data) {
10 SkASSERT(data);
11 State4& state = *(State4*) data;
12 char pathStr[1024];
13 sk_bzero(pathStr, sizeof(pathStr));
14 do {
15 int ax = state.a & 0x03;
16 int ay = state.a >> 2;
17 int bx = state.b & 0x03;
18 int by = state.b >> 2;
19 int cx = state.c & 0x03;
20 int cy = state.c >> 2;
21 for (int d = 0; d < 16; ++d) {
22 int dx = d & 0x03;
23 int dy = d >> 2;
24 for (int e = d ; e < 16; ++e) {
25 int ex = e & 0x03;
26 int ey = e >> 2;
27 for (int f = d ; f < 16; ++f) {
28 int fx = f & 0x03;
29 int fy = f >> 2;
30 if (state.d && (ex - dx) * (fy - dy)
31 != (ey - dy) * (fx - dx)) {
32 continue;
33 }
34 SkPath path, out;
35 path.setFillType(SkPath::kWinding_FillType);
36 path.moveTo(SkIntToScalar(ax), SkIntToScalar(ay));
37 path.lineTo(SkIntToScalar(bx), SkIntToScalar(by));
38 path.lineTo(SkIntToScalar(cx), SkIntToScalar(cy));
39 path.close();
40 path.moveTo(SkIntToScalar(dx), SkIntToScalar(dy));
41 path.lineTo(SkIntToScalar(ex), SkIntToScalar(ey));
42 path.lineTo(SkIntToScalar(fx), SkIntToScalar(fy));
43 path.close();
44 if (1) {
45 char* str = pathStr;
46 str += sprintf(str, " path.moveTo(%d, %d);\n", ax, ay);
47 str += sprintf(str, " path.lineTo(%d, %d);\n", bx, by);
48 str += sprintf(str, " path.lineTo(%d, %d);\n", cx, cy);
49 str += sprintf(str, " path.close();\n");
50 str += sprintf(str, " path.moveTo(%d, %d);\n", dx, dy);
51 str += sprintf(str, " path.lineTo(%d, %d);\n", ex, ey);
52 str += sprintf(str, " path.lineTo(%d, %d);\n", fx, fy);
53 str += sprintf(str, " path.close();\n");
54 }
55 outputProgress(state, pathStr, SkPath::kWinding_FillType);
56 testSimplify(path, false, out, state, pathStr);
57 state.testsRun++;
58 path.setFillType(SkPath::kEvenOdd_FillType);
59 outputProgress(state, pathStr, SkPath::kEvenOdd_FillType);
60 testSimplify(path, true, out, state, pathStr);
61 state.testsRun++;
62 }
63 }
64 }
65 } while (runNextTestSet(state));
66 THREAD_RETURN
67}
68
69static void TestSimplifyDegeneratesThreaded(skiatest::Reporter* reporter) {
70 int testsRun = 0;
71 if (gShowTestProgress) SkDebugf("%s\n", __FUNCTION__);
72#ifdef SK_DEBUG
73 gDebugMaxWindSum = 2;
74 gDebugMaxWindValue = 2;
75#endif
76 const char testStr[] = "testDegenerates";
77 initializeTests(reporter, testStr, sizeof(testStr));
78 for (int a = 0; a < 16; ++a) {
79 int ax = a & 0x03;
80 int ay = a >> 2;
81 for (int b = a ; b < 16; ++b) {
82 int bx = b & 0x03;
83 int by = b >> 2;
84 for (int c = a ; c < 16; ++c) {
85 int cx = c & 0x03;
86 int cy = c >> 2;
87 bool abcIsATriangle = (bx - ax) * (cy - ay) != (by - ay) * (cx - ax);
88 testsRun += dispatchTest4(testSimplifyDegeneratesMain,
89 a, b, c, abcIsATriangle);
90 }
91 if (!gAllowExtendedTest) goto finish;
92 if (gShowTestProgress) SkDebugf(".");
93 }
94 if (gShowTestProgress) SkDebugf("\n%d", a);
95 }
96finish:
97 testsRun += waitForCompletion();
98 if (gShowTestProgress) SkDebugf("%s tests=%d\n", __FUNCTION__, testsRun);
99}
100
101#include "TestClassDef.h"
102DEFINE_TESTCLASS("PathOpsSimplifyDegeneratesThreaded", SimplifyDegeneratesThreadedTestClass, \
103 TestSimplifyDegeneratesThreaded)