public static < P extends Point2D > Comparator < P > createPointComparator ( final P origin ) { return new Comparator < P > ( ) { public int compare ( P p1 , P p2 ) { double dist1 = origin . distance ( p1 ) ; double dist2 = origin . distance ( p2 ) ; return ( dist1 > dist2 ) ? 1 : ( ( dist1 < dist2 ) ? - 1 : 0 ) ; } } ; }
Create a comparator that compares against the distance from the specified point .