2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
7 #include "PathOpsExtendedTest.h"
8 #include "PathOpsThreadedCommon.h"
10 static void testOpLoopsMain(PathOpsThreadState* data) {
11 #if DEBUG_SHOW_TEST_NAME
12 strncpy(DEBUG_FILENAME_STRING, "", DEBUG_FILENAME_STRING_LENGTH);
15 PathOpsThreadState& state = *data;
16 char pathStr[1024]; // gdb: set print elements 400
17 bool progress = state.fReporter->verbose(); // FIXME: break out into its own parameter?
19 sk_bzero(pathStr, sizeof(pathStr));
21 for (int a = 0 ; a < 6; ++a) {
22 for (int b = a + 1 ; b < 7; ++b) {
23 for (int c = 0 ; c < 6; ++c) {
24 for (int d = c + 1 ; d < 7; ++d) {
25 // define 4 points that form two lines that often cross; one line is (a, b) (c, d)
26 SkVector v = {SkIntToScalar(a - c), SkIntToScalar(b - d)};
27 SkPoint midA = { SkIntToScalar(a * state.fA + c * (6 - state.fA)) / 6,
28 SkIntToScalar(b * state.fA + d * (6 - state.fA)) / 6 };
29 SkPoint midB = { SkIntToScalar(a * state.fB + c * (6 - state.fB)) / 6,
30 SkIntToScalar(b * state.fB + d * (6 - state.fB)) / 6 };
31 SkPoint endC = { midA.fX + v.fY * state.fC / 3,
32 midA.fY + v.fX * state.fC / 3 };
33 SkPoint endD = { midB.fX - v.fY * state.fD / 3,
34 midB.fY + v.fX * state.fD / 3 };
38 str += sprintf(str, " path.moveTo(%d,%d);\n", a, b);
39 str += sprintf(str, " path.cubicTo(%d,%d, %1.9gf,%1.9gf, %1.9gf,%1.9gf);\n",
40 c, d, endC.fX, endC.fY, endD.fX, endD.fY);
41 str += sprintf(str, " path.close();\n");
42 str += sprintf(str, " pathB.moveTo(%d,%d);\n", c, d);
43 str += sprintf(str, " pathB.cubicTo(%1.9gf,%1.9gf, %1.9gf,%1.9gf, %d,%d);\n",
44 endC.fX, endC.fY, endD.fX, endD.fY, a, b);
45 str += sprintf(str, " pathB.close();\n");
47 pathA.moveTo(SkIntToScalar(a), SkIntToScalar(b));
48 pathA.cubicTo(SkIntToScalar(c), SkIntToScalar(d), endC.fX, endC.fY, endD.fX, endD.fY);
50 pathB.moveTo(SkIntToScalar(c), SkIntToScalar(d));
51 pathB.cubicTo(endC.fX, endC.fY, endD.fX, endD.fY, SkIntToScalar(a), SkIntToScalar(b));
53 // SkDebugf("%s\n", pathStr);
55 outputProgress(state.fPathStr, pathStr, kIntersect_PathOp);
57 testThreadedPathOp(state.fReporter, pathA, pathB, kIntersect_PathOp, "loops");
64 DEF_TEST(PathOpsOpLoopsThreaded, reporter) {
68 initializeTests(reporter, "cubicOp");
69 PathOpsThreadedTestRunner testRunner(reporter);
70 for (int a = 0; a < 6; ++a) { // outermost
71 for (int b = a + 1; b < 7; ++b) {
72 for (int c = 0 ; c < 6; ++c) {
73 for (int d = c + 1; d < 7; ++d) {
74 *testRunner.fRunnables.append() = SkNEW_ARGS(PathOpsThreadedRunnable,
75 (&testOpLoopsMain, a, b, c, d, &testRunner));
78 if (!reporter->allowExtendedTest()) goto finish;
86 DEF_TEST(PathOpsOpLoops, reporter) {
90 initializeTests(reporter, "cubicOp");
91 PathOpsThreadState state;
92 state.fReporter = reporter;
94 state.fBitmap = &bitmap;
95 char pathStr[PATH_STR_SIZE];
96 state.fPathStr = pathStr;
97 for (state.fA = 0; state.fA < 6; ++state.fA) { // outermost
98 for (state.fB = state.fA + 1; state.fB < 7; ++state.fB) {
99 for (state.fC = 0 ; state.fC < 6; ++state.fC) {
100 for (state.fD = state.fC + 1; state.fD < 7; ++state.fD) {
101 testOpLoopsMain(&state);
104 if (!reporter->allowExtendedTest()) goto finish;