
762 A Practical Guide to Data Structures and Algorithms Using Java
Default XY Comparator
public class DefaultXYComparator<E extends XYPoint> implements XYComparator<E> {
public double compareX(E a, E b) {return a.getX() - b.getX();}
public double compareY(E a, E b) {return a.getY() - b.getY();}
public double getX(E item) { return item.getX();}
public double getY(E item) { return item.getY();}
public int compare(E a, E b) { //uses X comparisons by default
double d = compareX(a, b);
if (d < 0)
return -1;
else if (d == 0)
return 0;
else
return 1;
}
The quadrant method takes origin, the element that defines the origin, and target, the target
element. It returns