diff --git a/crates/fj-interop/src/ext.rs b/crates/fj-interop/src/ext.rs index cc5e5311e..b4d562186 100644 --- a/crates/fj-interop/src/ext.rs +++ b/crates/fj-interop/src/ext.rs @@ -13,6 +13,11 @@ pub trait ArrayExt { fn try_map_ext(self, f: F) -> Result<[U; N], E> where F: FnMut(T) -> Result; + + /// Stable replacement for `zip` + /// + /// + fn zip_ext(self, rhs: [U; N]) -> [(T, U); N]; } impl ArrayExt for [T; 2] { @@ -28,6 +33,12 @@ impl ArrayExt for [T; 2] { let [a, b] = self.map(f); Ok([a?, b?]) } + + fn zip_ext(self, rhs: [U; 2]) -> [(T, U); 2] { + let [a, b] = self; + let [q, r] = rhs; + [(a, q), (b, r)] + } } impl ArrayExt for [T; 4] { @@ -43,6 +54,12 @@ impl ArrayExt for [T; 4] { let [a, b, c, d] = self.map(f); Ok([a?, b?, c?, d?]) } + + fn zip_ext(self, rhs: [U; 4]) -> [(T, U); 4] { + let [a, b, c, d] = self; + let [q, r, s, t] = rhs; + [(a, q), (b, r), (c, s), (d, t)] + } } /// Extension trait for arrays diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 0f44ee1f6..be090554f 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -1,3 +1,4 @@ +use fj_interop::ext::ArrayExt; use fj_math::{Point, Scalar}; use iter_fixed::IntoIteratorFixed; @@ -6,7 +7,7 @@ use crate::{ objects::{Curve, Objects, Surface, Vertex, VerticesInNormalizedOrder}, partial::{ MaybePartial, MergeWith, PartialGlobalEdge, PartialHalfEdge, - PartialSurfaceVertex, PartialVertex, Replace, + PartialSurfaceVertex, PartialVertex, }, services::{Service, Services}, storage::Handle, @@ -108,21 +109,18 @@ impl HalfEdgeBuilder for PartialHalfEdge { surface: Handle, points: [impl Into>; 2], ) -> Self { - let vertices = points.map(|point| { - let surface_form = PartialSurfaceVertex { + self.vertices = self.vertices.zip_ext(points).map(|(vertex, point)| { + let mut vertex = vertex.into_partial(); + + vertex.surface_form = MaybePartial::from(PartialSurfaceVertex { position: Some(point.into()), surface: Some(surface.clone()), ..Default::default() - }; + }); - PartialVertex { - surface_form: surface_form.into(), - ..Default::default() - } + vertex.into() }); - self.replace(surface); - self.vertices = vertices.map(Into::into); self.update_as_line_segment() } diff --git a/crates/fj-kernel/src/partial/objects/cycle.rs b/crates/fj-kernel/src/partial/objects/cycle.rs index beee8a0b5..be6341c69 100644 --- a/crates/fj-kernel/src/partial/objects/cycle.rs +++ b/crates/fj-kernel/src/partial/objects/cycle.rs @@ -1,9 +1,7 @@ use crate::{ builder::HalfEdgeBuilder, objects::{Cycle, HalfEdge, Objects, Surface}, - partial::{ - MaybePartial, MergeWith, PartialHalfEdge, PartialVertex, Replace, - }, + partial::{MaybePartial, MergeWith, PartialHalfEdge, PartialVertex}, services::Service, storage::Handle, }; @@ -49,22 +47,6 @@ impl PartialCycle { self.half_edges.push(half_edge); } - self.with_surface(surface) - } - - /// Update the partial cycle with the provided surface - /// - /// All [`HalfEdge`]s will be updated with this surface. - pub fn with_surface(mut self, surface: Option>) -> Self { - if let Some(surface) = surface { - for half_edge in &mut self.half_edges { - *half_edge = - half_edge.clone().update_partial(|mut half_edge| { - half_edge.replace(surface.clone()); - half_edge - }); - } - } self } diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index 1cfff018b..22c2fe6ad 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -69,8 +69,7 @@ impl MergeWith for PartialVertex { impl Replace for PartialVertex { fn replace(&mut self, surface: Handle) -> &mut Self { - self.curve.replace(surface.clone()); - self.surface_form.replace(surface); + self.curve.replace(surface); self } } @@ -136,13 +135,6 @@ impl MergeWith for PartialSurfaceVertex { } } -impl Replace for PartialSurfaceVertex { - fn replace(&mut self, surface: Handle) -> &mut Self { - self.surface = Some(surface); - self - } -} - impl From<&SurfaceVertex> for PartialSurfaceVertex { fn from(surface_vertex: &SurfaceVertex) -> Self { Self {