commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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" |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 9 | #include "SkString.h" |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 10 | |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 11 | static int loopNo = 17; |
| 12 | |
| 13 | static void add_point(SkString* str, SkScalar x, SkScalar y) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 14 | int asInt = SkScalarRoundToInt(x); |
| 15 | if (SkIntToScalar(asInt) == x) { |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 16 | str->appendf("%d", asInt); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 17 | } else { |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 18 | str->appendf("%1.9gf", x); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 19 | } |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 20 | str->appendf(","); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 21 | asInt = SkScalarRoundToInt(y); |
| 22 | if (SkIntToScalar(asInt) == y) { |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 23 | str->appendf("%d", asInt); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 24 | } else { |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 25 | str->appendf("%1.9gf", y); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 26 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 27 | } |
| 28 | |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 29 | static void testOpLoopsMain(PathOpsThreadState* data) { |
| 30 | #if DEBUG_SHOW_TEST_NAME |
| 31 | strncpy(DEBUG_FILENAME_STRING, "", DEBUG_FILENAME_STRING_LENGTH); |
| 32 | #endif |
| 33 | SkASSERT(data); |
| 34 | PathOpsThreadState& state = *data; |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 35 | SkString pathStr; |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 36 | for (int a = 0 ; a < 6; ++a) { |
| 37 | for (int b = a + 1 ; b < 7; ++b) { |
| 38 | for (int c = 0 ; c < 6; ++c) { |
| 39 | for (int d = c + 1 ; d < 7; ++d) { |
| 40 | // define 4 points that form two lines that often cross; one line is (a, b) (c, d) |
| 41 | SkVector v = {SkIntToScalar(a - c), SkIntToScalar(b - d)}; |
| 42 | SkPoint midA = { SkIntToScalar(a * state.fA + c * (6 - state.fA)) / 6, |
| 43 | SkIntToScalar(b * state.fA + d * (6 - state.fA)) / 6 }; |
| 44 | SkPoint midB = { SkIntToScalar(a * state.fB + c * (6 - state.fB)) / 6, |
| 45 | SkIntToScalar(b * state.fB + d * (6 - state.fB)) / 6 }; |
| 46 | SkPoint endC = { midA.fX + v.fY * state.fC / 3, |
| 47 | midA.fY + v.fX * state.fC / 3 }; |
| 48 | SkPoint endD = { midB.fX - v.fY * state.fD / 3, |
| 49 | midB.fY + v.fX * state.fD / 3 }; |
| 50 | SkPath pathA, pathB; |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 51 | pathA.moveTo(SkIntToScalar(a), SkIntToScalar(b)); |
| 52 | pathA.cubicTo(SkIntToScalar(c), SkIntToScalar(d), endC.fX, endC.fY, endD.fX, endD.fY); |
| 53 | pathA.close(); |
| 54 | pathB.moveTo(SkIntToScalar(c), SkIntToScalar(d)); |
| 55 | pathB.cubicTo(endC.fX, endC.fY, endD.fX, endD.fY, SkIntToScalar(a), SkIntToScalar(b)); |
| 56 | pathB.close(); |
| 57 | // SkDebugf("%s\n", pathStr); |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 58 | if (state.fReporter->verbose()) { |
| 59 | pathStr.printf("static void loop%d(skiatest::Reporter* reporter," |
| 60 | " const char* filename) {\n", loopNo); |
| 61 | pathStr.appendf(" SkPath path, pathB;\n"); |
| 62 | pathStr.appendf(" path.moveTo(%d,%d);\n", a, b); |
| 63 | pathStr.appendf(" path.cubicTo(%d,%d, ", c, d); |
| 64 | add_point(&pathStr, endC.fX, endC.fY); |
| 65 | pathStr.appendf(", "); |
| 66 | add_point(&pathStr, endD.fX, endD.fY); |
| 67 | pathStr.appendf(");\n"); |
| 68 | pathStr.appendf(" path.close();\n"); |
| 69 | pathStr.appendf(" pathB.moveTo(%d,%d);\n", c, d); |
| 70 | pathStr.appendf(" pathB.cubicTo("); |
| 71 | add_point(&pathStr, endC.fX, endC.fY); |
| 72 | pathStr.appendf(", "); |
| 73 | add_point(&pathStr, endD.fX, endD.fY); |
| 74 | pathStr.appendf(", %d,%d);\n", a, b); |
| 75 | pathStr.appendf(" pathB.close();\n"); |
| 76 | pathStr.appendf(" testPathOp(reporter, path, pathB, kIntersect_SkPathOp," |
| 77 | " filename);\n"); |
| 78 | pathStr.appendf("}\n"); |
Mike Reed | ff80c2a | 2017-01-07 11:16:28 -0500 | [diff] [blame^] | 79 | state.outputProgress(pathStr.c_str(), kIntersect_SkPathOp); |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 80 | } |
caryclark | 38a017b | 2015-05-13 10:13:17 -0700 | [diff] [blame] | 81 | testPathOp(state.fReporter, pathA, pathB, kIntersect_SkPathOp, "loops"); |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 82 | } |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | DEF_TEST(PathOpsOpLoopsThreaded, reporter) { |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 89 | initializeTests(reporter, "loopOp"); |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 90 | PathOpsThreadedTestRunner testRunner(reporter); |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 91 | for (int a = 0; a < 6; ++a) { // outermost |
| 92 | for (int b = a + 1; b < 7; ++b) { |
| 93 | for (int c = 0 ; c < 6; ++c) { |
| 94 | for (int d = c + 1; d < 7; ++d) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 95 | *testRunner.fRunnables.append() = |
| 96 | new PathOpsThreadedRunnable(&testOpLoopsMain, a, b, c, d, &testRunner); |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | if (!reporter->allowExtendedTest()) goto finish; |
| 100 | } |
| 101 | } |
| 102 | finish: |
| 103 | testRunner.render(); |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 104 | } |