Package com.mg105.utils
Class PointComparator
java.lang.Object
com.mg105.utils.PointComparator
- All Implemented Interfaces:
Comparator<Point>
A comparator for calculating distances between Points.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
Compare two points.int
distanceTo
(@NotNull Point destination) Calculate the cartesian distance between the reference and the destination.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Constructor Details
-
PointComparator
Create a new PointComparator.- Parameters:
reference
- the point that distances will be compared against.
-
-
Method Details
-
distanceTo
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
Compare two points.- Specified by:
compare
in interfaceComparator<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.
-