pub struct Interval<T> {
pub lb: T,
pub ub: T,
pub _marker: PhantomData<T>,
}Expand description
A range of values with a lower bound (lb) and an upper bound (ub).
lb ub
|---------|
*=========*-----> TAn interval is valid when lb <= ub. The is_invalid() method checks for the
invalid case lb > ub.
§Examples
use physdes::interval::Interval;
let interval = Interval::new(1, 5);
assert_eq!(interval.lb, 1);
assert_eq!(interval.ub, 5);Fields§
§lb: T§ub: T§_marker: PhantomData<T>Implementations§
Source§impl<T> Interval<T>
impl<T> Interval<T>
Sourcepub const fn new(lb: T, ub: T) -> Self
pub const fn new(lb: T, ub: T) -> Self
Creates a new interval with the given lower and upper bounds.
Note: No validity check is performed. An interval where lb > ub is considered
invalid and can be checked with is_invalid().
§Examples
use physdes::interval::Interval;
let interval = Interval::new(1, 5);
assert_eq!(interval.lb, 1);
assert_eq!(interval.ub, 5);
let interval = Interval::new(5, 1); // Invalid interval but still created
assert_eq!(interval.lb, 5);
assert_eq!(interval.ub, 1);Source§impl<T: PartialOrd> Interval<T>
impl<T: PartialOrd> Interval<T>
Sourcepub fn is_invalid(&self) -> bool
pub fn is_invalid(&self) -> bool
Returns true if the lower bound exceeds the upper bound (invalid interval).
§Examples
use physdes::interval::Interval;
let valid_interval = Interval::new(1, 5);
assert!(!valid_interval.is_invalid());
let invalid_interval = Interval::new(5, 1);
assert!(invalid_interval.is_invalid());Trait Implementations§
Source§impl<T: Add<Output = T>> Add for Interval<T>
Interval addition (component-wise): $[a,b] + [c,d] = [a+c,; b+d]$
impl<T: Add<Output = T>> Add for Interval<T>
Interval addition (component-wise): $[a,b] + [c,d] = [a+c,; b+d]$
Source§impl<T> AddAssign<T> for Interval<T>
impl<T> AddAssign<T> for Interval<T>
Source§fn add_assign(&mut self, rhs: T)
fn add_assign(&mut self, rhs: T)
Shift the interval by a scalar: $[a,b] \mathrel{+}= t \implies [a+t,; b+t]$
Source§impl<T: PartialOrd> Contain<T> for Interval<T>
impl<T: PartialOrd> Contain<T> for Interval<T>
impl<T: Copy> Copy for Interval<T>
Source§impl<T> Displacement<Interval<T>> for Interval<T>where
T: Displacement<T, Output = T>,
impl<T> Displacement<Interval<T>> for Interval<T>where
T: Displacement<T, Output = T>,
impl<T: Eq> Eq for Interval<T>
Source§impl<T> Hull<T> for Interval<T>
impl<T> Hull<T> for Interval<T>
Source§fn hull_with(&self, other: &T) -> Self::Output
fn hull_with(&self, other: &T) -> Self::Output
The hull_with function calculates the hull (minimum and maximum values) between two values.
Arguments:
other: Theotherparameter is a reference to a value of typeT, which is the same type as the values stored in the struct implementing thehull_withmethod. In this method, theothervalue is used to update the lower bound (lb) and upper bound (`
type Output = Interval<T>
Source§impl MinDist<i32> for Interval<i32>
impl MinDist<i32> for Interval<i32>
Source§fn min_dist_with(&self, other: &i32) -> u32
fn min_dist_with(&self, other: &i32) -> u32
Computes the minimum distance between an interval and a scalar value.
Source§impl<T> MulAssign<T> for Interval<T>
impl<T> MulAssign<T> for Interval<T>
Source§fn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
Scale the interval by a scalar: $[a,b] \mathrel{*}= t \implies [a \cdot t,; b \cdot t]$
Source§impl<T: PartialOrd> Overlap<T> for Interval<T>
impl<T: PartialOrd> Overlap<T> for Interval<T>
Source§impl<T: PartialEq> PartialEq for Interval<T>
impl<T: PartialEq> PartialEq for Interval<T>
Source§impl<T: PartialOrd> PartialOrd for Interval<T>
impl<T: PartialOrd> PartialOrd for Interval<T>
Source§fn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
Orders intervals by their position: Less if ub < other.lb, Greater if other.ub < self.lb, Equal otherwise.
§Examples
use physdes::interval::Interval;
use std::marker::PhantomData;
assert_eq!(Interval::new(1, 2).partial_cmp(&Interval::new(3, 4)), Some(std::cmp::Ordering::Less));impl<T: PartialEq> StructuralPartialEq for Interval<T>
Source§impl<T: Sub<Output = T>> Sub for Interval<T>
Interval subtraction (component-wise): $[a,b] - [c,d] = [a-c,; b-d]$
impl<T: Sub<Output = T>> Sub for Interval<T>
Interval subtraction (component-wise): $[a,b] - [c,d] = [a-c,; b-d]$
Auto Trait Implementations§
impl<T> Freeze for Interval<T>where
T: Freeze,
impl<T> RefUnwindSafe for Interval<T>where
T: RefUnwindSafe,
impl<T> Send for Interval<T>where
T: Send,
impl<T> Sync for Interval<T>where
T: Sync,
impl<T> Unpin for Interval<T>where
T: Unpin,
impl<T> UnsafeUnpin for Interval<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Interval<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Contain<Interval<T>> for Twhere
T: PartialOrd,
impl<T> Contain<Interval<T>> for Twhere
T: PartialOrd,
Source§fn contains(&self, _other: &Interval<T>) -> bool
fn contains(&self, _other: &Interval<T>) -> bool
The function contains always returns false and takes a reference to another Interval as
input.
Arguments:
_other: The_otherparameter is a reference to anIntervalobject of the same typeTas the current object.
Returns:
The contains function is returning a boolean value false.