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.moveTo(SkIntToScalar(ax), SkIntToScalar(ay));
36 path.lineTo(SkIntToScalar(bx), SkIntToScalar(by));
37 path.lineTo(SkIntToScalar(cx), SkIntToScalar(cy));
38 path.close();
39 path.moveTo(SkIntToScalar(dx), SkIntToScalar(dy));
40 path.lineTo(SkIntToScalar(ex), SkIntToScalar(ey));
41 path.lineTo(SkIntToScalar(fx), SkIntToScalar(fy));
42 path.close();
43 if (state.fReporter->verbose()) {
44 pathStr.appendf(" path.moveTo(%d, %d);\n", ax, ay);
45 pathStr.appendf(" path.lineTo(%d, %d);\n", bx, by);
46 pathStr.appendf(" path.lineTo(%d, %d);\n", cx, cy);
47 pathStr.appendf(" path.close();\n");
48 pathStr.appendf(" path.moveTo(%d, %d);\n", dx, dy);
49 pathStr.appendf(" path.lineTo(%d, %d);\n", ex, ey);
50 pathStr.appendf(" path.lineTo(%d, %d);\n", fx, fy);
51 pathStr.appendf(" path.close();\n");
52 state.outputProgress(pathStr.c_str(), SkPathFillType::kWinding);
53 }
54 testSimplify(path, false, out, state, pathStr.c_str());
55 path.setFillType(SkPathFillType::kEvenOdd);
56 if (state.fReporter->verbose()) {
57 state.outputProgress(pathStr.c_str(), SkPathFillType::kEvenOdd);
58 }
59 testSimplify(path, true, out, state, pathStr.c_str());
60 }
61 }
62 }
63 }
64
DEF_TEST(PathOpsSimplifyDegeneratesThreaded,reporter)65 DEF_TEST(PathOpsSimplifyDegeneratesThreaded, reporter) {
66 initializeTests(reporter, "testDegenerates");
67 PathOpsThreadedTestRunner testRunner(reporter);
68 for (int a = 0; a < 16; ++a) {
69 int ax = a & 0x03;
70 int ay = a >> 2;
71 for (int b = a ; b < 16; ++b) {
72 int bx = b & 0x03;
73 int by = b >> 2;
74 for (int c = a ; c < 16; ++c) {
75 int cx = c & 0x03;
76 int cy = c >> 2;
77 bool abcIsATriangle = (bx - ax) * (cy - ay) != (by - ay) * (cx - ax);
78 *testRunner.fRunnables.append() = new PathOpsThreadedRunnable(
79 &testSimplifyDegeneratesMain, a, b, c, abcIsATriangle, &testRunner);
80 }
81 if (!reporter->allowExtendedTest()) goto finish;
82 }
83 }
84 finish:
85 testRunner.render();
86 }
87