Jim Van Verth | 061cc21 | 2018-07-11 14:09:09 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
| 8 | #include "Fuzz.h" |
| 9 | #include "FuzzCommon.h" |
| 10 | #include "SkPolyUtils.h" |
| 11 | |
| 12 | void inline ignoreResult(bool ) {} |
| 13 | |
| 14 | DEF_FUZZ(PolyUtils, fuzz) { |
| 15 | int count; |
| 16 | fuzz->nextRange(&count, 0, 512); |
| 17 | SkAutoSTMalloc<64, SkPoint> polygon(count); |
| 18 | for (int index = 0; index < count; ++index) { |
| 19 | fuzz->next(&polygon[index].fX, &polygon[index].fY); |
| 20 | } |
| 21 | |
| 22 | ignoreResult(SkGetPolygonWinding(polygon, count)); |
| 23 | ignoreResult(SkIsConvexPolygon(polygon, count)); |
| 24 | ignoreResult(SkIsSimplePolygon(polygon, count)); |
| 25 | |
| 26 | SkScalar inset; |
| 27 | fuzz->next(&inset); |
| 28 | SkTDArray<SkPoint> output; |
| 29 | ignoreResult(SkInsetConvexPolygon(polygon, count, inset, &output)); |
| 30 | std::function<SkScalar(const SkPoint&)> distanceFunc = [fuzz](const SkPoint& p) { |
| 31 | SkScalar retVal; |
| 32 | fuzz->next(&retVal); |
| 33 | return retVal; |
| 34 | }; |
| 35 | ignoreResult(SkInsetConvexPolygon(polygon, count, distanceFunc, &output)); |
| 36 | |
| 37 | SkScalar offset; |
| 38 | fuzz->next(&offset); |
| 39 | ignoreResult(SkOffsetSimplePolygon(polygon, count, offset, &output)); |
| 40 | ignoreResult(SkOffsetSimplePolygon(polygon, count, distanceFunc, &output)); |
| 41 | |
| 42 | SkAutoSTMalloc<64, uint16_t> indexMap(count); |
| 43 | for (int index = 0; index < count; ++index) { |
| 44 | fuzz->next(&indexMap[index]); |
| 45 | } |
| 46 | SkTDArray<uint16_t> outputIndices; |
| 47 | ignoreResult(SkTriangulateSimplePolygon(polygon, indexMap, count, &outputIndices)); |
| 48 | } |