Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make some improvements to CurveBoundaries #2046

Merged
merged 3 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions crates/fj-core/src/algorithms/approx/curve/approx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,10 @@ impl CurveApprox {
impl<const N: usize> From<[CurveApproxSegment; N]> for CurveApprox {
fn from(segments: [CurveApproxSegment; N]) -> Self {
Self {
segments: CurveBoundaries {
inner: segments
.into_iter()
.map(|segment| (segment.boundary, segment.points))
.collect(),
},
segments: segments
.into_iter()
.map(|segment| (segment.boundary, segment.points))
.collect(),
}
}
}
Expand Down
18 changes: 15 additions & 3 deletions crates/fj-core/src/geometry/boundary/multiple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use crate::geometry::CurveBoundary;
/// boundary.
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct CurveBoundaries<T: CurveBoundariesPayload = ()> {
/// The [`CurveBoundary`] instances
pub inner: Vec<(CurveBoundary<Point<1>>, T)>,
inner: Vec<(CurveBoundary<Point<1>>, T)>,
}

impl<T: CurveBoundariesPayload> CurveBoundaries<T> {
Expand All @@ -29,7 +28,7 @@ impl<T: CurveBoundariesPayload> CurveBoundaries<T> {
// the removed element's boundary matches the boundary provided
// to us.
//
// This is what the caller was asking for. Return it!
// This is what the caller is asking for. Return it!
Some(payload)
}
_ => {
Expand Down Expand Up @@ -115,6 +114,19 @@ impl<T: CurveBoundariesPayload> Default for CurveBoundaries<T> {
}
}

impl<T: CurveBoundariesPayload> FromIterator<(CurveBoundary<Point<1>>, T)>
for CurveBoundaries<T>
{
fn from_iter<I>(iter: I) -> Self
where
I: IntoIterator<Item = (CurveBoundary<Point<1>>, T)>,
{
Self {
inner: iter.into_iter().collect(),
}
}
}

/// A payload that can be used in [`CurveBoundaries`]
pub trait CurveBoundariesPayload: Clone + Ord {
/// Reverse the orientation of the payload
Expand Down