From 3f4a92e6c97ab05ce310fffbaef4aad457834e55 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 30 Apr 2024 12:36:33 +0200 Subject: [PATCH 1/4] Return `Option` from `Geometry::of_curve` This makes the method more flexible and error messages about missing curve geometry more targetted. --- crates/fj-core/src/geometry/geometry.rs | 6 ++---- crates/fj-core/src/operations/build/half_edge.rs | 1 + crates/fj-core/src/operations/build/shell.rs | 4 ++++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/fj-core/src/geometry/geometry.rs b/crates/fj-core/src/geometry/geometry.rs index 5b180ccf0..267696617 100644 --- a/crates/fj-core/src/geometry/geometry.rs +++ b/crates/fj-core/src/geometry/geometry.rs @@ -108,10 +108,8 @@ impl Geometry { /// ## Panics /// /// Panics, if the geometry of the curve is not defined. - pub fn of_curve(&self, curve: &Handle) -> &CurveGeom { - self.curve - .get(curve) - .expect("Expected geometry of half-edge to be defined") + pub fn of_curve(&self, curve: &Handle) -> Option<&CurveGeom> { + self.curve.get(curve) } /// # Access the geometry of the provided half-edge diff --git a/crates/fj-core/src/operations/build/half_edge.rs b/crates/fj-core/src/operations/build/half_edge.rs index 37532c4fb..6e931248e 100644 --- a/crates/fj-core/src/operations/build/half_edge.rs +++ b/crates/fj-core/src/operations/build/half_edge.rs @@ -133,6 +133,7 @@ pub trait BuildHalfEdge { .layers .geometry .of_curve(half_edge.curve()) + .expect("Curve geometry was just defined in same function") .local_on(&surface) .path, boundary: boundary.unwrap_or_default(), diff --git a/crates/fj-core/src/operations/build/shell.rs b/crates/fj-core/src/operations/build/shell.rs index 7d4b955fd..211bd80ea 100644 --- a/crates/fj-core/src/operations/build/shell.rs +++ b/crates/fj-core/src/operations/build/shell.rs @@ -107,6 +107,10 @@ pub trait BuildShell { .layers .geometry .of_curve(&curve) + .expect( + "Curve geometry was just \ + defined in same function", + ) .local_on(&surface) .path, boundary, From b143ffb8cfd1a7897e0fc483bfccd86b1f9f0ac5 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 30 Apr 2024 12:23:02 +0200 Subject: [PATCH 2/4] Implement `TransformObject` for `Handle` This is preparation for setting curve geometry there. --- crates/fj-core/src/operations/transform/curve.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/crates/fj-core/src/operations/transform/curve.rs b/crates/fj-core/src/operations/transform/curve.rs index 4457a35b4..12e4bef33 100644 --- a/crates/fj-core/src/operations/transform/curve.rs +++ b/crates/fj-core/src/operations/transform/curve.rs @@ -1,19 +1,24 @@ use fj_math::Transform; -use crate::{topology::Curve, Core}; +use crate::{ + operations::insert::Insert, storage::Handle, topology::Curve, Core, +}; use super::{TransformCache, TransformObject}; -impl TransformObject for Curve { +impl TransformObject for Handle { fn transform_with_cache( &self, _: &Transform, - _: &mut Core, - _: &mut TransformCache, + core: &mut Core, + cache: &mut TransformCache, ) -> Self { // There's nothing to actually transform here, as `Curve` holds no data. // We still need this implementation though, as a new `Curve` object // must be created to represent the new and transformed curve. - Self::new() + cache + .entry(self) + .or_insert_with(|| Curve::new().insert(core)) + .clone() } } From 8d0739f0d55a985eaf2d31382865afa8194a001b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 30 Apr 2024 12:39:46 +0200 Subject: [PATCH 3/4] Set geometry when transforming curve --- .../fj-core/src/operations/transform/curve.rs | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/crates/fj-core/src/operations/transform/curve.rs b/crates/fj-core/src/operations/transform/curve.rs index 12e4bef33..7e1bcc9d2 100644 --- a/crates/fj-core/src/operations/transform/curve.rs +++ b/crates/fj-core/src/operations/transform/curve.rs @@ -18,7 +18,27 @@ impl TransformObject for Handle { // must be created to represent the new and transformed curve. cache .entry(self) - .or_insert_with(|| Curve::new().insert(core)) + .or_insert_with(|| { + // We don't actually need to transform the curve, as its + // 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 + }) .clone() } } From 23af296ce93a9838aebd5a46c3b7cdd726da718f Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 30 Apr 2024 12:40:05 +0200 Subject: [PATCH 4/4] Remove obsolete comment --- crates/fj-core/src/operations/transform/curve.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/crates/fj-core/src/operations/transform/curve.rs b/crates/fj-core/src/operations/transform/curve.rs index 7e1bcc9d2..7f878009b 100644 --- a/crates/fj-core/src/operations/transform/curve.rs +++ b/crates/fj-core/src/operations/transform/curve.rs @@ -13,9 +13,6 @@ impl TransformObject for Handle { core: &mut Core, cache: &mut TransformCache, ) -> Self { - // There's nothing to actually transform here, as `Curve` holds no data. - // We still need this implementation though, as a new `Curve` object - // must be created to represent the new and transformed curve. cache .entry(self) .or_insert_with(|| {