interval.rs (918B)
1 pub struct Interval { 2 min: f64, 3 max: f64, 4 } 5 6 impl Default for Interval { 7 fn default() -> Self { 8 Interval::empty() 9 } 10 } 11 12 impl Interval { 13 pub const fn new(min: f64, max: f64) -> Self { 14 Interval { min, max } 15 } 16 17 pub const fn min(&self) -> f64 { 18 self.min 19 } 20 21 pub const fn max(&self) -> f64 { 22 self.max 23 } 24 25 pub const fn empty() -> Self { 26 Self { 27 min: f64::INFINITY, 28 max: f64::NEG_INFINITY, 29 } 30 } 31 32 pub const fn _full() -> Self { 33 Self { 34 min: f64::NEG_INFINITY, 35 max: f64::INFINITY, 36 } 37 } 38 39 pub const fn _size(&self) -> f64 { 40 (self.max - self.min).max(0.) 41 } 42 43 pub const fn _contains(&self, x: f64) -> bool { 44 self.min <= x && x <= self.max 45 } 46 47 pub const fn surrounds(&self, x: f64) -> bool { 48 self.min < x && x < self.max 49 } 50 }