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
impl Interval
sourcepub fn new(lo: f64, hi: f64) -> Self
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.
sourcepub fn from_point_pair(a: f64, b: f64) -> Self
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 [-π,π].
sourcepub fn is_inverted(&self) -> bool
pub fn is_inverted(&self) -> bool
is_inverted reports whether the interval is inverted; that is, whether Lo > Hi.
sourcepub fn center(&self) -> f64
pub fn center(&self) -> f64
center returns the midpoint of the interval. It is undefined for full and empty intervals.
sourcepub fn len(&self) -> f64
pub fn len(&self) -> f64
len returns the length of the interval. The length of an empty interval is negative.
sourcepub fn fast_contains(&self, p: f64) -> bool
pub fn fast_contains(&self, p: f64) -> bool
fast_contains returns true iff the interval contains p. Assumes p ∈ (-π,π].
sourcepub fn contains(&self, p: f64) -> bool
pub fn contains(&self, p: f64) -> bool
contains returns true iff the interval contains p. Assumes p ∈ [-π,π].
sourcepub fn contains_interval(&self, other: &Self) -> bool
pub fn contains_interval(&self, other: &Self) -> bool
contains_interval returns true iff the interval contains oi.
sourcepub fn interior_contains(&self, p: f64) -> bool
pub fn interior_contains(&self, p: f64) -> bool
interior_contains returns true iff the interior of the interval contains p. Assumes p ∈ [-π,π].
sourcepub fn interior_contains_interval(&self, other: &Self) -> bool
pub fn interior_contains_interval(&self, other: &Self) -> bool
interior_contains_interval returns true iff the interior of the interval contains oi.
sourcepub fn intersects(&self, other: &Self) -> bool
pub fn intersects(&self, other: &Self) -> bool
intersects returns true iff the interval contains any points in common with oi.
sourcepub fn interior_intersects(&self, other: &Self) -> bool
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.
sourcepub fn union(&self, other: &Self) -> Self
pub fn union(&self, other: &Self) -> Self
union returns the smallest interval that contains both the interval and oi.
sourcepub fn intersection(&self, other: &Self) -> Self
pub fn intersection(&self, other: &Self) -> Self
intersection returns the smallest interval that contains the intersection of the interval and oi.
sourcepub fn expanded(&self, margin: f64) -> Self
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.