Skip to content

Commit

Permalink
Change getDistanceFromPoint to work on Translation2d
Browse files Browse the repository at this point in the history
  • Loading branch information
rakrakon committed Feb 3, 2024
1 parent 45fb03d commit 95cc921
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/main/java/lib/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ public static Rotation2d normalize(Rotation2d angle) {
return Rotation2d.fromRadians(normalize(angle.getRadians()));
}

public static double getDistanceFromPoint(Pose2d point, Pose2d robotPose) {
return robotPose.getTranslation().getDistance(point.getTranslation());
public static double getDistanceFromPoint(Translation2d point, Pose2d robotPose) {
return robotPose.getTranslation().getDistance(point);
}

public static Pose2d calcOptimalPose(List<Pose2d> points, Pose2d robotPose) {
return points.stream()
.min(Comparator.comparingDouble(point -> getDistanceFromPoint(point, robotPose)))
.min(
Comparator.comparingDouble(
point -> getDistanceFromPoint(point.getTranslation(), robotPose)))
.orElse(null);
}
}

0 comments on commit 95cc921

Please sign in to comment.