pub struct Interval<T> {
pub lb: T,
pub ub: T,
pub _marker: PhantomData<T>,
}Expand description
The Interval struct represents a range of values with a lower bound (lb) and an upper bound
(ub).
Properties:
lb: Thelbproperty represents the lower bound of the interval. It is of typeT, which is a generic type that must implement thePartialOrdtrait. This means that the typeTmust be able to be compared for ordering.ub: Theubproperty represents the upper bound of the interval. It is of typeT, which is a generic type that must implement thePartialOrdtrait. ThePartialOrdtrait allows for comparison between values of typeT._marker: The_markerfield is a marker field that is used to indicate that the generic typeTis used in the struct. It is typically used when you want to associate a type parameter with a struct, but you don’t actually need to store any values of that type in the struct.
Fields§
§lb: T§ub: T§_marker: PhantomData<T>Implementations§
Source§impl<T> Interval<T>
impl<T> Interval<T>
Sourcepub fn new(lb: T, ub: T) -> Self
pub fn new(lb: T, ub: T) -> Self
The function new creates a new instance of a struct with given lower and upper bounds.
Arguments:
lb: Thelbparameter represents the lower bound value. It is of typeT, which means it can be any type that implements the necessary traits for the struct.ub: Theubparameter represents the upper bound value. It is of typeT, which means it can be any type that implements the necessary traits for the struct.
Returns:
The new function is returning an instance of the struct Self.
§Examples
use physdes::interval::Interval;
use std::marker::PhantomData;
assert_eq!(Interval::new(1, 2), Interval { lb: 1, ub: 2, _marker: PhantomData });
assert_eq!(Interval::new(2, 1), Interval { lb: 2, ub: 1, _marker: PhantomData });Source§impl<T: Copy> Interval<T>
impl<T: Copy> Interval<T>
Source§impl<T: PartialOrd> Interval<T>
impl<T: PartialOrd> Interval<T>
Sourcepub fn is_invalid(&self) -> bool
pub fn is_invalid(&self) -> bool
The function is_invalid checks if the lower bound is greater than the upper bound.
Returns:
The is_invalid function is returning a boolean value based on the comparison self.lb > self.ub. If self.lb is greater than self.ub, it will return true, indicating that the
values are invalid. Otherwise, it will return false.
Trait Implementations§
Source§impl<T> Add<T> for Interval<T>
impl<T> Add<T> for Interval<T>
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)
The add_assign function in Rust adds a value to both the lower and upper bounds of a data
structure.
Arguments:
rhs: Therhsparameter in theadd_assignfunction represents the right-hand side operand that will be added to thelbandubfields of the struct or object on which the method is called.
Source§impl<T: PartialOrd> Contain<Interval<T>> for Interval<T>
The impl<T: PartialOrd> Contain<Interval<T>> for Interval<T> block is implementing the Contain
trait for the Interval<T> struct.
impl<T: PartialOrd> Contain<Interval<T>> for Interval<T>
The impl<T: PartialOrd> Contain<Interval<T>> for Interval<T> block is implementing the Contain
trait for the Interval<T> struct.
Source§fn contains(&self, other: &Interval<T>) -> bool
fn contains(&self, other: &Interval<T>) -> bool
The contains function in Rust checks if one interval contains another interval.
Arguments:
other: Theotherparameter is a reference to anInterval<T>object that is being compared to the currentInterval<T>object.
Returns:
The contains method is returning a boolean value, which indicates whether the interval self
contains the interval other. It checks if the lower bound of self is less than or equal to
the lower bound of other, and if the upper bound of other is less than or equal to the upper
bound of self. If both conditions are true, it returns `true
Source§impl<T: PartialOrd> Contain<T> for Interval<T>
The impl<T: PartialOrd> Contain<T> for Interval<T> block is implementing the Contain trait for
the Interval<T> struct.
impl<T: PartialOrd> Contain<T> for Interval<T>
The impl<T: PartialOrd> Contain<T> for Interval<T> block is implementing the Contain trait for
the Interval<T> struct.
Source§fn contains(&self, other: &T) -> bool
fn contains(&self, other: &T) -> bool
The function checks if a value is within a specified range.
Arguments:
other: Theotherparameter is a reference to a value of typeT, which is the same type as the elements stored in the struct or data structure that contains thecontainsmethod. The method checks if the value referenced byotherfalls within the range defined by the lower bound (`
Returns:
A boolean value is being returned, indicating whether the value other is within the range
defined by self.lb and self.ub.
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>,
Source§fn displace(&self, other: &Interval<T>) -> Self::Output
fn displace(&self, other: &Interval<T>) -> Self::Output
The displace function in Rust calculates the displacement between two intervals.
Arguments:
other: Theotherparameter in thedisplacefunction represents anotherIntervalobject of the same type asself. It is used to displace the lower bound and upper bound of the currentIntervalobject (self) by the corresponding lower and upper bounds of theother
type Output = Interval<T>
Source§impl<T> Display for Interval<T>
impl<T> Display for Interval<T>
Source§fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult
The function fmt in Rust is used to format a struct by writing its lower bound and upper bound
values in square brackets.
Arguments:
f: Thefparameter in thefmtfunction is a mutable reference to aFormatterstruct. ThisFormatterstruct is used for formatting and writing output.
Returns:
The fmt method is returning a FmtResult, which is an alias for Result<(), Error>.
Source§impl<T> Enlarge<T> for Interval<T>
impl<T> Enlarge<T> for Interval<T>
Source§fn enlarge_with(&self, alpha: T) -> Self
fn enlarge_with(&self, alpha: T) -> Self
The enlarge_with function in Rust enlarges an interval by adding a specified value to its
lower bound and subtracting the same value from its upper bound.
Arguments:
alpha: Thealphaparameter in theenlarge_withfunction represents the amount by which the lower bound (lb) and upper bound (ub) of anIntervalstruct are adjusted. The lower bound is decreased byalphaand the upper bound is increased byalpha, effectively enlarg
Returns:
The enlarge_with method is returning a new Interval instance with the lower bound (lb)
decreased by alpha and the upper bound (ub) increased by alpha. The _marker field is
copied from the original Interval instance.
type Output = Interval<T>
Source§impl<T> Hull<Interval<T>> for Interval<T>
impl<T> Hull<Interval<T>> for Interval<T>
Source§fn hull_with(&self, other: &Interval<T>) -> Self::Output
fn hull_with(&self, other: &Interval<T>) -> Self::Output
The hull_with function calculates the hull (bounding interval) of two intervals by taking the
minimum lower bound and maximum upper bound.
Arguments:
other:otheris a reference to anInterval<T>object that is being passed as a parameter to thehull_withmethod.
type Output = 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<T> Intersect<Interval<T>> for Interval<T>
impl<T> Intersect<Interval<T>> for Interval<T>
Source§fn intersect_with(&self, other: &Interval<T>) -> Self::Output
fn intersect_with(&self, other: &Interval<T>) -> Self::Output
The intersect_with function returns the intersection of two intervals by finding the maximum
lower bound and minimum upper bound between them.
Arguments:
other: Theotherparameter is a reference to anInterval<T>object, which is used to intersect with the currentInterval<T>object. Theintersect_withmethod calculates the intersection of the two intervals and returns a newInterval<T>object as the output.
type Output = Interval<T>
Source§impl<T> Intersect<T> for Interval<T>
impl<T> Intersect<T> for Interval<T>
Source§fn intersect_with(&self, other: &T) -> Self::Output
fn intersect_with(&self, other: &T) -> Self::Output
The intersect_with function calculates the intersection of two values.
Arguments:
other: Theotherparameter is a reference to an object of typeT, which is the same type as the object on which theintersect_withmethod is being called. The method calculates the intersection of the object’s lower bound (lb) and upper bound (ub) with the corresponding values
type Output = Interval<T>
Source§impl MinDist<Interval<i32>> for Interval<i32>
impl MinDist<Interval<i32>> for Interval<i32>
Source§fn min_dist_with(&self, other: &Interval<i32>) -> u32
fn min_dist_with(&self, other: &Interval<i32>) -> u32
The min_dist_with function calculates the minimum distance between two intervals of integers.
Arguments:
other: Themin_dist_withfunction calculates the minimum distance between two intervals. Theselfinterval is represented by the lower boundlband upper boundubof the current instance, while theotherinterval is passed as a reference to anInterval<i32>.
Returns:
The min_dist_with function returns the minimum distance between two intervals. It calculates
the distance based on the upper and lower bounds of the intervals. If the upper bound of the
first interval is less than the lower bound of the second interval, it returns the difference
between the lower bound of the second interval and the upper bound of the first interval. If the
upper bound of the second interval is less
Source§impl MinDist<Interval<i32>> for i32
impl MinDist<Interval<i32>> for i32
Source§fn min_dist_with(&self, other: &Interval<i32>) -> u32
fn min_dist_with(&self, other: &Interval<i32>) -> u32
This Rust function calculates the minimum distance between two intervals of integers.
Arguments:
other: Themin_dist_withfunction calculates the minimum distance between two intervals. Theselfinterval is compared with theotherinterval to determine the minimum distance between them.
Returns:
The min_dist_with function returns the minimum distance between two intervals. If the lower
bound of self is less than the lower bound of other, it returns the difference between the
lower bounds as a u32. If the upper bound of other is less than the upper bound of self,
it returns the difference between the upper bounds as a u32. Otherwise
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
This Rust function calculates the minimum distance between a value and a range defined by lower and upper bounds.
Arguments:
other: Theotherparameter in themin_dist_withfunction is a reference to ani32value. This parameter is used to calculate the minimum distance between the current instance (self) and the providedi32value.
Returns:
The min_dist_with function returns the minimum distance between the value represented by
self and the value referenced by other. If the value referenced by other is greater than
the upper bound (ub) of self, it returns the difference between other and ub. If the
value referenced by other is less than the lower bound (lb) of `self
Source§impl<T> Mul<T> for Interval<T>
impl<T> Mul<T> for Interval<T>
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)
The mul_assign function in Rust multiplies both the lower and upper bounds of a range by a
given value.
Arguments:
rhs: Therhsparameter in themul_assignfunction represents the value that will be multiplied with thelbandubfields of the struct or object on which the method is called.
Source§impl<T: PartialOrd> Overlap<Interval<T>> for Interval<T>
The impl<T: PartialOrd> Overlap<Interval<T>> for Interval<T> block is implementing the Overlap
trait for the Interval<T> struct.
impl<T: PartialOrd> Overlap<Interval<T>> for Interval<T>
The impl<T: PartialOrd> Overlap<Interval<T>> for Interval<T> block is implementing the Overlap
trait for the Interval<T> struct.
Source§fn overlaps(&self, other: &Interval<T>) -> bool
fn overlaps(&self, other: &Interval<T>) -> bool
The overlaps function in Rust checks if two intervals overlap with each other.
Arguments:
other: Theotherparameter in theoverlapsfunction represents another interval that you want to check for overlap with the interval on which the method is called.
Returns:
The overlaps function is returning a boolean value, which indicates whether the interval
self overlaps with the interval other. If there is an overlap between the two intervals, the
function will return true, otherwise it will return false.
Source§impl<T: PartialOrd> Overlap<T> for Interval<T>
impl<T: PartialOrd> Overlap<T> for Interval<T>
Source§fn overlaps(&self, other: &T) -> bool
fn overlaps(&self, other: &T) -> bool
The overlaps function in Rust checks if two values overlap within a range.
Arguments:
other: Theotherparameter is a reference to an object of typeT, which is the same type as the object that the methodoverlapsis being called on.
Returns:
The overlaps function is returning a boolean value, which indicates whether the range
represented by self overlaps with the range represented by other.
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>
The function partial_cmp compares the lower bound of self with the upper bound of other
and returns the result as an Option of Ordering.
Arguments:
other: Theotherparameter is a reference to another object of the same type asself.
Returns:
an Option containing a std::cmp::Ordering value.
§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));Source§impl<T> Sub<T> for Interval<T>
impl<T> Sub<T> for Interval<T>
Source§fn sub(self, rhs: T) -> Self::Output
fn sub(self, rhs: T) -> Self::Output
The function subtracts a value from both the lower and upper bounds of an interval.
Arguments:
rhs: Therhsparameter in the code snippet represents the right-hand side operand that will be subtracted from the interval’s lower bound (lb) and upper bound (ub) values.
Source§impl<T> SubAssign<T> for Interval<T>
impl<T> SubAssign<T> for Interval<T>
Source§fn sub_assign(&mut self, rhs: T)
fn sub_assign(&mut self, rhs: T)
The sub_assign function subtracts a value from both the lower and upper bounds of a variable.
Arguments:
rhs:rhsis a parameter of typeTthat is passed by value to thesub_assignfunction. It is used to subtract its value from bothself.lbandself.ubin the function implementation.
impl<T: Copy> Copy for Interval<T>
impl<T: Eq> Eq for Interval<T>
impl<T> StructuralPartialEq for Interval<T>
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> 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.
Source§impl<T> Intersect<Interval<T>> for T
impl<T> Intersect<Interval<T>> for T
Source§fn intersect_with(
&self,
other: &Interval<T>,
) -> <T as Intersect<Interval<T>>>::Output
fn intersect_with( &self, other: &Interval<T>, ) -> <T as Intersect<Interval<T>>>::Output
The intersect_with function in Rust swaps the receiver and argument before calling the
intersect_with method on the argument.
Arguments:
other: Theotherparameter in theintersect_withfunction represents anotherInterval<T>that you want to intersect with the current interval.
type Output = Interval<T>
Source§impl<T> Overlap<Interval<T>> for Twhere
T: PartialOrd,
impl<T> Overlap<Interval<T>> for Twhere
T: PartialOrd,
Source§fn overlaps(&self, other: &Interval<T>) -> bool
fn overlaps(&self, other: &Interval<T>) -> bool
The overlaps function in Rust checks if two intervals overlap with each other.
Arguments:
other: Theotherparameter is a reference to anInterval<T>struct, which represents another interval. TheInterval<T>struct likely contains two fields,lbandub, representing the lower and upper bounds of the interval, respectively. Theoverlapsmethod is used to
Returns:
The overlaps function is returning a boolean value. It checks if the current interval (self)
overlaps with another interval (other) by comparing their lower bounds and upper bounds. If
there is any overlap between the two intervals, it returns true, otherwise it returns false.