Add CurveBoundary::subset

This commit is contained in:
Hanno Braun 2023-09-29 10:22:37 +02:00
parent b9aef596a1
commit f98436f46d
2 changed files with 20 additions and 11 deletions

View File

@ -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);
}

View File

@ -1,5 +1,5 @@
use std::{
cmp::Ordering,
cmp::{self, Ordering},
hash::{Hash, Hasher},
};
@ -75,6 +75,23 @@ impl CurveBoundary<Point<1>> {
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<S, T: CurveBoundaryElement> From<[S; 2]> for CurveBoundary<T>