Class PointComparator

java.lang.Object
com.mg105.utils.PointComparator
All Implemented Interfaces:
Comparator<Point>

public class PointComparator extends Object implements Comparator<Point>
A comparator for calculating distances between Points.
  • Constructor Details

    • PointComparator

      public PointComparator(@NotNull @NotNull Point reference)
      Create a new PointComparator.
      Parameters:
      reference - the point that distances will be compared against.
  • Method Details

    • distanceTo

      public int distanceTo(@NotNull @NotNull Point destination)
      Calculate the cartesian distance between the reference and the destination.
      Parameters:
      destination - the point whose distance is calculated.
      Returns:
      the cartesian distance between destination and the reference point.
    • compare

      public int compare(Point o1, Point o2)
      Compare two points.
      Specified by:
      compare in interface Comparator<Point>
      Parameters:
      o1 - the first object to be compared.
      o2 - the second object to be compared.
      Returns:
      less than 0 if o1 is closer than o2 to the reference point, greater than 0 if o2 is closer than o1, and 0 otherwise.