allwpilib
allwpilib copied to clipboard
Pose2d "nearest" method
would be convenient for Pose2d
to have a nearest(List<Pose2d> poses)
method that finds the nearest of a set of reference poses to the calling pose.
In C++, this is just https://en.cppreference.com/w/cpp/algorithm/min_element with a custom comparator for translation distance.
Same goes for Java with Collections.min(Collection<T>, Comparator<T>)
.
public Translation2d nearest(List<Translation2d> others) {
return Collections.min(others, Comparator.comparing(this::getDistance));
}