change isNestedRect to isNestedFillRect
R=reed@google.com, bsalomon@google.com
Let isNested(Fill)Rect return true if drawn path describes filled
rectangles.
Review URL: https://codereview.chromium.org/1073473002
diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp
index 76e70d9..19e7048 100644
--- a/src/core/SkPath.cpp
+++ b/src/core/SkPath.cpp
@@ -396,13 +396,16 @@
int nextDirection = 0;
bool closedOrMoved = false;
bool autoClose = false;
+ bool insertClose = false;
int verbCnt = fPathRef->countVerbs();
while (*currVerb < verbCnt && (!allowPartial || !autoClose)) {
- switch (fPathRef->atVerb(*currVerb)) {
+ uint8_t verb = insertClose ? (uint8_t) kClose_Verb : fPathRef->atVerb(*currVerb);
+ switch (verb) {
case kClose_Verb:
savePts = pts;
pts = *ptsPtr;
autoClose = true;
+ insertClose = false;
case kLine_Verb: {
SkScalar left = last.fX;
SkScalar top = last.fY;
@@ -455,6 +458,11 @@
case kCubic_Verb:
return false; // quadratic, cubic not allowed
case kMove_Verb:
+ if (allowPartial && !autoClose && firstDirection) {
+ insertClose = true;
+ *currVerb -= 1; // try move again afterwards
+ goto addMissingClose;
+ }
last = *pts++;
closedOrMoved = true;
break;
@@ -464,6 +472,8 @@
}
*currVerb += 1;
lastDirection = nextDirection;
+addMissingClose:
+ ;
}
// Success if 4 corners and first point equals last
bool result = 4 == corners && (first == last || autoClose);
@@ -518,7 +528,7 @@
return true;
}
-bool SkPath::isNestedRects(SkRect rects[2], Direction dirs[2]) const {
+bool SkPath::isNestedFillRects(SkRect rects[2], Direction dirs[2]) const {
SkDEBUGCODE(this->validate();)
int currVerb = 0;
const SkPoint* pts = fPathRef->points();
@@ -529,8 +539,12 @@
}
const SkPoint* last = pts;
SkRect testRects[2];
- if (isRectContour(false, &currVerb, &pts, NULL, &testDirs[1])) {
+ bool isClosed;
+ if (isRectContour(false, &currVerb, &pts, &isClosed, &testDirs[1])) {
testRects[0].set(first, SkToS32(last - first));
+ if (!isClosed) {
+ pts = fPathRef->points() + fPathRef->countPoints();
+ }
testRects[1].set(last, SkToS32(pts - last));
if (testRects[0].contains(testRects[1])) {
if (rects) {