diff --git a/crates/fj-core/src/operations/sweep/region.rs b/crates/fj-core/src/operations/sweep/region.rs index bbdc3fda3..34d6ef14d 100644 --- a/crates/fj-core/src/operations/sweep/region.rs +++ b/crates/fj-core/src/operations/sweep/region.rs @@ -52,7 +52,8 @@ impl SweepRegion for Region { let mut faces = Vec::new(); - let top_surface = bottom_surface.translate(path, core).insert(core); + let top_surface = + bottom_surface.clone().translate(path, core).insert(core); let top_exterior = sweep_cycle( self.exterior(), diff --git a/crates/fj-core/src/operations/transform/curve.rs b/crates/fj-core/src/operations/transform/curve.rs index fa6a686b6..7f6bfbd52 100644 --- a/crates/fj-core/src/operations/transform/curve.rs +++ b/crates/fj-core/src/operations/transform/curve.rs @@ -10,14 +10,16 @@ use crate::{ use super::{TransformCache, TransformObject}; impl TransformObject for Handle { + type Transformed = Self; + fn transform_with_cache( - &self, + self, _: &Transform, core: &mut Core, cache: &mut TransformCache, - ) -> Self { + ) -> Self::Transformed { cache - .entry(self) + .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 @@ -25,7 +27,7 @@ impl TransformObject for Handle { // represent the transformed curve. Curve::new() .insert(core) - .copy_geometry_from(self, &mut core.layers.geometry) + .copy_geometry_from(&self, &mut core.layers.geometry) }) .clone() } diff --git a/crates/fj-core/src/operations/transform/cycle.rs b/crates/fj-core/src/operations/transform/cycle.rs index 118f779a4..c4c1c93dd 100644 --- a/crates/fj-core/src/operations/transform/cycle.rs +++ b/crates/fj-core/src/operations/transform/cycle.rs @@ -5,16 +5,20 @@ use crate::{topology::Cycle, Core}; use super::{TransformCache, TransformObject}; impl TransformObject for Cycle { + type Transformed = Self; + fn transform_with_cache( - &self, + self, transform: &Transform, core: &mut Core, cache: &mut TransformCache, - ) -> Self { - let edges = self.half_edges().iter().map(|edge| { - edge.clone().transform_with_cache(transform, core, cache) + ) -> Self::Transformed { + let half_edges = self.half_edges().iter().map(|half_edge| { + half_edge + .clone() + .transform_with_cache(transform, core, cache) }); - Self::new(edges) + Self::new(half_edges) } } diff --git a/crates/fj-core/src/operations/transform/edge.rs b/crates/fj-core/src/operations/transform/edge.rs index ba3fa4370..e4875df87 100644 --- a/crates/fj-core/src/operations/transform/edge.rs +++ b/crates/fj-core/src/operations/transform/edge.rs @@ -7,12 +7,14 @@ use crate::{ use super::{TransformCache, TransformObject}; impl TransformObject for Handle { + type Transformed = Self; + fn transform_with_cache( - &self, + self, transform: &Transform, core: &mut Core, cache: &mut TransformCache, - ) -> Self { + ) -> Self::Transformed { let curve = self .curve() .clone() @@ -26,7 +28,7 @@ impl TransformObject for Handle { core.layers.geometry.define_half_edge( half_edge.clone(), - *core.layers.geometry.of_half_edge(self), + *core.layers.geometry.of_half_edge(&self), ); half_edge diff --git a/crates/fj-core/src/operations/transform/face.rs b/crates/fj-core/src/operations/transform/face.rs index ae8911dcb..3aa982844 100644 --- a/crates/fj-core/src/operations/transform/face.rs +++ b/crates/fj-core/src/operations/transform/face.rs @@ -5,12 +5,14 @@ use crate::{topology::Face, Core}; use super::{TransformCache, TransformObject}; impl TransformObject for Face { + type Transformed = Self; + fn transform_with_cache( - &self, + self, transform: &Transform, core: &mut Core, cache: &mut TransformCache, - ) -> Self { + ) -> Self::Transformed { let surface = self .surface() .clone() diff --git a/crates/fj-core/src/operations/transform/mod.rs b/crates/fj-core/src/operations/transform/mod.rs index 9916b7442..507a598c9 100644 --- a/crates/fj-core/src/operations/transform/mod.rs +++ b/crates/fj-core/src/operations/transform/mod.rs @@ -34,24 +34,35 @@ use super::derive::DeriveFrom; /// More convenience methods can be added as required. The only reason this /// hasn't been done so far, is that no one has put in the work yet. pub trait TransformObject: Sized { + /// The result of the transformation + type Transformed; + /// Transform the object - fn transform(&self, transform: &Transform, core: &mut Core) -> Self { + fn transform( + self, + transform: &Transform, + core: &mut Core, + ) -> Self::Transformed { let mut cache = TransformCache::default(); self.transform_with_cache(transform, core, &mut cache) } /// Transform the object using the provided cache fn transform_with_cache( - &self, + self, transform: &Transform, core: &mut Core, cache: &mut TransformCache, - ) -> Self; + ) -> Self::Transformed; /// Translate the object /// /// Convenience wrapper around [`TransformObject::transform`]. - fn translate(&self, offset: impl Into>, core: &mut Core) -> Self { + fn translate( + self, + offset: impl Into>, + core: &mut Core, + ) -> Self::Transformed { self.transform(&Transform::translation(offset), core) } @@ -59,26 +70,31 @@ pub trait TransformObject: Sized { /// /// Convenience wrapper around [`TransformObject::transform`]. fn rotate( - &self, + self, axis_angle: impl Into>, core: &mut Core, - ) -> Self { + ) -> Self::Transformed { self.transform(&Transform::rotation(axis_angle), core) } } impl TransformObject for Handle where - T: Clone + Insert> + TransformObject + 'static, + T: Clone + + Insert> + + TransformObject + + 'static, Handle: Into>, { + type Transformed = Self; + fn transform_with_cache( - &self, + self, transform: &Transform, core: &mut Core, cache: &mut TransformCache, - ) -> Self { - if let Some(object) = cache.get(self) { + ) -> Self::Transformed { + if let Some(object) = cache.get(&self) { return object.clone(); } @@ -86,7 +102,7 @@ where .clone_object() .transform_with_cache(transform, core, cache) .insert(core) - .derive_from(self, core); + .derive_from(&self, core); cache.insert(self.clone(), transformed.clone()); diff --git a/crates/fj-core/src/operations/transform/region.rs b/crates/fj-core/src/operations/transform/region.rs index 5896da254..0615b4259 100644 --- a/crates/fj-core/src/operations/transform/region.rs +++ b/crates/fj-core/src/operations/transform/region.rs @@ -3,12 +3,14 @@ use crate::{topology::Region, Core}; use super::TransformObject; impl TransformObject for Region { + type Transformed = Self; + fn transform_with_cache( - &self, + self, transform: &fj_math::Transform, core: &mut Core, cache: &mut super::TransformCache, - ) -> Self { + ) -> Self::Transformed { let exterior = self .exterior() .clone() diff --git a/crates/fj-core/src/operations/transform/shell.rs b/crates/fj-core/src/operations/transform/shell.rs index 09c1fe6ba..0e624e4a9 100644 --- a/crates/fj-core/src/operations/transform/shell.rs +++ b/crates/fj-core/src/operations/transform/shell.rs @@ -5,12 +5,14 @@ use crate::{topology::Shell, Core}; use super::{TransformCache, TransformObject}; impl TransformObject for Shell { + type Transformed = Self; + fn transform_with_cache( - &self, + self, transform: &Transform, core: &mut Core, cache: &mut TransformCache, - ) -> Self { + ) -> Self::Transformed { let faces = self .faces() .iter() diff --git a/crates/fj-core/src/operations/transform/solid.rs b/crates/fj-core/src/operations/transform/solid.rs index 6b8a1cdca..9ca8ed284 100644 --- a/crates/fj-core/src/operations/transform/solid.rs +++ b/crates/fj-core/src/operations/transform/solid.rs @@ -5,12 +5,14 @@ use crate::{topology::Solid, Core}; use super::{TransformCache, TransformObject}; impl TransformObject for Solid { + type Transformed = Self; + fn transform_with_cache( - &self, + self, transform: &Transform, core: &mut Core, cache: &mut TransformCache, - ) -> Self { + ) -> Self::Transformed { let shells = self.shells().iter().cloned().map(|shell| { shell.transform_with_cache(transform, core, cache) diff --git a/crates/fj-core/src/operations/transform/surface.rs b/crates/fj-core/src/operations/transform/surface.rs index 0a61532e5..74c8a4049 100644 --- a/crates/fj-core/src/operations/transform/surface.rs +++ b/crates/fj-core/src/operations/transform/surface.rs @@ -7,19 +7,21 @@ use crate::{ use super::{TransformCache, TransformObject}; impl TransformObject for Handle { + type Transformed = Self; + fn transform_with_cache( - &self, + self, transform: &Transform, core: &mut Core, cache: &mut TransformCache, - ) -> Self { + ) -> Self::Transformed { cache - .entry(self) + .entry(&self) .or_insert_with(|| { let surface = Surface::new().insert(core); let geometry = - core.layers.geometry.of_surface(self).transform(transform); + core.layers.geometry.of_surface(&self).transform(transform); core.layers .geometry .define_surface(surface.clone(), geometry); diff --git a/crates/fj-core/src/operations/transform/vertex.rs b/crates/fj-core/src/operations/transform/vertex.rs index 9e0f761bb..9a971a1ba 100644 --- a/crates/fj-core/src/operations/transform/vertex.rs +++ b/crates/fj-core/src/operations/transform/vertex.rs @@ -5,12 +5,14 @@ use crate::{topology::Vertex, Core}; use super::{TransformCache, TransformObject}; impl TransformObject for Vertex { + type Transformed = Self; + fn transform_with_cache( - &self, + self, _: &Transform, _: &mut Core, _: &mut TransformCache, - ) -> Self { + ) -> Self::Transformed { // There's nothing to actually transform here, as `Vertex` holds no // data. We still need this implementation though, as a new `Vertex` // object must be created to represent the new and transformed vertex.