blob: 8c1dbc2076d74ae9ffee12248791dccb2838bad7 [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 testSimplifyTrianglesMain(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.com03610322013-04-18 15:58:21 +000014 state.fKey = "?";
caryclark@google.com66089e42013-04-10 15:55:37 +000015 int ax = state.fA & 0x03;
16 int ay = state.fA >> 2;
17 int bx = state.fB & 0x03;
18 int by = state.fB >> 2;
19 int cx = state.fC & 0x03;
20 int cy = state.fC >> 2;
21 for (int d = 0; d < 15; ++d) {
22 int dx = d & 0x03;
23 int dy = d >> 2;
24 for (int e = d + 1; e < 16; ++e) {
25 int ex = e & 0x03;
26 int ey = e >> 2;
27 for (int f = d + 1; f < 16; ++f) {
28 if (e == f) {
29 continue;
caryclark@google.com818b0cc2013-04-08 11:50:46 +000030 }
caryclark@google.com66089e42013-04-10 15:55:37 +000031 int fx = f & 0x03;
32 int fy = f >> 2;
33 if ((ex - dx) * (fy - dy) == (ey - dy) * (fx - dx)) {
34 continue;
35 }
caryclark8f186432016-10-06 11:46:25 -070036 SkString pathStr;
caryclark@google.com66089e42013-04-10 15:55:37 +000037 SkPath path, out;
caryclark@google.com66089e42013-04-10 15:55:37 +000038 path.moveTo(SkIntToScalar(ax), SkIntToScalar(ay));
39 path.lineTo(SkIntToScalar(bx), SkIntToScalar(by));
40 path.lineTo(SkIntToScalar(cx), SkIntToScalar(cy));
41 path.close();
42 path.moveTo(SkIntToScalar(dx), SkIntToScalar(dy));
43 path.lineTo(SkIntToScalar(ex), SkIntToScalar(ey));
44 path.lineTo(SkIntToScalar(fx), SkIntToScalar(fy));
45 path.close();
caryclark8f186432016-10-06 11:46:25 -070046 if (state.fReporter->verbose()) {
47 pathStr.appendf(" path.moveTo(%d, %d);\n", ax, ay);
48 pathStr.appendf(" path.lineTo(%d, %d);\n", bx, by);
49 pathStr.appendf(" path.lineTo(%d, %d);\n", cx, cy);
50 pathStr.appendf(" path.close();\n");
51 pathStr.appendf(" path.moveTo(%d, %d);\n", dx, dy);
52 pathStr.appendf(" path.lineTo(%d, %d);\n", ex, ey);
53 pathStr.appendf(" path.lineTo(%d, %d);\n", fx, fy);
54 pathStr.appendf(" path.close();\n");
Mike Reed7d34dc72019-11-26 12:17:17 -050055 state.outputProgress(pathStr.c_str(), SkPathFillType::kWinding);
caryclark@google.com8d0a5242013-07-16 16:11:16 +000056 }
caryclark8f186432016-10-06 11:46:25 -070057 testSimplify(path, false, out, state, pathStr.c_str());
Mike Reed7d34dc72019-11-26 12:17:17 -050058 path.setFillType(SkPathFillType::kEvenOdd);
caryclark8f186432016-10-06 11:46:25 -070059 if (state.fReporter->verbose()) {
Mike Reed7d34dc72019-11-26 12:17:17 -050060 state.outputProgress(pathStr.c_str(), SkPathFillType::kEvenOdd);
caryclark@google.com8d0a5242013-07-16 16:11:16 +000061 }
caryclark8f186432016-10-06 11:46:25 -070062 testSimplify(path, true, out, state, pathStr.c_str());
caryclark@google.com818b0cc2013-04-08 11:50:46 +000063 }
64 }
caryclark@google.com66089e42013-04-10 15:55:37 +000065 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000066}
67
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +000068DEF_TEST(PathOpsSimplifyTrianglesThreaded, reporter) {
mtklein406654b2014-09-03 15:34:37 -070069 initializeTests(reporter, "testTriangles");
70 PathOpsThreadedTestRunner testRunner(reporter);
caryclark@google.com818b0cc2013-04-08 11:50:46 +000071 for (int a = 0; a < 15; ++a) {
72 int ax = a & 0x03;
73 int ay = a >> 2;
74 for (int b = a + 1; b < 16; ++b) {
75 int bx = b & 0x03;
76 int by = b >> 2;
77 for (int c = a + 1; c < 16; ++c) {
78 if (b == c) {
79 continue;
80 }
81 int cx = c & 0x03;
82 int cy = c >> 2;
83 if ((bx - ax) * (cy - ay) == (by - ay) * (cx - ax)) {
84 continue;
85 }
halcanary385fe4d2015-08-26 13:07:48 -070086 *testRunner.fRunnables.append() = new PathOpsThreadedRunnable(
87 &testSimplifyTrianglesMain, a, b, c, 0, &testRunner);
caryclark@google.com818b0cc2013-04-08 11:50:46 +000088 }
caryclark@google.com66089e42013-04-10 15:55:37 +000089 if (!reporter->allowExtendedTest()) goto finish;
caryclark@google.com818b0cc2013-04-08 11:50:46 +000090 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000091 }
92finish:
caryclark@google.com66089e42013-04-10 15:55:37 +000093 testRunner.render();
caryclark@google.com818b0cc2013-04-08 11:50:46 +000094}