import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.util.*;


public class Geom {
    public static double angle(Point tail, Point head) {
        // return "pseudo-angle" rather than true angle
        // the value is
        // |itan/(1+itan)| in the first quadrant
        // |2-itan/(1+itan)| in the second quadrant
        // |2+itan/(1+itan)| in the third quadrant
        // |4-itan/(1+itan)| in the fourth quadrant
        // remember that x increases to the right and y increases down

        int tx = tail.x, ty = tail.y, hx = head.x, hy = head.y;
        double dx = Math.abs(hx-tx);
        double dy = Math.abs(hy-ty);
        double res = dy/(dx+dy);
        if (hx > tx) { // on RHS
            if (hy > ty) res = 4.0 - res;
        }
        else { // on LHS
            if (hy > ty) res = 2.0 + res;
            else res = 2.0 - res;
        }
        return res;
    }

    public static boolean lineInsideRect(Point endpt1, Point endpt2, Point[] rect) {
        // line is from endpt1 to endpt2
        // rect[0] = (left, top), rect[1] = (right, bottom)
        int left = rect[0].x, right = rect[1].x;
        int top = rect[0].y, bottom = rect[1].y;
        int x1 = endpt1.x, x2 = endpt2.x;
        int y1 = endpt2.y, y2 = endpt2.y;

        // if either endpt of line is inside the rect, part of line is inside
        if (left < x1 && x1 < right && top < y1 && y1 < bottom) return true;
        if (left < x2 && x2 < right && top < y2 && y2 < bottom) return true;

        // now we know both endpts are outside
        // part of line is inside iff the line intersects one of the edges
        // get equation of line in the form f(x+y) = ax+by+c = 0
        double a = 0, b = 0, c = 0;
        a = y1 - y2;
        b = x2 - x1;
        c = -x2*y1 + x1*y2;
        double left_top = a*left + b*top + c;
        double right_top = a*right + b*bottom + c;
        double left_bottom = a*left + b*bottom + c;
        double right_bottom = a*right + b*bottom + c;
        if ((x1 < left && left < x2) || (x2 < left && left < x1)) {
            if (left_top*right_bottom < 0) return true;
        }
        if ((x1 < right && right < x2) || (x2 < right && right < x1)) {
            if (right_top*right_bottom < 0) return true;
        }
        if ((y1 < top && top < y2) || (y2 < top && top < y1)) {
            if (left_top*right_top < 0) return true;
        }
        if ((y1 < bottom && bottom < y2) || (y2 < bottom && bottom < y1)) {
            if (left_bottom*right_bottom < 0) return true;
        }
        return false;

    }

    public static boolean nearerThan(Pt newPt, Point[] oldPoints, int nOldPoints,
                                     int tolerance) {
        int newX = newPt.x, newY = newPt.y;
        int squaredTolerance = tolerance*tolerance;
        for (int i = 0; i < nOldPoints; i++) {
            int oldX = oldPoints[i].x,
                    oldY = oldPoints[i].y;
            if ((newX-oldX)*(newX-oldX) + (newY-oldY)*(newY-oldY) < squaredTolerance)
                return true;
        }
        return false;
    }

    public static void main(String[] args) throws Exception {
    }

} 