Base: fix IsNormal() and IsParallel()

Fix the IsNormal() and IsParallel() methods to pass the unit tests
This commit is contained in:
wmayer
2024-02-09 17:25:42 +01:00
committed by Chris Hennes
parent 5368465ec1
commit b03ed3b42e
2 changed files with 20 additions and 13 deletions

View File

@@ -25,6 +25,7 @@
#include <cmath>
#include <limits>
#include <boost/math/special_functions/fpclassify.hpp>
#include "Vector3D.h"
#include "Tools.h"
@@ -228,22 +229,26 @@ bool Vector3<float_type>::IsEqual(const Vector3<float_type>& rclPnt, float_type
}
template<class float_type>
bool Vector3<float_type>::IsParallel(const Vector3<float_type>& rclPnt, float_type tol) const
bool Vector3<float_type>::IsParallel(const Vector3<float_type>& rclDir, float_type tol) const
{
Vector3<float_type> v1 = *this;
Vector3<float_type> v2 = rclPnt;
double dot = abs(v1 * v2);
double mag = v1.Length() * v2.Length();
return (abs(dot - mag) < tol);
float_type angle = GetAngle(rclDir);
if (boost::math::isnan(angle)) {
return false;
}
return angle <= tol || traits_type::pi() - angle <= tol;
}
template<class float_type>
bool Vector3<float_type>::IsNormal(const Vector3<float_type>& rclPnt, float_type tol) const
bool Vector3<float_type>::IsNormal(const Vector3<float_type>& rclDir, float_type tol) const
{
Vector3<float_type> v1 = *this;
Vector3<float_type> v2 = rclPnt;
double dot = abs(v1 * v2);
return (dot < tol);
float_type angle = GetAngle(rclDir);
if (boost::math::isnan(angle)) {
return false;
}
float_type diff = std::abs(traits_type::pi() / 2.0 - angle); // NOLINT
return diff <= tol;
}
template<class float_type>

View File

@@ -211,9 +211,11 @@ public:
*/
bool IsEqual(const Vector3& rclPnt, float_type tol) const;
/// Returns true if two vectors are parallel within the tol
bool IsParallel(const Vector3& rclPnt, float_type tol) const;
/// If one of the vectors is the null vector then false is returned.
bool IsParallel(const Vector3& rclDir, float_type tol) const;
/// Returns true if two vectors are normal within the tol
bool IsNormal(const Vector3& rclPnt, float_type tol) const;
/// If one of the vectors is the null vector then false is returned.
bool IsNormal(const Vector3& rclDir, float_type tol) const;
/// Projects this point onto the plane given by the base \a rclBase and the normal \a rclNorm.
Vector3& ProjectToPlane(const Vector3& rclBase, const Vector3& rclNorm);
/**