mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
move FloatOrd to bevy_core
This commit is contained in:
parent
f4b07ec9c7
commit
e8e3e3c20f
3 changed files with 43 additions and 32 deletions
|
@ -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 {}
|
||||
}
|
41
crates/bevy_core/src/float_ord.rs
Normal file
41
crates/bevy_core/src/float_ord.rs
Normal file
|
@ -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<H: Hasher>(&self, state: &mut H) {
|
||||
state.write(self.0.as_bytes());
|
||||
}
|
||||
}
|
|
@ -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::{
|
||||
|
|
Loading…
Reference in a new issue