diff --git a/crates/fj-core/src/queries/all_edges_with_surface.rs b/crates/fj-core/src/queries/all_half_edges_with_surface.rs similarity index 55% rename from crates/fj-core/src/queries/all_edges_with_surface.rs rename to crates/fj-core/src/queries/all_half_edges_with_surface.rs index e2901009a..300e1b830 100644 --- a/crates/fj-core/src/queries/all_edges_with_surface.rs +++ b/crates/fj-core/src/queries/all_half_edges_with_surface.rs @@ -3,17 +3,17 @@ use crate::{ storage::Handle, }; -/// Access all edges referenced by the object and the surface they're on -pub trait AllEdgesWithSurface { - /// Access all edges referenced by the object and the surface they're on - fn all_edges_with_surface( +/// Access all half-edges referenced by an object, and the surface they're on +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 AllEdgesWithSurface for Face { - fn all_edges_with_surface( +impl AllHalfEdgesWithSurface for Face { + fn all_half_edges_with_surface( &self, result: &mut Vec<(Handle, Handle)>, ) { @@ -23,19 +23,19 @@ impl AllEdgesWithSurface for Face { .half_edges() .iter() .cloned() - .map(|edge| (edge, self.surface().clone())), + .map(|half_edge| (half_edge, self.surface().clone())), ); } } } -impl AllEdgesWithSurface for Shell { - fn all_edges_with_surface( +impl AllHalfEdgesWithSurface for Shell { + fn all_half_edges_with_surface( &self, result: &mut Vec<(Handle, Handle)>, ) { for face in self.faces() { - face.all_edges_with_surface(result); + face.all_half_edges_with_surface(result); } } } diff --git a/crates/fj-core/src/queries/bounding_vertices_of_edge.rs b/crates/fj-core/src/queries/bounding_vertices_of_edge.rs deleted file mode 100644 index 7c86118d9..000000000 --- a/crates/fj-core/src/queries/bounding_vertices_of_edge.rs +++ /dev/null @@ -1,68 +0,0 @@ -use crate::{ - geometry::CurveBoundary, - objects::{Cycle, Face, HalfEdge, Region, Shell, Vertex}, - storage::Handle, -}; - -/// Determine the bounding vertices of an edge -pub trait BoundingVerticesOfEdge { - /// Determine the bounding vertices of an edge - /// - /// Returns `None`, if the provided edge is not part of the object this - /// method is called on. - fn bounding_vertices_of_edge( - &self, - edge: &Handle, - ) -> Option>; -} - -impl BoundingVerticesOfEdge for Cycle { - fn bounding_vertices_of_edge( - &self, - edge: &Handle, - ) -> Option> { - let start = edge.start_vertex().clone(); - let end = self.half_edges().after(edge)?.start_vertex().clone(); - - Some(CurveBoundary::from([start, end])) - } -} - -impl BoundingVerticesOfEdge for Region { - fn bounding_vertices_of_edge( - &self, - edge: &Handle, - ) -> Option> { - for cycle in self.all_cycles() { - if let Some(vertices) = cycle.bounding_vertices_of_edge(edge) { - return Some(vertices); - } - } - - None - } -} - -impl BoundingVerticesOfEdge for Face { - fn bounding_vertices_of_edge( - &self, - edge: &Handle, - ) -> Option> { - self.region().bounding_vertices_of_edge(edge) - } -} - -impl BoundingVerticesOfEdge for Shell { - fn bounding_vertices_of_edge( - &self, - edge: &Handle, - ) -> Option> { - for face in self.faces() { - if let Some(vertices) = face.bounding_vertices_of_edge(edge) { - return Some(vertices); - } - } - - None - } -} diff --git a/crates/fj-core/src/queries/bounding_vertices_of_half_edge.rs b/crates/fj-core/src/queries/bounding_vertices_of_half_edge.rs new file mode 100644 index 000000000..92f1d243b --- /dev/null +++ b/crates/fj-core/src/queries/bounding_vertices_of_half_edge.rs @@ -0,0 +1,72 @@ +use crate::{ + geometry::CurveBoundary, + objects::{Cycle, Face, HalfEdge, Region, Shell, Vertex}, + storage::Handle, +}; + +/// Determine the bounding vertices of a half-edge +pub trait BoundingVerticesOfHalfEdge { + /// Determine the bounding vertices of a half-edge + /// + /// Returns `None`, if the provided half-edge is not part of the object this + /// method is called on. + fn bounding_vertices_of_half_edge( + &self, + half_edge: &Handle, + ) -> Option>; +} + +impl BoundingVerticesOfHalfEdge for Cycle { + fn bounding_vertices_of_half_edge( + &self, + half_edge: &Handle, + ) -> Option> { + let start = half_edge.start_vertex().clone(); + let end = self.half_edges().after(half_edge)?.start_vertex().clone(); + + Some(CurveBoundary::from([start, end])) + } +} + +impl BoundingVerticesOfHalfEdge for Region { + fn bounding_vertices_of_half_edge( + &self, + half_edge: &Handle, + ) -> Option> { + for cycle in self.all_cycles() { + if let Some(vertices) = + cycle.bounding_vertices_of_half_edge(half_edge) + { + return Some(vertices); + } + } + + None + } +} + +impl BoundingVerticesOfHalfEdge for Face { + fn bounding_vertices_of_half_edge( + &self, + half_edge: &Handle, + ) -> Option> { + self.region().bounding_vertices_of_half_edge(half_edge) + } +} + +impl BoundingVerticesOfHalfEdge for Shell { + fn bounding_vertices_of_half_edge( + &self, + half_edge: &Handle, + ) -> Option> { + for face in self.faces() { + if let Some(vertices) = + face.bounding_vertices_of_half_edge(half_edge) + { + return Some(vertices); + } + } + + None + } +} diff --git a/crates/fj-core/src/queries/mod.rs b/crates/fj-core/src/queries/mod.rs index 06f064a3f..03ac82d26 100644 --- a/crates/fj-core/src/queries/mod.rs +++ b/crates/fj-core/src/queries/mod.rs @@ -9,10 +9,10 @@ //! This module provides traits express such non-trivial queries, and implements //! them for various objects that have the information to answer the query. -mod all_edges_with_surface; -mod bounding_vertices_of_edge; +mod all_half_edges_with_surface; +mod bounding_vertices_of_half_edge; pub use self::{ - all_edges_with_surface::AllEdgesWithSurface, - bounding_vertices_of_edge::BoundingVerticesOfEdge, + all_half_edges_with_surface::AllHalfEdgesWithSurface, + bounding_vertices_of_half_edge::BoundingVerticesOfHalfEdge, }; diff --git a/crates/fj-core/src/validate/shell.rs b/crates/fj-core/src/validate/shell.rs index 550552743..a14a0d878 100644 --- a/crates/fj-core/src/validate/shell.rs +++ b/crates/fj-core/src/validate/shell.rs @@ -5,7 +5,7 @@ use fj_math::{Point, Scalar}; use crate::{ geometry::{CurveBoundaries, SurfaceGeometry}, objects::{HalfEdge, Shell, Surface}, - queries::{AllEdgesWithSurface, BoundingVerticesOfEdge}, + queries::{AllHalfEdgesWithSurface, BoundingVerticesOfHalfEdge}, storage::{Handle, HandleWrapper}, }; @@ -118,7 +118,7 @@ impl ShellValidationError { errors: &mut Vec, ) { let mut edges_and_surfaces = Vec::new(); - shell.all_edges_with_surface(&mut edges_and_surfaces); + shell.all_half_edges_with_surface(&mut edges_and_surfaces); for (edge_a, surface_a) in &edges_and_surfaces { for (edge_b, surface_b) in &edges_and_surfaces { @@ -211,7 +211,7 @@ impl ShellValidationError { errors: &mut Vec, ) { let mut edges_and_surfaces = Vec::new(); - shell.all_edges_with_surface(&mut edges_and_surfaces); + shell.all_half_edges_with_surface(&mut edges_and_surfaces); // 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 @@ -230,7 +230,7 @@ impl ShellValidationError { let have_same_boundary = { let bounding_vertices_of = |edge| { shell - .bounding_vertices_of_edge(edge) + .bounding_vertices_of_half_edge(edge) .expect("Expected edge to be part of shell") .normalize() }; @@ -332,7 +332,7 @@ impl ShellValidationError { for edge in cycle.half_edges() { let curve = HandleWrapper::from(edge.curve().clone()); let boundary = cycle - .bounding_vertices_of_edge(edge) + .bounding_vertices_of_half_edge(edge) .expect( "Just got edge from this cycle; must be part of it", )