1 /*
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 "include/core/SkString.h"
8 #include "tests/PathOpsExtendedTest.h"
9 #include "tests/PathOpsThreadedCommon.h"
10
testSimplifyDegeneratesMain(PathOpsThreadState * data)11 static void testSimplifyDegeneratesMain(PathOpsThreadState* data) {
12 SkASSERT(data);
13 PathOpsThreadState& state = *data;
14 int ax = state.fA & 0x03;
15 int ay = state.fA >> 2;
16 int bx = state.fB & 0x03;
17 int by = state.fB >> 2;
18 int cx = state.fC & 0x03;
19 int cy = state.fC >> 2;
20 for (int d = 0; d < 16; ++d) {
21 int dx = d & 0x03;
22 int dy = d >> 2;
23 for (int e = d ; e < 16; ++e) {
24 int ex = e & 0x03;
25 int ey = e >> 2;
26 for (int f = d ; f < 16; ++f) {
27 int fx = f & 0x03;
28 int fy = f >> 2;
29 if (state.fD && (ex - dx) * (fy - dy)
30 != (ey - dy) * (fx - dx)) {
31 continue;
32 }
33 SkString pathStr;
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 (state.fReporter->verbose()) {
45 pathStr.appendf(" path.moveTo(%d, %d);\n", ax, ay);
46 pathStr.appendf(" path.lineTo(%d, %d);\n", bx, by);
47 pathStr.appendf(" path.lineTo(%d, %d);\n", cx, cy);
48 pathStr.appendf(" path.close();\n");
49 pathStr.appendf(" path.moveTo(%d, %d);\n", dx, dy);
50 pathStr.appendf(" path.lineTo(%d, %d);\n", ex, ey);
51 pathStr.appendf(" path.lineTo(%d, %d);\n", fx, fy);
52 pathStr.appendf(" path.close();\n");
53 state.outputProgress(pathStr.c_str(), SkPath::kWinding_FillType);
54 }
55 testSimplify(path, false, out, state, pathStr.c_str());
56 path.setFillType(SkPath::kEvenOdd_FillType);
57 if (state.fReporter->verbose()) {
58 state.outputProgress(pathStr.c_str(), SkPath::kEvenOdd_FillType);
59 }
60 testSimplify(path, true, out, state, pathStr.c_str());
61 }
62 }
63 }
64 }
65
DEF_TEST(PathOpsSimplifyDegeneratesThreaded,reporter)66 DEF_TEST(PathOpsSimplifyDegeneratesThreaded, reporter) {
67 initializeTests(reporter, "testDegenerates");
68 PathOpsThreadedTestRunner testRunner(reporter);
69 for (int a = 0; a < 16; ++a) {
70 int ax = a & 0x03;
71 int ay = a >> 2;
72 for (int b = a ; b < 16; ++b) {
73 int bx = b & 0x03;
74 int by = b >> 2;
75 for (int c = a ; c < 16; ++c) {
76 int cx = c & 0x03;
77 int cy = c >> 2;
78 bool abcIsATriangle = (bx - ax) * (cy - ay) != (by - ay) * (cx - ax);
79 *testRunner.fRunnables.append() = new PathOpsThreadedRunnable(
80 &testSimplifyDegeneratesMain, a, b, c, abcIsATriangle, &testRunner);
81 }
82 if (!reporter->allowExtendedTest()) goto finish;
83 }
84 }
85 finish:
86 testRunner.render();
87 }
88