aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkPath.cpp
diff options
context:
space:
mode:
authorGravatar caryclark <caryclark@google.com>2015-04-08 08:34:15 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-04-08 08:34:15 -0700
commit95bc5f349561fef2d6fbae71adb08cf5c2eec0c9 (patch)
tree997d651f63e2aba803e7494852b72a9042a7eba6 /src/core/SkPath.cpp
parent929f63feccf500283571077586dbbd69c206bf13 (diff)
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
Diffstat (limited to 'src/core/SkPath.cpp')
-rw-r--r--src/core/SkPath.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp
index 76e70d99cf..19e7048869 100644
--- a/src/core/SkPath.cpp
+++ b/src/core/SkPath.cpp
@@ -396,13 +396,16 @@ bool SkPath::isRectContour(bool allowPartial, int* currVerb, const SkPoint** pts
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 @@ bool SkPath::isRectContour(bool allowPartial, int* currVerb, const SkPoint** pts
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 @@ bool SkPath::isRectContour(bool allowPartial, int* currVerb, const SkPoint** pts
}
*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 @@ bool SkPath::isRect(SkRect* rect, bool* isClosed, Direction* direction) const {
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 @@ bool SkPath::isNestedRects(SkRect rects[2], Direction dirs[2]) const {
}
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) {