mirror of
https://github.com/hannobraun/Fornjot
synced 2025-05-04 18:08:26 +00:00
Refactor query to not require allocations
This commit is contained in:
parent
eb32d919b1
commit
61011b28d2
@ -8,35 +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<HalfEdge>, Handle<Surface>)>,
|
||||
);
|
||||
) -> impl Iterator<Item = (Handle<HalfEdge>, Handle<Surface>)>;
|
||||
}
|
||||
|
||||
impl AllHalfEdgesWithSurface for Face {
|
||||
fn all_half_edges_with_surface(
|
||||
&self,
|
||||
result: &mut Vec<(Handle<HalfEdge>, Handle<Surface>)>,
|
||||
) {
|
||||
self.region()
|
||||
.all_cycles()
|
||||
.flat_map(|cycle| {
|
||||
) -> impl Iterator<Item = (Handle<HalfEdge>, Handle<Surface>)> {
|
||||
self.region().all_cycles().flat_map(|cycle| {
|
||||
cycle
|
||||
.half_edges()
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(|half_edge| (half_edge, self.surface().clone()))
|
||||
})
|
||||
.for_each(|r| result.push(r))
|
||||
}
|
||||
}
|
||||
|
||||
impl AllHalfEdgesWithSurface for Shell {
|
||||
fn all_half_edges_with_surface(
|
||||
&self,
|
||||
result: &mut Vec<(Handle<HalfEdge>, Handle<Surface>)>,
|
||||
) {
|
||||
for face in self.faces() {
|
||||
face.all_half_edges_with_surface(result);
|
||||
}
|
||||
) -> impl Iterator<Item = (Handle<HalfEdge>, Handle<Surface>)> {
|
||||
self.faces()
|
||||
.into_iter()
|
||||
.flat_map(|face| face.all_half_edges_with_surface())
|
||||
}
|
||||
}
|
||||
|
@ -84,8 +84,8 @@ impl ShellValidationError {
|
||||
config: &ValidationConfig,
|
||||
errors: &mut Vec<ValidationError>,
|
||||
) {
|
||||
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::<Vec<_>>();
|
||||
|
||||
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<ValidationError>,
|
||||
) {
|
||||
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::<Vec<_>>();
|
||||
|
||||
// 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
|
||||
|
Loading…
Reference in New Issue
Block a user