diff --git a/src/math/scalar.rs b/src/math/scalar.rs index 72a1df265..fecf8bf5b 100644 --- a/src/math/scalar.rs +++ b/src/math/scalar.rs @@ -1,4 +1,4 @@ -use std::{cmp, f64::consts::PI, ops}; +use std::{cmp, f64::consts::PI, hash::Hash, ops}; use approx::AbsDiffEq; @@ -84,6 +84,22 @@ impl Scalar { } } +impl Eq for Scalar {} + +impl Ord for Scalar { + fn cmp(&self, other: &Self) -> cmp::Ordering { + // Should never panic, as `from_f64` checks that the wrapped value is + // finite. + self.partial_cmp(&other).unwrap() + } +} + +impl Hash for Scalar { + fn hash(&self, state: &mut H) { + self.0.to_bits().hash(state); + } +} + impl From for Scalar { fn from(scalar: f32) -> Self { Self::from_f64(scalar as f64)