2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2019-07-24 02:57:39 -04:00
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
|
|
2021-05-26 00:09:36 -07:00
|
|
|
#include <wpi/numbers>
|
2019-07-31 22:15:22 -07:00
|
|
|
|
2019-07-24 02:57:39 -04:00
|
|
|
#include "frc/geometry/Rotation2d.h"
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
|
|
using namespace frc;
|
|
|
|
|
|
|
|
|
|
TEST(Rotation2dTest, RadiansToDegrees) {
|
2022-05-06 08:41:23 -07:00
|
|
|
const Rotation2d rot1{units::radian_t{wpi::numbers::pi / 3.0}};
|
|
|
|
|
const Rotation2d rot2{units::radian_t{wpi::numbers::pi / 4.0}};
|
2019-07-24 02:57:39 -04:00
|
|
|
|
2022-05-06 08:41:23 -07:00
|
|
|
EXPECT_DOUBLE_EQ(60.0, rot1.Degrees().value());
|
|
|
|
|
EXPECT_DOUBLE_EQ(45.0, rot2.Degrees().value());
|
2019-07-24 02:57:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(Rotation2dTest, DegreesToRadians) {
|
2022-05-06 08:41:23 -07:00
|
|
|
const auto rot1 = Rotation2d{45_deg};
|
|
|
|
|
const auto rot2 = Rotation2d{30_deg};
|
2019-07-24 02:57:39 -04:00
|
|
|
|
2022-05-06 08:41:23 -07:00
|
|
|
EXPECT_DOUBLE_EQ(wpi::numbers::pi / 4.0, rot1.Radians().value());
|
|
|
|
|
EXPECT_DOUBLE_EQ(wpi::numbers::pi / 6.0, rot2.Radians().value());
|
2019-07-24 02:57:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(Rotation2dTest, RotateByFromZero) {
|
|
|
|
|
const Rotation2d zero;
|
2022-05-06 08:41:23 -07:00
|
|
|
auto rotated = zero + Rotation2d(90_deg);
|
2019-07-24 02:57:39 -04:00
|
|
|
|
2022-05-06 08:41:23 -07:00
|
|
|
EXPECT_DOUBLE_EQ(wpi::numbers::pi / 2.0, rotated.Radians().value());
|
|
|
|
|
EXPECT_DOUBLE_EQ(90.0, rotated.Degrees().value());
|
2019-07-24 02:57:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(Rotation2dTest, RotateByNonZero) {
|
2022-05-06 08:41:23 -07:00
|
|
|
auto rot = Rotation2d{90_deg};
|
|
|
|
|
rot = rot + Rotation2d{30_deg};
|
2019-07-24 02:57:39 -04:00
|
|
|
|
2022-05-06 08:41:23 -07:00
|
|
|
EXPECT_DOUBLE_EQ(120.0, rot.Degrees().value());
|
2019-07-24 02:57:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(Rotation2dTest, Minus) {
|
2022-05-06 08:41:23 -07:00
|
|
|
const auto rot1 = Rotation2d{70_deg};
|
|
|
|
|
const auto rot2 = Rotation2d{30_deg};
|
2019-07-24 02:57:39 -04:00
|
|
|
|
2022-05-06 08:41:23 -07:00
|
|
|
EXPECT_DOUBLE_EQ(40.0, (rot1 - rot2).Degrees().value());
|
2019-07-24 02:57:39 -04:00
|
|
|
}
|
2019-09-08 14:20:26 -04:00
|
|
|
|
|
|
|
|
TEST(Rotation2dTest, Equality) {
|
2022-05-06 08:41:23 -07:00
|
|
|
auto rot1 = Rotation2d{43_deg};
|
|
|
|
|
auto rot2 = Rotation2d{43_deg};
|
2021-01-25 21:41:34 -08:00
|
|
|
EXPECT_EQ(rot1, rot2);
|
|
|
|
|
|
2022-05-06 08:41:23 -07:00
|
|
|
rot1 = Rotation2d{-180_deg};
|
|
|
|
|
rot2 = Rotation2d{180_deg};
|
|
|
|
|
EXPECT_EQ(rot1, rot2);
|
2019-09-08 14:20:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(Rotation2dTest, Inequality) {
|
2022-05-06 08:41:23 -07:00
|
|
|
const auto rot1 = Rotation2d{43_deg};
|
|
|
|
|
const auto rot2 = Rotation2d{43.5_deg};
|
2021-01-25 21:41:34 -08:00
|
|
|
EXPECT_NE(rot1, rot2);
|
2019-09-08 14:20:26 -04:00
|
|
|
}
|