Skip to content

Commit

Permalink
Make the types explicit in quaternion_helper.hpp. (#625) (#673)
Browse files Browse the repository at this point in the history
Windows started complaining that there was possible loss of
precision.  That came about because we were using the 'double'
versions of cmath functions (sqrt, pow, etc).  However, it
turns out that Ogre only deals with floats by default anyway
(and we don't change the default when we vendor it), so switch
all calculations to floats.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>

Co-authored-by: Chris Lalancette <clalancette@openrobotics.org>
  • Loading branch information
chapulina and clalancette committed Apr 21, 2021
1 parent a20f094 commit e19a075
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#ifndef RVIZ_DEFAULT_PLUGINS__DISPLAYS__ODOMETRY__QUATERNION_HELPER_HPP_
#define RVIZ_DEFAULT_PLUGINS__DISPLAYS__ODOMETRY__QUATERNION_HELPER_HPP_

#include <algorithm>
#include <cmath>

#include <OgreQuaternion.h>
Expand All @@ -40,10 +39,11 @@ namespace rviz_default_plugins

float ogreQuaternionAngularDistance(Ogre::Quaternion first, Ogre::Quaternion second)
{
auto product = first * Ogre::Quaternion(second.w, -second.x, -second.y, -second.z);
auto imaginary_norm = sqrt(pow(product.x, 2) + pow(product.y, 2) + pow(product.z, 2));
Ogre::Quaternion product = first * Ogre::Quaternion(second.w, -second.x, -second.y, -second.z);
float imaginary_norm =
sqrtf(powf(product.x, 2.0f) + powf(product.y, 2.0f) + powf(product.z, 2.0f));

return 2 * atan2(imaginary_norm, sqrt(pow(product.w, 2)));
return 2.0f * atan2f(imaginary_norm, sqrtf(powf(product.w, 2.0f)));
}

} // namespace rviz_default_plugins
Expand Down

0 comments on commit e19a075

Please sign in to comment.