public Point nearest(Point p) {
    if(p==null || size()==0)
        return null;
    Double dmin = null;
    Point nn = null;  // nearest neighbor

    for(Point candidate : this){
        Double d2 = p.squaredDistanceTo(candidate);
        if(dmin == null || d2 < dmin){
            dmin = d2;
            nn = candidate;
        }
    }
    return nn;
  }