1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2018 Google Inc. 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci#include "src/utils/SkPolyUtils.h" 8cb93a386Sopenharmony_ci#include "tests/Test.h" 9cb93a386Sopenharmony_ci 10cb93a386Sopenharmony_ciDEF_TEST(PolyUtils, reporter) { 11cb93a386Sopenharmony_ci 12cb93a386Sopenharmony_ci SkTDArray<SkPoint> poly; 13cb93a386Sopenharmony_ci // init simple index map 14cb93a386Sopenharmony_ci uint16_t indexMap[1024]; 15cb93a386Sopenharmony_ci for (int i = 0; i < 1024; ++i) { 16cb93a386Sopenharmony_ci indexMap[i] = i; 17cb93a386Sopenharmony_ci } 18cb93a386Sopenharmony_ci SkTDArray<uint16_t> triangleIndices; 19cb93a386Sopenharmony_ci 20cb93a386Sopenharmony_ci // skinny triangle 21cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(-100, 55); 22cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(100, 55); 23cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(102.5f, 54.330127f); 24cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) < 0); 25cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkIsConvexPolygon(poly.begin(), poly.count())); 26cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkIsSimplePolygon(poly.begin(), poly.count())); 27cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(), 28cb93a386Sopenharmony_ci &triangleIndices)); 29cb93a386Sopenharmony_ci 30cb93a386Sopenharmony_ci // switch winding 31cb93a386Sopenharmony_ci poly[2].set(102.5f, 55.330127f); 32cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) > 0); 33cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkIsConvexPolygon(poly.begin(), poly.count())); 34cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkIsSimplePolygon(poly.begin(), poly.count())); 35cb93a386Sopenharmony_ci triangleIndices.rewind(); 36cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(), 37cb93a386Sopenharmony_ci &triangleIndices)); 38cb93a386Sopenharmony_ci 39cb93a386Sopenharmony_ci // make degenerate 40cb93a386Sopenharmony_ci poly[2].set(100 + 2.5f, 55); 41cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) == 0); 42cb93a386Sopenharmony_ci // TODO: should these fail? 43cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkIsConvexPolygon(poly.begin(), poly.count())); 44cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkIsSimplePolygon(poly.begin(), poly.count())); 45cb93a386Sopenharmony_ci triangleIndices.rewind(); 46cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, !SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(), 47cb93a386Sopenharmony_ci &triangleIndices)); 48cb93a386Sopenharmony_ci 49cb93a386Sopenharmony_ci // giant triangle 50cb93a386Sopenharmony_ci poly[0].set(-1.0e+37f, 1.0e+37f); 51cb93a386Sopenharmony_ci poly[1].set(1.0e+37f, 1.0e+37f); 52cb93a386Sopenharmony_ci poly[2].set(-1.0e+37f, -1.0e+37f); 53cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) < 0); 54cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkIsConvexPolygon(poly.begin(), poly.count())); 55cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkIsSimplePolygon(poly.begin(), poly.count())); 56cb93a386Sopenharmony_ci triangleIndices.rewind(); 57cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(), 58cb93a386Sopenharmony_ci &triangleIndices)); 59cb93a386Sopenharmony_ci 60cb93a386Sopenharmony_ci // teeny triangle 61cb93a386Sopenharmony_ci poly[0].set(-1.0e-38f, 1.0e-38f); 62cb93a386Sopenharmony_ci poly[1].set(-1.0e-38f, -1.0e-38f); 63cb93a386Sopenharmony_ci poly[2].set(1.0e-38f, 1.0e-38f); 64cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) == 0); 65cb93a386Sopenharmony_ci // TODO: should these fail? 66cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkIsConvexPolygon(poly.begin(), poly.count())); 67cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkIsSimplePolygon(poly.begin(), poly.count())); 68cb93a386Sopenharmony_ci triangleIndices.rewind(); 69cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, !SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(), 70cb93a386Sopenharmony_ci &triangleIndices)); 71cb93a386Sopenharmony_ci 72cb93a386Sopenharmony_ci // triangle way off in space (relative to size so we don't completely obliterate values) 73cb93a386Sopenharmony_ci poly[0].set(-100 + 1.0e+9f, 55 - 1.0e+9f); 74cb93a386Sopenharmony_ci poly[1].set(100 + 1.0e+9f, 55 - 1.0e+9f); 75cb93a386Sopenharmony_ci poly[2].set(150 + 1.0e+9f, 100 - 1.0e+9f); 76cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) > 0); 77cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkIsConvexPolygon(poly.begin(), poly.count())); 78cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkIsSimplePolygon(poly.begin(), poly.count())); 79cb93a386Sopenharmony_ci triangleIndices.rewind(); 80cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(), 81cb93a386Sopenharmony_ci &triangleIndices)); 82cb93a386Sopenharmony_ci 83cb93a386Sopenharmony_ci /////////////////////////////////////////////////////////////////////// 84cb93a386Sopenharmony_ci // round rect 85cb93a386Sopenharmony_ci poly.rewind(); 86cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(-100, 55); 87cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(100, 55); 88cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(100 + 2.5f, 50 + 4.330127f); 89cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(100 + 3.535534f, 50 + 3.535534f); 90cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(100 + 4.330127f, 50 + 2.5f); 91cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(105, 50); 92cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(105, -50); 93cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(100 + 4.330127f, -50 - 2.5f); 94cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(100 + 3.535534f, -50 - 3.535534f); 95cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(100 + 2.5f, -50 - 4.330127f); 96cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(100, -55); 97cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(-100, -55); 98cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(-100 - 2.5f, -50 - 4.330127f); 99cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(-100 - 3.535534f, -50 - 3.535534f); 100cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(-100 - 4.330127f, -50 - 2.5f); 101cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(-105, -50); 102cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(-105, 50); 103cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(-100 - 4.330127f, 50 + 2.5f); 104cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(-100 - 3.535534f, 50 + 3.535534f); 105cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(-100 - 2.5f, 50 + 4.330127f); 106cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) < 0); 107cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkIsConvexPolygon(poly.begin(), poly.count())); 108cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkIsSimplePolygon(poly.begin(), poly.count())); 109cb93a386Sopenharmony_ci triangleIndices.rewind(); 110cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(), 111cb93a386Sopenharmony_ci &triangleIndices)); 112cb93a386Sopenharmony_ci 113cb93a386Sopenharmony_ci // translate far enough to obliterate some low bits 114cb93a386Sopenharmony_ci for (int i = 0; i < poly.count(); ++i) { 115cb93a386Sopenharmony_ci poly[i].offset(1.0e+7f, 1.0e+7f); 116cb93a386Sopenharmony_ci } 117cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) < 0); 118cb93a386Sopenharmony_ci // Due to floating point error it's no longer convex 119cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, !SkIsConvexPolygon(poly.begin(), poly.count())); 120cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkIsSimplePolygon(poly.begin(), poly.count())); 121cb93a386Sopenharmony_ci triangleIndices.rewind(); 122cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(), 123cb93a386Sopenharmony_ci &triangleIndices)); 124cb93a386Sopenharmony_ci 125cb93a386Sopenharmony_ci // translate a little farther to create some coincident vertices 126cb93a386Sopenharmony_ci for (int i = 0; i < poly.count(); ++i) { 127cb93a386Sopenharmony_ci poly[i].offset(4.0e+7f, 4.0e+7f); 128cb93a386Sopenharmony_ci } 129cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) < 0); 130cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkIsConvexPolygon(poly.begin(), poly.count())); 131cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkIsSimplePolygon(poly.begin(), poly.count())); 132cb93a386Sopenharmony_ci // This can't handle coincident vertices 133cb93a386Sopenharmony_ci triangleIndices.rewind(); 134cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, !SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(), 135cb93a386Sopenharmony_ci &triangleIndices)); 136cb93a386Sopenharmony_ci 137cb93a386Sopenharmony_ci // troublesome case -- clipped roundrect 138cb93a386Sopenharmony_ci poly.rewind(); 139cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(335.928101f, 428.219055f); 140cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(330.414459f, 423.034912f); 141cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(325.749084f, 417.395508f); 142cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(321.931946f, 411.300842f); 143cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(318.963074f, 404.750977f); 144cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(316.842468f, 397.745850f); 145cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(315.570068f, 390.285522f); 146cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(315.145966f, 382.369965f); 147cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(315.570068f, 374.454346f); 148cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(316.842468f, 366.994019f); 149cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(318.963074f, 359.988892f); 150cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(321.931946f, 353.439056f); 151cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(325.749084f, 347.344421f); 152cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(330.414459f, 341.705017f); 153cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(335.928101f, 336.520813f); 154cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(342.289948f, 331.791901f); 155cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(377.312134f, 331.791901f); 156cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(381.195313f, 332.532593f); 157cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(384.464935f, 334.754700f); 158cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(386.687042f, 338.024292f); 159cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(387.427765f, 341.907532f); 160cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(387.427765f, 422.832367f); 161cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(386.687042f, 426.715576f); 162cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(384.464935f, 429.985168f); 163cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(381.195313f, 432.207275f); 164cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(377.312134f, 432.947998f); 165cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(342.289948f, 432.947998f); 166cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) > 0); 167cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkIsConvexPolygon(poly.begin(), poly.count())); 168cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkIsSimplePolygon(poly.begin(), poly.count())); 169cb93a386Sopenharmony_ci triangleIndices.rewind(); 170cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(), 171cb93a386Sopenharmony_ci &triangleIndices)); 172cb93a386Sopenharmony_ci 173cb93a386Sopenharmony_ci // a star is born 174cb93a386Sopenharmony_ci poly.rewind(); 175cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(0.0f, -50.0f); 176cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(14.43f, -25.0f); 177cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(43.30f, -25.0f); 178cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(28.86f, 0.0f); 179cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(43.30f, 25.0f); 180cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(14.43f, 25.0f); 181cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(0.0f, 50.0f); 182cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(-14.43f, 25.0f); 183cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(-43.30f, 25.0f); 184cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(-28.86f, 0.0f); 185cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(-43.30f, -25.0f); 186cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(-14.43f, -25.0f); 187cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) > 0); 188cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, !SkIsConvexPolygon(poly.begin(), poly.count())); 189cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkIsSimplePolygon(poly.begin(), poly.count())); 190cb93a386Sopenharmony_ci triangleIndices.rewind(); 191cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(), 192cb93a386Sopenharmony_ci &triangleIndices)); 193cb93a386Sopenharmony_ci 194cb93a386Sopenharmony_ci // many spiked star 195cb93a386Sopenharmony_ci { 196cb93a386Sopenharmony_ci const SkScalar c = SkIntToScalar(45); 197cb93a386Sopenharmony_ci const SkScalar r1 = SkIntToScalar(20); 198cb93a386Sopenharmony_ci const SkScalar r2 = SkIntToScalar(3); 199cb93a386Sopenharmony_ci const int n = 500; 200cb93a386Sopenharmony_ci poly.rewind(); 201cb93a386Sopenharmony_ci SkScalar rad = 0; 202cb93a386Sopenharmony_ci const SkScalar drad = SK_ScalarPI / n; 203cb93a386Sopenharmony_ci for (int i = 0; i < n; i++) { 204cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(c + SkScalarCos(rad) * r1, c + SkScalarSin(rad) * r1); 205cb93a386Sopenharmony_ci rad += drad; 206cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(c + SkScalarCos(rad) * r2, c + SkScalarSin(rad) * r2); 207cb93a386Sopenharmony_ci rad += drad; 208cb93a386Sopenharmony_ci } 209cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) > 0); 210cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, !SkIsConvexPolygon(poly.begin(), poly.count())); 211cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkIsSimplePolygon(poly.begin(), poly.count())); 212cb93a386Sopenharmony_ci triangleIndices.rewind(); 213cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(), 214cb93a386Sopenharmony_ci &triangleIndices)); 215cb93a386Sopenharmony_ci } 216cb93a386Sopenharmony_ci 217cb93a386Sopenharmony_ci // self-intersecting polygon 218cb93a386Sopenharmony_ci poly.rewind(); 219cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(0.0f, -50.0f); 220cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(14.43f, -25.0f); 221cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(43.30f, -25.0f); 222cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(-28.86f, 0.0f); 223cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(43.30f, 25.0f); 224cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(14.43f, 25.0f); 225cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(0.0f, 50.0f); 226cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(-14.43f, 25.0f); 227cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(-43.30f, 25.0f); 228cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(28.86f, 0.0f); 229cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(-43.30f, -25.0f); 230cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(-14.43f, -25.0f); 231cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) > 0); 232cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, !SkIsConvexPolygon(poly.begin(), poly.count())); 233cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, !SkIsSimplePolygon(poly.begin(), poly.count())); 234cb93a386Sopenharmony_ci triangleIndices.rewind(); 235cb93a386Sopenharmony_ci // running this just to make sure it doesn't crash 236cb93a386Sopenharmony_ci // the fact that it succeeds doesn't mean anything since the input is not simple 237cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(), 238cb93a386Sopenharmony_ci &triangleIndices)); 239cb93a386Sopenharmony_ci 240cb93a386Sopenharmony_ci // self-intersecting polygon with coincident point 241cb93a386Sopenharmony_ci poly.rewind(); 242cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(0.0f, 0.0f); 243cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(-50, -50); 244cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(50, -50); 245cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(0.00000001f, -0.00000001f); 246cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(-50, 50); 247cb93a386Sopenharmony_ci *poly.push() = SkPoint::Make(50, 50); 248cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) == 0); 249cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, !SkIsConvexPolygon(poly.begin(), poly.count())); 250cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, !SkIsSimplePolygon(poly.begin(), poly.count())); 251cb93a386Sopenharmony_ci triangleIndices.rewind(); 252cb93a386Sopenharmony_ci // running this just to make sure it doesn't crash 253cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, !SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(), 254cb93a386Sopenharmony_ci &triangleIndices)); 255cb93a386Sopenharmony_ci} 256cb93a386Sopenharmony_ci 257cb93a386Sopenharmony_cistruct PtSet { 258cb93a386Sopenharmony_ci const SkPoint* fPts; 259cb93a386Sopenharmony_ci int fN; 260cb93a386Sopenharmony_ci}; 261cb93a386Sopenharmony_ci 262cb93a386Sopenharmony_ciDEF_TEST(IsPolyConvex_experimental, r) { 263cb93a386Sopenharmony_ci #define PTSET(array) {array, SK_ARRAY_COUNT(array)} 264cb93a386Sopenharmony_ci 265cb93a386Sopenharmony_ci const SkPoint g0[] = { {0, 0}, {10, 0}, {10, 10}, {0, 10} }; 266cb93a386Sopenharmony_ci const PtSet convex[] = { PTSET(g0) }; 267cb93a386Sopenharmony_ci for (auto& set : convex) { 268cb93a386Sopenharmony_ci REPORTER_ASSERT(r, SkIsPolyConvex_experimental(set.fPts, set.fN)); 269cb93a386Sopenharmony_ci } 270cb93a386Sopenharmony_ci 271cb93a386Sopenharmony_ci const SkPoint b0[] = { {0, 0}, {10, 0}, {0, 10}, {10, 10} }; 272cb93a386Sopenharmony_ci const SkPoint b1[] = { 273cb93a386Sopenharmony_ci {24.8219f, 8.05052f}, 274cb93a386Sopenharmony_ci {26.0616f, 24.4895f}, {8.49582f, 16.815f}, 275cb93a386Sopenharmony_ci {27.3047f, 7.75211f}, 276cb93a386Sopenharmony_ci {21.927f, 27.2051f}, 277cb93a386Sopenharmony_ci }; 278cb93a386Sopenharmony_ci const SkPoint b2[] = { 279cb93a386Sopenharmony_ci {20, 20}, {20, 50}, {80, 50}, {20, 50}, {20, 80}, 280cb93a386Sopenharmony_ci }; 281cb93a386Sopenharmony_ci const PtSet concave[] = { PTSET(b0), PTSET(b1), PTSET(b2) }; 282cb93a386Sopenharmony_ci for (auto& set : concave) { 283cb93a386Sopenharmony_ci if (SkIsPolyConvex_experimental(set.fPts, set.fN)) { 284cb93a386Sopenharmony_ci REPORTER_ASSERT(r, !SkIsPolyConvex_experimental(set.fPts, set.fN)); 285cb93a386Sopenharmony_ci } 286cb93a386Sopenharmony_ci } 287cb93a386Sopenharmony_ci 288cb93a386Sopenharmony_ci} 289cb93a386Sopenharmony_ci 290