detect more than one loop in computeconvexity

git-svn-id: http://skia.googlecode.com/svn/trunk@1326 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2011-05-15 20:25:17 +00:00
parent 7c42481c9d
commit 85b6e399d5
2 changed files with 20 additions and 2 deletions

View File

@ -1401,12 +1401,16 @@ static int SkScalarSign(SkScalar value) {
return value < 0 ? -1 : (value > 0);
}
static int sign(SkScalar x) { return x < 0 ? -1 : 1; }
static int CrossProductSign(const SkVector& a, const SkVector& b) {
return SkScalarSign(SkPoint::CrossProduct(a, b));
}
// only valid for a single contour
struct Convexicator {
int fDx, fDy, fSx, fSy;
Convexicator() : fPtCount(0), fConvexity(SkPath::kUnknown_Convexity) {
fSign = 0;
// warnings
@ -1414,6 +1418,9 @@ struct Convexicator {
fVec0.set(0, 0);
fVec1.set(0, 0);
fFirstVec.set(0, 0);
fDx = fDy = 0;
fSx = fSy = 2;
}
SkPath::Convexity getConvexity() const { return fConvexity; }
@ -1436,6 +1443,17 @@ struct Convexicator {
SkASSERT(fPtCount > 2);
this->addVec(vec);
}
int sx = sign(vec.fX);
int sy = sign(vec.fY);
fDx += (sx != fSx);
fDy += (sy != fSy);
fSx = sx;
fSy = sy;
if (fDx > 3 || fDy > 3) {
fConvexity = SkPath::kConcave_Convexity;
}
}
}
}

View File

@ -86,7 +86,7 @@ static void test_convexity2(skiatest::Reporter* reporter) {
spiral.lineTo(.5,.5);
spiral.lineTo(.5,.75);
spiral.close();
// check_convexity(reporter, spiral, SkPath::kConcave_Convexity);
check_convexity(reporter, spiral, SkPath::kConcave_Convexity);
SkPath dent;
dent.moveTo(0, 0);
@ -157,7 +157,7 @@ static void test_convexity(skiatest::Reporter* reporter) {
} gRec[] = {
{ "0 0", SkPath::kUnknown_Convexity },
{ "0 0 10 10", SkPath::kUnknown_Convexity },
{ "0 0 10 10 20 20 0 0 10 10", SkPath::kUnknown_Convexity },
{ "0 0 10 10 20 20 0 0 10 10", SkPath::kConcave_Convexity },
{ "0 0 10 10 10 20", SkPath::kConvex_Convexity },
{ "0 0 10 10 10 0", SkPath::kConvex_Convexity },
{ "0 0 10 10 10 0 0 10", SkPath::kConcave_Convexity },