Skip to content

Commit

Permalink
Merge pull request #1974 from hannobraun/query
Browse files Browse the repository at this point in the history
Add "all edges with surface" query, use it to clean up validation check
  • Loading branch information
hannobraun authored Aug 1, 2023
2 parents 7b4a38a + 6175fe6 commit b8f0da8
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 26 deletions.
40 changes: 40 additions & 0 deletions crates/fj-core/src/queries/all_edges_with_surface.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use crate::{
objects::{Face, HalfEdge, Shell, Surface},
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(
&self,
result: &mut Vec<(Handle<HalfEdge>, Handle<Surface>)>,
);
}

impl AllEdgesWithSurface for Face {
fn all_edges_with_surface(
&self,
result: &mut Vec<(Handle<HalfEdge>, Handle<Surface>)>,
) {
for cycle in self.region().all_cycles() {
result.extend(
cycle
.half_edges()
.cloned()
.map(|half_edge| (half_edge, self.surface().clone())),
);
}
}
}

impl AllEdgesWithSurface for Shell {
fn all_edges_with_surface(
&self,
result: &mut Vec<(Handle<HalfEdge>, Handle<Surface>)>,
) {
for face in self.faces() {
face.all_edges_with_surface(result);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
//! Queries about objects
//!
//! Objects have methods that provide access to anything that the object itself
//! has direct access to. However, not all potentially interesting information
//! can be accessed that way. An example are the bounding vertices of an edge:
//! `HalfEdge` only stores its starting vertex, so you need a `Cycle` to get
//! both vertices.
//!
//! This module provides traits express such non-trivial queries, and implements
//! them for various objects that have the information to answer the query.

use crate::{
geometry::CurveBoundary,
objects::{Cycle, Face, HalfEdge, Region, Shell, Vertex},
Expand Down
18 changes: 18 additions & 0 deletions crates/fj-core/src/queries/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//! Queries about objects
//!
//! Objects have methods that provide access to anything that the object itself
//! has direct access to. However, not all potentially interesting information
//! can be accessed that way. An example are the bounding vertices of an edge:
//! `HalfEdge` only stores its starting vertex, so you need a `Cycle` to get
//! both vertices.
//!
//! 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;

pub use self::{
all_edges_with_surface::AllEdgesWithSurface,
bounding_vertices_of_edge::BoundingVerticesOfEdge,
};
19 changes: 4 additions & 15 deletions crates/fj-core/src/validate/shell.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
use std::{
collections::{BTreeMap, HashMap},
iter::repeat,
};
use std::collections::{BTreeMap, HashMap};

use fj_math::{Point, Scalar};

use crate::{
geometry::SurfaceGeometry,
objects::{HalfEdge, Shell, Surface},
queries::BoundingVerticesOfEdge,
queries::{AllEdgesWithSurface, BoundingVerticesOfEdge},
storage::{Handle, HandleWrapper, ObjectId},
};

Expand Down Expand Up @@ -115,16 +112,8 @@ impl ShellValidationError {
config: &ValidationConfig,
errors: &mut Vec<ValidationError>,
) {
let edges_and_surfaces: Vec<_> = shell
.faces()
.into_iter()
.flat_map(|face| {
face.region()
.all_cycles()
.flat_map(|cycle| cycle.half_edges().cloned())
.zip(repeat(face.surface().clone()))
})
.collect();
let mut edges_and_surfaces = Vec::new();
shell.all_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 Down

0 comments on commit b8f0da8

Please sign in to comment.