mirror of
https://github.com/hannobraun/Fornjot
synced 2025-05-12 05:48:27 +00:00
Merge pull request #2358 from hannobraun/query
Refactor `AllHalfEdgesWithSurface` query to not require allocations
This commit is contained in:
commit
1f4569d1b4
@ -8,34 +8,29 @@ pub trait AllHalfEdgesWithSurface {
|
|||||||
/// Access all half-edges of the object, and the surface they're on
|
/// Access all half-edges of the object, and the surface they're on
|
||||||
fn all_half_edges_with_surface(
|
fn all_half_edges_with_surface(
|
||||||
&self,
|
&self,
|
||||||
result: &mut Vec<(Handle<HalfEdge>, Handle<Surface>)>,
|
) -> impl Iterator<Item = (Handle<HalfEdge>, Handle<Surface>)>;
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AllHalfEdgesWithSurface for Face {
|
impl AllHalfEdgesWithSurface for Face {
|
||||||
fn all_half_edges_with_surface(
|
fn all_half_edges_with_surface(
|
||||||
&self,
|
&self,
|
||||||
result: &mut Vec<(Handle<HalfEdge>, Handle<Surface>)>,
|
) -> impl Iterator<Item = (Handle<HalfEdge>, Handle<Surface>)> {
|
||||||
) {
|
self.region().all_cycles().flat_map(|cycle| {
|
||||||
for cycle in self.region().all_cycles() {
|
|
||||||
result.extend(
|
|
||||||
cycle
|
cycle
|
||||||
.half_edges()
|
.half_edges()
|
||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
.map(|half_edge| (half_edge, self.surface().clone())),
|
.map(|half_edge| (half_edge, self.surface().clone()))
|
||||||
);
|
})
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AllHalfEdgesWithSurface for Shell {
|
impl AllHalfEdgesWithSurface for Shell {
|
||||||
fn all_half_edges_with_surface(
|
fn all_half_edges_with_surface(
|
||||||
&self,
|
&self,
|
||||||
result: &mut Vec<(Handle<HalfEdge>, Handle<Surface>)>,
|
) -> impl Iterator<Item = (Handle<HalfEdge>, Handle<Surface>)> {
|
||||||
) {
|
self.faces()
|
||||||
for face in self.faces() {
|
.into_iter()
|
||||||
face.all_half_edges_with_surface(result);
|
.flat_map(|face| face.all_half_edges_with_surface())
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,8 +84,8 @@ impl ShellValidationError {
|
|||||||
config: &ValidationConfig,
|
config: &ValidationConfig,
|
||||||
errors: &mut Vec<ValidationError>,
|
errors: &mut Vec<ValidationError>,
|
||||||
) {
|
) {
|
||||||
let mut edges_and_surfaces = Vec::new();
|
let edges_and_surfaces =
|
||||||
shell.all_half_edges_with_surface(&mut edges_and_surfaces);
|
shell.all_half_edges_with_surface().collect::<Vec<_>>();
|
||||||
|
|
||||||
for (edge_a, surface_a) in &edges_and_surfaces {
|
for (edge_a, surface_a) in &edges_and_surfaces {
|
||||||
for (edge_b, surface_b) in &edges_and_surfaces {
|
for (edge_b, surface_b) in &edges_and_surfaces {
|
||||||
@ -230,8 +230,8 @@ impl ShellValidationError {
|
|||||||
config: &ValidationConfig,
|
config: &ValidationConfig,
|
||||||
errors: &mut Vec<ValidationError>,
|
errors: &mut Vec<ValidationError>,
|
||||||
) {
|
) {
|
||||||
let mut edges_and_surfaces = Vec::new();
|
let edges_and_surfaces =
|
||||||
shell.all_half_edges_with_surface(&mut 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
|
// 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
|
// need to deal with float inaccuracies. Maybe we could use some smarter
|
||||||
|
Loading…
Reference in New Issue
Block a user