blob: 372b667d9c4bd6265c7ad7995ab20ee4f0498e06 [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 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;
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();
caryclark8f186432016-10-06 11:46:25 -070047 if (state.fReporter->verbose()) {
48 pathStr.appendf(" path.moveTo(%d, %d);\n", ax, ay);
49 pathStr.appendf(" path.lineTo(%d, %d);\n", bx, by);
50 pathStr.appendf(" path.lineTo(%d, %d);\n", cx, cy);
51 pathStr.appendf(" path.close();\n");
52 pathStr.appendf(" path.moveTo(%d, %d);\n", dx, dy);
53 pathStr.appendf(" path.lineTo(%d, %d);\n", ex, ey);
54 pathStr.appendf(" path.lineTo(%d, %d);\n", fx, fy);
55 pathStr.appendf(" path.close();\n");
Mike Reedff80c2a2017-01-07 11:16:28 -050056 state.outputProgress(pathStr.c_str(), SkPath::kWinding_FillType);
caryclark@google.com8d0a5242013-07-16 16:11:16 +000057 }
caryclark@google.com03610322013-04-18 15:58:21 +000058 ShowTestName(&state, d, e, f, 0);
caryclark8f186432016-10-06 11:46:25 -070059 testSimplify(path, false, out, state, pathStr.c_str());
caryclark@google.com66089e42013-04-10 15:55:37 +000060 path.setFillType(SkPath::kEvenOdd_FillType);
caryclark8f186432016-10-06 11:46:25 -070061 if (state.fReporter->verbose()) {
Mike Reedff80c2a2017-01-07 11:16:28 -050062 state.outputProgress(pathStr.c_str(), SkPath::kEvenOdd_FillType);
caryclark@google.com8d0a5242013-07-16 16:11:16 +000063 }
caryclark@google.com03610322013-04-18 15:58:21 +000064 ShowTestName(&state, d, e, f, 1);
caryclark8f186432016-10-06 11:46:25 -070065 testSimplify(path, true, out, state, pathStr.c_str());
caryclark@google.com818b0cc2013-04-08 11:50:46 +000066 }
67 }
caryclark@google.com66089e42013-04-10 15:55:37 +000068 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000069}
70
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +000071DEF_TEST(PathOpsSimplifyTrianglesThreaded, reporter) {
mtklein406654b2014-09-03 15:34:37 -070072 initializeTests(reporter, "testTriangles");
73 PathOpsThreadedTestRunner testRunner(reporter);
caryclark@google.com818b0cc2013-04-08 11:50:46 +000074 for (int a = 0; a < 15; ++a) {
75 int ax = a & 0x03;
76 int ay = a >> 2;
77 for (int b = a + 1; b < 16; ++b) {
78 int bx = b & 0x03;
79 int by = b >> 2;
80 for (int c = a + 1; c < 16; ++c) {
81 if (b == c) {
82 continue;
83 }
84 int cx = c & 0x03;
85 int cy = c >> 2;
86 if ((bx - ax) * (cy - ay) == (by - ay) * (cx - ax)) {
87 continue;
88 }
halcanary385fe4d2015-08-26 13:07:48 -070089 *testRunner.fRunnables.append() = new PathOpsThreadedRunnable(
90 &testSimplifyTrianglesMain, a, b, c, 0, &testRunner);
caryclark@google.com818b0cc2013-04-08 11:50:46 +000091 }
caryclark@google.com66089e42013-04-10 15:55:37 +000092 if (!reporter->allowExtendedTest()) goto finish;
caryclark@google.com818b0cc2013-04-08 11:50:46 +000093 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000094 }
95finish:
caryclark@google.com66089e42013-04-10 15:55:37 +000096 testRunner.render();
caryclark@google.com818b0cc2013-04-08 11:50:46 +000097}