fix zero length dashed lines

targeted fix turns zero length line
into very short line.

R=egdaniel@google.com
Bug: skia:7387
Change-Id: Ic2a809d30d722f4e8f51d9205666dc1476a10067
Reviewed-on: https://skia-review.googlesource.com/84661
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Cary Clark <caryclark@google.com>
diff --git a/gm/strokes.cpp b/gm/strokes.cpp
index 7bd31c2..ed13d09 100644
--- a/gm/strokes.cpp
+++ b/gm/strokes.cpp
@@ -518,3 +518,18 @@
 
 DEF_GM( return new ZeroLenStrokesGM; )
 DEF_GM( return new TeenyStrokesGM; )
+
+DEF_SIMPLE_GM(zerolinedash, canvas, 256, 256) {
+    canvas->clear(SK_ColorWHITE);
+
+    SkPaint paint;
+    paint.setColor(SkColorSetARGB(255, 0, 0, 0));
+    paint.setStrokeWidth(11);
+    paint.setStrokeCap(SkPaint::kRound_Cap);
+    paint.setStrokeJoin(SkPaint::kBevel_Join);
+
+    SkScalar dash_pattern[] = {1, 5};
+    paint.setPathEffect(SkDashPathEffect::Make(dash_pattern, 2, 0));
+
+    canvas->drawLine(100, 100, 100, 100, paint);
+}
diff --git a/src/utils/SkDashPath.cpp b/src/utils/SkDashPath.cpp
index d3c52da..cbfc8f2 100644
--- a/src/utils/SkDashPath.cpp
+++ b/src/utils/SkDashPath.cpp
@@ -140,6 +140,12 @@
     pts[0].fX = minX;
     pts[1].fX = maxX;
 
+    // If line is zero-length, bump out the end by a tiny amount
+    // to draw endcaps. The bump factor is sized so that
+    // SkPoint::Distance() computes a non-zero length.
+    if (minX == maxX) {
+        pts[1].fX += maxX * FLT_EPSILON * 32;  // 16 instead of 32 does not draw; length stays zero
+    }
     dstPath->moveTo(pts[0]);
     dstPath->lineTo(pts[1]);
     return true;