From b24a955c0551bc66c46471148861f7f6806a69a7 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Feb 2024 13:50:49 +0100 Subject: [PATCH 1/4] Remove unused method --- crates/fj-core/src/objects/any_object.rs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/crates/fj-core/src/objects/any_object.rs b/crates/fj-core/src/objects/any_object.rs index ad2bd769e..bea44e0a3 100644 --- a/crates/fj-core/src/objects/any_object.rs +++ b/crates/fj-core/src/objects/any_object.rs @@ -34,15 +34,6 @@ macro_rules! any_object { } } - /// Validate the object - pub fn validate(&self, errors: &mut Vec) { - match self { - $( - Self::$ty(object) => object.validate(errors), - )* - } - } - /// Validate the object with a pre-defined validation configuration pub fn validate_with_config(&self, config: &ValidationConfig, From 0786e7ed89188004d4872eeb53e82c53bed3414b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Feb 2024 13:52:49 +0100 Subject: [PATCH 2/4] Inline redundant trait method It isn't used in a lot of places and doesn't quite carry its own weight. --- crates/fj-core/src/validate/mod.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/crates/fj-core/src/validate/mod.rs b/crates/fj-core/src/validate/mod.rs index 02841dd0b..cd8c50044 100644 --- a/crates/fj-core/src/validate/mod.rs +++ b/crates/fj-core/src/validate/mod.rs @@ -88,7 +88,10 @@ macro_rules! assert_contains_err { ($o:tt,$p:pat) => { assert!({ let mut errors = Vec::new(); - $o.validate(&mut errors); + $o.validate_with_config( + &$crate::validation::ValidationConfig::default(), + &mut errors, + ); errors.iter().any(|e| matches!(e, $p)) }) }; @@ -102,7 +105,7 @@ pub trait Validate: Sized { #[allow(clippy::result_large_err)] fn validate_and_return_first_error(&self) -> Result<(), ValidationError> { let mut errors = Vec::new(); - self.validate(&mut errors); + self.validate_with_config(&ValidationConfig::default(), &mut errors); if let Some(err) = errors.into_iter().next() { return Err(err); @@ -111,11 +114,6 @@ pub trait Validate: Sized { Ok(()) } - /// Validate the object using default configuration - fn validate(&self, errors: &mut Vec) { - self.validate_with_config(&ValidationConfig::default(), errors) - } - /// Validate the object fn validate_with_config( &self, From 55e14d375d7bdf6dc2e19d6a0fe1e29f0f64fb9b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Feb 2024 13:54:14 +0100 Subject: [PATCH 3/4] Simplify trait method name --- crates/fj-core/src/objects/any_object.rs | 2 +- crates/fj-core/src/validate/curve.rs | 7 +------ crates/fj-core/src/validate/cycle.rs | 2 +- crates/fj-core/src/validate/edge.rs | 2 +- crates/fj-core/src/validate/face.rs | 2 +- crates/fj-core/src/validate/mod.rs | 8 ++++---- crates/fj-core/src/validate/region.rs | 7 +------ crates/fj-core/src/validate/shell.rs | 2 +- crates/fj-core/src/validate/sketch.rs | 2 +- crates/fj-core/src/validate/solid.rs | 2 +- crates/fj-core/src/validate/surface.rs | 7 +------ crates/fj-core/src/validate/vertex.rs | 7 +------ 12 files changed, 15 insertions(+), 35 deletions(-) diff --git a/crates/fj-core/src/objects/any_object.rs b/crates/fj-core/src/objects/any_object.rs index bea44e0a3..f4b3a5555 100644 --- a/crates/fj-core/src/objects/any_object.rs +++ b/crates/fj-core/src/objects/any_object.rs @@ -41,7 +41,7 @@ macro_rules! any_object { ) { match self { $( - Self::$ty(object) => object.validate_with_config(config, errors), + Self::$ty(object) => object.validate(config, errors), )* } } diff --git a/crates/fj-core/src/validate/curve.rs b/crates/fj-core/src/validate/curve.rs index e5ce4147c..19b910d8d 100644 --- a/crates/fj-core/src/validate/curve.rs +++ b/crates/fj-core/src/validate/curve.rs @@ -6,10 +6,5 @@ use crate::{ use super::Validate; impl Validate for Curve { - fn validate_with_config( - &self, - _: &ValidationConfig, - _: &mut Vec, - ) { - } + fn validate(&self, _: &ValidationConfig, _: &mut Vec) {} } diff --git a/crates/fj-core/src/validate/cycle.rs b/crates/fj-core/src/validate/cycle.rs index e4e924fca..035d46781 100644 --- a/crates/fj-core/src/validate/cycle.rs +++ b/crates/fj-core/src/validate/cycle.rs @@ -9,7 +9,7 @@ use crate::{ use super::Validate; impl Validate for Cycle { - fn validate_with_config( + fn validate( &self, config: &ValidationConfig, errors: &mut Vec, diff --git a/crates/fj-core/src/validate/edge.rs b/crates/fj-core/src/validate/edge.rs index ff6a925e5..6f1e598b0 100644 --- a/crates/fj-core/src/validate/edge.rs +++ b/crates/fj-core/src/validate/edge.rs @@ -8,7 +8,7 @@ use crate::{ use super::Validate; impl Validate for HalfEdge { - fn validate_with_config( + fn validate( &self, config: &ValidationConfig, errors: &mut Vec, diff --git a/crates/fj-core/src/validate/face.rs b/crates/fj-core/src/validate/face.rs index 4df3ce2ed..94ded4be0 100644 --- a/crates/fj-core/src/validate/face.rs +++ b/crates/fj-core/src/validate/face.rs @@ -8,7 +8,7 @@ use crate::{ use super::Validate; impl Validate for Face { - fn validate_with_config( + fn validate( &self, _: &ValidationConfig, errors: &mut Vec, diff --git a/crates/fj-core/src/validate/mod.rs b/crates/fj-core/src/validate/mod.rs index cd8c50044..295ca5224 100644 --- a/crates/fj-core/src/validate/mod.rs +++ b/crates/fj-core/src/validate/mod.rs @@ -49,7 +49,7 @@ //! that are very close together can be considered coincident. What should be //! considered "very close" is dependent on the scale that your model operates //! on, and this fact is taken into account by allowing for configuration via -//! [`Validate::validate_with_config`] and [`ValidationConfig`]. +//! [`Validate::validate`] and [`ValidationConfig`]. //! //! //! ## Implementation Note @@ -88,7 +88,7 @@ macro_rules! assert_contains_err { ($o:tt,$p:pat) => { assert!({ let mut errors = Vec::new(); - $o.validate_with_config( + $o.validate( &$crate::validation::ValidationConfig::default(), &mut errors, ); @@ -105,7 +105,7 @@ pub trait Validate: Sized { #[allow(clippy::result_large_err)] fn validate_and_return_first_error(&self) -> Result<(), ValidationError> { let mut errors = Vec::new(); - self.validate_with_config(&ValidationConfig::default(), &mut errors); + self.validate(&ValidationConfig::default(), &mut errors); if let Some(err) = errors.into_iter().next() { return Err(err); @@ -115,7 +115,7 @@ pub trait Validate: Sized { } /// Validate the object - fn validate_with_config( + fn validate( &self, config: &ValidationConfig, errors: &mut Vec, diff --git a/crates/fj-core/src/validate/region.rs b/crates/fj-core/src/validate/region.rs index 3cd0ae87b..d8b6bbf32 100644 --- a/crates/fj-core/src/validate/region.rs +++ b/crates/fj-core/src/validate/region.rs @@ -3,10 +3,5 @@ use crate::objects::Region; use super::{Validate, ValidationConfig, ValidationError}; impl Validate for Region { - fn validate_with_config( - &self, - _: &ValidationConfig, - _: &mut Vec, - ) { - } + fn validate(&self, _: &ValidationConfig, _: &mut Vec) {} } diff --git a/crates/fj-core/src/validate/shell.rs b/crates/fj-core/src/validate/shell.rs index 5dba7492c..b9b9b45f0 100644 --- a/crates/fj-core/src/validate/shell.rs +++ b/crates/fj-core/src/validate/shell.rs @@ -14,7 +14,7 @@ use crate::{ use super::{Validate, ValidationConfig, ValidationError}; impl Validate for Shell { - fn validate_with_config( + fn validate( &self, config: &ValidationConfig, errors: &mut Vec, diff --git a/crates/fj-core/src/validate/sketch.rs b/crates/fj-core/src/validate/sketch.rs index 7de935d23..425e6812c 100644 --- a/crates/fj-core/src/validate/sketch.rs +++ b/crates/fj-core/src/validate/sketch.rs @@ -6,7 +6,7 @@ use super::{ }; impl Validate for Sketch { - fn validate_with_config( + fn validate( &self, config: &ValidationConfig, errors: &mut Vec, diff --git a/crates/fj-core/src/validate/solid.rs b/crates/fj-core/src/validate/solid.rs index befa649eb..b0bf01d85 100644 --- a/crates/fj-core/src/validate/solid.rs +++ b/crates/fj-core/src/validate/solid.rs @@ -13,7 +13,7 @@ use super::{ }; impl Validate for Solid { - fn validate_with_config( + fn validate( &self, config: &ValidationConfig, errors: &mut Vec, diff --git a/crates/fj-core/src/validate/surface.rs b/crates/fj-core/src/validate/surface.rs index 4462f9147..4cb39c1be 100644 --- a/crates/fj-core/src/validate/surface.rs +++ b/crates/fj-core/src/validate/surface.rs @@ -3,10 +3,5 @@ use crate::objects::Surface; use super::{Validate, ValidationConfig, ValidationError}; impl Validate for Surface { - fn validate_with_config( - &self, - _: &ValidationConfig, - _: &mut Vec, - ) { - } + fn validate(&self, _: &ValidationConfig, _: &mut Vec) {} } diff --git a/crates/fj-core/src/validate/vertex.rs b/crates/fj-core/src/validate/vertex.rs index 029f79f1d..1e2e7e700 100644 --- a/crates/fj-core/src/validate/vertex.rs +++ b/crates/fj-core/src/validate/vertex.rs @@ -3,10 +3,5 @@ use crate::objects::Vertex; use super::{Validate, ValidationConfig, ValidationError}; impl Validate for Vertex { - fn validate_with_config( - &self, - _: &ValidationConfig, - _: &mut Vec, - ) { - } + fn validate(&self, _: &ValidationConfig, _: &mut Vec) {} } From 0db6c04957c40da54e0c0e6331ddc8d82cdbca40 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 22 Feb 2024 13:54:38 +0100 Subject: [PATCH 4/4] Simplify method name --- crates/fj-core/src/layers/validation.rs | 2 +- crates/fj-core/src/objects/any_object.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-core/src/layers/validation.rs b/crates/fj-core/src/layers/validation.rs index 52adb3aea..a3ac931d3 100644 --- a/crates/fj-core/src/layers/validation.rs +++ b/crates/fj-core/src/layers/validation.rs @@ -22,7 +22,7 @@ impl Command for InsertObject { let mut errors = Vec::new(); let object: AnyObject = self.object.into(); - object.validate_with_config(&state.config, &mut errors); + object.validate(&state.config, &mut errors); for err in errors { events.push(ValidationFailed { diff --git a/crates/fj-core/src/objects/any_object.rs b/crates/fj-core/src/objects/any_object.rs index f4b3a5555..6c047e2e2 100644 --- a/crates/fj-core/src/objects/any_object.rs +++ b/crates/fj-core/src/objects/any_object.rs @@ -35,7 +35,7 @@ macro_rules! any_object { } /// Validate the object with a pre-defined validation configuration - pub fn validate_with_config(&self, + pub fn validate(&self, config: &ValidationConfig, errors: &mut Vec ) {