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.
This commit is contained in:
parent
292abfbaa0
commit
49906a35be
|
@ -9,7 +9,7 @@ use crate::traits::Number;
|
||||||
///
|
///
|
||||||
/// * [`are_collinear2d()`]
|
/// * [`are_collinear2d()`]
|
||||||
pub fn are_collinear<T: Number>(v0: &TVec3<T>, v1: &TVec3<T>, epsilon: T) -> bool {
|
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).
|
/// Returns `true` if two 2D vectors are collinear (up to an epsilon).
|
||||||
|
@ -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).
|
/// 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 {
|
pub fn is_null<T: RealNumber, const D: usize>(v: &TVec<T, D>, epsilon: T) -> bool {
|
||||||
abs_diff_eq!(*v, TVec::<T, D>::zeros(), epsilon = epsilon)
|
abs_diff_eq!(v.norm_squared(), T::zero(), epsilon = epsilon * epsilon)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue