mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[wpimath] Constrain Rotation2d range to -pi to pi (#4611)
Co-authored-by: Ryan Blue <ryanzblue@gmail.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user