use crate::geometry::{plane::GpuFacetPlane, stone_metrics::measure_solid};
use glam::DVec3;
#[must_use]
pub fn measure_model_width(planes: &[GpuFacetPlane]) -> Option<f64> {
let converted: Vec<(DVec3, f64)> = planes
.iter()
.map(|p| {
(
DVec3::new(
f64::from(p.normal[0]),
f64::from(p.normal[1]),
f64::from(p.normal[2]),
),
-f64::from(p.d),
)
})
.collect();
measure_solid(&converted).map(|m| m.width_axis)
}
#[cfg(test)]
mod tests {
use super::*;
use crate::geometry::cuts::StandardGemCuts;
#[test]
fn measures_the_standard_round_brilliant_girdle_width() {
let planes = StandardGemCuts::standard_round_brilliant();
let width = measure_model_width(&planes).expect("SRB must measure");
assert!(width > 0.0, "width {width}");
}
#[test]
fn differs_between_two_different_designs() {
let srb = StandardGemCuts::standard_round_brilliant();
let emerald = StandardGemCuts::emerald_cut();
assert_ne!(measure_model_width(&srb), measure_model_width(&emerald));
}
#[test]
fn an_empty_plane_set_does_not_measure() {
assert_eq!(measure_model_width(&[]), None);
}
}