make SkPath::conservativelyContainsRect consume degenerate segments
authorLee Salzman <lsalzman@mozilla.com>
Thu, 12 Jan 2017 18:06:21 +0000 (13:06 -0500)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Mon, 23 Jan 2017 22:08:37 +0000 (22:08 +0000)
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>

src/core/SkPath.cpp
tests/PathTest.cpp

index 53678de..4c7ebe5 100644 (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:
index 0ace812..42771d0 100644 (file)
@@ -1923,6 +1923,18 @@ static void test_conservativelyContains(skiatest::Reporter* reporter) {
                                                                                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))));
+
     // Test that multiple move commands do not cause asserts and that the function
     // is not confused by the multiple moves.
     path.reset();