Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/main/java/frc/robot/util/AllianceFlipUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,25 @@
public class AllianceFlipUtil {

public static double applyX(double x) {
return shouldFlip() ? FieldConstants.FIELD_LENGTH - x : x;
return shouldFlip()
? FieldConstants.FIELD_LENGTH - x
: x;
}

public static double applyY(double y) {
return shouldFlip() ? FieldConstants.FIELD_WIDTH - y : y;
return shouldFlip()
? FieldConstants.FIELD_WIDTH - y
: y;
}

public static Translation2d apply(Translation2d translation) {
return new Translation2d(applyX(translation.getX()), applyY(translation.getY()));
}

public static Rotation2d apply(Rotation2d rotation) {
return shouldFlip() ? rotation.rotateBy(Rotation2d.kPi) : rotation;
return shouldFlip()
? rotation.rotateBy(Rotation2d.kPi)
: rotation;
}

public static Pose2d apply(Pose2d pose) {
Expand All @@ -40,15 +46,11 @@ public static Pose2d apply(Pose2d pose) {
: pose;
}

public static Pose2d flip(Pose2d pose) {
return new Pose2d(apply(pose.getTranslation()), apply(pose.getRotation()));
}

public static ArrayList<Pose2d> flip(List<Pose2d> poses) {
public static ArrayList<Pose2d> apply(List<Pose2d> poses) {
ArrayList<Pose2d> flippedPoses = new ArrayList<Pose2d>();

for (Pose2d pose : poses) {
flippedPoses.add(flip(pose));
flippedPoses.add(apply(pose));
}

return flippedPoses;
Expand All @@ -58,4 +60,4 @@ public static boolean shouldFlip() {
return (DriverStation.getAlliance().isPresent()
&& DriverStation.getAlliance().get() == DriverStation.Alliance.Red);
}
}
}