use std::sync::Arc;
use crate::openscad::{scad, ScadPart};
#[derive(Debug, Clone)]
pub struct ScadFrame {
pub index: usize,
pub t: f64,
pub parts: Arc<Vec<ScadPart>>,
pub viewport: scad::Viewport,
}
impl ScadFrame {
pub fn bounds(&self) -> Option<([f32; 3], [f32; 3])> {
let mut lo = [f32::MAX; 3];
let mut hi = [f32::MIN; 3];
let mut any = false;
for part in self.parts.iter() {
let (min, max) = crate::openscad::geometry_bounds(&part.geometry);
if min[0] > max[0] {
continue;
}
any = true;
for i in 0..3 {
lo[i] = lo[i].min(min[i]);
hi[i] = hi[i].max(max[i]);
}
}
any.then_some((lo, hi))
}
pub fn triangle_count(&self) -> usize {
self.parts
.iter()
.map(|p| match &p.geometry.index {
Some(idx) => idx.len() / 3,
None => p
.geometry
.attributes
.get("position")
.map(|a| a.array.len() / 9)
.unwrap_or(0),
})
.sum()
}
}