Port part of validation check to new infra

This commit is contained in:
Hanno Braun 2024-05-27 14:29:45 +02:00
parent fa4642ff8a
commit aa9a44c60a
2 changed files with 36 additions and 8 deletions

View File

@ -3,9 +3,12 @@ use fj_math::Winding;
use crate::{ use crate::{
geometry::Geometry, geometry::Geometry,
storage::Handle, storage::Handle,
topology::{Cycle, Sketch}, topology::{Cycle, HalfEdge, Sketch},
validation::{ validation::{
checks::{AdjacentHalfEdgesNotConnected, ReferenceCounter}, checks::{
AdjacentHalfEdgesNotConnected, MultipleReferencesToObject,
ReferenceCounter,
},
ValidationCheck, ValidationCheck,
}, },
}; };
@ -23,6 +26,12 @@ impl Validate for Sketch {
AdjacentHalfEdgesNotConnected::check(self, geometry, config) AdjacentHalfEdgesNotConnected::check(self, geometry, config)
.map(Into::into), .map(Into::into),
); );
errors.extend(
MultipleReferencesToObject::<HalfEdge, Cycle>::check(
self, geometry, config,
)
.map(Into::into),
);
SketchValidationError::check_object_references(self, config, errors); SketchValidationError::check_object_references(self, config, errors);
SketchValidationError::check_exterior_cycles( SketchValidationError::check_exterior_cycles(
self, geometry, config, errors, self, geometry, config, errors,
@ -64,19 +73,14 @@ impl SketchValidationError {
errors: &mut Vec<ValidationError>, errors: &mut Vec<ValidationError>,
) { ) {
let mut cycles = ReferenceCounter::new(); let mut cycles = ReferenceCounter::new();
let mut half_edges = ReferenceCounter::new();
sketch.regions().iter().for_each(|r| { sketch.regions().iter().for_each(|r| {
r.all_cycles().for_each(|c| { r.all_cycles().for_each(|c| {
cycles.count(c.clone(), r.clone()); cycles.count(c.clone(), r.clone());
c.half_edges().into_iter().for_each(|e| {
half_edges.count(e.clone(), c.clone());
})
}) })
}); });
errors.extend(cycles.multiples().map(Into::into)); errors.extend(cycles.multiples().map(Into::into));
errors.extend(half_edges.multiples().map(Into::into));
} }
fn check_exterior_cycles( fn check_exterior_cycles(

View File

@ -1,6 +1,10 @@
use std::{any::type_name_of_val, collections::HashMap, fmt}; use std::{any::type_name_of_val, collections::HashMap, fmt};
use crate::storage::Handle; use crate::{
storage::Handle,
topology::{Cycle, HalfEdge, Sketch},
validation::ValidationCheck,
};
/// Object that should be exclusively owned by another, is not /// Object that should be exclusively owned by another, is not
/// ///
@ -30,6 +34,26 @@ where
} }
} }
impl ValidationCheck<Sketch> for MultipleReferencesToObject<HalfEdge, Cycle> {
fn check<'r>(
object: &'r Sketch,
_: &'r crate::geometry::Geometry,
_: &'r crate::validation::ValidationConfig,
) -> impl Iterator<Item = Self> + 'r {
let mut half_edges = ReferenceCounter::new();
for region in object.regions() {
for cycle in region.all_cycles() {
for half_edge in cycle.half_edges() {
half_edges.count(half_edge.clone(), cycle.clone());
}
}
}
half_edges.multiples()
}
}
// Warnings are temporarily silenced, until this struct can be made private. // Warnings are temporarily silenced, until this struct can be made private.
// This can happen once this validation check has been fully ported from the old // This can happen once this validation check has been fully ported from the old
// infrastructure. // infrastructure.