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
diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp
index de3bb2e..7256021 100644
--- a/src/core/SkPath.cpp
+++ b/src/core/SkPath.cpp
@@ -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 @@
fPath->fBounds = fRect;
fPath->fBoundsIsDirty = false;
} else if (!fDirty) {
- fPath->fBounds.join(fRect);
+ joinNoEmptyChecks(&fPath->fBounds, fRect);
fPath->fBoundsIsDirty = false;
}
}
@@ -1437,7 +1449,9 @@
if (bounds.isEmpty()) {
SkASSERT(fBounds.isEmpty());
} else {
- SkASSERT(fBounds.contains(bounds));
+ if (!fBounds.isEmpty()) {
+ SkASSERT(fBounds.contains(bounds));
+ }
}
}
}
diff --git a/tests/PathTest.cpp b/tests/PathTest.cpp
index b869329..5e9a520 100644
--- a/tests/PathTest.cpp
+++ b/tests/PathTest.cpp
@@ -23,10 +23,10 @@
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 @@
test_flattening(reporter);
test_transform(reporter);
-// test_bounds(reporter);
+ test_bounds(reporter);
}
#include "TestClassDef.h"