diff --git a/tests/PathTest.cpp b/tests/PathTest.cpp index 4d00f70db..82f230dd5 100644 --- a/tests/PathTest.cpp +++ b/tests/PathTest.cpp @@ -3,6 +3,101 @@ #include "SkParse.h" #include "SkSize.h" +static void check_convexity(skiatest::Reporter* reporter, const SkPath& path, + SkPath::Convexity expected) { + SkPath::Convexity c = SkPath::ComputeConvexity(path); + REPORTER_ASSERT(reporter, c == expected); +} + +static void test_convexity2(skiatest::Reporter* reporter) { + SkPath pt; + pt.moveTo(0, 0); + pt.close(); +// check_convexity(reporter, pt, SkPath::kConvex_Convexity); + check_convexity(reporter, pt, SkPath::kUnknown_Convexity); + + SkPath line; + line.moveTo(12, 20); + line.lineTo(-12, -20); + line.close(); + // check_convexity(reporter, pt, SkPath::kConvex_Convexity); + check_convexity(reporter, pt, SkPath::kUnknown_Convexity); + + SkPath triLeft; + triLeft.moveTo(0, 0); + triLeft.lineTo(1, 0); + triLeft.lineTo(1, 1); + triLeft.close(); + check_convexity(reporter, triLeft, SkPath::kConvex_Convexity); + + SkPath triRight; + triRight.moveTo(0, 0); + triRight.lineTo(-1, 0); + triRight.lineTo(1, 1); + triRight.close(); + check_convexity(reporter, triRight, SkPath::kConvex_Convexity); + + SkPath square; + square.moveTo(0, 0); + square.lineTo(1, 0); + square.lineTo(1, 1); + square.lineTo(0, 1); + square.close(); + check_convexity(reporter, square, SkPath::kConvex_Convexity); + + SkPath redundantSquare; + redundantSquare.moveTo(0, 0); + redundantSquare.lineTo(0, 0); + redundantSquare.lineTo(0, 0); + redundantSquare.lineTo(1, 0); + redundantSquare.lineTo(1, 0); + redundantSquare.lineTo(1, 0); + redundantSquare.lineTo(1, 1); + redundantSquare.lineTo(1, 1); + redundantSquare.lineTo(1, 1); + redundantSquare.lineTo(0, 1); + redundantSquare.lineTo(0, 1); + redundantSquare.lineTo(0, 1); + redundantSquare.close(); + check_convexity(reporter, redundantSquare, SkPath::kConvex_Convexity); + + SkPath bowTie; + bowTie.moveTo(0, 0); + bowTie.lineTo(0, 0); + bowTie.lineTo(0, 0); + bowTie.lineTo(1, 1); + bowTie.lineTo(1, 1); + bowTie.lineTo(1, 1); + bowTie.lineTo(1, 0); + bowTie.lineTo(1, 0); + bowTie.lineTo(1, 0); + bowTie.lineTo(0, 1); + bowTie.lineTo(0, 1); + bowTie.lineTo(0, 1); + bowTie.close(); + check_convexity(reporter, bowTie, SkPath::kConcave_Convexity); + + SkPath spiral; + spiral.moveTo(0, 0); + spiral.lineTo(1, 0); + spiral.lineTo(1, 1); + spiral.lineTo(0, 1); + spiral.lineTo(0,.5); + spiral.lineTo(.5,.5); + spiral.lineTo(.5,.75); + spiral.close(); +// check_convexity(reporter, spiral, SkPath::kConcave_Convexity); + + SkPath dent; + dent.moveTo(0, 0); + dent.lineTo(1, 1); + dent.lineTo(0, 1); + dent.lineTo(-.5,2); + dent.lineTo(-2, 1); + dent.close(); + check_convexity(reporter, dent, SkPath::kConcave_Convexity); +} + static void check_convex_bounds(skiatest::Reporter* reporter, const SkPath& p, const SkRect& bounds) { REPORTER_ASSERT(reporter, p.isConvex()); @@ -163,6 +258,7 @@ void TestPath(skiatest::Reporter* reporter) { REPORTER_ASSERT(reporter, !p.isConvex()); test_convexity(reporter); + test_convexity2(reporter); } #include "TestClassDef.h"