blob: ee0ca2bcaab9ea02d2a224bd7f39688d4bec0a60 [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"
caryclark@google.com818b0cc2013-04-08 11:50:46 +00009
caryclark@google.com66089e42013-04-10 15:55:37 +000010static void testSimplifyTrianglesMain(PathOpsThreadState* data) {
caryclark@google.com818b0cc2013-04-08 11:50:46 +000011 SkASSERT(data);
caryclark@google.com66089e42013-04-10 15:55:37 +000012 PathOpsThreadState& state = *data;
caryclark@google.com818b0cc2013-04-08 11:50:46 +000013 char pathStr[1024];
caryclark@google.com8d0a5242013-07-16 16:11:16 +000014 bool progress = state.fReporter->verbose(); // FIXME: break out into its own parameter?
15 if (progress) {
16 sk_bzero(pathStr, sizeof(pathStr));
17 }
caryclark@google.com03610322013-04-18 15:58:21 +000018 state.fKey = "?";
caryclark@google.com66089e42013-04-10 15:55:37 +000019 int ax = state.fA & 0x03;
20 int ay = state.fA >> 2;
21 int bx = state.fB & 0x03;
22 int by = state.fB >> 2;
23 int cx = state.fC & 0x03;
24 int cy = state.fC >> 2;
25 for (int d = 0; d < 15; ++d) {
26 int dx = d & 0x03;
27 int dy = d >> 2;
28 for (int e = d + 1; e < 16; ++e) {
29 int ex = e & 0x03;
30 int ey = e >> 2;
31 for (int f = d + 1; f < 16; ++f) {
32 if (e == f) {
33 continue;
caryclark@google.com818b0cc2013-04-08 11:50:46 +000034 }
caryclark@google.com66089e42013-04-10 15:55:37 +000035 int fx = f & 0x03;
36 int fy = f >> 2;
37 if ((ex - dx) * (fy - dy) == (ey - dy) * (fx - dx)) {
38 continue;
39 }
40 SkPath path, out;
41 path.setFillType(SkPath::kWinding_FillType);
42 path.moveTo(SkIntToScalar(ax), SkIntToScalar(ay));
43 path.lineTo(SkIntToScalar(bx), SkIntToScalar(by));
44 path.lineTo(SkIntToScalar(cx), SkIntToScalar(cy));
45 path.close();
46 path.moveTo(SkIntToScalar(dx), SkIntToScalar(dy));
47 path.lineTo(SkIntToScalar(ex), SkIntToScalar(ey));
48 path.lineTo(SkIntToScalar(fx), SkIntToScalar(fy));
49 path.close();
caryclark@google.com8d0a5242013-07-16 16:11:16 +000050 if (progress) {
51 char* str = pathStr;
52 str += sprintf(str, " path.moveTo(%d, %d);\n", ax, ay);
53 str += sprintf(str, " path.lineTo(%d, %d);\n", bx, by);
54 str += sprintf(str, " path.lineTo(%d, %d);\n", cx, cy);
55 str += sprintf(str, " path.close();\n");
56 str += sprintf(str, " path.moveTo(%d, %d);\n", dx, dy);
57 str += sprintf(str, " path.lineTo(%d, %d);\n", ex, ey);
58 str += sprintf(str, " path.lineTo(%d, %d);\n", fx, fy);
59 str += sprintf(str, " path.close();\n");
60 outputProgress(state.fPathStr, pathStr, SkPath::kWinding_FillType);
61 }
caryclark@google.com03610322013-04-18 15:58:21 +000062 ShowTestName(&state, d, e, f, 0);
caryclark@google.com66089e42013-04-10 15:55:37 +000063 testSimplify(path, false, out, state, pathStr);
64 path.setFillType(SkPath::kEvenOdd_FillType);
caryclark@google.com8d0a5242013-07-16 16:11:16 +000065 if (progress) {
66 outputProgress(state.fPathStr, pathStr, SkPath::kEvenOdd_FillType);
67 }
caryclark@google.com03610322013-04-18 15:58:21 +000068 ShowTestName(&state, d, e, f, 1);
caryclark@google.com66089e42013-04-10 15:55:37 +000069 testSimplify(path, true, out, state, pathStr);
caryclark@google.com818b0cc2013-04-08 11:50:46 +000070 }
71 }
caryclark@google.com66089e42013-04-10 15:55:37 +000072 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000073}
74
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +000075DEF_TEST(PathOpsSimplifyTrianglesThreaded, reporter) {
mtklein406654b2014-09-03 15:34:37 -070076 initializeTests(reporter, "testTriangles");
77 PathOpsThreadedTestRunner testRunner(reporter);
caryclark@google.com818b0cc2013-04-08 11:50:46 +000078 for (int a = 0; a < 15; ++a) {
79 int ax = a & 0x03;
80 int ay = a >> 2;
81 for (int b = a + 1; b < 16; ++b) {
82 int bx = b & 0x03;
83 int by = b >> 2;
84 for (int c = a + 1; c < 16; ++c) {
85 if (b == c) {
86 continue;
87 }
88 int cx = c & 0x03;
89 int cy = c >> 2;
90 if ((bx - ax) * (cy - ay) == (by - ay) * (cx - ax)) {
91 continue;
92 }
caryclark@google.com66089e42013-04-10 15:55:37 +000093 *testRunner.fRunnables.append() = SkNEW_ARGS(PathOpsThreadedRunnable,
94 (&testSimplifyTrianglesMain, a, b, c, 0, &testRunner));
caryclark@google.com818b0cc2013-04-08 11:50:46 +000095 }
caryclark@google.com66089e42013-04-10 15:55:37 +000096 if (!reporter->allowExtendedTest()) goto finish;
caryclark@google.com818b0cc2013-04-08 11:50:46 +000097 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000098 }
99finish:
caryclark@google.com66089e42013-04-10 15:55:37 +0000100 testRunner.render();
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000101}