use super::{mesh_to_tris, orient_outward, tris_to_mesh};
use crate::kernel::{
arrangement::{union_all, Tri},
budget,
plane_weld::promote_operands_mutually,
};
use crate::Mesh;
pub fn union_many(meshes: &[&Mesh]) -> Mesh {
arrange(meshes, true)
}
pub(crate) fn union_many_preserving_coordinates(meshes: &[&Mesh]) -> Mesh {
arrange(meshes, false)
}
fn arrange(meshes: &[&Mesh], reconcile: bool) -> Mesh {
budget::begin();
if budget::tripped() {
return Mesh::new();
}
let mut operands: Vec<Vec<Tri>> = meshes.iter().map(|m| mesh_to_tris(m)).collect();
if reconcile {
promote_operands_mutually(&mut operands);
}
let operands: Vec<Vec<Tri>> = operands.into_iter().map(orient_outward).collect();
let refs: Vec<&[Tri]> = operands.iter().map(Vec::as_slice).collect();
let (out, _) = union_all(&refs);
if budget::tripped() {
Mesh::new()
} else {
tris_to_mesh(&out)
}
}
#[cfg(test)]
#[path = "nary_union_tests.rs"]
mod tests;