Skip to main content

Interval

Struct Interval 

Source
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
  |---------|
  *=========*-----> T

An 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>

Source

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: Copy> Interval<T>

Source

pub const fn lb(&self) -> T

Returns the lower bound.

Source

pub const fn ub(&self) -> T

Returns the upper bound.

Source§

impl<T: PartialOrd> Interval<T>

Source

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

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

Source

pub fn length(&self) -> T

Computes the length of the interval: ub - lb.

$$L = ub - lb$$

§Examples
use physdes::interval::Interval;

let interval = Interval::new(2, 8);
assert_eq!(interval.length(), 6);

let interval = Interval::new(-3, 5);
assert_eq!(interval.length(), 8);

Trait Implementations§

Source§

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

Interval addition (component-wise): $[a,b] + [c,d] = [a+c,; b+d]$

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

Source§

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

Shift the interval by a scalar: $[a,b] + t = [a+t,; b+t]$

Source§

type Output = Interval<T>

The resulting type after applying the + operator.
Source§

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

Source§

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: Clone> Clone for Interval<T>

Source§

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

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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>

Source§

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

Checks if self entirely contains other: $[a,b] \supseteq [c,d] \iff a \le c \land d \le b$

Source§

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

Source§

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

Checks if the interval contains a scalar value: $x \in [a,b] \iff a \le x \le b$

Source§

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

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

Computes the component-wise displacement between two intervals.

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

Formats the interval as [lb, ub].

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

Enlarges the interval by alpha on both sides: $\text{enlarge}([a,b], \alpha) = [a-\alpha,; b+\alpha]$

Source§

type Output = Interval<T>

Source§

impl<T: Eq> Eq for 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

Computes the hull (bounding interval) of two intervals:

$$\text{hull}([a,b],[c,d]) = [\min(a,c),; \max(b,d)]$$

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

Computes the intersection of two intervals:

$$\text{intersect}([a,b],[c,d]) = [\max(a,c),; \min(b,d)]$$

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

Computes the intersection of an interval and a scalar value.

Source§

type Output = Interval<T>

Source§

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

Source§

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

Computes the minimum distance between two intervals:

$$d = \begin{cases} c-b & \text{if } b < c \ a-d & \text{if } d < a \ 0 & \text{otherwise} \end{cases}$$

Source§

impl MinDist<Interval<i32>> for i32

Source§

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

Computes the minimum distance between a scalar and an interval.

Source§

impl MinDist<i32> for Interval<i32>

Source§

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

Computes the minimum distance between an interval and a scalar value.

Source§

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

Source§

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

Scale the interval by a scalar: $[a,b] \cdot t = [a \cdot t,; b \cdot t]$

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)

Scale the interval by a scalar: $[a,b] \mathrel{*}= t \implies [a \cdot t,; b \cdot t]$

Source§

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

Interval negation: $-[a,b] = [-b,; -a]$

Source§

type Output = Interval<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

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

Source§

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

Checks if two intervals overlap: $[a,b] \cap [c,d] \neq \varnothing \iff a \le d \land c \le b$

Source§

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

Source§

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

Checks if the interval contains a scalar value: $x \in [a,b] \iff a \le x \le b$

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 (const: unstable) · 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>

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));
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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: 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]$

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

Source§

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

Shift the interval by a negative scalar: $[a,b] - t = [a-t,; b-t]$

Source§

type Output = Interval<T>

The resulting type after applying the - operator.
Source§

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

Source§

fn sub_assign(&mut self, rhs: T)

Shift the interval by a negative scalar: $[a,b] \mathrel{-}= t \implies [a-t,; b-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> UnsafeUnpin for Interval<T>
where T: UnsafeUnpin,

§

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

Computes the hull of a scalar value with an interval (delegates to Interval::hull_with).

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

Computes the intersection of a scalar value with an 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

Checks if this value falls within the given interval.

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.