constructive/
span.rs

1#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
2pub struct Span {
3    pub min: f32,
4    pub max: f32,
5}
6
7impl Span {
8    pub fn new(min: f32, max: f32) -> Self {
9        Self { min, max }
10    }
11
12    pub fn empty() -> Self {
13        Self::new(0.0, 0.0)
14    }
15
16    pub fn is_empty(&self) -> bool {
17        self.min >= self.max
18    }
19
20    pub fn intersect(&self, other: Self) -> Self {
21        if self.is_empty() || other.is_empty() {
22            Self::empty()
23        } else {
24            Self::new(self.min.max(other.min), self.max.min(other.max))
25        }
26    }
27}