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 testSimplifyTrianglesMain(PathOpsThreadState* data) { 12cb93a386Sopenharmony_ci SkASSERT(data); 13cb93a386Sopenharmony_ci PathOpsThreadState& state = *data; 14cb93a386Sopenharmony_ci state.fKey = "?"; 15cb93a386Sopenharmony_ci int ax = state.fA & 0x03; 16cb93a386Sopenharmony_ci int ay = state.fA >> 2; 17cb93a386Sopenharmony_ci int bx = state.fB & 0x03; 18cb93a386Sopenharmony_ci int by = state.fB >> 2; 19cb93a386Sopenharmony_ci int cx = state.fC & 0x03; 20cb93a386Sopenharmony_ci int cy = state.fC >> 2; 21cb93a386Sopenharmony_ci for (int d = 0; d < 15; ++d) { 22cb93a386Sopenharmony_ci int dx = d & 0x03; 23cb93a386Sopenharmony_ci int dy = d >> 2; 24cb93a386Sopenharmony_ci for (int e = d + 1; e < 16; ++e) { 25cb93a386Sopenharmony_ci int ex = e & 0x03; 26cb93a386Sopenharmony_ci int ey = e >> 2; 27cb93a386Sopenharmony_ci for (int f = d + 1; f < 16; ++f) { 28cb93a386Sopenharmony_ci if (e == f) { 29cb93a386Sopenharmony_ci continue; 30cb93a386Sopenharmony_ci } 31cb93a386Sopenharmony_ci int fx = f & 0x03; 32cb93a386Sopenharmony_ci int fy = f >> 2; 33cb93a386Sopenharmony_ci if ((ex - dx) * (fy - dy) == (ey - dy) * (fx - dx)) { 34cb93a386Sopenharmony_ci continue; 35cb93a386Sopenharmony_ci } 36cb93a386Sopenharmony_ci SkString pathStr; 37cb93a386Sopenharmony_ci SkPath path, out; 38cb93a386Sopenharmony_ci path.moveTo(SkIntToScalar(ax), SkIntToScalar(ay)); 39cb93a386Sopenharmony_ci path.lineTo(SkIntToScalar(bx), SkIntToScalar(by)); 40cb93a386Sopenharmony_ci path.lineTo(SkIntToScalar(cx), SkIntToScalar(cy)); 41cb93a386Sopenharmony_ci path.close(); 42cb93a386Sopenharmony_ci path.moveTo(SkIntToScalar(dx), SkIntToScalar(dy)); 43cb93a386Sopenharmony_ci path.lineTo(SkIntToScalar(ex), SkIntToScalar(ey)); 44cb93a386Sopenharmony_ci path.lineTo(SkIntToScalar(fx), SkIntToScalar(fy)); 45cb93a386Sopenharmony_ci path.close(); 46cb93a386Sopenharmony_ci if (state.fReporter->verbose()) { 47cb93a386Sopenharmony_ci pathStr.appendf(" path.moveTo(%d, %d);\n", ax, ay); 48cb93a386Sopenharmony_ci pathStr.appendf(" path.lineTo(%d, %d);\n", bx, by); 49cb93a386Sopenharmony_ci pathStr.appendf(" path.lineTo(%d, %d);\n", cx, cy); 50cb93a386Sopenharmony_ci pathStr.appendf(" path.close();\n"); 51cb93a386Sopenharmony_ci pathStr.appendf(" path.moveTo(%d, %d);\n", dx, dy); 52cb93a386Sopenharmony_ci pathStr.appendf(" path.lineTo(%d, %d);\n", ex, ey); 53cb93a386Sopenharmony_ci pathStr.appendf(" path.lineTo(%d, %d);\n", fx, fy); 54cb93a386Sopenharmony_ci pathStr.appendf(" path.close();\n"); 55cb93a386Sopenharmony_ci state.outputProgress(pathStr.c_str(), SkPathFillType::kWinding); 56cb93a386Sopenharmony_ci } 57cb93a386Sopenharmony_ci testSimplify(path, false, out, state, pathStr.c_str()); 58cb93a386Sopenharmony_ci path.setFillType(SkPathFillType::kEvenOdd); 59cb93a386Sopenharmony_ci if (state.fReporter->verbose()) { 60cb93a386Sopenharmony_ci state.outputProgress(pathStr.c_str(), SkPathFillType::kEvenOdd); 61cb93a386Sopenharmony_ci } 62cb93a386Sopenharmony_ci testSimplify(path, true, out, state, pathStr.c_str()); 63cb93a386Sopenharmony_ci } 64cb93a386Sopenharmony_ci } 65cb93a386Sopenharmony_ci } 66cb93a386Sopenharmony_ci} 67cb93a386Sopenharmony_ci 68cb93a386Sopenharmony_ciDEF_TEST(PathOpsSimplifyTrianglesThreaded, reporter) { 69cb93a386Sopenharmony_ci initializeTests(reporter, "testTriangles"); 70cb93a386Sopenharmony_ci PathOpsThreadedTestRunner testRunner(reporter); 71cb93a386Sopenharmony_ci for (int a = 0; a < 15; ++a) { 72cb93a386Sopenharmony_ci int ax = a & 0x03; 73cb93a386Sopenharmony_ci int ay = a >> 2; 74cb93a386Sopenharmony_ci for (int b = a + 1; b < 16; ++b) { 75cb93a386Sopenharmony_ci int bx = b & 0x03; 76cb93a386Sopenharmony_ci int by = b >> 2; 77cb93a386Sopenharmony_ci for (int c = a + 1; c < 16; ++c) { 78cb93a386Sopenharmony_ci if (b == c) { 79cb93a386Sopenharmony_ci continue; 80cb93a386Sopenharmony_ci } 81cb93a386Sopenharmony_ci int cx = c & 0x03; 82cb93a386Sopenharmony_ci int cy = c >> 2; 83cb93a386Sopenharmony_ci if ((bx - ax) * (cy - ay) == (by - ay) * (cx - ax)) { 84cb93a386Sopenharmony_ci continue; 85cb93a386Sopenharmony_ci } 86cb93a386Sopenharmony_ci *testRunner.fRunnables.append() = new PathOpsThreadedRunnable( 87cb93a386Sopenharmony_ci &testSimplifyTrianglesMain, a, b, c, 0, &testRunner); 88cb93a386Sopenharmony_ci } 89cb93a386Sopenharmony_ci if (!reporter->allowExtendedTest()) goto finish; 90cb93a386Sopenharmony_ci } 91cb93a386Sopenharmony_ci } 92cb93a386Sopenharmony_cifinish: 93cb93a386Sopenharmony_ci testRunner.render(); 94cb93a386Sopenharmony_ci} 95