Skip to main content

Interval

Struct Interval 

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

A closed interval on the unit circle.

This type is Copy and intended to be passed by value.

§Examples

use std::f64::consts::PI;
use s2rst::s1::Interval;

// A simple interval from 0 to π/2 (first quadrant).
let i = Interval::new(0.0, PI / 2.0);
assert!(!i.is_empty());
assert!(i.contains(PI / 4.0));
assert!(!i.contains(PI));

// An inverted interval that wraps through -π/π.
let wrap = Interval::new(3.0, -3.0);
assert!(wrap.is_inverted());
assert!(wrap.contains(PI));  // π is between 3.0 and -3.0 the "long way"

// The full circle.
let full = Interval::full();
assert!(full.is_full());
assert_eq!(full.length(), 2.0 * PI);

Fields§

§lo: f64

The low bound of the interval.

§hi: f64

The high bound of the interval.

Implementations§

Source§

impl Interval

Source

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

Creates a new interval from endpoints. Both endpoints must be in [-π, π]. The value -π is normalized to π (except for full/empty).

Source

pub fn empty() -> Self

Returns the empty interval [π, -π].

Source

pub fn full() -> Self

Returns the full interval [-π, π].

Source

pub fn from_point(p: f64) -> Self

Returns an interval containing a single point.

Source

pub fn from_point_pair(p1: f64, p2: f64) -> Self

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

Source

pub fn is_valid(self) -> bool

Reports whether the interval is valid.

Source

pub fn is_full(self) -> bool

Reports whether the interval is full (contains all points).

Source

pub fn is_empty(self) -> bool

Reports whether the interval is empty (contains no points).

Source

pub fn is_inverted(self) -> bool

Reports whether the interval is inverted (lo > hi). This is true for empty intervals.

Source

pub fn center(self) -> f64

Returns the midpoint of the interval. Undefined for full and empty intervals.

Source

pub fn length(self) -> f64

Returns the length of the interval. The length of an empty interval is negative.

Source

pub fn complement(self) -> Interval

Returns the complement of the interior of the interval.

An interval and its complement have the same boundary but do not share any interior values. The complement of a singleton interval is full.

Source

pub fn complement_center(self) -> f64

Returns the midpoint of the complement of the interval.

For full and empty intervals, the result is arbitrary. For a singleton interval, the result is its antipodal point on S1.

Source

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

Reports whether the interval contains the point p. Assumes p is in [-π, π].

Source

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

Reports whether the interior of the interval contains the point p.

Source

pub fn contains_interval(self, y: Interval) -> bool

Reports whether this interval contains the interval y.

Source

pub fn interior_contains_interval(self, y: Interval) -> bool

Reports whether the interior of this interval contains the entire interval y.

Source

pub fn intersects(self, y: Interval) -> bool

Reports whether this interval intersects the given interval.

Source

pub fn interior_intersects(self, y: Interval) -> bool

Reports whether the interior of this interval intersects any point of the interval y (including its boundary).

Source

pub fn directed_hausdorff_distance(self, y: Interval) -> f64

Returns the Hausdorff distance to the given interval y, measured along S1.

Source

pub fn add_point(self, p: f64) -> Interval

Returns the interval expanded to contain the given point p.

Source

pub fn project(self, p: f64) -> f64

Returns the closest point in the interval to the given point p. The interval must be non-empty.

Source

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

Returns an interval expanded on each side by margin.

If margin is negative, the interval is shrunk 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 union(self, y: Interval) -> Interval

Returns the smallest interval that contains both this interval and y.

Source

pub fn intersection(self, y: Interval) -> Interval

Returns the smallest interval that contains the intersection of this interval with y. The region of intersection may consist of two disjoint subintervals.

Source

pub fn approx_eq_with(self, y: Interval, max_error: f64) -> bool

Reports whether this interval can be transformed into y by moving each endpoint by at most max_error (without crossing).

Empty and full intervals are considered to start at an arbitrary point, so any interval with length <= 2*max_error matches empty, and any interval with length >= 2π - 2*max_error matches full.

Source

pub fn approx_eq(self, y: Interval) -> bool

Like approx_eq_with with a default max_error of 1e-15.

Source

pub fn bound(self, i: usize) -> f64

Provides indexed access: 0 → lo, 1 → hi.

§Panics

Panics if i is not 0 or 1.

Trait Implementations§

Source§

impl Clone for Interval

Source§

fn clone(&self) -> Interval

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

Source§

fn default() -> Self

The default interval is empty.

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 Display 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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.