Skip to content

Commit

Permalink
Merge pull request #1540 from hannobraun/validate
Browse files Browse the repository at this point in the history
Improve validation error messages
  • Loading branch information
hannobraun authored Jan 26, 2023
2 parents c850ddd + bdb2a4e commit b217664
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
32 changes: 21 additions & 11 deletions crates/fj-kernel/src/validate/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use fj_math::{Point, Scalar};
use itertools::Itertools;

use crate::{
objects::{Cycle, SurfaceVertex},
objects::{Cycle, HalfEdge, SurfaceVertex},
storage::Handle,
};

Expand Down Expand Up @@ -44,23 +44,31 @@ pub enum CycleValidationError {
/// Mismatch between half-edge boundary and surface vertex position
#[error(
"Half-edge boundary on curve doesn't match surface vertex position\n\
- Position on curve: {position_on_curve:#?}\n\
- Surface vertex: {surface_vertex:#?}\n\
- Position on curve: {position_on_curve:?}\n\
- Curve position converted to surface: {curve_position_on_surface:?}\n\
- Distance between the positions: {distance}"
- Surface position from vertex: {surface_position_from_vertex:?}\n\
- Distance between the positions: {distance}\n\
- Surface vertex: {surface_vertex:#?}\n\
- Half-edge: {half_edge:#?}"
)]
HalfEdgeBoundaryMismatch {
/// The position on the curve
position_on_curve: Point<1>,

/// The surface vertex
surface_vertex: Handle<SurfaceVertex>,

/// The curve position converted into a surface position
curve_position_on_surface: Point<2>,

/// The surface position from the vertex
surface_position_from_vertex: Point<2>,

/// The distance between the positions
distance: Scalar,

/// The surface vertex
surface_vertex: Handle<SurfaceVertex>,

/// The half-edge
half_edge: Handle<HalfEdge>,
},
}

Expand Down Expand Up @@ -101,18 +109,20 @@ impl CycleValidationError {
.curve()
.path()
.point_from_path_coords(position_on_curve);
let surface_position = surface_vertex.position();
let surface_position_from_vertex = surface_vertex.position();

let distance =
curve_position_on_surface.distance_to(&surface_position);
let distance = curve_position_on_surface
.distance_to(&surface_position_from_vertex);

if distance > config.identical_max_distance {
errors.push(
Self::HalfEdgeBoundaryMismatch {
position_on_curve,
surface_vertex: surface_vertex.clone(),
curve_position_on_surface,
surface_position_from_vertex,
distance,
surface_vertex: surface_vertex.clone(),
half_edge: half_edge.clone(),
}
.into(),
);
Expand Down
8 changes: 4 additions & 4 deletions crates/fj-kernel/src/validate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,19 @@ impl Default for ValidationConfig {
#[derive(Clone, Debug, thiserror::Error)]
pub enum ValidationError {
/// `Cycle` validation error
#[error(transparent)]
#[error("`Cycle` validation error:\n{0}")]
Cycle(#[from] CycleValidationError),

/// `Face` validation error
#[error(transparent)]
#[error("`Face` validation error:\n{0}")]
Face(#[from] Box<FaceValidationError>),

/// `HalfEdge` validation error
#[error(transparent)]
#[error("`HalfEdge` validation error:\n{0}")]
HalfEdge(#[from] Box<HalfEdgeValidationError>),

/// `SurfaceVertex` validation error
#[error(transparent)]
#[error("`SurfaceVertex` validation error:\n{0}")]
SurfaceVertex(#[from] Box<SurfaceVertexValidationError>),
}

Expand Down

0 comments on commit b217664

Please sign in to comment.