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, diff --git a/crates/fj-core/src/operations/transform/curve.rs b/crates/fj-core/src/operations/transform/curve.rs index 4457a35b4..7f878009b 100644 --- a/crates/fj-core/src/operations/transform/curve.rs +++ b/crates/fj-core/src/operations/transform/curve.rs @@ -1,19 +1,41 @@ 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(|| { + // 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() } }