blob: 9a9d3883b7697b0b9c8ec4def0d8e8ab1aa2a9e5 [file] [log] [blame]
Jim Van Verth061cc212018-07-11 14:09:09 -04001/*
2 * Copyright 2018 Google LLC
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "fuzz/Fuzz.h"
9#include "src/utils/SkPolyUtils.h"
Jim Van Verth061cc212018-07-11 14:09:09 -040010
11void inline ignoreResult(bool ) {}
12
13DEF_FUZZ(PolyUtils, fuzz) {
14 int count;
15 fuzz->nextRange(&count, 0, 512);
16 SkAutoSTMalloc<64, SkPoint> polygon(count);
17 for (int index = 0; index < count; ++index) {
18 fuzz->next(&polygon[index].fX, &polygon[index].fY);
19 }
Jim Van Vertha5ef3972019-05-01 13:28:07 -040020 SkRect bounds;
21 bounds.setBoundsCheck(polygon, count);
Jim Van Verth061cc212018-07-11 14:09:09 -040022
23 ignoreResult(SkGetPolygonWinding(polygon, count));
24 ignoreResult(SkIsConvexPolygon(polygon, count));
25 ignoreResult(SkIsSimplePolygon(polygon, count));
26
27 SkScalar inset;
28 fuzz->next(&inset);
29 SkTDArray<SkPoint> output;
30 ignoreResult(SkInsetConvexPolygon(polygon, count, inset, &output));
Jim Van Verth061cc212018-07-11 14:09:09 -040031
32 SkScalar offset;
33 fuzz->next(&offset);
Jim Van Vertha5ef3972019-05-01 13:28:07 -040034 ignoreResult(SkOffsetSimplePolygon(polygon, count, bounds, offset, &output));
Jim Van Verth061cc212018-07-11 14:09:09 -040035
36 SkAutoSTMalloc<64, uint16_t> indexMap(count);
37 for (int index = 0; index < count; ++index) {
38 fuzz->next(&indexMap[index]);
39 }
40 SkTDArray<uint16_t> outputIndices;
41 ignoreResult(SkTriangulateSimplePolygon(polygon, indexMap, count, &outputIndices));
42}