-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2277 from hannobraun/validation
Port face boundary check to new validation infrastructure
- Loading branch information
Showing
5 changed files
with
97 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use crate::{ | ||
geometry::Geometry, | ||
objects::Face, | ||
validation::{ValidationCheck, ValidationConfig}, | ||
}; | ||
|
||
/// [`Face`] has no boundary | ||
/// | ||
/// A face must have a boundary, meaning its exterior cycle must not be empty. | ||
/// Checking *that* the exterior cycle is not empty is enough, as | ||
/// [`AdjacentHalfEdgesNotConnected`] makes sure that any cycle that is not | ||
/// empty, is closed. | ||
/// | ||
/// [`AdjacentHalfEdgesNotConnected`]: super::AdjacentHalfEdgesNotConnected | ||
#[derive(Clone, Debug, thiserror::Error)] | ||
#[error("`Face` has no boundary")] | ||
pub struct FaceHasNoBoundary {} | ||
|
||
impl ValidationCheck<Face> for FaceHasNoBoundary { | ||
fn check( | ||
object: &Face, | ||
_: &Geometry, | ||
_: &ValidationConfig, | ||
) -> impl Iterator<Item = Self> { | ||
let error = if object.region().exterior().half_edges().is_empty() { | ||
Some(FaceHasNoBoundary {}) | ||
} else { | ||
None | ||
}; | ||
|
||
error.into_iter() | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::{ | ||
objects::{Cycle, Face}, | ||
operations::{ | ||
build::{BuildCycle, BuildFace}, | ||
update::{UpdateFace, UpdateRegion}, | ||
}, | ||
validation::{checks::FaceHasNoBoundary, ValidationCheck}, | ||
Core, | ||
}; | ||
|
||
#[test] | ||
fn face_has_no_boundary() -> anyhow::Result<()> { | ||
let mut core = Core::new(); | ||
|
||
let valid = Face::circle( | ||
core.layers.objects.surfaces.xy_plane(), | ||
[0., 0.], | ||
1., | ||
&mut core, | ||
); | ||
FaceHasNoBoundary::check_and_return_first_error( | ||
&valid, | ||
&core.layers.geometry, | ||
)?; | ||
|
||
let invalid = valid.update_region( | ||
|region, core| region.update_exterior(|_, _| Cycle::empty(), core), | ||
&mut core, | ||
); | ||
FaceHasNoBoundary::check_and_expect_one_error( | ||
&invalid, | ||
&core.layers.geometry, | ||
); | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters