mirror of
https://github.com/hannobraun/Fornjot
synced 2025-02-07 15:55:53 +00:00
Add CurveBoundary::union
This commit is contained in:
parent
332992015f
commit
efec190e25
@ -99,13 +99,7 @@ impl CurveApproxSegment {
|
||||
);
|
||||
assert!(other.is_normalized(), "Can't merge non-normalized segment.");
|
||||
|
||||
let [self_min, self_max] = self.boundary.inner;
|
||||
let [other_min, other_max] = other.boundary.inner;
|
||||
|
||||
let min = cmp::min(self_min, other_min);
|
||||
let max = cmp::max(self_max, other_max);
|
||||
|
||||
self.boundary.inner = [min, max];
|
||||
self.boundary = self.boundary.union(other.boundary);
|
||||
|
||||
self.points.retain(|point| {
|
||||
// Only retain points that don't overlap with the other segment, or
|
||||
|
@ -98,6 +98,32 @@ impl CurveBoundary<Point<1>> {
|
||||
|
||||
Self { inner: [min, max] }
|
||||
}
|
||||
|
||||
/// Create the union of this boundary and another
|
||||
///
|
||||
/// The result will be normalized.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics, if the two boundaries don't overlap (touching counts as
|
||||
/// overlapping).
|
||||
pub fn union(self, other: Self) -> Self {
|
||||
let self_ = self.normalize();
|
||||
let other = other.normalize();
|
||||
|
||||
assert!(
|
||||
self.overlaps(&other),
|
||||
"Can't merge boundaries that don't at least touch"
|
||||
);
|
||||
|
||||
let [self_min, self_max] = self_.inner;
|
||||
let [other_min, other_max] = other.inner;
|
||||
|
||||
let min = cmp::min(self_min, other_min);
|
||||
let max = cmp::max(self_max, other_max);
|
||||
|
||||
Self { inner: [min, max] }
|
||||
}
|
||||
}
|
||||
|
||||
impl<S, T: CurveBoundaryElement> From<[S; 2]> for CurveBoundary<T>
|
||||
|
Loading…
Reference in New Issue
Block a user