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: f64The low bound of the interval.
hi: f64The high bound of the interval.
Implementations§
Source§impl Interval
impl Interval
Sourcepub fn new(lo: f64, hi: f64) -> Self
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).
Sourcepub fn from_point(p: f64) -> Self
pub fn from_point(p: f64) -> Self
Returns an interval containing a single point.
Sourcepub fn from_point_pair(p1: f64, p2: f64) -> Self
pub fn from_point_pair(p1: f64, p2: f64) -> Self
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
Reports whether the interval is inverted (lo > hi). This is true for empty intervals.
Sourcepub fn center(self) -> f64
pub fn center(self) -> f64
Returns the midpoint of the interval. Undefined for full and empty intervals.
Sourcepub fn length(self) -> f64
pub fn length(self) -> f64
Returns the length of the interval. The length of an empty interval is negative.
Sourcepub fn complement(self) -> Interval
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.
Sourcepub fn complement_center(self) -> f64
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.
Sourcepub fn contains(self, p: f64) -> bool
pub fn contains(self, p: f64) -> bool
Reports whether the interval contains the point p.
Assumes p is in [-π, π].
Sourcepub fn interior_contains(self, p: f64) -> bool
pub fn interior_contains(self, p: f64) -> bool
Reports whether the interior of the interval contains the point p.
Sourcepub fn contains_interval(self, y: Interval) -> bool
pub fn contains_interval(self, y: Interval) -> bool
Reports whether this interval contains the interval y.
Sourcepub fn interior_contains_interval(self, y: Interval) -> bool
pub fn interior_contains_interval(self, y: Interval) -> bool
Reports whether the interior of this interval contains the entire
interval y.
Sourcepub fn intersects(self, y: Interval) -> bool
pub fn intersects(self, y: Interval) -> bool
Reports whether this interval intersects the given interval.
Sourcepub fn interior_intersects(self, y: Interval) -> bool
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).
Sourcepub fn directed_hausdorff_distance(self, y: Interval) -> f64
pub fn directed_hausdorff_distance(self, y: Interval) -> f64
Returns the Hausdorff distance to the given interval y, measured
along S1.
Sourcepub fn add_point(self, p: f64) -> Interval
pub fn add_point(self, p: f64) -> Interval
Returns the interval expanded to contain the given point p.
Sourcepub fn project(self, p: f64) -> f64
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.
Sourcepub fn expanded(self, margin: f64) -> Interval
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.
Sourcepub fn union(self, y: Interval) -> Interval
pub fn union(self, y: Interval) -> Interval
Returns the smallest interval that contains both this interval and y.
Sourcepub fn intersection(self, y: Interval) -> Interval
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.
Sourcepub fn approx_eq_with(self, y: Interval, max_error: f64) -> bool
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.
Sourcepub fn approx_eq(self, y: Interval) -> bool
pub fn approx_eq(self, y: Interval) -> bool
Like approx_eq_with with a default
max_error of 1e-15.