From 49906a35be163182a547f6300f67e94eb5012882 Mon Sep 17 00:00:00 2001 From: Christopher Durham Date: Sun, 23 Jun 2024 05:09:52 -0400 Subject: [PATCH] Fix glm::is_null epsilon test (#1350) The existing implementation compares each component to zero with an epsilon; effectively `glm::all(glm::is_comp_null(v, epsilon))`. This probably isn't the desired semantics when calling `glm::is_null`; rather, we want to determine if the magnitude of the vector is within `epsilon` units of zero. It's the question of circle versus square. This behavior matches that of OpenGL Mathematics. --- nalgebra-glm/src/gtx/vector_query.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nalgebra-glm/src/gtx/vector_query.rs b/nalgebra-glm/src/gtx/vector_query.rs index a0b9f6214..e9fef7b39 100644 --- a/nalgebra-glm/src/gtx/vector_query.rs +++ b/nalgebra-glm/src/gtx/vector_query.rs @@ -9,7 +9,7 @@ use crate::traits::Number; /// /// * [`are_collinear2d()`] pub fn are_collinear(v0: &TVec3, v1: &TVec3, epsilon: T) -> bool { - is_null(&v0.cross(v1), epsilon) + abs_diff_eq!(v0.cross(v1), TVec3::::zeros(), epsilon = epsilon) } /// Returns `true` if two 2D vectors are collinear (up to an epsilon). @@ -48,6 +48,6 @@ pub fn is_normalized(v: &TVec, epsilon: T) } /// Returns `true` if `v` is zero (up to an epsilon). -pub fn is_null(v: &TVec, epsilon: T) -> bool { - abs_diff_eq!(*v, TVec::::zeros(), epsilon = epsilon) +pub fn is_null(v: &TVec, epsilon: T) -> bool { + abs_diff_eq!(v.norm_squared(), T::zero(), epsilon = epsilon * epsilon) }