aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/core/SkPath.cpp17
-rw-r--r--tests/PathTest.cpp14
2 files changed, 27 insertions, 4 deletions
diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp
index cee93d352e..f8aa8521da 100644
--- a/src/core/SkPath.cpp
+++ b/src/core/SkPath.cpp
@@ -538,11 +538,20 @@ bool SkPath::isRect(SkRect* rect) const {
SkDEBUGCODE(this->validate();)
int currVerb = 0;
const SkPoint* pts = fPathRef->points();
- bool result = isRectContour(false, &currVerb, &pts, NULL, NULL);
- if (result && rect) {
- *rect = getBounds();
+ const SkPoint* first = pts;
+ bool isClosed;
+ if (!this->isRectContour(false, &currVerb, &pts, &isClosed, NULL)) {
+ return false;
}
- return result;
+ if (rect) {
+ if (isClosed) {
+ rect->set(first, SkToS32(pts - first));
+ } else {
+ // 'pts' isn't updated for open rects
+ *rect = this->getBounds();
+ }
+ }
+ return true;
}
bool SkPath::isRect(bool* isClosed, Direction* direction) const {
diff --git a/tests/PathTest.cpp b/tests/PathTest.cpp
index 2ec54d79fa..960cdc3b16 100644
--- a/tests/PathTest.cpp
+++ b/tests/PathTest.cpp
@@ -3712,6 +3712,20 @@ DEF_TEST(Paths, reporter) {
p.addRect(bounds);
REPORTER_ASSERT(reporter, !p.isRect(NULL));
+ // Test an edge case w.r.t. the bound returned by isRect (i.e., the
+ // path has a trailing moveTo. Please see crbug.com\445368)
+ {
+ SkRect r;
+ p.reset();
+ p.addRect(bounds);
+ REPORTER_ASSERT(reporter, p.isRect(&r));
+ REPORTER_ASSERT(reporter, r == bounds);
+ // add a moveTo outside of our bounds
+ p.moveTo(bounds.fLeft + 10, bounds.fBottom + 10);
+ REPORTER_ASSERT(reporter, p.isRect(&r));
+ REPORTER_ASSERT(reporter, r == bounds);
+ }
+
test_operatorEqual(reporter);
test_isLine(reporter);
test_isRect(reporter);