pub struct Interval<BOUND: PartialOrd> {
pub lo: BOUND,
pub hi: BOUND,
}Expand description
Interval struct.
Represents a set where each element x satisfies lo <= x && x <= hi.
Fields§
§lo: BOUNDInclusive lower bound.
hi: BOUNDInclusive upper bound.
Implementations§
Source§impl<BOUND: Float> Interval<BOUND>
impl<BOUND: Float> Interval<BOUND>
Sourcepub fn new(lo: BOUND, hi: BOUND) -> Self
pub fn new(lo: BOUND, hi: BOUND) -> Self
Constructs a new interval from given bounds.
Lower bound must be less than or equal to upper bound. Only exception is when they are both NaNs, in which case a NaN (empty) interval is created.
Cases where both bounds are negative infinity or positive infinity are not allowed as these
are empty sets. If you want to represent an empty set, use Interval::nan().
Sourcepub fn minimal_cover(intervals: Vec<Self>, precision: usize) -> Self
pub fn minimal_cover(intervals: Vec<Self>, precision: usize) -> Self
Constructs the minimal interval that covers all of the given intervals.
Sourcepub fn singleton(val: BOUND) -> Self
pub fn singleton(val: BOUND) -> Self
Constructs a singleton interval (an interval with only one element).
Sourcepub fn from_with_prec(val: f64, precision: usize) -> Self
pub fn from_with_prec(val: f64, precision: usize) -> Self
Constructs an interval from a float with given precision.
Sourcepub fn from_str_with_prec(
s: &str,
precision: usize,
) -> Result<Self, ParseIntervalError>
pub fn from_str_with_prec( s: &str, precision: usize, ) -> Result<Self, ParseIntervalError>
Constructs an interval by parsing a string.
Accepts INTERVAL according to the rule below.
INTERVAL = FLOAT | ‘<’ FLOAT ‘,’ FLOAT ‘>’
Sourcepub fn sign_class(&self) -> SignClass
pub fn sign_class(&self) -> SignClass
Returns the sign class of self.
Sourcepub fn size(&self) -> Self
pub fn size(&self) -> Self
Returns the difference between the upper bound and the lower bound of self.
As the result is not always exactly representable as BOUND, an interval is returned
instead.
Sourcepub fn is_singleton(&self) -> bool
pub fn is_singleton(&self) -> bool
Whether self is a singleton interval (an interval containing only one element).