pub struct Interval<T> {
pub min: T,
pub max: T,
}
Expand description
An interval on the real number line.
Fields§
§min: T
The smallest value in the interval.
max: T
The largest value in the interval.
Implementations§
Source§impl<T: PartialOrd> Interval<T>
impl<T: PartialOrd> Interval<T>
Source§impl<T: Float> Interval<T>
impl<T: Float> Interval<T>
Sourcepub fn disc(centre: T, radius: T) -> Self
pub fn disc(centre: T, radius: T) -> Self
Creates an interval with the given centre and radius.
Sourcepub fn clearance_with(&self, other: &Self) -> T
pub fn clearance_with(&self, other: &Self) -> T
Computes the gap between two intervals. Will be negative if the intervals overlap.
Sourcepub fn distance(&self, other: T) -> T
pub fn distance(&self, other: T) -> T
Computes the distance between a point and the interval. Will be negative if the point is within the interval.
Sourcepub fn lerp(&self, t: T) -> T
pub fn lerp(&self, t: T) -> T
Interpolates between the two endpoints of the interval,
where t=0
will yield self.min
and t=1
will yield self.max
.
Sourcepub fn inv_lerp(&self, value: T) -> T
pub fn inv_lerp(&self, value: T) -> T
Performs the inverse operation of Self::lerp
, such that providing
an input of self.min
will yield 0
and an input of self.max
will yield 1
.
Trait Implementations§
Source§impl<'de, T> Deserialize<'de> for Interval<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Interval<T>where
T: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more