blob: 3f49718c4123941d98d65e2895bb745571ca6a4f [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"
caryclark8f186432016-10-06 11:46:25 -07009#include "SkString.h"
caryclark@google.com818b0cc2013-04-08 11:50:46 +000010
caryclark@google.com66089e42013-04-10 15:55:37 +000011static void testSimplifyDegeneratesMain(PathOpsThreadState* data) {
caryclark@google.com818b0cc2013-04-08 11:50:46 +000012 SkASSERT(data);
caryclark@google.com66089e42013-04-10 15:55:37 +000013 PathOpsThreadState& state = *data;
caryclark@google.com66089e42013-04-10 15:55:37 +000014 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;
caryclark@google.com818b0cc2013-04-08 11:50:46 +000032 }
caryclark8f186432016-10-06 11:46:25 -070033 SkString pathStr;
caryclark@google.com66089e42013-04-10 15:55:37 +000034 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();
caryclark8f186432016-10-06 11:46:25 -070044 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");
Mike Reedff80c2a2017-01-07 11:16:28 -050053 state.outputProgress(pathStr.c_str(), SkPath::kWinding_FillType);
caryclark@google.com8d0a5242013-07-16 16:11:16 +000054 }
caryclark8f186432016-10-06 11:46:25 -070055 testSimplify(path, false, out, state, pathStr.c_str());
caryclark@google.com66089e42013-04-10 15:55:37 +000056 path.setFillType(SkPath::kEvenOdd_FillType);
caryclark8f186432016-10-06 11:46:25 -070057 if (state.fReporter->verbose()) {
Mike Reedff80c2a2017-01-07 11:16:28 -050058 state.outputProgress(pathStr.c_str(), SkPath::kEvenOdd_FillType);
caryclark@google.com8d0a5242013-07-16 16:11:16 +000059 }
caryclark8f186432016-10-06 11:46:25 -070060 testSimplify(path, true, out, state, pathStr.c_str());
caryclark@google.com818b0cc2013-04-08 11:50:46 +000061 }
62 }
caryclark@google.com66089e42013-04-10 15:55:37 +000063 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000064}
65
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +000066DEF_TEST(PathOpsSimplifyDegeneratesThreaded, reporter) {
mtklein406654b2014-09-03 15:34:37 -070067 initializeTests(reporter, "testDegenerates");
68 PathOpsThreadedTestRunner testRunner(reporter);
caryclark@google.com818b0cc2013-04-08 11:50:46 +000069 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);
halcanary385fe4d2015-08-26 13:07:48 -070079 *testRunner.fRunnables.append() = new PathOpsThreadedRunnable(
80 &testSimplifyDegeneratesMain, a, b, c, abcIsATriangle, &testRunner);
caryclark@google.com818b0cc2013-04-08 11:50:46 +000081 }
caryclark@google.com66089e42013-04-10 15:55:37 +000082 if (!reporter->allowExtendedTest()) goto finish;
caryclark@google.com818b0cc2013-04-08 11:50:46 +000083 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000084 }
85finish:
caryclark@google.com66089e42013-04-10 15:55:37 +000086 testRunner.render();
caryclark@google.com818b0cc2013-04-08 11:50:46 +000087}