From 9ba8e987359b3f235ecf32b530a79b7dc42a419a Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 5 Nov 2022 21:59:56 +0100 Subject: [PATCH] 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(),