[wpimath] Add distance/angle constructor to Translation2d (#2791)

This commit is contained in:
Prateek Machiraju
2020-10-21 00:22:41 -04:00
committed by GitHub
parent b66fcdb3f7
commit 17698af5e3
5 changed files with 47 additions and 0 deletions

View File

@@ -13,6 +13,7 @@ import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
@SuppressWarnings("PMD.TooManyMethods")
class Translation2dTest {
private static final double kEpsilon = 1E-9;
@@ -112,4 +113,16 @@ class Translation2dTest {
var two = new Translation2d(9, 5.7);
assertNotEquals(one, two);
}
@Test
void testPolarConstructor() {
var one = new Translation2d(Math.sqrt(2), Rotation2d.fromDegrees(45.0));
var two = new Translation2d(2, Rotation2d.fromDegrees(60.0));
assertAll(
() -> assertEquals(one.getX(), 1.0, kEpsilon),
() -> assertEquals(one.getY(), 1.0, kEpsilon),
() -> assertEquals(two.getX(), 1.0, kEpsilon),
() -> assertEquals(two.getY(), Math.sqrt(3), kEpsilon)
);
}
}