diff --git a/crates/bevy_app/src/schedule_plan.rs b/crates/bevy_app/src/schedule_plan.rs index c252ed9c3e..a7d00ce421 100644 --- a/crates/bevy_app/src/schedule_plan.rs +++ b/crates/bevy_app/src/schedule_plan.rs @@ -2,7 +2,6 @@ use crate::System; use legion::prelude::Schedule; use std::{ borrow::Cow, - cmp::Ordering, collections::{HashMap, HashSet}, }; @@ -105,34 +104,4 @@ impl SchedulePlan { self } -} - -// working around the famous "rust float ordering" problem -#[derive(PartialOrd)] -struct FloatOrd(f32); - -impl Ord for FloatOrd { - fn cmp(&self, other: &Self) -> Ordering { - self.0.partial_cmp(&other.0).unwrap_or_else(|| { - if self.0.is_nan() && !other.0.is_nan() { - Ordering::Less - } else if !self.0.is_nan() && other.0.is_nan() { - Ordering::Greater - } else { - Ordering::Equal - } - }) - } -} - -impl PartialEq for FloatOrd { - fn eq(&self, other: &Self) -> bool { - if self.0.is_nan() && other.0.is_nan() { - true - } else { - self.0 == other.0 - } - } -} - -impl Eq for FloatOrd {} +} \ No newline at end of file diff --git a/crates/bevy_core/src/float_ord.rs b/crates/bevy_core/src/float_ord.rs new file mode 100644 index 0000000000..7a02e85fc7 --- /dev/null +++ b/crates/bevy_core/src/float_ord.rs @@ -0,0 +1,41 @@ +use crate::bytes::AsBytes; +use std::{ + cmp::Ordering, + hash::{Hash, Hasher}, +}; + +// working around the famous "rust float ordering" problem +#[derive(Debug, Copy, Clone, PartialOrd)] +pub struct FloatOrd(pub f32); + +impl Ord for FloatOrd { + fn cmp(&self, other: &Self) -> Ordering { + self.0.partial_cmp(&other.0).unwrap_or_else(|| { + if self.0.is_nan() && !other.0.is_nan() { + Ordering::Less + } else if !self.0.is_nan() && other.0.is_nan() { + Ordering::Greater + } else { + Ordering::Equal + } + }) + } +} + +impl PartialEq for FloatOrd { + fn eq(&self, other: &Self) -> bool { + if self.0.is_nan() && other.0.is_nan() { + true + } else { + self.0 == other.0 + } + } +} + +impl Eq for FloatOrd {} + +impl Hash for FloatOrd { + fn hash(&self, state: &mut H) { + state.write(self.0.as_bytes()); + } +} diff --git a/crates/bevy_core/src/lib.rs b/crates/bevy_core/src/lib.rs index a9ddc544db..178716fa56 100644 --- a/crates/bevy_core/src/lib.rs +++ b/crates/bevy_core/src/lib.rs @@ -1,6 +1,7 @@ pub mod bytes; pub mod time; pub mod transform; +pub mod float_ord; use bevy_app::{stage, AppBuilder, AppPlugin}; use bevy_transform::{