blob: d9bdb53fdef51fb0b9890526eaf1322b74da136d [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 }
caryclark@google.com03610322013-04-18 15:58:21 +000057 ShowTestName(&state, d, e, f, 0);
caryclark8f186432016-10-06 11:46:25 -070058 testSimplify(path, false, out, state, pathStr.c_str());
Mike Reed7d34dc72019-11-26 12:17:17 -050059 path.setFillType(SkPathFillType::kEvenOdd);
caryclark8f186432016-10-06 11:46:25 -070060 if (state.fReporter->verbose()) {
Mike Reed7d34dc72019-11-26 12:17:17 -050061 state.outputProgress(pathStr.c_str(), SkPathFillType::kEvenOdd);
caryclark@google.com8d0a5242013-07-16 16:11:16 +000062 }
caryclark@google.com03610322013-04-18 15:58:21 +000063 ShowTestName(&state, d, e, f, 1);
caryclark8f186432016-10-06 11:46:25 -070064 testSimplify(path, true, out, state, pathStr.c_str());
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(PathOpsSimplifyTrianglesThreaded, reporter) {
mtklein406654b2014-09-03 15:34:37 -070071 initializeTests(reporter, "testTriangles");
72 PathOpsThreadedTestRunner testRunner(reporter);
caryclark@google.com818b0cc2013-04-08 11:50:46 +000073 for (int a = 0; a < 15; ++a) {
74 int ax = a & 0x03;
75 int ay = a >> 2;
76 for (int b = a + 1; b < 16; ++b) {
77 int bx = b & 0x03;
78 int by = b >> 2;
79 for (int c = a + 1; c < 16; ++c) {
80 if (b == c) {
81 continue;
82 }
83 int cx = c & 0x03;
84 int cy = c >> 2;
85 if ((bx - ax) * (cy - ay) == (by - ay) * (cx - ax)) {
86 continue;
87 }
halcanary385fe4d2015-08-26 13:07:48 -070088 *testRunner.fRunnables.append() = new PathOpsThreadedRunnable(
89 &testSimplifyTrianglesMain, a, b, c, 0, &testRunner);
caryclark@google.com818b0cc2013-04-08 11:50:46 +000090 }
caryclark@google.com66089e42013-04-10 15:55:37 +000091 if (!reporter->allowExtendedTest()) goto finish;
caryclark@google.com818b0cc2013-04-08 11:50:46 +000092 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000093 }
94finish:
caryclark@google.com66089e42013-04-10 15:55:37 +000095 testRunner.render();
caryclark@google.com818b0cc2013-04-08 11:50:46 +000096}