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

Fix watertightness check requiring congruent edges #2058

Merged
merged 3 commits into from
Oct 16, 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
10 changes: 10 additions & 0 deletions crates/fj-core/src/geometry/boundary/multiple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ pub struct CurveBoundaries<T: CurveBoundariesPayload = ()> {
}

impl<T: CurveBoundariesPayload> CurveBoundaries<T> {
/// Create an empty instance of `CurveBoundaries`
pub fn empty() -> Self {
Self { inner: Vec::new() }
}

/// Indicate whether this `CurveBoundaries` instance is empty
pub fn is_empty(&self) -> bool {
self.inner.is_empty()
}

/// Transform `self` into the payload of the single boundary requested
///
/// If there are no boundaries or multiple boundaries in `self`, or if the
Expand Down
24 changes: 12 additions & 12 deletions crates/fj-core/src/validate/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::BTreeMap;
use fj_math::{Point, Scalar};

use crate::{
geometry::SurfaceGeometry,
geometry::{CurveBoundaries, SurfaceGeometry},
objects::{Edge, Shell, Surface},
queries::{AllEdgesWithSurface, BoundingVerticesOfEdge},
storage::{Handle, HandleWrapper},
Expand Down Expand Up @@ -294,28 +294,28 @@ impl ShellValidationError {
_: &ValidationConfig,
errors: &mut Vec<ValidationError>,
) {
let mut num_edges = BTreeMap::new();
let mut unmatched_edges_by_curve = BTreeMap::new();

for face in shell.faces() {
for cycle in face.region().all_cycles() {
for edge in cycle.edges() {
let curve = HandleWrapper::from(edge.curve().clone());
let bounding_vertices = cycle
.bounding_vertices_of_edge(edge)
.expect("Cycle should provide bounds of its own edge")
.normalize();

let edge = (curve, bounding_vertices);
let unmatched_edges = unmatched_edges_by_curve
.entry(curve)
.or_insert_with(CurveBoundaries::empty);

*num_edges.entry(edge).or_insert(0) += 1;
*unmatched_edges = unmatched_edges
.clone()
.symmetric_difference((edge.boundary(), ()));
}
}
}

// Every edge should have exactly one matching edge that shares a curve
// and boundary.
if num_edges.into_values().any(|num| num != 2) {
errors.push(Self::NotWatertight.into());
for unmatched_edges in unmatched_edges_by_curve.into_values() {
if !unmatched_edges.is_empty() {
errors.push(Self::NotWatertight.into());
}
}
}

Expand Down