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(