blob: 99a54d8fb62cb290191354db3d95af55051bcca7 [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"
caryclark@google.com66089e42013-04-10 15:55:37 +00008#include "PathOpsThreadedCommon.h"
caryclark@google.com818b0cc2013-04-08 11:50:46 +00009
caryclark@google.com66089e42013-04-10 15:55:37 +000010static void testSimplifyDegeneratesMain(PathOpsThreadState* data) {
caryclark@google.com818b0cc2013-04-08 11:50:46 +000011 SkASSERT(data);
caryclark@google.com66089e42013-04-10 15:55:37 +000012 PathOpsThreadState& state = *data;
caryclark@google.com818b0cc2013-04-08 11:50:46 +000013 char pathStr[1024];
caryclark@google.com8d0a5242013-07-16 16:11:16 +000014 bool progress = state.fReporter->verbose(); // FIXME: break out into its own parameter?
15 if (progress) {
16 sk_bzero(pathStr, sizeof(pathStr));
17 }
caryclark@google.com66089e42013-04-10 15:55:37 +000018 int ax = state.fA & 0x03;
19 int ay = state.fA >> 2;
20 int bx = state.fB & 0x03;
21 int by = state.fB >> 2;
22 int cx = state.fC & 0x03;
23 int cy = state.fC >> 2;
24 for (int d = 0; d < 16; ++d) {
25 int dx = d & 0x03;
26 int dy = d >> 2;
27 for (int e = d ; e < 16; ++e) {
28 int ex = e & 0x03;
29 int ey = e >> 2;
30 for (int f = d ; f < 16; ++f) {
31 int fx = f & 0x03;
32 int fy = f >> 2;
33 if (state.fD && (ex - dx) * (fy - dy)
34 != (ey - dy) * (fx - dx)) {
35 continue;
caryclark@google.com818b0cc2013-04-08 11:50:46 +000036 }
caryclark@google.com66089e42013-04-10 15:55:37 +000037 SkPath path, out;
38 path.setFillType(SkPath::kWinding_FillType);
39 path.moveTo(SkIntToScalar(ax), SkIntToScalar(ay));
40 path.lineTo(SkIntToScalar(bx), SkIntToScalar(by));
41 path.lineTo(SkIntToScalar(cx), SkIntToScalar(cy));
42 path.close();
43 path.moveTo(SkIntToScalar(dx), SkIntToScalar(dy));
44 path.lineTo(SkIntToScalar(ex), SkIntToScalar(ey));
45 path.lineTo(SkIntToScalar(fx), SkIntToScalar(fy));
46 path.close();
caryclark@google.com8d0a5242013-07-16 16:11:16 +000047 if (progress) {
48 char* str = pathStr;
49 str += sprintf(str, " path.moveTo(%d, %d);\n", ax, ay);
50 str += sprintf(str, " path.lineTo(%d, %d);\n", bx, by);
51 str += sprintf(str, " path.lineTo(%d, %d);\n", cx, cy);
52 str += sprintf(str, " path.close();\n");
53 str += sprintf(str, " path.moveTo(%d, %d);\n", dx, dy);
54 str += sprintf(str, " path.lineTo(%d, %d);\n", ex, ey);
55 str += sprintf(str, " path.lineTo(%d, %d);\n", fx, fy);
56 str += sprintf(str, " path.close();\n");
57 outputProgress(state.fPathStr, pathStr, SkPath::kWinding_FillType);
58 }
caryclark@google.com66089e42013-04-10 15:55:37 +000059 testSimplify(path, false, out, state, pathStr);
60 path.setFillType(SkPath::kEvenOdd_FillType);
caryclark@google.com8d0a5242013-07-16 16:11:16 +000061 if (progress) {
62 outputProgress(state.fPathStr, pathStr, SkPath::kEvenOdd_FillType);
63 }
caryclark@google.com66089e42013-04-10 15:55:37 +000064 testSimplify(path, true, out, state, pathStr);
caryclark@google.com818b0cc2013-04-08 11:50:46 +000065 }
66 }
caryclark@google.com66089e42013-04-10 15:55:37 +000067 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000068}
69
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +000070DEF_TEST(PathOpsSimplifyDegeneratesThreaded, reporter) {
mtklein406654b2014-09-03 15:34:37 -070071 initializeTests(reporter, "testDegenerates");
72 PathOpsThreadedTestRunner testRunner(reporter);
caryclark@google.com818b0cc2013-04-08 11:50:46 +000073 for (int a = 0; a < 16; ++a) {
74 int ax = a & 0x03;
75 int ay = a >> 2;
76 for (int b = a ; b < 16; ++b) {
77 int bx = b & 0x03;
78 int by = b >> 2;
79 for (int c = a ; c < 16; ++c) {
80 int cx = c & 0x03;
81 int cy = c >> 2;
82 bool abcIsATriangle = (bx - ax) * (cy - ay) != (by - ay) * (cx - ax);
halcanary385fe4d2015-08-26 13:07:48 -070083 *testRunner.fRunnables.append() = new PathOpsThreadedRunnable(
84 &testSimplifyDegeneratesMain, a, b, c, abcIsATriangle, &testRunner);
caryclark@google.com818b0cc2013-04-08 11:50:46 +000085 }
caryclark@google.com66089e42013-04-10 15:55:37 +000086 if (!reporter->allowExtendedTest()) goto finish;
caryclark@google.com818b0cc2013-04-08 11:50:46 +000087 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000088 }
89finish:
caryclark@google.com66089e42013-04-10 15:55:37 +000090 testRunner.render();
caryclark@google.com818b0cc2013-04-08 11:50:46 +000091}