mirror of https://github.com/hannobraun/Fornjot
Remove uniqueness validation
It is the only check left that runs on the old validation infrastructure, and I'm not sure it actually does something useful anymore, given the coverage provided by all the other checks. If it turns out it does, we can re-add some form of it later, based on the new validation infrastructure.
This commit is contained in:
parent
6113fe6a4a
commit
09fbd74ee1
|
@ -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<Validated<Self>, 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<T> Deref for Validated<T> {
|
|||
#[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<Infallible> 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(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<GlobalVertex>,
|
||||
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<GlobalVertex>,
|
||||
}
|
||||
|
||||
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(())
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue