fix autobounds dude to call a custom version of rect.join that doesn't ignore

empty rects (since path.bounds must be the bounds of its control-pts, including
empty subcontours)



git-svn-id: http://skia.googlecode.com/svn/trunk@2679 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2011-11-14 19:34:57 +00:00
parent 1dcf506a1a
commit 3563c9ee52
2 changed files with 21 additions and 7 deletions

View File

@ -14,6 +14,18 @@
////////////////////////////////////////////////////////////////////////////
/**
* Path.bounds is defined to be the bounds of all the control points.
* If we called bounds.join(r) we would skip r if r was empty, which breaks
* our promise. Hence we have a custom joiner that doesn't look at emptiness
*/
static void joinNoEmptyChecks(SkRect* dst, const SkRect& src) {
dst->fLeft = SkMinScalar(dst->fLeft, src.fLeft);
dst->fTop = SkMinScalar(dst->fTop, src.fTop);
dst->fRight = SkMaxScalar(dst->fRight, src.fRight);
dst->fBottom = SkMaxScalar(dst->fBottom, src.fBottom);
}
/* This guy's constructor/destructor bracket a path editing operation. It is
used when we know the bounds of the amount we are going to add to the path
(usually a new contour, but not required).
@ -43,7 +55,7 @@ public:
fPath->fBounds = fRect;
fPath->fBoundsIsDirty = false;
} else if (!fDirty) {
fPath->fBounds.join(fRect);
joinNoEmptyChecks(&fPath->fBounds, fRect);
fPath->fBoundsIsDirty = false;
}
}
@ -1437,7 +1449,9 @@ void SkPath::validate() const {
if (bounds.isEmpty()) {
SkASSERT(fBounds.isEmpty());
} else {
SkASSERT(fBounds.contains(bounds));
if (!fBounds.isEmpty()) {
SkASSERT(fBounds.contains(bounds));
}
}
}
}

View File

@ -23,10 +23,10 @@ static void add_rect(SkPath* path, const SkRect& r) {
static void test_bounds(skiatest::Reporter* reporter) {
static const SkRect rects[] = {
{ 10, 160, 610, 160 },
{ 610, 160, 610, 199 },
{ 10, 198, 610, 199 },
{ 10, 160, 10, 199 },
{ SkIntToScalar(10), SkIntToScalar(160), SkIntToScalar(610), SkIntToScalar(160) },
{ SkIntToScalar(610), SkIntToScalar(160), SkIntToScalar(610), SkIntToScalar(199) },
{ SkIntToScalar(10), SkIntToScalar(198), SkIntToScalar(610), SkIntToScalar(199) },
{ SkIntToScalar(10), SkIntToScalar(160), SkIntToScalar(10), SkIntToScalar(199) },
};
SkPath path0, path1;
@ -617,7 +617,7 @@ void TestPath(skiatest::Reporter* reporter) {
test_flattening(reporter);
test_transform(reporter);
// test_bounds(reporter);
test_bounds(reporter);
}
#include "TestClassDef.h"