public static int intersectLinesWithParams(double x1, double y1, double x2, double y2,
                                               double x3, double y3, double x4, double y4,
                                               double[] params) {
        double dx = x4 - x3;
        double dy = y4 - y3;
        double d = dx * (y2 - y1) - dy * (x2 - x1);
        // double comparison
        if (Math.abs(d) < EPSILON) {
            return 0;
        }

        params[0] = (- dx * (y1 - y3) + dy * (x1 - x3)) / d;
        
        if (dx != 0) {
            params[1] = (line(params[0], x1, x2) - x3) / dx;
        } else if (dy != 0) {
            params[1] = (line(params[0], y1, y2) - y3) / dy;
        } else {
            params[1] = 0.0;
        }
        
        if (params[0] >= 0 && params[0] <= 1 && params[1] >= 0 && params[1] <= 1) {
            return 1;
        }
        
        return 0;
    }