Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refine new validation infrastructure #1283

Merged
merged 4 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 1 addition & 36 deletions crates/fj-kernel/src/validate/coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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`].
Expand Down
19 changes: 10 additions & 9 deletions crates/fj-kernel/src/validate/curve.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
use crate::{
objects::{Curve, GlobalCurve},
storage::Store,
};
use std::convert::Infallible;

use super::{Validate2, ValidationConfig, ValidationError};
use crate::objects::{Curve, GlobalCurve};

use super::{Validate2, ValidationConfig};

impl Validate2 for Curve {
type Error = Infallible;

fn validate_with_config(
&self,
_: &Store<Self>,
_: &ValidationConfig,
) -> Result<(), ValidationError> {
) -> Result<(), Self::Error> {
Ok(())
}
}

impl Validate2 for GlobalCurve {
type Error = Infallible;

fn validate_with_config(
&self,
_: &Store<Self>,
_: &ValidationConfig,
) -> Result<(), ValidationError> {
) -> Result<(), Self::Error> {
Ok(())
}
}
11 changes: 7 additions & 4 deletions crates/fj-kernel/src/validate/cycle.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use crate::{objects::Cycle, storage::Store};
use std::convert::Infallible;

use super::{Validate2, ValidationConfig, ValidationError};
use crate::objects::Cycle;

use super::{Validate2, ValidationConfig};

impl Validate2 for Cycle {
type Error = Infallible;

fn validate_with_config(
&self,
_: &Store<Self>,
_: &ValidationConfig,
) -> Result<(), ValidationError> {
) -> Result<(), Self::Error> {
Ok(())
}
}
19 changes: 10 additions & 9 deletions crates/fj-kernel/src/validate/edge.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
use crate::{
objects::{GlobalEdge, HalfEdge},
storage::Store,
};
use std::convert::Infallible;

use super::{Validate2, ValidationConfig, ValidationError};
use crate::objects::{GlobalEdge, HalfEdge};

use super::{Validate2, ValidationConfig};

impl Validate2 for HalfEdge {
type Error = Infallible;

fn validate_with_config(
&self,
_: &Store<Self>,
_: &ValidationConfig,
) -> Result<(), ValidationError> {
) -> Result<(), Self::Error> {
Ok(())
}
}

impl Validate2 for GlobalEdge {
type Error = Infallible;

fn validate_with_config(
&self,
_: &Store<Self>,
_: &ValidationConfig,
) -> Result<(), ValidationError> {
) -> Result<(), Self::Error> {
Ok(())
}
}
11 changes: 7 additions & 4 deletions crates/fj-kernel/src/validate/face.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use crate::{objects::Face, storage::Store};
use std::convert::Infallible;

use super::{Validate2, ValidationConfig, ValidationError};
use crate::objects::Face;

use super::{Validate2, ValidationConfig};

impl Validate2 for Face {
type Error = Infallible;

fn validate_with_config(
&self,
_: &Store<Self>,
_: &ValidationConfig,
) -> Result<(), ValidationError> {
) -> Result<(), Self::Error> {
Ok(())
}
}
20 changes: 14 additions & 6 deletions crates/fj-kernel/src/validate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ pub use self::{
uniqueness::UniquenessIssues,
};

use std::{collections::HashSet, ops::Deref};
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 {
Expand Down Expand Up @@ -104,17 +104,19 @@ where

/// Validate an object
pub trait Validate2: Sized {
/// The error that validation of the implementing type can result in
type Error: Into<ValidationError>;

/// Validate the object using default configuration
fn validate(&self, store: &Store<Self>) -> Result<(), ValidationError> {
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<Self>,
config: &ValidationConfig,
) -> Result<(), ValidationError>;
) -> Result<(), Self::Error>;
}

/// Configuration required for the validation process
Expand Down Expand Up @@ -187,6 +189,12 @@ pub enum ValidationError {
Uniqueness(#[from] UniquenessIssues),
}

impl From<Infallible> for ValidationError {
fn from(infallible: Infallible) -> Self {
match infallible {}
}
}

#[cfg(test)]
mod tests {
use fj_interop::ext::ArrayExt;
Expand Down
11 changes: 7 additions & 4 deletions crates/fj-kernel/src/validate/shell.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use crate::{objects::Shell, storage::Store};
use std::convert::Infallible;

use super::{Validate2, ValidationConfig, ValidationError};
use crate::objects::Shell;

use super::{Validate2, ValidationConfig};

impl Validate2 for Shell {
type Error = Infallible;

fn validate_with_config(
&self,
_: &Store<Self>,
_: &ValidationConfig,
) -> Result<(), ValidationError> {
) -> Result<(), Self::Error> {
Ok(())
}
}
11 changes: 7 additions & 4 deletions crates/fj-kernel/src/validate/sketch.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use crate::{objects::Sketch, storage::Store};
use std::convert::Infallible;

use super::{Validate2, ValidationConfig, ValidationError};
use crate::objects::Sketch;

use super::{Validate2, ValidationConfig};

impl Validate2 for Sketch {
type Error = Infallible;

fn validate_with_config(
&self,
_: &Store<Self>,
_: &ValidationConfig,
) -> Result<(), ValidationError> {
) -> Result<(), Self::Error> {
Ok(())
}
}
11 changes: 7 additions & 4 deletions crates/fj-kernel/src/validate/solid.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use crate::{objects::Solid, storage::Store};
use std::convert::Infallible;

use super::{Validate2, ValidationConfig, ValidationError};
use crate::objects::Solid;

use super::{Validate2, ValidationConfig};

impl Validate2 for Solid {
type Error = Infallible;

fn validate_with_config(
&self,
_: &Store<Self>,
_: &ValidationConfig,
) -> Result<(), ValidationError> {
) -> Result<(), Self::Error> {
Ok(())
}
}
11 changes: 7 additions & 4 deletions crates/fj-kernel/src/validate/surface.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use crate::{objects::Surface, storage::Store};
use std::convert::Infallible;

use super::{Validate2, ValidationConfig, ValidationError};
use crate::objects::Surface;

use super::{Validate2, ValidationConfig};

impl Validate2 for Surface {
type Error = Infallible;

fn validate_with_config(
&self,
_: &Store<Self>,
_: &ValidationConfig,
) -> Result<(), ValidationError> {
) -> Result<(), Self::Error> {
Ok(())
}
}
24 changes: 13 additions & 11 deletions crates/fj-kernel/src/validate/vertex.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
use crate::{
objects::{GlobalVertex, SurfaceVertex, Vertex},
storage::Store,
};
use std::convert::Infallible;

use super::{Validate2, ValidationConfig, ValidationError};
use crate::objects::{GlobalVertex, SurfaceVertex, Vertex};

use super::{Validate2, ValidationConfig};

impl Validate2 for Vertex {
type Error = Infallible;

fn validate_with_config(
&self,
_: &Store<Self>,
_: &ValidationConfig,
) -> Result<(), ValidationError> {
) -> Result<(), Self::Error> {
Ok(())
}
}

impl Validate2 for SurfaceVertex {
type Error = Infallible;

fn validate_with_config(
&self,
_: &Store<Self>,
_: &ValidationConfig,
) -> Result<(), ValidationError> {
) -> Result<(), Self::Error> {
Ok(())
}
}

impl Validate2 for GlobalVertex {
type Error = Infallible;

fn validate_with_config(
&self,
_: &Store<Self>,
_: &ValidationConfig,
) -> Result<(), ValidationError> {
) -> Result<(), Self::Error> {
Ok(())
}
}