Interval

Struct Interval 

Source
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: The lb property represents the lower bound of the interval. It is of type T, which is a generic type that must implement the PartialOrd trait. This means that the type T must be able to be compared for ordering.
  • ub: The ub property represents the upper bound of the interval. It is of type T, which is a generic type that must implement the PartialOrd trait. The PartialOrd trait allows for comparison between values of type T.
  • _marker: The _marker field is a marker field that is used to indicate that the generic type T is 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>

Source

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: The lb parameter represents the lower bound value. It is of type T, which means it can be any type that implements the necessary traits for the struct.
  • ub: The ub parameter represents the upper bound value. It is of type T, 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>

Source

pub fn lb(&self) -> T

The function lb returns the value of the field lb from the struct.

Returns:

The lb method is returning the value of the lb field of the struct or object that the method is being called on.

Source

pub fn ub(&self) -> T

This Rust function returns the value of the field ub.

Returns:

The ub field of the struct is being returned.

Source§

impl<T: PartialOrd> Interval<T>

Source

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.

Source§

impl<T: Copy + Sub<Output = T>> Interval<T>

Source

pub fn length(&self) -> T

The length function calculates the difference between the upper bound (ub) and lower bound (lb) of a value.

Returns:

The length method is returning the difference between the ub (upper bound) and lb (lower bound) values of the struct instance.

Trait Implementations§

Source§

impl<T> Add<T> for Interval<T>
where T: Copy + Add<Output = T>,

Source§

fn add(self, rhs: T) -> Self::Output

The add function in Rust adds a value to both the lower and upper bounds of an Interval struct.

Arguments:

  • rhs: The rhs parameter in the add function represents the right-hand side operand that will be added to the current Interval instance.
Source§

type Output = Interval<T>

The resulting type after applying the + operator.
Source§

impl<T: Add<Output = T>> Add for Interval<T>

Source§

type Output = Interval<T>

The resulting type after applying the + operator.
Source§

fn add(self, other: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<T> AddAssign<T> for Interval<T>
where T: Copy + AddAssign<T>,

Source§

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: The rhs parameter in the add_assign function represents the right-hand side operand that will be added to the lb and ub fields of the struct or object on which the method is called.
Source§

impl<T: Clone> Clone for Interval<T>

Source§

fn clone(&self) -> Interval<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
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.

Source§

fn contains(&self, other: &Interval<T>) -> bool

The contains function in Rust checks if one interval contains another interval.

Arguments:

  • other: The other parameter is a reference to an Interval<T> object that is being compared to the current Interval<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.

Source§

fn contains(&self, other: &T) -> bool

The function checks if a value is within a specified range.

Arguments:

  • other: The other parameter is a reference to a value of type T, which is the same type as the elements stored in the struct or data structure that contains the contains method. The method checks if the value referenced by other falls 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: Debug> Debug for Interval<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Displacement<Interval<T>> for Interval<T>
where T: Displacement<T, Output = T>,

Source§

fn displace(&self, other: &Interval<T>) -> Self::Output

The displace function in Rust calculates the displacement between two intervals.

Arguments:

  • other: The other parameter in the displace function represents another Interval object of the same type as self. It is used to displace the lower bound and upper bound of the current Interval object (self) by the corresponding lower and upper bounds of the other
Source§

type Output = Interval<T>

Source§

impl<T> Display for Interval<T>
where T: PartialOrd + Copy + Display,

Source§

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: The f parameter in the fmt function is a mutable reference to a Formatter struct. This Formatter struct 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>
where T: Copy + Add<Output = T> + Sub<Output = T>,

Source§

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: The alpha parameter in the enlarge_with function represents the amount by which the lower bound (lb) and upper bound (ub) of an Interval struct are adjusted. The lower bound is decreased by alpha and the upper bound is increased by alpha, 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.

Source§

type Output = Interval<T>

Source§

impl<T> Hull<Interval<T>> for Interval<T>
where T: Copy + Ord,

Source§

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: other is a reference to an Interval<T> object that is being passed as a parameter to the hull_with method.
Source§

type Output = Interval<T>

Source§

impl<T> Hull<T> for Interval<T>
where T: Copy + Ord,

Source§

fn hull_with(&self, other: &T) -> Self::Output

The hull_with function calculates the hull (minimum and maximum values) between two values.

Arguments:

  • other: The other parameter is a reference to a value of type T, which is the same type as the values stored in the struct implementing the hull_with method. In this method, the other value is used to update the lower bound (lb) and upper bound (`
Source§

type Output = Interval<T>

Source§

impl<T> Intersect<Interval<T>> for Interval<T>
where T: Copy + Ord,

Source§

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: The other parameter is a reference to an Interval<T> object, which is used to intersect with the current Interval<T> object. The intersect_with method calculates the intersection of the two intervals and returns a new Interval<T> object as the output.
Source§

type Output = Interval<T>

Source§

impl<T> Intersect<T> for Interval<T>
where T: Copy + Ord,

Source§

fn intersect_with(&self, other: &T) -> Self::Output

The intersect_with function calculates the intersection of two values.

Arguments:

  • other: The other parameter is a reference to an object of type T, which is the same type as the object on which the intersect_with method is being called. The method calculates the intersection of the object’s lower bound (lb) and upper bound (ub) with the corresponding values
Source§

type Output = Interval<T>

Source§

impl MinDist<Interval<i32>> for Interval<i32>

Source§

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: The min_dist_with function calculates the minimum distance between two intervals. The self interval is represented by the lower bound lb and upper bound ub of the current instance, while the other interval is passed as a reference to an Interval<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

Source§

fn min_dist_with(&self, other: &Interval<i32>) -> u32

This Rust function calculates the minimum distance between two intervals of integers.

Arguments:

  • other: The min_dist_with function calculates the minimum distance between two intervals. The self interval is compared with the other interval 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>

Source§

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: The other parameter in the min_dist_with function is a reference to an i32 value. This parameter is used to calculate the minimum distance between the current instance (self) and the provided i32 value.

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>
where T: Copy + Mul<Output = T>,

Source§

fn mul(self, rhs: T) -> Self::Output

The mul function in Rust defines multiplication for an Interval type.

Arguments:

  • rhs: The rhs parameter in the mul function represents the right-hand side operand that will be multiplied with the Interval instance on which the method is called.
Source§

type Output = Interval<T>

The resulting type after applying the * operator.
Source§

impl<T> MulAssign<T> for Interval<T>
where T: Copy + MulAssign<T>,

Source§

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: The rhs parameter in the mul_assign function represents the value that will be multiplied with the lb and ub fields of the struct or object on which the method is called.
Source§

impl<T> Neg for Interval<T>
where T: Copy + Neg<Output = T>,

Source§

fn neg(self) -> Self::Output

The neg function in Rust returns a new Interval with its lower and upper bounds negated.

Source§

type Output = Interval<T>

The resulting type after applying the - operator.
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.

Source§

fn overlaps(&self, other: &Interval<T>) -> bool

The overlaps function in Rust checks if two intervals overlap with each other.

Arguments:

  • other: The other parameter in the overlaps function 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>

Source§

fn overlaps(&self, other: &T) -> bool

The overlaps function in Rust checks if two values overlap within a range.

Arguments:

  • other: The other parameter is a reference to an object of type T, which is the same type as the object that the method overlaps is 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: PartialEq> PartialEq for Interval<T>

Source§

fn eq(&self, other: &Interval<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialOrd> PartialOrd for Interval<T>

Source§

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: The other parameter is a reference to another object of the same type as self.

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));
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T> Sub<T> for Interval<T>
where T: Copy + Sub<Output = T>,

Source§

fn sub(self, rhs: T) -> Self::Output

The function subtracts a value from both the lower and upper bounds of an interval.

Arguments:

  • rhs: The rhs parameter 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§

type Output = Interval<T>

The resulting type after applying the - operator.
Source§

impl<T: Sub<Output = T>> Sub for Interval<T>

Source§

type Output = Interval<T>

The resulting type after applying the - operator.
Source§

fn sub(self, other: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl<T> SubAssign<T> for Interval<T>
where T: Copy + SubAssign<T>,

Source§

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: rhs is a parameter of type T that is passed by value to the sub_assign function. It is used to subtract its value from both self.lb and self.ub in the function implementation.
Source§

impl<T: Copy> Copy for Interval<T>

Source§

impl<T: Eq> Eq for Interval<T>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Contain<Interval<T>> for T
where T: PartialOrd,

Source§

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 _other parameter is a reference to an Interval object of the same type T as the current object.

Returns:

The contains function is returning a boolean value false.

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Hull<Interval<T>> for T
where T: Copy + Ord,

Source§

fn hull_with(&self, other: &Interval<T>) -> <T as Hull<Interval<T>>>::Output

The hull_with function in Rust calculates the convex hull of two intervals.

Arguments:

  • other: The other parameter in the hull_with function is a reference to an Interval<T> object.
Source§

type Output = Interval<T>

Source§

impl<T> Intersect<Interval<T>> for T
where T: Copy + Ord,

Source§

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: The other parameter in the intersect_with function represents another Interval<T> that you want to intersect with the current interval.
Source§

type Output = Interval<T>

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Overlap<Interval<T>> for T
where T: PartialOrd,

Source§

fn overlaps(&self, other: &Interval<T>) -> bool

The overlaps function in Rust checks if two intervals overlap with each other.

Arguments:

  • other: The other parameter is a reference to an Interval<T> struct, which represents another interval. The Interval<T> struct likely contains two fields, lb and ub, representing the lower and upper bounds of the interval, respectively. The overlaps method 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.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.