From 6784ffa78e70e17084e1b30e724a8ded175d6007 Mon Sep 17 00:00:00 2001 From: Jim Van Verth Date: Tue, 3 Jul 2018 16:12:39 -0400 Subject: Add some new PolyUtils tests. Also: * clean up PolyUtils checks to be correct and consistent. * fix some bugs discovered by the unit tests. Bug: skia: Change-Id: I1a8e07d13cb44fecc67344154dc1002f3f910f5d Reviewed-on: https://skia-review.googlesource.com/138592 Reviewed-by: Robert Phillips Reviewed-by: Greg Daniel Commit-Queue: Jim Van Verth --- tests/InsetConvexPolyTest.cpp | 47 +++------ tests/OffsetSimplePolyTest.cpp | 75 ++++++------- tests/PolyUtilsTest.cpp | 232 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 274 insertions(+), 80 deletions(-) create mode 100644 tests/PolyUtilsTest.cpp (limited to 'tests') diff --git a/tests/InsetConvexPolyTest.cpp b/tests/InsetConvexPolyTest.cpp index 022060c0f4..facabb76fa 100644 --- a/tests/InsetConvexPolyTest.cpp +++ b/tests/InsetConvexPolyTest.cpp @@ -7,30 +7,6 @@ #include "Test.h" #include "SkPolyUtils.h" -static bool is_convex(const SkTDArray& poly) { - if (poly.count() < 3) { - return false; - } - - SkVector v0 = poly[0] - poly[poly.count() - 1]; - SkVector v1 = poly[1] - poly[poly.count() - 1]; - SkScalar winding = v0.cross(v1); - - for (int i = 0; i < poly.count()-1; ++i) { - int j = i + 1; - int k = (i + 2) % poly.count(); - - SkVector v0 = poly[j] - poly[i]; - SkVector v1 = poly[k] - poly[i]; - SkScalar perpDot = v0.cross(v1); - if (winding*perpDot < 0) { - return false; - } - } - - return true; -} - DEF_TEST(InsetConvexPoly, reporter) { SkTDArray rrectPoly; @@ -55,18 +31,18 @@ DEF_TEST(InsetConvexPoly, reporter) { *rrectPoly.push() = SkPoint::Make(-100 - 4.330127f, 50 + 2.5f); *rrectPoly.push() = SkPoint::Make(-100 - 3.535534f, 50 + 3.535534f); *rrectPoly.push() = SkPoint::Make(-100 - 2.5f, 50 + 4.330127f); - REPORTER_ASSERT(reporter, is_convex(rrectPoly)); + REPORTER_ASSERT(reporter, SkIsConvexPolygon(rrectPoly.begin(), rrectPoly.count())); // inset a little SkTDArray insetPoly; - bool result = SkInsetConvexPolygon(&rrectPoly[0], rrectPoly.count(), 3, &insetPoly); + bool result = SkInsetConvexPolygon(rrectPoly.begin(), rrectPoly.count(), 3, &insetPoly); REPORTER_ASSERT(reporter, result); - REPORTER_ASSERT(reporter, is_convex(insetPoly)); + REPORTER_ASSERT(reporter, SkIsConvexPolygon(insetPoly.begin(), insetPoly.count())); // inset to rect - result = SkInsetConvexPolygon(&rrectPoly[0], rrectPoly.count(), 10, &insetPoly); + result = SkInsetConvexPolygon(rrectPoly.begin(), rrectPoly.count(), 10, &insetPoly); REPORTER_ASSERT(reporter, result); - REPORTER_ASSERT(reporter, is_convex(insetPoly)); + REPORTER_ASSERT(reporter, SkIsConvexPolygon(insetPoly.begin(), insetPoly.count())); REPORTER_ASSERT(reporter, insetPoly.count() == 4); if (insetPoly.count() == 4) { REPORTER_ASSERT(reporter, insetPoly[0].equals(-95, 45)); @@ -77,9 +53,9 @@ DEF_TEST(InsetConvexPoly, reporter) { // just to full inset // fails, but outputs a line segment - result = SkInsetConvexPolygon(&rrectPoly[0], rrectPoly.count(), 55, &insetPoly); + result = SkInsetConvexPolygon(rrectPoly.begin(), rrectPoly.count(), 55, &insetPoly); REPORTER_ASSERT(reporter, !result); - REPORTER_ASSERT(reporter, !is_convex(insetPoly)); + REPORTER_ASSERT(reporter, !SkIsConvexPolygon(insetPoly.begin(), insetPoly.count())); REPORTER_ASSERT(reporter, insetPoly.count() == 2); if (insetPoly.count() == 2) { REPORTER_ASSERT(reporter, insetPoly[0].equals(-50, 0)); @@ -87,7 +63,7 @@ DEF_TEST(InsetConvexPoly, reporter) { } // past full inset - result = SkInsetConvexPolygon(&rrectPoly[0], rrectPoly.count(), 75, &insetPoly); + result = SkInsetConvexPolygon(rrectPoly.begin(), rrectPoly.count(), 75, &insetPoly); REPORTER_ASSERT(reporter, !result); REPORTER_ASSERT(reporter, insetPoly.count() == 0); @@ -120,10 +96,11 @@ DEF_TEST(InsetConvexPoly, reporter) { *clippedRRectPoly.push() = SkPoint::Make(381.195313f, 432.207275f); *clippedRRectPoly.push() = SkPoint::Make(377.312134f, 432.947998f); *clippedRRectPoly.push() = SkPoint::Make(342.289948f, 432.947998f); - REPORTER_ASSERT(reporter, is_convex(clippedRRectPoly)); + REPORTER_ASSERT(reporter, SkIsConvexPolygon(clippedRRectPoly.begin(), + clippedRRectPoly.count())); - result = SkInsetConvexPolygon(&clippedRRectPoly[0], clippedRRectPoly.count(), 32.3699417f, + result = SkInsetConvexPolygon(clippedRRectPoly.begin(), clippedRRectPoly.count(), 32.3699417f, &insetPoly); REPORTER_ASSERT(reporter, result); - REPORTER_ASSERT(reporter, is_convex(insetPoly)); + REPORTER_ASSERT(reporter, SkIsConvexPolygon(insetPoly.begin(), insetPoly.count())); } diff --git a/tests/OffsetSimplePolyTest.cpp b/tests/OffsetSimplePolyTest.cpp index 547dc9e529..0f4f18f2ad 100644 --- a/tests/OffsetSimplePolyTest.cpp +++ b/tests/OffsetSimplePolyTest.cpp @@ -7,30 +7,6 @@ #include "Test.h" #include "SkPolyUtils.h" -static bool is_convex(const SkTDArray& poly) { - if (poly.count() < 3) { - return false; - } - - SkVector v0 = poly[0] - poly[poly.count() - 1]; - SkVector v1 = poly[1] - poly[poly.count() - 1]; - SkScalar winding = v0.cross(v1); - - for (int i = 0; i < poly.count()-1; ++i) { - int j = i + 1; - int k = (i + 2) % poly.count(); - - SkVector v0 = poly[j] - poly[i]; - SkVector v1 = poly[k] - poly[i]; - SkScalar perpDot = v0.cross(v1); - if (winding*perpDot < 0) { - return false; - } - } - - return true; -} - DEF_TEST(OffsetSimplePoly, reporter) { SkTDArray rrectPoly; @@ -58,18 +34,18 @@ DEF_TEST(OffsetSimplePoly, reporter) { *rrectPoly.push() = SkPoint::Make(-100 - 4.330127f, 50 + 2.5f); *rrectPoly.push() = SkPoint::Make(-100 - 3.535534f, 50 + 3.535534f); *rrectPoly.push() = SkPoint::Make(-100 - 2.5f, 50 + 4.330127f); - REPORTER_ASSERT(reporter, is_convex(rrectPoly)); + REPORTER_ASSERT(reporter, SkIsConvexPolygon(rrectPoly.begin(), rrectPoly.count())); // inset a little SkTDArray offsetPoly; - bool result = SkOffsetSimplePolygon(&rrectPoly[0], rrectPoly.count(), 3, &offsetPoly); + bool result = SkOffsetSimplePolygon(rrectPoly.begin(), rrectPoly.count(), 3, &offsetPoly); REPORTER_ASSERT(reporter, result); - REPORTER_ASSERT(reporter, is_convex(offsetPoly)); + REPORTER_ASSERT(reporter, SkIsConvexPolygon(offsetPoly.begin(), offsetPoly.count())); // inset to rect - result = SkOffsetSimplePolygon(&rrectPoly[0], rrectPoly.count(), 10, &offsetPoly); + result = SkOffsetSimplePolygon(rrectPoly.begin(), rrectPoly.count(), 10, &offsetPoly); REPORTER_ASSERT(reporter, result); - REPORTER_ASSERT(reporter, is_convex(offsetPoly)); + REPORTER_ASSERT(reporter, SkIsConvexPolygon(offsetPoly.begin(), offsetPoly.count())); REPORTER_ASSERT(reporter, offsetPoly.count() == 4); if (offsetPoly.count() == 4) { REPORTER_ASSERT(reporter, offsetPoly[0].equals(-95, 45)); @@ -80,9 +56,9 @@ DEF_TEST(OffsetSimplePoly, reporter) { // just to full inset // fails, but outputs a line segment - result = SkOffsetSimplePolygon(&rrectPoly[0], rrectPoly.count(), 55, &offsetPoly); + result = SkOffsetSimplePolygon(rrectPoly.begin(), rrectPoly.count(), 55, &offsetPoly); REPORTER_ASSERT(reporter, !result); - REPORTER_ASSERT(reporter, !is_convex(offsetPoly)); + REPORTER_ASSERT(reporter, !SkIsConvexPolygon(offsetPoly.begin(), offsetPoly.count())); REPORTER_ASSERT(reporter, offsetPoly.count() == 2); if (offsetPoly.count() == 2) { REPORTER_ASSERT(reporter, offsetPoly[0].equals(-50, 0)); @@ -90,7 +66,7 @@ DEF_TEST(OffsetSimplePoly, reporter) { } // past full inset - result = SkOffsetSimplePolygon(&rrectPoly[0], rrectPoly.count(), 75, &offsetPoly); + result = SkOffsetSimplePolygon(rrectPoly.begin(), rrectPoly.count(), 75, &offsetPoly); REPORTER_ASSERT(reporter, !result); // troublesome case @@ -122,12 +98,13 @@ DEF_TEST(OffsetSimplePoly, reporter) { *clippedRRectPoly.push() = SkPoint::Make(381.195313f, 432.207275f); *clippedRRectPoly.push() = SkPoint::Make(377.312134f, 432.947998f); *clippedRRectPoly.push() = SkPoint::Make(342.289948f, 432.947998f); - REPORTER_ASSERT(reporter, is_convex(clippedRRectPoly)); + REPORTER_ASSERT(reporter, SkIsConvexPolygon(clippedRRectPoly.begin(), + clippedRRectPoly.count())); - result = SkOffsetSimplePolygon(&clippedRRectPoly[0], clippedRRectPoly.count(), 32.3699417f, + result = SkOffsetSimplePolygon(clippedRRectPoly.begin(), clippedRRectPoly.count(), 32.3699417f, &offsetPoly); REPORTER_ASSERT(reporter, result); - REPORTER_ASSERT(reporter, is_convex(offsetPoly)); + REPORTER_ASSERT(reporter, SkIsConvexPolygon(offsetPoly.begin(), offsetPoly.count())); //////////////////////////////////////////////////////////////////////////////// // Concave tests @@ -145,46 +122,54 @@ DEF_TEST(OffsetSimplePoly, reporter) { *starPoly.push() = SkPoint::Make(-28.86f, 0.0f); *starPoly.push() = SkPoint::Make(-43.30f, -25.0f); *starPoly.push() = SkPoint::Make(-14.43f, -25.0f); + REPORTER_ASSERT(reporter, SkIsSimplePolygon(starPoly.begin(), starPoly.count())); // try a variety of distances - result = SkOffsetSimplePolygon(&starPoly[0], starPoly.count(), 0.1f, + result = SkOffsetSimplePolygon(starPoly.begin(), starPoly.count(), 0.1f, &offsetPoly); REPORTER_ASSERT(reporter, result); + REPORTER_ASSERT(reporter, SkIsSimplePolygon(offsetPoly.begin(), offsetPoly.count())); - result = SkOffsetSimplePolygon(&starPoly[0], starPoly.count(), 5.665f, + result = SkOffsetSimplePolygon(starPoly.begin(), starPoly.count(), 5.665f, &offsetPoly); REPORTER_ASSERT(reporter, result); + REPORTER_ASSERT(reporter, SkIsSimplePolygon(offsetPoly.begin(), offsetPoly.count())); - result = SkOffsetSimplePolygon(&starPoly[0], starPoly.count(), 28, + result = SkOffsetSimplePolygon(starPoly.begin(), starPoly.count(), 28, &offsetPoly); REPORTER_ASSERT(reporter, result); + REPORTER_ASSERT(reporter, SkIsSimplePolygon(offsetPoly.begin(), offsetPoly.count())); // down to a point - result = SkOffsetSimplePolygon(&starPoly[0], starPoly.count(), 28.866f, + result = SkOffsetSimplePolygon(starPoly.begin(), starPoly.count(), 28.866f, &offsetPoly); REPORTER_ASSERT(reporter, !result); // and past - result = SkOffsetSimplePolygon(&starPoly[0], starPoly.count(), 50.5f, + result = SkOffsetSimplePolygon(starPoly.begin(), starPoly.count(), 50.5f, &offsetPoly); REPORTER_ASSERT(reporter, !result); // and now out - result = SkOffsetSimplePolygon(&starPoly[0], starPoly.count(), -0.1f, + result = SkOffsetSimplePolygon(starPoly.begin(), starPoly.count(), -0.1f, &offsetPoly); REPORTER_ASSERT(reporter, result); + REPORTER_ASSERT(reporter, SkIsSimplePolygon(offsetPoly.begin(), offsetPoly.count())); - result = SkOffsetSimplePolygon(&starPoly[0], starPoly.count(), -5.6665f, + result = SkOffsetSimplePolygon(starPoly.begin(), starPoly.count(), -5.6665f, &offsetPoly); REPORTER_ASSERT(reporter, result); + REPORTER_ASSERT(reporter, SkIsSimplePolygon(offsetPoly.begin(), offsetPoly.count())); - result = SkOffsetSimplePolygon(&starPoly[0], starPoly.count(), -50, + result = SkOffsetSimplePolygon(starPoly.begin(), starPoly.count(), -50, &offsetPoly); REPORTER_ASSERT(reporter, result); + REPORTER_ASSERT(reporter, SkIsSimplePolygon(offsetPoly.begin(), offsetPoly.count())); - result = SkOffsetSimplePolygon(&starPoly[0], starPoly.count(), -100, + result = SkOffsetSimplePolygon(starPoly.begin(), starPoly.count(), -100, &offsetPoly); REPORTER_ASSERT(reporter, result); + REPORTER_ASSERT(reporter, SkIsSimplePolygon(offsetPoly.begin(), offsetPoly.count())); SkTDArray intersectingPoly; *intersectingPoly.push() = SkPoint::Make(0.0f, -50.0f); @@ -201,6 +186,6 @@ DEF_TEST(OffsetSimplePoly, reporter) { *intersectingPoly.push() = SkPoint::Make(-14.43f, -25.0f); // SkOffsetSimplePolygon now assumes that the input is simple, so we'll just check for that - result = SkIsSimplePolygon(&intersectingPoly[0], intersectingPoly.count()); + result = SkIsSimplePolygon(intersectingPoly.begin(), intersectingPoly.count()); REPORTER_ASSERT(reporter, !result); } diff --git a/tests/PolyUtilsTest.cpp b/tests/PolyUtilsTest.cpp new file mode 100644 index 0000000000..bc5a1a4858 --- /dev/null +++ b/tests/PolyUtilsTest.cpp @@ -0,0 +1,232 @@ +/* + * Copyright 2018 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#include "Test.h" +#include "SkPolyUtils.h" + +DEF_TEST(PolyUtils, reporter) { + + SkTDArray poly; + // init simple index map + uint16_t indexMap[256]; + for (int i = 0; i < 256; ++i) { + indexMap[i] = i; + } + SkTDArray triangleIndices; + + // skinny triangle + *poly.push() = SkPoint::Make(-100, 55); + *poly.push() = SkPoint::Make(100, 55); + *poly.push() = SkPoint::Make(102.5f, 54.330127f); + REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) < 0); + REPORTER_ASSERT(reporter, SkIsConvexPolygon(poly.begin(), poly.count())); + REPORTER_ASSERT(reporter, SkIsSimplePolygon(poly.begin(), poly.count())); + REPORTER_ASSERT(reporter, SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(), + &triangleIndices)); + + // switch winding + poly[2].set(102.5f, 55.330127f); + REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) > 0); + REPORTER_ASSERT(reporter, SkIsConvexPolygon(poly.begin(), poly.count())); + REPORTER_ASSERT(reporter, SkIsSimplePolygon(poly.begin(), poly.count())); + triangleIndices.reset(); + REPORTER_ASSERT(reporter, SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(), + &triangleIndices)); + + // make degenerate + poly[2].set(100 + 2.5f, 55); + REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) == 0); + // TODO: should these fail? + REPORTER_ASSERT(reporter, SkIsConvexPolygon(poly.begin(), poly.count())); + REPORTER_ASSERT(reporter, SkIsSimplePolygon(poly.begin(), poly.count())); + triangleIndices.reset(); + REPORTER_ASSERT(reporter, !SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(), + &triangleIndices)); + + // giant triangle + poly[0].set(-1.0e+37f, 1.0e+37f); + poly[1].set(1.0e+37f, 1.0e+37f); + poly[2].set(-1.0e+37f, -1.0e+37f); + REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) < 0); + REPORTER_ASSERT(reporter, SkIsConvexPolygon(poly.begin(), poly.count())); + REPORTER_ASSERT(reporter, SkIsSimplePolygon(poly.begin(), poly.count())); + triangleIndices.reset(); + REPORTER_ASSERT(reporter, SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(), + &triangleIndices)); + + // teeny triangle + poly[0].set(-1.0e-38f, 1.0e-38f); + poly[1].set(-1.0e-38f, -1.0e-38f); + poly[2].set(1.0e-38f, 1.0e-38f); + REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) == 0); + // TODO: should these fail? + REPORTER_ASSERT(reporter, SkIsConvexPolygon(poly.begin(), poly.count())); + REPORTER_ASSERT(reporter, SkIsSimplePolygon(poly.begin(), poly.count())); + triangleIndices.reset(); + REPORTER_ASSERT(reporter, !SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(), + &triangleIndices)); + + // triangle way off in space (relative to size so we don't completely obliterate values) + poly[0].set(-100 + 1.0e+9f, 55 - 1.0e+9f); + poly[1].set(100 + 1.0e+9f, 55 - 1.0e+9f); + poly[2].set(150 + 1.0e+9f, 100 - 1.0e+9f); + REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) > 0); + REPORTER_ASSERT(reporter, SkIsConvexPolygon(poly.begin(), poly.count())); + REPORTER_ASSERT(reporter, SkIsSimplePolygon(poly.begin(), poly.count())); + triangleIndices.reset(); + REPORTER_ASSERT(reporter, SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(), + &triangleIndices)); + + /////////////////////////////////////////////////////////////////////// + // round rect + poly.reset(); + *poly.push() = SkPoint::Make(-100, 55); + *poly.push() = SkPoint::Make(100, 55); + *poly.push() = SkPoint::Make(100 + 2.5f, 50 + 4.330127f); + *poly.push() = SkPoint::Make(100 + 3.535534f, 50 + 3.535534f); + *poly.push() = SkPoint::Make(100 + 4.330127f, 50 + 2.5f); + *poly.push() = SkPoint::Make(105, 50); + *poly.push() = SkPoint::Make(105, -50); + *poly.push() = SkPoint::Make(100 + 4.330127f, -50 - 2.5f); + *poly.push() = SkPoint::Make(100 + 3.535534f, -50 - 3.535534f); + *poly.push() = SkPoint::Make(100 + 2.5f, -50 - 4.330127f); + *poly.push() = SkPoint::Make(100, -55); + *poly.push() = SkPoint::Make(-100, -55); + *poly.push() = SkPoint::Make(-100 - 2.5f, -50 - 4.330127f); + *poly.push() = SkPoint::Make(-100 - 3.535534f, -50 - 3.535534f); + *poly.push() = SkPoint::Make(-100 - 4.330127f, -50 - 2.5f); + *poly.push() = SkPoint::Make(-105, -50); + *poly.push() = SkPoint::Make(-105, 50); + *poly.push() = SkPoint::Make(-100 - 4.330127f, 50 + 2.5f); + *poly.push() = SkPoint::Make(-100 - 3.535534f, 50 + 3.535534f); + *poly.push() = SkPoint::Make(-100 - 2.5f, 50 + 4.330127f); + REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) < 0); + REPORTER_ASSERT(reporter, SkIsConvexPolygon(poly.begin(), poly.count())); + REPORTER_ASSERT(reporter, SkIsSimplePolygon(poly.begin(), poly.count())); + triangleIndices.reset(); + REPORTER_ASSERT(reporter, SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(), + &triangleIndices)); + + // translate far enough to obliterate some low bits + for (int i = 0; i < poly.count(); ++i) { + poly[i].offset(1.0e+7f, 1.0e+7f); + } + REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) < 0); + // Due to floating point error it's no longer convex + REPORTER_ASSERT(reporter, !SkIsConvexPolygon(poly.begin(), poly.count())); + REPORTER_ASSERT(reporter, SkIsSimplePolygon(poly.begin(), poly.count())); + triangleIndices.reset(); + REPORTER_ASSERT(reporter, SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(), + &triangleIndices)); + + // translate a little farther to create some coincident vertices + for (int i = 0; i < poly.count(); ++i) { + poly[i].offset(4.0e+7f, 4.0e+7f); + } + REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) < 0); + REPORTER_ASSERT(reporter, SkIsConvexPolygon(poly.begin(), poly.count())); + // These can't handle coincident vertices + REPORTER_ASSERT(reporter, !SkIsSimplePolygon(poly.begin(), poly.count())); + triangleIndices.reset(); + REPORTER_ASSERT(reporter, !SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(), + &triangleIndices)); + + // troublesome case -- clipped roundrect + poly.reset(); + *poly.push() = SkPoint::Make(335.928101f, 428.219055f); + *poly.push() = SkPoint::Make(330.414459f, 423.034912f); + *poly.push() = SkPoint::Make(325.749084f, 417.395508f); + *poly.push() = SkPoint::Make(321.931946f, 411.300842f); + *poly.push() = SkPoint::Make(318.963074f, 404.750977f); + *poly.push() = SkPoint::Make(316.842468f, 397.745850f); + *poly.push() = SkPoint::Make(315.570068f, 390.285522f); + *poly.push() = SkPoint::Make(315.145966f, 382.369965f); + *poly.push() = SkPoint::Make(315.570068f, 374.454346f); + *poly.push() = SkPoint::Make(316.842468f, 366.994019f); + *poly.push() = SkPoint::Make(318.963074f, 359.988892f); + *poly.push() = SkPoint::Make(321.931946f, 353.439056f); + *poly.push() = SkPoint::Make(325.749084f, 347.344421f); + *poly.push() = SkPoint::Make(330.414459f, 341.705017f); + *poly.push() = SkPoint::Make(335.928101f, 336.520813f); + *poly.push() = SkPoint::Make(342.289948f, 331.791901f); + *poly.push() = SkPoint::Make(377.312134f, 331.791901f); + *poly.push() = SkPoint::Make(381.195313f, 332.532593f); + *poly.push() = SkPoint::Make(384.464935f, 334.754700f); + *poly.push() = SkPoint::Make(386.687042f, 338.024292f); + *poly.push() = SkPoint::Make(387.427765f, 341.907532f); + *poly.push() = SkPoint::Make(387.427765f, 422.832367f); + *poly.push() = SkPoint::Make(386.687042f, 426.715576f); + *poly.push() = SkPoint::Make(384.464935f, 429.985168f); + *poly.push() = SkPoint::Make(381.195313f, 432.207275f); + *poly.push() = SkPoint::Make(377.312134f, 432.947998f); + *poly.push() = SkPoint::Make(342.289948f, 432.947998f); + REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) > 0); + REPORTER_ASSERT(reporter, SkIsConvexPolygon(poly.begin(), poly.count())); + REPORTER_ASSERT(reporter, SkIsSimplePolygon(poly.begin(), poly.count())); + triangleIndices.reset(); + REPORTER_ASSERT(reporter, SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(), + &triangleIndices)); + + // a star is born + poly.reset(); + *poly.push() = SkPoint::Make(0.0f, -50.0f); + *poly.push() = SkPoint::Make(14.43f, -25.0f); + *poly.push() = SkPoint::Make(43.30f, -25.0f); + *poly.push() = SkPoint::Make(28.86f, 0.0f); + *poly.push() = SkPoint::Make(43.30f, 25.0f); + *poly.push() = SkPoint::Make(14.43f, 25.0f); + *poly.push() = SkPoint::Make(0.0f, 50.0f); + *poly.push() = SkPoint::Make(-14.43f, 25.0f); + *poly.push() = SkPoint::Make(-43.30f, 25.0f); + *poly.push() = SkPoint::Make(-28.86f, 0.0f); + *poly.push() = SkPoint::Make(-43.30f, -25.0f); + *poly.push() = SkPoint::Make(-14.43f, -25.0f); + REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) > 0); + REPORTER_ASSERT(reporter, !SkIsConvexPolygon(poly.begin(), poly.count())); + REPORTER_ASSERT(reporter, SkIsSimplePolygon(poly.begin(), poly.count())); + triangleIndices.reset(); + REPORTER_ASSERT(reporter, SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(), + &triangleIndices)); + + // self-intersecting polygon + poly.reset(); + *poly.push() = SkPoint::Make(0.0f, -50.0f); + *poly.push() = SkPoint::Make(14.43f, -25.0f); + *poly.push() = SkPoint::Make(43.30f, -25.0f); + *poly.push() = SkPoint::Make(-28.86f, 0.0f); + *poly.push() = SkPoint::Make(43.30f, 25.0f); + *poly.push() = SkPoint::Make(14.43f, 25.0f); + *poly.push() = SkPoint::Make(0.0f, 50.0f); + *poly.push() = SkPoint::Make(-14.43f, 25.0f); + *poly.push() = SkPoint::Make(-43.30f, 25.0f); + *poly.push() = SkPoint::Make(28.86f, 0.0f); + *poly.push() = SkPoint::Make(-43.30f, -25.0f); + *poly.push() = SkPoint::Make(-14.43f, -25.0f); + REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) > 0); + REPORTER_ASSERT(reporter, !SkIsConvexPolygon(poly.begin(), poly.count())); + REPORTER_ASSERT(reporter, !SkIsSimplePolygon(poly.begin(), poly.count())); + triangleIndices.reset(); + // running this just to make sure it doesn't crash + // the fact that it succeeds doesn't mean anything since the input is not simple + REPORTER_ASSERT(reporter, SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(), + &triangleIndices)); + + // self-intersecting polygon with coincident point + poly.reset(); + *poly.push() = SkPoint::Make(0.0f, 0.0f); + *poly.push() = SkPoint::Make(-50, -50); + *poly.push() = SkPoint::Make(50, -50); + *poly.push() = SkPoint::Make(0.00000001f, -0.00000001f); + *poly.push() = SkPoint::Make(-50, 50); + *poly.push() = SkPoint::Make(50, 50); + REPORTER_ASSERT(reporter, SkGetPolygonWinding(poly.begin(), poly.count()) == 0); + REPORTER_ASSERT(reporter, !SkIsConvexPolygon(poly.begin(), poly.count())); + REPORTER_ASSERT(reporter, !SkIsSimplePolygon(poly.begin(), poly.count())); + triangleIndices.reset(); + // running this just to make sure it doesn't crash + REPORTER_ASSERT(reporter, !SkTriangulateSimplePolygon(poly.begin(), indexMap, poly.count(), + &triangleIndices)); +} -- cgit v1.2.3