From 3259b3e0676c01c86c6f1cd40734ce84bbea1156 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 30 Apr 2024 12:54:18 +0200 Subject: [PATCH 1/4] Refactor to prepare for follow-on change --- crates/fj-core/src/validate/shell.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/fj-core/src/validate/shell.rs b/crates/fj-core/src/validate/shell.rs index 42baef843..a10e3aaef 100644 --- a/crates/fj-core/src/validate/shell.rs +++ b/crates/fj-core/src/validate/shell.rs @@ -539,11 +539,10 @@ mod tests { cycle.update_half_edge( cycle.half_edges().nth_circular(0), |half_edge, core| { + let curve = Curve::new(); + [half_edge - .update_curve( - |_, _| Curve::new(), - core, - ) + .update_curve(|_, _| curve, core) .insert(core) .set_geometry( *core From 3fd05d07cd33656e024ef5dceb61cb77c644b528 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 30 Apr 2024 12:54:43 +0200 Subject: [PATCH 2/4] Refactor to prepare for follow-on change --- crates/fj-core/src/validate/shell.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/fj-core/src/validate/shell.rs b/crates/fj-core/src/validate/shell.rs index a10e3aaef..c6d48144f 100644 --- a/crates/fj-core/src/validate/shell.rs +++ b/crates/fj-core/src/validate/shell.rs @@ -539,7 +539,7 @@ mod tests { cycle.update_half_edge( cycle.half_edges().nth_circular(0), |half_edge, core| { - let curve = Curve::new(); + let curve = Curve::new().insert(core); [half_edge .update_curve(|_, _| curve, core) From 013f881426b31ddffbff2e5a9bf9b12f07a35c24 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 30 Apr 2024 12:59:15 +0200 Subject: [PATCH 3/4] Add `UpdateCurveGeometry::update_geometry_from` --- .../fj-core/src/operations/geometry/curve.rs | 22 ++++++++++++++++++ .../fj-core/src/operations/transform/curve.rs | 23 ++++++------------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/crates/fj-core/src/operations/geometry/curve.rs b/crates/fj-core/src/operations/geometry/curve.rs index 831e07229..b4ccf2755 100644 --- a/crates/fj-core/src/operations/geometry/curve.rs +++ b/crates/fj-core/src/operations/geometry/curve.rs @@ -10,6 +10,13 @@ use crate::{ /// Update the geometry of a [`Curve`] pub trait UpdateCurveGeometry { + /// Copy the geometry of the provided curve + fn copy_geometry_from( + self, + curve: &Handle, + geometry: &mut Layer, + ) -> Self; + /// Define the geometry as a path on a surface fn make_path_on_surface( self, @@ -35,6 +42,21 @@ pub trait UpdateCurveGeometry { } impl UpdateCurveGeometry for Handle { + fn copy_geometry_from( + self, + curve: &Handle, + geometry: &mut Layer, + ) -> Self { + let curve_geom = geometry.of_curve(curve).cloned(); + if let Some(curve_geom) = curve_geom { + for (surface, local_definition) in curve_geom.definitions { + geometry.define_curve(self.clone(), surface, local_definition); + } + } + + self + } + fn make_path_on_surface( self, path: SurfacePath, diff --git a/crates/fj-core/src/operations/transform/curve.rs b/crates/fj-core/src/operations/transform/curve.rs index 7f878009b..fa6a686b6 100644 --- a/crates/fj-core/src/operations/transform/curve.rs +++ b/crates/fj-core/src/operations/transform/curve.rs @@ -1,7 +1,10 @@ use fj_math::Transform; use crate::{ - operations::insert::Insert, storage::Handle, topology::Curve, Core, + operations::{geometry::UpdateCurveGeometry, insert::Insert}, + storage::Handle, + topology::Curve, + Core, }; use super::{TransformCache, TransformObject}; @@ -20,21 +23,9 @@ impl TransformObject for Handle { // geometry is locally defined on a surface. We need to set that // geometry for the new object though, that we created here to // represent the transformed curve. - - let curve = Curve::new().insert(core); - - let curve_geom = core.layers.geometry.of_curve(self).cloned(); - if let Some(curve_geom) = curve_geom { - for (surface, local_definition) in curve_geom.definitions { - core.layers.geometry.define_curve( - curve.clone(), - surface, - local_definition, - ); - } - } - - curve + Curve::new() + .insert(core) + .copy_geometry_from(self, &mut core.layers.geometry) }) .clone() } From b345881ad898f6d5cf1b8ef306f1db3d7451f841 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 30 Apr 2024 12:59:58 +0200 Subject: [PATCH 4/4] Set curve geometry in shell validation test --- crates/fj-core/src/validate/shell.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/fj-core/src/validate/shell.rs b/crates/fj-core/src/validate/shell.rs index c6d48144f..f06fb6054 100644 --- a/crates/fj-core/src/validate/shell.rs +++ b/crates/fj-core/src/validate/shell.rs @@ -423,7 +423,7 @@ mod tests { assert_contains_err, operations::{ build::BuildShell, - geometry::UpdateHalfEdgeGeometry, + geometry::{UpdateCurveGeometry, UpdateHalfEdgeGeometry}, insert::Insert, update::{ UpdateCycle, UpdateFace, UpdateHalfEdge, UpdateRegion, @@ -539,7 +539,12 @@ mod tests { cycle.update_half_edge( cycle.half_edges().nth_circular(0), |half_edge, core| { - let curve = Curve::new().insert(core); + let curve = Curve::new() + .insert(core) + .copy_geometry_from( + half_edge.curve(), + &mut core.layers.geometry, + ); [half_edge .update_curve(|_, _| curve, core)