Skip to main content

Interval

Struct Interval 

Source
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

Source

pub const REAL: Interval

The whole real line, [−∞, +∞]: the domain of a line or a plane’s parameter.

Source

pub const UNIT: Interval

[0, 1].

Source

pub const TURN: Interval

[0, 2π]: one turn of an angular parameter, both ends included — the closed fundamental interval of every periodic direction.

Source

pub fn new(lo: f64, hi: f64) -> Result<Self, IntervalError>

[lo, hi]; an error when lo > hi or either is NaN.

Source

pub const fn lo(&self) -> f64

The lower end.

Source

pub const fn hi(&self) -> f64

The upper end.

Source

pub fn length(&self) -> f64

hi − lo; infinite for an unbounded interval, zero for a point.

Source

pub fn is_bounded(&self) -> bool

true when both ends are finite.

Source

pub fn midpoint(&self) -> f64

(lo + hi) / 2; NaN for Interval::REAL, where no midpoint exists.

Source

pub fn contains(&self, t: f64) -> bool

lo ≤ t ≤ hi. Both ends are inside; NaN is not.

Source

pub fn clamp(&self, t: f64) -> f64

The nearest parameter inside: t itself when it is contained, the nearer end otherwise. NaN stays NaN.

Source

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.

Source

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

true when the two closed intervals share at least one point: touching at an end counts.

Source

pub fn intersection(&self, other: &Interval) -> Option<Interval>

The common part, or None when they do not overlap.

Source

pub fn hull(&self, other: &Interval) -> Interval

The smallest interval containing both.

Trait Implementations§

Source§

impl Clone for Interval

Source§

fn clone(&self) -> Self

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 Copy for Interval

Source§

impl Debug for Interval

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Interval

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Interval

Auto Trait Implementations§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.