Skip to content

Commit

Permalink
Merge pull request #1294 from hannobraun/partial
Browse files Browse the repository at this point in the history
Make `PartialGlobalEdge` more flexible
  • Loading branch information
hannobraun committed Nov 1, 2022
2 parents 2f608f6 + 2b26695 commit eba97af
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
6 changes: 2 additions & 4 deletions crates/fj-kernel/src/objects/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,10 @@ impl HalfEdge {
assert_eq!(
vertices_in_normalized_order
.access_in_normalized_order()
.clone()
.map(|global_vertex| global_vertex.id()),
global_form
.vertices()
.access_in_normalized_order()
.clone()
.map(|global_vertex| global_vertex.id()),
"The global forms of a half-edge's vertices must match the \
vertices of the half-edge's global form"
Expand Down Expand Up @@ -192,8 +190,8 @@ impl VerticesInNormalizedOrder {
/// Access the vertices
///
/// The vertices in the returned array will be in normalized order.
pub fn access_in_normalized_order(&self) -> &[Handle<GlobalVertex>; 2] {
&self.0
pub fn access_in_normalized_order(&self) -> [Handle<GlobalVertex>; 2] {
self.0.clone()
}
}

Expand Down
10 changes: 5 additions & 5 deletions crates/fj-kernel/src/partial/maybe_partial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ impl MaybePartial<GlobalEdge> {
}

/// Access the vertices
pub fn vertices(&self) -> Option<&[Handle<GlobalVertex>; 2]> {
pub fn vertices(&self) -> Option<[MaybePartial<GlobalVertex>; 2]> {
match self {
Self::Full(full) => {
Some(full.vertices().access_in_normalized_order())
}
Self::Partial(partial) => partial.vertices.as_ref(),
Self::Full(full) => Some(
full.vertices().access_in_normalized_order().map(Into::into),
),
Self::Partial(partial) => partial.vertices.clone(),
}
}
}
Expand Down
22 changes: 14 additions & 8 deletions crates/fj-kernel/src/partial/objects/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ impl PartialHalfEdge {
}

/// Access the vertices of the global form, if available
pub fn extract_global_vertices(&self) -> Option<[Handle<GlobalVertex>; 2]> {
self.global_form.vertices().cloned()
pub fn extract_global_vertices(
&self,
) -> Option<[MaybePartial<GlobalVertex>; 2]> {
self.global_form.vertices()
}

/// Update the partial half-edge with the given surface
Expand Down Expand Up @@ -136,7 +138,7 @@ impl PartialHalfEdge {

let global_vertex = self
.extract_global_vertices()
.map(|[global_form, _]| MaybePartial::from(global_form))
.map(|[global_form, _]| global_form)
.unwrap_or_else(|| {
GlobalVertex::partial()
.from_curve_and_position(curve.clone(), a_curve)
Expand Down Expand Up @@ -320,7 +322,7 @@ pub struct PartialGlobalEdge {
/// The vertices that bound the [`GlobalEdge`] in the curve
///
/// Must be provided before [`PartialGlobalEdge::build`] is called.
pub vertices: Option<[Handle<GlobalVertex>; 2]>,
pub vertices: Option<[MaybePartial<GlobalVertex>; 2]>,
}

impl PartialGlobalEdge {
Expand All @@ -335,10 +337,10 @@ impl PartialGlobalEdge {
/// Update the partial global edge with the given vertices
pub fn with_vertices(
mut self,
vertices: Option<[Handle<GlobalVertex>; 2]>,
vertices: Option<[impl Into<MaybePartial<GlobalVertex>>; 2]>,
) -> Self {
if let Some(vertices) = vertices {
self.vertices = Some(vertices);
self.vertices = Some(vertices.map(Into::into));
}
self
}
Expand All @@ -365,7 +367,8 @@ impl PartialGlobalEdge {
.expect("Can't build `GlobalEdge` without `GlobalCurve`");
let vertices = self
.vertices
.expect("Can't build `GlobalEdge` without vertices");
.expect("Can't build `GlobalEdge` without vertices")
.try_map_ext(|global_vertex| global_vertex.into_full(objects))?;

Ok(objects
.global_edges
Expand All @@ -378,7 +381,10 @@ impl From<&GlobalEdge> for PartialGlobalEdge {
Self {
curve: Some(global_edge.curve().clone().into()),
vertices: Some(
global_edge.vertices().access_in_normalized_order().clone(),
global_edge
.vertices()
.access_in_normalized_order()
.map(Into::into),
),
}
}
Expand Down

0 comments on commit eba97af

Please sign in to comment.