Apply fix from #3739 to quads and cubics as well
Fixes http://code.google.com/p/chromium/issues/detail?id=125249
Review URL: https://codereview.appspot.com/6137046

git-svn-id: http://skia.googlecode.com/svn/trunk@3786 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/core/SkPathMeasure.cpp b/src/core/SkPathMeasure.cpp
index 0d4dcd4..d09bf92 100644
--- a/src/core/SkPathMeasure.cpp
+++ b/src/core/SkPathMeasure.cpp
@@ -108,8 +108,12 @@
     } else {
         SkScalar d = SkPoint::Distance(pts[0], pts[2]);
         SkASSERT(d >= 0);
-        if (!SkScalarNearlyZero(d)) {
-            distance += d;
+        if (SkScalarNearlyZero(d)) {
+            d = 0;
+        }
+        SkScalar prevD = distance;
+        distance += d;
+        if (distance > prevD) {
             Segment* seg = fSegments.append();
             seg->fDistance = distance;
             seg->fPtIndex = ptIndex;
@@ -132,8 +136,12 @@
     } else {
         SkScalar d = SkPoint::Distance(pts[0], pts[3]);
         SkASSERT(d >= 0);
-        if (!SkScalarNearlyZero(d)) {
-            distance += d;
+        if (SkScalarNearlyZero(d)) {
+            d = 0;
+        }
+        SkScalar prevD = distance;
+        distance += d;
+        if (distance > prevD) {
             Segment* seg = fSegments.append();
             seg->fDistance = distance;
             seg->fPtIndex = ptIndex;
@@ -156,6 +164,8 @@
      *  as we accumulate distance, we have to check that the result of +=
      *  actually made it larger, since a very small delta might be > 0, but
      *  still have no effect on distance (if distance >>> delta).
+     *
+     *  We do this check below, and in compute_quad_segs and compute_cubic_segs
      */
     fSegments.reset();
     bool done = false;
diff --git a/tests/PathMeasureTest.cpp b/tests/PathMeasureTest.cpp
index e636ff3..453cdeb 100644
--- a/tests/PathMeasureTest.cpp
+++ b/tests/PathMeasureTest.cpp
@@ -8,6 +8,43 @@
 #include "Test.h"
 #include "SkPathMeasure.h"
 
+static void test_small_segment3(skiatest::Reporter* reporter) {
+#ifdef SK_SCALAR_IS_FLOAT
+    SkPath path;
+    const SkPoint pts[] = {
+        { 0, 0 },
+        { 100000000000.0f, 100000000000.0f }, { 0, 0 }, { 10, 10 },
+        { 10, 10 }, { 0, 0 }, { 10, 10 }
+    };
+    
+    path.moveTo(pts[0]);
+    for (size_t i = 1; i < SK_ARRAY_COUNT(pts); i += 2) {
+        path.cubicTo(pts[i], pts[i + 1], pts[i + 2]);
+    }
+    
+    SkPathMeasure meas(path, false);
+    meas.getLength();
+#endif
+}
+
+static void test_small_segment2(skiatest::Reporter* reporter) {
+#ifdef SK_SCALAR_IS_FLOAT
+    SkPath path;
+    const SkPoint pts[] = {
+        { 0, 0 },
+        { 100000000000.0f, 100000000000.0f }, { 0, 0 }, 
+        { 10, 10 }, { 0, 0 }, 
+    };
+    
+    path.moveTo(pts[0]);
+    for (size_t i = 1; i < SK_ARRAY_COUNT(pts); i += 2) {
+        path.quadTo(pts[i], pts[i + 1]);
+    }
+    SkPathMeasure meas(path, false);
+    meas.getLength();
+#endif
+}
+
 static void test_small_segment(skiatest::Reporter* reporter) {
 #ifdef SK_SCALAR_IS_FLOAT
     SkPath path;
@@ -18,7 +55,7 @@
         // tiny (non-zero) jump between these points
         { 1, 1 },
     };
-        
+    
     path.moveTo(pts[0]);
     for (size_t i = 1; i < SK_ARRAY_COUNT(pts); ++i) {
         path.lineTo(pts[i]);
@@ -31,7 +68,7 @@
         d = distance(pts[0], pts[1]);
         distance += d;
         seg->fDistance = distance;
-     
+
         SkASSERT(d > 0);    // TRUE
         SkASSERT(seg->fDistance > prevSeg->fDistance);  // FALSE
 
@@ -167,6 +204,8 @@
     REPORTER_ASSERT(reporter, tangent.fY == 0);
 
     test_small_segment(reporter);
+    test_small_segment2(reporter);
+    test_small_segment3(reporter);
 }
 
 #include "TestClassDef.h"