From 4bac06cbf410d454580f6631e3729d36741e521e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 5 Nov 2022 19:52:57 +0100 Subject: [PATCH 01/12] Make `MaybePartial::merge_with` more convenient --- crates/fj-kernel/src/partial/maybe_partial.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-kernel/src/partial/maybe_partial.rs b/crates/fj-kernel/src/partial/maybe_partial.rs index 5e7e7c1da..5b9cee73c 100644 --- a/crates/fj-kernel/src/partial/maybe_partial.rs +++ b/crates/fj-kernel/src/partial/maybe_partial.rs @@ -65,8 +65,8 @@ impl MaybePartial { } /// Merge this `MaybePartial` with another of the same type - pub fn merge_with(self, other: Self) -> Self { - match (self, other) { + pub fn merge_with(self, other: impl Into) -> Self { + match (self, other.into()) { (Self::Full(_), Self::Full(_)) => { panic!("Can't merge two full objects") } From 62f69e20d5034616fa6c6a06ca1c156d7a9e39d0 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 5 Nov 2022 20:13:34 +0100 Subject: [PATCH 02/12] Clarify some really weird code To be quite honest, I don't understand why this worked in the first place. --- crates/fj-kernel/src/algorithms/transform/vertex.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/vertex.rs b/crates/fj-kernel/src/algorithms/transform/vertex.rs index a1a370621..ac3f9a4dd 100644 --- a/crates/fj-kernel/src/algorithms/transform/vertex.rs +++ b/crates/fj-kernel/src/algorithms/transform/vertex.rs @@ -18,15 +18,14 @@ impl TransformObject for PartialVertex { let surface_form = self .surface_form() .into_partial() - .transform(transform, objects)? - .into(); + .transform(transform, objects)?; // Don't need to transform `self.position`, as that is in curve // coordinates and thus transforming the curve takes care of it. Ok(Self::default() .with_position(self.position()) .with_curve(Some(curve)) - .with_surface_form(surface_form)) + .with_surface_form(Some(surface_form))) } } From 41d1fb87aae61f545e569fdac9c5731aba7defce Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 5 Nov 2022 19:37:59 +0100 Subject: [PATCH 03/12] Simplify `last_vertex` in `PartialCycle::build` --- crates/fj-kernel/src/partial/objects/cycle.rs | 52 ++++++++----------- 1 file changed, 21 insertions(+), 31 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/cycle.rs b/crates/fj-kernel/src/partial/objects/cycle.rs index 7d2c146a3..fec5f7d5e 100644 --- a/crates/fj-kernel/src/partial/objects/cycle.rs +++ b/crates/fj-kernel/src/partial/objects/cycle.rs @@ -1,6 +1,8 @@ use crate::{ objects::{Cycle, HalfEdge, Objects, Surface}, - partial::{util::merge_options, MaybePartial}, + partial::{ + util::merge_options, MaybePartial, PartialHalfEdge, PartialVertex, + }, storage::Handle, validate::ValidationError, }; @@ -85,36 +87,24 @@ impl PartialCycle { objects: &Objects, ) -> Result, ValidationError> { let half_edges = { - let last_vertex = self - .half_edges - .last_mut() - .map(|half_edge| { - let vertex = half_edge.front(); - (half_edge, vertex) - }) - .map(|(half_edge, vertex)| { - let surface_vertex = vertex.surface_form(); - (half_edge, vertex, surface_vertex) - }) - .map(|(half_edge, vertex, surface_vertex)| - -> Result<_, ValidationError> - { - let surface_vertex = surface_vertex.into_full(objects)?; + let last_vertex = { + let last_half_edge = self + .half_edges + .last_mut() + .expect("Can't build cycle without any half-edges"); - *half_edge = - half_edge.clone().update_partial(|half_edge| { - half_edge.with_front_vertex(Some( - vertex.update_partial(|vertex| { - vertex.with_surface_form(Some( - surface_vertex.clone(), - )) - }), - )) - }); + let surface_vertex = + last_half_edge.front().surface_form().into_full(objects)?; - Ok(surface_vertex) - }) - .transpose()?; + *last_half_edge = last_half_edge.clone().merge_with( + PartialHalfEdge::default().with_front_vertex(Some( + PartialVertex::default() + .with_surface_form(Some(surface_vertex.clone())), + )), + ); + + surface_vertex + }; let (half_edges, _) = self.half_edges.into_iter().fold( Ok((Vec::new(), last_vertex)), @@ -125,7 +115,7 @@ impl PartialCycle { .update_partial(|half_edge| { let [back, _] = half_edge.vertices(); let back = back.update_partial(|partial| { - partial.with_surface_form(previous_vertex) + partial.with_surface_form(Some(previous_vertex)) }); half_edge.with_back_vertex(Some(back)) @@ -135,7 +125,7 @@ impl PartialCycle { let front = half_edge.front().surface_form().clone(); half_edges.push(half_edge); - Ok((half_edges, Some(front))) + Ok((half_edges, front)) }, )?; From 5c4d56c8dc4809797016873b904ae1bc731b7cba Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 5 Nov 2022 20:15:43 +0100 Subject: [PATCH 04/12] Simplify `PartialVertex::with_surface_form` --- crates/fj-kernel/src/algorithms/sweep/edge.rs | 39 ++++++++++--------- .../src/algorithms/transform/vertex.rs | 2 +- crates/fj-kernel/src/builder/cycle.rs | 2 +- crates/fj-kernel/src/builder/edge.rs | 8 ++-- crates/fj-kernel/src/builder/shell.rs | 14 +++---- crates/fj-kernel/src/builder/vertex.rs | 2 +- crates/fj-kernel/src/partial/objects/cycle.rs | 4 +- crates/fj-kernel/src/partial/objects/edge.rs | 2 +- .../fj-kernel/src/partial/objects/vertex.rs | 6 +-- 9 files changed, 40 insertions(+), 39 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index 2f3cce225..ca7e3cf31 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -219,37 +219,40 @@ mod tests { .build(&objects)?; let side_up = HalfEdge::partial() .with_surface(Some(surface.clone())) - .with_back_vertex(Some(Vertex::partial().with_surface_form( - Some(bottom.front().surface_form().clone()), - ))) - .with_front_vertex(Some(Vertex::partial().with_surface_form( - Some( - SurfaceVertex::partial().with_position(Some([1., 1.])), + .with_back_vertex(Some( + Vertex::partial().with_surface_form( + bottom.front().surface_form().clone(), ), + )) + .with_front_vertex(Some(Vertex::partial().with_surface_form( + SurfaceVertex::partial().with_position(Some([1., 1.])), ))) .update_as_line_segment() .build(&objects)?; let top = HalfEdge::partial() .with_surface(Some(surface.clone())) .with_back_vertex(Some(Vertex::partial().with_surface_form( - Some( - SurfaceVertex::partial().with_position(Some([0., 1.])), + SurfaceVertex::partial().with_position(Some([0., 1.])), + ))) + .with_front_vertex(Some( + Vertex::partial().with_surface_form( + side_up.front().surface_form().clone(), ), - ))) - .with_front_vertex(Some(Vertex::partial().with_surface_form( - Some(side_up.front().surface_form().clone()), - ))) + )) .update_as_line_segment() .build(&objects)? .reverse(&objects)?; let side_down = HalfEdge::partial() .with_surface(Some(surface)) - .with_back_vertex(Some(Vertex::partial().with_surface_form( - Some(bottom.back().surface_form().clone()), - ))) - .with_front_vertex(Some(Vertex::partial().with_surface_form( - Some(top.front().surface_form().clone()), - ))) + .with_back_vertex(Some( + Vertex::partial().with_surface_form( + bottom.back().surface_form().clone(), + ), + )) + .with_front_vertex(Some( + Vertex::partial() + .with_surface_form(top.front().surface_form().clone()), + )) .update_as_line_segment() .build(&objects)? .reverse(&objects)?; diff --git a/crates/fj-kernel/src/algorithms/transform/vertex.rs b/crates/fj-kernel/src/algorithms/transform/vertex.rs index ac3f9a4dd..a86753e0d 100644 --- a/crates/fj-kernel/src/algorithms/transform/vertex.rs +++ b/crates/fj-kernel/src/algorithms/transform/vertex.rs @@ -25,7 +25,7 @@ impl TransformObject for PartialVertex { Ok(Self::default() .with_position(self.position()) .with_curve(Some(curve)) - .with_surface_form(Some(surface_form))) + .with_surface_form(surface_form)) } } diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 86103d627..afca811b6 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -76,7 +76,7 @@ impl CycleBuilder for PartialCycle { Vertex::partial() .with_curve(Some(curve.clone())) .with_position(Some([position])) - .with_surface_form(Some(surface_form)) + .with_surface_form(surface_form) }); half_edges.push( diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 65c20f4a0..c47ce959c 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -76,7 +76,7 @@ impl HalfEdgeBuilder for PartialHalfEdge { Vertex::partial() .with_position(Some(point_curve)) .with_curve(Some(curve.clone())) - .with_surface_form(Some(surface_vertex.clone())) + .with_surface_form(surface_vertex.clone()) }); Ok(self @@ -94,7 +94,7 @@ impl HalfEdgeBuilder for PartialHalfEdge { .with_surface(Some(surface.clone())) .with_position(Some(point)); - Vertex::partial().with_surface_form(Some(surface_form)) + Vertex::partial().with_surface_form(surface_form) }); self.with_surface(Some(surface)) @@ -170,13 +170,13 @@ impl HalfEdgeBuilder for PartialHalfEdge { vertices.zip_ext(global_forms).map(|(vertex, global_form)| { vertex.update_partial(|vertex| { - vertex.clone().with_surface_form(Some( + vertex.clone().with_surface_form( vertex.surface_form().update_partial( |surface_vertex| { surface_vertex.with_global_form(global_form) }, ), - )) + ) }) }) }; diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index 1785af97b..4ae6ef6c8 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -113,8 +113,8 @@ impl<'a> ShellBuilder<'a> { HalfEdge::partial() .with_vertices(Some([ - Vertex::partial().with_surface_form(Some(from)), - Vertex::partial().with_surface_form(Some(to)), + Vertex::partial().with_surface_form(from), + Vertex::partial().with_surface_form(to), ])) .update_as_line_segment() .build(self.objects) @@ -150,8 +150,8 @@ impl<'a> ShellBuilder<'a> { HalfEdge::partial() .with_curve(Some(curve)) .with_vertices(Some([ - Vertex::partial().with_surface_form(Some(from)), - Vertex::partial().with_surface_form(Some(to)), + Vertex::partial().with_surface_form(from), + Vertex::partial().with_surface_form(to), ])) .update_as_line_segment() .build(self.objects) @@ -171,8 +171,8 @@ impl<'a> ShellBuilder<'a> { let from = from.surface_form().clone(); let to = to.surface_form().clone(); - let from = Vertex::partial().with_surface_form(Some(from)); - let to = Vertex::partial().with_surface_form(Some(to)); + let from = Vertex::partial().with_surface_form(from); + let to = Vertex::partial().with_surface_form(to); HalfEdge::partial() .with_vertices(Some([from, to])) @@ -246,7 +246,7 @@ impl<'a> ShellBuilder<'a> { .map(|(vertex, surface_form)| { Vertex::partial() .with_position(Some(vertex.position())) - .with_surface_form(Some(surface_form)) + .with_surface_form(surface_form) }); edges.push( diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index 56c817738..813268a74 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -16,7 +16,7 @@ pub trait VertexBuilder { impl VertexBuilder for PartialVertex { fn infer_surface_form(self) -> Self { - self.with_surface_form(Some(PartialSurfaceVertex::default())) + self.with_surface_form(PartialSurfaceVertex::default()) } } diff --git a/crates/fj-kernel/src/partial/objects/cycle.rs b/crates/fj-kernel/src/partial/objects/cycle.rs index fec5f7d5e..f283c7340 100644 --- a/crates/fj-kernel/src/partial/objects/cycle.rs +++ b/crates/fj-kernel/src/partial/objects/cycle.rs @@ -99,7 +99,7 @@ impl PartialCycle { *last_half_edge = last_half_edge.clone().merge_with( PartialHalfEdge::default().with_front_vertex(Some( PartialVertex::default() - .with_surface_form(Some(surface_vertex.clone())), + .with_surface_form(surface_vertex.clone()), )), ); @@ -115,7 +115,7 @@ impl PartialCycle { .update_partial(|half_edge| { let [back, _] = half_edge.vertices(); let back = back.update_partial(|partial| { - partial.with_surface_form(Some(previous_vertex)) + partial.with_surface_form(previous_vertex) }); half_edge.with_back_vertex(Some(back)) diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 2aadf3bb4..437f35b6b 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -61,7 +61,7 @@ impl PartialHalfEdge { }, ); - vertex.with_surface_form(Some(surface_form)) + vertex.with_surface_form(surface_form) }) }); } diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index b04a67b02..8cad7c7ca 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -59,11 +59,9 @@ impl PartialVertex { /// Provide a surface form for the partial vertex pub fn with_surface_form( mut self, - surface_form: Option>>, + surface_form: impl Into>, ) -> Self { - if let Some(surface_form) = surface_form { - self.surface_form = surface_form.into(); - } + self.surface_form = surface_form.into(); self } From 162aba8caa11008fdc31f24ddaed5ad28aa29586 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 5 Nov 2022 20:17:38 +0100 Subject: [PATCH 05/12] Simplify `PartialHalfEdge::with_front_vertex` --- crates/fj-kernel/src/algorithms/sweep/edge.rs | 12 ++++++------ crates/fj-kernel/src/partial/objects/cycle.rs | 4 ++-- crates/fj-kernel/src/partial/objects/edge.rs | 9 ++++----- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index ca7e3cf31..50c944d85 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -224,9 +224,9 @@ mod tests { bottom.front().surface_form().clone(), ), )) - .with_front_vertex(Some(Vertex::partial().with_surface_form( + .with_front_vertex(Vertex::partial().with_surface_form( SurfaceVertex::partial().with_position(Some([1., 1.])), - ))) + )) .update_as_line_segment() .build(&objects)?; let top = HalfEdge::partial() @@ -234,11 +234,11 @@ mod tests { .with_back_vertex(Some(Vertex::partial().with_surface_form( SurfaceVertex::partial().with_position(Some([0., 1.])), ))) - .with_front_vertex(Some( + .with_front_vertex( Vertex::partial().with_surface_form( side_up.front().surface_form().clone(), ), - )) + ) .update_as_line_segment() .build(&objects)? .reverse(&objects)?; @@ -249,10 +249,10 @@ mod tests { bottom.back().surface_form().clone(), ), )) - .with_front_vertex(Some( + .with_front_vertex( Vertex::partial() .with_surface_form(top.front().surface_form().clone()), - )) + ) .update_as_line_segment() .build(&objects)? .reverse(&objects)?; diff --git a/crates/fj-kernel/src/partial/objects/cycle.rs b/crates/fj-kernel/src/partial/objects/cycle.rs index f283c7340..aca41f414 100644 --- a/crates/fj-kernel/src/partial/objects/cycle.rs +++ b/crates/fj-kernel/src/partial/objects/cycle.rs @@ -97,10 +97,10 @@ impl PartialCycle { last_half_edge.front().surface_form().into_full(objects)?; *last_half_edge = last_half_edge.clone().merge_with( - PartialHalfEdge::default().with_front_vertex(Some( + PartialHalfEdge::default().with_front_vertex( PartialVertex::default() .with_surface_form(surface_vertex.clone()), - )), + ), ); surface_vertex diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 437f35b6b..9f1b01bc0 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -94,12 +94,11 @@ impl PartialHalfEdge { /// Update the partial half-edge with the given front vertex pub fn with_front_vertex( mut self, - vertex: Option>>, + vertex: impl Into>, ) -> Self { - if let Some(vertex) = vertex { - let [_, to] = &mut self.vertices; - *to = vertex.into(); - } + let [_, to] = &mut self.vertices; + *to = vertex.into(); + self } From e2ddd014b1982c8b8d3c38ebc01ccdb6674cd8bd Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 5 Nov 2022 20:19:20 +0100 Subject: [PATCH 06/12] Simplify `PartialHalfEdge::with_back_vertex` --- crates/fj-kernel/src/algorithms/sweep/edge.rs | 95 +++++++++---------- crates/fj-kernel/src/partial/objects/cycle.rs | 2 +- crates/fj-kernel/src/partial/objects/edge.rs | 9 +- 3 files changed, 50 insertions(+), 56 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index 50c944d85..2018259de 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -208,61 +208,56 @@ mod tests { let face = (half_edge, Color::default()).sweep([0., 0., 1.], &objects)?; - let expected_face = { - let surface = objects.surfaces.xz_plane(); + let expected_face = + { + let surface = objects.surfaces.xz_plane(); - let bottom = HalfEdge::partial() - .update_as_line_segment_from_points( - surface.clone(), - [[0., 0.], [1., 0.]], - ) - .build(&objects)?; - let side_up = HalfEdge::partial() - .with_surface(Some(surface.clone())) - .with_back_vertex(Some( - Vertex::partial().with_surface_form( + let bottom = HalfEdge::partial() + .update_as_line_segment_from_points( + surface.clone(), + [[0., 0.], [1., 0.]], + ) + .build(&objects)?; + let side_up = HalfEdge::partial() + .with_surface(Some(surface.clone())) + .with_back_vertex(Vertex::partial().with_surface_form( bottom.front().surface_form().clone(), - ), - )) - .with_front_vertex(Vertex::partial().with_surface_form( - SurfaceVertex::partial().with_position(Some([1., 1.])), - )) - .update_as_line_segment() - .build(&objects)?; - let top = HalfEdge::partial() - .with_surface(Some(surface.clone())) - .with_back_vertex(Some(Vertex::partial().with_surface_form( - SurfaceVertex::partial().with_position(Some([0., 1.])), - ))) - .with_front_vertex( - Vertex::partial().with_surface_form( + )) + .with_front_vertex(Vertex::partial().with_surface_form( + SurfaceVertex::partial().with_position(Some([1., 1.])), + )) + .update_as_line_segment() + .build(&objects)?; + let top = HalfEdge::partial() + .with_surface(Some(surface.clone())) + .with_back_vertex(Vertex::partial().with_surface_form( + SurfaceVertex::partial().with_position(Some([0., 1.])), + )) + .with_front_vertex(Vertex::partial().with_surface_form( side_up.front().surface_form().clone(), - ), - ) - .update_as_line_segment() - .build(&objects)? - .reverse(&objects)?; - let side_down = HalfEdge::partial() - .with_surface(Some(surface)) - .with_back_vertex(Some( - Vertex::partial().with_surface_form( - bottom.back().surface_form().clone(), - ), - )) - .with_front_vertex( - Vertex::partial() - .with_surface_form(top.front().surface_form().clone()), - ) - .update_as_line_segment() - .build(&objects)? - .reverse(&objects)?; + )) + .update_as_line_segment() + .build(&objects)? + .reverse(&objects)?; + let side_down = + HalfEdge::partial() + .with_surface(Some(surface)) + .with_back_vertex(Vertex::partial().with_surface_form( + bottom.back().surface_form().clone(), + )) + .with_front_vertex(Vertex::partial().with_surface_form( + top.front().surface_form().clone(), + )) + .update_as_line_segment() + .build(&objects)? + .reverse(&objects)?; - let cycle = objects - .cycles - .insert(Cycle::new([bottom, side_up, top, side_down]))?; + let cycle = objects + .cycles + .insert(Cycle::new([bottom, side_up, top, side_down]))?; - Face::builder(&objects).with_exterior(cycle).build() - }; + Face::builder(&objects).with_exterior(cycle).build() + }; assert_eq!(face, expected_face); Ok(()) diff --git a/crates/fj-kernel/src/partial/objects/cycle.rs b/crates/fj-kernel/src/partial/objects/cycle.rs index aca41f414..8e3658b8e 100644 --- a/crates/fj-kernel/src/partial/objects/cycle.rs +++ b/crates/fj-kernel/src/partial/objects/cycle.rs @@ -118,7 +118,7 @@ impl PartialCycle { partial.with_surface_form(previous_vertex) }); - half_edge.with_back_vertex(Some(back)) + half_edge.with_back_vertex(back) }) .into_full(objects)?; diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 9f1b01bc0..a3a5459ad 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -82,12 +82,11 @@ impl PartialHalfEdge { /// Update the partial half-edge with the given back vertex pub fn with_back_vertex( mut self, - vertex: Option>>, + vertex: impl Into>, ) -> Self { - if let Some(vertex) = vertex { - let [from, _] = &mut self.vertices; - *from = vertex.into(); - } + let [from, _] = &mut self.vertices; + *from = vertex.into(); + self } From 3278ae73ad851ab284aced56853d0247900c4c87 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 5 Nov 2022 20:31:51 +0100 Subject: [PATCH 07/12] Rewrite `PartialCycle::build` to be more clear --- crates/fj-kernel/src/partial/objects/cycle.rs | 72 +++++++++---------- 1 file changed, 34 insertions(+), 38 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/cycle.rs b/crates/fj-kernel/src/partial/objects/cycle.rs index 8e3658b8e..578831c23 100644 --- a/crates/fj-kernel/src/partial/objects/cycle.rs +++ b/crates/fj-kernel/src/partial/objects/cycle.rs @@ -86,51 +86,47 @@ impl PartialCycle { mut self, objects: &Objects, ) -> Result, ValidationError> { - let half_edges = { - let last_vertex = { - let last_half_edge = self - .half_edges - .last_mut() - .expect("Can't build cycle without any half-edges"); + // To create a cycle, we need to make sure that all its half-edges + // connect to each other. Let's start with all the connections between + // the first and the last half-edge. + let mut previous_vertex = None; + for half_edge in &mut self.half_edges { + let back_vertex = previous_vertex.unwrap_or_default(); + let front_vertex = + half_edge.front().surface_form().into_full(objects)?; - let surface_vertex = - last_half_edge.front().surface_form().into_full(objects)?; - - *last_half_edge = last_half_edge.clone().merge_with( - PartialHalfEdge::default().with_front_vertex( + *half_edge = half_edge.clone().merge_with( + PartialHalfEdge::default() + .with_back_vertex( + PartialVertex::default().with_surface_form(back_vertex), + ) + .with_front_vertex( PartialVertex::default() - .with_surface_form(surface_vertex.clone()), + .with_surface_form(front_vertex.clone()), ), - ); + ); - surface_vertex - }; + previous_vertex = Some(MaybePartial::from(front_vertex)); + } - let (half_edges, _) = self.half_edges.into_iter().fold( - Ok((Vec::new(), last_vertex)), - |result: Result<_, ValidationError>, half_edge| { - let (mut half_edges, previous_vertex) = result?; + // We're not quite done yet. We need to close the cycle, by connecting + // the last half-edge back around to the first one. + if let Some(half_edge) = self.half_edges.first_mut() { + let back_vertex = previous_vertex.unwrap_or_default(); - let half_edge = half_edge - .update_partial(|half_edge| { - let [back, _] = half_edge.vertices(); - let back = back.update_partial(|partial| { - partial.with_surface_form(previous_vertex) - }); + *half_edge = half_edge.clone().merge_with( + PartialHalfEdge::default().with_back_vertex( + PartialVertex::default().with_surface_form(back_vertex), + ), + ); + } - half_edge.with_back_vertex(back) - }) - .into_full(objects)?; - - let front = half_edge.front().surface_form().clone(); - half_edges.push(half_edge); - - Ok((half_edges, front)) - }, - )?; - - half_edges - }; + // All connections made! All that's left is to build the half-edges. + let mut half_edges = Vec::new(); + for half_edge in self.half_edges { + let half_edge = half_edge.into_full(objects)?; + half_edges.push(half_edge); + } Ok(objects.cycles.insert(Cycle::new(half_edges))?) } From 076400632c229ded0c04d3523d1581654a6a8fc5 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 5 Nov 2022 21:45:08 +0100 Subject: [PATCH 08/12] Simplify `PartialHalfEdge::with_surface` --- crates/fj-kernel/src/algorithms/sweep/edge.rs | 6 ++-- crates/fj-kernel/src/builder/edge.rs | 2 +- crates/fj-kernel/src/partial/objects/cycle.rs | 2 +- crates/fj-kernel/src/partial/objects/edge.rs | 30 +++++++++---------- crates/fj-operations/src/sketch.rs | 2 +- 5 files changed, 20 insertions(+), 22 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index 2018259de..a4c09f01e 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -219,7 +219,7 @@ mod tests { ) .build(&objects)?; let side_up = HalfEdge::partial() - .with_surface(Some(surface.clone())) + .with_surface(surface.clone()) .with_back_vertex(Vertex::partial().with_surface_form( bottom.front().surface_form().clone(), )) @@ -229,7 +229,7 @@ mod tests { .update_as_line_segment() .build(&objects)?; let top = HalfEdge::partial() - .with_surface(Some(surface.clone())) + .with_surface(surface.clone()) .with_back_vertex(Vertex::partial().with_surface_form( SurfaceVertex::partial().with_position(Some([0., 1.])), )) @@ -241,7 +241,7 @@ mod tests { .reverse(&objects)?; let side_down = HalfEdge::partial() - .with_surface(Some(surface)) + .with_surface(surface) .with_back_vertex(Vertex::partial().with_surface_form( bottom.back().surface_form().clone(), )) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index c47ce959c..e3ab4d1d0 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -97,7 +97,7 @@ impl HalfEdgeBuilder for PartialHalfEdge { Vertex::partial().with_surface_form(surface_form) }); - self.with_surface(Some(surface)) + self.with_surface(surface) .with_vertices(Some(vertices)) .update_as_line_segment() } diff --git a/crates/fj-kernel/src/partial/objects/cycle.rs b/crates/fj-kernel/src/partial/objects/cycle.rs index 578831c23..bc8479abf 100644 --- a/crates/fj-kernel/src/partial/objects/cycle.rs +++ b/crates/fj-kernel/src/partial/objects/cycle.rs @@ -58,7 +58,7 @@ impl PartialCycle { if let Some(surface) = surface { for half_edge in &mut self.half_edges { *half_edge = half_edge.clone().update_partial(|half_edge| { - half_edge.with_surface(Some(surface.clone())) + half_edge.with_surface(surface.clone()) }); } } diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index a3a5459ad..e9704695f 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -47,24 +47,22 @@ impl PartialHalfEdge { } /// Update the partial half-edge with the given surface - pub fn with_surface(mut self, surface: Option>) -> Self { - if let Some(surface) = surface { - self.curve = self.curve.update_partial(|curve| { - curve.with_surface(Some(surface.clone())) - }); + pub fn with_surface(mut self, surface: Handle) -> Self { + self.curve = self + .curve + .update_partial(|curve| curve.with_surface(Some(surface.clone()))); - self.vertices = self.vertices.map(|vertex| { - vertex.update_partial(|vertex| { - let surface_form = vertex.surface_form().update_partial( - |surface_vertex| { - surface_vertex.with_surface(Some(surface.clone())) - }, - ); + self.vertices = self.vertices.map(|vertex| { + vertex.update_partial(|vertex| { + let surface_form = + vertex.surface_form().update_partial(|surface_vertex| { + surface_vertex.with_surface(Some(surface.clone())) + }); + + vertex.with_surface_form(surface_form) + }) + }); - vertex.with_surface_form(surface_form) - }) - }); - } self } diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index 0250d1184..8e838ec2b 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -28,7 +28,7 @@ impl Shape for fj::Sketch { // none need to be added here. let half_edge = HalfEdge::partial() - .with_surface(Some(surface)) + .with_surface(surface) .update_as_circle_from_radius(circle.radius(), objects)? .build(objects)?; let cycle = objects.cycles.insert(Cycle::new([half_edge]))?; From 421e03efda040108a6220509512c7f6fbec43a4a Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 5 Nov 2022 21:46:40 +0100 Subject: [PATCH 09/12] Simplify `PartialHalfEdge::with_curve` --- crates/fj-kernel/src/algorithms/transform/edge.rs | 2 +- crates/fj-kernel/src/builder/cycle.rs | 2 +- crates/fj-kernel/src/builder/edge.rs | 7 ++----- crates/fj-kernel/src/builder/shell.rs | 2 +- crates/fj-kernel/src/partial/objects/edge.rs | 10 +++------- 5 files changed, 8 insertions(+), 15 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/edge.rs b/crates/fj-kernel/src/algorithms/transform/edge.rs index 71c72a8d1..9ff8ca2ac 100644 --- a/crates/fj-kernel/src/algorithms/transform/edge.rs +++ b/crates/fj-kernel/src/algorithms/transform/edge.rs @@ -36,7 +36,7 @@ impl TransformObject for PartialHalfEdge { .into(); Ok(Self::default() - .with_curve(Some(curve)) + .with_curve(curve) .with_vertices(Some(vertices)) .with_global_form(global_form)) } diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index afca811b6..e123c457b 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -81,7 +81,7 @@ impl CycleBuilder for PartialCycle { half_edges.push( HalfEdge::partial() - .with_curve(Some(curve)) + .with_curve(curve) .with_vertices(Some([from, to])), ); diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index e3ab4d1d0..8fd977874 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -79,9 +79,7 @@ impl HalfEdgeBuilder for PartialHalfEdge { .with_surface_form(surface_vertex.clone()) }); - Ok(self - .with_curve(Some(curve)) - .with_vertices(Some([back, front]))) + Ok(self.with_curve(curve).with_vertices(Some([back, front]))) } fn update_as_line_segment_from_points( @@ -181,8 +179,7 @@ impl HalfEdgeBuilder for PartialHalfEdge { }) }; - self.with_curve(Some(curve)) - .with_vertices(Some([back, front])) + self.with_curve(curve).with_vertices(Some([back, front])) } } diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index 4ae6ef6c8..98c593442 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -148,7 +148,7 @@ impl<'a> ShellBuilder<'a> { )); HalfEdge::partial() - .with_curve(Some(curve)) + .with_curve(curve) .with_vertices(Some([ Vertex::partial().with_surface_form(from), Vertex::partial().with_surface_form(to), diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index e9704695f..26ece8472 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -67,13 +67,9 @@ impl PartialHalfEdge { } /// Update the partial half-edge with the given curve - pub fn with_curve( - mut self, - curve: Option>>, - ) -> Self { - if let Some(curve) = curve { - self.curve = curve.into(); - } + pub fn with_curve(mut self, curve: impl Into>) -> Self { + self.curve = curve.into(); + self } From 5ccea9e80e13c3dbf24d7d205dc2583e9ae9da5a Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 5 Nov 2022 21:49:12 +0100 Subject: [PATCH 10/12] Simplify `PartialHalfEdge::with_vertices` --- crates/fj-kernel/src/algorithms/transform/edge.rs | 2 +- crates/fj-kernel/src/builder/cycle.rs | 2 +- crates/fj-kernel/src/builder/edge.rs | 6 +++--- crates/fj-kernel/src/builder/shell.rs | 12 ++++++------ crates/fj-kernel/src/partial/objects/edge.rs | 7 ++----- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/edge.rs b/crates/fj-kernel/src/algorithms/transform/edge.rs index 9ff8ca2ac..265baa084 100644 --- a/crates/fj-kernel/src/algorithms/transform/edge.rs +++ b/crates/fj-kernel/src/algorithms/transform/edge.rs @@ -37,7 +37,7 @@ impl TransformObject for PartialHalfEdge { Ok(Self::default() .with_curve(curve) - .with_vertices(Some(vertices)) + .with_vertices(vertices) .with_global_form(global_form)) } } diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index e123c457b..0052f9f98 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -82,7 +82,7 @@ impl CycleBuilder for PartialCycle { half_edges.push( HalfEdge::partial() .with_curve(curve) - .with_vertices(Some([from, to])), + .with_vertices([from, to]), ); continue; diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 8fd977874..f8e258842 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -79,7 +79,7 @@ impl HalfEdgeBuilder for PartialHalfEdge { .with_surface_form(surface_vertex.clone()) }); - Ok(self.with_curve(curve).with_vertices(Some([back, front]))) + Ok(self.with_curve(curve).with_vertices([back, front])) } fn update_as_line_segment_from_points( @@ -96,7 +96,7 @@ impl HalfEdgeBuilder for PartialHalfEdge { }); self.with_surface(surface) - .with_vertices(Some(vertices)) + .with_vertices(vertices) .update_as_line_segment() } @@ -179,7 +179,7 @@ impl HalfEdgeBuilder for PartialHalfEdge { }) }; - self.with_curve(curve).with_vertices(Some([back, front])) + self.with_curve(curve).with_vertices([back, front]) } } diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index 98c593442..59007984d 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -112,10 +112,10 @@ impl<'a> ShellBuilder<'a> { .with_surface(Some(surface.clone())); HalfEdge::partial() - .with_vertices(Some([ + .with_vertices([ Vertex::partial().with_surface_form(from), Vertex::partial().with_surface_form(to), - ])) + ]) .update_as_line_segment() .build(self.objects) .unwrap() @@ -149,10 +149,10 @@ impl<'a> ShellBuilder<'a> { HalfEdge::partial() .with_curve(curve) - .with_vertices(Some([ + .with_vertices([ Vertex::partial().with_surface_form(from), Vertex::partial().with_surface_form(to), - ])) + ]) .update_as_line_segment() .build(self.objects) .unwrap() @@ -175,7 +175,7 @@ impl<'a> ShellBuilder<'a> { let to = Vertex::partial().with_surface_form(to); HalfEdge::partial() - .with_vertices(Some([from, to])) + .with_vertices([from, to]) .update_as_line_segment() .build(self.objects) .unwrap() @@ -251,7 +251,7 @@ impl<'a> ShellBuilder<'a> { edges.push( HalfEdge::partial() - .with_vertices(Some(vertices)) + .with_vertices(vertices) .with_global_form(Some(edge.global_form().clone())) .update_as_line_segment() .build(self.objects) diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 26ece8472..19161235f 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -98,12 +98,9 @@ impl PartialHalfEdge { /// Update the partial half-edge with the given vertices pub fn with_vertices( mut self, - vertices: Option<[impl Into>; 2]>, + vertices: [impl Into>; 2], ) -> Self { - let vertices = vertices.map(|vertices| vertices.map(Into::into)); - if let Some([back, front]) = vertices { - self.vertices = [back, front]; - } + self.vertices = vertices.map(Into::into); self } From 18e1fb6eb3d4e81d416fb1b182de2c686e5ca3e2 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 5 Nov 2022 21:50:29 +0100 Subject: [PATCH 11/12] Simplify `PartialHalfEdge::with_global_form` --- crates/fj-kernel/src/algorithms/transform/edge.rs | 3 +-- crates/fj-kernel/src/builder/shell.rs | 4 ++-- crates/fj-kernel/src/partial/objects/edge.rs | 7 +++---- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/edge.rs b/crates/fj-kernel/src/algorithms/transform/edge.rs index 265baa084..3a9bc69e8 100644 --- a/crates/fj-kernel/src/algorithms/transform/edge.rs +++ b/crates/fj-kernel/src/algorithms/transform/edge.rs @@ -32,8 +32,7 @@ impl TransformObject for PartialHalfEdge { .global_form() .into_partial() .transform(transform, objects)? - .with_curve(curve.global_form()) - .into(); + .with_curve(curve.global_form()); Ok(Self::default() .with_curve(curve) diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index 59007984d..9c6d1629b 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -89,7 +89,7 @@ impl<'a> ShellBuilder<'a> { .zip(&surfaces) .map(|(half_edge, surface)| { HalfEdge::partial() - .with_global_form(Some(half_edge.global_form().clone())) + .with_global_form(half_edge.global_form().clone()) .update_as_line_segment_from_points( surface.clone(), [[Z, Z], [edge_length, Z]], @@ -252,7 +252,7 @@ impl<'a> ShellBuilder<'a> { edges.push( HalfEdge::partial() .with_vertices(vertices) - .with_global_form(Some(edge.global_form().clone())) + .with_global_form(edge.global_form().clone()) .update_as_line_segment() .build(self.objects) .unwrap(), diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 19161235f..02c60af4b 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -107,11 +107,10 @@ impl PartialHalfEdge { /// Update the partial half-edge with the given global form pub fn with_global_form( mut self, - global_form: Option>>, + global_form: impl Into>, ) -> Self { - if let Some(global_form) = global_form { - self.global_form = global_form.into(); - } + self.global_form = global_form.into(); + self } From 9ba8e987359b3f235ecf32b530a79b7dc42a419a Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 5 Nov 2022 21:59:56 +0100 Subject: [PATCH 12/12] Simplify `PartialVertex::with_curve` --- crates/fj-kernel/src/algorithms/sweep/vertex.rs | 2 +- crates/fj-kernel/src/algorithms/transform/edge.rs | 2 +- crates/fj-kernel/src/algorithms/transform/vertex.rs | 2 +- crates/fj-kernel/src/builder/cycle.rs | 2 +- crates/fj-kernel/src/builder/edge.rs | 4 ++-- crates/fj-kernel/src/partial/objects/edge.rs | 2 +- crates/fj-kernel/src/partial/objects/vertex.rs | 9 ++------- crates/fj-kernel/src/validate/edge.rs | 2 +- crates/fj-kernel/src/validate/vertex.rs | 8 ++++---- 9 files changed, 14 insertions(+), 19 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/vertex.rs b/crates/fj-kernel/src/algorithms/sweep/vertex.rs index f348b561d..e99c493bc 100644 --- a/crates/fj-kernel/src/algorithms/sweep/vertex.rs +++ b/crates/fj-kernel/src/algorithms/sweep/vertex.rs @@ -184,7 +184,7 @@ mod tests { .build(&objects)?; let vertex = Vertex::partial() .with_position(Some([0.])) - .with_curve(Some(curve)) + .with_curve(curve) .build(&objects)?; let half_edge = diff --git a/crates/fj-kernel/src/algorithms/transform/edge.rs b/crates/fj-kernel/src/algorithms/transform/edge.rs index 3a9bc69e8..5e96fbc03 100644 --- a/crates/fj-kernel/src/algorithms/transform/edge.rs +++ b/crates/fj-kernel/src/algorithms/transform/edge.rs @@ -25,7 +25,7 @@ impl TransformObject for PartialHalfEdge { Ok(vertex .into_partial() .transform(transform, objects)? - .with_curve(Some(curve.clone()))) + .with_curve(curve.clone())) }, )?; let global_form = self diff --git a/crates/fj-kernel/src/algorithms/transform/vertex.rs b/crates/fj-kernel/src/algorithms/transform/vertex.rs index a86753e0d..b9db0f704 100644 --- a/crates/fj-kernel/src/algorithms/transform/vertex.rs +++ b/crates/fj-kernel/src/algorithms/transform/vertex.rs @@ -24,7 +24,7 @@ impl TransformObject for PartialVertex { // coordinates and thus transforming the curve takes care of it. Ok(Self::default() .with_position(self.position()) - .with_curve(Some(curve)) + .with_curve(curve) .with_surface_form(surface_form)) } } diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 0052f9f98..a2b5ca081 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -74,7 +74,7 @@ impl CycleBuilder for PartialCycle { let [from, to] = [(0., from), (1., to)].map(|(position, surface_form)| { Vertex::partial() - .with_curve(Some(curve.clone())) + .with_curve(curve.clone()) .with_position(Some([position])) .with_surface_form(surface_form) }); diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index f8e258842..f85b1bc45 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -75,7 +75,7 @@ impl HalfEdgeBuilder for PartialHalfEdge { let [back, front] = [a_curve, b_curve].map(|point_curve| { Vertex::partial() .with_position(Some(point_curve)) - .with_curve(Some(curve.clone())) + .with_curve(curve.clone()) .with_surface_form(surface_vertex.clone()) }); @@ -127,7 +127,7 @@ impl HalfEdgeBuilder for PartialHalfEdge { vertex.update_partial(|vertex| { vertex .with_position(Some([position])) - .with_curve(Some(curve.clone())) + .with_curve(curve.clone()) }) }); diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 02c60af4b..7b5ffe3c9 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -131,7 +131,7 @@ impl PartialHalfEdge { let curve = self.curve.into_full(objects)?; let vertices = self.vertices.try_map_ext(|vertex| { vertex - .update_partial(|vertex| vertex.with_curve(Some(curve.clone()))) + .update_partial(|vertex| vertex.with_curve(curve.clone())) .into_full(objects) })?; diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index 8cad7c7ca..f3cd84539 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -46,13 +46,8 @@ impl PartialVertex { } /// Provide a curve for the partial vertex - pub fn with_curve( - mut self, - curve: Option>>, - ) -> Self { - if let Some(curve) = curve { - self.curve = curve.into(); - } + pub fn with_curve(mut self, curve: impl Into>) -> Self { + self.curve = curve.into(); self } diff --git a/crates/fj-kernel/src/validate/edge.rs b/crates/fj-kernel/src/validate/edge.rs index ffc50c29f..2babcdf94 100644 --- a/crates/fj-kernel/src/validate/edge.rs +++ b/crates/fj-kernel/src/validate/edge.rs @@ -217,7 +217,7 @@ mod tests { vertices[1] = vertices[1] .to_partial() // Arranging for an equal but not identical curve here. - .with_curve(Some(valid.curve().to_partial())) + .with_curve(valid.curve().to_partial()) .build(&objects)?; HalfEdge::new(vertices, valid.global_form().clone()) diff --git a/crates/fj-kernel/src/validate/vertex.rs b/crates/fj-kernel/src/validate/vertex.rs index 075c57cf1..3055f88fa 100644 --- a/crates/fj-kernel/src/validate/vertex.rs +++ b/crates/fj-kernel/src/validate/vertex.rs @@ -191,11 +191,11 @@ mod tests { let valid = Vertex::partial() .with_position(Some([0.])) - .with_curve(Some( + .with_curve( Curve::partial() .with_surface(Some(objects.surfaces.xy_plane())) .update_as_u_axis(), - )) + ) .build(&objects)?; let invalid = Vertex::new( valid.position(), @@ -219,11 +219,11 @@ mod tests { let valid = Vertex::partial() .with_position(Some([0.])) - .with_curve(Some( + .with_curve( Curve::partial() .with_surface(Some(objects.surfaces.xy_plane())) .update_as_u_axis(), - )) + ) .build(&objects)?; let invalid = Vertex::new( valid.position(),