move FloatOrd to bevy_core
This commit is contained in:
parent
f4b07ec9c7
commit
e8e3e3c20f
@ -2,7 +2,6 @@ use crate::System;
|
|||||||
use legion::prelude::Schedule;
|
use legion::prelude::Schedule;
|
||||||
use std::{
|
use std::{
|
||||||
borrow::Cow,
|
borrow::Cow,
|
||||||
cmp::Ordering,
|
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -106,33 +105,3 @@ impl SchedulePlan {
|
|||||||
self
|
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 bytes;
|
||||||
pub mod time;
|
pub mod time;
|
||||||
pub mod transform;
|
pub mod transform;
|
||||||
|
pub mod float_ord;
|
||||||
|
|
||||||
use bevy_app::{stage, AppBuilder, AppPlugin};
|
use bevy_app::{stage, AppBuilder, AppPlugin};
|
||||||
use bevy_transform::{
|
use bevy_transform::{
|
||||||
|
Loading…
Reference in New Issue
Block a user