From ca54d1b54dfb22255cfbd5cf78352a0cf0fa73d1 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sat, 3 Mar 2018 18:25:21 -1000 Subject: [PATCH] Add CVector3f::isMagnitudeSafe() --- include/zeus/CVector3f.hpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/include/zeus/CVector3f.hpp b/include/zeus/CVector3f.hpp index 469cd0d..da0277f 100644 --- a/include/zeus/CVector3f.hpp +++ b/include/zeus/CVector3f.hpp @@ -247,14 +247,12 @@ public: inline void normalize() { - float mag = magnitude(); - mag = 1.f / mag; + float mag = 1.f / magnitude(); *this *= CVector3f(mag); } inline CVector3f normalized() const { - float mag = magnitude(); - mag = 1.f / mag; + float mag = 1.f / magnitude(); return *this * mag; } inline CVector3f cross(const CVector3f& rhs) const @@ -298,6 +296,16 @@ public: inline float magnitude() const { return sqrtF(magSquared()); } + inline bool isNotInf() const + { + return !(isinf(x) || isinf(y) || isinf(z)); + } + + inline bool isMagnitudeSafe() const + { + return isNotInf() && magSquared() >= 9.9999994e-29; + } + inline void zeroOut() { *this = CVector3f::skZero;