pub struct Interval<T> {
pub lower: Bound<T>,
pub upper: Bound<T>,
}Expand description
A mathematical interval described by a lower and upper bound.
Intervals may be open, closed, half-open, or unbounded on either side.
§Examples
use use_interval::{Bound, Interval};
let closed = Interval::closed(1.0, 3.0);
let half_open = Interval::new(Bound::Closed(0.0), Bound::Open(1.0));
assert!(closed.contains(2.0));
assert!(half_open.contains(0.5));Fields§
§lower: Bound<T>The lower endpoint rule.
upper: Bound<T>The upper endpoint rule.
Implementations§
Source§impl<T> Interval<T>
impl<T> Interval<T>
Sourcepub const fn new(lower: Bound<T>, upper: Bound<T>) -> Self
pub const fn new(lower: Bound<T>, upper: Bound<T>) -> Self
Creates an interval from explicit lower and upper bounds.
Sourcepub const fn open_closed(lower: T, upper: T) -> Self
pub const fn open_closed(lower: T, upper: T) -> Self
Creates a half-open interval (lower, upper].
Sourcepub const fn closed_open(lower: T, upper: T) -> Self
pub const fn closed_open(lower: T, upper: T) -> Self
Creates a half-open interval [lower, upper).
Sourcepub const fn greater_than(lower: T) -> Self
pub const fn greater_than(lower: T) -> Self
Creates the interval (lower, +inf).
Sourcepub const fn greater_than_or_equal(lower: T) -> Self
pub const fn greater_than_or_equal(lower: T) -> Self
Creates the interval [lower, +inf).
Sourcepub const fn less_than_or_equal(upper: T) -> Self
pub const fn less_than_or_equal(upper: T) -> Self
Creates the interval (-inf, upper].
Source§impl<T: PartialOrd + Copy> Interval<T>
impl<T: PartialOrd + Copy> Interval<T>
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true when the interval contains no values.
(a, a), (a, a], and [a, a) are empty. [a, a] is not empty.
Sourcepub fn is_bounded(&self) -> bool
pub fn is_bounded(&self) -> bool
Returns true when the interval has both lower and upper bounds.
Sourcepub fn has_lower_bound(&self) -> bool
pub fn has_lower_bound(&self) -> bool
Returns true when the interval has a lower bound.
Sourcepub fn has_upper_bound(&self) -> bool
pub fn has_upper_bound(&self) -> bool
Returns true when the interval has an upper bound.
Sourcepub fn overlaps(&self, other: &Self) -> bool
pub fn overlaps(&self, other: &Self) -> bool
Returns true when the interval and other share at least one value.
Sourcepub fn intersection(&self, other: &Self) -> Option<Self>
pub fn intersection(&self, other: &Self) -> Option<Self>
Returns the intersection with other, or None when it is empty.