private double closestPair(int left, int right) {
        double d = Double.MAX_VALUE;
        if (left == right) {
            return d;
        }
        if (left+1 == right) {
            double td = distance(left, right);
            System.out.println("td:"+left+" "+right+ " d="+td);
            setPointPair(td, left, right);
            return td;
        }
        int mid = (left + right)/2;
        double dl = closestPair(left, mid);
        double dr = closestPair(mid+1, right);
        d = min(dl, dr);
        int k = 0;
        for (int i=left; i<=right; i++) {
            if (Math.abs(points[mid].x - points[i].x) <= d && mid != i) {
                tempPs[k++] = i;
                d = distance(mid, i);
                setPointPair(d, mid, i);
                System.out.println("first:"+mid+" "+i+ " d="+d);
            }
        }
        Arrays.sort(tempPs, 0, k);
        for(int i=0; i<k; i++) {
            for (int j = i + 1; j < k && points[tempPs[j]].y - points[tempPs[i]].y <= d; j++) {
                if (d >= distance(tempPs[i], tempPs[j])) {
                    d = distance(tempPs[i], tempPs[j]);
                    setPointPair(d, tempPs[i], tempPs[j]);
                    System.out.println("second:"+tempPs[i]+" "+tempPs[j] + " d="+d);
                }
            }
        }
        return d;
    }