public static int intersectLineAndCubic(double x1, double y1, double x2, double y2,
                                            double cx1, double cy1, double cx2, double cy2,
                                            double cx3, double cy3, double cx4, double cy4,
                                            double[] params) {
        double[] eqn = new double[4];
        double[] t = new double[3];
        double[] s = new double[3];
        double dy = y2 - y1;
        double dx = x2 - x1;
        int quantity = 0;
        int count = 0;

        eqn[0] = (cy1 - y1) * dx + (x1 - cx1) * dy;
        eqn[1] = - 3 * (cy1 - cy2) * dx + 3 * (cx1 - cx2) * dy ;
        eqn[2] = (3 * cy1 - 6 * cy2 + 3 * cy3) * dx - (3 * cx1 - 6 * cx2 + 3 * cx3) * dy;
        eqn[3] = (- 3 * cy1 + 3 * cy2 - 3 * cy3 + cy4) * dx + 
        		 (3 * cx1 - 3 * cx2 + 3 * cx3 - cx4) * dy;

        if ((count = Crossing.solveCubic(eqn, t)) == 0) {
            return 0;
        }
        
        for (int i = 0; i < count; i++) {
            if (dx != 0) {
                s[i] = (cubic(t[i], cx1, cx2, cx3, cx4) - x1) / dx;
            } else if (dy != 0) {
                s[i] = (cubic(t[i], cy1, cy2, cy3, cy4) - y1) / dy;
            } else {
            	s[i] = 0.0;
            }
            if (t[i] >= 0 && t[i] <= 1 && s[i] >= 0 && s[i] <= 1) {
                params[2 * quantity] = t[i];
                params[2 * quantity + 1] = s[i];
                ++quantity;
            }
        }

        return quantity;
    }