caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 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 | */ |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 7 | #include "include/core/SkString.h" |
| 8 | #include "tests/PathOpsExtendedTest.h" |
| 9 | #include "tests/PathOpsThreadedCommon.h" |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 10 | |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 11 | static void testSimplifyTrianglesMain(PathOpsThreadState* data) { |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 12 | SkASSERT(data); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 13 | PathOpsThreadState& state = *data; |
caryclark@google.com | 0361032 | 2013-04-18 15:58:21 +0000 | [diff] [blame] | 14 | state.fKey = "?"; |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 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; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 30 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 31 | int fx = f & 0x03; |
| 32 | int fy = f >> 2; |
| 33 | if ((ex - dx) * (fy - dy) == (ey - dy) * (fx - dx)) { |
| 34 | continue; |
| 35 | } |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 36 | SkString pathStr; |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 37 | SkPath path, out; |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 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(); |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 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"); |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 55 | state.outputProgress(pathStr.c_str(), SkPathFillType::kWinding); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 56 | } |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 57 | testSimplify(path, false, out, state, pathStr.c_str()); |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 58 | path.setFillType(SkPathFillType::kEvenOdd); |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 59 | if (state.fReporter->verbose()) { |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 60 | state.outputProgress(pathStr.c_str(), SkPathFillType::kEvenOdd); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 61 | } |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 62 | testSimplify(path, true, out, state, pathStr.c_str()); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 63 | } |
| 64 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 65 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 66 | } |
| 67 | |
tfarina@chromium.org | 78e7b4e | 2014-01-02 21:45:03 +0000 | [diff] [blame] | 68 | DEF_TEST(PathOpsSimplifyTrianglesThreaded, reporter) { |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 69 | initializeTests(reporter, "testTriangles"); |
| 70 | PathOpsThreadedTestRunner testRunner(reporter); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 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 | } |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 86 | *testRunner.fRunnables.append() = new PathOpsThreadedRunnable( |
| 87 | &testSimplifyTrianglesMain, a, b, c, 0, &testRunner); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 88 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 89 | if (!reporter->allowExtendedTest()) goto finish; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 90 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 91 | } |
| 92 | finish: |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 93 | testRunner.render(); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 94 | } |