1 /*
2 * Copyright 2018 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 "src/utils/SkPolyUtils.h"
8 #include "tests/Test.h"
9
DEF_TEST(PolyUtils,reporter)10 DEF_TEST(PolyUtils, reporter) {
11
12 SkTDArray<SkPoint> poly;
13 // init simple index map
14 uint16_t indexMap[1024];
15 for (int i = 0; i < 1024; ++i) {
16 indexMap[i] = i;
17 }
18 SkTDArray<uint16_t> triangleIndices;
19
20 // skinny triangle
21 *poly.push() = SkPoint::Make(-100, 55);
22 *poly.push() = SkPoint::Make(100, 55);
23 *poly.push() = SkPoint::Make(102.5f, 54.330127f);
24 REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) < 0);
25 REPORTER_ASSERT(reporter, SkIsConvexPolygon(poly.begin(), poly.count()));
26 REPORTER_ASSERT(reporter, SkIsSimplePolygon(poly.begin(), poly.count()));
27 REPORTER_ASSERT(reporter, SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(),
28 &triangleIndices));
29
30 // switch winding
31 poly[2].set(102.5f, 55.330127f);
32 REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) > 0);
33 REPORTER_ASSERT(reporter, SkIsConvexPolygon(poly.begin(), poly.count()));
34 REPORTER_ASSERT(reporter, SkIsSimplePolygon(poly.begin(), poly.count()));
35 triangleIndices.rewind();
36 REPORTER_ASSERT(reporter, SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(),
37 &triangleIndices));
38
39 // make degenerate
40 poly[2].set(100 + 2.5f, 55);
41 REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) == 0);
42 // TODO: should these fail?
43 REPORTER_ASSERT(reporter, SkIsConvexPolygon(poly.begin(), poly.count()));
44 REPORTER_ASSERT(reporter, SkIsSimplePolygon(poly.begin(), poly.count()));
45 triangleIndices.rewind();
46 REPORTER_ASSERT(reporter, !SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(),
47 &triangleIndices));
48
49 // giant triangle
50 poly[0].set(-1.0e+37f, 1.0e+37f);
51 poly[1].set(1.0e+37f, 1.0e+37f);
52 poly[2].set(-1.0e+37f, -1.0e+37f);
53 REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) < 0);
54 REPORTER_ASSERT(reporter, SkIsConvexPolygon(poly.begin(), poly.count()));
55 REPORTER_ASSERT(reporter, SkIsSimplePolygon(poly.begin(), poly.count()));
56 triangleIndices.rewind();
57 REPORTER_ASSERT(reporter, SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(),
58 &triangleIndices));
59
60 // teeny triangle
61 poly[0].set(-1.0e-38f, 1.0e-38f);
62 poly[1].set(-1.0e-38f, -1.0e-38f);
63 poly[2].set(1.0e-38f, 1.0e-38f);
64 REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) == 0);
65 // TODO: should these fail?
66 REPORTER_ASSERT(reporter, SkIsConvexPolygon(poly.begin(), poly.count()));
67 REPORTER_ASSERT(reporter, SkIsSimplePolygon(poly.begin(), poly.count()));
68 triangleIndices.rewind();
69 REPORTER_ASSERT(reporter, !SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(),
70 &triangleIndices));
71
72 // triangle way off in space (relative to size so we don't completely obliterate values)
73 poly[0].set(-100 + 1.0e+9f, 55 - 1.0e+9f);
74 poly[1].set(100 + 1.0e+9f, 55 - 1.0e+9f);
75 poly[2].set(150 + 1.0e+9f, 100 - 1.0e+9f);
76 REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) > 0);
77 REPORTER_ASSERT(reporter, SkIsConvexPolygon(poly.begin(), poly.count()));
78 REPORTER_ASSERT(reporter, SkIsSimplePolygon(poly.begin(), poly.count()));
79 triangleIndices.rewind();
80 REPORTER_ASSERT(reporter, SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(),
81 &triangleIndices));
82
83 ///////////////////////////////////////////////////////////////////////
84 // round rect
85 poly.rewind();
86 *poly.push() = SkPoint::Make(-100, 55);
87 *poly.push() = SkPoint::Make(100, 55);
88 *poly.push() = SkPoint::Make(100 + 2.5f, 50 + 4.330127f);
89 *poly.push() = SkPoint::Make(100 + 3.535534f, 50 + 3.535534f);
90 *poly.push() = SkPoint::Make(100 + 4.330127f, 50 + 2.5f);
91 *poly.push() = SkPoint::Make(105, 50);
92 *poly.push() = SkPoint::Make(105, -50);
93 *poly.push() = SkPoint::Make(100 + 4.330127f, -50 - 2.5f);
94 *poly.push() = SkPoint::Make(100 + 3.535534f, -50 - 3.535534f);
95 *poly.push() = SkPoint::Make(100 + 2.5f, -50 - 4.330127f);
96 *poly.push() = SkPoint::Make(100, -55);
97 *poly.push() = SkPoint::Make(-100, -55);
98 *poly.push() = SkPoint::Make(-100 - 2.5f, -50 - 4.330127f);
99 *poly.push() = SkPoint::Make(-100 - 3.535534f, -50 - 3.535534f);
100 *poly.push() = SkPoint::Make(-100 - 4.330127f, -50 - 2.5f);
101 *poly.push() = SkPoint::Make(-105, -50);
102 *poly.push() = SkPoint::Make(-105, 50);
103 *poly.push() = SkPoint::Make(-100 - 4.330127f, 50 + 2.5f);
104 *poly.push() = SkPoint::Make(-100 - 3.535534f, 50 + 3.535534f);
105 *poly.push() = SkPoint::Make(-100 - 2.5f, 50 + 4.330127f);
106 REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) < 0);
107 REPORTER_ASSERT(reporter, SkIsConvexPolygon(poly.begin(), poly.count()));
108 REPORTER_ASSERT(reporter, SkIsSimplePolygon(poly.begin(), poly.count()));
109 triangleIndices.rewind();
110 REPORTER_ASSERT(reporter, SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(),
111 &triangleIndices));
112
113 // translate far enough to obliterate some low bits
114 for (int i = 0; i < poly.count(); ++i) {
115 poly[i].offset(1.0e+7f, 1.0e+7f);
116 }
117 REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) < 0);
118 // Due to floating point error it's no longer convex
119 REPORTER_ASSERT(reporter, !SkIsConvexPolygon(poly.begin(), poly.count()));
120 REPORTER_ASSERT(reporter, SkIsSimplePolygon(poly.begin(), poly.count()));
121 triangleIndices.rewind();
122 REPORTER_ASSERT(reporter, SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(),
123 &triangleIndices));
124
125 // translate a little farther to create some coincident vertices
126 for (int i = 0; i < poly.count(); ++i) {
127 poly[i].offset(4.0e+7f, 4.0e+7f);
128 }
129 REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) < 0);
130 REPORTER_ASSERT(reporter, SkIsConvexPolygon(poly.begin(), poly.count()));
131 REPORTER_ASSERT(reporter, SkIsSimplePolygon(poly.begin(), poly.count()));
132 // This can't handle coincident vertices
133 triangleIndices.rewind();
134 REPORTER_ASSERT(reporter, !SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(),
135 &triangleIndices));
136
137 // troublesome case -- clipped roundrect
138 poly.rewind();
139 *poly.push() = SkPoint::Make(335.928101f, 428.219055f);
140 *poly.push() = SkPoint::Make(330.414459f, 423.034912f);
141 *poly.push() = SkPoint::Make(325.749084f, 417.395508f);
142 *poly.push() = SkPoint::Make(321.931946f, 411.300842f);
143 *poly.push() = SkPoint::Make(318.963074f, 404.750977f);
144 *poly.push() = SkPoint::Make(316.842468f, 397.745850f);
145 *poly.push() = SkPoint::Make(315.570068f, 390.285522f);
146 *poly.push() = SkPoint::Make(315.145966f, 382.369965f);
147 *poly.push() = SkPoint::Make(315.570068f, 374.454346f);
148 *poly.push() = SkPoint::Make(316.842468f, 366.994019f);
149 *poly.push() = SkPoint::Make(318.963074f, 359.988892f);
150 *poly.push() = SkPoint::Make(321.931946f, 353.439056f);
151 *poly.push() = SkPoint::Make(325.749084f, 347.344421f);
152 *poly.push() = SkPoint::Make(330.414459f, 341.705017f);
153 *poly.push() = SkPoint::Make(335.928101f, 336.520813f);
154 *poly.push() = SkPoint::Make(342.289948f, 331.791901f);
155 *poly.push() = SkPoint::Make(377.312134f, 331.791901f);
156 *poly.push() = SkPoint::Make(381.195313f, 332.532593f);
157 *poly.push() = SkPoint::Make(384.464935f, 334.754700f);
158 *poly.push() = SkPoint::Make(386.687042f, 338.024292f);
159 *poly.push() = SkPoint::Make(387.427765f, 341.907532f);
160 *poly.push() = SkPoint::Make(387.427765f, 422.832367f);
161 *poly.push() = SkPoint::Make(386.687042f, 426.715576f);
162 *poly.push() = SkPoint::Make(384.464935f, 429.985168f);
163 *poly.push() = SkPoint::Make(381.195313f, 432.207275f);
164 *poly.push() = SkPoint::Make(377.312134f, 432.947998f);
165 *poly.push() = SkPoint::Make(342.289948f, 432.947998f);
166 REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) > 0);
167 REPORTER_ASSERT(reporter, SkIsConvexPolygon(poly.begin(), poly.count()));
168 REPORTER_ASSERT(reporter, SkIsSimplePolygon(poly.begin(), poly.count()));
169 triangleIndices.rewind();
170 REPORTER_ASSERT(reporter, SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(),
171 &triangleIndices));
172
173 // a star is born
174 poly.rewind();
175 *poly.push() = SkPoint::Make(0.0f, -50.0f);
176 *poly.push() = SkPoint::Make(14.43f, -25.0f);
177 *poly.push() = SkPoint::Make(43.30f, -25.0f);
178 *poly.push() = SkPoint::Make(28.86f, 0.0f);
179 *poly.push() = SkPoint::Make(43.30f, 25.0f);
180 *poly.push() = SkPoint::Make(14.43f, 25.0f);
181 *poly.push() = SkPoint::Make(0.0f, 50.0f);
182 *poly.push() = SkPoint::Make(-14.43f, 25.0f);
183 *poly.push() = SkPoint::Make(-43.30f, 25.0f);
184 *poly.push() = SkPoint::Make(-28.86f, 0.0f);
185 *poly.push() = SkPoint::Make(-43.30f, -25.0f);
186 *poly.push() = SkPoint::Make(-14.43f, -25.0f);
187 REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) > 0);
188 REPORTER_ASSERT(reporter, !SkIsConvexPolygon(poly.begin(), poly.count()));
189 REPORTER_ASSERT(reporter, SkIsSimplePolygon(poly.begin(), poly.count()));
190 triangleIndices.rewind();
191 REPORTER_ASSERT(reporter, SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(),
192 &triangleIndices));
193
194 // many spiked star
195 {
196 const SkScalar c = SkIntToScalar(45);
197 const SkScalar r1 = SkIntToScalar(20);
198 const SkScalar r2 = SkIntToScalar(3);
199 const int n = 500;
200 poly.rewind();
201 SkScalar rad = 0;
202 const SkScalar drad = SK_ScalarPI / n;
203 for (int i = 0; i < n; i++) {
204 *poly.push() = SkPoint::Make(c + SkScalarCos(rad) * r1, c + SkScalarSin(rad) * r1);
205 rad += drad;
206 *poly.push() = SkPoint::Make(c + SkScalarCos(rad) * r2, c + SkScalarSin(rad) * r2);
207 rad += drad;
208 }
209 REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) > 0);
210 REPORTER_ASSERT(reporter, !SkIsConvexPolygon(poly.begin(), poly.count()));
211 REPORTER_ASSERT(reporter, SkIsSimplePolygon(poly.begin(), poly.count()));
212 triangleIndices.rewind();
213 REPORTER_ASSERT(reporter, SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(),
214 &triangleIndices));
215 }
216
217 // self-intersecting polygon
218 poly.rewind();
219 *poly.push() = SkPoint::Make(0.0f, -50.0f);
220 *poly.push() = SkPoint::Make(14.43f, -25.0f);
221 *poly.push() = SkPoint::Make(43.30f, -25.0f);
222 *poly.push() = SkPoint::Make(-28.86f, 0.0f);
223 *poly.push() = SkPoint::Make(43.30f, 25.0f);
224 *poly.push() = SkPoint::Make(14.43f, 25.0f);
225 *poly.push() = SkPoint::Make(0.0f, 50.0f);
226 *poly.push() = SkPoint::Make(-14.43f, 25.0f);
227 *poly.push() = SkPoint::Make(-43.30f, 25.0f);
228 *poly.push() = SkPoint::Make(28.86f, 0.0f);
229 *poly.push() = SkPoint::Make(-43.30f, -25.0f);
230 *poly.push() = SkPoint::Make(-14.43f, -25.0f);
231 REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) > 0);
232 REPORTER_ASSERT(reporter, !SkIsConvexPolygon(poly.begin(), poly.count()));
233 REPORTER_ASSERT(reporter, !SkIsSimplePolygon(poly.begin(), poly.count()));
234 triangleIndices.rewind();
235 // running this just to make sure it doesn't crash
236 // the fact that it succeeds doesn't mean anything since the input is not simple
237 REPORTER_ASSERT(reporter, SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(),
238 &triangleIndices));
239
240 // self-intersecting polygon with coincident point
241 poly.rewind();
242 *poly.push() = SkPoint::Make(0.0f, 0.0f);
243 *poly.push() = SkPoint::Make(-50, -50);
244 *poly.push() = SkPoint::Make(50, -50);
245 *poly.push() = SkPoint::Make(0.00000001f, -0.00000001f);
246 *poly.push() = SkPoint::Make(-50, 50);
247 *poly.push() = SkPoint::Make(50, 50);
248 REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) == 0);
249 REPORTER_ASSERT(reporter, !SkIsConvexPolygon(poly.begin(), poly.count()));
250 REPORTER_ASSERT(reporter, !SkIsSimplePolygon(poly.begin(), poly.count()));
251 triangleIndices.rewind();
252 // running this just to make sure it doesn't crash
253 REPORTER_ASSERT(reporter, !SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(),
254 &triangleIndices));
255
256 // self-intersecting polygon with two equal edges
257 poly.rewind();
258 *poly.push() = SkPoint::Make(0.0f, 0.0f);
259 *poly.push() = SkPoint::Make(10, 0);
260 *poly.push() = SkPoint::Make(0, 10);
261 *poly.push() = SkPoint::Make(10, 10);
262 *poly.push() = SkPoint::Make(10, 0);
263 *poly.push() = SkPoint::Make(0, 10);
264 REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) == 0);
265 REPORTER_ASSERT(reporter, !SkIsConvexPolygon(poly.begin(), poly.count()));
266 REPORTER_ASSERT(reporter, !SkIsSimplePolygon(poly.begin(), poly.count()));
267 triangleIndices.rewind();
268 // running this just to make sure it doesn't crash
269 REPORTER_ASSERT(reporter, !SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(),
270 &triangleIndices));
271
272 // absurd self-intersecting polygon
273 poly.rewind();
274 *poly.push() = SkPoint::Make(0.0000f, 0.0000f);
275 *poly.push() = SkPoint::Make(-32768.0625f, 0.0000f);
276 *poly.push() = SkPoint::Make(0.0000f, 138.0000f);
277 *poly.push() = SkPoint::Make(3284.8125f, -10411310938997512334153865557442560.0000f);
278 *poly.push() = SkPoint::Make(-32768.7500f, 0.0000f);
279 *poly.push() = SkPoint::Make(138.0000f, 3172.8125f);
280 *poly.push() = SkPoint::Make(0.0000f, -2147485952.0000f);
281 *poly.push() = SkPoint::Make(0.0000f, 170.0000f);
282 *poly.push() = SkPoint::Make(3284.8125f, 0.0000f);
283 *poly.push() = SkPoint::Make(-32768.0625f, 0.0000f);
284 *poly.push() = SkPoint::Make(137.0000f, 4105.6875f);
285 *poly.push() = SkPoint::Make(0.0000f, -32768.0625f);
286 *poly.push() = SkPoint::Make(0.0000f, 138.0000f);
287 *poly.push() = SkPoint::Make(3283.0000f, 0.0000f);
288 *poly.push() = SkPoint::Make(-32768.0625f, 0.0000f);
289 *poly.push() = SkPoint::Make(138.0000f, 3284.8125f);
290 *poly.push() = SkPoint::Make(0.0000f, -32768.0625f);
291 *poly.push() = SkPoint::Make(0.0000f, 138.0000f);
292 *poly.push() = SkPoint::Make(3284.8125f, 0.0000f);
293 *poly.push() = SkPoint::Make(-32768.0625f, 0.0000f);
294 *poly.push() = SkPoint::Make(138.0000f, 821.1250f);
295 *poly.push() = SkPoint::Make(0.0000f, -32768.0625f);
296 *poly.push() = SkPoint::Make(0.0000f, 138.0000f);
297 *poly.push() = SkPoint::Make(3284.8125f, 0.0000f);
298 *poly.push() = SkPoint::Make(-32768.0625f, 0.0000f);
299 *poly.push() = SkPoint::Make(138.0000f, 3284.8125f);
300 *poly.push() = SkPoint::Make(0.0000f, -30897.0625f);
301 *poly.push() = SkPoint::Make(0.0000f, 138.0000f);
302 *poly.push() = SkPoint::Make(3284.8125f, 0.0000f);
303 *poly.push() = SkPoint::Make(-32768.0625f, 0.0000f);
304 *poly.push() = SkPoint::Make(138.0000f, 3284.8125f);
305 *poly.push() = SkPoint::Make(0.0000f, -32768.0625f);
306 *poly.push() = SkPoint::Make(0.0000f, 138.0000f);
307 *poly.push() = SkPoint::Make(3284.5625f, 0.0000f);
308 *poly.push() = SkPoint::Make(-32768.0625f, 0.0000f);
309 *poly.push() = SkPoint::Make(138.0000f, 3284.8125f);
310 *poly.push() = SkPoint::Make(0.0000f, -32768.0625f);
311 *poly.push() = SkPoint::Make(0.0000f, 138.0000f);
312 *poly.push() = SkPoint::Make(3526523879424.0000f, 0.0000f);
313 *poly.push() = SkPoint::Make(-32768.9375f, 0.0000f);
314 *poly.push() = SkPoint::Make(138.0000f, 3284.8125f);
315 *poly.push() = SkPoint::Make(0.0000f, -32768.0625f);
316 *poly.push() = SkPoint::Make(0.0000f, 138.0000f);
317 *poly.push() = SkPoint::Make(3284.8125f, 0.0000f);
318 *poly.push() = SkPoint::Make(-32768.0625f, 0.0000f);
319 *poly.push() = SkPoint::Make(129.0000f, 3284.8125f);
320 *poly.push() = SkPoint::Make(0.0000f, -32768.0625f);
321 *poly.push() = SkPoint::Make(0.0000f, 138.0000f);
322 *poly.push() = SkPoint::Make(3284.8125f, 0.0000f);
323 *poly.push() = SkPoint::Make(-32768.0625f, 0.0000f);
324 *poly.push() = SkPoint::Make(138.0000f, 3284.8125f);
325 *poly.push() = SkPoint::Make(0.0000f, -32768.0625f);
326 *poly.push() = SkPoint::Make(0.0000f, 859832320.0000f);
327 *poly.push() = SkPoint::Make(0.0000f, 0.0000f);
328 *poly.push() = SkPoint::Make(-32768.0625f, 0.0000f);
329 *poly.push() = SkPoint::Make(138.0000f, 3284.8125f);
330 *poly.push() = SkPoint::Make(0.0000f, -32768.0625f);
331 *poly.push() = SkPoint::Make(0.0000f, 129.0000f);
332 *poly.push() = SkPoint::Make(3284.8125f, 0.0000f);
333 *poly.push() = SkPoint::Make(-33554468.0000f, 0.0000f);
334 *poly.push() = SkPoint::Make(138.0000f, 3284.8125f);
335 *poly.push() = SkPoint::Make(0.0000f, -32768.0625f);
336 *poly.push() = SkPoint::Make(0.0000f, 219.0000f);
337 *poly.push() = SkPoint::Make(3220.8125f, 0.0000f);
338 *poly.push() = SkPoint::Make(-35840.0625f, 0.0000f);
339 *poly.push() = SkPoint::Make(0.0000f, 3284.8125f);
340 *poly.push() = SkPoint::Make(0.0000f, -41625560509365411790244566154608640.0000f);
341 *poly.push() = SkPoint::Make(0.0000f, 215282736.0000f);
342 *poly.push() = SkPoint::Make(0.0000f, 0.0000f);
343 *poly.push() = SkPoint::Make(-41625560509365411790244566154608640.0000f, 0.0000f);
344 *poly.push() = SkPoint::Make(215282736.0000f, 0.0000f);
345 *poly.push() = SkPoint::Make(0.0000f, -32768.0625f);
346 *poly.push() = SkPoint::Make(0.0000f, 138.0000f);
347 *poly.push() = SkPoint::Make(0.0000f, 0.0000f);
348 *poly.push() = SkPoint::Make(-32768.0625f, 0.0000f);
349 *poly.push() = SkPoint::Make(138.0000f, 3156.8125f);
350 *poly.push() = SkPoint::Make(0.0000f, -32768.0625f);
351 *poly.push() = SkPoint::Make(0.0000f, 129.0000f);
352 *poly.push() = SkPoint::Make(7433.6875f, 0.0000f);
353 *poly.push() = SkPoint::Make(-32768.0625f, 0.0000f);
354 *poly.push() = SkPoint::Make(138.0000f, 3284.8125f);
355 *poly.push() = SkPoint::Make(0.0000f, -32768.0625f);
356 *poly.push() = SkPoint::Make(0.0000f, 0.0000f);
357 *poly.push() = SkPoint::Make(59324728941049917997056.0000f, 0.0000f);
358 *poly.push() = SkPoint::Make(-35840.0625f, 0.0000f);
359 *poly.push() = SkPoint::Make(0.0000f, 3284.8125f);
360 *poly.push() = SkPoint::Make(0.0000f, -32768.0625f);
361 *poly.push() = SkPoint::Make(0.0000f, 138.0000f);
362 *poly.push() = SkPoint::Make(0.0000f, -32768.0625f);
363 *poly.push() = SkPoint::Make(0.0000f, 0.0000f);
364 *poly.push() = SkPoint::Make(137.0000f, 4105.6875f);
365 *poly.push() = SkPoint::Make(0.0000f, -32768.0625f);
366 *poly.push() = SkPoint::Make(0.0000f, 138.0000f);
367 *poly.push() = SkPoint::Make(3283.0000f, 0.0000f);
368 *poly.push() = SkPoint::Make(-32768.0625f, 0.0000f);
369 *poly.push() = SkPoint::Make(138.0000f, 3284.8125f);
370 *poly.push() = SkPoint::Make(0.0000f, -32768.0625f);
371 *poly.push() = SkPoint::Make(0.0000f, 138.0000f);
372 *poly.push() = SkPoint::Make(3284.8125f, 0.0000f);
373 *poly.push() = SkPoint::Make(0.0000f, 0.0000f);
374 *poly.push() = SkPoint::Make(138.0000f, 3284.5625f);
375 *poly.push() = SkPoint::Make(0.0000f, 0.0000f);
376 *poly.push() = SkPoint::Make(-44882437151680690189392273689542656.0000f, 134217728.0000f);
377 *poly.push() = SkPoint::Make(0.0000f, 0.0000f);
378 *poly.push() = SkPoint::Make(0.0000f, -32768.0625f);
379 *poly.push() = SkPoint::Make(0.0000f, 217055232.0000f);
380 *poly.push() = SkPoint::Make(138.3125f, 0.0000f);
381 *poly.push() = SkPoint::Make(-32768.0625f, 0.0000f);
382 *poly.push() = SkPoint::Make(138.0000f, 3284.5625f);
383 *poly.push() = SkPoint::Make(0.0000f, -32768.0625f);
384 *poly.push() = SkPoint::Make(0.0000f, 138.0000f);
385 *poly.push() = SkPoint::Make(3284.8125f, 0.0000f);
386 *poly.push() = SkPoint::Make(-32768.0625f, 0.0000f);
387 *poly.push() = SkPoint::Make(138.0000f, 3284.8125f);
388 *poly.push() = SkPoint::Make(0.0000f, -32768.0625f);
389 *poly.push() = SkPoint::Make(0.0000f, 138.0000f);
390 *poly.push() = SkPoint::Make(3284.8125f, 0.0000f);
391 *poly.push() = SkPoint::Make(-32768.0625f, 0.0000f);
392 *poly.push() = SkPoint::Make(138.0000f, 3284.8125f);
393 *poly.push() = SkPoint::Make(0.0000f, -32768.0625f);
394 *poly.push() = SkPoint::Make(0.0000f, 138.0000f);
395 *poly.push() = SkPoint::Make(2152988672.0000f, 0.0000f);
396 *poly.push() = SkPoint::Make(-32768.0625f, 0.0000f);
397 *poly.push() = SkPoint::Make(138.0000f, 3284.8125f);
398 *poly.push() = SkPoint::Make(0.0000f, -32768.0625f);
399 *poly.push() = SkPoint::Make(0.0000f, 138.0000f);
400 *poly.push() = SkPoint::Make(3284.8125f, 0.0000f);
401 *poly.push() = SkPoint::Make(-32768.0625f, 0.0000f);
402 *poly.push() = SkPoint::Make(138.0000f, 3284.8125f);
403 *poly.push() = SkPoint::Make(0.0000f, -32768.0625f);
404 *poly.push() = SkPoint::Make(0.0000f, 138.0000f);
405 *poly.push() = SkPoint::Make(3284.8125f, 0.0000f);
406 *poly.push() = SkPoint::Make(-32768.0625f, 0.0000f);
407 REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) < 0);
408 REPORTER_ASSERT(reporter, !SkIsConvexPolygon(poly.begin(), poly.count()));
409 REPORTER_ASSERT(reporter, !SkIsSimplePolygon(poly.begin(), poly.count()));
410 triangleIndices.rewind();
411 // running this just to make sure it doesn't crash
412 REPORTER_ASSERT(reporter, SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(),
413 &triangleIndices));
414 }
415
416 struct PtSet {
417 const SkPoint* fPts;
418 int fN;
419 };
420
DEF_TEST(IsPolyConvex_experimental,r)421 DEF_TEST(IsPolyConvex_experimental, r) {
422 #define PTSET(array) {array, SK_ARRAY_COUNT(array)}
423
424 const SkPoint g0[] = { {0, 0}, {10, 0}, {10, 10}, {0, 10} };
425 const PtSet convex[] = { PTSET(g0) };
426 for (auto& set : convex) {
427 REPORTER_ASSERT(r, SkIsPolyConvex_experimental(set.fPts, set.fN));
428 }
429
430 const SkPoint b0[] = { {0, 0}, {10, 0}, {0, 10}, {10, 10} };
431 const SkPoint b1[] = {
432 {24.8219f, 8.05052f},
433 {26.0616f, 24.4895f}, {8.49582f, 16.815f},
434 {27.3047f, 7.75211f},
435 {21.927f, 27.2051f},
436 };
437 const SkPoint b2[] = {
438 {20, 20}, {20, 50}, {80, 50}, {20, 50}, {20, 80},
439 };
440 const PtSet concave[] = { PTSET(b0), PTSET(b1), PTSET(b2) };
441 for (auto& set : concave) {
442 if (SkIsPolyConvex_experimental(set.fPts, set.fN)) {
443 REPORTER_ASSERT(r, !SkIsPolyConvex_experimental(set.fPts, set.fN));
444 }
445 }
446
447 }
448
449