1cb93a386Sopenharmony_ci/*
2cb93a386Sopenharmony_ci * Copyright 2012 Google Inc.
3cb93a386Sopenharmony_ci *
4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be
5cb93a386Sopenharmony_ci * found in the LICENSE file.
6cb93a386Sopenharmony_ci */
7cb93a386Sopenharmony_ci#include "include/core/SkString.h"
8cb93a386Sopenharmony_ci#include "tests/PathOpsExtendedTest.h"
9cb93a386Sopenharmony_ci#include "tests/PathOpsThreadedCommon.h"
10cb93a386Sopenharmony_ci
11cb93a386Sopenharmony_cistatic void testSimplifyDegeneratesMain(PathOpsThreadState* data) {
12cb93a386Sopenharmony_ci    SkASSERT(data);
13cb93a386Sopenharmony_ci    PathOpsThreadState& state = *data;
14cb93a386Sopenharmony_ci    int ax = state.fA & 0x03;
15cb93a386Sopenharmony_ci    int ay = state.fA >> 2;
16cb93a386Sopenharmony_ci    int bx = state.fB & 0x03;
17cb93a386Sopenharmony_ci    int by = state.fB >> 2;
18cb93a386Sopenharmony_ci    int cx = state.fC & 0x03;
19cb93a386Sopenharmony_ci    int cy = state.fC >> 2;
20cb93a386Sopenharmony_ci    for (int d = 0; d < 16; ++d) {
21cb93a386Sopenharmony_ci        int dx = d & 0x03;
22cb93a386Sopenharmony_ci        int dy = d >> 2;
23cb93a386Sopenharmony_ci        for (int e = d ; e < 16; ++e) {
24cb93a386Sopenharmony_ci            int ex = e & 0x03;
25cb93a386Sopenharmony_ci            int ey = e >> 2;
26cb93a386Sopenharmony_ci            for (int f = d ; f < 16; ++f) {
27cb93a386Sopenharmony_ci                int fx = f & 0x03;
28cb93a386Sopenharmony_ci                int fy = f >> 2;
29cb93a386Sopenharmony_ci                if (state.fD && (ex - dx) * (fy - dy)
30cb93a386Sopenharmony_ci                        != (ey - dy) * (fx - dx)) {
31cb93a386Sopenharmony_ci                    continue;
32cb93a386Sopenharmony_ci                }
33cb93a386Sopenharmony_ci                SkString pathStr;
34cb93a386Sopenharmony_ci                SkPath path, out;
35cb93a386Sopenharmony_ci                path.moveTo(SkIntToScalar(ax), SkIntToScalar(ay));
36cb93a386Sopenharmony_ci                path.lineTo(SkIntToScalar(bx), SkIntToScalar(by));
37cb93a386Sopenharmony_ci                path.lineTo(SkIntToScalar(cx), SkIntToScalar(cy));
38cb93a386Sopenharmony_ci                path.close();
39cb93a386Sopenharmony_ci                path.moveTo(SkIntToScalar(dx), SkIntToScalar(dy));
40cb93a386Sopenharmony_ci                path.lineTo(SkIntToScalar(ex), SkIntToScalar(ey));
41cb93a386Sopenharmony_ci                path.lineTo(SkIntToScalar(fx), SkIntToScalar(fy));
42cb93a386Sopenharmony_ci                path.close();
43cb93a386Sopenharmony_ci                if (state.fReporter->verbose()) {
44cb93a386Sopenharmony_ci                    pathStr.appendf("    path.moveTo(%d, %d);\n", ax, ay);
45cb93a386Sopenharmony_ci                    pathStr.appendf("    path.lineTo(%d, %d);\n", bx, by);
46cb93a386Sopenharmony_ci                    pathStr.appendf("    path.lineTo(%d, %d);\n", cx, cy);
47cb93a386Sopenharmony_ci                    pathStr.appendf("    path.close();\n");
48cb93a386Sopenharmony_ci                    pathStr.appendf("    path.moveTo(%d, %d);\n", dx, dy);
49cb93a386Sopenharmony_ci                    pathStr.appendf("    path.lineTo(%d, %d);\n", ex, ey);
50cb93a386Sopenharmony_ci                    pathStr.appendf("    path.lineTo(%d, %d);\n", fx, fy);
51cb93a386Sopenharmony_ci                    pathStr.appendf("    path.close();\n");
52cb93a386Sopenharmony_ci                    state.outputProgress(pathStr.c_str(), SkPathFillType::kWinding);
53cb93a386Sopenharmony_ci                }
54cb93a386Sopenharmony_ci                testSimplify(path, false, out, state, pathStr.c_str());
55cb93a386Sopenharmony_ci                path.setFillType(SkPathFillType::kEvenOdd);
56cb93a386Sopenharmony_ci                if (state.fReporter->verbose()) {
57cb93a386Sopenharmony_ci                    state.outputProgress(pathStr.c_str(), SkPathFillType::kEvenOdd);
58cb93a386Sopenharmony_ci                }
59cb93a386Sopenharmony_ci                testSimplify(path, true, out, state, pathStr.c_str());
60cb93a386Sopenharmony_ci            }
61cb93a386Sopenharmony_ci        }
62cb93a386Sopenharmony_ci    }
63cb93a386Sopenharmony_ci}
64cb93a386Sopenharmony_ci
65cb93a386Sopenharmony_ciDEF_TEST(PathOpsSimplifyDegeneratesThreaded, reporter) {
66cb93a386Sopenharmony_ci    initializeTests(reporter, "testDegenerates");
67cb93a386Sopenharmony_ci    PathOpsThreadedTestRunner testRunner(reporter);
68cb93a386Sopenharmony_ci    for (int a = 0; a < 16; ++a) {
69cb93a386Sopenharmony_ci        int ax = a & 0x03;
70cb93a386Sopenharmony_ci        int ay = a >> 2;
71cb93a386Sopenharmony_ci        for (int b = a ; b < 16; ++b) {
72cb93a386Sopenharmony_ci            int bx = b & 0x03;
73cb93a386Sopenharmony_ci            int by = b >> 2;
74cb93a386Sopenharmony_ci            for (int c = a ; c < 16; ++c) {
75cb93a386Sopenharmony_ci                int cx = c & 0x03;
76cb93a386Sopenharmony_ci                int cy = c >> 2;
77cb93a386Sopenharmony_ci                bool abcIsATriangle = (bx - ax) * (cy - ay) != (by - ay) * (cx - ax);
78cb93a386Sopenharmony_ci                *testRunner.fRunnables.append() = new PathOpsThreadedRunnable(
79cb93a386Sopenharmony_ci                        &testSimplifyDegeneratesMain, a, b, c, abcIsATriangle, &testRunner);
80cb93a386Sopenharmony_ci            }
81cb93a386Sopenharmony_ci            if (!reporter->allowExtendedTest()) goto finish;
82cb93a386Sopenharmony_ci        }
83cb93a386Sopenharmony_ci    }
84cb93a386Sopenharmony_cifinish:
85cb93a386Sopenharmony_ci    testRunner.render();
86cb93a386Sopenharmony_ci}
87