From 00527992ca6fc6ae7c5dc6f0189ea69f90bfbcfe Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 14:14:48 +0100 Subject: [PATCH 01/10] Make fields of `PartialCurve` public --- crates/fj-kernel/src/partial/objects/curve.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/curve.rs b/crates/fj-kernel/src/partial/objects/curve.rs index 233b6b2c7..0b3729aa8 100644 --- a/crates/fj-kernel/src/partial/objects/curve.rs +++ b/crates/fj-kernel/src/partial/objects/curve.rs @@ -11,9 +11,14 @@ use crate::{ /// See [`crate::partial`] for more information. #[derive(Clone, Debug, Default)] pub struct PartialCurve { - path: Option, - surface: Option>, - global_form: Option>, + /// The path that defines the [`Curve`] + pub path: Option, + + /// The surface that the [`Curve`] is defined in + pub surface: Option>, + + /// The global form of the [`Curve`] + pub global_form: Option>, } impl PartialCurve { From 6772f0d5598d2825dd8f635429f9ac29c870dc4f Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 14:15:12 +0100 Subject: [PATCH 02/10] Remove `PartialCurve` getters --- .../fj-kernel/src/algorithms/transform/curve.rs | 6 +++--- crates/fj-kernel/src/builder/edge.rs | 4 ++-- crates/fj-kernel/src/builder/vertex.rs | 4 ++-- crates/fj-kernel/src/partial/maybe_partial.rs | 6 +++--- crates/fj-kernel/src/partial/objects/curve.rs | 15 --------------- 5 files changed, 10 insertions(+), 25 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/curve.rs b/crates/fj-kernel/src/algorithms/transform/curve.rs index 109002f10..960114022 100644 --- a/crates/fj-kernel/src/algorithms/transform/curve.rs +++ b/crates/fj-kernel/src/algorithms/transform/curve.rs @@ -29,11 +29,11 @@ impl TransformObject for PartialCurve { objects: &Objects, ) -> Result { let surface = self - .surface() + .surface .map(|surface| surface.transform(transform, objects)) .transpose()?; let global_form = self - .global_form() + .global_form .map(|global_form| global_form.transform(transform, objects)) .transpose()?; @@ -41,7 +41,7 @@ impl TransformObject for PartialCurve { // coordinates, and thus transforming `surface` takes care of it. Ok(Self::default() .with_surface(surface) - .with_path(self.path()) + .with_path(self.path) .with_global_form(global_form)) } } diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 928583ca0..9a7eab91e 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -71,7 +71,7 @@ impl HalfEdgeBuilder for PartialHalfEdge { .with_global_form(Some(self.extract_global_curve())) .update_as_circle_from_radius(radius); - let path = curve.path().expect("Expected path that was just created"); + let path = curve.path.expect("Expected path that was just created"); let [a_curve, b_curve] = [Scalar::ZERO, Scalar::TAU].map(|coord| Point::from([coord])); @@ -88,7 +88,7 @@ impl HalfEdgeBuilder for PartialHalfEdge { let surface_vertex = SurfaceVertex::partial() .with_position(Some(path.point_from_path_coords(a_curve))) - .with_surface(curve.surface()) + .with_surface(curve.surface.clone()) .with_global_form(Some(global_vertex)) .build(objects)? .insert(objects)?; diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index 813268a74..ca2776ff8 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -57,10 +57,10 @@ impl GlobalVertexBuilder for PartialGlobalVertex { ) -> Self { let curve = curve.into().into_partial(); - let path = curve.path().expect( + let path = curve.path.expect( "Need path to create `GlobalVertex` from curve and position", ); - let surface = curve.surface().expect( + let surface = curve.surface.expect( "Need surface to create `GlobalVertex` from curve and position", ); diff --git a/crates/fj-kernel/src/partial/maybe_partial.rs b/crates/fj-kernel/src/partial/maybe_partial.rs index 03caa5e6c..3db76684d 100644 --- a/crates/fj-kernel/src/partial/maybe_partial.rs +++ b/crates/fj-kernel/src/partial/maybe_partial.rs @@ -142,7 +142,7 @@ impl MaybePartial { pub fn path(&self) -> Option { match self { MaybePartial::Full(full) => Some(full.path()), - MaybePartial::Partial(partial) => partial.path(), + MaybePartial::Partial(partial) => partial.path, } } @@ -150,7 +150,7 @@ impl MaybePartial { pub fn surface(&self) -> Option> { match self { MaybePartial::Full(full) => Some(full.surface().clone()), - MaybePartial::Partial(partial) => partial.surface(), + MaybePartial::Partial(partial) => partial.surface.clone(), } } @@ -158,7 +158,7 @@ impl MaybePartial { pub fn global_form(&self) -> Option> { match self { Self::Full(full) => Some(full.global_form().clone().into()), - Self::Partial(partial) => partial.global_form(), + Self::Partial(partial) => partial.global_form.clone(), } } } diff --git a/crates/fj-kernel/src/partial/objects/curve.rs b/crates/fj-kernel/src/partial/objects/curve.rs index 0b3729aa8..18d6ab5bf 100644 --- a/crates/fj-kernel/src/partial/objects/curve.rs +++ b/crates/fj-kernel/src/partial/objects/curve.rs @@ -22,21 +22,6 @@ pub struct PartialCurve { } impl PartialCurve { - /// Access the path that defines the [`Curve`] - pub fn path(&self) -> Option { - self.path - } - - /// Access the surface that the [`Curve`] is defined in - pub fn surface(&self) -> Option> { - self.surface.clone() - } - - /// Access the global form of the [`Curve`] - pub fn global_form(&self) -> Option> { - self.global_form.clone() - } - /// Provide a path for the partial curve pub fn with_path(mut self, path: Option) -> Self { if let Some(path) = path { From a1638400df304157a8abca0745a1a74f25576c11 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 14:24:38 +0100 Subject: [PATCH 03/10] Remove `PartialCurve::with_path` --- crates/fj-kernel/src/algorithms/transform/curve.rs | 10 ++++++---- crates/fj-kernel/src/builder/curve.rs | 10 ++++++++-- crates/fj-kernel/src/partial/objects/curve.rs | 8 -------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/curve.rs b/crates/fj-kernel/src/algorithms/transform/curve.rs index 960114022..ce81ca8d9 100644 --- a/crates/fj-kernel/src/algorithms/transform/curve.rs +++ b/crates/fj-kernel/src/algorithms/transform/curve.rs @@ -39,9 +39,11 @@ impl TransformObject for PartialCurve { // Don't need to transform `self.path`, as that's defined in surface // coordinates, and thus transforming `surface` takes care of it. - Ok(Self::default() - .with_surface(surface) - .with_path(self.path) - .with_global_form(global_form)) + Ok(PartialCurve { + path: self.path, + ..Default::default() + } + .with_surface(surface) + .with_global_form(global_form)) } } diff --git a/crates/fj-kernel/src/builder/curve.rs b/crates/fj-kernel/src/builder/curve.rs index 9135009e6..b9e93097b 100644 --- a/crates/fj-kernel/src/builder/curve.rs +++ b/crates/fj-kernel/src/builder/curve.rs @@ -36,13 +36,19 @@ impl CurveBuilder for PartialCurve { } fn update_as_circle_from_radius(self, radius: impl Into) -> Self { - self.with_path(Some(SurfacePath::circle_from_radius(radius))) + Self { + path: Some(SurfacePath::circle_from_radius(radius)), + ..self + } } fn update_as_line_from_points( self, points: [impl Into>; 2], ) -> Self { - self.with_path(Some(SurfacePath::line_from_points(points))) + Self { + path: Some(SurfacePath::line_from_points(points)), + ..self + } } } diff --git a/crates/fj-kernel/src/partial/objects/curve.rs b/crates/fj-kernel/src/partial/objects/curve.rs index 18d6ab5bf..3a6b3986b 100644 --- a/crates/fj-kernel/src/partial/objects/curve.rs +++ b/crates/fj-kernel/src/partial/objects/curve.rs @@ -22,14 +22,6 @@ pub struct PartialCurve { } impl PartialCurve { - /// Provide a path for the partial curve - pub fn with_path(mut self, path: Option) -> Self { - if let Some(path) = path { - self.path = Some(path); - } - self - } - /// Provide a surface for the partial curve pub fn with_surface(mut self, surface: Option>) -> Self { if let Some(surface) = surface { From 8524c2f773745b98c8027c26af40953d2e8c8a1d Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 14:29:11 +0100 Subject: [PATCH 04/10] Remove `PartialCurve::with_surface` --- .../fj-kernel/src/algorithms/approx/curve.rs | 52 +++++++++++-------- .../src/algorithms/intersect/curve_edge.rs | 44 +++++++++------- .../src/algorithms/intersect/curve_face.rs | 14 ++--- .../src/algorithms/intersect/face_face.rs | 16 +++--- .../algorithms/intersect/surface_surface.rs | 31 +++++------ .../fj-kernel/src/algorithms/sweep/vertex.rs | 16 +++--- .../src/algorithms/transform/curve.rs | 2 +- crates/fj-kernel/src/builder/cycle.rs | 12 +++-- crates/fj-kernel/src/builder/edge.rs | 15 ++++-- crates/fj-kernel/src/iter.rs | 30 ++++++----- crates/fj-kernel/src/partial/objects/curve.rs | 8 --- crates/fj-kernel/src/partial/objects/edge.rs | 7 +-- crates/fj-kernel/src/validate/vertex.rs | 20 ++++--- 13 files changed, 149 insertions(+), 118 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/curve.rs b/crates/fj-kernel/src/algorithms/approx/curve.rs index 16f9e26e4..45b893d20 100644 --- a/crates/fj-kernel/src/algorithms/approx/curve.rs +++ b/crates/fj-kernel/src/algorithms/approx/curve.rs @@ -199,8 +199,8 @@ mod tests { algorithms::approx::{path::RangeOnPath, Approx, ApproxPoint}, builder::CurveBuilder, insert::Insert, - objects::{Curve, Objects, Surface}, - partial::HasPartial, + objects::{Objects, Surface}, + partial::PartialCurve, path::GlobalPath, }; @@ -213,11 +213,13 @@ mod tests { let surface = objects .surfaces .insert(Surface::new(GlobalPath::x_axis(), [0., 0., 1.]))?; - let curve = Curve::partial() - .with_surface(Some(surface)) - .update_as_line_from_points([[1., 1.], [2., 1.]]) - .build(&objects)? - .insert(&objects)?; + let curve = PartialCurve { + surface: Some(surface), + ..Default::default() + } + .update_as_line_from_points([[1., 1.], [2., 1.]]) + .build(&objects)? + .insert(&objects)?; let range = RangeOnPath::from([[0.], [1.]]); let approx = (&curve, range).approx(1.); @@ -235,11 +237,13 @@ mod tests { GlobalPath::circle_from_radius(1.), [0., 0., 1.], ))?; - let curve = Curve::partial() - .with_surface(Some(surface)) - .update_as_line_from_points([[1., 1.], [1., 2.]]) - .build(&objects)? - .insert(&objects)?; + let curve = PartialCurve { + surface: Some(surface), + ..Default::default() + } + .update_as_line_from_points([[1., 1.], [1., 2.]]) + .build(&objects)? + .insert(&objects)?; let range = RangeOnPath::from([[0.], [1.]]); let approx = (&curve, range).approx(1.); @@ -255,11 +259,13 @@ mod tests { let path = GlobalPath::circle_from_radius(1.); let surface = objects.surfaces.insert(Surface::new(path, [0., 0., 1.]))?; - let curve = Curve::partial() - .with_surface(Some(surface.clone())) - .update_as_line_from_points([[0., 1.], [1., 1.]]) - .build(&objects)? - .insert(&objects)?; + let curve = PartialCurve { + surface: Some(surface.clone()), + ..Default::default() + } + .update_as_line_from_points([[0., 1.], [1., 1.]]) + .build(&objects)? + .insert(&objects)?; let range = RangeOnPath::from([[0.], [TAU]]); let tolerance = 1.; @@ -288,11 +294,13 @@ mod tests { let surface = objects .surfaces .insert(Surface::new(GlobalPath::x_axis(), [0., 0., 1.]))?; - let curve = Curve::partial() - .with_surface(Some(surface)) - .update_as_circle_from_radius(1.) - .build(&objects)? - .insert(&objects)?; + let curve = PartialCurve { + surface: Some(surface), + ..Default::default() + } + .update_as_circle_from_radius(1.) + .build(&objects)? + .insert(&objects)?; let range = RangeOnPath::from([[0.], [TAU]]); let tolerance = 1.; diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs b/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs index 4b6376820..1b6d14a8b 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs @@ -76,8 +76,8 @@ mod tests { use crate::{ builder::{CurveBuilder, HalfEdgeBuilder}, - objects::{Curve, HalfEdge, Objects}, - partial::HasPartial, + objects::{HalfEdge, Objects}, + partial::{HasPartial, PartialCurve}, }; use super::CurveEdgeIntersection; @@ -87,10 +87,12 @@ mod tests { let objects = Objects::new(); let surface = objects.surfaces.xy_plane(); - let curve = Curve::partial() - .with_surface(Some(surface.clone())) - .update_as_u_axis() - .build(&objects)?; + let curve = PartialCurve { + surface: Some(surface.clone()), + ..Default::default() + } + .update_as_u_axis() + .build(&objects)?; let half_edge = HalfEdge::partial() .update_as_line_segment_from_points(surface, [[1., -1.], [1., 1.]]) .build(&objects)?; @@ -111,10 +113,12 @@ mod tests { let objects = Objects::new(); let surface = objects.surfaces.xy_plane(); - let curve = Curve::partial() - .with_surface(Some(surface.clone())) - .update_as_u_axis() - .build(&objects)?; + let curve = PartialCurve { + surface: Some(surface.clone()), + ..Default::default() + } + .update_as_u_axis() + .build(&objects)?; let half_edge = HalfEdge::partial() .update_as_line_segment_from_points( surface, @@ -138,10 +142,12 @@ mod tests { let objects = Objects::new(); let surface = objects.surfaces.xy_plane(); - let curve = Curve::partial() - .with_surface(Some(surface.clone())) - .update_as_u_axis() - .build(&objects)?; + let curve = PartialCurve { + surface: Some(surface.clone()), + ..Default::default() + } + .update_as_u_axis() + .build(&objects)?; let half_edge = HalfEdge::partial() .update_as_line_segment_from_points( surface, @@ -160,10 +166,12 @@ mod tests { let objects = Objects::new(); let surface = objects.surfaces.xy_plane(); - let curve = Curve::partial() - .with_surface(Some(surface.clone())) - .update_as_u_axis() - .build(&objects)?; + let curve = PartialCurve { + surface: Some(surface.clone()), + ..Default::default() + } + .update_as_u_axis() + .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/curve_face.rs b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs index 9e87ec130..c87c06d12 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs @@ -151,8 +151,8 @@ where mod tests { use crate::{ builder::{CurveBuilder, FaceBuilder}, - objects::{Curve, Face, Objects}, - partial::HasPartial, + objects::{Face, Objects}, + partial::{HasPartial, PartialCurve}, }; use super::CurveFaceIntersection; @@ -163,10 +163,12 @@ mod tests { let surface = objects.surfaces.xy_plane(); - let curve = Curve::partial() - .with_surface(Some(surface.clone())) - .update_as_line_from_points([[-3., 0.], [-2., 0.]]) - .build(&objects)?; + let curve = PartialCurve { + surface: Some(surface.clone()), + ..Default::default() + } + .update_as_line_from_points([[-3., 0.], [-2., 0.]]) + .build(&objects)?; #[rustfmt::skip] let exterior = [ diff --git a/crates/fj-kernel/src/algorithms/intersect/face_face.rs b/crates/fj-kernel/src/algorithms/intersect/face_face.rs index 6c3fb9c77..d197b5b81 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_face.rs @@ -72,8 +72,8 @@ mod tests { algorithms::intersect::CurveFaceIntersection, builder::{CurveBuilder, FaceBuilder}, insert::Insert, - objects::{Curve, Face, Objects}, - partial::HasPartial, + objects::{Face, Objects}, + partial::{HasPartial, PartialCurve}, validate::ValidationError, }; @@ -129,11 +129,13 @@ mod tests { let expected_curves = surfaces.try_map_ext(|surface| -> Result<_, ValidationError> { - Ok(Curve::partial() - .with_surface(Some(surface)) - .update_as_line_from_points([[0., 0.], [1., 0.]]) - .build(&objects)? - .insert(&objects)?) + Ok(PartialCurve { + surface: Some(surface), + ..Default::default() + } + .update_as_line_from_points([[0., 0.], [1., 0.]]) + .build(&objects)? + .insert(&objects)?) })?; let expected_intervals = CurveFaceIntersection::from_intervals([[[-1.], [1.]]]); diff --git a/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs b/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs index 7481608f9..ebc7c2d16 100644 --- a/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs +++ b/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs @@ -91,11 +91,8 @@ mod tests { use pretty_assertions::assert_eq; use crate::{ - algorithms::transform::TransformObject, - builder::CurveBuilder, - insert::Insert, - objects::{Curve, Objects}, - partial::HasPartial, + algorithms::transform::TransformObject, builder::CurveBuilder, + insert::Insert, objects::Objects, partial::PartialCurve, }; use super::SurfaceSurfaceIntersection; @@ -122,16 +119,20 @@ mod tests { None, ); - let expected_xy = Curve::partial() - .with_surface(Some(xy.clone())) - .update_as_u_axis() - .build(&objects)? - .insert(&objects)?; - let expected_xz = Curve::partial() - .with_surface(Some(xz.clone())) - .update_as_u_axis() - .build(&objects)? - .insert(&objects)?; + let expected_xy = PartialCurve { + surface: Some(xy.clone()), + ..Default::default() + } + .update_as_u_axis() + .build(&objects)? + .insert(&objects)?; + let expected_xz = PartialCurve { + surface: Some(xz.clone()), + ..Default::default() + } + .update_as_u_axis() + .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 0e2d69e4a..750a0c338 100644 --- a/crates/fj-kernel/src/algorithms/sweep/vertex.rs +++ b/crates/fj-kernel/src/algorithms/sweep/vertex.rs @@ -170,8 +170,8 @@ mod tests { algorithms::sweep::Sweep, builder::{CurveBuilder, HalfEdgeBuilder}, insert::Insert, - objects::{Curve, HalfEdge, Objects, Vertex}, - partial::HasPartial, + objects::{HalfEdge, Objects, Vertex}, + partial::{HasPartial, PartialCurve}, }; #[test] @@ -179,11 +179,13 @@ mod tests { let objects = Objects::new(); let surface = objects.surfaces.xz_plane(); - let curve = Curve::partial() - .with_surface(Some(surface.clone())) - .update_as_u_axis() - .build(&objects)? - .insert(&objects)?; + let curve = PartialCurve { + surface: Some(surface.clone()), + ..Default::default() + } + .update_as_u_axis() + .build(&objects)? + .insert(&objects)?; let vertex = Vertex::partial() .with_position(Some([0.])) .with_curve(curve) diff --git a/crates/fj-kernel/src/algorithms/transform/curve.rs b/crates/fj-kernel/src/algorithms/transform/curve.rs index ce81ca8d9..351f1e689 100644 --- a/crates/fj-kernel/src/algorithms/transform/curve.rs +++ b/crates/fj-kernel/src/algorithms/transform/curve.rs @@ -41,9 +41,9 @@ impl TransformObject for PartialCurve { // coordinates, and thus transforming `surface` takes care of it. Ok(PartialCurve { path: self.path, + surface, ..Default::default() } - .with_surface(surface) .with_global_form(global_form)) } } diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 09f25cd30..a2499bbd2 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -1,8 +1,8 @@ use fj_math::Point; use crate::{ - objects::{Curve, HalfEdge, Surface, SurfaceVertex, Vertex}, - partial::{HasPartial, MaybePartial, PartialCycle}, + objects::{HalfEdge, Surface, SurfaceVertex, Vertex}, + partial::{HasPartial, MaybePartial, PartialCurve, PartialCycle}, storage::Handle, }; @@ -64,9 +64,11 @@ impl CycleBuilder for PartialCycle { previous = Some(vertex_next.clone()); - let curve = Curve::partial() - .with_surface(Some(surface.clone())) - .update_as_line_from_points([position_prev, position_next]); + let curve = PartialCurve { + surface: Some(surface.clone()), + ..Default::default() + } + .update_as_line_from_points([position_prev, position_next]); let vertices = [(0., vertex_prev), (1., vertex_next)].map( |(position, surface_form)| { diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 9a7eab91e..a1cf231f6 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -7,7 +7,10 @@ use crate::{ Curve, GlobalVertex, Objects, Surface, SurfaceVertex, Vertex, VerticesInNormalizedOrder, }, - partial::{HasPartial, MaybePartial, PartialGlobalEdge, PartialHalfEdge}, + partial::{ + HasPartial, MaybePartial, PartialCurve, PartialGlobalEdge, + PartialHalfEdge, + }, storage::Handle, validate::ValidationError, }; @@ -138,10 +141,12 @@ impl HalfEdgeBuilder for PartialHalfEdge { .expect("Can't infer line segment without surface position") }); - let curve = Curve::partial() - .with_global_form(Some(self.extract_global_curve())) - .with_surface(Some(surface)) - .update_as_line_from_points(points); + let curve = PartialCurve { + surface: Some(surface), + ..Default::default() + } + .with_global_form(Some(self.extract_global_curve())) + .update_as_line_from_points(points); let [back, front] = { let vertices = [(from, 0.), (to, 1.)].map(|(vertex, position)| { diff --git a/crates/fj-kernel/src/iter.rs b/crates/fj-kernel/src/iter.rs index 61d91aa1d..b3bbc65ac 100644 --- a/crates/fj-kernel/src/iter.rs +++ b/crates/fj-kernel/src/iter.rs @@ -363,10 +363,10 @@ mod tests { builder::{CurveBuilder, CycleBuilder, FaceBuilder, HalfEdgeBuilder}, insert::Insert, objects::{ - Curve, Cycle, Face, GlobalCurve, GlobalVertex, HalfEdge, Objects, - Shell, Sketch, Solid, SurfaceVertex, Vertex, + Cycle, Face, GlobalCurve, GlobalVertex, HalfEdge, Objects, Shell, + Sketch, Solid, SurfaceVertex, Vertex, }, - partial::HasPartial, + partial::{HasPartial, PartialCurve}, }; use super::ObjectIters as _; @@ -376,11 +376,13 @@ mod tests { let objects = Objects::new(); let surface = objects.surfaces.xy_plane(); - let object = Curve::partial() - .with_surface(Some(surface)) - .update_as_u_axis() - .build(&objects)? - .insert(&objects)?; + let object = PartialCurve { + surface: Some(surface), + ..Default::default() + } + .update_as_u_axis() + .build(&objects)? + .insert(&objects)?; assert_eq!(1, object.curve_iter().count()); assert_eq!(0, object.cycle_iter().count()); @@ -616,11 +618,13 @@ mod tests { let objects = Objects::new(); let surface = objects.surfaces.xy_plane(); - let curve = Curve::partial() - .with_surface(Some(surface.clone())) - .update_as_u_axis() - .build(&objects)? - .insert(&objects)?; + let curve = PartialCurve { + surface: Some(surface.clone()), + ..Default::default() + } + .update_as_u_axis() + .build(&objects)? + .insert(&objects)?; let global_vertex = objects .global_vertices .insert(GlobalVertex::from_position([0., 0., 0.]))?; diff --git a/crates/fj-kernel/src/partial/objects/curve.rs b/crates/fj-kernel/src/partial/objects/curve.rs index 3a6b3986b..846438a8a 100644 --- a/crates/fj-kernel/src/partial/objects/curve.rs +++ b/crates/fj-kernel/src/partial/objects/curve.rs @@ -22,14 +22,6 @@ pub struct PartialCurve { } impl PartialCurve { - /// Provide a surface for the partial curve - pub fn with_surface(mut self, surface: Option>) -> Self { - if let Some(surface) = surface { - self.surface = Some(surface); - } - self - } - /// Provide a global form for the partial curve pub fn with_global_form( mut self, diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 40e32906e..aaaf6d33a 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -48,9 +48,10 @@ impl PartialHalfEdge { /// Update the partial half-edge with the given surface pub fn with_surface(mut self, surface: Handle) -> Self { - self.curve = self - .curve - .update_partial(|curve| curve.with_surface(Some(surface.clone()))); + self.curve = self.curve.update_partial(|mut curve| { + curve.surface = Some(surface.clone()); + curve + }); self.vertices = self.vertices.map(|vertex| { vertex.update_partial(|vertex| { diff --git a/crates/fj-kernel/src/validate/vertex.rs b/crates/fj-kernel/src/validate/vertex.rs index 0ef103fe9..2d04eab55 100644 --- a/crates/fj-kernel/src/validate/vertex.rs +++ b/crates/fj-kernel/src/validate/vertex.rs @@ -181,8 +181,8 @@ mod tests { use crate::{ builder::{CurveBuilder, SurfaceVertexBuilder}, insert::Insert, - objects::{Curve, GlobalVertex, Objects, SurfaceVertex, Vertex}, - partial::HasPartial, + objects::{GlobalVertex, Objects, SurfaceVertex, Vertex}, + partial::{HasPartial, PartialCurve}, validate::Validate, }; @@ -193,9 +193,11 @@ mod tests { let valid = Vertex::partial() .with_position(Some([0.])) .with_curve( - Curve::partial() - .with_surface(Some(objects.surfaces.xy_plane())) - .update_as_u_axis(), + PartialCurve { + surface: Some(objects.surfaces.xy_plane()), + ..Default::default() + } + .update_as_u_axis(), ) .build(&objects)?; let invalid = Vertex::new( @@ -222,9 +224,11 @@ mod tests { let valid = Vertex::partial() .with_position(Some([0.])) .with_curve( - Curve::partial() - .with_surface(Some(objects.surfaces.xy_plane())) - .update_as_u_axis(), + PartialCurve { + surface: Some(objects.surfaces.xy_plane()), + ..Default::default() + } + .update_as_u_axis(), ) .build(&objects)?; let invalid = Vertex::new( From 651cd6bfa3791b87350ecf0b890f5b4b465d0486 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 14:32:04 +0100 Subject: [PATCH 05/10] Remove `PartialCurve::with_global_form` --- .../src/algorithms/transform/curve.rs | 5 ++--- crates/fj-kernel/src/builder/edge.rs | 10 ++++------ crates/fj-kernel/src/builder/shell.rs | 19 +++++++++++++------ crates/fj-kernel/src/partial/objects/curve.rs | 11 ----------- 4 files changed, 19 insertions(+), 26 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/curve.rs b/crates/fj-kernel/src/algorithms/transform/curve.rs index 351f1e689..a89192b7f 100644 --- a/crates/fj-kernel/src/algorithms/transform/curve.rs +++ b/crates/fj-kernel/src/algorithms/transform/curve.rs @@ -42,8 +42,7 @@ impl TransformObject for PartialCurve { Ok(PartialCurve { path: self.path, surface, - ..Default::default() - } - .with_global_form(global_form)) + global_form, + }) } } diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index a1cf231f6..1c6abd920 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -68,11 +68,9 @@ impl HalfEdgeBuilder for PartialHalfEdge { radius: impl Into, objects: &Objects, ) -> Result { - let curve = self - .curve() - .into_partial() - .with_global_form(Some(self.extract_global_curve())) - .update_as_circle_from_radius(radius); + let mut curve = self.curve().into_partial(); + curve.global_form = Some(self.extract_global_curve()); + let curve = curve.update_as_circle_from_radius(radius); let path = curve.path.expect("Expected path that was just created"); @@ -143,9 +141,9 @@ impl HalfEdgeBuilder for PartialHalfEdge { let curve = PartialCurve { surface: Some(surface), + global_form: Some(self.extract_global_curve()), ..Default::default() } - .with_global_form(Some(self.extract_global_curve())) .update_as_line_from_points(points); let [back, front] = { diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index bee310e32..fcd8a61f3 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -9,10 +9,10 @@ use crate::{ builder::{FaceBuilder, HalfEdgeBuilder}, insert::Insert, objects::{ - Curve, Cycle, Face, FaceSet, HalfEdge, Objects, Shell, Surface, - SurfaceVertex, Vertex, + Cycle, Face, FaceSet, HalfEdge, Objects, Shell, Surface, SurfaceVertex, + Vertex, }, - partial::HasPartial, + partial::{HasPartial, PartialCurve}, storage::Handle, }; @@ -152,9 +152,16 @@ impl<'a> ShellBuilder<'a> { .with_surface(Some(surface.clone())) .with_global_form(Some(from.global_form().clone())); - let curve = Curve::partial().with_global_form(Some( - side_up_prev.curve().global_form().clone(), - )); + let curve = PartialCurve { + global_form: Some( + side_up_prev + .curve() + .global_form() + .clone() + .into(), + ), + ..Default::default() + }; HalfEdge::partial() .with_curve(curve) diff --git a/crates/fj-kernel/src/partial/objects/curve.rs b/crates/fj-kernel/src/partial/objects/curve.rs index 846438a8a..10ba14dee 100644 --- a/crates/fj-kernel/src/partial/objects/curve.rs +++ b/crates/fj-kernel/src/partial/objects/curve.rs @@ -22,17 +22,6 @@ pub struct PartialCurve { } impl PartialCurve { - /// Provide a global form for the partial curve - pub fn with_global_form( - mut self, - global_form: Option>>, - ) -> Self { - if let Some(global_form) = global_form { - self.global_form = Some(global_form.into()); - } - self - } - /// Build a full [`Curve`] from the partial curve pub fn build(self, objects: &Objects) -> Result { let path = self.path.expect("Can't build `Curve` without path"); From 0e44127ebdd83107f080f3deef7344487a33cab4 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 14:37:10 +0100 Subject: [PATCH 06/10] Add implementation note --- crates/fj-kernel/src/partial/objects/curve.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/fj-kernel/src/partial/objects/curve.rs b/crates/fj-kernel/src/partial/objects/curve.rs index 10ba14dee..f5670e27a 100644 --- a/crates/fj-kernel/src/partial/objects/curve.rs +++ b/crates/fj-kernel/src/partial/objects/curve.rs @@ -18,6 +18,12 @@ pub struct PartialCurve { pub surface: Option>, /// The global form of the [`Curve`] + /// + /// # Implementation Note + /// + /// This can in principle be simplified to just `MaybePartial>, } From 686f63543997832cf6645543aaa08fdfa0eec63d Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 14:41:30 +0100 Subject: [PATCH 07/10] Change style of `update_as_line_from_points` --- .../fj-kernel/src/algorithms/approx/curve.rs | 27 +++++++++---------- .../src/algorithms/intersect/curve_face.rs | 8 +++--- .../src/algorithms/intersect/face_face.rs | 9 +++---- crates/fj-kernel/src/builder/curve.rs | 24 ++++++++--------- crates/fj-kernel/src/builder/cycle.rs | 7 ++--- crates/fj-kernel/src/builder/edge.rs | 6 ++--- 6 files changed, 39 insertions(+), 42 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/curve.rs b/crates/fj-kernel/src/algorithms/approx/curve.rs index 45b893d20..aa17fc9b7 100644 --- a/crates/fj-kernel/src/algorithms/approx/curve.rs +++ b/crates/fj-kernel/src/algorithms/approx/curve.rs @@ -213,13 +213,12 @@ mod tests { let surface = objects .surfaces .insert(Surface::new(GlobalPath::x_axis(), [0., 0., 1.]))?; - let curve = PartialCurve { + let mut curve = PartialCurve { surface: Some(surface), ..Default::default() - } - .update_as_line_from_points([[1., 1.], [2., 1.]]) - .build(&objects)? - .insert(&objects)?; + }; + curve.update_as_line_from_points([[1., 1.], [2., 1.]]); + let curve = curve.build(&objects)?.insert(&objects)?; let range = RangeOnPath::from([[0.], [1.]]); let approx = (&curve, range).approx(1.); @@ -237,13 +236,12 @@ mod tests { GlobalPath::circle_from_radius(1.), [0., 0., 1.], ))?; - let curve = PartialCurve { + let mut curve = PartialCurve { surface: Some(surface), ..Default::default() - } - .update_as_line_from_points([[1., 1.], [1., 2.]]) - .build(&objects)? - .insert(&objects)?; + }; + curve.update_as_line_from_points([[1., 1.], [1., 2.]]); + let curve = curve.build(&objects)?.insert(&objects)?; let range = RangeOnPath::from([[0.], [1.]]); let approx = (&curve, range).approx(1.); @@ -259,13 +257,12 @@ mod tests { let path = GlobalPath::circle_from_radius(1.); let surface = objects.surfaces.insert(Surface::new(path, [0., 0., 1.]))?; - let curve = PartialCurve { + let mut curve = PartialCurve { surface: Some(surface.clone()), ..Default::default() - } - .update_as_line_from_points([[0., 1.], [1., 1.]]) - .build(&objects)? - .insert(&objects)?; + }; + curve.update_as_line_from_points([[0., 1.], [1., 1.]]); + let curve = curve.build(&objects)?.insert(&objects)?; let range = RangeOnPath::from([[0.], [TAU]]); let tolerance = 1.; diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs index c87c06d12..39a74cfa1 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs @@ -163,12 +163,12 @@ mod tests { let surface = objects.surfaces.xy_plane(); - let curve = PartialCurve { + let mut curve = PartialCurve { surface: Some(surface.clone()), ..Default::default() - } - .update_as_line_from_points([[-3., 0.], [-2., 0.]]) - .build(&objects)?; + }; + curve.update_as_line_from_points([[-3., 0.], [-2., 0.]]); + let curve = curve.build(&objects)?; #[rustfmt::skip] let exterior = [ diff --git a/crates/fj-kernel/src/algorithms/intersect/face_face.rs b/crates/fj-kernel/src/algorithms/intersect/face_face.rs index d197b5b81..26a992a51 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_face.rs @@ -129,13 +129,12 @@ mod tests { let expected_curves = surfaces.try_map_ext(|surface| -> Result<_, ValidationError> { - Ok(PartialCurve { + let mut curve = PartialCurve { surface: Some(surface), ..Default::default() - } - .update_as_line_from_points([[0., 0.], [1., 0.]]) - .build(&objects)? - .insert(&objects)?) + }; + curve.update_as_line_from_points([[0., 0.], [1., 0.]]); + Ok(curve.build(&objects)?.insert(&objects)?) })?; let expected_intervals = CurveFaceIntersection::from_intervals([[[-1.], [1.]]]); diff --git a/crates/fj-kernel/src/builder/curve.rs b/crates/fj-kernel/src/builder/curve.rs index b9e93097b..a16324b32 100644 --- a/crates/fj-kernel/src/builder/curve.rs +++ b/crates/fj-kernel/src/builder/curve.rs @@ -15,24 +15,26 @@ pub trait CurveBuilder { /// Update partial curve as a line, from the provided points fn update_as_line_from_points( - self, + &mut self, points: [impl Into>; 2], - ) -> Self; + ) -> &mut Self; } impl CurveBuilder for PartialCurve { - fn update_as_u_axis(self) -> Self { + fn update_as_u_axis(mut self) -> Self { let a = Point::origin(); let b = a + Vector::unit_u(); - self.update_as_line_from_points([a, b]) + self.update_as_line_from_points([a, b]); + self } - fn update_as_v_axis(self) -> Self { + fn update_as_v_axis(mut self) -> Self { let a = Point::origin(); let b = a + Vector::unit_v(); - self.update_as_line_from_points([a, b]) + self.update_as_line_from_points([a, b]); + self } fn update_as_circle_from_radius(self, radius: impl Into) -> Self { @@ -43,12 +45,10 @@ impl CurveBuilder for PartialCurve { } fn update_as_line_from_points( - self, + &mut self, points: [impl Into>; 2], - ) -> Self { - Self { - path: Some(SurfacePath::line_from_points(points)), - ..self - } + ) -> &mut Self { + self.path = Some(SurfacePath::line_from_points(points)); + self } } diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index a2499bbd2..64ba97be6 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -64,11 +64,12 @@ impl CycleBuilder for PartialCycle { previous = Some(vertex_next.clone()); - let curve = PartialCurve { + let mut curve = PartialCurve { surface: Some(surface.clone()), ..Default::default() - } - .update_as_line_from_points([position_prev, position_next]); + }; + curve + .update_as_line_from_points([position_prev, position_next]); let vertices = [(0., vertex_prev), (1., vertex_next)].map( |(position, surface_form)| { diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 1c6abd920..c05c65120 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -139,12 +139,12 @@ impl HalfEdgeBuilder for PartialHalfEdge { .expect("Can't infer line segment without surface position") }); - let curve = PartialCurve { + let mut curve = PartialCurve { surface: Some(surface), global_form: Some(self.extract_global_curve()), ..Default::default() - } - .update_as_line_from_points(points); + }; + curve.update_as_line_from_points(points); let [back, front] = { let vertices = [(from, 0.), (to, 1.)].map(|(vertex, position)| { From ad87bd46dadec6e5fb42af214973a6081d8c1d33 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 14:43:07 +0100 Subject: [PATCH 08/10] Change style of `update_as_circle_from_radius` --- crates/fj-kernel/src/algorithms/approx/curve.rs | 9 ++++----- crates/fj-kernel/src/builder/curve.rs | 16 ++++++++++------ crates/fj-kernel/src/builder/edge.rs | 2 +- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/curve.rs b/crates/fj-kernel/src/algorithms/approx/curve.rs index aa17fc9b7..870925bcc 100644 --- a/crates/fj-kernel/src/algorithms/approx/curve.rs +++ b/crates/fj-kernel/src/algorithms/approx/curve.rs @@ -291,13 +291,12 @@ mod tests { let surface = objects .surfaces .insert(Surface::new(GlobalPath::x_axis(), [0., 0., 1.]))?; - let curve = PartialCurve { + let mut curve = PartialCurve { surface: Some(surface), ..Default::default() - } - .update_as_circle_from_radius(1.) - .build(&objects)? - .insert(&objects)?; + }; + curve.update_as_circle_from_radius(1.); + let curve = curve.build(&objects)?.insert(&objects)?; let range = RangeOnPath::from([[0.], [TAU]]); let tolerance = 1.; diff --git a/crates/fj-kernel/src/builder/curve.rs b/crates/fj-kernel/src/builder/curve.rs index a16324b32..9afedb650 100644 --- a/crates/fj-kernel/src/builder/curve.rs +++ b/crates/fj-kernel/src/builder/curve.rs @@ -11,7 +11,10 @@ pub trait CurveBuilder { fn update_as_v_axis(self) -> Self; /// Update partial curve as a circle, from the provided radius - fn update_as_circle_from_radius(self, radius: impl Into) -> Self; + fn update_as_circle_from_radius( + &mut self, + radius: impl Into, + ) -> &mut Self; /// Update partial curve as a line, from the provided points fn update_as_line_from_points( @@ -37,11 +40,12 @@ impl CurveBuilder for PartialCurve { self } - fn update_as_circle_from_radius(self, radius: impl Into) -> Self { - Self { - path: Some(SurfacePath::circle_from_radius(radius)), - ..self - } + fn update_as_circle_from_radius( + &mut self, + radius: impl Into, + ) -> &mut Self { + self.path = Some(SurfacePath::circle_from_radius(radius)); + self } fn update_as_line_from_points( diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index c05c65120..2fc232795 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -70,7 +70,7 @@ impl HalfEdgeBuilder for PartialHalfEdge { ) -> Result { let mut curve = self.curve().into_partial(); curve.global_form = Some(self.extract_global_curve()); - let curve = curve.update_as_circle_from_radius(radius); + curve.update_as_circle_from_radius(radius); let path = curve.path.expect("Expected path that was just created"); From c001b18fbd5ae5d2fc630bffe5cd80f614bd7f42 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 14:43:51 +0100 Subject: [PATCH 09/10] Change style of `update_as_v_axis` --- crates/fj-kernel/src/builder/curve.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/fj-kernel/src/builder/curve.rs b/crates/fj-kernel/src/builder/curve.rs index 9afedb650..2e6b15827 100644 --- a/crates/fj-kernel/src/builder/curve.rs +++ b/crates/fj-kernel/src/builder/curve.rs @@ -8,7 +8,7 @@ pub trait CurveBuilder { fn update_as_u_axis(self) -> Self; /// Update partial curve to represent the v-axis - fn update_as_v_axis(self) -> Self; + fn update_as_v_axis(&mut self) -> &mut Self; /// Update partial curve as a circle, from the provided radius fn update_as_circle_from_radius( @@ -32,12 +32,11 @@ impl CurveBuilder for PartialCurve { self } - fn update_as_v_axis(mut self) -> Self { + fn update_as_v_axis(&mut self) -> &mut Self { let a = Point::origin(); let b = a + Vector::unit_v(); - self.update_as_line_from_points([a, b]); - self + self.update_as_line_from_points([a, b]) } fn update_as_circle_from_radius( From 7e5500a884b448c8fc7c9e3d241b25630368b007 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 14:49:20 +0100 Subject: [PATCH 10/10] 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(),