[−][src]Enum intervals_general::interval::Interval
Interval enum capable of general interval representation
Where applicable, using lower bound a and upper bound b. An Interval taxonomy was pulled from proofwiki.
- Closed ->
[a, b] - Open ->
(a,b) - LeftHalfOpen ->
(a, b] - RightHalfOpen ->
[a, b) - UnboundedClosedRight ->
(-inf, a] - UnboundedOpenRight ->
(-inf, a) - UnboundedClosedLeft ->
[a, inf) - UnboundedOpenLeft ->
(a, inf) - Singeleton ->
[a] - Unbounded ->
(-inf, inf) - Empty
Examples
use intervals_general::bound_pair::BoundPair; use intervals_general::interval::Interval; let bounds = BoundPair::new(1.0, 2.0).ok_or("invalid BoundPair")?; let right_half_open = Interval::RightHalfOpen { bound_pair: bounds }; // [1.0, 2.0)
Variants
ClosedFields of Closed
bound_pair: BoundPair<T>OpenFields of Open
bound_pair: BoundPair<T>LeftHalfOpenFields of LeftHalfOpen
bound_pair: BoundPair<T>RightHalfOpenFields of RightHalfOpen
bound_pair: BoundPair<T>UnboundedClosedRightFields of UnboundedClosedRight
UnboundedOpenRightFields of UnboundedOpenRight
UnboundedClosedLeftFields of UnboundedClosedLeft
UnboundedOpenLeftFields of UnboundedOpenLeft
SingletonFields of Singleton
UnboundedEmptyMethods
impl<T> Interval<T> where
T: Copy,
T: PartialOrd, [src]
T: Copy,
T: PartialOrd,
pub fn contains(&self, other: &Interval<T>) -> bool[src]
Verify whether self contains the specified interval
Interval I1.contains(I2) if and only if:
- The left bound of I1 is bounded and less than or equal to the left bound of I2 OR
- the left bound of I1 is unbounded and the left bound of I2 is unbounded
AND
- The right bound of I1 is bounded and greater than or equal to the right bound of I2 OR
- The right bound of I1 isunbounded and the left bound of I2 is unbounded
Additionally:
- The Empty interval does not contain the Empty interval
Examples
use intervals_general::bound_pair::BoundPair; use intervals_general::interval::Interval; let right_half_open = Interval::RightHalfOpen { bound_pair: BoundPair::new(1.0, 5.0).ok_or("invalid BoundPair")?, }; let contained_interval = Interval::Open { bound_pair: BoundPair::new(1.0, 2.0).ok_or("invalid BoundPair")?, }; let non_contained_interval = Interval::Closed { bound_pair: BoundPair::new(4.0, 5.0).ok_or("invalid BoundPair")?, }; assert_eq!(right_half_open.contains(&contained_interval), true); assert_eq!(right_half_open.contains(&non_contained_interval), false);
pub fn intersect(&self, other: &Interval<T>) -> Interval<T>[src]
Intersect an with the specified Interval
Take the intersection of self with the specified Interval.
Examples
use intervals_general::bound_pair::BoundPair; use intervals_general::interval::Interval; let i1 = Interval::RightHalfOpen { bound_pair: BoundPair::new(1, 5).ok_or("invalid BoundPair")?, }; let i2 = Interval::Open { bound_pair: BoundPair::new(-1, 2).ok_or("invalid BoundPair")?, }; assert_eq!( i1.intersect(&i2), Interval::RightHalfOpen { bound_pair: BoundPair::new(1, 2).ok_or("invalid BoundPair")? } );
pub fn left_partial_cmp(&self, other: &Interval<T>) -> Option<Ordering>[src]
The PartialOrd::partial_cmp implementation for left Bounds
Though Intervals on some generics (e.g. integers) can supply Ord because they form a total order, unfortunately our floating point implementations break such properties. Therefore the best we can do under some generics is satisfy PartialOrd.
Examples
use intervals_general::bound_pair::BoundPair; use intervals_general::interval::Interval; use std::cmp::Ordering; let right_half_open = Interval::RightHalfOpen { bound_pair: BoundPair::new(1.0, 5.0).ok_or("invalid BoundPair")?, }; let contained_interval = Interval::Open { bound_pair: BoundPair::new(1.0, 2.0).ok_or("invalid BoundPair")?, }; assert_eq!( contained_interval.left_partial_cmp(&right_half_open), Some(Ordering::Greater) );
pub fn right_partial_cmp(&self, other: &Interval<T>) -> Option<Ordering>[src]
The PartialOrd::partial_cmp implementation for right Bounds
Though Intervals on some generics (e.g. integers) can supply Ord because they form a total order, unfortunately our floating point implementations break such properties. Therefore the best we can do under some generics is satisfy PartialOrd.
Examples
use intervals_general::bound_pair::BoundPair; use intervals_general::interval::Interval; use std::cmp::Ordering; let right_half_open = Interval::RightHalfOpen { bound_pair: BoundPair::new(1.0, 5.0).ok_or("invalid BoundPair")?, }; let contained_interval = Interval::Open { bound_pair: BoundPair::new(1.0, 2.0).ok_or("invalid BoundPair")?, }; assert_eq!( contained_interval.right_partial_cmp(&right_half_open), Some(Ordering::Less) );
pub fn width(&self) -> Option<<T as Sub>::Output> where
T: Sub, [src]
T: Sub,
Compute the width of the interval
Returns right - left bound, so long as finite, else None TODO How to handle overflow detection? I do not have access to check_sub due to generic? Presently for interval widths exceeding the Boundary type representation, panic occurs in debug mode and wrapping occurs in production mode.
Examples
use intervals_general::bound_pair::BoundPair; use intervals_general::interval::Interval; let interval = Interval::RightHalfOpen { bound_pair: BoundPair::new(1, 5).ok_or("invalid BoundPair")?, }; let width: i32 = interval.width().ok_or("width was None")?; assert_eq!(width, 4);
pub fn complement(
&self
) -> Either<Once<Interval<T>>, Chain<Once<Interval<T>>, Once<Interval<T>>>>[src]
&self
) -> Either<Once<Interval<T>>, Chain<Once<Interval<T>>, Once<Interval<T>>>>
Take the complement of the Interval, return one or two Intervals
The return value is iterable and contains exclusively one or two Intervals, depending upon result.
Example
use intervals_general::bound_pair::BoundPair; use intervals_general::interval::Interval; let mut result_it = Interval::Closed { bound_pair: BoundPair::new(1, 5).ok_or("invalid BoundPair")?, } .complement(); assert_eq!( result_it.next(), Some(Interval::UnboundedOpenRight { right: 1 }) ); assert_eq!( result_it.next(), Some(Interval::UnboundedOpenLeft{ left: 5 }) ); assert_eq!( result_it.next(), None );
Trait Implementations
impl<T: Copy> Copy for Interval<T>[src]
impl<T: PartialEq> PartialEq<Interval<T>> for Interval<T>[src]
impl<T: Clone> Clone for Interval<T>[src]
fn clone(&self) -> Interval<T>[src]
fn clone_from(&mut self, source: &Self)1.0.0[src]
Performs copy-assignment from source. Read more
impl<T: Debug> Debug for Interval<T>[src]
impl<T> Display for Interval<T> where
T: Debug, [src]
T: Debug,
Implement the Display trait for Intervals
Here I uses Wirth Interval Notation.
Examples
use intervals_general::bound_pair::BoundPair; use intervals_general::interval::Interval; let bp = BoundPair::new(1, 5).ok_or("invalid BoundPair")?; assert_eq!(format!("{}", Interval::Closed { bound_pair: bp }), "[1..5]"); assert_eq!( format!("{}", Interval::UnboundedOpenRight { right: 5 }), "(←..5)" );
Auto Trait Implementations
Blanket Implementations
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T[src]
fn clone_into(&self, target: &mut T)[src]
impl<T> From for T[src]
impl<T, U> Into for T where
U: From<T>, [src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized, [src]
T: Display + ?Sized,
impl<T, U> TryFrom for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T> Borrow for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T, U> TryInto for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,