// Path: src/main/java/com/github/davidmoten/rtree/geometry/Circle.java
// public interface Circle extends Geometry {
// 
//     double x();
// 
//     double y();
// 
//     double radius();
// 
//     boolean intersects(Circle c);
// 
//     boolean intersects(Point point);
// 
//     boolean intersects(Line line);
// 
// }
// 
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
// 
//     double x1();
// 
//     double y1();
// 
//     double x2();
// 
//     double y2();
// 
//     double area();
// 
//     double intersectionArea(Rectangle r);
// 
//     double perimeter();
// 
//     Rectangle add(Rectangle r);
// 
//     boolean contains(double x, double y);
//     
//     boolean isDoublePrecision();
// 
// }


import com.github.davidmoten.rtree.geometry.Circle;
import com.github.davidmoten.rtree.geometry.Rectangle;
    public static double distance(double x, double y, double a1, double b1, double a2, double b2) {
        return distance(x, y, x, y, a1, b1, a2, b2);
    }

    public static double distance(double x1, double y1, double x2, double y2, double a1, double b1,
            double a2, double b2) {
        if (intersects(x1, y1, x2, y2, a1, b1, a2, b2)) {
            return 0;
        }
        boolean xyMostLeft = x1 < a1;
        double mostLeftX1 = xyMostLeft ? x1 : a1;
        double mostRightX1 = xyMostLeft ? a1 : x1;
        double mostLeftX2 = xyMostLeft ? x2 : a2;
        double xDifference = max(0, mostLeftX1 == mostRightX1 ? 0 : mostRightX1 - mostLeftX2);

        boolean xyMostDown = y1 < b1;
        double mostDownY1 = xyMostDown ? y1 : b1;
        double mostUpY1 = xyMostDown ? b1 : y1;
        double mostDownY2 = xyMostDown ? y2 : b2;

        double yDifference = max(0, mostDownY1 == mostUpY1 ? 0 : mostUpY1 - mostDownY2);

        return Math.sqrt(xDifference * xDifference + yDifference * yDifference);
    }

    public static boolean intersects(double x1, double y1, double x2, double y2, double a1,
            double b1, double a2, double b2) {
        return x1 <= a2 && a1 <= x2 && y1 <= b2 && b1 <= y2;
    }
    
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Circle.java
// public interface Circle extends Geometry {
// 
//     double x();
// 
//     double y();
// 
//     double radius();
// 
//     boolean intersects(Circle c);
// 
//     boolean intersects(Point point);
// 
//     boolean intersects(Line line);
// 
// }
// 
// Path: src/main/java/com/github/davidmoten/rtree/geometry/Rectangle.java
// public interface Rectangle extends Geometry, HasGeometry {
// 
//     double x1();
// 
//     double y1();
// 
//     double x2();
// 
//     double y2();
// 
//     double area();
// 
//     double intersectionArea(Rectangle r);
// 
//     double perimeter();
// 
//     Rectangle add(Rectangle r);
// 
//     boolean contains(double x, double y);
//     
//     boolean isDoublePrecision();
// 
// }


// Path: src/main/java/com/github/davidmoten/rtree/geometry/internal/GeometryUtil.java
import com.github.davidmoten.rtree.geometry.Circle;
import com.github.davidmoten.rtree.geometry.Rectangle;

    public static double distance(double x, double y, double a1, double b1, double a2, double b2) {
        return distance(x, y, x, y, a1, b1, a2, b2);
    }

    public static double distance(double x1, double y1, double x2, double y2, double a1, double b1,
            double a2, double b2) {
        if (intersects(x1, y1, x2, y2, a1, b1, a2, b2)) {
            return 0;
        }
        boolean xyMostLeft = x1 < a1;
        double mostLeftX1 = xyMostLeft ? x1 : a1;
        double mostRightX1 = xyMostLeft ? a1 : x1;
        double mostLeftX2 = xyMostLeft ? x2 : a2;
        double xDifference = max(0, mostLeftX1 == mostRightX1 ? 0 : mostRightX1 - mostLeftX2);

        boolean xyMostDown = y1 < b1;
        double mostDownY1 = xyMostDown ? y1 : b1;
        double mostUpY1 = xyMostDown ? b1 : y1;
        double mostDownY2 = xyMostDown ? y2 : b2;

        double yDifference = max(0, mostDownY1 == mostUpY1 ? 0 : mostUpY1 - mostDownY2);

        return Math.sqrt(xDifference * xDifference + yDifference * yDifference);
    }

    public static boolean intersects(double x1, double y1, double x2, double y2, double a1,
            double b1, double a2, double b2) {
        return x1 <= a2 && a1 <= x2 && y1 <= b2 && b1 <= y2;
    }
    
    public static boolean lineIntersects(double x1, double y1, double x2, double y2, Circle circle) {