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 | */ |
| 7 | #include "PathOpsExtendedTest.h" |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 8 | #include "PathOpsThreadedCommon.h" |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 9 | #include "SkString.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 testSimplifyDegeneratesMain(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 | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 14 | int ax = state.fA & 0x03; |
| 15 | int ay = state.fA >> 2; |
| 16 | int bx = state.fB & 0x03; |
| 17 | int by = state.fB >> 2; |
| 18 | int cx = state.fC & 0x03; |
| 19 | int cy = state.fC >> 2; |
| 20 | for (int d = 0; d < 16; ++d) { |
| 21 | int dx = d & 0x03; |
| 22 | int dy = d >> 2; |
| 23 | for (int e = d ; e < 16; ++e) { |
| 24 | int ex = e & 0x03; |
| 25 | int ey = e >> 2; |
| 26 | for (int f = d ; f < 16; ++f) { |
| 27 | int fx = f & 0x03; |
| 28 | int fy = f >> 2; |
| 29 | if (state.fD && (ex - dx) * (fy - dy) |
| 30 | != (ey - dy) * (fx - dx)) { |
| 31 | continue; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 32 | } |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 33 | SkString pathStr; |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 34 | SkPath path, out; |
| 35 | path.setFillType(SkPath::kWinding_FillType); |
| 36 | path.moveTo(SkIntToScalar(ax), SkIntToScalar(ay)); |
| 37 | path.lineTo(SkIntToScalar(bx), SkIntToScalar(by)); |
| 38 | path.lineTo(SkIntToScalar(cx), SkIntToScalar(cy)); |
| 39 | path.close(); |
| 40 | path.moveTo(SkIntToScalar(dx), SkIntToScalar(dy)); |
| 41 | path.lineTo(SkIntToScalar(ex), SkIntToScalar(ey)); |
| 42 | path.lineTo(SkIntToScalar(fx), SkIntToScalar(fy)); |
| 43 | path.close(); |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 44 | if (state.fReporter->verbose()) { |
| 45 | pathStr.appendf(" path.moveTo(%d, %d);\n", ax, ay); |
| 46 | pathStr.appendf(" path.lineTo(%d, %d);\n", bx, by); |
| 47 | pathStr.appendf(" path.lineTo(%d, %d);\n", cx, cy); |
| 48 | pathStr.appendf(" path.close();\n"); |
| 49 | pathStr.appendf(" path.moveTo(%d, %d);\n", dx, dy); |
| 50 | pathStr.appendf(" path.lineTo(%d, %d);\n", ex, ey); |
| 51 | pathStr.appendf(" path.lineTo(%d, %d);\n", fx, fy); |
| 52 | pathStr.appendf(" path.close();\n"); |
Mike Reed | ff80c2a | 2017-01-07 11:16:28 -0500 | [diff] [blame] | 53 | state.outputProgress(pathStr.c_str(), SkPath::kWinding_FillType); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 54 | } |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 55 | testSimplify(path, false, out, state, pathStr.c_str()); |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 56 | path.setFillType(SkPath::kEvenOdd_FillType); |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 57 | if (state.fReporter->verbose()) { |
Mike Reed | ff80c2a | 2017-01-07 11:16:28 -0500 | [diff] [blame] | 58 | state.outputProgress(pathStr.c_str(), SkPath::kEvenOdd_FillType); |
caryclark@google.com | 8d0a524 | 2013-07-16 16:11:16 +0000 | [diff] [blame] | 59 | } |
caryclark | 8f18643 | 2016-10-06 11:46:25 -0700 | [diff] [blame] | 60 | testSimplify(path, true, out, state, pathStr.c_str()); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 61 | } |
| 62 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 63 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 64 | } |
| 65 | |
tfarina@chromium.org | 78e7b4e | 2014-01-02 21:45:03 +0000 | [diff] [blame] | 66 | DEF_TEST(PathOpsSimplifyDegeneratesThreaded, reporter) { |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 67 | initializeTests(reporter, "testDegenerates"); |
| 68 | PathOpsThreadedTestRunner testRunner(reporter); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 69 | for (int a = 0; a < 16; ++a) { |
| 70 | int ax = a & 0x03; |
| 71 | int ay = a >> 2; |
| 72 | for (int b = a ; b < 16; ++b) { |
| 73 | int bx = b & 0x03; |
| 74 | int by = b >> 2; |
| 75 | for (int c = a ; c < 16; ++c) { |
| 76 | int cx = c & 0x03; |
| 77 | int cy = c >> 2; |
| 78 | bool abcIsATriangle = (bx - ax) * (cy - ay) != (by - ay) * (cx - ax); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 79 | *testRunner.fRunnables.append() = new PathOpsThreadedRunnable( |
| 80 | &testSimplifyDegeneratesMain, a, b, c, abcIsATriangle, &testRunner); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 81 | } |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 82 | if (!reporter->allowExtendedTest()) goto finish; |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 83 | } |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 84 | } |
| 85 | finish: |
caryclark@google.com | 66089e4 | 2013-04-10 15:55:37 +0000 | [diff] [blame] | 86 | testRunner.render(); |
caryclark@google.com | 818b0cc | 2013-04-08 11:50:46 +0000 | [diff] [blame] | 87 | } |