diff --git a/crates/fj-kernel/src/validate/mod.rs b/crates/fj-kernel/src/validate/mod.rs index f1a290243..953c5a43d 100644 --- a/crates/fj-kernel/src/validate/mod.rs +++ b/crates/fj-kernel/src/validate/mod.rs @@ -22,18 +22,16 @@ mod shell; mod sketch; mod solid; mod surface; -mod uniqueness; mod vertex; pub use self::{ cycle::CycleValidationError, edge::HalfEdgeValidationError, face::FaceValidationError, - uniqueness::UniquenessIssues, vertex::{SurfaceVertexValidationError, VertexValidationError}, }; -use std::{collections::HashSet, convert::Infallible, ops::Deref}; +use std::{convert::Infallible, ops::Deref}; use fj_math::Scalar; @@ -83,20 +81,8 @@ where { fn validate_with_config( self, - config: &ValidationConfig, + _: &ValidationConfig, ) -> Result, ValidationError> { - let mut global_vertices = HashSet::new(); - - for global_vertex in self.global_vertex_iter() { - uniqueness::validate_vertex( - global_vertex, - &global_vertices, - config.distinct_min_distance, - )?; - - global_vertices.insert(*global_vertex); - } - Ok(Validated(self)) } } @@ -175,10 +161,6 @@ impl Deref for Validated { #[allow(clippy::large_enum_variant)] #[derive(Debug, thiserror::Error)] pub enum ValidationError { - /// Uniqueness validation failed - #[error("Uniqueness validation failed")] - Uniqueness(#[from] UniquenessIssues), - /// `Cycle` validation error #[error(transparent)] Cycle(#[from] CycleValidationError), @@ -205,50 +187,3 @@ impl From for ValidationError { match infallible {} } } - -#[cfg(test)] -mod tests { - use fj_math::{Point, Scalar}; - - use crate::{ - objects::{GlobalVertex, Objects}, - validate::{Validate, ValidationConfig, ValidationError}, - }; - - #[test] - fn uniqueness_vertex() -> anyhow::Result<()> { - let objects = Objects::new(); - let mut shape = Vec::new(); - - let deviation = Scalar::from_f64(0.25); - - let a = Point::from([0., 0., 0.]); - - let mut b = a; - b.x += deviation; - - let config = ValidationConfig { - distinct_min_distance: deviation * 2., - ..ValidationConfig::default() - }; - - // Adding a vertex should work. - shape.push( - objects - .global_vertices - .insert(GlobalVertex::from_position(a)), - ); - shape.clone().validate_with_config(&config)?; - - // Adding a second vertex that is considered identical should fail. - shape.push( - objects - .global_vertices - .insert(GlobalVertex::from_position(b)), - ); - let result = shape.validate_with_config(&config); - assert!(matches!(result, Err(ValidationError::Uniqueness(_)))); - - Ok(()) - } -} diff --git a/crates/fj-kernel/src/validate/uniqueness.rs b/crates/fj-kernel/src/validate/uniqueness.rs deleted file mode 100644 index 516740d81..000000000 --- a/crates/fj-kernel/src/validate/uniqueness.rs +++ /dev/null @@ -1,51 +0,0 @@ -use std::{collections::HashSet, fmt}; - -use fj_math::Scalar; - -use crate::objects::GlobalVertex; - -pub fn validate_vertex( - vertex: &GlobalVertex, - vertices: &HashSet, - min_distance: Scalar, -) -> Result<(), UniquenessIssues> { - for existing in vertices { - if (existing.position() - vertex.position()).magnitude() < min_distance - { - return Err(UniquenessIssues { - duplicate_vertex: Some(*existing), - }); - } - } - - Ok(()) -} - -/// Uniqueness issues found during validation -/// -/// Used by [`ValidationError`]. -/// -/// # Implementation Note -/// -/// This struct doesn't carry any actual information, currently. Information -/// about the specific uniqueness issues found can be added as required. For -/// now, this struct exists to ease the error handling code. -/// -/// [`ValidationError`]: super::ValidationError -#[derive(Debug, Default, thiserror::Error)] -pub struct UniquenessIssues { - /// Duplicate vertex found - pub duplicate_vertex: Option, -} - -impl fmt::Display for UniquenessIssues { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - writeln!(f, "Uniqueness issues found:")?; - - if let Some(duplicate_vertex) = &self.duplicate_vertex { - writeln!(f, "- Duplicate vertex ({:?}", duplicate_vertex)?; - } - - Ok(()) - } -}