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 PartialGlobalEdge more flexible #1294

Merged
merged 5 commits into from
Nov 1, 2022
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
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