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