blob: e191ecee5ec1106fdbdb2be020f80daca2641b34 [file] [log] [blame]
caryclark45fa4472015-01-16 07:04:10 -08001/*
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 */
caryclark54359292015-03-26 07:52:43 -07007
8#include "PathOpsExtendedTest.h"
caryclark45fa4472015-01-16 07:04:10 -08009#include "PathOpsTestCommon.h"
caryclark54359292015-03-26 07:52:43 -070010#include "SkBitmap.h"
caryclark45fa4472015-01-16 07:04:10 -080011#include "Test.h"
12
13DEF_TEST(PathOpsBuilder, reporter) {
14 SkOpBuilder builder;
15 SkPath result;
16 REPORTER_ASSERT(reporter, builder.resolve(&result));
17 REPORTER_ASSERT(reporter, result.isEmpty());
18
caryclark54359292015-03-26 07:52:43 -070019 builder.add(result, kDifference_SkPathOp);
caryclark45fa4472015-01-16 07:04:10 -080020 REPORTER_ASSERT(reporter, builder.resolve(&result));
21 REPORTER_ASSERT(reporter, result.isEmpty());
22
caryclark54359292015-03-26 07:52:43 -070023 builder.add(result, kUnion_SkPathOp);
caryclark45fa4472015-01-16 07:04:10 -080024 REPORTER_ASSERT(reporter, builder.resolve(&result));
25 REPORTER_ASSERT(reporter, result.isEmpty());
26
27 SkPath rectPath;
caryclark54359292015-03-26 07:52:43 -070028 rectPath.setFillType(SkPath::kEvenOdd_FillType);
caryclark45fa4472015-01-16 07:04:10 -080029 rectPath.addRect(0, 1, 2, 3, SkPath::kCW_Direction);
caryclark54359292015-03-26 07:52:43 -070030 builder.add(rectPath, kUnion_SkPathOp);
caryclark45fa4472015-01-16 07:04:10 -080031 REPORTER_ASSERT(reporter, builder.resolve(&result));
32 bool closed;
33 SkPath::Direction dir;
halcanary96fcdcc2015-08-27 07:41:13 -070034 REPORTER_ASSERT(reporter, result.isRect(nullptr, &closed, &dir));
caryclark45fa4472015-01-16 07:04:10 -080035 REPORTER_ASSERT(reporter, closed);
caryclark5b5ddd72015-05-18 05:12:56 -070036 REPORTER_ASSERT(reporter, dir == SkPath::kCCW_Direction);
caryclark4e1a4c92015-05-18 12:56:57 -070037 int pixelDiff = comparePaths(reporter, __FUNCTION__, rectPath, result);
caryclark5b5ddd72015-05-18 05:12:56 -070038 REPORTER_ASSERT(reporter, pixelDiff == 0);
caryclark45fa4472015-01-16 07:04:10 -080039
40 rectPath.reset();
caryclark54359292015-03-26 07:52:43 -070041 rectPath.setFillType(SkPath::kEvenOdd_FillType);
caryclark45fa4472015-01-16 07:04:10 -080042 rectPath.addRect(0, 1, 2, 3, SkPath::kCCW_Direction);
caryclark54359292015-03-26 07:52:43 -070043 builder.add(rectPath, kUnion_SkPathOp);
caryclark45fa4472015-01-16 07:04:10 -080044 REPORTER_ASSERT(reporter, builder.resolve(&result));
halcanary96fcdcc2015-08-27 07:41:13 -070045 REPORTER_ASSERT(reporter, result.isRect(nullptr, &closed, &dir));
caryclark45fa4472015-01-16 07:04:10 -080046 REPORTER_ASSERT(reporter, closed);
47 REPORTER_ASSERT(reporter, dir == SkPath::kCCW_Direction);
caryclark5b5ddd72015-05-18 05:12:56 -070048 REPORTER_ASSERT(reporter, rectPath == result);
caryclark45fa4472015-01-16 07:04:10 -080049
caryclark54359292015-03-26 07:52:43 -070050 builder.add(rectPath, kDifference_SkPathOp);
caryclark45fa4472015-01-16 07:04:10 -080051 REPORTER_ASSERT(reporter, builder.resolve(&result));
52 REPORTER_ASSERT(reporter, result.isEmpty());
53
54 SkPath rect2, rect3;
55 rect2.addRect(2, 1, 4, 3, SkPath::kCW_Direction);
56 rect3.addRect(4, 1, 5, 3, SkPath::kCCW_Direction);
caryclark54359292015-03-26 07:52:43 -070057 builder.add(rectPath, kUnion_SkPathOp);
58 builder.add(rect2, kUnion_SkPathOp);
59 builder.add(rect3, kUnion_SkPathOp);
caryclark45fa4472015-01-16 07:04:10 -080060 REPORTER_ASSERT(reporter, builder.resolve(&result));
halcanary96fcdcc2015-08-27 07:41:13 -070061 REPORTER_ASSERT(reporter, result.isRect(nullptr, &closed, &dir));
caryclark45fa4472015-01-16 07:04:10 -080062 REPORTER_ASSERT(reporter, closed);
63 SkRect expected;
64 expected.set(0, 1, 5, 3);
65 REPORTER_ASSERT(reporter, result.getBounds() == expected);
66
67 SkPath circle1, circle2, circle3;
68 circle1.addCircle(5, 6, 4, SkPath::kCW_Direction);
69 circle2.addCircle(7, 4, 8, SkPath::kCCW_Direction);
70 circle3.addCircle(6, 5, 6, SkPath::kCW_Direction);
71 SkPath opCompare;
caryclark54359292015-03-26 07:52:43 -070072 Op(circle1, circle2, kUnion_SkPathOp, &opCompare);
73 Op(opCompare, circle3, kDifference_SkPathOp, &opCompare);
74 builder.add(circle1, kUnion_SkPathOp);
75 builder.add(circle2, kUnion_SkPathOp);
76 builder.add(circle3, kDifference_SkPathOp);
caryclark45fa4472015-01-16 07:04:10 -080077 REPORTER_ASSERT(reporter, builder.resolve(&result));
caryclark4e1a4c92015-05-18 12:56:57 -070078 pixelDiff = comparePaths(reporter, __FUNCTION__, opCompare, result);
caryclark54359292015-03-26 07:52:43 -070079 REPORTER_ASSERT(reporter, pixelDiff == 0);
caryclark45fa4472015-01-16 07:04:10 -080080}
caryclarkfba9da72015-05-14 14:18:13 -070081
caryclark5b5ddd72015-05-18 05:12:56 -070082DEF_TEST(BuilderIssue3838, reporter) {
caryclarkfba9da72015-05-14 14:18:13 -070083 SkPath path;
84 path.moveTo(200, 170);
85 path.lineTo(220, 170);
86 path.lineTo(220, 230);
87 path.lineTo(240, 230);
88 path.lineTo(240, 210);
89 path.lineTo(180, 210);
90 path.lineTo(180, 190);
91 path.lineTo(260, 190);
92 path.lineTo(260, 250);
93 path.lineTo(200, 250);
94 path.lineTo(200, 170);
95 path.close();
caryclarkfba9da72015-05-14 14:18:13 -070096 SkPath path2;
97 SkOpBuilder builder;
98 builder.add(path, kUnion_SkPathOp);
99 builder.resolve(&path2);
caryclark4e1a4c92015-05-18 12:56:57 -0700100 int pixelDiff = comparePaths(reporter, __FUNCTION__, path, path2);
caryclarkfba9da72015-05-14 14:18:13 -0700101 REPORTER_ASSERT(reporter, pixelDiff == 0);
102}
caryclark5b5ddd72015-05-18 05:12:56 -0700103
104DEF_TEST(BuilderIssue3838_2, reporter) {
105 SkPath path;
106 path.addCircle(100, 100, 50);
107
108 SkOpBuilder builder;
109 builder.add(path, kUnion_SkPathOp);
110 builder.add(path, kUnion_SkPathOp);
111
112 SkPath result;
caryclark5b5ddd72015-05-18 05:12:56 -0700113 builder.resolve(&result);
caryclark4e1a4c92015-05-18 12:56:57 -0700114 int pixelDiff = comparePaths(reporter, __FUNCTION__, path, result);
115 REPORTER_ASSERT(reporter, pixelDiff == 0);
116}
117
118DEF_TEST(BuilderIssue3838_3, reporter) {
119 SkPath path;
120 path.moveTo(40, 10);
121 path.lineTo(60, 10);
122 path.lineTo(60, 30);
123 path.lineTo(40, 30);
124 path.lineTo(40, 10);
125 path.moveTo(41, 11);
126 path.lineTo(41, 29);
127 path.lineTo(59, 29);
128 path.lineTo(59, 11);
129 path.lineTo(41, 11);
130
131 SkOpBuilder builder;
132 builder.add(path, kUnion_SkPathOp);
133 SkPath result;
134 builder.resolve(&result);
135 int pixelDiff = comparePaths(reporter, __FUNCTION__, path, result);
caryclark5b5ddd72015-05-18 05:12:56 -0700136 REPORTER_ASSERT(reporter, pixelDiff == 0);
137}
caryclark218f21a2015-06-29 11:41:52 -0700138
139DEF_TEST(BuilderIssue502792_2, reporter) {
140 SkPath path, pathB;
141 path.setFillType(SkPath::kWinding_FillType);
142 path.addRect(0, 0, 1, 1, SkPath::kCW_Direction);
143 path.addRect(2, 2, 3, 3, SkPath::kCW_Direction);
144 pathB.setFillType(SkPath::kEvenOdd_FillType);
145 pathB.addRect(3, 3, 4, 4, SkPath::kCW_Direction);
146 pathB.addRect(3, 3, 4, 4, SkPath::kCW_Direction);
147 SkOpBuilder builder;
148 builder.add(path, kUnion_SkPathOp);
149 builder.add(pathB, kDifference_SkPathOp);
150 SkPath result;
151 builder.resolve(&result);
152}
caryclarkd4349722015-07-23 12:40:22 -0700153
154DEF_TEST(Fuzz846, reporter) {
155/*
156<clipPath id="clip-circle">
157 <circle id="circle" cx="60" cy="60" r="50" />
158</clipPath>
159<clipPath id="clip-rect">
160 <clipPath id="clip-rect">
161 <clipPath id="clip-rect">
162 <clipPath id="clip-rect">
163 <rect x="10" y="30" width="0" height="60" />
164 <rect x="10" y="30" width="0" height="60" />
165 <rect x="10" y="30" width="100" height="60" />
166 <rect x="10" y="30" width="32668" />
167 <rect x="10" y="30" width="100" height="18446744073709551615" />
168 <rect x="10" y="255" width="100" height="60" />
169 <rect width="100" height="60" />
170 <rect x="10" y="30" width="100" height="60" />
171 <rect x="10" y="30" width="100" height="4294967236" />
172 <rect x="10" y="30" width="100" height="60" />
173 </clipPath>
174 <rect x="10" y="30" width="0" height="60" />
175 <rect x="10" y="30" width="0" height="0.18093252719929986369568203" />
176 <rect x="10" y="30" width="100" height="60" />
177 <rect x="10" y="30" width="32668" height="60" />
178 <rect x="10" y="30" width="100" height="18446744073709551615" />
179 <rect x="10" y="255" width="100" height="60" />
180 <rect x="2147483649" y="30" width="100" height="60" />
181 <rect x="10" y="30" width="100" height="60" />
182 <rect x="10" y="30" width="100" height="60" />
183 <rect x="10" y="30" width="100" height="60" />
184 </clipPath>
185 <rect x="10" y="30" width="0" height="60" />
186 <rect x="10" y="30" width="0" height="60" />
187 <rect x="10" y="30" width="100" height="60" />
188 <rect x="10" y="30" width="32668" height="60" />
189 <rect x="10" y="30" width="100" height="18446744073709551615" />
190 <rect x="10" y="255" width="100" height="60" />
191 <rect x="2147483649" y="30" width="100" height="60" />
192 <rect x="10" y="30" width="100" height="60" />
193 <rect x="10" y="2879753595" width="100" height="60" />
194 <rect x="10" y="30" width="100" height="60" />
195 </clipPath>
196 <rect x="10" y="30" width="100" height="60" />
197 <rect x="10" y="30" width="0" height="60" />
198 <rect x="10" y="30" width="100" height="60" />
199 <rect x="10" y="30" width="32668" height="60" />
200 <rect x="10" y="30" width="100" height="18446744073709551615" />
201 <rect x="10" y="255" width="100" height="60" />
202 <rect x="2147483649" y="30" width="100" height="60" />
203 <rect x="10" y="30" width="100" height="60" />
204 <rect x="10" y="30" width="100" height="4294967236" />
205 <rect x="10" y="30" width="100" height="4294967236" />
206 <rect x="10" y="30" width="100" height="4294967236" />
207 <rect x="10" y="30" width="100" height="4294967236" />
208 <rect x="10" y="30" width="100" height="60" />
209 <rect x="757798030" y="30" width="100" height="60" />
210*/
211 SkPath clipCircle, clipRect;
212 SkPath inner;
213 clipCircle.addCircle(60, 60, 50); // <circle id="circle" cx="60" cy="60" r="50" />
214
215 inner.addRect(10, 30, 10+0, 30+60); // <rect x="10" y="30" width="0" height="60" />
216 inner.addRect(10, 30, 10+0, 30+60); // <rect x="10" y="30" width="0" height="60" />
217 inner.addRect(10, 30, 10+100, 30+60); // <rect x="10" y="30" width="100" height="60" />
218 inner.addRect(10, 30, 10+32668, 30+0); // <rect x="10" y="30" width="32668" />
219 inner.addRect(10, 30, 10+100, 30+18446744073709551615.f); // <rect x="10" y="30" width="100" height="18446744073709551615" />
220 inner.addRect(10, 255, 10+100, 255+60); // <rect x="10" y="255" width="100" height="60" />
221 inner.addRect(0, 0, 0+100, 0+60); // <rect width="100" height="60" />
222 inner.addRect(10, 30, 10+100, 30+60); // <rect x="10" y="30" width="100" height="60" />
223 inner.addRect(10, 30, 10+100, 30+4294967236.f); // <rect x="10" y="30" width="100" height="4294967236" />
224 inner.addRect(10, 30, 10+100, 30+60); // <rect x="10" y="30" width="100" height="60" />
225 clipRect.addPath(inner);
226 inner.reset();
227 inner.addRect(10, 30, 10+0, 30+60); // <rect x="10" y="30" width="0" height="60" />
228 inner.addRect(10, 30, 10+0, 30+0.18093252719929986369568203f); // <rect x="10" y="30" width="0" height="0.18093252719929986369568203" />
229 inner.addRect(10, 30, 10+100, 30+60); // <rect x="10" y="30" width="100" height="60" />
230 inner.addRect(10, 30, 10+32668, 30+60); // <rect x="10" y="30" width="32668" height="60" />
231 inner.addRect(10, 30, 10+100, 30+18446744073709551615.f); // <rect x="10" y="30" width="100" height="18446744073709551615" />
232 inner.addRect(10, 255, 10+100, 255+60); // <rect x="10" y="255" width="100" height="60" />
233 inner.addRect(2147483649.f, 30, 2147483649.f+100, 30+60); // <rect x="2147483649" y="30" width="100" height="60" />
234 inner.addRect(10, 30, 10+100, 30+60); // <rect x="10" y="30" width="100" height="60" />
235 inner.addRect(10, 30, 10+100, 30+60); // <rect x="10" y="30" width="100" height="60" />
236 inner.addRect(10, 30, 10+100, 30+60); // <rect x="10" y="30" width="100" height="60" />
237 clipRect.addPath(inner);
238 inner.reset();
239 inner.addRect(10, 30, 10+0, 30+60); // <rect x="10" y="30" width="0" height="60" />
240 inner.addRect(10, 30, 10+0, 30+60); // <rect x="10" y="30" width="0" height="60" />
241 inner.addRect(10, 30, 10+100, 30+60); // <rect x="10" y="30" width="100" height="60" />
242 inner.addRect(10, 30, 10+32668, 30+60); // <rect x="10" y="30" width="32668" height="60" />
243 inner.addRect(10, 30, 10+100, 30+18446744073709551615.f); // <rect x="10" y="30" width="100" height="18446744073709551615" />
244 inner.addRect(10, 255, 10+100, 255+60); // <rect x="10" y="255" width="100" height="60" />
245 inner.addRect(2147483649.f, 30, 2147483649.f+100, 30+60); // <rect x="2147483649" y="30" width="100" height="60" />
246 inner.addRect(10, 30, 10+100, 30+60); // <rect x="10" y="30" width="100" height="60" />
247 inner.addRect(10, 2879753595.f, 10+100, 30+2879753595.f); // <rect x="10" y="2879753595" width="100" height="60" />
248 inner.addRect(10, 30, 10+100, 30+60); // <rect x="10" y="30" width="100" height="60" />
249 clipRect.addPath(inner);
250 inner.reset();
251 inner.addRect(10, 30, 10+100, 30+60); // <rect x="10" y="30" width="100" height="60" />
252 inner.addRect(10, 30, 10+0, 30+60); // <rect x="10" y="30" width="0" height="60" />
253 inner.addRect(10, 30, 10+100, 30+60); // <rect x="10" y="30" width="100" height="60" />
254 inner.addRect(10, 30, 10+32668, 30+60); // <rect x="10" y="30" width="32668" height="60" />
255 inner.addRect(10, 30, 10+100, 30+18446744073709551615.f); // <rect x="10" y="30" width="100" height="18446744073709551615" />
256 inner.addRect(10, 255, 10+100, 255+60); // <rect x="10" y="255" width="100" height="60" />
257 inner.addRect(2147483649.f, 30, 2147483649.f+100, 30+60); // <rect x="2147483649" y="30" width="100" height="60" />
258 inner.addRect(10, 30, 10+100, 30+60); // <rect x="10" y="30" width="100" height="60" />
259 inner.addRect(10, 30, 10+100, 30+4294967236.f); // <rect x="10" y="30" width="100" height="4294967236" />
260 inner.addRect(10, 30, 10+100, 30+4294967236.f); // <rect x="10" y="30" width="100" height="4294967236" />
261 inner.addRect(10, 30, 10+100, 30+4294967236.f); // <rect x="10" y="30" width="100" height="4294967236" />
262 inner.addRect(10, 30, 10+100, 30+4294967236.f); // <rect x="10" y="30" width="100" height="4294967236" />
263 inner.addRect(10, 30, 10+100, 30+60); // <rect x="10" y="30" width="100" height="60" />
264 inner.addRect(757798030.f, 30, 757798030.f+100, 30+60); // <rect x="757798030" y="30" width="100" height="60" />
265 clipRect.addPath(inner);
266
267 SkOpBuilder builder;
268 builder.add(clipCircle, kUnion_SkPathOp);
269 builder.add(clipRect, kDifference_SkPathOp);
270 SkPath result;
271 builder.resolve(&result);
272}
caryclark364a0072015-12-14 08:43:21 -0800273
274DEF_TEST(Issue569540, reporter) {
275 SkPath path1;
276 path1.moveTo(5, -225);
277 path1.lineTo(-225, 7425);
278 path1.lineTo(7425, 7425);
279 path1.lineTo(7425, -225);
280 path1.lineTo(-225, -225);
281 path1.lineTo(5, -225);
282 path1.close();
283
284 SkPath path2;
285 path2.moveTo(5940, 2790);
286 path2.lineTo(5940, 2160);
287 path2.lineTo(5970, 1980);
288 path2.lineTo(5688, 773669888);
289 path2.lineTo(5688, 2160);
290 path2.lineTo(5688, 2430);
291 path2.lineTo(5400, 4590);
292 path2.lineTo(5220, 4590);
293 path2.lineTo(5220, 4920);
294 path2.cubicTo(5182.22900390625f, 4948.328125f, 5160, 4992.78662109375f, 5160, 5040.00048828125f);
295 path2.lineTo(5940, 2790);
296 path2.close();
297
298 SkOpBuilder builder;
299 builder.add(path1, kUnion_SkPathOp);
300 builder.add(path2, kUnion_SkPathOp);
301 SkPath result;
302 builder.resolve(&result);
303}