From 462f54c36cdeb5fd659e949341ae422bb7568946 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Mon, 13 May 2024 22:33:59 +0800 Subject: [PATCH] added IsNearlyZero/IsNearlyEqual to support vec2/vec3. --- inc/hgl/math/Vector.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/inc/hgl/math/Vector.h b/inc/hgl/math/Vector.h index 2cc3303..ca62e4b 100644 --- a/inc/hgl/math/Vector.h +++ b/inc/hgl/math/Vector.h @@ -377,5 +377,35 @@ namespace hgl hgl_max(v1.z,v2.z), hgl_max(v1.w,v2.w)); } + + template + const bool IsNearlyZero(const glm::vec<2,T,Q> &v) + { + return IsNearlyZero(v.x) + &&IsNearlyZero(v.y); + } + + template + const bool IsNearlyZero(const glm::vec<3,T,Q> &v) + { + return IsNearlyZero(v.x) + &&IsNearlyZero(v.y) + &&IsNearlyZero(v.z); + } + + template + const bool IsNearlyEqual(const glm::vec<2,T,Q> &a,const glm::vec<2,T,Q> &b) + { + return IsNearlyZero(a.x-b.x) + &&IsNearlyZero(a.y-b.y); + } + + template + const bool IsNearlyEqual(const glm::vec<3,T,Q> &a,const glm::vec<3,T,Q> &b) + { + return IsNearlyZero(a.x-b.x) + &&IsNearlyZero(a.y-b.y) + &&IsNearlyZero(a.z-b.z); + } }//namespace hgl #endif//HGL_ALGORITHM_MATH_VECTOR_INCLUDE