Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update names in queries module that refer to half-edges #2063

Merged
merged 10 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<HalfEdge>, Handle<Surface>)>,
);
}

impl AllEdgesWithSurface for Face {
fn all_edges_with_surface(
impl AllHalfEdgesWithSurface for Face {
fn all_half_edges_with_surface(
&self,
result: &mut Vec<(Handle<HalfEdge>, Handle<Surface>)>,
) {
Expand All @@ -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<HalfEdge>, Handle<Surface>)>,
) {
for face in self.faces() {
face.all_edges_with_surface(result);
face.all_half_edges_with_surface(result);
}
}
}
68 changes: 0 additions & 68 deletions crates/fj-core/src/queries/bounding_vertices_of_edge.rs

This file was deleted.

72 changes: 72 additions & 0 deletions crates/fj-core/src/queries/bounding_vertices_of_half_edge.rs
Original file line number Diff line number Diff line change
@@ -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<HalfEdge>,
) -> Option<CurveBoundary<Vertex>>;
}

impl BoundingVerticesOfHalfEdge for Cycle {
fn bounding_vertices_of_half_edge(
&self,
half_edge: &Handle<HalfEdge>,
) -> Option<CurveBoundary<Vertex>> {
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<HalfEdge>,
) -> Option<CurveBoundary<Vertex>> {
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<HalfEdge>,
) -> Option<CurveBoundary<Vertex>> {
self.region().bounding_vertices_of_half_edge(half_edge)
}
}

impl BoundingVerticesOfHalfEdge for Shell {
fn bounding_vertices_of_half_edge(
&self,
half_edge: &Handle<HalfEdge>,
) -> Option<CurveBoundary<Vertex>> {
for face in self.faces() {
if let Some(vertices) =
face.bounding_vertices_of_half_edge(half_edge)
{
return Some(vertices);
}
}

None
}
}
8 changes: 4 additions & 4 deletions crates/fj-core/src/queries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
10 changes: 5 additions & 5 deletions crates/fj-core/src/validate/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};

Expand Down Expand Up @@ -118,7 +118,7 @@ impl ShellValidationError {
errors: &mut Vec<ValidationError>,
) {
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 {
Expand Down Expand Up @@ -211,7 +211,7 @@ impl ShellValidationError {
errors: &mut Vec<ValidationError>,
) {
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
Expand All @@ -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()
};
Expand Down Expand Up @@ -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",
)
Expand Down