don't create zero length intervals
authorcaryclark <caryclark@google.com>
Thu, 17 Mar 2016 12:33:28 +0000 (05:33 -0700)
committerCommit bot <commit-bot@chromium.org>
Thu, 17 Mar 2016 12:33:28 +0000 (05:33 -0700)
Dashing a pattern without zero-length intervals should
not create them if the end of the on interval coincides
with the beginning of the initial dash offset.

R=reed@google.com
BUG=591993
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1766243004

Committed: https://skia.googlesource.com/skia/+/18bbd00190623fb6cdb119df4a118ac3c1aed52a

Review URL: https://codereview.chromium.org/1766243004

gm/bug530095.cpp
src/utils/SkDashPath.cpp

index 690da3c9d0ba054b4f2094a522e9bdfffcfed264..76f6bc8f2e55f15cb80714ab2f2f02ac94f45548 100644 (file)
@@ -46,3 +46,16 @@ DEF_SIMPLE_GM(bug530095, canvas, 900, 1200) {
     canvas->translate(4, 4);
     canvas->drawPath(path2, paint);
 }
+
+DEF_SIMPLE_GM(bug591993, canvas, 40, 140) {
+    SkPaint p;
+    p.setColor(SK_ColorRED);
+    p.setAntiAlias(true);
+    p.setStyle(SkPaint::kStroke_Style);
+    p.setStrokeCap(SkPaint::kRound_Cap);
+    p.setStrokeWidth(10);
+    SkScalar intervals[] = { 100, 100 };
+    SkPathEffect* dash = SkDashPathEffect::Create(intervals, SK_ARRAY_COUNT(intervals), 100);
+    p.setPathEffect(dash)->unref();
+    canvas->drawLine(20, 20, 120, 20, p);
+}
index cd01a9972b94695e1a4b27e1e819bb675fcb56e0..0d2783eba257b35bef23ca56e7d71c8a51094bfc 100644 (file)
@@ -16,11 +16,12 @@ static inline int is_even(int x) {
 static SkScalar find_first_interval(const SkScalar intervals[], SkScalar phase,
                                     int32_t* index, int count) {
     for (int i = 0; i < count; ++i) {
-        if (phase > intervals[i]) {
-            phase -= intervals[i];
+        SkScalar gap = intervals[i];
+        if (phase > gap || (phase == gap && gap)) {
+            phase -= gap;
         } else {
             *index = i;
-            return intervals[i] - phase;
+            return gap - phase;
         }
     }
     // If we get here, phase "appears" to be larger than our length. This