Skip to content

Commit

Permalink
Add info about boundaries to validation error
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Dec 21, 2023
1 parent f3a77af commit a8ec305
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions crates/fj-core/src/validate/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,16 @@ pub enum ShellValidationError {
#[error(
"`Shell` contains `HalfEdge`s that are coincident but are not \
siblings\n\
{boundaries}\
{curves}\
{vertices}\
Half-edge 1: {half_edge_a:#?}\n\
Half-edge 2: {half_edge_b:#?}"
)]
CoincidentHalfEdgesAreNotSiblings {
/// The boundaries of the half-edges
boundaries: Box<CoincidentHalfEdgeBoundaries>,

/// The curves of the half-edges
curves: Box<CoincidentHalfEdgeCurves>,

Expand Down Expand Up @@ -239,6 +243,10 @@ impl ShellValidationError {
)
.all(|d| d < config.distinct_min_distance)
{
let boundaries = Box::new(CoincidentHalfEdgeBoundaries {
boundaries: [half_edge_a, half_edge_b]
.map(|half_edge| half_edge.boundary()),
});
let curves = Box::new(CoincidentHalfEdgeCurves {
curves: [half_edge_a, half_edge_b]
.map(|half_edge| half_edge.curve().clone()),
Expand All @@ -255,6 +263,7 @@ impl ShellValidationError {

errors.push(
Self::CoincidentHalfEdgesAreNotSiblings {
boundaries,
curves,
vertices,
half_edge_a: half_edge_a.clone(),
Expand All @@ -268,6 +277,29 @@ impl ShellValidationError {
}
}

#[derive(Clone, Debug)]
pub struct CoincidentHalfEdgeBoundaries {
pub boundaries: [CurveBoundary<Point<1>>; 2],
}

impl fmt::Display for CoincidentHalfEdgeBoundaries {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let [a, b] = &self.boundaries;

if a != &b.reverse() {
writeln!(
f,
"Boundaries don't match.\n\
\tHalf-edge 1 has boundary `{a:?}`\n\
\tHalf-edge 2 has boundary `{b:?}`\n\
\t(expecting same boundary, but reversed)"
)?;
}

Ok(())
}
}

#[derive(Clone, Debug)]
pub struct CoincidentHalfEdgeCurves {
pub curves: [Handle<Curve>; 2],
Expand Down

0 comments on commit a8ec305

Please sign in to comment.