From 7987e272a0df6f1d31aab7c1fadeba8b6e248245 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 27 Oct 2022 09:46:38 +0200 Subject: [PATCH 1/4] Remove unused code --- crates/fj-kernel/src/validate/coherence.rs | 37 +--------------------- 1 file changed, 1 insertion(+), 36 deletions(-) diff --git a/crates/fj-kernel/src/validate/coherence.rs b/crates/fj-kernel/src/validate/coherence.rs index 46d4655f1..dc7842d4b 100644 --- a/crates/fj-kernel/src/validate/coherence.rs +++ b/crates/fj-kernel/src/validate/coherence.rs @@ -2,7 +2,7 @@ use std::fmt; use fj_math::{Point, Scalar}; -use crate::objects::{Curve, Vertex}; +use crate::objects::Vertex; pub fn validate_vertex( vertex: &Vertex, @@ -38,46 +38,11 @@ pub fn validate_vertex( #[allow(clippy::large_enum_variant)] #[derive(Debug, thiserror::Error)] pub enum CoherenceIssues { - /// Mismatch between the surface and global forms of a curve - #[error("Mismatch between surface and global forms of curve")] - Curve(#[from] CurveCoherenceMismatch), - /// Mismatch between the local and global coordinates of a vertex #[error("Mismatch between local and global coordinates of vertex")] Vertex(#[from] VertexCoherenceMismatch), } -/// A mismatch between the surface and global forms of a curve -/// -/// Used in [`CoherenceIssues`]. -#[derive(Debug, thiserror::Error)] -pub struct CurveCoherenceMismatch { - /// The curve coordinate for which a mismatch was found - pub point_curve: Point<1>, - - /// The curve coordinate, converted to surface coordinates - pub point_surface: Point<2>, - - /// The surface coordinates, converted to global coordinates - pub point_surface_as_global: Point<3>, - - /// The curve coordinate, converted to global coordinates - pub point_global: Point<3>, - - /// The incoherent curve - pub curve: Curve, -} - -impl fmt::Display for CurveCoherenceMismatch { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!( - f, - "local: {:?} (converted to surface: {:?}; to global: {:?}), global: {:?},", - self.point_curve, self.point_surface, self.point_surface_as_global, self.point_global, - ) - } -} - /// A mismatch between the local and global forms of a vertex /// /// Used in [`CoherenceIssues`]. From 99513c80c19ccf5e220263041bdd4f8ba088897d Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 27 Oct 2022 10:52:02 +0200 Subject: [PATCH 2/4] Convert from `Infallible` to `ValidationError` --- crates/fj-kernel/src/validate/mod.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/validate/mod.rs b/crates/fj-kernel/src/validate/mod.rs index 3ac3ff8ed..f68f8587a 100644 --- a/crates/fj-kernel/src/validate/mod.rs +++ b/crates/fj-kernel/src/validate/mod.rs @@ -31,7 +31,7 @@ pub use self::{ uniqueness::UniquenessIssues, }; -use std::{collections::HashSet, ops::Deref}; +use std::{collections::HashSet, convert::Infallible, ops::Deref}; use fj_math::Scalar; @@ -187,6 +187,12 @@ pub enum ValidationError { Uniqueness(#[from] UniquenessIssues), } +impl From for ValidationError { + fn from(infallible: Infallible) -> Self { + match infallible {} + } +} + #[cfg(test)] mod tests { use fj_interop::ext::ArrayExt; From fac62678f401d7c3551c825b2c1d6b9daabdac74 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 27 Oct 2022 10:53:13 +0200 Subject: [PATCH 3/4] Add custom error type to `Validate2` --- crates/fj-kernel/src/validate/curve.rs | 12 +++++++++--- crates/fj-kernel/src/validate/cycle.rs | 8 ++++++-- crates/fj-kernel/src/validate/edge.rs | 12 +++++++++--- crates/fj-kernel/src/validate/face.rs | 8 ++++++-- crates/fj-kernel/src/validate/mod.rs | 7 +++++-- crates/fj-kernel/src/validate/shell.rs | 8 ++++++-- crates/fj-kernel/src/validate/sketch.rs | 8 ++++++-- crates/fj-kernel/src/validate/solid.rs | 8 ++++++-- crates/fj-kernel/src/validate/surface.rs | 8 ++++++-- crates/fj-kernel/src/validate/vertex.rs | 16 ++++++++++++---- 10 files changed, 71 insertions(+), 24 deletions(-) diff --git a/crates/fj-kernel/src/validate/curve.rs b/crates/fj-kernel/src/validate/curve.rs index 92ffe11fe..4d1f64561 100644 --- a/crates/fj-kernel/src/validate/curve.rs +++ b/crates/fj-kernel/src/validate/curve.rs @@ -1,26 +1,32 @@ +use std::convert::Infallible; + use crate::{ objects::{Curve, GlobalCurve}, storage::Store, }; -use super::{Validate2, ValidationConfig, ValidationError}; +use super::{Validate2, ValidationConfig}; impl Validate2 for Curve { + type Error = Infallible; + fn validate_with_config( &self, _: &Store, _: &ValidationConfig, - ) -> Result<(), ValidationError> { + ) -> Result<(), Self::Error> { Ok(()) } } impl Validate2 for GlobalCurve { + type Error = Infallible; + fn validate_with_config( &self, _: &Store, _: &ValidationConfig, - ) -> Result<(), ValidationError> { + ) -> Result<(), Self::Error> { Ok(()) } } diff --git a/crates/fj-kernel/src/validate/cycle.rs b/crates/fj-kernel/src/validate/cycle.rs index 4405691ac..e23552128 100644 --- a/crates/fj-kernel/src/validate/cycle.rs +++ b/crates/fj-kernel/src/validate/cycle.rs @@ -1,13 +1,17 @@ +use std::convert::Infallible; + use crate::{objects::Cycle, storage::Store}; -use super::{Validate2, ValidationConfig, ValidationError}; +use super::{Validate2, ValidationConfig}; impl Validate2 for Cycle { + type Error = Infallible; + fn validate_with_config( &self, _: &Store, _: &ValidationConfig, - ) -> Result<(), ValidationError> { + ) -> Result<(), Self::Error> { Ok(()) } } diff --git a/crates/fj-kernel/src/validate/edge.rs b/crates/fj-kernel/src/validate/edge.rs index 22bf099c4..525a52100 100644 --- a/crates/fj-kernel/src/validate/edge.rs +++ b/crates/fj-kernel/src/validate/edge.rs @@ -1,26 +1,32 @@ +use std::convert::Infallible; + use crate::{ objects::{GlobalEdge, HalfEdge}, storage::Store, }; -use super::{Validate2, ValidationConfig, ValidationError}; +use super::{Validate2, ValidationConfig}; impl Validate2 for HalfEdge { + type Error = Infallible; + fn validate_with_config( &self, _: &Store, _: &ValidationConfig, - ) -> Result<(), ValidationError> { + ) -> Result<(), Self::Error> { Ok(()) } } impl Validate2 for GlobalEdge { + type Error = Infallible; + fn validate_with_config( &self, _: &Store, _: &ValidationConfig, - ) -> Result<(), ValidationError> { + ) -> Result<(), Self::Error> { Ok(()) } } diff --git a/crates/fj-kernel/src/validate/face.rs b/crates/fj-kernel/src/validate/face.rs index dd274ead8..9b5277014 100644 --- a/crates/fj-kernel/src/validate/face.rs +++ b/crates/fj-kernel/src/validate/face.rs @@ -1,13 +1,17 @@ +use std::convert::Infallible; + use crate::{objects::Face, storage::Store}; -use super::{Validate2, ValidationConfig, ValidationError}; +use super::{Validate2, ValidationConfig}; impl Validate2 for Face { + type Error = Infallible; + fn validate_with_config( &self, _: &Store, _: &ValidationConfig, - ) -> Result<(), ValidationError> { + ) -> Result<(), Self::Error> { Ok(()) } } diff --git a/crates/fj-kernel/src/validate/mod.rs b/crates/fj-kernel/src/validate/mod.rs index f68f8587a..ee9ef62b3 100644 --- a/crates/fj-kernel/src/validate/mod.rs +++ b/crates/fj-kernel/src/validate/mod.rs @@ -104,8 +104,11 @@ where /// Validate an object pub trait Validate2: Sized { + /// The error that validation of the implementing type can result in + type Error: Into; + /// Validate the object using default configuration - fn validate(&self, store: &Store) -> Result<(), ValidationError> { + fn validate(&self, store: &Store) -> Result<(), Self::Error> { self.validate_with_config(store, &ValidationConfig::default()) } @@ -114,7 +117,7 @@ pub trait Validate2: Sized { &self, store: &Store, config: &ValidationConfig, - ) -> Result<(), ValidationError>; + ) -> Result<(), Self::Error>; } /// Configuration required for the validation process diff --git a/crates/fj-kernel/src/validate/shell.rs b/crates/fj-kernel/src/validate/shell.rs index 7a6ca5ab2..212e28d84 100644 --- a/crates/fj-kernel/src/validate/shell.rs +++ b/crates/fj-kernel/src/validate/shell.rs @@ -1,13 +1,17 @@ +use std::convert::Infallible; + use crate::{objects::Shell, storage::Store}; -use super::{Validate2, ValidationConfig, ValidationError}; +use super::{Validate2, ValidationConfig}; impl Validate2 for Shell { + type Error = Infallible; + fn validate_with_config( &self, _: &Store, _: &ValidationConfig, - ) -> Result<(), ValidationError> { + ) -> Result<(), Self::Error> { Ok(()) } } diff --git a/crates/fj-kernel/src/validate/sketch.rs b/crates/fj-kernel/src/validate/sketch.rs index 5d242baf3..a7ad9be1c 100644 --- a/crates/fj-kernel/src/validate/sketch.rs +++ b/crates/fj-kernel/src/validate/sketch.rs @@ -1,13 +1,17 @@ +use std::convert::Infallible; + use crate::{objects::Sketch, storage::Store}; -use super::{Validate2, ValidationConfig, ValidationError}; +use super::{Validate2, ValidationConfig}; impl Validate2 for Sketch { + type Error = Infallible; + fn validate_with_config( &self, _: &Store, _: &ValidationConfig, - ) -> Result<(), ValidationError> { + ) -> Result<(), Self::Error> { Ok(()) } } diff --git a/crates/fj-kernel/src/validate/solid.rs b/crates/fj-kernel/src/validate/solid.rs index 23a200eba..44631899d 100644 --- a/crates/fj-kernel/src/validate/solid.rs +++ b/crates/fj-kernel/src/validate/solid.rs @@ -1,13 +1,17 @@ +use std::convert::Infallible; + use crate::{objects::Solid, storage::Store}; -use super::{Validate2, ValidationConfig, ValidationError}; +use super::{Validate2, ValidationConfig}; impl Validate2 for Solid { + type Error = Infallible; + fn validate_with_config( &self, _: &Store, _: &ValidationConfig, - ) -> Result<(), ValidationError> { + ) -> Result<(), Self::Error> { Ok(()) } } diff --git a/crates/fj-kernel/src/validate/surface.rs b/crates/fj-kernel/src/validate/surface.rs index 799b86559..2e22ebd4b 100644 --- a/crates/fj-kernel/src/validate/surface.rs +++ b/crates/fj-kernel/src/validate/surface.rs @@ -1,13 +1,17 @@ +use std::convert::Infallible; + use crate::{objects::Surface, storage::Store}; -use super::{Validate2, ValidationConfig, ValidationError}; +use super::{Validate2, ValidationConfig}; impl Validate2 for Surface { + type Error = Infallible; + fn validate_with_config( &self, _: &Store, _: &ValidationConfig, - ) -> Result<(), ValidationError> { + ) -> Result<(), Self::Error> { Ok(()) } } diff --git a/crates/fj-kernel/src/validate/vertex.rs b/crates/fj-kernel/src/validate/vertex.rs index 0a39555e6..56ac1d7b2 100644 --- a/crates/fj-kernel/src/validate/vertex.rs +++ b/crates/fj-kernel/src/validate/vertex.rs @@ -1,36 +1,44 @@ +use std::convert::Infallible; + use crate::{ objects::{GlobalVertex, SurfaceVertex, Vertex}, storage::Store, }; -use super::{Validate2, ValidationConfig, ValidationError}; +use super::{Validate2, ValidationConfig}; impl Validate2 for Vertex { + type Error = Infallible; + fn validate_with_config( &self, _: &Store, _: &ValidationConfig, - ) -> Result<(), ValidationError> { + ) -> Result<(), Self::Error> { Ok(()) } } impl Validate2 for SurfaceVertex { + type Error = Infallible; + fn validate_with_config( &self, _: &Store, _: &ValidationConfig, - ) -> Result<(), ValidationError> { + ) -> Result<(), Self::Error> { Ok(()) } } impl Validate2 for GlobalVertex { + type Error = Infallible; + fn validate_with_config( &self, _: &Store, _: &ValidationConfig, - ) -> Result<(), ValidationError> { + ) -> Result<(), Self::Error> { Ok(()) } } From a133cd928dabd94ad90748f4f76555b98bd9cd55 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 27 Oct 2022 11:54:54 +0200 Subject: [PATCH 4/4] Remove unused argument from `Validate2` methods Contrary to my initial assumptions, I don't think I'm going to need access to the store. --- crates/fj-kernel/src/validate/curve.rs | 7 +------ crates/fj-kernel/src/validate/cycle.rs | 3 +-- crates/fj-kernel/src/validate/edge.rs | 7 +------ crates/fj-kernel/src/validate/face.rs | 3 +-- crates/fj-kernel/src/validate/mod.rs | 7 +++---- crates/fj-kernel/src/validate/shell.rs | 3 +-- crates/fj-kernel/src/validate/sketch.rs | 3 +-- crates/fj-kernel/src/validate/solid.rs | 3 +-- crates/fj-kernel/src/validate/surface.rs | 3 +-- crates/fj-kernel/src/validate/vertex.rs | 8 +------- 10 files changed, 12 insertions(+), 35 deletions(-) diff --git a/crates/fj-kernel/src/validate/curve.rs b/crates/fj-kernel/src/validate/curve.rs index 4d1f64561..95e680f8f 100644 --- a/crates/fj-kernel/src/validate/curve.rs +++ b/crates/fj-kernel/src/validate/curve.rs @@ -1,9 +1,6 @@ use std::convert::Infallible; -use crate::{ - objects::{Curve, GlobalCurve}, - storage::Store, -}; +use crate::objects::{Curve, GlobalCurve}; use super::{Validate2, ValidationConfig}; @@ -12,7 +9,6 @@ impl Validate2 for Curve { fn validate_with_config( &self, - _: &Store, _: &ValidationConfig, ) -> Result<(), Self::Error> { Ok(()) @@ -24,7 +20,6 @@ impl Validate2 for GlobalCurve { fn validate_with_config( &self, - _: &Store, _: &ValidationConfig, ) -> Result<(), Self::Error> { Ok(()) diff --git a/crates/fj-kernel/src/validate/cycle.rs b/crates/fj-kernel/src/validate/cycle.rs index e23552128..57eb8b348 100644 --- a/crates/fj-kernel/src/validate/cycle.rs +++ b/crates/fj-kernel/src/validate/cycle.rs @@ -1,6 +1,6 @@ use std::convert::Infallible; -use crate::{objects::Cycle, storage::Store}; +use crate::objects::Cycle; use super::{Validate2, ValidationConfig}; @@ -9,7 +9,6 @@ impl Validate2 for Cycle { fn validate_with_config( &self, - _: &Store, _: &ValidationConfig, ) -> Result<(), Self::Error> { Ok(()) diff --git a/crates/fj-kernel/src/validate/edge.rs b/crates/fj-kernel/src/validate/edge.rs index 525a52100..5e4153f44 100644 --- a/crates/fj-kernel/src/validate/edge.rs +++ b/crates/fj-kernel/src/validate/edge.rs @@ -1,9 +1,6 @@ use std::convert::Infallible; -use crate::{ - objects::{GlobalEdge, HalfEdge}, - storage::Store, -}; +use crate::objects::{GlobalEdge, HalfEdge}; use super::{Validate2, ValidationConfig}; @@ -12,7 +9,6 @@ impl Validate2 for HalfEdge { fn validate_with_config( &self, - _: &Store, _: &ValidationConfig, ) -> Result<(), Self::Error> { Ok(()) @@ -24,7 +20,6 @@ impl Validate2 for GlobalEdge { fn validate_with_config( &self, - _: &Store, _: &ValidationConfig, ) -> Result<(), Self::Error> { Ok(()) diff --git a/crates/fj-kernel/src/validate/face.rs b/crates/fj-kernel/src/validate/face.rs index 9b5277014..934695e19 100644 --- a/crates/fj-kernel/src/validate/face.rs +++ b/crates/fj-kernel/src/validate/face.rs @@ -1,6 +1,6 @@ use std::convert::Infallible; -use crate::{objects::Face, storage::Store}; +use crate::objects::Face; use super::{Validate2, ValidationConfig}; @@ -9,7 +9,6 @@ impl Validate2 for Face { fn validate_with_config( &self, - _: &Store, _: &ValidationConfig, ) -> Result<(), Self::Error> { Ok(()) diff --git a/crates/fj-kernel/src/validate/mod.rs b/crates/fj-kernel/src/validate/mod.rs index ee9ef62b3..ba29f0611 100644 --- a/crates/fj-kernel/src/validate/mod.rs +++ b/crates/fj-kernel/src/validate/mod.rs @@ -35,7 +35,7 @@ use std::{collections::HashSet, convert::Infallible, ops::Deref}; use fj_math::Scalar; -use crate::{iter::ObjectIters, storage::Store}; +use crate::iter::ObjectIters; /// Validate an object pub trait Validate: Sized { @@ -108,14 +108,13 @@ pub trait Validate2: Sized { type Error: Into; /// Validate the object using default configuration - fn validate(&self, store: &Store) -> Result<(), Self::Error> { - self.validate_with_config(store, &ValidationConfig::default()) + fn validate(&self) -> Result<(), Self::Error> { + self.validate_with_config(&ValidationConfig::default()) } /// Validate the object fn validate_with_config( &self, - store: &Store, config: &ValidationConfig, ) -> Result<(), Self::Error>; } diff --git a/crates/fj-kernel/src/validate/shell.rs b/crates/fj-kernel/src/validate/shell.rs index 212e28d84..e8a9756e6 100644 --- a/crates/fj-kernel/src/validate/shell.rs +++ b/crates/fj-kernel/src/validate/shell.rs @@ -1,6 +1,6 @@ use std::convert::Infallible; -use crate::{objects::Shell, storage::Store}; +use crate::objects::Shell; use super::{Validate2, ValidationConfig}; @@ -9,7 +9,6 @@ impl Validate2 for Shell { fn validate_with_config( &self, - _: &Store, _: &ValidationConfig, ) -> Result<(), Self::Error> { Ok(()) diff --git a/crates/fj-kernel/src/validate/sketch.rs b/crates/fj-kernel/src/validate/sketch.rs index a7ad9be1c..7b9ebc8d8 100644 --- a/crates/fj-kernel/src/validate/sketch.rs +++ b/crates/fj-kernel/src/validate/sketch.rs @@ -1,6 +1,6 @@ use std::convert::Infallible; -use crate::{objects::Sketch, storage::Store}; +use crate::objects::Sketch; use super::{Validate2, ValidationConfig}; @@ -9,7 +9,6 @@ impl Validate2 for Sketch { fn validate_with_config( &self, - _: &Store, _: &ValidationConfig, ) -> Result<(), Self::Error> { Ok(()) diff --git a/crates/fj-kernel/src/validate/solid.rs b/crates/fj-kernel/src/validate/solid.rs index 44631899d..b75954be2 100644 --- a/crates/fj-kernel/src/validate/solid.rs +++ b/crates/fj-kernel/src/validate/solid.rs @@ -1,6 +1,6 @@ use std::convert::Infallible; -use crate::{objects::Solid, storage::Store}; +use crate::objects::Solid; use super::{Validate2, ValidationConfig}; @@ -9,7 +9,6 @@ impl Validate2 for Solid { fn validate_with_config( &self, - _: &Store, _: &ValidationConfig, ) -> Result<(), Self::Error> { Ok(()) diff --git a/crates/fj-kernel/src/validate/surface.rs b/crates/fj-kernel/src/validate/surface.rs index 2e22ebd4b..219bb8404 100644 --- a/crates/fj-kernel/src/validate/surface.rs +++ b/crates/fj-kernel/src/validate/surface.rs @@ -1,6 +1,6 @@ use std::convert::Infallible; -use crate::{objects::Surface, storage::Store}; +use crate::objects::Surface; use super::{Validate2, ValidationConfig}; @@ -9,7 +9,6 @@ impl Validate2 for Surface { fn validate_with_config( &self, - _: &Store, _: &ValidationConfig, ) -> Result<(), Self::Error> { Ok(()) diff --git a/crates/fj-kernel/src/validate/vertex.rs b/crates/fj-kernel/src/validate/vertex.rs index 56ac1d7b2..3058f447f 100644 --- a/crates/fj-kernel/src/validate/vertex.rs +++ b/crates/fj-kernel/src/validate/vertex.rs @@ -1,9 +1,6 @@ use std::convert::Infallible; -use crate::{ - objects::{GlobalVertex, SurfaceVertex, Vertex}, - storage::Store, -}; +use crate::objects::{GlobalVertex, SurfaceVertex, Vertex}; use super::{Validate2, ValidationConfig}; @@ -12,7 +9,6 @@ impl Validate2 for Vertex { fn validate_with_config( &self, - _: &Store, _: &ValidationConfig, ) -> Result<(), Self::Error> { Ok(()) @@ -24,7 +20,6 @@ impl Validate2 for SurfaceVertex { fn validate_with_config( &self, - _: &Store, _: &ValidationConfig, ) -> Result<(), Self::Error> { Ok(()) @@ -36,7 +31,6 @@ impl Validate2 for GlobalVertex { fn validate_with_config( &self, - _: &Store, _: &ValidationConfig, ) -> Result<(), Self::Error> { Ok(())