Add CurveBoundary::contains

This commit is contained in:
Hanno Braun 2023-09-29 10:30:07 +02:00
parent 952c2ff845
commit 332992015f
2 changed files with 8 additions and 4 deletions

View File

@ -79,10 +79,8 @@ impl CurveApproxSegment {
); );
self.boundary = self.boundary.subset(boundary); self.boundary = self.boundary.subset(boundary);
let [min, max] = self.boundary.inner;
self.points self.points
.retain(|point| point.local_form > min && point.local_form < max); .retain(|point| self.boundary.contains(point.local_form));
} }
/// Merge the provided segment into this one /// Merge the provided segment into this one
@ -112,7 +110,7 @@ impl CurveApproxSegment {
self.points.retain(|point| { self.points.retain(|point| {
// Only retain points that don't overlap with the other segment, or // Only retain points that don't overlap with the other segment, or
// we might end up with duplicates. // we might end up with duplicates.
point.local_form < other_min || point.local_form > other_max !other.boundary.contains(point.local_form)
}); });
self.points.extend(&other.points); self.points.extend(&other.points);
self.points.sort(); self.points.sort();

View File

@ -65,6 +65,12 @@ impl CurveBoundary<Point<1>> {
min >= max min >= max
} }
/// Indicate whether the boundary contains the given element
pub fn contains(&self, point: Point<1>) -> bool {
let [min, max] = self.inner;
point > min && point < max
}
/// Indicate whether the boundary overlaps another /// Indicate whether the boundary overlaps another
/// ///
/// Boundaries that touch (i.e. their closest boundary elements are equal) /// Boundaries that touch (i.e. their closest boundary elements are equal)