path is rect bug number twelve

Exposes that final close along a diagonal need not
include a close verb if the subsequent verb is move;
so we have to check for a diagonal then.

The later check for diagonal included a comment that
it may not be needed which does appear to be the case.

R=robertphillips@google.com
Bug: 824145,skia:7792
Change-Id: I17a9414e8b3e69b82c2eda28195696eae4e3d513
Reviewed-on: https://skia-review.googlesource.com/121801
Commit-Queue: Cary Clark <caryclark@skia.org>
Commit-Queue: Robert Phillips <robertphillips@google.com>
Auto-Submit: Cary Clark <caryclark@skia.org>
Reviewed-by: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Cary Clark 2018-04-17 11:53:34 -04:00 committed by Skia Commit-Bot
parent a580fb3f9e
commit 1cd6098d52
3 changed files with 22 additions and 4 deletions

View File

@ -558,4 +558,14 @@ DEF_SIMPLE_GM(bug7792, canvas, 600, 800) {
path.moveTo(75, 75); path.moveTo(75, 75);
path.close(); path.close();
canvas->drawPath(path, p); canvas->drawPath(path, p);
// from skbug.com/7792#c36
canvas->translate(200, 0);
path.reset();
path.moveTo(75, 75);
path.lineTo(150, 75);
path.lineTo(150, 150);
path.lineTo(10, 150);
path.moveTo(75, 75);
path.lineTo(75, 75);
canvas->drawPath(path, p);
} }

View File

@ -450,6 +450,7 @@ static int rect_make_dir(SkScalar dx, SkScalar dy) {
bool SkPath::isRectContour(bool allowPartial, int* currVerb, const SkPoint** ptsPtr, bool SkPath::isRectContour(bool allowPartial, int* currVerb, const SkPoint** ptsPtr,
bool* isClosed, Direction* direction, SkRect* rect) const { bool* isClosed, Direction* direction, SkRect* rect) const {
int corners = 0; int corners = 0;
SkPoint closeXY; // used to determine if final line falls on a diagonal
SkPoint lineStart; // used to construct line from previous point SkPoint lineStart; // used to construct line from previous point
const SkPoint* firstPt = nullptr; // first point in the rect (last of first moves) const SkPoint* firstPt = nullptr; // first point in the rect (last of first moves)
const SkPoint* lastPt = nullptr; // last point in the rect (last of lines or first if closed) const SkPoint* lastPt = nullptr; // last point in the rect (last of lines or first if closed)
@ -538,6 +539,10 @@ bool SkPath::isRectContour(bool allowPartial, int* currVerb, const SkPoint** pts
firstPt = pts; firstPt = pts;
accumulatingRect = true; accumulatingRect = true;
} else { } else {
closeXY = *firstPt - *lastPt;
if (closeXY.fX && closeXY.fY) {
return false; // we're diagonal, abort
}
accumulatingRect = false; accumulatingRect = false;
} }
lineStart = *pts++; lineStart = *pts++;
@ -555,7 +560,7 @@ addMissingClose:
if (corners < 3 || corners > 4) { if (corners < 3 || corners > 4) {
return false; return false;
} }
SkPoint closeXY = *firstPt - *lastPt; closeXY = *firstPt - *lastPt;
// If autoClose, check if close generates diagonal // If autoClose, check if close generates diagonal
bool result = 4 == corners && (closeXY.isZero() || (autoClose && (!closeXY.fX || !closeXY.fY))); bool result = 4 == corners && (closeXY.isZero() || (autoClose && (!closeXY.fX || !closeXY.fY)));
if (!result) { if (!result) {
@ -565,9 +570,6 @@ addMissingClose:
// 3 sided rectangle // 3 sided rectangle
// 4 sided but the last edge is not long enough to reach the start // 4 sided but the last edge is not long enough to reach the start
// //
if (closeXY.fX && closeXY.fY) {
return false; // we're diagonal, abort (can we ever reach this?)
}
int closeDirection = rect_make_dir(closeXY.fX, closeXY.fY); int closeDirection = rect_make_dir(closeXY.fX, closeXY.fY);
// make sure the close-segment doesn't double-back on itself // make sure the close-segment doesn't double-back on itself
if (3 == corners || (closeDirection ^ directions[1]) == 2) { if (3 == corners || (closeDirection ^ directions[1]) == 2) {

View File

@ -5012,4 +5012,10 @@ DEF_TEST(Path_isRect, reporter) {
REPORTER_ASSERT(reporter, path.isRect(&rect, nullptr, nullptr)); REPORTER_ASSERT(reporter, path.isRect(&rect, nullptr, nullptr));
compare.set(&points31[0], 4); compare.set(&points31[0], 4);
REPORTER_ASSERT(reporter, rect == compare); REPORTER_ASSERT(reporter, rect == compare);
// isolated from skbug.com/7792#c36
SkPath::Verb verbs36[] = { SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb,
SkPath::kLine_Verb, SkPath::kMove_Verb, SkPath::kLine_Verb };
SkPoint points36[] = { {75, 75}, {150, 75}, {150, 150}, {10, 150}, {75, 75}, {75, 75} };
path = makePath2(points36, verbs36, SK_ARRAY_COUNT(verbs36));
REPORTER_ASSERT(reporter, !path.isRect(&rect, nullptr, nullptr));
} }