diff options
author | 2013-08-01 15:35:06 +0000 | |
---|---|---|
committer | 2013-08-01 15:35:06 +0000 | |
commit | 62df526042f8a753c6817ba9d809ff8dfc412d4a (patch) | |
tree | 7ccc808282b8d2bd68e744e19823658dd0989a1a | |
parent | d4c3565aac5c83ff0008453abed4c6d6009bb394 (diff) |
Make SkPath::conservativelyContainsRect not assert on paths that begin with repeated moveTos
R=reed@google.com
Author: bsalomon@google.com
Review URL: https://chromiumcodereview.appspot.com/21565002
git-svn-id: http://skia.googlecode.com/svn/trunk@10484 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | src/core/SkPath.cpp | 14 | ||||
-rw-r--r-- | tests/PathTest.cpp | 12 |
2 files changed, 22 insertions, 4 deletions
diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp index b28518425e..d1e4d79179 100644 --- a/src/core/SkPath.cpp +++ b/src/core/SkPath.cpp @@ -301,29 +301,35 @@ bool SkPath::conservativelyContainsRect(const SkRect& rect) const { SkPath::Verb verb; SkPoint pts[4]; SkDEBUGCODE(int moveCnt = 0;) + SkDEBUGCODE(int segmentCount = 0;) + SkDEBUGCODE(int closeCount = 0;) while ((verb = iter.next(pts)) != kDone_Verb) { int nextPt = -1; switch (verb) { case kMove_Verb: - SkASSERT(!moveCnt); + SkASSERT(!segmentCount && !closeCount); SkDEBUGCODE(++moveCnt); firstPt = prevPt = pts[0]; break; case kLine_Verb: nextPt = 1; - SkASSERT(moveCnt); + SkASSERT(moveCnt && !closeCount); + SkDEBUGCODE(++segmentCount); break; case kQuad_Verb: case kConic_Verb: - SkASSERT(moveCnt); + SkASSERT(moveCnt && !closeCount); + SkDEBUGCODE(++segmentCount); nextPt = 2; break; case kCubic_Verb: - SkASSERT(moveCnt); + SkASSERT(moveCnt && !closeCount); + SkDEBUGCODE(++segmentCount); nextPt = 3; break; case kClose_Verb: + SkDEBUGCODE(++closeCount;) break; default: SkDEBUGFAIL("unknown verb"); diff --git a/tests/PathTest.cpp b/tests/PathTest.cpp index 6c8f83e540..e33c912062 100644 --- a/tests/PathTest.cpp +++ b/tests/PathTest.cpp @@ -1161,6 +1161,18 @@ static void test_conservativelyContains(skiatest::Reporter* reporter) { SkIntToScalar(200), SkIntToScalar(20), SkIntToScalar(5)))); + + // same as above path and first test but with an extra moveTo. + path.reset(); + path.moveTo(100, 100); + path.moveTo(0, 0); + path.lineTo(SkIntToScalar(100), 0); + path.lineTo(0, SkIntToScalar(100)); + + REPORTER_ASSERT(reporter, path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(50), 0, + SkIntToScalar(10), + SkIntToScalar(10)))); + } // Simple isRect test is inline TestPath, below. |