mirror of
https://github.com/hannobraun/Fornjot
synced 2025-05-04 18:08:26 +00:00
Move error variants to ValidationError
This makes it possible to further simplify `ObjectNotExclusivelyOwned` in a next step.
This commit is contained in:
parent
11857d16d8
commit
4ea6aec162
@ -1,9 +1,6 @@
|
||||
use std::{any::type_name_of_val, collections::HashMap, fmt};
|
||||
|
||||
use crate::{
|
||||
storage::Handle,
|
||||
topology::{Cycle, Face, HalfEdge, Region, Shell},
|
||||
};
|
||||
use crate::storage::Handle;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct ReferenceCounter<T, U>(HashMap<Handle<T>, Vec<Handle<U>>>);
|
||||
@ -35,7 +32,7 @@ macro_rules! validate_references {
|
||||
($errors:ident, $error_ty:ty;$($counter:ident, $err:ident;)*) => {
|
||||
$(
|
||||
$counter.find_multiples().iter().for_each(|multiple| {
|
||||
let reference_error = ObjectNotExclusivelyOwned::$err { references: multiple.clone() };
|
||||
let reference_error = ValidationError::$err(ObjectNotExclusivelyOwned{ references: multiple.clone() });
|
||||
$errors.push(reference_error.into());
|
||||
});
|
||||
)*
|
||||
@ -48,34 +45,10 @@ macro_rules! validate_references {
|
||||
/// that only one reference to these objects must exist within the topological
|
||||
/// object graph.
|
||||
#[derive(Clone, Debug, thiserror::Error)]
|
||||
pub enum ObjectNotExclusivelyOwned {
|
||||
/// Multiple references to [`Region`]
|
||||
#[error(transparent)]
|
||||
MultipleReferencesToRegion {
|
||||
/// The invalid references
|
||||
references: MultipleReferences<Region, Face>,
|
||||
},
|
||||
|
||||
/// Multiple references to [`Face`]
|
||||
#[error(transparent)]
|
||||
MultipleReferencesToFace {
|
||||
/// The invalid references
|
||||
references: MultipleReferences<Face, Shell>,
|
||||
},
|
||||
|
||||
/// Multiple references to [`HalfEdge`]
|
||||
#[error(transparent)]
|
||||
MultipleReferencesToHalfEdge {
|
||||
/// The invalid references
|
||||
references: MultipleReferences<HalfEdge, Cycle>,
|
||||
},
|
||||
|
||||
/// Multiple references to [`Cycle`]
|
||||
#[error(transparent)]
|
||||
MultipleReferencesToCycle {
|
||||
/// The invalid references
|
||||
references: MultipleReferences<Cycle, Region>,
|
||||
},
|
||||
#[error(transparent)]
|
||||
pub struct ObjectNotExclusivelyOwned<T, U> {
|
||||
/// The invalid references
|
||||
pub references: MultipleReferences<T, U>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, thiserror::Error)]
|
||||
|
@ -131,10 +131,7 @@ mod tests {
|
||||
build::BuildHalfEdge, build::BuildRegion, insert::Insert,
|
||||
},
|
||||
topology::{Cycle, HalfEdge, Region, Sketch, Vertex},
|
||||
validate::{
|
||||
references::ObjectNotExclusivelyOwned, SketchValidationError,
|
||||
Validate, ValidationError,
|
||||
},
|
||||
validate::{SketchValidationError, Validate, ValidationError},
|
||||
Core,
|
||||
};
|
||||
|
||||
@ -166,11 +163,7 @@ mod tests {
|
||||
assert_contains_err!(
|
||||
core,
|
||||
invalid_sketch,
|
||||
ValidationError::ObjectNotExclusivelyOwned(
|
||||
ObjectNotExclusivelyOwned::MultipleReferencesToCycle {
|
||||
references: _
|
||||
}
|
||||
)
|
||||
ValidationError::MultipleReferencesToCycle(_)
|
||||
);
|
||||
|
||||
Ok(())
|
||||
@ -206,11 +199,7 @@ mod tests {
|
||||
assert_contains_err!(
|
||||
core,
|
||||
invalid_sketch,
|
||||
ValidationError::ObjectNotExclusivelyOwned(
|
||||
ObjectNotExclusivelyOwned::MultipleReferencesToHalfEdge {
|
||||
references: _
|
||||
}
|
||||
)
|
||||
ValidationError::MultipleReferencesToHalfEdge(_)
|
||||
);
|
||||
|
||||
Ok(())
|
||||
|
@ -183,9 +183,7 @@ mod tests {
|
||||
insert::Insert,
|
||||
},
|
||||
topology::{Cycle, Face, HalfEdge, Region, Shell, Solid, Surface},
|
||||
validate::{
|
||||
references::ObjectNotExclusivelyOwned, Validate, ValidationError,
|
||||
},
|
||||
validate::{Validate, ValidationError},
|
||||
Core,
|
||||
};
|
||||
|
||||
@ -233,11 +231,7 @@ mod tests {
|
||||
assert_contains_err!(
|
||||
core,
|
||||
invalid_solid,
|
||||
ValidationError::ObjectNotExclusivelyOwned(
|
||||
ObjectNotExclusivelyOwned::MultipleReferencesToFace {
|
||||
references: _
|
||||
}
|
||||
)
|
||||
ValidationError::MultipleReferencesToFace(_)
|
||||
);
|
||||
|
||||
let valid_solid = Solid::new(vec![]).insert(&mut core);
|
||||
@ -281,11 +275,7 @@ mod tests {
|
||||
assert_contains_err!(
|
||||
core,
|
||||
invalid_solid,
|
||||
ValidationError::ObjectNotExclusivelyOwned(
|
||||
ObjectNotExclusivelyOwned::MultipleReferencesToRegion {
|
||||
references: _
|
||||
}
|
||||
)
|
||||
ValidationError::MultipleReferencesToRegion(_)
|
||||
);
|
||||
|
||||
let valid_solid = Solid::new(vec![]).insert(&mut core);
|
||||
@ -333,11 +323,7 @@ mod tests {
|
||||
assert_contains_err!(
|
||||
core,
|
||||
invalid_solid,
|
||||
ValidationError::ObjectNotExclusivelyOwned(
|
||||
ObjectNotExclusivelyOwned::MultipleReferencesToCycle {
|
||||
references: _
|
||||
}
|
||||
)
|
||||
ValidationError::MultipleReferencesToCycle(_)
|
||||
);
|
||||
|
||||
let valid_solid = Solid::new(vec![]).insert(&mut core);
|
||||
@ -377,11 +363,7 @@ mod tests {
|
||||
assert_contains_err!(
|
||||
core,
|
||||
invalid_solid,
|
||||
ValidationError::ObjectNotExclusivelyOwned(
|
||||
ObjectNotExclusivelyOwned::MultipleReferencesToHalfEdge {
|
||||
references: _
|
||||
}
|
||||
)
|
||||
ValidationError::MultipleReferencesToHalfEdge(_)
|
||||
);
|
||||
|
||||
let valid_solid = Solid::new(vec![]).insert(&mut core);
|
||||
|
@ -1,7 +1,10 @@
|
||||
use std::{convert::Infallible, fmt};
|
||||
|
||||
use crate::validate::{
|
||||
ObjectNotExclusivelyOwned, SketchValidationError, SolidValidationError,
|
||||
use crate::{
|
||||
topology::{Cycle, Face, HalfEdge, Region, Shell},
|
||||
validate::{
|
||||
ObjectNotExclusivelyOwned, SketchValidationError, SolidValidationError,
|
||||
},
|
||||
};
|
||||
|
||||
use super::checks::{
|
||||
@ -39,9 +42,21 @@ pub enum ValidationError {
|
||||
#[error(transparent)]
|
||||
InteriorCycleHasInvalidWinding(#[from] InteriorCycleHasInvalidWinding),
|
||||
|
||||
/// An object that should be exclusively owned by another, is not
|
||||
/// Multiple references to [`Cycle`]
|
||||
#[error(transparent)]
|
||||
ObjectNotExclusivelyOwned(#[from] ObjectNotExclusivelyOwned),
|
||||
MultipleReferencesToCycle(ObjectNotExclusivelyOwned<Cycle, Region>),
|
||||
|
||||
/// Multiple references to [`Face`]
|
||||
#[error(transparent)]
|
||||
MultipleReferencesToFace(ObjectNotExclusivelyOwned<Face, Shell>),
|
||||
|
||||
/// Multiple references to [`HalfEdge`]
|
||||
#[error(transparent)]
|
||||
MultipleReferencesToHalfEdge(ObjectNotExclusivelyOwned<HalfEdge, Cycle>),
|
||||
|
||||
/// Multiple references to [`Region`]
|
||||
#[error(transparent)]
|
||||
MultipleReferencesToRegion(ObjectNotExclusivelyOwned<Region, Face>),
|
||||
|
||||
/// `Solid` validation error
|
||||
#[error("`Solid` validation error")]
|
||||
|
Loading…
Reference in New Issue
Block a user