blob: 7a94d07c665b01e33523eb6c00dd75a620ff2528 [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 */
Mike Kleinc0bd9f92019-04-23 12:05:21 -05007#include "include/core/SkString.h"
8#include "tests/PathOpsExtendedTest.h"
9#include "tests/PathOpsThreadedCommon.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;
caryclark@google.com66089e42013-04-10 15:55:37 +000035 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();
caryclark8f186432016-10-06 11:46:25 -070043 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");
Mike Reed7d34dc72019-11-26 12:17:17 -050052 state.outputProgress(pathStr.c_str(), SkPathFillType::kWinding);
caryclark@google.com8d0a5242013-07-16 16:11:16 +000053 }
caryclark8f186432016-10-06 11:46:25 -070054 testSimplify(path, false, out, state, pathStr.c_str());
Mike Reed7d34dc72019-11-26 12:17:17 -050055 path.setFillType(SkPathFillType::kEvenOdd);
caryclark8f186432016-10-06 11:46:25 -070056 if (state.fReporter->verbose()) {
Mike Reed7d34dc72019-11-26 12:17:17 -050057 state.outputProgress(pathStr.c_str(), SkPathFillType::kEvenOdd);
caryclark@google.com8d0a5242013-07-16 16:11:16 +000058 }
caryclark8f186432016-10-06 11:46:25 -070059 testSimplify(path, true, out, state, pathStr.c_str());
caryclark@google.com818b0cc2013-04-08 11:50:46 +000060 }
61 }
caryclark@google.com66089e42013-04-10 15:55:37 +000062 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000063}
64
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +000065DEF_TEST(PathOpsSimplifyDegeneratesThreaded, reporter) {
mtklein406654b2014-09-03 15:34:37 -070066 initializeTests(reporter, "testDegenerates");
67 PathOpsThreadedTestRunner testRunner(reporter);
caryclark@google.com818b0cc2013-04-08 11:50:46 +000068 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);
halcanary385fe4d2015-08-26 13:07:48 -070078 *testRunner.fRunnables.append() = new PathOpsThreadedRunnable(
79 &testSimplifyDegeneratesMain, a, b, c, abcIsATriangle, &testRunner);
caryclark@google.com818b0cc2013-04-08 11:50:46 +000080 }
caryclark@google.com66089e42013-04-10 15:55:37 +000081 if (!reporter->allowExtendedTest()) goto finish;
caryclark@google.com818b0cc2013-04-08 11:50:46 +000082 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000083 }
84finish:
caryclark@google.com66089e42013-04-10 15:55:37 +000085 testRunner.render();
caryclark@google.com818b0cc2013-04-08 11:50:46 +000086}