From 9d30113fdde8f7468fb49ce8fd73e06a01cb60cd Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 8 Aug 2023 10:07:09 +0200 Subject: [PATCH 1/3] Refactor to prepare for follow-on change --- crates/fj-core/src/geometry/boundary.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/fj-core/src/geometry/boundary.rs b/crates/fj-core/src/geometry/boundary.rs index bb5ed9935..6df775c22 100644 --- a/crates/fj-core/src/geometry/boundary.rs +++ b/crates/fj-core/src/geometry/boundary.rs @@ -34,9 +34,13 @@ impl CurveBoundary { /// in a defined order. This can be used to compare a boundary while /// disregarding its direction. #[must_use] - pub fn normalize(mut self) -> Self { - self.inner.sort(); - self + pub fn normalize(self) -> Self { + let [a, b] = &self.inner; + if a > b { + self.reverse() + } else { + self + } } } From 6ed2aaa39711f07539d6308eea5fbaecf8ccc40e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 8 Aug 2023 10:11:03 +0200 Subject: [PATCH 2/3] Return more info from `CurveBoundary::normalize` --- crates/fj-core/src/geometry/boundary.rs | 6 +++--- crates/fj-core/src/validate/shell.rs | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/fj-core/src/geometry/boundary.rs b/crates/fj-core/src/geometry/boundary.rs index 6df775c22..35a99d6cf 100644 --- a/crates/fj-core/src/geometry/boundary.rs +++ b/crates/fj-core/src/geometry/boundary.rs @@ -34,12 +34,12 @@ impl CurveBoundary { /// in a defined order. This can be used to compare a boundary while /// disregarding its direction. #[must_use] - pub fn normalize(self) -> Self { + pub fn normalize(self) -> (Self, bool) { let [a, b] = &self.inner; if a > b { - self.reverse() + (self.reverse(), true) } else { - self + (self, false) } } } diff --git a/crates/fj-core/src/validate/shell.rs b/crates/fj-core/src/validate/shell.rs index eb1f1f328..c87b92542 100644 --- a/crates/fj-core/src/validate/shell.rs +++ b/crates/fj-core/src/validate/shell.rs @@ -235,6 +235,7 @@ impl ShellValidationError { .bounding_vertices_of_edge(edge) .expect("Expected edge to be part of shell") .normalize() + .0 }; bounding_vertices_of(edge_a) @@ -314,7 +315,8 @@ impl ShellValidationError { .expect( "Cycle should provide bounds of its own half-edge", ) - .normalize(); + .normalize() + .0; let edge = (curve, bounding_vertices); @@ -394,7 +396,8 @@ impl ShellValidationError { .expect( "Just got edge from this cycle; must be part of it", ) - .normalize(); + .normalize() + .0; edges_by_coincidence .entry((curve, boundary)) From c5cee37a9be9f63e948636217e7fa80fb4108299 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 8 Aug 2023 10:12:32 +0200 Subject: [PATCH 3/3] Update doc comment --- crates/fj-core/src/geometry/boundary.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/fj-core/src/geometry/boundary.rs b/crates/fj-core/src/geometry/boundary.rs index 35a99d6cf..8a6eef11a 100644 --- a/crates/fj-core/src/geometry/boundary.rs +++ b/crates/fj-core/src/geometry/boundary.rs @@ -31,8 +31,10 @@ impl CurveBoundary { /// Normalize the boundary /// /// Returns a new instance of this struct, which has the bounding elements - /// in a defined order. This can be used to compare a boundary while - /// disregarding its direction. + /// in a defined order, alongside a boolean that indicates whether the new + /// instance is different from the original one. + /// + /// This can be used to compare a boundary while disregarding its direction. #[must_use] pub fn normalize(self) -> (Self, bool) { let [a, b] = &self.inner;