From 15f47a2415b681e948d390f656ff36a020f9b8b1 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 29 May 2024 13:48:27 +0200 Subject: [PATCH 01/18] Clean up imports --- .../src/validation/checks/multiple_references.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/crates/fj-core/src/validation/checks/multiple_references.rs b/crates/fj-core/src/validation/checks/multiple_references.rs index a44f51c98..3eabab854 100644 --- a/crates/fj-core/src/validation/checks/multiple_references.rs +++ b/crates/fj-core/src/validation/checks/multiple_references.rs @@ -1,9 +1,10 @@ use std::{any::type_name_of_val, collections::HashMap, fmt}; use crate::{ + geometry::Geometry, storage::Handle, topology::{Cycle, HalfEdge, Region, Sketch}, - validation::ValidationCheck, + validation::{ValidationCheck, ValidationConfig}, }; /// Object that should be exclusively owned by another, is not @@ -37,8 +38,8 @@ where impl ValidationCheck for MultipleReferencesToObject { fn check<'r>( object: &'r Sketch, - _: &'r crate::geometry::Geometry, - _: &'r crate::validation::ValidationConfig, + _: &'r Geometry, + _: &'r ValidationConfig, ) -> impl Iterator + 'r { let mut cycles = ReferenceCounter::new(); @@ -55,8 +56,8 @@ impl ValidationCheck for MultipleReferencesToObject { impl ValidationCheck for MultipleReferencesToObject { fn check<'r>( object: &'r Sketch, - _: &'r crate::geometry::Geometry, - _: &'r crate::validation::ValidationConfig, + _: &'r Geometry, + _: &'r ValidationConfig, ) -> impl Iterator + 'r { let mut half_edges = ReferenceCounter::new(); From 9da967db6117816ecc627e7731ff067da8f5bbe5 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 29 May 2024 13:51:25 +0200 Subject: [PATCH 02/18] Port part of validation test to new infrastructure --- crates/fj-core/src/validate/solid.rs | 18 ++++++++------ .../validation/checks/multiple_references.rs | 24 ++++++++++++++++++- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/crates/fj-core/src/validate/solid.rs b/crates/fj-core/src/validate/solid.rs index 753cbc2ee..83a7561c1 100644 --- a/crates/fj-core/src/validate/solid.rs +++ b/crates/fj-core/src/validate/solid.rs @@ -3,8 +3,11 @@ use std::iter::repeat; use crate::{ geometry::Geometry, storage::Handle, - topology::{Solid, Vertex}, - validation::checks::ReferenceCounter, + topology::{Cycle, HalfEdge, Solid, Vertex}, + validation::{ + checks::{MultipleReferencesToObject, ReferenceCounter}, + ValidationCheck, + }, }; use fj_math::Point; @@ -17,6 +20,12 @@ impl Validate for Solid { errors: &mut Vec, geometry: &Geometry, ) { + errors.extend( + MultipleReferencesToObject::::check( + self, geometry, config, + ) + .map(Into::into), + ); SolidValidationError::check_vertices(self, geometry, config, errors); SolidValidationError::check_object_references(self, config, errors); } @@ -143,7 +152,6 @@ impl SolidValidationError { let mut faces = ReferenceCounter::new(); let mut regions = ReferenceCounter::new(); let mut cycles = ReferenceCounter::new(); - let mut half_edges = ReferenceCounter::new(); solid.shells().iter().for_each(|s| { s.faces().into_iter().for_each(|f| { @@ -151,9 +159,6 @@ impl SolidValidationError { regions.count(f.region().clone(), f.clone()); f.region().all_cycles().for_each(|c| { cycles.count(c.clone(), f.region().clone()); - c.half_edges().into_iter().for_each(|e| { - half_edges.count(e.clone(), c.clone()); - }) }) }) }); @@ -161,7 +166,6 @@ impl SolidValidationError { errors.extend(faces.multiples().map(Into::into)); errors.extend(regions.multiples().map(Into::into)); errors.extend(cycles.multiples().map(Into::into)); - errors.extend(half_edges.multiples().map(Into::into)); } } diff --git a/crates/fj-core/src/validation/checks/multiple_references.rs b/crates/fj-core/src/validation/checks/multiple_references.rs index 3eabab854..e93e97015 100644 --- a/crates/fj-core/src/validation/checks/multiple_references.rs +++ b/crates/fj-core/src/validation/checks/multiple_references.rs @@ -3,7 +3,7 @@ use std::{any::type_name_of_val, collections::HashMap, fmt}; use crate::{ geometry::Geometry, storage::Handle, - topology::{Cycle, HalfEdge, Region, Sketch}, + topology::{Cycle, HalfEdge, Region, Sketch, Solid}, validation::{ValidationCheck, ValidationConfig}, }; @@ -73,6 +73,28 @@ impl ValidationCheck for MultipleReferencesToObject { } } +impl ValidationCheck for MultipleReferencesToObject { + fn check<'r>( + object: &'r Solid, + _: &'r Geometry, + _: &'r ValidationConfig, + ) -> impl Iterator + 'r { + let mut half_edges = ReferenceCounter::new(); + + for shell in object.shells() { + for face in shell.faces() { + for cycle in face.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. // This can happen once this validation check has been fully ported from the old // infrastructure. From 96617eeb1de5ae30e6e339c2015a222abb5ab6f9 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 29 May 2024 13:51:25 +0200 Subject: [PATCH 03/18] Port part of validation test to new infrastructure --- crates/fj-core/src/validate/solid.rs | 13 ++++++------ .../validation/checks/multiple_references.rs | 20 +++++++++++++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/crates/fj-core/src/validate/solid.rs b/crates/fj-core/src/validate/solid.rs index 83a7561c1..27d4802fa 100644 --- a/crates/fj-core/src/validate/solid.rs +++ b/crates/fj-core/src/validate/solid.rs @@ -3,7 +3,7 @@ use std::iter::repeat; use crate::{ geometry::Geometry, storage::Handle, - topology::{Cycle, HalfEdge, Solid, Vertex}, + topology::{Cycle, HalfEdge, Region, Solid, Vertex}, validation::{ checks::{MultipleReferencesToObject, ReferenceCounter}, ValidationCheck, @@ -20,6 +20,12 @@ impl Validate for Solid { errors: &mut Vec, geometry: &Geometry, ) { + errors.extend( + MultipleReferencesToObject::::check( + self, geometry, config, + ) + .map(Into::into), + ); errors.extend( MultipleReferencesToObject::::check( self, geometry, config, @@ -151,21 +157,16 @@ impl SolidValidationError { ) { let mut faces = ReferenceCounter::new(); let mut regions = ReferenceCounter::new(); - let mut cycles = ReferenceCounter::new(); solid.shells().iter().for_each(|s| { s.faces().into_iter().for_each(|f| { faces.count(f.clone(), s.clone()); regions.count(f.region().clone(), f.clone()); - f.region().all_cycles().for_each(|c| { - cycles.count(c.clone(), f.region().clone()); - }) }) }); errors.extend(faces.multiples().map(Into::into)); errors.extend(regions.multiples().map(Into::into)); - errors.extend(cycles.multiples().map(Into::into)); } } diff --git a/crates/fj-core/src/validation/checks/multiple_references.rs b/crates/fj-core/src/validation/checks/multiple_references.rs index e93e97015..19fc8a6ab 100644 --- a/crates/fj-core/src/validation/checks/multiple_references.rs +++ b/crates/fj-core/src/validation/checks/multiple_references.rs @@ -73,6 +73,26 @@ impl ValidationCheck for MultipleReferencesToObject { } } +impl ValidationCheck for MultipleReferencesToObject { + fn check<'r>( + object: &'r Solid, + _: &'r Geometry, + _: &'r ValidationConfig, + ) -> impl Iterator + 'r { + let mut cycles = ReferenceCounter::new(); + + for shell in object.shells() { + for face in shell.faces() { + for cycle in face.region().all_cycles() { + cycles.count(cycle.clone(), face.region().clone()); + } + } + } + + cycles.multiples() + } +} + impl ValidationCheck for MultipleReferencesToObject { fn check<'r>( object: &'r Solid, From e5d7a54a43585e5d8e06219a308f61fe38574c49 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 29 May 2024 13:51:25 +0200 Subject: [PATCH 04/18] Port part of validation test to new infrastructure --- crates/fj-core/src/validate/solid.rs | 11 ++++++---- .../validation/checks/multiple_references.rs | 20 ++++++++++++++++++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/crates/fj-core/src/validate/solid.rs b/crates/fj-core/src/validate/solid.rs index 27d4802fa..deece5cd1 100644 --- a/crates/fj-core/src/validate/solid.rs +++ b/crates/fj-core/src/validate/solid.rs @@ -3,7 +3,7 @@ use std::iter::repeat; use crate::{ geometry::Geometry, storage::Handle, - topology::{Cycle, HalfEdge, Region, Solid, Vertex}, + topology::{Cycle, Face, HalfEdge, Region, Solid, Vertex}, validation::{ checks::{MultipleReferencesToObject, ReferenceCounter}, ValidationCheck, @@ -20,6 +20,12 @@ impl Validate for Solid { errors: &mut Vec, geometry: &Geometry, ) { + errors.extend( + MultipleReferencesToObject::::check( + self, geometry, config, + ) + .map(Into::into), + ); errors.extend( MultipleReferencesToObject::::check( self, geometry, config, @@ -156,17 +162,14 @@ impl SolidValidationError { errors: &mut Vec, ) { let mut faces = ReferenceCounter::new(); - let mut regions = ReferenceCounter::new(); solid.shells().iter().for_each(|s| { s.faces().into_iter().for_each(|f| { faces.count(f.clone(), s.clone()); - regions.count(f.region().clone(), f.clone()); }) }); errors.extend(faces.multiples().map(Into::into)); - errors.extend(regions.multiples().map(Into::into)); } } diff --git a/crates/fj-core/src/validation/checks/multiple_references.rs b/crates/fj-core/src/validation/checks/multiple_references.rs index 19fc8a6ab..9dff58505 100644 --- a/crates/fj-core/src/validation/checks/multiple_references.rs +++ b/crates/fj-core/src/validation/checks/multiple_references.rs @@ -3,7 +3,7 @@ use std::{any::type_name_of_val, collections::HashMap, fmt}; use crate::{ geometry::Geometry, storage::Handle, - topology::{Cycle, HalfEdge, Region, Sketch, Solid}, + topology::{Cycle, Face, HalfEdge, Region, Sketch, Solid}, validation::{ValidationCheck, ValidationConfig}, }; @@ -73,6 +73,24 @@ impl ValidationCheck for MultipleReferencesToObject { } } +impl ValidationCheck for MultipleReferencesToObject { + fn check<'r>( + object: &'r Solid, + _: &'r Geometry, + _: &'r ValidationConfig, + ) -> impl Iterator + 'r { + let mut regions = ReferenceCounter::new(); + + for shell in object.shells() { + for face in shell.faces() { + regions.count(face.region().clone(), face.clone()); + } + } + + regions.multiples() + } +} + impl ValidationCheck for MultipleReferencesToObject { fn check<'r>( object: &'r Solid, From d714275d85fb5b2cae3047c1404dff3bc308c395 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 29 May 2024 13:51:25 +0200 Subject: [PATCH 05/18] Port rest of validation test to new infrastructure --- crates/fj-core/src/validate/solid.rs | 30 +++++-------------- .../validation/checks/multiple_references.rs | 20 ++++++++++++- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/crates/fj-core/src/validate/solid.rs b/crates/fj-core/src/validate/solid.rs index deece5cd1..c0e5e2803 100644 --- a/crates/fj-core/src/validate/solid.rs +++ b/crates/fj-core/src/validate/solid.rs @@ -3,11 +3,8 @@ use std::iter::repeat; use crate::{ geometry::Geometry, storage::Handle, - topology::{Cycle, Face, HalfEdge, Region, Solid, Vertex}, - validation::{ - checks::{MultipleReferencesToObject, ReferenceCounter}, - ValidationCheck, - }, + topology::{Cycle, Face, HalfEdge, Region, Shell, Solid, Vertex}, + validation::{checks::MultipleReferencesToObject, ValidationCheck}, }; use fj_math::Point; @@ -20,6 +17,12 @@ impl Validate for Solid { errors: &mut Vec, geometry: &Geometry, ) { + errors.extend( + MultipleReferencesToObject::::check( + self, geometry, config, + ) + .map(Into::into), + ); errors.extend( MultipleReferencesToObject::::check( self, geometry, config, @@ -39,7 +42,6 @@ impl Validate for Solid { .map(Into::into), ); SolidValidationError::check_vertices(self, geometry, config, errors); - SolidValidationError::check_object_references(self, config, errors); } } @@ -155,22 +157,6 @@ impl SolidValidationError { } } } - - fn check_object_references( - solid: &Solid, - _config: &ValidationConfig, - errors: &mut Vec, - ) { - let mut faces = ReferenceCounter::new(); - - solid.shells().iter().for_each(|s| { - s.faces().into_iter().for_each(|f| { - faces.count(f.clone(), s.clone()); - }) - }); - - errors.extend(faces.multiples().map(Into::into)); - } } #[cfg(test)] diff --git a/crates/fj-core/src/validation/checks/multiple_references.rs b/crates/fj-core/src/validation/checks/multiple_references.rs index 9dff58505..bad774bff 100644 --- a/crates/fj-core/src/validation/checks/multiple_references.rs +++ b/crates/fj-core/src/validation/checks/multiple_references.rs @@ -3,7 +3,7 @@ use std::{any::type_name_of_val, collections::HashMap, fmt}; use crate::{ geometry::Geometry, storage::Handle, - topology::{Cycle, Face, HalfEdge, Region, Sketch, Solid}, + topology::{Cycle, Face, HalfEdge, Region, Shell, Sketch, Solid}, validation::{ValidationCheck, ValidationConfig}, }; @@ -73,6 +73,24 @@ impl ValidationCheck for MultipleReferencesToObject { } } +impl ValidationCheck for MultipleReferencesToObject { + fn check<'r>( + object: &'r Solid, + _: &'r Geometry, + _: &'r ValidationConfig, + ) -> impl Iterator + 'r { + let mut faces = ReferenceCounter::new(); + + for shell in object.shells() { + for face in shell.faces() { + faces.count(face.clone(), shell.clone()); + } + } + + faces.multiples() + } +} + impl ValidationCheck for MultipleReferencesToObject { fn check<'r>( object: &'r Solid, From 8743c605e77b930aff3ac2376a456dd5df2c5e0e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 29 May 2024 14:00:20 +0200 Subject: [PATCH 06/18] Move tests closer to code under test --- crates/fj-core/src/validate/solid.rs | 203 ------------------ .../validation/checks/multiple_references.rs | 203 +++++++++++++++++- 2 files changed, 200 insertions(+), 206 deletions(-) diff --git a/crates/fj-core/src/validate/solid.rs b/crates/fj-core/src/validate/solid.rs index c0e5e2803..7f392bb6c 100644 --- a/crates/fj-core/src/validate/solid.rs +++ b/crates/fj-core/src/validate/solid.rs @@ -158,206 +158,3 @@ impl SolidValidationError { } } } - -#[cfg(test)] -mod tests { - use crate::{ - assert_contains_err, - geometry::GlobalPath, - operations::{ - build::{BuildFace, BuildHalfEdge, BuildSurface}, - insert::Insert, - }, - topology::{Cycle, Face, HalfEdge, Region, Shell, Solid, Surface}, - validate::{Validate, ValidationError}, - Core, - }; - - #[test] - fn should_find_face_multiple_references() -> anyhow::Result<()> { - let mut core = Core::new(); - - let surface = Surface::from_uv( - GlobalPath::circle_from_radius(1.), - [0., 1., 1.], - &mut core, - ); - - let shared_face = Face::new( - surface.clone(), - Region::new( - Cycle::new(vec![HalfEdge::circle( - [0., 0.], - 1., - surface, - &mut core, - )]) - .insert(&mut core), - vec![], - ) - .insert(&mut core), - ) - .insert(&mut core); - - let invalid_solid = Solid::new(vec![ - Shell::new(vec![shared_face.clone()]).insert(&mut core), - Shell::new(vec![ - shared_face, - Face::triangle( - [[0., 0., 0.], [1., 0., 0.], [1., 1., 0.]], - &mut core, - ) - .insert(&mut core) - .face, - ]) - .insert(&mut core), - ]) - .insert(&mut core); - - assert_contains_err!( - core, - invalid_solid, - ValidationError::MultipleReferencesToFace(_) - ); - - let valid_solid = Solid::new(vec![]).insert(&mut core); - valid_solid.validate_and_return_first_error(&core.layers.geometry)?; - - // Ignore remaining validation errors. - let _ = core.layers.validation.take_errors(); - - Ok(()) - } - - #[test] - fn should_find_region_multiple_references() -> anyhow::Result<()> { - let mut core = Core::new(); - - let surface = Surface::from_uv( - GlobalPath::circle_from_radius(1.), - [0., 0., 1.], - &mut core, - ); - - let shared_region = Region::new( - Cycle::new(vec![HalfEdge::circle( - [0., 0.], - 1., - surface.clone(), - &mut core, - )]) - .insert(&mut core), - vec![], - ) - .insert(&mut core); - - let invalid_solid = Solid::new(vec![Shell::new(vec![ - Face::new(surface.clone(), shared_region.clone()).insert(&mut core), - Face::new(surface, shared_region.clone()).insert(&mut core), - ]) - .insert(&mut core)]) - .insert(&mut core); - - assert_contains_err!( - core, - invalid_solid, - ValidationError::MultipleReferencesToRegion(_) - ); - - let valid_solid = Solid::new(vec![]).insert(&mut core); - valid_solid.validate_and_return_first_error(&core.layers.geometry)?; - - // Ignore remaining validation errors. - let _ = core.layers.validation.take_errors(); - - Ok(()) - } - - #[test] - fn should_find_cycle_multiple_references() -> anyhow::Result<()> { - let mut core = Core::new(); - - let surface = Surface::from_uv( - GlobalPath::circle_from_radius(1.), - [0., 0., 1.], - &mut core, - ); - - let shared_cycle = Cycle::new(vec![HalfEdge::circle( - [0., 0.], - 1., - surface.clone(), - &mut core, - )]) - .insert(&mut core); - - let invalid_solid = Solid::new(vec![Shell::new(vec![ - Face::new( - surface.clone(), - Region::new(shared_cycle.clone(), vec![]).insert(&mut core), - ) - .insert(&mut core), - Face::new( - surface, - Region::new(shared_cycle, vec![]).insert(&mut core), - ) - .insert(&mut core), - ]) - .insert(&mut core)]) - .insert(&mut core); - - assert_contains_err!( - core, - invalid_solid, - ValidationError::MultipleReferencesToCycle(_) - ); - - let valid_solid = Solid::new(vec![]).insert(&mut core); - valid_solid.validate_and_return_first_error(&core.layers.geometry)?; - - // Ignore remaining validation errors. - let _ = core.layers.validation.take_errors(); - - Ok(()) - } - - #[test] - fn should_find_half_edge_multiple_references() -> anyhow::Result<()> { - let mut core = Core::new(); - - let surface = Surface::from_uv( - GlobalPath::circle_from_radius(1.), - [0., 0., 1.], - &mut core, - ); - - let shared_edge = - HalfEdge::circle([0., 0.], 1., surface.clone(), &mut core); - - let invalid_solid = Solid::new(vec![Shell::new(vec![Face::new( - surface, - Region::new( - Cycle::new(vec![shared_edge.clone()]).insert(&mut core), - vec![Cycle::new(vec![shared_edge.clone()]).insert(&mut core)], - ) - .insert(&mut core), - ) - .insert(&mut core)]) - .insert(&mut core)]) - .insert(&mut core); - - assert_contains_err!( - core, - invalid_solid, - ValidationError::MultipleReferencesToHalfEdge(_) - ); - - let valid_solid = Solid::new(vec![]).insert(&mut core); - valid_solid.validate_and_return_first_error(&core.layers.geometry)?; - - // Ignore remaining validation errors. - let _ = core.layers.validation.take_errors(); - - Ok(()) - } -} diff --git a/crates/fj-core/src/validation/checks/multiple_references.rs b/crates/fj-core/src/validation/checks/multiple_references.rs index bad774bff..9ae664f50 100644 --- a/crates/fj-core/src/validation/checks/multiple_references.rs +++ b/crates/fj-core/src/validation/checks/multiple_references.rs @@ -187,12 +187,21 @@ impl ReferenceCounter { #[cfg(test)] mod tests { use crate::{ + assert_contains_err, + geometry::GlobalPath, operations::{ - build::BuildSketch, + build::{BuildFace, BuildHalfEdge, BuildSketch, BuildSurface}, + insert::Insert, update::{UpdateRegion, UpdateSketch}, }, - topology::{Cycle, HalfEdge, Region, Sketch}, - validation::{checks::MultipleReferencesToObject, ValidationCheck}, + topology::{ + Cycle, Face, HalfEdge, Region, Shell, Sketch, Solid, Surface, + }, + validate::Validate, + validation::{ + checks::MultipleReferencesToObject, ValidationCheck, + ValidationError, + }, Core, }; @@ -262,4 +271,192 @@ mod tests { Ok(()) } + + #[test] + fn should_find_face_multiple_references() -> anyhow::Result<()> { + let mut core = Core::new(); + + let surface = Surface::from_uv( + GlobalPath::circle_from_radius(1.), + [0., 1., 1.], + &mut core, + ); + + let shared_face = Face::new( + surface.clone(), + Region::new( + Cycle::new(vec![HalfEdge::circle( + [0., 0.], + 1., + surface, + &mut core, + )]) + .insert(&mut core), + vec![], + ) + .insert(&mut core), + ) + .insert(&mut core); + + let invalid_solid = Solid::new(vec![ + Shell::new(vec![shared_face.clone()]).insert(&mut core), + Shell::new(vec![ + shared_face, + Face::triangle( + [[0., 0., 0.], [1., 0., 0.], [1., 1., 0.]], + &mut core, + ) + .insert(&mut core) + .face, + ]) + .insert(&mut core), + ]) + .insert(&mut core); + + assert_contains_err!( + core, + invalid_solid, + ValidationError::MultipleReferencesToFace(_) + ); + + let valid_solid = Solid::new(vec![]).insert(&mut core); + valid_solid.validate_and_return_first_error(&core.layers.geometry)?; + + // Ignore remaining validation errors. + let _ = core.layers.validation.take_errors(); + + Ok(()) + } + + #[test] + fn should_find_region_multiple_references() -> anyhow::Result<()> { + let mut core = Core::new(); + + let surface = Surface::from_uv( + GlobalPath::circle_from_radius(1.), + [0., 0., 1.], + &mut core, + ); + + let shared_region = Region::new( + Cycle::new(vec![HalfEdge::circle( + [0., 0.], + 1., + surface.clone(), + &mut core, + )]) + .insert(&mut core), + vec![], + ) + .insert(&mut core); + + let invalid_solid = Solid::new(vec![Shell::new(vec![ + Face::new(surface.clone(), shared_region.clone()).insert(&mut core), + Face::new(surface, shared_region.clone()).insert(&mut core), + ]) + .insert(&mut core)]) + .insert(&mut core); + + assert_contains_err!( + core, + invalid_solid, + ValidationError::MultipleReferencesToRegion(_) + ); + + let valid_solid = Solid::new(vec![]).insert(&mut core); + valid_solid.validate_and_return_first_error(&core.layers.geometry)?; + + // Ignore remaining validation errors. + let _ = core.layers.validation.take_errors(); + + Ok(()) + } + + #[test] + fn should_find_cycle_multiple_references() -> anyhow::Result<()> { + let mut core = Core::new(); + + let surface = Surface::from_uv( + GlobalPath::circle_from_radius(1.), + [0., 0., 1.], + &mut core, + ); + + let shared_cycle = Cycle::new(vec![HalfEdge::circle( + [0., 0.], + 1., + surface.clone(), + &mut core, + )]) + .insert(&mut core); + + let invalid_solid = Solid::new(vec![Shell::new(vec![ + Face::new( + surface.clone(), + Region::new(shared_cycle.clone(), vec![]).insert(&mut core), + ) + .insert(&mut core), + Face::new( + surface, + Region::new(shared_cycle, vec![]).insert(&mut core), + ) + .insert(&mut core), + ]) + .insert(&mut core)]) + .insert(&mut core); + + assert_contains_err!( + core, + invalid_solid, + ValidationError::MultipleReferencesToCycle(_) + ); + + let valid_solid = Solid::new(vec![]).insert(&mut core); + valid_solid.validate_and_return_first_error(&core.layers.geometry)?; + + // Ignore remaining validation errors. + let _ = core.layers.validation.take_errors(); + + Ok(()) + } + + #[test] + fn should_find_half_edge_multiple_references() -> anyhow::Result<()> { + let mut core = Core::new(); + + let surface = Surface::from_uv( + GlobalPath::circle_from_radius(1.), + [0., 0., 1.], + &mut core, + ); + + let shared_edge = + HalfEdge::circle([0., 0.], 1., surface.clone(), &mut core); + + let invalid_solid = Solid::new(vec![Shell::new(vec![Face::new( + surface, + Region::new( + Cycle::new(vec![shared_edge.clone()]).insert(&mut core), + vec![Cycle::new(vec![shared_edge.clone()]).insert(&mut core)], + ) + .insert(&mut core), + ) + .insert(&mut core)]) + .insert(&mut core)]) + .insert(&mut core); + + assert_contains_err!( + core, + invalid_solid, + ValidationError::MultipleReferencesToHalfEdge(_) + ); + + let valid_solid = Solid::new(vec![]).insert(&mut core); + valid_solid.validate_and_return_first_error(&core.layers.geometry)?; + + // Ignore remaining validation errors. + let _ = core.layers.validation.take_errors(); + + Ok(()) + } } From d5cb49758c59290baedc91e5559e0a5d2afc1017 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 29 May 2024 14:01:25 +0200 Subject: [PATCH 07/18] Make test names more specific --- crates/fj-core/src/validation/checks/multiple_references.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-core/src/validation/checks/multiple_references.rs b/crates/fj-core/src/validation/checks/multiple_references.rs index 9ae664f50..c9171dfc2 100644 --- a/crates/fj-core/src/validation/checks/multiple_references.rs +++ b/crates/fj-core/src/validation/checks/multiple_references.rs @@ -206,7 +206,7 @@ mod tests { }; #[test] - fn multiple_references_to_cycle() -> anyhow::Result<()> { + fn multiple_references_to_cycle_within_sketch() -> anyhow::Result<()> { let mut core = Core::new(); let valid = Sketch::circle([0., 0.], 1., &mut core); @@ -234,7 +234,7 @@ mod tests { } #[test] - fn multiple_references_to_half_edge() -> anyhow::Result<()> { + fn multiple_references_to_half_edge_within_sketch() -> anyhow::Result<()> { let mut core = Core::new(); let valid = Sketch::polygon([[0., 0.], [1., 1.], [0., 1.]], &mut core); From 57269cf47fa6b89432c51dc5438854365eccb6a9 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 29 May 2024 14:02:42 +0200 Subject: [PATCH 08/18] Update test names --- .../fj-core/src/validation/checks/multiple_references.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/fj-core/src/validation/checks/multiple_references.rs b/crates/fj-core/src/validation/checks/multiple_references.rs index c9171dfc2..228dd9532 100644 --- a/crates/fj-core/src/validation/checks/multiple_references.rs +++ b/crates/fj-core/src/validation/checks/multiple_references.rs @@ -273,7 +273,7 @@ mod tests { } #[test] - fn should_find_face_multiple_references() -> anyhow::Result<()> { + fn multiple_references_to_face_within_solid() -> anyhow::Result<()> { let mut core = Core::new(); let surface = Surface::from_uv( @@ -329,7 +329,7 @@ mod tests { } #[test] - fn should_find_region_multiple_references() -> anyhow::Result<()> { + fn multiple_references_to_region_within_solid() -> anyhow::Result<()> { let mut core = Core::new(); let surface = Surface::from_uv( @@ -373,7 +373,7 @@ mod tests { } #[test] - fn should_find_cycle_multiple_references() -> anyhow::Result<()> { + fn multiple_references_to_cycle_within_solid() -> anyhow::Result<()> { let mut core = Core::new(); let surface = Surface::from_uv( @@ -421,7 +421,7 @@ mod tests { } #[test] - fn should_find_half_edge_multiple_references() -> anyhow::Result<()> { + fn multiple_references_to_half_edge_within_solid() -> anyhow::Result<()> { let mut core = Core::new(); let surface = Surface::from_uv( From 4ed903e1503c5d32ec7aa8c287d55a9b9737f56b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 29 May 2024 14:03:27 +0200 Subject: [PATCH 09/18] Simplify variable names --- .../src/validation/checks/multiple_references.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/fj-core/src/validation/checks/multiple_references.rs b/crates/fj-core/src/validation/checks/multiple_references.rs index 228dd9532..9730a93cc 100644 --- a/crates/fj-core/src/validation/checks/multiple_references.rs +++ b/crates/fj-core/src/validation/checks/multiple_references.rs @@ -319,8 +319,8 @@ mod tests { ValidationError::MultipleReferencesToFace(_) ); - let valid_solid = Solid::new(vec![]).insert(&mut core); - valid_solid.validate_and_return_first_error(&core.layers.geometry)?; + let valid = Solid::new(vec![]).insert(&mut core); + valid.validate_and_return_first_error(&core.layers.geometry)?; // Ignore remaining validation errors. let _ = core.layers.validation.take_errors(); @@ -363,8 +363,8 @@ mod tests { ValidationError::MultipleReferencesToRegion(_) ); - let valid_solid = Solid::new(vec![]).insert(&mut core); - valid_solid.validate_and_return_first_error(&core.layers.geometry)?; + let valid = Solid::new(vec![]).insert(&mut core); + valid.validate_and_return_first_error(&core.layers.geometry)?; // Ignore remaining validation errors. let _ = core.layers.validation.take_errors(); @@ -411,8 +411,8 @@ mod tests { ValidationError::MultipleReferencesToCycle(_) ); - let valid_solid = Solid::new(vec![]).insert(&mut core); - valid_solid.validate_and_return_first_error(&core.layers.geometry)?; + let valid = Solid::new(vec![]).insert(&mut core); + valid.validate_and_return_first_error(&core.layers.geometry)?; // Ignore remaining validation errors. let _ = core.layers.validation.take_errors(); @@ -451,8 +451,8 @@ mod tests { ValidationError::MultipleReferencesToHalfEdge(_) ); - let valid_solid = Solid::new(vec![]).insert(&mut core); - valid_solid.validate_and_return_first_error(&core.layers.geometry)?; + let valid = Solid::new(vec![]).insert(&mut core); + valid.validate_and_return_first_error(&core.layers.geometry)?; // Ignore remaining validation errors. let _ = core.layers.validation.take_errors(); From 4031971dcf1da2224df4b6d996a19b2dbd48af0f Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 29 May 2024 14:04:07 +0200 Subject: [PATCH 10/18] Simplify variable names --- .../src/validation/checks/multiple_references.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/fj-core/src/validation/checks/multiple_references.rs b/crates/fj-core/src/validation/checks/multiple_references.rs index 9730a93cc..41610c554 100644 --- a/crates/fj-core/src/validation/checks/multiple_references.rs +++ b/crates/fj-core/src/validation/checks/multiple_references.rs @@ -298,7 +298,7 @@ mod tests { ) .insert(&mut core); - let invalid_solid = Solid::new(vec![ + let invalid = Solid::new(vec![ Shell::new(vec![shared_face.clone()]).insert(&mut core), Shell::new(vec![ shared_face, @@ -315,7 +315,7 @@ mod tests { assert_contains_err!( core, - invalid_solid, + invalid, ValidationError::MultipleReferencesToFace(_) ); @@ -350,7 +350,7 @@ mod tests { ) .insert(&mut core); - let invalid_solid = Solid::new(vec![Shell::new(vec![ + let invalid = Solid::new(vec![Shell::new(vec![ Face::new(surface.clone(), shared_region.clone()).insert(&mut core), Face::new(surface, shared_region.clone()).insert(&mut core), ]) @@ -359,7 +359,7 @@ mod tests { assert_contains_err!( core, - invalid_solid, + invalid, ValidationError::MultipleReferencesToRegion(_) ); @@ -390,7 +390,7 @@ mod tests { )]) .insert(&mut core); - let invalid_solid = Solid::new(vec![Shell::new(vec![ + let invalid = Solid::new(vec![Shell::new(vec![ Face::new( surface.clone(), Region::new(shared_cycle.clone(), vec![]).insert(&mut core), @@ -407,7 +407,7 @@ mod tests { assert_contains_err!( core, - invalid_solid, + invalid, ValidationError::MultipleReferencesToCycle(_) ); @@ -433,7 +433,7 @@ mod tests { let shared_edge = HalfEdge::circle([0., 0.], 1., surface.clone(), &mut core); - let invalid_solid = Solid::new(vec![Shell::new(vec![Face::new( + let invalid = Solid::new(vec![Shell::new(vec![Face::new( surface, Region::new( Cycle::new(vec![shared_edge.clone()]).insert(&mut core), @@ -447,7 +447,7 @@ mod tests { assert_contains_err!( core, - invalid_solid, + invalid, ValidationError::MultipleReferencesToHalfEdge(_) ); From 27b84a0fb878e904c519d94077c9463eee0cb431 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 29 May 2024 14:07:05 +0200 Subject: [PATCH 11/18] Prepare for follow-on change --- .../validation/checks/multiple_references.rs | 44 +++++++++++++++---- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/crates/fj-core/src/validation/checks/multiple_references.rs b/crates/fj-core/src/validation/checks/multiple_references.rs index 41610c554..855b5be42 100644 --- a/crates/fj-core/src/validation/checks/multiple_references.rs +++ b/crates/fj-core/src/validation/checks/multiple_references.rs @@ -190,7 +190,9 @@ mod tests { assert_contains_err, geometry::GlobalPath, operations::{ - build::{BuildFace, BuildHalfEdge, BuildSketch, BuildSurface}, + build::{ + BuildFace, BuildHalfEdge, BuildSketch, BuildSolid, BuildSurface, + }, insert::Insert, update::{UpdateRegion, UpdateSketch}, }, @@ -276,6 +278,11 @@ mod tests { fn multiple_references_to_face_within_solid() -> anyhow::Result<()> { let mut core = Core::new(); + let valid = Solid::tetrahedron( + [[0., 0., 0.], [1., 0., 0.], [0., 1., 0.], [0., 0., 1.]], + &mut core, + ); + let surface = Surface::from_uv( GlobalPath::circle_from_radius(1.), [0., 1., 1.], @@ -319,8 +326,9 @@ mod tests { ValidationError::MultipleReferencesToFace(_) ); - let valid = Solid::new(vec![]).insert(&mut core); - valid.validate_and_return_first_error(&core.layers.geometry)?; + valid + .solid + .validate_and_return_first_error(&core.layers.geometry)?; // Ignore remaining validation errors. let _ = core.layers.validation.take_errors(); @@ -332,6 +340,11 @@ mod tests { fn multiple_references_to_region_within_solid() -> anyhow::Result<()> { let mut core = Core::new(); + let valid = Solid::tetrahedron( + [[0., 0., 0.], [1., 0., 0.], [0., 1., 0.], [0., 0., 1.]], + &mut core, + ); + let surface = Surface::from_uv( GlobalPath::circle_from_radius(1.), [0., 0., 1.], @@ -363,8 +376,9 @@ mod tests { ValidationError::MultipleReferencesToRegion(_) ); - let valid = Solid::new(vec![]).insert(&mut core); - valid.validate_and_return_first_error(&core.layers.geometry)?; + valid + .solid + .validate_and_return_first_error(&core.layers.geometry)?; // Ignore remaining validation errors. let _ = core.layers.validation.take_errors(); @@ -376,6 +390,11 @@ mod tests { fn multiple_references_to_cycle_within_solid() -> anyhow::Result<()> { let mut core = Core::new(); + let valid = Solid::tetrahedron( + [[0., 0., 0.], [1., 0., 0.], [0., 1., 0.], [0., 0., 1.]], + &mut core, + ); + let surface = Surface::from_uv( GlobalPath::circle_from_radius(1.), [0., 0., 1.], @@ -411,8 +430,9 @@ mod tests { ValidationError::MultipleReferencesToCycle(_) ); - let valid = Solid::new(vec![]).insert(&mut core); - valid.validate_and_return_first_error(&core.layers.geometry)?; + valid + .solid + .validate_and_return_first_error(&core.layers.geometry)?; // Ignore remaining validation errors. let _ = core.layers.validation.take_errors(); @@ -424,6 +444,11 @@ mod tests { fn multiple_references_to_half_edge_within_solid() -> anyhow::Result<()> { let mut core = Core::new(); + let valid = Solid::tetrahedron( + [[0., 0., 0.], [1., 0., 0.], [0., 1., 0.], [0., 0., 1.]], + &mut core, + ); + let surface = Surface::from_uv( GlobalPath::circle_from_radius(1.), [0., 0., 1.], @@ -451,8 +476,9 @@ mod tests { ValidationError::MultipleReferencesToHalfEdge(_) ); - let valid = Solid::new(vec![]).insert(&mut core); - valid.validate_and_return_first_error(&core.layers.geometry)?; + valid + .solid + .validate_and_return_first_error(&core.layers.geometry)?; // Ignore remaining validation errors. let _ = core.layers.validation.take_errors(); From ba5d82c54ac7e1f42c830ba1aae99428919223d8 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 29 May 2024 14:12:41 +0200 Subject: [PATCH 12/18] Use more targeted test condition --- .../validation/checks/multiple_references.rs | 44 ++++++++++++------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/crates/fj-core/src/validation/checks/multiple_references.rs b/crates/fj-core/src/validation/checks/multiple_references.rs index 855b5be42..e5028d43a 100644 --- a/crates/fj-core/src/validation/checks/multiple_references.rs +++ b/crates/fj-core/src/validation/checks/multiple_references.rs @@ -282,6 +282,13 @@ mod tests { [[0., 0., 0.], [1., 0., 0.], [0., 1., 0.], [0., 0., 1.]], &mut core, ); + MultipleReferencesToObject::< + Face, + Shell + >::check_and_return_first_error( + &valid.solid, + &core.layers.geometry, + )?; let surface = Surface::from_uv( GlobalPath::circle_from_radius(1.), @@ -326,10 +333,6 @@ mod tests { ValidationError::MultipleReferencesToFace(_) ); - valid - .solid - .validate_and_return_first_error(&core.layers.geometry)?; - // Ignore remaining validation errors. let _ = core.layers.validation.take_errors(); @@ -344,6 +347,13 @@ mod tests { [[0., 0., 0.], [1., 0., 0.], [0., 1., 0.], [0., 0., 1.]], &mut core, ); + MultipleReferencesToObject::< + Region, + Face + >::check_and_return_first_error( + &valid.solid, + &core.layers.geometry, + )?; let surface = Surface::from_uv( GlobalPath::circle_from_radius(1.), @@ -376,10 +386,6 @@ mod tests { ValidationError::MultipleReferencesToRegion(_) ); - valid - .solid - .validate_and_return_first_error(&core.layers.geometry)?; - // Ignore remaining validation errors. let _ = core.layers.validation.take_errors(); @@ -394,6 +400,13 @@ mod tests { [[0., 0., 0.], [1., 0., 0.], [0., 1., 0.], [0., 0., 1.]], &mut core, ); + MultipleReferencesToObject::< + Cycle, + Region + >::check_and_return_first_error( + &valid.solid, + &core.layers.geometry, + )?; let surface = Surface::from_uv( GlobalPath::circle_from_radius(1.), @@ -430,10 +443,6 @@ mod tests { ValidationError::MultipleReferencesToCycle(_) ); - valid - .solid - .validate_and_return_first_error(&core.layers.geometry)?; - // Ignore remaining validation errors. let _ = core.layers.validation.take_errors(); @@ -448,6 +457,13 @@ mod tests { [[0., 0., 0.], [1., 0., 0.], [0., 1., 0.], [0., 0., 1.]], &mut core, ); + MultipleReferencesToObject::< + HalfEdge, + Cycle + >::check_and_return_first_error( + &valid.solid, + &core.layers.geometry, + )?; let surface = Surface::from_uv( GlobalPath::circle_from_radius(1.), @@ -476,10 +492,6 @@ mod tests { ValidationError::MultipleReferencesToHalfEdge(_) ); - valid - .solid - .validate_and_return_first_error(&core.layers.geometry)?; - // Ignore remaining validation errors. let _ = core.layers.validation.take_errors(); From d3ac878d25c42fc35c1d4ca3312ab2a482b0da9f Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 29 May 2024 14:20:39 +0200 Subject: [PATCH 13/18] Derive invalid solid from valid one --- .../validation/checks/multiple_references.rs | 53 +++++++------------ 1 file changed, 18 insertions(+), 35 deletions(-) diff --git a/crates/fj-core/src/validation/checks/multiple_references.rs b/crates/fj-core/src/validation/checks/multiple_references.rs index e5028d43a..2a5976389 100644 --- a/crates/fj-core/src/validation/checks/multiple_references.rs +++ b/crates/fj-core/src/validation/checks/multiple_references.rs @@ -191,10 +191,11 @@ mod tests { geometry::GlobalPath, operations::{ build::{ - BuildFace, BuildHalfEdge, BuildSketch, BuildSolid, BuildSurface, + BuildHalfEdge, BuildShell, BuildSketch, BuildSolid, + BuildSurface, }, insert::Insert, - update::{UpdateRegion, UpdateSketch}, + update::{UpdateRegion, UpdateShell, UpdateSketch, UpdateSolid}, }, topology::{ Cycle, Face, HalfEdge, Region, Shell, Sketch, Solid, Surface, @@ -290,42 +291,24 @@ mod tests { &core.layers.geometry, )?; - let surface = Surface::from_uv( - GlobalPath::circle_from_radius(1.), - [0., 1., 1.], - &mut core, - ); - - let shared_face = Face::new( - surface.clone(), - Region::new( - Cycle::new(vec![HalfEdge::circle( - [0., 0.], - 1., - surface, + let invalid = valid.solid.add_shells( + { + let shell = Shell::tetrahedron( + [[0., 0., 0.], [1., 0., 0.], [0., 1., 0.], [0., 0., 1.]], &mut core, - )]) - .insert(&mut core), - vec![], - ) - .insert(&mut core), - ) - .insert(&mut core); + ) + .shell; - let invalid = Solid::new(vec![ - Shell::new(vec![shared_face.clone()]).insert(&mut core), - Shell::new(vec![ - shared_face, - Face::triangle( - [[0., 0., 0.], [1., 0., 0.], [1., 1., 0.]], + [shell.update_face( + shell.faces().first(), + |_, _| { + [valid.solid.shells().first().faces().first().clone()] + }, &mut core, - ) - .insert(&mut core) - .face, - ]) - .insert(&mut core), - ]) - .insert(&mut core); + )] + }, + &mut core, + ); assert_contains_err!( core, From 1fe77d0a939ca2a8241a389bb9688a43a304cfd4 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 29 May 2024 14:20:39 +0200 Subject: [PATCH 14/18] Derive invalid solid from valid one --- .../validation/checks/multiple_references.rs | 43 +++++++++---------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/crates/fj-core/src/validation/checks/multiple_references.rs b/crates/fj-core/src/validation/checks/multiple_references.rs index 2a5976389..9ae6f7bf3 100644 --- a/crates/fj-core/src/validation/checks/multiple_references.rs +++ b/crates/fj-core/src/validation/checks/multiple_references.rs @@ -195,7 +195,10 @@ mod tests { BuildSurface, }, insert::Insert, - update::{UpdateRegion, UpdateShell, UpdateSketch, UpdateSolid}, + update::{ + UpdateFace, UpdateRegion, UpdateShell, UpdateSketch, + UpdateSolid, + }, }, topology::{ Cycle, Face, HalfEdge, Region, Shell, Sketch, Solid, Surface, @@ -338,31 +341,25 @@ mod tests { &core.layers.geometry, )?; - let surface = Surface::from_uv( - GlobalPath::circle_from_radius(1.), - [0., 0., 1.], + let invalid = valid.solid.update_shell( + valid.solid.shells().first(), + |shell, core| { + [shell.update_face( + shell.faces().first(), + |face, core| { + [face.update_region( + |_, _| { + shell.faces().nth(1).unwrap().region().clone() + }, + core, + )] + }, + core, + )] + }, &mut core, ); - let shared_region = Region::new( - Cycle::new(vec![HalfEdge::circle( - [0., 0.], - 1., - surface.clone(), - &mut core, - )]) - .insert(&mut core), - vec![], - ) - .insert(&mut core); - - let invalid = Solid::new(vec![Shell::new(vec![ - Face::new(surface.clone(), shared_region.clone()).insert(&mut core), - Face::new(surface, shared_region.clone()).insert(&mut core), - ]) - .insert(&mut core)]) - .insert(&mut core); - assert_contains_err!( core, invalid, From 73d9b16ad65151a2b3738cc489926bbb7605adad Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 29 May 2024 14:20:39 +0200 Subject: [PATCH 15/18] Derive invalid solid from valid one --- .../validation/checks/multiple_references.rs | 53 ++++++++++--------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/crates/fj-core/src/validation/checks/multiple_references.rs b/crates/fj-core/src/validation/checks/multiple_references.rs index 9ae6f7bf3..74045dad8 100644 --- a/crates/fj-core/src/validation/checks/multiple_references.rs +++ b/crates/fj-core/src/validation/checks/multiple_references.rs @@ -388,35 +388,36 @@ mod tests { &core.layers.geometry, )?; - let surface = Surface::from_uv( - GlobalPath::circle_from_radius(1.), - [0., 0., 1.], + let invalid = valid.solid.update_shell( + valid.solid.shells().first(), + |shell, core| { + [shell.update_face( + shell.faces().first(), + |face, core| { + [face.update_region( + |region, core| { + region.update_exterior( + |_, _| { + shell + .faces() + .nth(1) + .unwrap() + .region() + .exterior() + .clone() + }, + core, + ) + }, + core, + )] + }, + core, + )] + }, &mut core, ); - let shared_cycle = Cycle::new(vec![HalfEdge::circle( - [0., 0.], - 1., - surface.clone(), - &mut core, - )]) - .insert(&mut core); - - let invalid = Solid::new(vec![Shell::new(vec![ - Face::new( - surface.clone(), - Region::new(shared_cycle.clone(), vec![]).insert(&mut core), - ) - .insert(&mut core), - Face::new( - surface, - Region::new(shared_cycle, vec![]).insert(&mut core), - ) - .insert(&mut core), - ]) - .insert(&mut core)]) - .insert(&mut core); - assert_contains_err!( core, invalid, From 6fd750b4983e784e253bad1c0752718224ad99a4 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 29 May 2024 14:20:39 +0200 Subject: [PATCH 16/18] Derive invalid solid from valid one --- .../validation/checks/multiple_references.rs | 68 +++++++++++-------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/crates/fj-core/src/validation/checks/multiple_references.rs b/crates/fj-core/src/validation/checks/multiple_references.rs index 74045dad8..c8d69949b 100644 --- a/crates/fj-core/src/validation/checks/multiple_references.rs +++ b/crates/fj-core/src/validation/checks/multiple_references.rs @@ -188,21 +188,14 @@ impl ReferenceCounter { mod tests { use crate::{ assert_contains_err, - geometry::GlobalPath, operations::{ - build::{ - BuildHalfEdge, BuildShell, BuildSketch, BuildSolid, - BuildSurface, - }, - insert::Insert, + build::{BuildShell, BuildSketch, BuildSolid}, update::{ - UpdateFace, UpdateRegion, UpdateShell, UpdateSketch, - UpdateSolid, + UpdateCycle, UpdateFace, UpdateRegion, UpdateShell, + UpdateSketch, UpdateSolid, }, }, - topology::{ - Cycle, Face, HalfEdge, Region, Shell, Sketch, Solid, Surface, - }, + topology::{Cycle, Face, HalfEdge, Region, Shell, Sketch, Solid}, validate::Validate, validation::{ checks::MultipleReferencesToObject, ValidationCheck, @@ -446,27 +439,44 @@ mod tests { &core.layers.geometry, )?; - let surface = Surface::from_uv( - GlobalPath::circle_from_radius(1.), - [0., 0., 1.], + let invalid = valid.solid.update_shell( + valid.solid.shells().first(), + |shell, core| { + [shell.update_face( + shell.faces().first(), + |face, core| { + [face.update_region( + |region, core| { + region.update_exterior( + |cycle, core| { + cycle.update_half_edge( + cycle.half_edges().first(), + |_, _| { + [shell + .faces() + .nth(1) + .unwrap() + .region() + .exterior() + .half_edges() + .first() + .clone()] + }, + core, + ) + }, + core, + ) + }, + core, + )] + }, + core, + )] + }, &mut core, ); - let shared_edge = - HalfEdge::circle([0., 0.], 1., surface.clone(), &mut core); - - let invalid = Solid::new(vec![Shell::new(vec![Face::new( - surface, - Region::new( - Cycle::new(vec![shared_edge.clone()]).insert(&mut core), - vec![Cycle::new(vec![shared_edge.clone()]).insert(&mut core)], - ) - .insert(&mut core), - ) - .insert(&mut core)]) - .insert(&mut core)]) - .insert(&mut core); - assert_contains_err!( core, invalid, From f4a5d9064c884b83f2fc0a6630191e11ba53b686 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 29 May 2024 14:40:27 +0200 Subject: [PATCH 17/18] Use more targeted test conditions --- .../validation/checks/multiple_references.rs | 46 +++++++++++-------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/crates/fj-core/src/validation/checks/multiple_references.rs b/crates/fj-core/src/validation/checks/multiple_references.rs index c8d69949b..8cef7ec61 100644 --- a/crates/fj-core/src/validation/checks/multiple_references.rs +++ b/crates/fj-core/src/validation/checks/multiple_references.rs @@ -305,12 +305,13 @@ mod tests { }, &mut core, ); - - assert_contains_err!( - core, - invalid, - ValidationError::MultipleReferencesToFace(_) - ); + assert!(MultipleReferencesToObject::< + Face, + Shell + >::check_and_return_first_error( + &invalid, + &core.layers.geometry, + ).is_err()); // Ignore remaining validation errors. let _ = core.layers.validation.take_errors(); @@ -352,12 +353,13 @@ mod tests { }, &mut core, ); - - assert_contains_err!( - core, - invalid, - ValidationError::MultipleReferencesToRegion(_) - ); + assert!(MultipleReferencesToObject::< + Region, + Face + >::check_and_return_first_error( + &invalid, + &core.layers.geometry, + ).is_err()); // Ignore remaining validation errors. let _ = core.layers.validation.take_errors(); @@ -410,6 +412,13 @@ mod tests { }, &mut core, ); + assert!(MultipleReferencesToObject::< + Cycle, + Region + >::check_and_return_first_error( + &invalid, + &core.layers.geometry, + ).is_err()); assert_contains_err!( core, @@ -476,12 +485,13 @@ mod tests { }, &mut core, ); - - assert_contains_err!( - core, - invalid, - ValidationError::MultipleReferencesToHalfEdge(_) - ); + assert!(MultipleReferencesToObject::< + HalfEdge, + Cycle + >::check_and_return_first_error( + &invalid, + &core.layers.geometry, + ).is_err()); // Ignore remaining validation errors. let _ = core.layers.validation.take_errors(); From 5a91557cfb6cfbc0e1065f78cf609dbbfd3938fb Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 29 May 2024 14:41:20 +0200 Subject: [PATCH 18/18] Make helper struct private --- crates/fj-core/src/validation/checks/mod.rs | 2 +- .../src/validation/checks/multiple_references.rs | 10 +--------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/crates/fj-core/src/validation/checks/mod.rs b/crates/fj-core/src/validation/checks/mod.rs index 888f959ed..238806401 100644 --- a/crates/fj-core/src/validation/checks/mod.rs +++ b/crates/fj-core/src/validation/checks/mod.rs @@ -17,5 +17,5 @@ pub use self::{ face_winding::InteriorCycleHasInvalidWinding, half_edge_connection::AdjacentHalfEdgesNotConnected, half_edge_has_no_sibling::HalfEdgeHasNoSibling, - multiple_references::{MultipleReferencesToObject, ReferenceCounter}, + multiple_references::MultipleReferencesToObject, }; diff --git a/crates/fj-core/src/validation/checks/multiple_references.rs b/crates/fj-core/src/validation/checks/multiple_references.rs index 8cef7ec61..0a6365ec2 100644 --- a/crates/fj-core/src/validation/checks/multiple_references.rs +++ b/crates/fj-core/src/validation/checks/multiple_references.rs @@ -151,17 +151,9 @@ impl ValidationCheck for MultipleReferencesToObject { } } -// 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 -// infrastructure. -#[allow(missing_docs)] #[derive(Default)] -pub struct ReferenceCounter(HashMap, Vec>>); +struct ReferenceCounter(HashMap, Vec>>); -// 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 -// infrastructure. -#[allow(missing_docs)] impl ReferenceCounter { pub fn new() -> Self { Self(HashMap::new())