blob: 4da43b8532f89a3b76f64cf3ee363c0315fe0285 [file] [log] [blame]
caryclark@google.com66560ca2013-04-26 19:51:16 +00001/*
2 * Copyright 2013 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 */
caryclark55888e42016-07-18 10:01:36 -07007#include "PathOpsExtendedTest.h"
caryclark@google.com66560ca2013-04-26 19:51:16 +00008#include "SkPath.h"
tfarina@chromium.org8f6884a2014-01-24 20:56:26 +00009#include "SkPathOps.h"
caryclark@google.com66560ca2013-04-26 19:51:16 +000010#include "SkPoint.h"
11#include "Test.h"
12
13static const SkPoint nonFinitePts[] = {
14 { SK_ScalarInfinity, 0 },
15 { 0, SK_ScalarInfinity },
16 { SK_ScalarInfinity, SK_ScalarInfinity },
17 { SK_ScalarNegativeInfinity, 0},
18 { 0, SK_ScalarNegativeInfinity },
19 { SK_ScalarNegativeInfinity, SK_ScalarNegativeInfinity },
20 { SK_ScalarNegativeInfinity, SK_ScalarInfinity },
21 { SK_ScalarInfinity, SK_ScalarNegativeInfinity },
22 { SK_ScalarNaN, 0 },
23 { 0, SK_ScalarNaN },
24 { SK_ScalarNaN, SK_ScalarNaN },
25};
26
27const size_t nonFinitePtsCount = sizeof(nonFinitePts) / sizeof(nonFinitePts[0]);
28
29static const SkPoint finitePts[] = {
30 { 0, 0 },
31 { SK_ScalarMax, 0 },
32 { 0, SK_ScalarMax },
33 { SK_ScalarMax, SK_ScalarMax },
34 { SK_ScalarMin, 0 },
35 { 0, SK_ScalarMin },
36 { SK_ScalarMin, SK_ScalarMin },
37};
38
39const size_t finitePtsCount = sizeof(finitePts) / sizeof(finitePts[0]);
40
caryclark@google.com570863f2013-09-16 15:55:01 +000041static void failOne(skiatest::Reporter* reporter, int index) {
42 SkPath path;
43 int i = (int) (index % nonFinitePtsCount);
44 int f = (int) (index % finitePtsCount);
45 int g = (int) ((f + 1) % finitePtsCount);
46 switch (index % 13) {
47 case 0: path.lineTo(nonFinitePts[i]); break;
48 case 1: path.quadTo(nonFinitePts[i], nonFinitePts[i]); break;
49 case 2: path.quadTo(nonFinitePts[i], finitePts[f]); break;
50 case 3: path.quadTo(finitePts[f], nonFinitePts[i]); break;
51 case 4: path.cubicTo(nonFinitePts[i], finitePts[f], finitePts[f]); break;
52 case 5: path.cubicTo(finitePts[f], nonFinitePts[i], finitePts[f]); break;
53 case 6: path.cubicTo(finitePts[f], finitePts[f], nonFinitePts[i]); break;
54 case 7: path.cubicTo(nonFinitePts[i], nonFinitePts[i], finitePts[f]); break;
55 case 8: path.cubicTo(nonFinitePts[i], finitePts[f], nonFinitePts[i]); break;
56 case 9: path.cubicTo(finitePts[f], nonFinitePts[i], nonFinitePts[i]); break;
57 case 10: path.cubicTo(nonFinitePts[i], nonFinitePts[i], nonFinitePts[i]); break;
58 case 11: path.cubicTo(nonFinitePts[i], finitePts[f], finitePts[g]); break;
59 case 12: path.moveTo(nonFinitePts[i]); break;
60 }
61 SkPath result;
62 result.setFillType(SkPath::kWinding_FillType);
63 bool success = Simplify(path, &result);
64 REPORTER_ASSERT(reporter, !success);
65 REPORTER_ASSERT(reporter, result.isEmpty());
66 REPORTER_ASSERT(reporter, result.getFillType() == SkPath::kWinding_FillType);
67 reporter->bumpTestCount();
68}
69
70static void dontFailOne(skiatest::Reporter* reporter, int index) {
71 SkPath path;
72 int f = (int) (index % finitePtsCount);
73 int g = (int) ((f + 1) % finitePtsCount);
74 switch (index % 11) {
75 case 0: path.lineTo(finitePts[f]); break;
76 case 1: path.quadTo(finitePts[f], finitePts[f]); break;
77 case 2: path.quadTo(finitePts[f], finitePts[g]); break;
78 case 3: path.quadTo(finitePts[g], finitePts[f]); break;
79 case 4: path.cubicTo(finitePts[f], finitePts[f], finitePts[f]); break;
80 case 5: path.cubicTo(finitePts[f], finitePts[f], finitePts[g]); break;
81 case 6: path.cubicTo(finitePts[f], finitePts[g], finitePts[f]); break;
82 case 7: path.cubicTo(finitePts[f], finitePts[g], finitePts[g]); break;
83 case 8: path.cubicTo(finitePts[g], finitePts[f], finitePts[f]); break;
84 case 9: path.cubicTo(finitePts[g], finitePts[f], finitePts[g]); break;
85 case 10: path.moveTo(finitePts[f]); break;
86 }
87 SkPath result;
88 result.setFillType(SkPath::kWinding_FillType);
89 bool success = Simplify(path, &result);
caryclark1049f122015-04-20 08:31:59 -070090 if (index != 17 && index != 31 && index != 38) { // cubic fails to chop in two without creating NaNs
91 REPORTER_ASSERT(reporter, success);
92 REPORTER_ASSERT(reporter, result.getFillType() != SkPath::kWinding_FillType);
93 }
caryclark@google.com570863f2013-09-16 15:55:01 +000094 reporter->bumpTestCount();
95}
96
caryclark55888e42016-07-18 10:01:36 -070097static void fuzz_59(skiatest::Reporter* reporter, const char* filename) {
98 SkPath path;
99 path.moveTo(SkBits2Float(0x430c0000), SkBits2Float(0xce58f41c)); // 140, -9.09969e+08f
100 path.lineTo(SkBits2Float(0x43480000), SkBits2Float(0xce58f419)); // 200, -9.09969e+08f
101 path.lineTo(SkBits2Float(0x42200000), SkBits2Float(0xce58f41b)); // 40, -9.09969e+08f
102 path.lineTo(SkBits2Float(0x43700000), SkBits2Float(0xce58f41b)); // 240, -9.09969e+08f
103 path.lineTo(SkBits2Float(0x428c0000), SkBits2Float(0xce58f419)); // 70, -9.09969e+08f
104 path.lineTo(SkBits2Float(0x430c0000), SkBits2Float(0xce58f41c)); // 140, -9.09969e+08f
105 path.close();
caryclark30b9fdd2016-08-31 14:36:29 -0700106 testSimplifyFuzz(reporter, path, filename);
caryclark55888e42016-07-18 10:01:36 -0700107}
108
109static void fuzz_x1(skiatest::Reporter* reporter, const char* filename) {
110 SkPath path;
111path.moveTo(SkBits2Float(0x00000000), SkBits2Float(0x00000000)); // 0, 0
112path.cubicTo(SkBits2Float(0x1931204a), SkBits2Float(0x2ba1a14a), SkBits2Float(0x4a4a08ff), SkBits2Float(0x4a4a08ff), SkBits2Float(0x4a4a4a34), SkBits2Float(0x4a4a4a4a)); // 9.15721e-24f, 1.14845e-12f, 3.31014e+06f, 3.31014e+06f, 3.31432e+06f, 3.31432e+06f
113path.moveTo(SkBits2Float(0x000010a1), SkBits2Float(0x19312000)); // 5.96533e-42f, 9.15715e-24f
114path.cubicTo(SkBits2Float(0x4a6a4a4a), SkBits2Float(0x4a4a4a4a), SkBits2Float(0xa14a4a4a), SkBits2Float(0x08ff2ba1), SkBits2Float(0x08ff4a4a), SkBits2Float(0x4a344a4a)); // 3.83861e+06f, 3.31432e+06f, -6.85386e-19f, 1.53575e-33f, 1.53647e-33f, 2.95387e+06f
115path.cubicTo(SkBits2Float(0x4a4a4a4a), SkBits2Float(0x4a4a4a4a), SkBits2Float(0x2ba1a14a), SkBits2Float(0x4e4a08ff), SkBits2Float(0x4a4a4a4a), SkBits2Float(0xa1a181ff)); // 3.31432e+06f, 3.31432e+06f, 1.14845e-12f, 8.47397e+08f, 3.31432e+06f, -1.09442e-18f
116 testSimplify(reporter, path, filename);
117}
118
119static void fuzz_x2(skiatest::Reporter* reporter, const char* filename) {
120 SkPath path;
121path.moveTo(SkBits2Float(0x00000000), SkBits2Float(0x00000000)); // 0, 0
122path.cubicTo(SkBits2Float(0x1931204a), SkBits2Float(0x2ba1a14a), SkBits2Float(0x4a4a08ff), SkBits2Float(0x4a4a08ff), SkBits2Float(0x4a4a4a34), SkBits2Float(0x4a4a4a4a)); // 9.15721e-24f, 1.14845e-12f, 3.31014e+06f, 3.31014e+06f, 3.31432e+06f, 3.31432e+06f
123path.moveTo(SkBits2Float(0x000010a1), SkBits2Float(0x19312000)); // 5.96533e-42f, 9.15715e-24f
124path.cubicTo(SkBits2Float(0x4a6a4a4a), SkBits2Float(0x4a4a4a4a), SkBits2Float(0xa14a4a4a), SkBits2Float(0x08ff2ba1), SkBits2Float(0x08ff4a4a), SkBits2Float(0x4a344a4a)); // 3.83861e+06f, 3.31432e+06f, -6.85386e-19f, 1.53575e-33f, 1.53647e-33f, 2.95387e+06f
125path.cubicTo(SkBits2Float(0x4a4a4a4a), SkBits2Float(0x4a4a4a4a), SkBits2Float(0x2ba1a14a), SkBits2Float(0x4e4a08ff), SkBits2Float(0x4a4a4a4a), SkBits2Float(0xa1a181ff)); // 3.31432e+06f, 3.31432e+06f, 1.14845e-12f, 8.47397e+08f, 3.31432e+06f, -1.09442e-18f
126 testSimplify(reporter, path, filename);
127}
128
caryclark8ccc0752016-08-17 06:14:06 -0700129static void fuzz763_1(skiatest::Reporter* reporter, const char* filename) {
130 SkPath path;
131 path.setFillType((SkPath::FillType) 0);
132path.moveTo(SkBits2Float(0x00000000), SkBits2Float(0x00000000)); // 0, 0
133path.cubicTo(SkBits2Float(0xbcb63000), SkBits2Float(0xb6b6b6b7), SkBits2Float(0x38b6b6b6), SkBits2Float(0xafb63a5a), SkBits2Float(0xca000087), SkBits2Float(0xe93ae9e9)); // -0.0222397f, -5.44529e-06f, 8.71247e-05f, -3.31471e-10f, -2.09719e+06f, -1.41228e+25f
134path.quadTo(SkBits2Float(0xb6007fb6), SkBits2Float(0xb69fb6b6), SkBits2Float(0xe9e964b6), SkBits2Float(0xe9e9e9e9)); // -1.91478e-06f, -4.75984e-06f, -3.52694e+25f, -3.5348e+25f
135path.quadTo(SkBits2Float(0xb6b6b8b7), SkBits2Float(0xb60000b6), SkBits2Float(0xb6b6b6b6), SkBits2Float(0xe9e92064)); // -5.44553e-06f, -1.90739e-06f, -5.44529e-06f, -3.52291e+25f
136path.quadTo(SkBits2Float(0x000200e9), SkBits2Float(0xe9e9d100), SkBits2Float(0xe93ae9e9), SkBits2Float(0xe964b6e9)); // 1.83997e-40f, -3.53333e+25f, -1.41228e+25f, -1.72812e+25f
137path.quadTo(SkBits2Float(0x40b6e9e9), SkBits2Float(0xe9b60000), SkBits2Float(0x00b6b8e9), SkBits2Float(0xe9000001)); // 5.71605f, -2.75031e+25f, 1.67804e-38f, -9.67141e+24f
138path.quadTo(SkBits2Float(0xe9d3b6b2), SkBits2Float(0x40404540), SkBits2Float(0x803d4043), SkBits2Float(0xe9e9e9ff)); // -3.19933e+25f, 3.00423f, -5.62502e-39f, -3.53481e+25f
139path.cubicTo(SkBits2Float(0x00000000), SkBits2Float(0xe8b3b6b6), SkBits2Float(0xe90a0003), SkBits2Float(0x4040403c), SkBits2Float(0x803d4040), SkBits2Float(0xe9e80900)); // 0, -6.78939e+24f, -1.0427e+25f, 3.00392f, -5.62501e-39f, -3.50642e+25f
140path.quadTo(SkBits2Float(0xe9e910e9), SkBits2Float(0xe9e93ae9), SkBits2Float(0x0000b6b6), SkBits2Float(0xb6b6aab6)); // -3.52199e+25f, -3.52447e+25f, 6.55443e-41f, -5.4439e-06f
141path.moveTo(SkBits2Float(0xe9e92064), SkBits2Float(0xe9e9d106)); // -3.52291e+25f, -3.53334e+25f
142path.quadTo(SkBits2Float(0xe9e93ae9), SkBits2Float(0x0000abb6), SkBits2Float(0xb6b6bdb6), SkBits2Float(0xe92064b6)); // -3.52447e+25f, 6.15983e-41f, -5.44611e-06f, -1.2119e+25f
143path.quadTo(SkBits2Float(0x0000e9e9), SkBits2Float(0xb6b6b6e9), SkBits2Float(0x05ffff05), SkBits2Float(0xe9ea06e9)); // 8.39112e-41f, -5.44532e-06f, 2.40738e-35f, -3.53652e+25f
144path.quadTo(SkBits2Float(0xe93ae9e9), SkBits2Float(0x02007fe9), SkBits2Float(0xb8b7b600), SkBits2Float(0xe9e9b6b6)); // -1.41228e+25f, 9.44066e-38f, -8.76002e-05f, -3.53178e+25f
145path.quadTo(SkBits2Float(0xe9e9e9b6), SkBits2Float(0xedb6b6b6), SkBits2Float(0x5a38a1b6), SkBits2Float(0xe93ae9e9)); // -3.53479e+25f, -7.06839e+27f, 1.29923e+16f, -1.41228e+25f
146path.quadTo(SkBits2Float(0x0000b6b6), SkBits2Float(0xb6b6b6b6), SkBits2Float(0xe9e9e9b6), SkBits2Float(0xe9e9e954)); // 6.55443e-41f, -5.44529e-06f, -3.53479e+25f, -3.53477e+25f
147path.quadTo(SkBits2Float(0xb6e9e93a), SkBits2Float(0x375837ff), SkBits2Float(0xceb6b6b6), SkBits2Float(0x0039e94f)); // -6.97109e-06f, 1.28876e-05f, -1.53271e+09f, 5.31832e-39f
148path.quadTo(SkBits2Float(0xe9e9e9e9), SkBits2Float(0xe9e6e9e9), SkBits2Float(0xb6b641b6), SkBits2Float(0xede9e9e9)); // -3.5348e+25f, -3.48947e+25f, -5.43167e-06f, -9.0491e+27f
149path.moveTo(SkBits2Float(0xb6b6e9e9), SkBits2Float(0xb6b60000)); // -5.45125e-06f, -5.42402e-06f
150path.moveTo(SkBits2Float(0xe9b6b6b6), SkBits2Float(0xe9b6b8e9)); // -2.76109e+25f, -2.76122e+25f
151path.close();
152path.moveTo(SkBits2Float(0xe9b6b6b6), SkBits2Float(0xe9b6b8e9)); // -2.76109e+25f, -2.76122e+25f
153path.quadTo(SkBits2Float(0xe93ae9e9), SkBits2Float(0xe964b6e9), SkBits2Float(0x0000203a), SkBits2Float(0xb6000000)); // -1.41228e+25f, -1.72812e+25f, 1.15607e-41f, -1.90735e-06f
154path.moveTo(SkBits2Float(0x64b6b6b6), SkBits2Float(0xe9e9e900)); // 2.69638e+22f, -3.53475e+25f
155path.quadTo(SkBits2Float(0xb6b6b6e9), SkBits2Float(0xb6b6b6b6), SkBits2Float(0xe9e9b6ce), SkBits2Float(0xe9e93ae9)); // -5.44532e-06f, -5.44529e-06f, -3.53179e+25f, -3.52447e+25f
156
157 testSimplify(reporter, path, filename);
158}
159
160
caryclark55888e42016-07-18 10:01:36 -0700161#define TEST(test) test(reporter, #test)
162
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +0000163DEF_TEST(PathOpsSimplifyFail, reporter) {
caryclark8ccc0752016-08-17 06:14:06 -0700164 TEST(fuzz763_1),
caryclark55888e42016-07-18 10:01:36 -0700165 TEST(fuzz_x2);
166 TEST(fuzz_x1);
167 TEST(fuzz_59);
caryclark@google.com66560ca2013-04-26 19:51:16 +0000168 for (int index = 0; index < (int) (13 * nonFinitePtsCount * finitePtsCount); ++index) {
caryclark@google.com570863f2013-09-16 15:55:01 +0000169 failOne(reporter, index);
caryclark@google.come23b4a42013-04-26 20:41:24 +0000170 }
caryclark@google.com66560ca2013-04-26 19:51:16 +0000171 for (int index = 0; index < (int) (11 * finitePtsCount); ++index) {
caryclark@google.com570863f2013-09-16 15:55:01 +0000172 dontFailOne(reporter, index);
caryclark@google.com66560ca2013-04-26 19:51:16 +0000173 }
174}
175
caryclark55888e42016-07-18 10:01:36 -0700176#undef TEST
177
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +0000178DEF_TEST(PathOpsSimplifyFailOne, reporter) {
caryclark@google.com570863f2013-09-16 15:55:01 +0000179 int index = 0;
180 failOne(reporter, index);
181}
182
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +0000183DEF_TEST(PathOpsSimplifyDontFailOne, reporter) {
caryclark1049f122015-04-20 08:31:59 -0700184 int index = 17;
caryclark@google.com570863f2013-09-16 15:55:01 +0000185 dontFailOne(reporter, index);
186}