pub struct Interval { /* private fields */ }Expand description
A closed interval [lo, hi] with lo ≤ hi, neither end NaN. Either end
may be infinite: a line’s domain is Interval::REAL. An interval may
be longer than a curve’s period — an edge range on a periodic curve may
cross the period (docs/DATA-MODEL.md §Topology).
use arris_math::Interval;
let i = Interval::new(1.0, 3.0).unwrap();
assert!(i.contains(3.0));
assert_eq!(i.clamp(5.0), 3.0);
assert_eq!(i.lerp(0.5), 2.0);
assert!(i.overlaps(&Interval::new(3.0, 4.0).unwrap()));
assert!(Interval::new(3.0, 1.0).is_err());Implementations§
Source§impl Interval
impl Interval
Sourcepub const REAL: Interval
pub const REAL: Interval
The whole real line, [−∞, +∞]: the domain of a line or a plane’s
parameter.
Sourcepub const TURN: Interval
pub const TURN: Interval
[0, 2π]: one turn of an angular parameter, both ends included —
the closed fundamental interval of every periodic direction.
Sourcepub fn new(lo: f64, hi: f64) -> Result<Self, IntervalError>
pub fn new(lo: f64, hi: f64) -> Result<Self, IntervalError>
[lo, hi]; an error when lo > hi or either is NaN.
Sourcepub fn is_bounded(&self) -> bool
pub fn is_bounded(&self) -> bool
true when both ends are finite.
Sourcepub fn midpoint(&self) -> f64
pub fn midpoint(&self) -> f64
(lo + hi) / 2; NaN for Interval::REAL, where no midpoint
exists.
Sourcepub fn clamp(&self, t: f64) -> f64
pub fn clamp(&self, t: f64) -> f64
The nearest parameter inside: t itself when it is contained, the
nearer end otherwise. NaN stays NaN.
Sourcepub fn lerp(&self, s: f64) -> f64
pub fn lerp(&self, s: f64) -> f64
lo at s = 0, hi at s = 1, both exactly, linear between and
beyond. Bounded intervals only; an infinite end yields an infinite
or NaN result.
Sourcepub fn overlaps(&self, other: &Interval) -> bool
pub fn overlaps(&self, other: &Interval) -> bool
true when the two closed intervals share at least one point:
touching at an end counts.
Trait Implementations§
impl Copy for Interval
impl StructuralPartialEq for Interval
Auto Trait Implementations§
impl Freeze for Interval
impl RefUnwindSafe for Interval
impl Send for Interval
impl Sync for Interval
impl Unpin for Interval
impl UnsafeUnpin for Interval
impl UnwindSafe for Interval
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> Scalar for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.