diff --git a/src/Base/Vector3D.cpp b/src/Base/Vector3D.cpp index 60612eebae..88a8a37397 100644 --- a/src/Base/Vector3D.cpp +++ b/src/Base/Vector3D.cpp @@ -25,6 +25,7 @@ #include #include +#include #include "Vector3D.h" #include "Tools.h" @@ -228,22 +229,26 @@ bool Vector3::IsEqual(const Vector3& rclPnt, float_type } template -bool Vector3::IsParallel(const Vector3& rclPnt, float_type tol) const +bool Vector3::IsParallel(const Vector3& rclDir, float_type tol) const { - Vector3 v1 = *this; - Vector3 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 -bool Vector3::IsNormal(const Vector3& rclPnt, float_type tol) const +bool Vector3::IsNormal(const Vector3& rclDir, float_type tol) const { - Vector3 v1 = *this; - Vector3 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 diff --git a/src/Base/Vector3D.h b/src/Base/Vector3D.h index 285ec9ed95..de9b2d19c7 100644 --- a/src/Base/Vector3D.h +++ b/src/Base/Vector3D.h @@ -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); /**