migrate more tests from GrPath.cpp

git-svn-id: http://skia.googlecode.com/svn/trunk@1325 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2011-05-15 04:38:34 +00:00
Родитель 04863fa14a
Коммит 7c42481c9d
1 изменённых файлов: 96 добавлений и 0 удалений

Просмотреть файл

@ -3,6 +3,101 @@
#include "SkParse.h" #include "SkParse.h"
#include "SkSize.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, static void check_convex_bounds(skiatest::Reporter* reporter, const SkPath& p,
const SkRect& bounds) { const SkRect& bounds) {
REPORTER_ASSERT(reporter, p.isConvex()); REPORTER_ASSERT(reporter, p.isConvex());
@ -163,6 +258,7 @@ void TestPath(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, !p.isConvex()); REPORTER_ASSERT(reporter, !p.isConvex());
test_convexity(reporter); test_convexity(reporter);
test_convexity2(reporter);
} }
#include "TestClassDef.h" #include "TestClassDef.h"