blob: 567713ce6e583798a2ce6a33bc30dd909060aafa [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 testSimplifyTrianglesMain(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 < 15; ++d) {
22 int dx = d & 0x03;
23 int dy = d >> 2;
24 for (int e = d + 1; e < 16; ++e) {
25 int ex = e & 0x03;
26 int ey = e >> 2;
27 for (int f = d + 1; f < 16; ++f) {
28 if (e == f) {
29 continue;
30 }
31 int fx = f & 0x03;
32 int fy = f >> 2;
33 if ((ex - dx) * (fy - dy) == (ey - dy) * (fx - dx)) {
34 continue;
35 }
36 SkPath path, out;
37 path.setFillType(SkPath::kWinding_FillType);
38 path.moveTo(SkIntToScalar(ax), SkIntToScalar(ay));
39 path.lineTo(SkIntToScalar(bx), SkIntToScalar(by));
40 path.lineTo(SkIntToScalar(cx), SkIntToScalar(cy));
41 path.close();
42 path.moveTo(SkIntToScalar(dx), SkIntToScalar(dy));
43 path.lineTo(SkIntToScalar(ex), SkIntToScalar(ey));
44 path.lineTo(SkIntToScalar(fx), SkIntToScalar(fy));
45 path.close();
46 if (1) {
47 char* str = pathStr;
48 str += sprintf(str, " path.moveTo(%d, %d);\n", ax, ay);
49 str += sprintf(str, " path.lineTo(%d, %d);\n", bx, by);
50 str += sprintf(str, " path.lineTo(%d, %d);\n", cx, cy);
51 str += sprintf(str, " path.close();\n");
52 str += sprintf(str, " path.moveTo(%d, %d);\n", dx, dy);
53 str += sprintf(str, " path.lineTo(%d, %d);\n", ex, ey);
54 str += sprintf(str, " path.lineTo(%d, %d);\n", fx, fy);
55 str += sprintf(str, " path.close();\n");
56 }
57 outputProgress(state, pathStr, SkPath::kWinding_FillType);
58 testSimplify(path, false, out, state, pathStr);
59 state.testsRun++;
60 path.setFillType(SkPath::kEvenOdd_FillType);
61 outputProgress(state, pathStr, SkPath::kEvenOdd_FillType);
62 testSimplify(path, true, out, state, pathStr);
63 state.testsRun++;
64 }
65 }
66 }
67 } while (runNextTestSet(state));
68 THREAD_RETURN
69}
70
71static void TestSimplifyTrianglesThreaded(skiatest::Reporter* reporter) {
72 int testsRun = 0;
73 if (gShowTestProgress) SkDebugf("%s\n", __FUNCTION__);
74#ifdef SK_DEBUG
75 gDebugMaxWindSum = 2;
76 gDebugMaxWindValue = 2;
77#endif
78 const char testStr[] = "testTriangles";
79 initializeTests(reporter, testStr, sizeof(testStr));
80 for (int a = 0; a < 15; ++a) {
81 int ax = a & 0x03;
82 int ay = a >> 2;
83 for (int b = a + 1; b < 16; ++b) {
84 int bx = b & 0x03;
85 int by = b >> 2;
86 for (int c = a + 1; c < 16; ++c) {
87 if (b == c) {
88 continue;
89 }
90 int cx = c & 0x03;
91 int cy = c >> 2;
92 if ((bx - ax) * (cy - ay) == (by - ay) * (cx - ax)) {
93 continue;
94 }
95 testsRun += dispatchTest4(testSimplifyTrianglesMain, a, b, c, 0);
96 }
97 if (!gAllowExtendedTest) goto finish;
98 if (gShowTestProgress) SkDebugf(".");
99 }
100 if (gShowTestProgress) SkDebugf("\n%d", a);
101 }
102finish:
103 testsRun += waitForCompletion();
104 if (gShowTestProgress) SkDebugf("%s tests=%d\n", __FUNCTION__, testsRun);
105}
106
107#include "TestClassDef.h"
108DEFINE_TESTCLASS("SimplifyTrianglesThreaded", SimplifyTrianglesThreadedTestClass, \
109 TestSimplifyTrianglesThreaded)