fix clamping when we chop a cubic
Review URL: https://codereview.appspot.com/6039048

git-svn-id: http://skia.googlecode.com/svn/trunk@3691 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/core/SkEdgeClipper.cpp b/src/core/SkEdgeClipper.cpp
index 70da7e6..14afce5 100644
--- a/src/core/SkEdgeClipper.cpp
+++ b/src/core/SkEdgeClipper.cpp
@@ -286,8 +286,8 @@
             // still be monotonic in Y. Since we can't trust the numerics of
             // the chopper, we force those conditions now
             tmp[3].fY = clip.fTop;
-            tmp[4].fY = SkMaxScalar(tmp[4].fY, clip.fTop);
-            tmp[5].fY = SkMaxScalar(tmp[5].fY, tmp[4].fY);
+            clamp_ge(tmp[4].fY, clip.fTop);
+            clamp_ge(tmp[5].fY, tmp[4].fY);
 
             pts[0] = tmp[3];
             pts[1] = tmp[4];
@@ -307,9 +307,10 @@
         if (chopMonoCubicAtY(pts, clip.fBottom, &t)) {
             SkPoint tmp[7];
             SkChopCubicAt(pts, tmp, t);
-            clamp_le(tmp[1].fY, clip.fBottom);
+            tmp[3].fY = clip.fBottom;
             clamp_le(tmp[2].fY, clip.fBottom);
-            clamp_le(tmp[3].fY, clip.fBottom);
+            clamp_le(tmp[1].fY, tmp[2].fY);
+
             pts[1] = tmp[1];
             pts[2] = tmp[2];
             pts[3] = tmp[3];
@@ -365,8 +366,8 @@
             // still be monotonic in X. Since we can't trust the numerics of
             // the chopper, we force those conditions now
             tmp[3].fX = clip.fLeft;
-            tmp[4].fX = SkMaxScalar(tmp[4].fX, clip.fLeft);
-            tmp[5].fX = SkMaxScalar(tmp[5].fX, tmp[4].fX);
+            clamp_ge(tmp[4].fX, clip.fLeft);
+            clamp_ge(tmp[5].fX, tmp[4].fX);
 
             pts[0] = tmp[3];
             pts[1] = tmp[4];
@@ -385,9 +386,10 @@
         if (chopMonoCubicAtX(pts, clip.fRight, &t)) {
             SkPoint tmp[7];
             SkChopCubicAt(pts, tmp, t);
-            clamp_le(tmp[1].fX, clip.fRight);
+            tmp[3].fX = clip.fRight;
             clamp_le(tmp[2].fX, clip.fRight);
-            clamp_le(tmp[3].fX, clip.fRight);
+            clamp_le(tmp[1].fX, tmp[2].fX);
+
             this->appendCubic(tmp, reverse);
             this->appendVLine(clip.fRight, tmp[3].fY, tmp[6].fY, reverse);
         } else {
diff --git a/tests/DrawPathTest.cpp b/tests/DrawPathTest.cpp
index f0556c2..9bbb88f 100644
--- a/tests/DrawPathTest.cpp
+++ b/tests/DrawPathTest.cpp
@@ -25,6 +25,8 @@
     return create(SkBitmap::kARGB_8888_Config, w, h, 0, NULL);
 }
 
+///////////////////////////////////////////////////////////////////////////////
+
 static void test_bug533(skiatest::Reporter* reporter) {
 #ifdef SK_SCALAR_IS_FLOAT
     /*
@@ -44,6 +46,20 @@
 #endif
 }
 
+static void test_bigcubic(skiatest::Reporter* reporter) {
+#ifdef SK_SCALAR_IS_FLOAT
+    SkPath path;
+    path.moveTo(64, 3);
+    path.cubicTo(-329936, -100000000, -329936, 100000000, 1153, 330003);
+    
+    SkPaint paint;
+    paint.setAntiAlias(true);
+    
+    SkAutoTUnref<SkCanvas> canvas(new_canvas(640, 480));
+    canvas.get()->drawPath(path, paint);
+#endif
+}
+
 // we used to assert if the bounds of the device (clip) was larger than 32K
 // even when the path itself was smaller. We just draw and hope in the debug
 // version to not assert.
@@ -63,6 +79,7 @@
 static void TestDrawPath(skiatest::Reporter* reporter) {
     test_giantaa(reporter);
     test_bug533(reporter);
+    test_bigcubic(reporter);
 }
 
 #include "TestClassDef.h"