use crate::types::domain::DomainBound;
#[derive(Debug, Clone, PartialEq)]
pub struct BBox {
pub min: Vec<DomainBound>,
pub max: Vec<DomainBound>,
}
impl BBox {
pub fn from_mbr(mbr: &crate::tile::mbr::TileMBR) -> Self {
Self {
min: mbr.dim_mins.clone(),
max: mbr.dim_maxs.clone(),
}
}
pub fn arity(&self) -> usize {
self.min.len()
}
pub fn extend(&mut self, other: &BBox) {
if self.arity() == 0 {
*self = other.clone();
return;
}
for i in 0..self.arity().min(other.arity()) {
if super::predicate::lt_bound(&other.min[i], &self.min[i]) {
self.min[i] = other.min[i].clone();
}
if super::predicate::lt_bound(&self.max[i], &other.max[i]) {
self.max[i] = other.max[i].clone();
}
}
}
}
#[derive(Debug, Clone)]
pub struct RNode {
pub bbox: BBox,
pub kind: RNodeKind,
}
#[derive(Debug, Clone)]
pub enum RNodeKind {
Leaf {
tiles: Vec<(usize, BBox)>,
},
Internal {
children: Vec<usize>,
},
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn bbox_extend_grows_bounds() {
let mut a = BBox {
min: vec![DomainBound::Int64(0)],
max: vec![DomainBound::Int64(10)],
};
let b = BBox {
min: vec![DomainBound::Int64(-5)],
max: vec![DomainBound::Int64(20)],
};
a.extend(&b);
assert_eq!(a.min[0], DomainBound::Int64(-5));
assert_eq!(a.max[0], DomainBound::Int64(20));
}
#[test]
fn bbox_extend_from_empty_takes_other() {
let mut a = BBox {
min: vec![],
max: vec![],
};
let b = BBox {
min: vec![DomainBound::Int64(0)],
max: vec![DomainBound::Int64(1)],
};
a.extend(&b);
assert_eq!(a, b);
}
}