Skip to content

Commit

Permalink
Merge pull request #2231 from hannobraun/validation
Browse files Browse the repository at this point in the history
Unify `validate` and `validate_with_config`
  • Loading branch information
hannobraun authored Feb 22, 2024
2 parents 813dd89 + 0db6c04 commit 666451c
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 51 deletions.
2 changes: 1 addition & 1 deletion crates/fj-core/src/layers/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl Command<Validation> for InsertObject {
let mut errors = Vec::new();

let object: AnyObject<Stored> = self.object.into();
object.validate_with_config(&state.config, &mut errors);
object.validate(&state.config, &mut errors);

for err in errors {
events.push(ValidationFailed {
Expand Down
13 changes: 2 additions & 11 deletions crates/fj-core/src/objects/any_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,14 @@ macro_rules! any_object {
}
}

/// Validate the object
pub fn validate(&self, errors: &mut Vec<ValidationError>) {
match self {
$(
Self::$ty(object) => object.validate(errors),
)*
}
}

/// Validate the object with a pre-defined validation configuration
pub fn validate_with_config(&self,
pub fn validate(&self,
config: &ValidationConfig,
errors: &mut Vec<ValidationError>
) {
match self {
$(
Self::$ty(object) => object.validate_with_config(config, errors),
Self::$ty(object) => object.validate(config, errors),
)*
}
}
Expand Down
7 changes: 1 addition & 6 deletions crates/fj-core/src/validate/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,5 @@ use crate::{
use super::Validate;

impl Validate for Curve {
fn validate_with_config(
&self,
_: &ValidationConfig,
_: &mut Vec<ValidationError>,
) {
}
fn validate(&self, _: &ValidationConfig, _: &mut Vec<ValidationError>) {}
}
2 changes: 1 addition & 1 deletion crates/fj-core/src/validate/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ValidationError>,
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-core/src/validate/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ValidationError>,
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-core/src/validate/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
use super::Validate;

impl Validate for Face {
fn validate_with_config(
fn validate(
&self,
_: &ValidationConfig,
errors: &mut Vec<ValidationError>,
Expand Down
16 changes: 7 additions & 9 deletions crates/fj-core/src/validate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
&$crate::validation::ValidationConfig::default(),
&mut errors,
);
errors.iter().any(|e| matches!(e, $p))
})
};
Expand All @@ -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(&ValidationConfig::default(), &mut errors);

if let Some(err) = errors.into_iter().next() {
return Err(err);
Expand All @@ -111,13 +114,8 @@ pub trait Validate: Sized {
Ok(())
}

/// Validate the object using default configuration
fn validate(&self, errors: &mut Vec<ValidationError>) {
self.validate_with_config(&ValidationConfig::default(), errors)
}

/// Validate the object
fn validate_with_config(
fn validate(
&self,
config: &ValidationConfig,
errors: &mut Vec<ValidationError>,
Expand Down
7 changes: 1 addition & 6 deletions crates/fj-core/src/validate/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ValidationError>,
) {
}
fn validate(&self, _: &ValidationConfig, _: &mut Vec<ValidationError>) {}
}
2 changes: 1 addition & 1 deletion crates/fj-core/src/validate/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ValidationError>,
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-core/src/validate/sketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use super::{
};

impl Validate for Sketch {
fn validate_with_config(
fn validate(
&self,
config: &ValidationConfig,
errors: &mut Vec<ValidationError>,
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-core/src/validate/solid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use super::{
};

impl Validate for Solid {
fn validate_with_config(
fn validate(
&self,
config: &ValidationConfig,
errors: &mut Vec<ValidationError>,
Expand Down
7 changes: 1 addition & 6 deletions crates/fj-core/src/validate/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ValidationError>,
) {
}
fn validate(&self, _: &ValidationConfig, _: &mut Vec<ValidationError>) {}
}
7 changes: 1 addition & 6 deletions crates/fj-core/src/validate/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ValidationError>,
) {
}
fn validate(&self, _: &ValidationConfig, _: &mut Vec<ValidationError>) {}
}

0 comments on commit 666451c

Please sign in to comment.