Interval

Struct Interval 

Source
pub struct Interval {
    pub lo: f64,
    pub hi: f64,
}
Expand description

Interval represents a closed interval on a unit circle. Zero-length intervals (where Lo == Hi) represent single points. If Lo > Hi then the interval is “inverted”. The point at (-1, 0) on the unit circle has two valid representations, [π,π] and [-π,-π]. We normalize the latter to the former in Interval::new. There are two special intervals that take advantage of that:

  • the full interval, [-π,π], and
  • the empty interval, [π,-π]. Treat the exported fields as read-only.

Fields§

§lo: f64§hi: f64

Implementations§

Source§

impl Interval

Source

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

from_endpoint constructs a new interval from endpoints. Both arguments must be in the range [-π,π]. This function allows inverted intervals to be created.

Source

pub fn from_point_pair(a: f64, b: f64) -> Self

from_point_pair returns the minimal interval containing the two given points. Both arguments must be in [-π,π].

Source

pub fn is_valid(&self) -> bool

is_valid reports whether the interval is valid.

Source

pub fn is_full(&self) -> bool

is_full reports whether the interval is full.

Source

pub fn is_empty(&self) -> bool

is_empty reports whether the interval is empty.

Source

pub fn is_inverted(&self) -> bool

is_inverted reports whether the interval is inverted; that is, whether Lo > Hi.

Source

pub fn invert(&self) -> Interval

invert returns the interval with endpoints swapped.

Source

pub fn center(&self) -> f64

center returns the midpoint of the interval. It is undefined for full and empty intervals.

Source

pub fn len(&self) -> f64

len returns the length of the interval. The length of an empty interval is negative.

Source

pub fn fast_contains(&self, p: f64) -> bool

fast_contains returns true iff the interval contains p. Assumes p ∈ (-π,π].

Source

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

contains returns true iff the interval contains p. Assumes p ∈ [-π,π].

Source

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

contains_interval returns true iff the interval contains oi.

Source

pub fn interior_contains(&self, p: f64) -> bool

interior_contains returns true iff the interior of the interval contains p. Assumes p ∈ [-π,π].

Source

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

interior_contains_interval returns true iff the interior of the interval contains oi.

Source

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

intersects returns true iff the interval contains any points in common with oi.

Source

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

interior_intersects returns true iff the interior of the interval contains any points in common with other, including the latter’s boundary.

Source

pub fn union(&self, other: &Self) -> Self

union returns the smallest interval that contains both the interval and oi.

Source

pub fn intersection(&self, other: &Self) -> Self

intersection returns the smallest interval that contains the intersection of the interval and oi.

Source

pub fn expanded(&self, margin: f64) -> Self

Expanded returns an interval that has been expanded on each side by margin. If margin is negative, then the function shrinks the interval on each side by margin instead. The resulting interval may be empty or full. Any expansion (positive or negative) of a full interval remains full, and any expansion of an empty interval remains empty.

Source

pub fn complement(&self) -> Interval

Source

pub fn complement_center(&self) -> f64

Source

pub fn directed_hausdorff_distance(&self, y: &Self) -> Angle

Source

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

Source

pub fn approx_eq_by(&self, other: &Self, max_error: f64) -> bool

Trait Implementations§

Source§

impl<'a> Add<f64> for &'a Interval

Source§

fn add(self, p: f64) -> Self::Output

add returns the interval expanded by the minimum amount necessary such that it contains the given point “p” (an angle in the range [-Pi, Pi]).

Source§

type Output = Interval

The resulting type after applying the + operator.
Source§

impl Add<f64> for Interval

Source§

type Output = Interval

The resulting type after applying the + operator.
Source§

fn add(self, p: f64) -> Self::Output

Performs the + operation. Read more
Source§

impl Clone for Interval

Source§

fn clone(&self) -> Interval

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Interval

Source§

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

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

impl Default for Interval

Source§

fn default() -> Interval

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Interval

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<Interval> for Interval

Source§

fn from(i: Interval) -> Self

Converts to this type from the input type.
Source§

impl From<Interval> for Interval

Source§

fn from(i: Interval) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Interval

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Interval

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for Interval

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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,