Intervals on ℝⁿ
Mathematical intervals, i.g., [a, b], (a, b), [a, b), and (a, b] on ℝ (real number line). Also supports multi-dimensional axis-aligned boxes.
NOTE: Not yet stable.
Intervals on ℝ
Intervals like [a, b], (a, b), [a, b), and (a, b] for any PartialOrd type.
Properties
lower_bound left . center right upper_bound
...------------>|<------- self -------------------->|<------------ ...
inf sup
[<------------ closure ------------>]
(<----------- interior ---------->)
Set operations
|<------------- a ----------------->| . p |<-------- c -------->|
|<--------------- b ------------------->|
|<--- a.intersection(&b) --->|
|<-- a.gap(&c) -->|
|<------------- a.hull(p) ------------->|
|<---------------------------------- a.span(&c) --------------------------->|
|<--------------------------------->| + |<------------------->| a.union(&c)
|<---->| a.difference(&b)
|<- δ -+---- c.dilate(δ) ----+- δ ->|
Examples
use ;
// Closed interval of i32
let a = Inclusive.at.to; // [0, 10]
assert!;
// Half-open interval of f64
let b = Inclusive.at.to; // [1.23, 4.56)
assert!;
assert!;
// Intersection
let c = Inclusive.between; // [5, 15]
let isect = a.intersection.unwrap; // [0, 10] ∩ [5, 15] = [5, 10]
assert_eq!;
assert_eq!;
// Span & Gap
let d = Inclusive.between; // [12, 15]
let span = a.span; // [0, 15]
let gap = a.gap; // (10, 12)
assert_eq!;
assert_eq!;
// Union
let union = a.union;
assert_eq!;
assert_eq!;
assert_eq!;
// Hull
let hull = hull_many.unwrap; // [2, 9]
assert_eq!;
// Linear interpolation
assert_eq!;
assert_eq!;
assert_eq!;
// Split
let = b.split_at; // Split [1.23, 4.56) at 3.45
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Axis-aligned box on ℝⁿ
Boxes represented by Cartesian product of intervals.
use ;
// [0.0, 10.0] × [5.0, 20.0]
let a: = new;
// Another way to construct [0.0, 10.0] × [5.0, 20.0]
let b: = between;
assert_eq!;
// Hull
let b = a.hull;
assert_eq!;
Future work
- Enhance
BoxN. - Interval set.
- Sufficient tests.
Not promised :-)