Home | History | Annotate | Download | only in tests
      1 /*
      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"
      8 #include "PathOpsThreadedCommon.h"
      9 #include "SkString.h"
     10 
     11 static void testSimplifyTrianglesMain(PathOpsThreadState* data) {
     12     SkASSERT(data);
     13     PathOpsThreadState& state = *data;
     14     state.fKey = "?";
     15     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;
     30                 }
     31                 int fx = f & 0x03;
     32                 int fy = f >> 2;
     33                 if ((ex - dx) * (fy - dy) == (ey - dy) * (fx - dx)) {
     34                     continue;
     35                 }
     36                 SkString pathStr;
     37                 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();
     47                 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");
     56                     state.outputProgress(pathStr.c_str(), SkPath::kWinding_FillType);
     57                 }
     58                 ShowTestName(&state, d, e, f, 0);
     59                 testSimplify(path, false, out, state, pathStr.c_str());
     60                 path.setFillType(SkPath::kEvenOdd_FillType);
     61                 if (state.fReporter->verbose()) {
     62                     state.outputProgress(pathStr.c_str(), SkPath::kEvenOdd_FillType);
     63                 }
     64                 ShowTestName(&state, d, e, f, 1);
     65                 testSimplify(path, true, out, state, pathStr.c_str());
     66             }
     67         }
     68     }
     69 }
     70 
     71 DEF_TEST(PathOpsSimplifyTrianglesThreaded, reporter) {
     72     initializeTests(reporter, "testTriangles");
     73     PathOpsThreadedTestRunner testRunner(reporter);
     74     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                 }
     89                 *testRunner.fRunnables.append() = new PathOpsThreadedRunnable(
     90                         &testSimplifyTrianglesMain, a, b, c, 0, &testRunner);
     91             }
     92             if (!reporter->allowExtendedTest()) goto finish;
     93         }
     94     }
     95 finish:
     96     testRunner.render();
     97 }
     98