[wpimath] Constrain Rotation2d range to -pi to pi (#4611)

Co-authored-by: Ryan Blue <ryanzblue@gmail.com>
This commit is contained in:
ohowe
2022-11-14 15:25:15 -07:00
committed by GitHub
parent f656e99245
commit d1d458db2b
7 changed files with 69 additions and 43 deletions

View File

@@ -13,6 +13,15 @@ import org.junit.jupiter.api.Test;
class Rotation2dTest {
private static final double kEpsilon = 1E-9;
@Test
void testInScope() {
var rot1 = Rotation2d.fromRadians(Math.PI * 5 / 2);
var rot2 = Rotation2d.fromRadians(Math.PI * 7 / 2);
assertEquals(Math.PI / 2, rot1.getRadians(), kEpsilon);
assertEquals(-Math.PI / 2, rot2.getRadians(), kEpsilon);
}
@Test
void testRadiansToDegrees() {
var rot1 = Rotation2d.fromRadians(Math.PI / 3);
@@ -59,6 +68,21 @@ class Rotation2dTest {
assertEquals(40.0, rot1.minus(rot2).getDegrees(), kEpsilon);
}
@Test
void testUnaryMinus() {
var rot = Rotation2d.fromDegrees(20.0);
assertEquals(-20.0, rot.unaryMinus().getDegrees(), kEpsilon);
}
@Test
void testMultiply() {
var rot = Rotation2d.fromDegrees(10.0);
assertEquals(30.0, rot.times(3.0).getDegrees(), kEpsilon);
assertEquals(50.0, rot.times(41.0).getDegrees(), kEpsilon);
}
@Test
void testEquality() {
var rot1 = Rotation2d.fromDegrees(43.0);