mirror of
https://github.com/hannobraun/Fornjot
synced 2025-01-11 18:57:01 +00:00
Merge pull request #2272 from hannobraun/geometry
Make `Geometry` available to `ValidationCheck` implementations
This commit is contained in:
commit
9f817d9738
@ -14,10 +14,11 @@ impl Validate for Cycle {
|
|||||||
&self,
|
&self,
|
||||||
config: &ValidationConfig,
|
config: &ValidationConfig,
|
||||||
errors: &mut Vec<ValidationError>,
|
errors: &mut Vec<ValidationError>,
|
||||||
_: &Geometry,
|
geometry: &Geometry,
|
||||||
) {
|
) {
|
||||||
errors.extend(
|
errors.extend(
|
||||||
AdjacentHalfEdgesNotConnected::check(self, config).map(Into::into),
|
AdjacentHalfEdgesNotConnected::check(self, geometry, config)
|
||||||
|
.map(Into::into),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use fj_math::{Point, Scalar};
|
use fj_math::{Point, Scalar};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
geometry::Geometry,
|
||||||
objects::{Cycle, HalfEdge},
|
objects::{Cycle, HalfEdge},
|
||||||
storage::Handle,
|
storage::Handle,
|
||||||
validation::{validation_check::ValidationCheck, ValidationConfig},
|
validation::{validation_check::ValidationCheck, ValidationConfig},
|
||||||
@ -40,6 +41,7 @@ pub struct AdjacentHalfEdgesNotConnected {
|
|||||||
impl ValidationCheck<Cycle> for AdjacentHalfEdgesNotConnected {
|
impl ValidationCheck<Cycle> for AdjacentHalfEdgesNotConnected {
|
||||||
fn check(
|
fn check(
|
||||||
object: &Cycle,
|
object: &Cycle,
|
||||||
|
_: &Geometry,
|
||||||
config: &ValidationConfig,
|
config: &ValidationConfig,
|
||||||
) -> impl Iterator<Item = Self> {
|
) -> impl Iterator<Item = Self> {
|
||||||
object.half_edges().pairs().filter_map(|(first, second)| {
|
object.half_edges().pairs().filter_map(|(first, second)| {
|
||||||
@ -87,7 +89,10 @@ mod tests {
|
|||||||
let mut core = Core::new();
|
let mut core = Core::new();
|
||||||
|
|
||||||
let valid = Cycle::polygon([[0., 0.], [1., 0.], [1., 1.]], &mut core);
|
let valid = Cycle::polygon([[0., 0.], [1., 0.], [1., 1.]], &mut core);
|
||||||
AdjacentHalfEdgesNotConnected::check_and_return_first_error(&valid)?;
|
AdjacentHalfEdgesNotConnected::check_and_return_first_error(
|
||||||
|
&valid,
|
||||||
|
&core.layers.geometry,
|
||||||
|
)?;
|
||||||
|
|
||||||
let invalid = valid.update_half_edge(
|
let invalid = valid.update_half_edge(
|
||||||
valid.half_edges().first(),
|
valid.half_edges().first(),
|
||||||
@ -96,7 +101,10 @@ mod tests {
|
|||||||
},
|
},
|
||||||
&mut core,
|
&mut core,
|
||||||
);
|
);
|
||||||
AdjacentHalfEdgesNotConnected::check_and_expect_one_error(&invalid);
|
AdjacentHalfEdgesNotConnected::check_and_expect_one_error(
|
||||||
|
&invalid,
|
||||||
|
&core.layers.geometry,
|
||||||
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
|
|
||||||
|
use crate::geometry::Geometry;
|
||||||
|
|
||||||
use super::ValidationConfig;
|
use super::ValidationConfig;
|
||||||
|
|
||||||
/// Run a specific validation check on an object
|
/// Run a specific validation check on an object
|
||||||
@ -10,6 +12,7 @@ pub trait ValidationCheck<T>: Sized {
|
|||||||
/// Run the validation check on the implementing object
|
/// Run the validation check on the implementing object
|
||||||
fn check(
|
fn check(
|
||||||
object: &T,
|
object: &T,
|
||||||
|
geometry: &Geometry,
|
||||||
config: &ValidationConfig,
|
config: &ValidationConfig,
|
||||||
) -> impl Iterator<Item = Self>;
|
) -> impl Iterator<Item = Self>;
|
||||||
|
|
||||||
@ -17,9 +20,12 @@ pub trait ValidationCheck<T>: Sized {
|
|||||||
///
|
///
|
||||||
/// This method is designed for convenience over flexibility (it is intended
|
/// This method is designed for convenience over flexibility (it is intended
|
||||||
/// for use in unit tests), and thus always uses the default configuration.
|
/// for use in unit tests), and thus always uses the default configuration.
|
||||||
fn check_and_return_first_error(object: &T) -> Result<(), Self> {
|
fn check_and_return_first_error(
|
||||||
|
object: &T,
|
||||||
|
geometry: &Geometry,
|
||||||
|
) -> Result<(), Self> {
|
||||||
let config = ValidationConfig::default();
|
let config = ValidationConfig::default();
|
||||||
let mut errors = Self::check(object, &config);
|
let mut errors = Self::check(object, geometry, &config);
|
||||||
|
|
||||||
if let Some(err) = errors.next() {
|
if let Some(err) = errors.next() {
|
||||||
return Err(err);
|
return Err(err);
|
||||||
@ -32,12 +38,12 @@ pub trait ValidationCheck<T>: Sized {
|
|||||||
///
|
///
|
||||||
/// This method is designed for convenience over flexibility (it is intended
|
/// This method is designed for convenience over flexibility (it is intended
|
||||||
/// for use in unit tests), and thus always uses the default configuration.
|
/// for use in unit tests), and thus always uses the default configuration.
|
||||||
fn check_and_expect_one_error(object: &T) -> Self
|
fn check_and_expect_one_error(object: &T, geometry: &Geometry) -> Self
|
||||||
where
|
where
|
||||||
Self: Display,
|
Self: Display,
|
||||||
{
|
{
|
||||||
let config = ValidationConfig::default();
|
let config = ValidationConfig::default();
|
||||||
let mut errors = Self::check(object, &config).peekable();
|
let mut errors = Self::check(object, geometry, &config).peekable();
|
||||||
|
|
||||||
let err = errors
|
let err = errors
|
||||||
.next()
|
.next()
|
||||||
|
Loading…
Reference in New Issue
Block a user