Skip to content

Commit

Permalink
✨ Implement partial ordering for the intervals
Browse files Browse the repository at this point in the history
  • Loading branch information
eigenein committed Jul 29, 2022
1 parent 9951fb6 commit 9758eff
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/interval/lower_upper.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::cmp::Ordering;
use std::ops::{Add, Div, Mul, Sub};

use num_traits::One;
Expand Down Expand Up @@ -80,3 +81,23 @@ where
}
}
}

impl<T> PartialEq for LowerUpperInterval<T> {
#[must_use]
fn eq(&self, _other: &Self) -> bool {
false
}
}

impl<T: PartialOrd> PartialOrd for LowerUpperInterval<T> {
#[must_use]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
if self.upper < other.lower {
Some(Ordering::Less)
} else if self.lower > other.upper {
Some(Ordering::Greater)
} else {
None
}
}
}
24 changes: 24 additions & 0 deletions src/interval/mean_margin.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::cmp::Ordering;
use std::ops::{Add, Div, Mul, Sub};

use num_traits::One;
Expand Down Expand Up @@ -78,3 +79,26 @@ where
}
}
}

impl<T> PartialEq for MeanMarginInterval<T> {
#[must_use]
fn eq(&self, _other: &Self) -> bool {
false
}
}

impl<T> PartialOrd for MeanMarginInterval<T>
where
T: Copy + Sub<Output = T> + Add<Output = T> + PartialOrd,
{
#[must_use]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
if self.upper() < other.lower() {
Some(Ordering::Less)
} else if self.lower() > other.upper() {
Some(Ordering::Greater)
} else {
None
}
}
}

0 comments on commit 9758eff

Please sign in to comment.