runmat_geometry_ops/
bounds.rs1use runmat_geometry_core::GeometryAsset;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5pub struct AxisAlignedBounds {
6 pub min: [f64; 3],
7 pub max: [f64; 3],
8}
9
10pub fn compute_axis_aligned_bounds(asset: &GeometryAsset) -> AxisAlignedBounds {
11 let mut min = [f64::INFINITY; 3];
12 let mut max = [f64::NEG_INFINITY; 3];
13 let mut found = false;
14 for vertex in asset
15 .surface_meshes
16 .iter()
17 .flat_map(|surface_mesh| surface_mesh.vertices.iter())
18 {
19 for axis in 0..3 {
20 min[axis] = min[axis].min(vertex[axis]);
21 max[axis] = max[axis].max(vertex[axis]);
22 }
23 found = true;
24 }
25 if found {
26 return AxisAlignedBounds { min, max };
27 }
28 AxisAlignedBounds {
29 min: [0.0, 0.0, 0.0],
30 max: [0.0, 0.0, 0.0],
31 }
32}