Skip to content

Commit

Permalink
Add specializations to fix conversion warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <[email protected]>
  • Loading branch information
mjcarroll committed Mar 29, 2022
1 parent f6d9392 commit 57ff875
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions src/MovingWindowFilter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,45 @@ bool MovingWindowFilter<T>::WindowFilled() const
template<typename T>
T MovingWindowFilter<T>::Value() const
{
auto value =
this->sum / static_cast<double>(this->samples);
return static_cast<T>(value);
if (std::is_integral_v<T>)
{
auto value = this->sum / this->samples;
return T(value);
}
else
{
auto value = this->sum / static_cast<double>(this->samples);
return T(value);
}
}

//////////////////////////////////////////////////
template<>
ignition::math::Vector3i
MovingWindowFilter<ignition::math::Vector3i>::Value() const
{
auto value = this->sum / this->samples;
return value;
}

//////////////////////////////////////////////////
template<>
ignition::math::Vector3f
MovingWindowFilter<ignition::math::Vector3f>::Value() const
{
ignition::math::Vector3f divisor;
divisor = static_cast<float>(this->samples);
auto value = this->sum / divisor;
return value;
}

//////////////////////////////////////////////////
template<>
ignition::math::Vector3d
MovingWindowFilter<ignition::math::Vector3d>::Value() const
{
auto value = this->sum / this->samples;
return value;
}

template class MovingWindowFilter<int>;
Expand Down

0 comments on commit 57ff875

Please sign in to comment.