From a79bd1a7c223b1b68fb3d78572deefa511167a8b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 4 Nov 2022 15:33:22 +0100 Subject: [PATCH] Refactor --- .../fj-kernel/src/algorithms/transform/cycle.rs | 15 ++------------- crates/fj-kernel/src/partial/objects/cycle.rs | 14 ++++++++++---- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/cycle.rs b/crates/fj-kernel/src/algorithms/transform/cycle.rs index 1cbf50694..5f222af69 100644 --- a/crates/fj-kernel/src/algorithms/transform/cycle.rs +++ b/crates/fj-kernel/src/algorithms/transform/cycle.rs @@ -12,22 +12,11 @@ impl TransformObject for PartialCycle { transform: &Transform, objects: &Objects, ) -> Result { - let surface = self - .surface() - .map(|surface| surface.transform(transform, objects)) - .transpose()?; let half_edges = self .half_edges() - .map(|edge| { - Ok(edge - .into_partial() - .transform(transform, objects)? - .with_surface(surface.clone())) - }) + .map(|edge| edge.into_partial().transform(transform, objects)) .collect::, ValidationError>>()?; - Ok(Self::default() - .with_surface(surface) - .with_half_edges(half_edges)) + Ok(Self::default().with_half_edges(half_edges)) } } diff --git a/crates/fj-kernel/src/partial/objects/cycle.rs b/crates/fj-kernel/src/partial/objects/cycle.rs index 4709d6337..b4e55ef07 100644 --- a/crates/fj-kernel/src/partial/objects/cycle.rs +++ b/crates/fj-kernel/src/partial/objects/cycle.rs @@ -1,6 +1,6 @@ use crate::{ objects::{Cycle, HalfEdge, Objects, Surface}, - partial::MaybePartial, + partial::{util::merge_options, MaybePartial}, storage::Handle, validate::ValidationError, }; @@ -43,9 +43,15 @@ impl PartialCycle { mut self, half_edges: impl IntoIterator>>, ) -> Self { - self.half_edges - .extend(half_edges.into_iter().map(Into::into)); - self + let half_edges = half_edges.into_iter().map(Into::into); + + let mut surface = self.surface(); + for half_edge in half_edges { + surface = merge_options(surface, half_edge.curve().surface()); + self.half_edges.push(half_edge); + } + + self.with_surface(surface) } /// Merge this partial object with another