diff --git a/crates/fj-core/src/queries/all_half_edges_with_surface.rs b/crates/fj-core/src/queries/all_half_edges_with_surface.rs index 55fa85d9f..d368bf230 100644 --- a/crates/fj-core/src/queries/all_half_edges_with_surface.rs +++ b/crates/fj-core/src/queries/all_half_edges_with_surface.rs @@ -8,34 +8,29 @@ pub trait AllHalfEdgesWithSurface { /// Access all half-edges of the object, and the surface they're on fn all_half_edges_with_surface( &self, - result: &mut Vec<(Handle, Handle)>, - ); + ) -> impl Iterator, Handle)>; } impl AllHalfEdgesWithSurface for Face { fn all_half_edges_with_surface( &self, - result: &mut Vec<(Handle, Handle)>, - ) { - for cycle in self.region().all_cycles() { - result.extend( - cycle - .half_edges() - .iter() - .cloned() - .map(|half_edge| (half_edge, self.surface().clone())), - ); - } + ) -> impl Iterator, Handle)> { + self.region().all_cycles().flat_map(|cycle| { + cycle + .half_edges() + .iter() + .cloned() + .map(|half_edge| (half_edge, self.surface().clone())) + }) } } impl AllHalfEdgesWithSurface for Shell { fn all_half_edges_with_surface( &self, - result: &mut Vec<(Handle, Handle)>, - ) { - for face in self.faces() { - face.all_half_edges_with_surface(result); - } + ) -> impl Iterator, Handle)> { + self.faces() + .into_iter() + .flat_map(|face| face.all_half_edges_with_surface()) } } diff --git a/crates/fj-core/src/validate/shell.rs b/crates/fj-core/src/validate/shell.rs index f06fb6054..7c7f73654 100644 --- a/crates/fj-core/src/validate/shell.rs +++ b/crates/fj-core/src/validate/shell.rs @@ -84,8 +84,8 @@ impl ShellValidationError { config: &ValidationConfig, errors: &mut Vec, ) { - let mut edges_and_surfaces = Vec::new(); - shell.all_half_edges_with_surface(&mut edges_and_surfaces); + let edges_and_surfaces = + shell.all_half_edges_with_surface().collect::>(); for (edge_a, surface_a) in &edges_and_surfaces { for (edge_b, surface_b) in &edges_and_surfaces { @@ -230,8 +230,8 @@ impl ShellValidationError { config: &ValidationConfig, errors: &mut Vec, ) { - let mut edges_and_surfaces = Vec::new(); - shell.all_half_edges_with_surface(&mut edges_and_surfaces); + let edges_and_surfaces = + shell.all_half_edges_with_surface().collect::>(); // This is O(N^2) which isn't great, but we can't use a HashMap since we // need to deal with float inaccuracies. Maybe we could use some smarter