From f98436f46d187ff997f5960ebc5354155f78a9d0 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 29 Sep 2023 10:22:37 +0200 Subject: [PATCH] Add `CurveBoundary::subset` --- .../src/algorithms/approx/curve/segment.rs | 12 ++---------- crates/fj-core/src/geometry/boundary.rs | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/crates/fj-core/src/algorithms/approx/curve/segment.rs b/crates/fj-core/src/algorithms/approx/curve/segment.rs index 5dc30242e..0047e712f 100644 --- a/crates/fj-core/src/algorithms/approx/curve/segment.rs +++ b/crates/fj-core/src/algorithms/approx/curve/segment.rs @@ -78,17 +78,9 @@ impl CurveApproxSegment { "Expected subset to be defined by normalized boundary." ); - let [min, max] = boundary.inner; - - self.boundary.inner = { - let [self_min, self_max] = self.boundary.inner; - - let min = cmp::max(self_min, min); - let max = cmp::min(self_max, max); - - [min, max] - }; + self.boundary = self.boundary.subset(boundary); + let [min, max] = self.boundary.inner; self.points .retain(|point| point.local_form > min && point.local_form < max); } diff --git a/crates/fj-core/src/geometry/boundary.rs b/crates/fj-core/src/geometry/boundary.rs index 0f68432e0..a7d2dea5b 100644 --- a/crates/fj-core/src/geometry/boundary.rs +++ b/crates/fj-core/src/geometry/boundary.rs @@ -1,5 +1,5 @@ use std::{ - cmp::Ordering, + cmp::{self, Ordering}, hash::{Hash, Hasher}, }; @@ -75,6 +75,23 @@ impl CurveBoundary> { a_low <= b_high && a_high >= b_low } + + /// Create the subset of this boundary and another + /// + /// The result will be normalized. + #[must_use] + pub fn subset(self, other: Self) -> Self { + let self_ = self.normalize(); + let other = other.normalize(); + + let [self_min, self_max] = self_.inner; + let [other_min, other_max] = other.inner; + + let min = cmp::max(self_min, other_min); + let max = cmp::min(self_max, other_max); + + Self { inner: [min, max] } + } } impl From<[S; 2]> for CurveBoundary