Use template magic

This commit is contained in:
Prateek Machiraju 2019-06-28 11:53:23 -04:00
parent b16d864d3d
commit 2ab366547d
2 changed files with 5 additions and 5 deletions

View File

@ -23,13 +23,13 @@ constexpr T Deg2Rad(const T& deg) {
return deg * kPi / 180.0;
}
template <typename T>
template <typename T, typename std::enable_if_t<!units::traits::is_unit_t<T>::value, int> = 0>
bool EpsilonEquals(const T& a, const T& b) {
return std::abs(a - b) < kEpsilon;
}
template <typename T>
bool UnitsEpsilonEquals(const T& a, const T& b) {
template <typename T, typename std::enable_if_t<units::traits::is_unit_t<T>::value, int> = 0>
bool EpsilonEquals(const T& a, const T& b) {
return units::unit_cast<double>(units::math::abs(a - b)) < kEpsilon;
}

View File

@ -29,7 +29,7 @@ class TimedEntry final : public VaryInterpolatable<TimedEntry<S>> {
if (delta_t < 0_s) return end_value.Interpolate(*this, 1.0 - t);
auto reversing = velocity_ < 0_mps ||
UnitsEpsilonEquals(velocity_, 0_mps) && acceleration_ < 0_mps_sq;
EpsilonEquals(velocity_, 0_mps) && acceleration_ < 0_mps_sq;
units::meters_per_second_t new_v = velocity_ + acceleration_ * delta_t;
units::meter_t new_s =
@ -91,7 +91,7 @@ class TimedTrajectory : public Trajectory<units::second_t, TimedEntry<S>> {
const auto s = this->Point(i);
if (s.state.T() >= interpolant) {
const auto prev_s = this->Point(i - 1);
if (UnitsEpsilonEquals(s.state.T(), prev_s.state.T())) {
if (EpsilonEquals(s.state.T(), prev_s.state.T())) {
return TrajectorySamplePoint<TimedEntry<S>>(s);
}
return TrajectorySamplePoint<TimedEntry<S>>(