diff --git a/src/CVector2f.cpp b/src/CVector2f.cpp index b4ff15a..cf22192 100644 --- a/src/CVector2f.cpp +++ b/src/CVector2f.cpp @@ -9,12 +9,11 @@ float CVector2f::getAngleDiff(const CVector2f& a, const CVector2f& b) { float mag1 = a.magnitude(); float mag2 = b.magnitude(); - if (!mag1 || !mag2) - return 0; + if (mag1 <= FLT_EPSILON || mag2 <= FLT_EPSILON) + return 0.f; float dot = a.dot(b); - float theta = std::acos(dot / (mag1 * mag2)); - return theta; + return std::acos(zeus::clamp(-1.f, dot / (mag1 * mag2), 1.f)); } CVector2f CVector2f::slerp(const CVector2f& a, const CVector2f& b, float t) { diff --git a/src/CVector3f.cpp b/src/CVector3f.cpp index fe50554..6559dfe 100644 --- a/src/CVector3f.cpp +++ b/src/CVector3f.cpp @@ -11,12 +11,11 @@ float CVector3f::getAngleDiff(const CVector3f& a, const CVector3f& b) { float mag1 = a.magnitude(); float mag2 = b.magnitude(); - if (!mag1 || !mag2) + if (mag1 <= FLT_EPSILON || mag2 <= FLT_EPSILON) return 0.f; float dot = a.dot(b); - float theta = std::acos(dot / (mag1 * mag2)); - return theta; + return std::acos(zeus::clamp(-1.f, dot / (mag1 * mag2), 1.f)); } CVector3f CVector3f::slerp(const CVector3f& a, const CVector3f& b, CRelAngle clampAngle) {