diff --git a/crates/fj-core/src/operations/sweep/region.rs b/crates/fj-core/src/operations/sweep/region.rs index 78cd701d0..a91255f24 100644 --- a/crates/fj-core/src/operations/sweep/region.rs +++ b/crates/fj-core/src/operations/sweep/region.rs @@ -32,7 +32,7 @@ pub trait SweepRegion { /// operation's scope. fn sweep_region( &self, - surface: &Surface, + surface: &Handle, color: Option, path: impl Into>, cache: &mut SweepCache, @@ -43,7 +43,7 @@ pub trait SweepRegion { impl SweepRegion for Region { fn sweep_region( &self, - surface: &Surface, + surface: &Handle, color: Option, path: impl Into>, cache: &mut SweepCache, diff --git a/crates/fj-core/src/operations/transform/mod.rs b/crates/fj-core/src/operations/transform/mod.rs index 6f6bc8c05..8f93d8aee 100644 --- a/crates/fj-core/src/operations/transform/mod.rs +++ b/crates/fj-core/src/operations/transform/mod.rs @@ -10,7 +10,7 @@ mod solid; mod surface; mod vertex; -use std::collections::BTreeMap; +use std::collections::{btree_map, BTreeMap}; use fj_math::{Transform, Vector}; use type_map::TypeMap; @@ -101,10 +101,19 @@ where pub struct TransformCache(TypeMap); impl TransformCache { + fn entry( + &mut self, + key: &Handle, + ) -> btree_map::Entry> { + let map = self + .0 + .entry::>>() + .or_insert_with(BTreeMap::new); + + map.entry(key.id()) + } + fn get(&mut self, key: &Handle) -> Option<&Handle> { - // Silencing Clippy warning due to false positive in Rust 1.73.0. See: - // https://github.com/rust-lang/rust-clippy/issues/11390#issuecomment-1750951533 - #[allow(clippy::unwrap_or_default)] let map = self .0 .entry::>>() @@ -114,9 +123,6 @@ impl TransformCache { } fn insert(&mut self, key: Handle, value: Handle) { - // Silencing Clippy warning due to false positive in Rust 1.73.0. See: - // https://github.com/rust-lang/rust-clippy/issues/11390#issuecomment-1750951533 - #[allow(clippy::unwrap_or_default)] let map = self .0 .entry::>>() diff --git a/crates/fj-core/src/operations/transform/surface.rs b/crates/fj-core/src/operations/transform/surface.rs index 579d606b4..5e0e9af15 100644 --- a/crates/fj-core/src/operations/transform/surface.rs +++ b/crates/fj-core/src/operations/transform/surface.rs @@ -1,17 +1,24 @@ use fj_math::Transform; -use crate::{objects::Surface, Core}; +use crate::{ + objects::Surface, operations::insert::Insert, storage::Handle, Core, +}; use super::{TransformCache, TransformObject}; -impl TransformObject for Surface { +impl TransformObject for Handle { fn transform_with_cache( &self, transform: &Transform, - _: &mut Core, - _: &mut TransformCache, + core: &mut Core, + cache: &mut TransformCache, ) -> Self { - let geometry = self.geometry().transform(transform); - Self::new(geometry) + cache + .entry(self) + .or_insert_with(|| { + let geometry = self.geometry().transform(transform); + Surface::new(geometry).insert(core) + }) + .clone() } }