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 "include/core/SkString.h" 8#include "tests/PathOpsExtendedTest.h" 9#include "tests/PathOpsThreadedCommon.h" 10 11static 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.moveTo(SkIntToScalar(ax), SkIntToScalar(ay)); 39 path.lineTo(SkIntToScalar(bx), SkIntToScalar(by)); 40 path.lineTo(SkIntToScalar(cx), SkIntToScalar(cy)); 41 path.close(); 42 path.moveTo(SkIntToScalar(dx), SkIntToScalar(dy)); 43 path.lineTo(SkIntToScalar(ex), SkIntToScalar(ey)); 44 path.lineTo(SkIntToScalar(fx), SkIntToScalar(fy)); 45 path.close(); 46 if (state.fReporter->verbose()) { 47 pathStr.appendf(" path.moveTo(%d, %d);\n", ax, ay); 48 pathStr.appendf(" path.lineTo(%d, %d);\n", bx, by); 49 pathStr.appendf(" path.lineTo(%d, %d);\n", cx, cy); 50 pathStr.appendf(" path.close();\n"); 51 pathStr.appendf(" path.moveTo(%d, %d);\n", dx, dy); 52 pathStr.appendf(" path.lineTo(%d, %d);\n", ex, ey); 53 pathStr.appendf(" path.lineTo(%d, %d);\n", fx, fy); 54 pathStr.appendf(" path.close();\n"); 55 state.outputProgress(pathStr.c_str(), SkPathFillType::kWinding); 56 } 57 testSimplify(path, false, out, state, pathStr.c_str()); 58 path.setFillType(SkPathFillType::kEvenOdd); 59 if (state.fReporter->verbose()) { 60 state.outputProgress(pathStr.c_str(), SkPathFillType::kEvenOdd); 61 } 62 testSimplify(path, true, out, state, pathStr.c_str()); 63 } 64 } 65 } 66} 67 68DEF_TEST(PathOpsSimplifyTrianglesThreaded, reporter) { 69 initializeTests(reporter, "testTriangles"); 70 PathOpsThreadedTestRunner testRunner(reporter); 71 for (int a = 0; a < 15; ++a) { 72 int ax = a & 0x03; 73 int ay = a >> 2; 74 for (int b = a + 1; b < 16; ++b) { 75 int bx = b & 0x03; 76 int by = b >> 2; 77 for (int c = a + 1; c < 16; ++c) { 78 if (b == c) { 79 continue; 80 } 81 int cx = c & 0x03; 82 int cy = c >> 2; 83 if ((bx - ax) * (cy - ay) == (by - ay) * (cx - ax)) { 84 continue; 85 } 86 *testRunner.fRunnables.append() = new PathOpsThreadedRunnable( 87 &testSimplifyTrianglesMain, a, b, c, 0, &testRunner); 88 } 89 if (!reporter->allowExtendedTest()) goto finish; 90 } 91 } 92finish: 93 testRunner.render(); 94} 95