use super::FuzzyEq;
pub trait FuzzyOrd: FuzzyEq {
fn fuzzy_gt_eps(&self, other: Self, fuzzy_epsilon: Self) -> bool;
#[inline]
fn fuzzy_gt(&self, other: Self) -> bool {
self.fuzzy_gt_eps(other, Self::fuzzy_epsilon())
}
fn fuzzy_lt_eps(&self, other: Self, fuzzy_epsilon: Self) -> bool;
#[inline]
fn fuzzy_lt(&self, other: Self) -> bool {
self.fuzzy_lt_eps(other, Self::fuzzy_epsilon())
}
#[inline]
fn fuzzy_in_range_eps(&self, min: Self, max: Self, fuzzy_epsilon: Self) -> bool {
self.fuzzy_gt_eps(min, fuzzy_epsilon) && self.fuzzy_lt_eps(max, fuzzy_epsilon)
}
#[inline]
fn fuzzy_in_range(&self, min: Self, max: Self) -> bool {
self.fuzzy_in_range_eps(min, max, Self::fuzzy_epsilon())
}
}
macro_rules! impl_fuzzy_ord {
($ty:ty) => {
impl FuzzyOrd for $ty {
#[inline]
fn fuzzy_gt_eps(&self, other: $ty, fuzzy_epsilon: $ty) -> bool {
self + fuzzy_epsilon > other
}
#[inline]
fn fuzzy_lt_eps(&self, other: $ty, fuzzy_epsilon: $ty) -> bool {
*self < other + fuzzy_epsilon
}
}
};
}
impl_fuzzy_ord!(f32);
impl_fuzzy_ord!(f64);