mirror of
https://github.com/hannobraun/Fornjot
synced 2025-01-24 00:56:06 +00:00
Implement Eq
, Ord
, and Hash
for Scalar
These implementations aren't available for `f64` and other floating-point values. Providing them is the whole point of why `Scalar` exists.
This commit is contained in:
parent
3a75c9ef92
commit
8f3d6f2178
@ -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<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||
self.0.to_bits().hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl From<f32> for Scalar {
|
||||
fn from(scalar: f32) -> Self {
|
||||
Self::from_f64(scalar as f64)
|
||||
|
Loading…
Reference in New Issue
Block a user