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 
     10 static void testSimplifyTrianglesMain(PathOpsThreadState* data) {
     11     SkASSERT(data);
     12     PathOpsThreadState& state = *data;
     13     char pathStr[1024];
     14     bool progress = state.fReporter->verbose(); // FIXME: break out into its own parameter?
     15     if (progress) {
     16         sk_bzero(pathStr, sizeof(pathStr));
     17     }
     18     state.fKey = "?";
     19     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;
     34                 }
     35                 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();
     50                 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                 }
     62                 ShowTestName(&state, d, e, f, 0);
     63                 testSimplify(path, false, out, state, pathStr);
     64                 path.setFillType(SkPath::kEvenOdd_FillType);
     65                 if (progress) {
     66                     outputProgress(state.fPathStr, pathStr, SkPath::kEvenOdd_FillType);
     67                 }
     68                 ShowTestName(&state, d, e, f, 1);
     69                 testSimplify(path, true, out, state, pathStr);
     70             }
     71         }
     72     }
     73 }
     74 
     75 DEF_TEST(PathOpsSimplifyTrianglesThreaded, reporter) {
     76     initializeTests(reporter, "testTriangles");
     77     PathOpsThreadedTestRunner testRunner(reporter);
     78     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                 }
     93                 *testRunner.fRunnables.append() = new PathOpsThreadedRunnable(
     94                         &testSimplifyTrianglesMain, a, b, c, 0, &testRunner);
     95             }
     96             if (!reporter->allowExtendedTest()) goto finish;
     97         }
     98     }
     99 finish:
    100     testRunner.render();
    101 }
    102