blob: a8feaaf10baeb56c6df8848172baabafca4df938 [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"
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +00009#include "TestClassDef.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.com818b0cc2013-04-08 11:50:46 +000014 char pathStr[1024];
caryclark@google.com8d0a5242013-07-16 16:11:16 +000015 bool progress = state.fReporter->verbose(); // FIXME: break out into its own parameter?
16 if (progress) {
17 sk_bzero(pathStr, sizeof(pathStr));
18 }
caryclark@google.com03610322013-04-18 15:58:21 +000019 state.fKey = "?";
caryclark@google.com66089e42013-04-10 15:55:37 +000020 int ax = state.fA & 0x03;
21 int ay = state.fA >> 2;
22 int bx = state.fB & 0x03;
23 int by = state.fB >> 2;
24 int cx = state.fC & 0x03;
25 int cy = state.fC >> 2;
26 for (int d = 0; d < 15; ++d) {
27 int dx = d & 0x03;
28 int dy = d >> 2;
29 for (int e = d + 1; e < 16; ++e) {
30 int ex = e & 0x03;
31 int ey = e >> 2;
32 for (int f = d + 1; f < 16; ++f) {
33 if (e == f) {
34 continue;
caryclark@google.com818b0cc2013-04-08 11:50:46 +000035 }
caryclark@google.com66089e42013-04-10 15:55:37 +000036 int fx = f & 0x03;
37 int fy = f >> 2;
38 if ((ex - dx) * (fy - dy) == (ey - dy) * (fx - dx)) {
39 continue;
40 }
41 SkPath path, out;
42 path.setFillType(SkPath::kWinding_FillType);
43 path.moveTo(SkIntToScalar(ax), SkIntToScalar(ay));
44 path.lineTo(SkIntToScalar(bx), SkIntToScalar(by));
45 path.lineTo(SkIntToScalar(cx), SkIntToScalar(cy));
46 path.close();
47 path.moveTo(SkIntToScalar(dx), SkIntToScalar(dy));
48 path.lineTo(SkIntToScalar(ex), SkIntToScalar(ey));
49 path.lineTo(SkIntToScalar(fx), SkIntToScalar(fy));
50 path.close();
caryclark@google.com8d0a5242013-07-16 16:11:16 +000051 if (progress) {
52 char* str = pathStr;
53 str += sprintf(str, " path.moveTo(%d, %d);\n", ax, ay);
54 str += sprintf(str, " path.lineTo(%d, %d);\n", bx, by);
55 str += sprintf(str, " path.lineTo(%d, %d);\n", cx, cy);
56 str += sprintf(str, " path.close();\n");
57 str += sprintf(str, " path.moveTo(%d, %d);\n", dx, dy);
58 str += sprintf(str, " path.lineTo(%d, %d);\n", ex, ey);
59 str += sprintf(str, " path.lineTo(%d, %d);\n", fx, fy);
60 str += sprintf(str, " path.close();\n");
61 outputProgress(state.fPathStr, pathStr, SkPath::kWinding_FillType);
62 }
caryclark@google.com03610322013-04-18 15:58:21 +000063 ShowTestName(&state, d, e, f, 0);
caryclark@google.com66089e42013-04-10 15:55:37 +000064 testSimplify(path, false, out, state, pathStr);
65 path.setFillType(SkPath::kEvenOdd_FillType);
caryclark@google.com8d0a5242013-07-16 16:11:16 +000066 if (progress) {
67 outputProgress(state.fPathStr, pathStr, SkPath::kEvenOdd_FillType);
68 }
caryclark@google.com03610322013-04-18 15:58:21 +000069 ShowTestName(&state, d, e, f, 1);
caryclark@google.com66089e42013-04-10 15:55:37 +000070 testSimplify(path, true, out, state, pathStr);
caryclark@google.com818b0cc2013-04-08 11:50:46 +000071 }
72 }
caryclark@google.com66089e42013-04-10 15:55:37 +000073 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000074}
75
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +000076DEF_TEST(PathOpsSimplifyTrianglesThreaded, reporter) {
caryclark@google.com16cfe402013-04-18 18:47:37 +000077 int threadCount = initializeTests(reporter, "testTriangles");
caryclark@google.com66089e42013-04-10 15:55:37 +000078 PathOpsThreadedTestRunner testRunner(reporter, threadCount);
caryclark@google.com818b0cc2013-04-08 11:50:46 +000079 for (int a = 0; a < 15; ++a) {
80 int ax = a & 0x03;
81 int ay = a >> 2;
82 for (int b = a + 1; b < 16; ++b) {
83 int bx = b & 0x03;
84 int by = b >> 2;
85 for (int c = a + 1; c < 16; ++c) {
86 if (b == c) {
87 continue;
88 }
89 int cx = c & 0x03;
90 int cy = c >> 2;
91 if ((bx - ax) * (cy - ay) == (by - ay) * (cx - ax)) {
92 continue;
93 }
caryclark@google.com66089e42013-04-10 15:55:37 +000094 *testRunner.fRunnables.append() = SkNEW_ARGS(PathOpsThreadedRunnable,
95 (&testSimplifyTrianglesMain, a, b, c, 0, &testRunner));
caryclark@google.com818b0cc2013-04-08 11:50:46 +000096 }
caryclark@google.com66089e42013-04-10 15:55:37 +000097 if (!reporter->allowExtendedTest()) goto finish;
caryclark@google.com818b0cc2013-04-08 11:50:46 +000098 }
caryclark@google.com818b0cc2013-04-08 11:50:46 +000099 }
100finish:
caryclark@google.com66089e42013-04-10 15:55:37 +0000101 testRunner.render();
caryclark@google.com818b0cc2013-04-08 11:50:46 +0000102}