Merge pull request #1991 from hannobraun/boundary

Add `CurveBoundary::is_normalized`, simplify `CurveBoundary::normalize`
This commit is contained in:
Hanno Braun 2023-08-11 13:07:27 +02:00 committed by GitHub
commit 7681261f03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 14 deletions

View File

@ -28,20 +28,26 @@ impl<T: CurveBoundaryElement> CurveBoundary<T> {
Self { inner: [b, a] } Self { inner: [b, a] }
} }
/// Indicate whether the boundary is normalized
///
/// If the boundary is normalized, its bounding elements are in a defined
/// order, and calling `normalize` will return an identical instance.
pub fn is_normalized(&self) -> bool {
let [a, b] = &self.inner;
a <= b
}
/// Normalize the boundary /// Normalize the boundary
/// ///
/// Returns a new instance of this struct, which has the bounding elements /// Returns a new instance of this struct, which has the bounding elements
/// in a defined order, alongside a boolean that indicates whether the new /// in a defined order. This can be used to compare boundaries while
/// instance is different from the original one. /// disregarding their direction.
///
/// This can be used to compare a boundary while disregarding its direction.
#[must_use] #[must_use]
pub fn normalize(self) -> (Self, bool) { pub fn normalize(self) -> Self {
let [a, b] = &self.inner; if self.is_normalized() {
if a > b { self
(self.reverse(), true)
} else { } else {
(self, false) self.reverse()
} }
} }
} }

View File

@ -235,7 +235,6 @@ impl ShellValidationError {
.bounding_vertices_of_edge(edge) .bounding_vertices_of_edge(edge)
.expect("Expected edge to be part of shell") .expect("Expected edge to be part of shell")
.normalize() .normalize()
.0
}; };
bounding_vertices_of(edge_a) bounding_vertices_of(edge_a)
@ -315,8 +314,7 @@ impl ShellValidationError {
.expect( .expect(
"Cycle should provide bounds of its own half-edge", "Cycle should provide bounds of its own half-edge",
) )
.normalize() .normalize();
.0;
let edge = (curve, bounding_vertices); let edge = (curve, bounding_vertices);
@ -396,8 +394,7 @@ impl ShellValidationError {
.expect( .expect(
"Just got edge from this cycle; must be part of it", "Just got edge from this cycle; must be part of it",
) )
.normalize() .normalize();
.0;
edges_by_coincidence edges_by_coincidence
.entry((curve, boundary)) .entry((curve, boundary))