From 18ff694f02bd812b4bc8bdd930c614cecbfaa1ba Mon Sep 17 00:00:00 2001 From: Starlight220 <53231611+Starlight220@users.noreply.github.com> Date: Sat, 30 Apr 2022 10:19:29 +0300 Subject: [PATCH] [wpimath] Add Rotation2d.fromRadians factory (#4178) --- .../java/edu/wpi/first/math/geometry/Rotation2d.java | 10 ++++++++++ .../edu/wpi/first/math/geometry/Rotation2dTest.java | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/wpimath/src/main/java/edu/wpi/first/math/geometry/Rotation2d.java b/wpimath/src/main/java/edu/wpi/first/math/geometry/Rotation2d.java index b4ad39dcb4..5f37740e44 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/geometry/Rotation2d.java +++ b/wpimath/src/main/java/edu/wpi/first/math/geometry/Rotation2d.java @@ -58,6 +58,16 @@ public class Rotation2d implements Interpolatable { m_value = Math.atan2(m_sin, m_cos); } + /** + * Constructs and returns a Rotation2d with the given radian value. + * + * @param radians The value of the angle in degrees. + * @return The rotation object with the desired angle value. + */ + public static Rotation2d fromRadians(double radians) { + return new Rotation2d(radians); + } + /** * Constructs and returns a Rotation2d with the given degree value. * diff --git a/wpimath/src/test/java/edu/wpi/first/math/geometry/Rotation2dTest.java b/wpimath/src/test/java/edu/wpi/first/math/geometry/Rotation2dTest.java index 87055ef210..2368ba3b3c 100644 --- a/wpimath/src/test/java/edu/wpi/first/math/geometry/Rotation2dTest.java +++ b/wpimath/src/test/java/edu/wpi/first/math/geometry/Rotation2dTest.java @@ -15,8 +15,8 @@ class Rotation2dTest { @Test void testRadiansToDegrees() { - var rot1 = new Rotation2d(Math.PI / 3); - var rot2 = new Rotation2d(Math.PI / 4); + var rot1 = Rotation2d.fromRadians(Math.PI / 3); + var rot2 = Rotation2d.fromRadians(Math.PI / 4); assertAll( () -> assertEquals(rot1.getDegrees(), 60.0, kEpsilon),