diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index 01b70720f..901533c47 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -199,8 +199,8 @@ mod tests { algorithms::{reverse::Reverse, sweep::Sweep}, builder::HalfEdgeBuilder, insert::Insert, - objects::{Cycle, Face, HalfEdge, Objects, Vertex}, - partial::{HasPartial, PartialSurfaceVertex}, + objects::{Cycle, Face, HalfEdge, Objects}, + partial::{HasPartial, PartialSurfaceVertex, PartialVertex}, }; #[test] @@ -218,69 +218,75 @@ 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)? - .insert(&objects)?; - let side_up = HalfEdge::partial() - .with_surface(surface.clone()) - .with_back_vertex(Vertex::partial().with_surface_form( - bottom.front().surface_form().clone(), - )) - .with_front_vertex(Vertex::partial().with_surface_form( - PartialSurfaceVertex { - position: Some([1., 1.].into()), - ..Default::default() - }, - )) - .update_as_line_segment() - .build(&objects)? - .insert(&objects)?; - let top = HalfEdge::partial() - .with_surface(surface.clone()) - .with_back_vertex(Vertex::partial().with_surface_form( - PartialSurfaceVertex { - position: Some([0., 1.].into()), - ..Default::default() - }, - )) - .with_front_vertex(Vertex::partial().with_surface_form( - side_up.front().surface_form().clone(), - )) - .update_as_line_segment() - .build(&objects)? - .insert(&objects)? - .reverse(&objects)?; - let side_down = - HalfEdge::partial() - .with_surface(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)? - .insert(&objects)? - .reverse(&objects)?; + let bottom = HalfEdge::partial() + .update_as_line_segment_from_points( + surface.clone(), + [[0., 0.], [1., 0.]], + ) + .build(&objects)? + .insert(&objects)?; + let side_up = HalfEdge::partial() + .with_surface(surface.clone()) + .with_back_vertex(PartialVertex { + surface_form: bottom.front().surface_form().clone().into(), + ..Default::default() + }) + .with_front_vertex(PartialVertex { + surface_form: PartialSurfaceVertex { + position: Some([1., 1.].into()), + ..Default::default() + } + .into(), + ..Default::default() + }) + .update_as_line_segment() + .build(&objects)? + .insert(&objects)?; + let top = HalfEdge::partial() + .with_surface(surface.clone()) + .with_back_vertex(PartialVertex { + surface_form: PartialSurfaceVertex { + position: Some([0., 1.].into()), + ..Default::default() + } + .into(), + ..Default::default() + }) + .with_front_vertex(PartialVertex { + surface_form: side_up.front().surface_form().clone().into(), + ..Default::default() + }) + .update_as_line_segment() + .build(&objects)? + .insert(&objects)? + .reverse(&objects)?; + let side_down = HalfEdge::partial() + .with_surface(surface) + .with_back_vertex(PartialVertex { + surface_form: bottom.back().surface_form().clone().into(), + ..Default::default() + }) + .with_front_vertex(PartialVertex { + surface_form: top.front().surface_form().clone().into(), + ..Default::default() + }) + .update_as_line_segment() + .build(&objects)? + .insert(&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::partial() - .with_exterior(cycle) - .build(&objects)? - .insert(&objects)? - }; + Face::partial() + .with_exterior(cycle) + .build(&objects)? + .insert(&objects)? + }; assert_eq!(face, expected_face); Ok(()) diff --git a/crates/fj-kernel/src/algorithms/transform/vertex.rs b/crates/fj-kernel/src/algorithms/transform/vertex.rs index fc66e5642..d925898bb 100644 --- a/crates/fj-kernel/src/algorithms/transform/vertex.rs +++ b/crates/fj-kernel/src/algorithms/transform/vertex.rs @@ -25,9 +25,8 @@ impl TransformObject for PartialVertex { Ok(Self { position: self.position, curve, - ..Default::default() - } - .with_surface_form(surface_form)) + surface_form: surface_form.into(), + }) } } diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 5e0c2c794..bbdf5a6d6 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -75,13 +75,10 @@ impl CycleBuilder for PartialCycle { .update_as_line_from_points([position_prev, position_next]); let vertices = [(0., vertex_prev), (1., vertex_next)].map( - |(position, surface_form)| { - PartialVertex { - position: Some([position].into()), - curve: curve.clone().into(), - ..Default::default() - } - .with_surface_form(surface_form) + |(position, surface_form)| PartialVertex { + position: Some([position].into()), + curve: curve.clone().into(), + surface_form, }, ); diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index b5362bc55..06468f3c8 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -96,14 +96,12 @@ impl HalfEdgeBuilder for PartialHalfEdge { .build(objects)? .insert(objects)?; - let [back, front] = [a_curve, b_curve].map(|point_curve| { - PartialVertex { + let [back, front] = + [a_curve, b_curve].map(|point_curve| PartialVertex { position: Some(point_curve), curve: curve.clone().into(), - ..Default::default() - } - .with_surface_form(surface_vertex.clone()) - }); + surface_form: surface_vertex.clone().into(), + }); Ok(self.with_curve(curve).with_vertices([back, front])) } @@ -120,7 +118,10 @@ impl HalfEdgeBuilder for PartialHalfEdge { ..Default::default() }; - Vertex::partial().with_surface_form(surface_form) + PartialVertex { + surface_form: surface_form.into(), + ..Default::default() + } }); self.with_surface(surface) @@ -201,18 +202,16 @@ impl HalfEdgeBuilder for PartialHalfEdge { .zip(global_forms) .collect::<[_; 2]>() .map(|(vertex, global_form)| { - vertex.update_partial(|vertex| { - vertex.clone().with_surface_form( - vertex.surface_form.update_partial( - |mut surface_vertex| { - if let Some(global_form) = global_form { - surface_vertex.global_form = - global_form; - } - surface_vertex - }, - ), - ) + vertex.update_partial(|mut vertex| { + vertex.surface_form = vertex + .surface_form + .update_partial(|mut surface_vertex| { + if let Some(global_form) = global_form { + surface_vertex.global_form = global_form; + } + surface_vertex + }); + vertex }) }) }; diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index eb86fb61e..343b45857 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -8,9 +8,7 @@ use crate::{ algorithms::transform::TransformObject, builder::{FaceBuilder, HalfEdgeBuilder}, insert::Insert, - objects::{ - Cycle, Face, FaceSet, HalfEdge, Objects, Shell, Surface, Vertex, - }, + objects::{Cycle, Face, FaceSet, HalfEdge, Objects, Shell, Surface}, partial::{HasPartial, PartialCurve, PartialSurfaceVertex, PartialVertex}, storage::Handle, }; @@ -121,8 +119,14 @@ impl<'a> ShellBuilder<'a> { HalfEdge::partial() .with_vertices([ - Vertex::partial().with_surface_form(from), - Vertex::partial().with_surface_form(to), + PartialVertex { + surface_form: from.into(), + ..Default::default() + }, + PartialVertex { + surface_form: to.into(), + ..Default::default() + }, ]) .update_as_line_segment() .build(self.objects) @@ -166,8 +170,14 @@ impl<'a> ShellBuilder<'a> { HalfEdge::partial() .with_curve(curve) .with_vertices([ - Vertex::partial().with_surface_form(from), - Vertex::partial().with_surface_form(to), + PartialVertex { + surface_form: from.into(), + ..Default::default() + }, + PartialVertex { + surface_form: to.into(), + ..Default::default() + }, ]) .update_as_line_segment() .build(self.objects) @@ -189,8 +199,14 @@ impl<'a> ShellBuilder<'a> { let from = from.surface_form().clone(); let to = to.surface_form().clone(); - let from = Vertex::partial().with_surface_form(from); - let to = Vertex::partial().with_surface_form(to); + let from = PartialVertex { + surface_form: from.into(), + ..Default::default() + }; + let to = PartialVertex { + surface_form: to.into(), + ..Default::default() + }; HalfEdge::partial() .with_vertices([from, to]) @@ -276,12 +292,10 @@ impl<'a> ShellBuilder<'a> { .into_iter_fixed() .zip(surface_vertices.clone()) .collect::<[_; 2]>() - .map(|(vertex, surface_form)| { - PartialVertex { - position: Some(vertex.position()), - ..Default::default() - } - .with_surface_form(surface_form) + .map(|(vertex, surface_form)| PartialVertex { + position: Some(vertex.position()), + surface_form: surface_form.into(), + ..Default::default() }); edges.push( diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index 30a0d3f0e..fda3e8873 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -15,8 +15,9 @@ pub trait VertexBuilder { } impl VertexBuilder for PartialVertex { - fn infer_surface_form(self) -> Self { - self.with_surface_form(PartialSurfaceVertex::default()) + fn infer_surface_form(mut self) -> Self { + self.surface_form = PartialSurfaceVertex::default().into(); + self } } diff --git a/crates/fj-kernel/src/partial/objects/cycle.rs b/crates/fj-kernel/src/partial/objects/cycle.rs index a802133e3..eedf39ff8 100644 --- a/crates/fj-kernel/src/partial/objects/cycle.rs +++ b/crates/fj-kernel/src/partial/objects/cycle.rs @@ -96,9 +96,14 @@ impl PartialCycle { *half_edge = half_edge.clone().merge_with( PartialHalfEdge::default().with_vertices([ - PartialVertex::default().with_surface_form(back_vertex), - PartialVertex::default() - .with_surface_form(front_vertex.clone()), + PartialVertex { + surface_form: back_vertex, + ..Default::default() + }, + PartialVertex { + surface_form: front_vertex.clone().into(), + ..Default::default() + }, ]), ); @@ -111,9 +116,10 @@ impl PartialCycle { let back_vertex = previous_vertex.unwrap_or_default(); *half_edge = half_edge.clone().merge_with( - PartialHalfEdge::default().with_back_vertex( - PartialVertex::default().with_surface_form(back_vertex), - ), + PartialHalfEdge::default().with_back_vertex(PartialVertex { + surface_form: back_vertex, + ..Default::default() + }), ); } diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index d26f806a3..cbace6209 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -54,7 +54,7 @@ impl PartialHalfEdge { }); self.vertices = self.vertices.map(|vertex| { - vertex.update_partial(|vertex| { + vertex.update_partial(|mut vertex| { let surface_form = vertex.surface_form.clone().update_partial( |mut surface_vertex| { surface_vertex.surface = Some(surface.clone()); @@ -62,7 +62,8 @@ impl PartialHalfEdge { }, ); - vertex.with_surface_form(surface_form) + vertex.surface_form = surface_form; + vertex }) }); diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index 9f2330b7b..39a1fffc3 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -24,15 +24,6 @@ pub struct PartialVertex { } impl PartialVertex { - /// Provide a surface form for the partial vertex - pub fn with_surface_form( - mut self, - surface_form: impl Into>, - ) -> Self { - self.surface_form = surface_form.into(); - self - } - /// Build a full [`Vertex`] from the partial vertex /// /// # Panics