From f3a77af94ba13590524055f11bef4a75a3a7a159 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 21 Dec 2023 20:56:49 +0100 Subject: [PATCH] Add information about curves to validation error --- crates/fj-core/src/validate/shell.rs | 34 +++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/crates/fj-core/src/validate/shell.rs b/crates/fj-core/src/validate/shell.rs index e39f14105..1bdd22be0 100644 --- a/crates/fj-core/src/validate/shell.rs +++ b/crates/fj-core/src/validate/shell.rs @@ -4,7 +4,7 @@ use fj_math::{Point, Scalar}; use crate::{ geometry::{CurveBoundary, SurfaceGeometry}, - objects::{HalfEdge, Shell, Surface, Vertex}, + objects::{Curve, HalfEdge, Shell, Surface, Vertex}, queries::{ AllHalfEdgesWithSurface, BoundingVerticesOfHalfEdge, SiblingOfHalfEdge, }, @@ -47,11 +47,15 @@ pub enum ShellValidationError { #[error( "`Shell` contains `HalfEdge`s that are coincident but are not \ siblings\n\ + {curves}\ {vertices}\ Half-edge 1: {half_edge_a:#?}\n\ Half-edge 2: {half_edge_b:#?}" )] CoincidentHalfEdgesAreNotSiblings { + /// The curves of the half-edges + curves: Box, + /// The vertices of the half-edges vertices: Box, @@ -235,6 +239,10 @@ impl ShellValidationError { ) .all(|d| d < config.distinct_min_distance) { + let curves = Box::new(CoincidentHalfEdgeCurves { + curves: [half_edge_a, half_edge_b] + .map(|half_edge| half_edge.curve().clone()), + }); let vertices = Box::new(CoincidentHalfEdgeVertices { vertices: [half_edge_a, half_edge_b].map(|half_edge| { shell @@ -247,6 +255,7 @@ impl ShellValidationError { errors.push( Self::CoincidentHalfEdgesAreNotSiblings { + curves, vertices, half_edge_a: half_edge_a.clone(), half_edge_b: half_edge_b.clone(), @@ -259,6 +268,29 @@ impl ShellValidationError { } } +#[derive(Clone, Debug)] +pub struct CoincidentHalfEdgeCurves { + pub curves: [Handle; 2], +} + +impl fmt::Display for CoincidentHalfEdgeCurves { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let [a, b] = &self.curves; + + if a.id() != b.id() { + writeln!( + f, + "Curves don't match.\n\ + \tHalf-edge 1 lies on {a:?}\n\ + \tHalf-edge 2 lies on {b:?}\n\ + \t(must be the same)" + )?; + } + + Ok(()) + } +} + #[derive(Clone, Debug)] pub struct CurveCoordinateSystemMismatch { pub half_edge_a: Handle,