From 7e5500a884b448c8fc7c9e3d241b25630368b007 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 14:49:20 +0100 Subject: [PATCH] Change style of `update_as_u_axis` --- .../src/algorithms/intersect/curve_edge.rs | 32 ++++++++--------- .../algorithms/intersect/surface_surface.rs | 18 +++++----- .../fj-kernel/src/algorithms/sweep/vertex.rs | 9 +++-- crates/fj-kernel/src/builder/curve.rs | 7 ++-- crates/fj-kernel/src/iter.rs | 18 +++++----- crates/fj-kernel/src/validate/vertex.rs | 36 ++++++++++--------- 6 files changed, 58 insertions(+), 62 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs b/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs index 1b6d14a8b..ac53e7fff 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs @@ -87,12 +87,12 @@ mod tests { let objects = Objects::new(); let surface = objects.surfaces.xy_plane(); - let curve = PartialCurve { + let mut curve = PartialCurve { surface: Some(surface.clone()), ..Default::default() - } - .update_as_u_axis() - .build(&objects)?; + }; + curve.update_as_u_axis(); + let curve = curve.build(&objects)?; let half_edge = HalfEdge::partial() .update_as_line_segment_from_points(surface, [[1., -1.], [1., 1.]]) .build(&objects)?; @@ -113,12 +113,12 @@ mod tests { let objects = Objects::new(); let surface = objects.surfaces.xy_plane(); - let curve = PartialCurve { + let mut curve = PartialCurve { surface: Some(surface.clone()), ..Default::default() - } - .update_as_u_axis() - .build(&objects)?; + }; + curve.update_as_u_axis(); + let curve = curve.build(&objects)?; let half_edge = HalfEdge::partial() .update_as_line_segment_from_points( surface, @@ -142,12 +142,12 @@ mod tests { let objects = Objects::new(); let surface = objects.surfaces.xy_plane(); - let curve = PartialCurve { + let mut curve = PartialCurve { surface: Some(surface.clone()), ..Default::default() - } - .update_as_u_axis() - .build(&objects)?; + }; + curve.update_as_u_axis(); + let curve = curve.build(&objects)?; let half_edge = HalfEdge::partial() .update_as_line_segment_from_points( surface, @@ -166,12 +166,12 @@ mod tests { let objects = Objects::new(); let surface = objects.surfaces.xy_plane(); - let curve = PartialCurve { + let mut curve = PartialCurve { surface: Some(surface.clone()), ..Default::default() - } - .update_as_u_axis() - .build(&objects)?; + }; + curve.update_as_u_axis(); + let curve = curve.build(&objects)?; let half_edge = HalfEdge::partial() .update_as_line_segment_from_points(surface, [[-1., 0.], [1., 0.]]) .build(&objects)?; diff --git a/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs b/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs index ebc7c2d16..43ed585d6 100644 --- a/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs +++ b/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs @@ -119,20 +119,18 @@ mod tests { None, ); - let expected_xy = PartialCurve { + let mut expected_xy = PartialCurve { surface: Some(xy.clone()), ..Default::default() - } - .update_as_u_axis() - .build(&objects)? - .insert(&objects)?; - let expected_xz = PartialCurve { + }; + expected_xy.update_as_u_axis(); + let expected_xy = expected_xy.build(&objects)?.insert(&objects)?; + let mut expected_xz = PartialCurve { surface: Some(xz.clone()), ..Default::default() - } - .update_as_u_axis() - .build(&objects)? - .insert(&objects)?; + }; + expected_xz.update_as_u_axis(); + let expected_xz = expected_xz.build(&objects)?.insert(&objects)?; assert_eq!( SurfaceSurfaceIntersection::compute([xy, xz], &objects)?, diff --git a/crates/fj-kernel/src/algorithms/sweep/vertex.rs b/crates/fj-kernel/src/algorithms/sweep/vertex.rs index 750a0c338..69c557727 100644 --- a/crates/fj-kernel/src/algorithms/sweep/vertex.rs +++ b/crates/fj-kernel/src/algorithms/sweep/vertex.rs @@ -179,13 +179,12 @@ mod tests { let objects = Objects::new(); let surface = objects.surfaces.xz_plane(); - let curve = PartialCurve { + let mut curve = PartialCurve { surface: Some(surface.clone()), ..Default::default() - } - .update_as_u_axis() - .build(&objects)? - .insert(&objects)?; + }; + curve.update_as_u_axis(); + let curve = curve.build(&objects)?.insert(&objects)?; let vertex = Vertex::partial() .with_position(Some([0.])) .with_curve(curve) diff --git a/crates/fj-kernel/src/builder/curve.rs b/crates/fj-kernel/src/builder/curve.rs index 2e6b15827..1380bfff8 100644 --- a/crates/fj-kernel/src/builder/curve.rs +++ b/crates/fj-kernel/src/builder/curve.rs @@ -5,7 +5,7 @@ use crate::{partial::PartialCurve, path::SurfacePath}; /// Builder API for [`PartialCurve`] pub trait CurveBuilder { /// Update partial curve to represent the u-axis - fn update_as_u_axis(self) -> Self; + fn update_as_u_axis(&mut self) -> &mut Self; /// Update partial curve to represent the v-axis fn update_as_v_axis(&mut self) -> &mut Self; @@ -24,12 +24,11 @@ pub trait CurveBuilder { } impl CurveBuilder for PartialCurve { - fn update_as_u_axis(mut self) -> Self { + fn update_as_u_axis(&mut self) -> &mut Self { let a = Point::origin(); let b = a + Vector::unit_u(); - self.update_as_line_from_points([a, b]); - self + self.update_as_line_from_points([a, b]) } fn update_as_v_axis(&mut self) -> &mut Self { diff --git a/crates/fj-kernel/src/iter.rs b/crates/fj-kernel/src/iter.rs index b3bbc65ac..f68e0c1c6 100644 --- a/crates/fj-kernel/src/iter.rs +++ b/crates/fj-kernel/src/iter.rs @@ -376,13 +376,12 @@ mod tests { let objects = Objects::new(); let surface = objects.surfaces.xy_plane(); - let object = PartialCurve { + let mut object = PartialCurve { surface: Some(surface), ..Default::default() - } - .update_as_u_axis() - .build(&objects)? - .insert(&objects)?; + }; + object.update_as_u_axis(); + let object = object.build(&objects)?.insert(&objects)?; assert_eq!(1, object.curve_iter().count()); assert_eq!(0, object.cycle_iter().count()); @@ -618,13 +617,12 @@ mod tests { let objects = Objects::new(); let surface = objects.surfaces.xy_plane(); - let curve = PartialCurve { + let mut curve = PartialCurve { surface: Some(surface.clone()), ..Default::default() - } - .update_as_u_axis() - .build(&objects)? - .insert(&objects)?; + }; + curve.update_as_u_axis(); + let curve = curve.build(&objects)?.insert(&objects)?; let global_vertex = objects .global_vertices .insert(GlobalVertex::from_position([0., 0., 0.]))?; diff --git a/crates/fj-kernel/src/validate/vertex.rs b/crates/fj-kernel/src/validate/vertex.rs index 2d04eab55..6b76257b1 100644 --- a/crates/fj-kernel/src/validate/vertex.rs +++ b/crates/fj-kernel/src/validate/vertex.rs @@ -190,15 +190,15 @@ mod tests { fn vertex_surface_mismatch() -> anyhow::Result<()> { let objects = Objects::new(); + let mut curve = PartialCurve { + surface: Some(objects.surfaces.xy_plane()), + ..Default::default() + }; + curve.update_as_u_axis(); + let valid = Vertex::partial() .with_position(Some([0.])) - .with_curve( - PartialCurve { - surface: Some(objects.surfaces.xy_plane()), - ..Default::default() - } - .update_as_u_axis(), - ) + .with_curve(curve) .build(&objects)?; let invalid = Vertex::new( valid.position(), @@ -221,16 +221,18 @@ mod tests { fn vertex_position_mismatch() -> anyhow::Result<()> { let objects = Objects::new(); - let valid = Vertex::partial() - .with_position(Some([0.])) - .with_curve( - PartialCurve { - surface: Some(objects.surfaces.xy_plane()), - ..Default::default() - } - .update_as_u_axis(), - ) - .build(&objects)?; + let valid = { + let mut curve = PartialCurve { + surface: Some(objects.surfaces.xy_plane()), + ..Default::default() + }; + curve.update_as_u_axis(); + + Vertex::partial() + .with_position(Some([0.])) + .with_curve(curve) + .build(&objects)? + }; let invalid = Vertex::new( valid.position(), valid.curve().clone(),