Skip to content

Commit

Permalink
Merge pull request #1349 from CAD97/patch-3
Browse files Browse the repository at this point in the history
Fix `glm::is_normalized` epsilon test
  • Loading branch information
tpdickso authored Mar 21, 2024
2 parents 990afe6 + f578181 commit 9948bf7
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion nalgebra-glm/src/gtx/vector_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ pub fn is_comp_null<T: Number, const D: usize>(v: &TVec<T, D>, epsilon: T) -> TV

/// Returns `true` if `v` has a magnitude of 1 (up to an epsilon).
pub fn is_normalized<T: RealNumber, const D: usize>(v: &TVec<T, D>, epsilon: T) -> bool {
abs_diff_eq!(v.norm_squared(), T::one(), epsilon = epsilon * epsilon)
// sqrt(1 + epsilon_{norm²} = 1 + epsilon_{norm}
// ==> epsilon_{norm²} = epsilon_{norm}² + 2*epsilon_{norm}
// For small epsilon, epsilon² is basically zero, so use 2*epsilon.
abs_diff_eq!(v.norm_squared(), T::one(), epsilon = epsilon + epsilon)
}

/// Returns `true` if `v` is zero (up to an epsilon).
Expand Down

0 comments on commit 9948bf7

Please sign in to comment.