make SkPath::conservativelyContainsRect consume degenerate segments

BUG=skia:

Change-Id: I3a39318bceaf6c95a50d84961d93af4ba62550e3
Reviewed-on: https://skia-review.googlesource.com/6900
Reviewed-by: Cary Clark <caryclark@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Lee Salzman 2017-01-12 13:06:21 -05:00 committed by Skia Commit-Bot
parent 42e8c53b3e
commit a19f024953
2 changed files with 14 additions and 2 deletions

View File

@ -263,14 +263,14 @@ bool SkPath::conservativelyContainsRect(const SkRect& rect) const {
SkPoint firstPt;
SkPoint prevPt;
RawIter iter(*this);
SkPath::Iter iter(*this, true);
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) {
while ((verb = iter.next(pts, true, true)) != kDone_Verb) {
int nextPt = -1;
switch (verb) {
case kMove_Verb:

View File

@ -1919,6 +1919,18 @@ static void test_conservativelyContains(skiatest::Reporter* reporter) {
path.lineTo(SkIntToScalar(100), 0);
path.lineTo(0, SkIntToScalar(100));
REPORTER_ASSERT(reporter, path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(50), 0,
SkIntToScalar(10),
SkIntToScalar(10))));
// Same as above path and first test but with the extra moveTo making a degenerate sub-path
// following the non-empty sub-path. Verifies that this does not trigger assertions.
path.reset();
path.moveTo(0, 0);
path.lineTo(SkIntToScalar(100), 0);
path.lineTo(0, SkIntToScalar(100));
path.moveTo(100, 100);
REPORTER_ASSERT(reporter, path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(50), 0,
SkIntToScalar(10),
SkIntToScalar(10))));