mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
Use stricter C++ type conversions (#4357)
Now, implicit narrowing conversions are only used with wpi::Now(). This
also fixes clang-tidy warnings about C-style casts. For example:
```
== clang-tidy /__w/allwpilib/allwpilib/wpilibNewCommands/src/main/native/include/frc2/command/SwerveControllerCommand.inc ==
/__w/allwpilib/allwpilib/wpilibNewCommands/src/main/native/include/frc2/command/SwerveControllerCommand.inc:95:18: warning: C-style casts are discouraged; use static_cast/const_cast/reinterpret_cast [google-readability-casting]
auto curTime = units::second_t(m_timer.Get());
^
```
In that case at least, the cast was removed entirely since Get() already
returns a units::second_t.
This commit is contained in:
@@ -93,31 +93,29 @@ class CubicHermiteSplineTest : public ::testing::Test {
|
||||
} // namespace frc
|
||||
|
||||
TEST_F(CubicHermiteSplineTest, StraightLine) {
|
||||
Run(Pose2d(), std::vector<Translation2d>(), Pose2d(3_m, 0_m, Rotation2d()));
|
||||
Run(Pose2d{}, std::vector<Translation2d>(), Pose2d{3_m, 0_m, 0_deg});
|
||||
}
|
||||
|
||||
TEST_F(CubicHermiteSplineTest, SCurve) {
|
||||
Pose2d start{0_m, 0_m, Rotation2d(90_deg)};
|
||||
std::vector<Translation2d> waypoints{Translation2d(1_m, 1_m),
|
||||
Translation2d(2_m, -1_m)};
|
||||
Pose2d end{3_m, 0_m, Rotation2d{90_deg}};
|
||||
Pose2d start{0_m, 0_m, 90_deg};
|
||||
std::vector<Translation2d> waypoints{Translation2d{1_m, 1_m},
|
||||
Translation2d{2_m, -1_m}};
|
||||
Pose2d end{3_m, 0_m, 90_deg};
|
||||
Run(start, waypoints, end);
|
||||
}
|
||||
|
||||
TEST_F(CubicHermiteSplineTest, OneInterior) {
|
||||
Pose2d start{0_m, 0_m, 0_rad};
|
||||
std::vector<Translation2d> waypoints{Translation2d(2_m, 0_m)};
|
||||
std::vector<Translation2d> waypoints{Translation2d{2_m, 0_m}};
|
||||
Pose2d end{4_m, 0_m, 0_rad};
|
||||
Run(start, waypoints, end);
|
||||
}
|
||||
|
||||
TEST_F(CubicHermiteSplineTest, ThrowsOnMalformed) {
|
||||
EXPECT_THROW(
|
||||
Run(Pose2d{0_m, 0_m, Rotation2d(0_deg)}, std::vector<Translation2d>{},
|
||||
Pose2d{1_m, 0_m, Rotation2d(180_deg)}),
|
||||
SplineParameterizer::MalformedSplineException);
|
||||
EXPECT_THROW(
|
||||
Run(Pose2d{10_m, 10_m, Rotation2d(90_deg)}, std::vector<Translation2d>{},
|
||||
Pose2d{10_m, 11_m, Rotation2d(-90_deg)}),
|
||||
SplineParameterizer::MalformedSplineException);
|
||||
EXPECT_THROW(Run(Pose2d{0_m, 0_m, 0_deg}, std::vector<Translation2d>{},
|
||||
Pose2d{1_m, 0_m, 180_deg}),
|
||||
SplineParameterizer::MalformedSplineException);
|
||||
EXPECT_THROW(Run(Pose2d{10_m, 10_m, 90_deg}, std::vector<Translation2d>{},
|
||||
Pose2d{10_m, 11_m, -90_deg}),
|
||||
SplineParameterizer::MalformedSplineException);
|
||||
}
|
||||
|
||||
@@ -65,23 +65,20 @@ class QuinticHermiteSplineTest : public ::testing::Test {
|
||||
} // namespace frc
|
||||
|
||||
TEST_F(QuinticHermiteSplineTest, StraightLine) {
|
||||
Run(Pose2d(), Pose2d(3_m, 0_m, Rotation2d()));
|
||||
Run(Pose2d{}, Pose2d{3_m, 0_m, 0_deg});
|
||||
}
|
||||
|
||||
TEST_F(QuinticHermiteSplineTest, SimpleSCurve) {
|
||||
Run(Pose2d(), Pose2d(1_m, 1_m, Rotation2d()));
|
||||
Run(Pose2d{}, Pose2d{1_m, 1_m, 0_deg});
|
||||
}
|
||||
|
||||
TEST_F(QuinticHermiteSplineTest, SquigglyCurve) {
|
||||
Run(Pose2d(0_m, 0_m, Rotation2d(90_deg)),
|
||||
Pose2d(-1_m, 0_m, Rotation2d(90_deg)));
|
||||
Run(Pose2d{0_m, 0_m, 90_deg}, Pose2d{-1_m, 0_m, 90_deg});
|
||||
}
|
||||
|
||||
TEST_F(QuinticHermiteSplineTest, ThrowsOnMalformed) {
|
||||
EXPECT_THROW(Run(Pose2d(0_m, 0_m, Rotation2d(0_deg)),
|
||||
Pose2d(1_m, 0_m, Rotation2d(180_deg))),
|
||||
EXPECT_THROW(Run(Pose2d{0_m, 0_m, 0_deg}, Pose2d{1_m, 0_m, 180_deg}),
|
||||
SplineParameterizer::MalformedSplineException);
|
||||
EXPECT_THROW(Run(Pose2d(10_m, 10_m, Rotation2d(90_deg)),
|
||||
Pose2d(10_m, 11_m, Rotation2d(-90_deg))),
|
||||
EXPECT_THROW(Run(Pose2d{10_m, 10_m, 90_deg}, Pose2d{10_m, 11_m, -90_deg}),
|
||||
SplineParameterizer::MalformedSplineException);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user