From a8ec30565f6406d707483ec8f92f3636696f95f7 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 21 Dec 2023 21:09:01 +0100 Subject: [PATCH] Add info about boundaries to validation error --- crates/fj-core/src/validate/shell.rs | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/crates/fj-core/src/validate/shell.rs b/crates/fj-core/src/validate/shell.rs index 1bdd22be0..55268ced2 100644 --- a/crates/fj-core/src/validate/shell.rs +++ b/crates/fj-core/src/validate/shell.rs @@ -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, + /// The curves of the half-edges curves: Box, @@ -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()), @@ -255,6 +263,7 @@ impl ShellValidationError { errors.push( Self::CoincidentHalfEdgesAreNotSiblings { + boundaries, curves, vertices, half_edge_a: half_edge_a.clone(), @@ -268,6 +277,29 @@ impl ShellValidationError { } } +#[derive(Clone, Debug)] +pub struct CoincidentHalfEdgeBoundaries { + pub boundaries: [CurveBoundary>; 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; 2],