Skip to content

Commit

Permalink
Fix glm::is_null epsilon test (#1350)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
CAD97 authored Jun 23, 2024
1 parent 292abfb commit 49906a3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions nalgebra-glm/src/gtx/vector_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::traits::Number;
///
/// * [`are_collinear2d()`]
pub fn are_collinear<T: Number>(v0: &TVec3<T>, v1: &TVec3<T>, epsilon: T) -> bool {
is_null(&v0.cross(v1), epsilon)
abs_diff_eq!(v0.cross(v1), TVec3::<T>::zeros(), epsilon = epsilon)
}

/// Returns `true` if two 2D vectors are collinear (up to an epsilon).
Expand Down Expand Up @@ -48,6 +48,6 @@ pub fn is_normalized<T: RealNumber, const D: usize>(v: &TVec<T, D>, epsilon: T)
}

/// Returns `true` if `v` is zero (up to an epsilon).
pub fn is_null<T: Number, const D: usize>(v: &TVec<T, D>, epsilon: T) -> bool {
abs_diff_eq!(*v, TVec::<T, D>::zeros(), epsilon = epsilon)
pub fn is_null<T: RealNumber, const D: usize>(v: &TVec<T, D>, epsilon: T) -> bool {
abs_diff_eq!(v.norm_squared(), T::zero(), epsilon = epsilon * epsilon)
}

0 comments on commit 49906a3

Please sign in to comment.