Consolidate error variants in ValidationError

This commit is contained in:
Hanno Braun 2024-05-24 22:05:43 +02:00
parent d612c0dba3
commit e92123b0a8
4 changed files with 21 additions and 36 deletions

View File

@ -36,7 +36,7 @@ macro_rules! validate_references {
$( $(
$counter.find_multiples().iter().for_each(|multiple| { $counter.find_multiples().iter().for_each(|multiple| {
let reference_error = ObjectNotExclusivelyOwned::$err { references: multiple.clone() }; let reference_error = ObjectNotExclusivelyOwned::$err { references: multiple.clone() };
$errors.push(Into::<$error_ty>::into(reference_error).into()); $errors.push(reference_error.into());
}); });
)* )*
}; };

View File

@ -37,10 +37,6 @@ impl Validate for Sketch {
/// [`Sketch`] validation failed /// [`Sketch`] validation failed
#[derive(Clone, Debug, thiserror::Error)] #[derive(Clone, Debug, thiserror::Error)]
pub enum SketchValidationError { pub enum SketchValidationError {
/// An object that should be exclusively owned by another, is not
#[error(transparent)]
ObjectNotExclusivelyOwned(#[from] ObjectNotExclusivelyOwned),
/// Region within sketch has exterior cycle with clockwise winding /// Region within sketch has exterior cycle with clockwise winding
#[error( #[error(
"Exterior cycle within sketch region has clockwise winding\n "Exterior cycle within sketch region has clockwise winding\n
@ -170,10 +166,8 @@ mod tests {
assert_contains_err!( assert_contains_err!(
core, core,
invalid_sketch, invalid_sketch,
ValidationError::Sketch( ValidationError::ObjectNotExclusivelyOwned(
SketchValidationError::ObjectNotExclusivelyOwned( ObjectNotExclusivelyOwned::Cycle { references: _ }
ObjectNotExclusivelyOwned::Cycle { references: _ }
)
) )
); );
@ -210,10 +204,8 @@ mod tests {
assert_contains_err!( assert_contains_err!(
core, core,
invalid_sketch, invalid_sketch,
ValidationError::Sketch( ValidationError::ObjectNotExclusivelyOwned(
SketchValidationError::ObjectNotExclusivelyOwned( ObjectNotExclusivelyOwned::HalfEdge { references: _ }
ObjectNotExclusivelyOwned::HalfEdge { references: _ }
)
) )
); );

View File

@ -67,10 +67,6 @@ pub enum SolidValidationError {
/// Position of second vertex /// Position of second vertex
position_b: Point<3>, position_b: Point<3>,
}, },
/// Object within solid referenced by more than one other object
#[error(transparent)]
ObjectNotExclusivelyOwned(#[from] ObjectNotExclusivelyOwned),
} }
impl SolidValidationError { impl SolidValidationError {
@ -188,8 +184,7 @@ mod tests {
}, },
topology::{Cycle, Face, HalfEdge, Region, Shell, Solid, Surface}, topology::{Cycle, Face, HalfEdge, Region, Shell, Solid, Surface},
validate::{ validate::{
references::ObjectNotExclusivelyOwned, SolidValidationError, references::ObjectNotExclusivelyOwned, Validate, ValidationError,
Validate, ValidationError,
}, },
Core, Core,
}; };
@ -238,10 +233,8 @@ mod tests {
assert_contains_err!( assert_contains_err!(
core, core,
invalid_solid, invalid_solid,
ValidationError::Solid( ValidationError::ObjectNotExclusivelyOwned(
SolidValidationError::ObjectNotExclusivelyOwned( ObjectNotExclusivelyOwned::Face { references: _ }
ObjectNotExclusivelyOwned::Face { references: _ }
)
) )
); );
@ -286,10 +279,8 @@ mod tests {
assert_contains_err!( assert_contains_err!(
core, core,
invalid_solid, invalid_solid,
ValidationError::Solid( ValidationError::ObjectNotExclusivelyOwned(
SolidValidationError::ObjectNotExclusivelyOwned( ObjectNotExclusivelyOwned::Region { references: _ }
ObjectNotExclusivelyOwned::Region { references: _ }
)
) )
); );
@ -338,10 +329,8 @@ mod tests {
assert_contains_err!( assert_contains_err!(
core, core,
invalid_solid, invalid_solid,
ValidationError::Solid( ValidationError::ObjectNotExclusivelyOwned(
SolidValidationError::ObjectNotExclusivelyOwned( ObjectNotExclusivelyOwned::Cycle { references: _ }
ObjectNotExclusivelyOwned::Cycle { references: _ }
)
) )
); );
@ -382,10 +371,8 @@ mod tests {
assert_contains_err!( assert_contains_err!(
core, core,
invalid_solid, invalid_solid,
ValidationError::Solid( ValidationError::ObjectNotExclusivelyOwned(
SolidValidationError::ObjectNotExclusivelyOwned( ObjectNotExclusivelyOwned::HalfEdge { references: _ }
ObjectNotExclusivelyOwned::HalfEdge { references: _ }
)
) )
); );

View File

@ -1,6 +1,8 @@
use std::{convert::Infallible, fmt}; use std::{convert::Infallible, fmt};
use crate::validate::{SketchValidationError, SolidValidationError}; use crate::validate::{
ObjectNotExclusivelyOwned, SketchValidationError, SolidValidationError,
};
use super::checks::{ use super::checks::{
AdjacentHalfEdgesNotConnected, CoincidentHalfEdgesAreNotSiblings, AdjacentHalfEdgesNotConnected, CoincidentHalfEdgesAreNotSiblings,
@ -37,6 +39,10 @@ pub enum ValidationError {
#[error(transparent)] #[error(transparent)]
InteriorCycleHasInvalidWinding(#[from] InteriorCycleHasInvalidWinding), InteriorCycleHasInvalidWinding(#[from] InteriorCycleHasInvalidWinding),
/// An object that should be exclusively owned by another, is not
#[error(transparent)]
ObjectNotExclusivelyOwned(#[from] ObjectNotExclusivelyOwned),
/// `Solid` validation error /// `Solid` validation error
#[error("`Solid` validation error")] #[error("`Solid` validation error")]
Solid(#[from] SolidValidationError), Solid(#[from] SolidValidationError),