work in progress
in the middle of switching to sortless version

git-svn-id: http://skia.googlecode.com/svn/trunk@3768 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/experimental/Intersection/LineCubicIntersection.cpp b/experimental/Intersection/LineCubicIntersection.cpp
index 8517b7e..6f2cf6c 100644
--- a/experimental/Intersection/LineCubicIntersection.cpp
+++ b/experimental/Intersection/LineCubicIntersection.cpp
@@ -109,6 +109,13 @@
     return cubicRoots(A, B, C, D, range);
 }
 
+int verticalIntersect(double axisIntercept) {
+    double A, B, C, D;
+    coefficients(&cubic[0].x, A, B, C, D);
+    D -= axisIntercept;
+    return cubicRoots(A, B, C, D, range);
+}
+
 double findLineT(double t) {
     const double* cPtr;
     const double* lPtr;
@@ -158,6 +165,56 @@
     return result;
 }
 
+int horizontalIntersect(const Cubic& cubic, double left, double right, double y,
+        bool flipped, Intersections& intersections) {
+    LineCubicIntersections c(cubic, *((_Line*) 0), intersections.fT[0]);
+    int result = c.horizontalIntersect(y);
+    for (int index = 0; index < result; ) {
+        double x, y;
+        xy_at_t(cubic, intersections.fT[0][index], x, y);
+        if (x < left || x > right) {
+            if (--result > index) {
+                intersections.fT[0][index] = intersections.fT[0][result];
+            }
+            continue;
+        }
+        intersections.fT[0][index] = (x - left) / (right - left);
+        ++index;
+    }
+    if (flipped) {
+        // OPTIMIZATION: instead of swapping, pass original line, use [1].x - [0].x
+        for (int index = 0; index < result; ++index) {
+            intersections.fT[1][index] = 1 - intersections.fT[1][index];
+        }
+    }
+    return result;
+}
+
+int verticalIntersect(const Cubic& cubic, double top, double bottom, double x,
+        bool flipped, Intersections& intersections) {
+    LineCubicIntersections c(cubic, *((_Line*) 0), intersections.fT[0]);
+    int result = c.verticalIntersect(x);
+    for (int index = 0; index < result; ) {
+        double x, y;
+        xy_at_t(cubic, intersections.fT[0][index], x, y);
+        if (y < top || y > bottom) {
+            if (--result > index) {
+                intersections.fT[0][index] = intersections.fT[0][result];
+            }
+            continue;
+        }
+        intersections.fT[0][index] = (y - top) / (bottom - top);
+        ++index;
+    }
+    if (flipped) {
+        // OPTIMIZATION: instead of swapping, pass original line, use [1].x - [0].x
+        for (int index = 0; index < result; ++index) {
+            intersections.fT[1][index] = 1 - intersections.fT[1][index];
+        }
+    }
+    return result;
+}
+
 int intersect(const Cubic& cubic, const _Line& line, double cRange[3], double lRange[3]) {
     LineCubicIntersections c(cubic, line, cRange);
     int roots;