aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Cary Clark <caryclark@skia.org>2018-04-18 12:25:08 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-04-18 17:46:03 +0000
commitb120e9291a7d43347ebce89de522a15771cd9dea (patch)
tree77a2153ecda21fadfba3f13d90a888e44a43d587
parent1ccaa6e056296db61eb1af2668a23995fe98e6b3 (diff)
fix path is rect flaw exposed by gold
One of the path is rect bug fixes changed the behavior of zero-length strokes which showed up as a change in Gold. The bug is if a rect is defined by a series of colinear movetos, the bounds did not work out if the rect started and stopped in the middle of a side. R=robertphillips@google.com Bug: 824145,skia:7792 Change-Id: I226545efeda03dedd928eebc120d2508b428fef0 Reviewed-on: https://skia-review.googlesource.com/122002 Auto-Submit: Cary Clark <caryclark@skia.org> Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Cary Clark <caryclark@skia.org>
-rw-r--r--gm/pathfill.cpp12
-rw-r--r--src/core/SkPath.cpp9
-rw-r--r--tests/PathTest.cpp36
3 files changed, 41 insertions, 16 deletions
diff --git a/gm/pathfill.cpp b/gm/pathfill.cpp
index ebe6d4a340..23fd5302ae 100644
--- a/gm/pathfill.cpp
+++ b/gm/pathfill.cpp
@@ -576,4 +576,16 @@ DEF_SIMPLE_GM(bug7792, canvas, 800, 800) {
path.lineTo(75, 150);
path.lineTo(75, 100);
canvas->drawPath(path, p);
+ // from zero_length_paths_aa
+ canvas->translate(0, 200);
+ path.reset();
+ path.moveTo(150, 100);
+ path.lineTo(150, 100);
+ path.lineTo(150, 150);
+ path.lineTo(75, 150);
+ path.lineTo(75, 100);
+ path.lineTo(75, 75);
+ path.lineTo(150, 75);
+ path.close();
+ canvas->drawPath(path, p);
}
diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp
index 7110a3086a..0bfeae1d91 100644
--- a/src/core/SkPath.cpp
+++ b/src/core/SkPath.cpp
@@ -506,6 +506,9 @@ bool SkPath::isRectContour(bool allowPartial, int* currVerb, const SkPoint** pts
closedOrMoved = autoClose;
lineStart = lineEnd;
if (directions[corners - 1] == nextDirection) {
+ if (3 == corners && kLine_Verb == verb) {
+ lastCountedPt = lastPt;
+ }
break; // colinear segment
}
if (corners >= 4) {
@@ -513,12 +516,12 @@ bool SkPath::isRectContour(bool allowPartial, int* currVerb, const SkPoint** pts
}
directions[corners++] = nextDirection;
// opposite lines must point in opposite directions; xoring them should equal 2
- if (corners == 3) {
+ if (3 == corners) {
if ((directions[0] ^ directions[2]) != 2) {
return false;
}
accumulatingRect = false;
- } else if (corners == 4) {
+ } else if (4 == corners) {
if ((directions[1] ^ directions[3]) != 2) {
return false;
}
@@ -575,7 +578,7 @@ addMissingClose:
//
int closeDirection = rect_make_dir(closeXY.fX, closeXY.fY);
// make sure the close-segment doesn't double-back on itself
- if (3 == corners || (closeDirection ^ directions[1]) == 2) {
+ if (3 == corners || 2 == (closeDirection ^ directions[1])) {
result = true;
autoClose = false; // we are not closed
}
diff --git a/tests/PathTest.cpp b/tests/PathTest.cpp
index 611393becd..b108b7f1bf 100644
--- a/tests/PathTest.cpp
+++ b/tests/PathTest.cpp
@@ -4934,18 +4934,18 @@ DEF_TEST(Path_isRect, reporter) {
SkRect rect;
SkPoint points[] = { {10, 10}, {75, 75}, {150, 75}, {150, 150}, {75, 150} };
SkPath path = makePath(points, SK_ARRAY_COUNT(points), false);
- REPORTER_ASSERT(reporter, path.isRect(&rect, nullptr, nullptr));
+ REPORTER_ASSERT(reporter, path.isRect(&rect));
SkRect compare;
compare.set(&points[1], SK_ARRAY_COUNT(points) - 1);
REPORTER_ASSERT(reporter, rect == compare);
// isolated from skbug.com/7792#c3
SkPoint points3[] = { {75, 50}, {100, 75}, {150, 75}, {150, 150}, {75, 150}, {75, 50} };
path = makePath(points3, SK_ARRAY_COUNT(points3), true);
- REPORTER_ASSERT(reporter, !path.isRect(&rect, nullptr, nullptr));
+ REPORTER_ASSERT(reporter, !path.isRect(&rect));
// isolated from skbug.com/7792#c9
SkPoint points9[] = { {10, 10}, {75, 75}, {150, 75}, {150, 150}, {75, 150} };
path = makePath(points9, SK_ARRAY_COUNT(points9), true);
- REPORTER_ASSERT(reporter, path.isRect(&rect, nullptr, nullptr));
+ REPORTER_ASSERT(reporter, path.isRect(&rect));
compare.set(&points9[1], SK_ARRAY_COUNT(points9) - 1);
REPORTER_ASSERT(reporter, rect == compare);
// isolated from skbug.com/7792#c11
@@ -4953,7 +4953,7 @@ DEF_TEST(Path_isRect, reporter) {
SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kMove_Verb };
SkPoint points11[] = { {75, 150}, {75, 75}, {150, 75}, {150, 150}, {75, 150}, {75, 150} };
path = makePath2(points11, verbs11, SK_ARRAY_COUNT(verbs11));
- REPORTER_ASSERT(reporter, path.isRect(&rect, nullptr, nullptr));
+ REPORTER_ASSERT(reporter, path.isRect(&rect));
compare.set(&points11[0], SK_ARRAY_COUNT(points11));
REPORTER_ASSERT(reporter, rect == compare);
// isolated from skbug.com/7792#c14
@@ -4964,19 +4964,19 @@ DEF_TEST(Path_isRect, reporter) {
SkPoint points14[] = { {250, 75}, {250, 75}, {250, 75}, {100, 75},
{150, 75}, {150, 150}, {75, 150}, {75, 75}, {0, 0} };
path = makePath2(points14, verbs14, SK_ARRAY_COUNT(verbs14));
- REPORTER_ASSERT(reporter, !path.isRect(&rect, nullptr, nullptr));
+ REPORTER_ASSERT(reporter, !path.isRect(&rect));
// isolated from skbug.com/7792#c15
SkPath::Verb verbs15[] = { SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb,
SkPath::kLine_Verb, SkPath::kMove_Verb };
SkPoint points15[] = { {75, 75}, {150, 75}, {150, 150}, {75, 150}, {250, 75} };
path = makePath2(points15, verbs15, SK_ARRAY_COUNT(verbs15));
- REPORTER_ASSERT(reporter, path.isRect(&rect, nullptr, nullptr));
+ REPORTER_ASSERT(reporter, path.isRect(&rect));
compare.set(&points15[0], SK_ARRAY_COUNT(points15) - 1);
REPORTER_ASSERT(reporter, rect == compare);
// isolated from skbug.com/7792#c17
SkPoint points17[] = { {75, 10}, {75, 75}, {150, 75}, {150, 150}, {75, 150}, {75, 10} };
path = makePath(points17, SK_ARRAY_COUNT(points17), true);
- REPORTER_ASSERT(reporter, !path.isRect(&rect, nullptr, nullptr));
+ REPORTER_ASSERT(reporter, !path.isRect(&rect));
// isolated from skbug.com/7792#c19
SkPath::Verb verbs19[] = { SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb,
SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb,
@@ -4985,7 +4985,7 @@ DEF_TEST(Path_isRect, reporter) {
SkPoint points19[] = { {75, 75}, {75, 75}, {75, 75}, {75, 75}, {150, 75}, {150, 150},
{75, 150}, {10, 10}, {30, 10}, {10, 30} };
path = makePath2(points19, verbs19, SK_ARRAY_COUNT(verbs19));
- REPORTER_ASSERT(reporter, !path.isRect(&rect, nullptr, nullptr));
+ REPORTER_ASSERT(reporter, !path.isRect(&rect));
// isolated from skbug.com/7792#c23
SkPath::Verb verbs23[] = { SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kMove_Verb,
SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb,
@@ -4993,7 +4993,7 @@ DEF_TEST(Path_isRect, reporter) {
SkPoint points23[] = { {75, 75}, {75, 75}, {75, 75}, {75, 75}, {150, 75}, {150, 150},
{75, 150} };
path = makePath2(points23, verbs23, SK_ARRAY_COUNT(verbs23));
- REPORTER_ASSERT(reporter, path.isRect(&rect, nullptr, nullptr));
+ REPORTER_ASSERT(reporter, path.isRect(&rect));
compare.set(&points23[0], SK_ARRAY_COUNT(points23));
REPORTER_ASSERT(reporter, rect == compare);
// isolated from skbug.com/7792#c29
@@ -5002,14 +5002,14 @@ DEF_TEST(Path_isRect, reporter) {
SkPath::kClose_Verb };
SkPoint points29[] = { {75, 75}, {150, 75}, {150, 150}, {75, 150}, {75, 250}, {75, 75} };
path = makePath2(points29, verbs29, SK_ARRAY_COUNT(verbs29));
- REPORTER_ASSERT(reporter, !path.isRect(&rect, nullptr, nullptr));
+ REPORTER_ASSERT(reporter, !path.isRect(&rect));
// isolated from skbug.com/7792#c31
SkPath::Verb verbs31[] = { SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb,
SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kMove_Verb,
SkPath::kClose_Verb };
SkPoint points31[] = { {75, 75}, {150, 75}, {150, 150}, {75, 150}, {75, 10}, {75, 75} };
path = makePath2(points31, verbs31, SK_ARRAY_COUNT(verbs31));
- REPORTER_ASSERT(reporter, path.isRect(&rect, nullptr, nullptr));
+ REPORTER_ASSERT(reporter, path.isRect(&rect));
compare.set(&points31[0], 4);
REPORTER_ASSERT(reporter, rect == compare);
// isolated from skbug.com/7792#c36
@@ -5017,11 +5017,21 @@ DEF_TEST(Path_isRect, reporter) {
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));
+ REPORTER_ASSERT(reporter, !path.isRect(&rect));
// isolated from skbug.com/7792#c39
SkPath::Verb verbs39[] = { SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb,
SkPath::kLine_Verb };
SkPoint points39[] = { {150, 75}, {150, 150}, {75, 150}, {75, 100} };
path = makePath2(points39, verbs39, SK_ARRAY_COUNT(verbs39));
- REPORTER_ASSERT(reporter, !path.isRect(&rect, nullptr, nullptr));
+ REPORTER_ASSERT(reporter, !path.isRect(&rect));
+ // from zero_length_paths_aa
+ SkPath::Verb verbsAA[] = { SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb,
+ SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb,
+ SkPath::kLine_Verb, SkPath::kClose_Verb };
+ SkPoint pointsAA[] = { {32, 9.5f}, {32, 9.5f}, {32, 17}, {17, 17}, {17, 9.5f}, {17, 2},
+ {32, 2} };
+ path = makePath2(pointsAA, verbsAA, SK_ARRAY_COUNT(verbsAA));
+ REPORTER_ASSERT(reporter, path.isRect(&rect));
+ compare.set(&pointsAA[0], SK_ARRAY_COUNT(pointsAA));
+ REPORTER_ASSERT(reporter, rect == compare);
}