From 5d55cc6deb0c5fe751e9cbab8669e4c9b89845fc Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 28 Feb 2024 12:16:59 +0100 Subject: [PATCH 1/3] Remove unused `#[allow(...)]`s --- crates/fj-core/src/operations/transform/mod.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/crates/fj-core/src/operations/transform/mod.rs b/crates/fj-core/src/operations/transform/mod.rs index 6f6bc8c05..cb5d67ead 100644 --- a/crates/fj-core/src/operations/transform/mod.rs +++ b/crates/fj-core/src/operations/transform/mod.rs @@ -102,9 +102,6 @@ pub struct TransformCache(TypeMap); impl TransformCache { 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 +111,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::>>() From 4eec1576eeb4613219c9034015599b23656b0813 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 28 Feb 2024 12:34:25 +0100 Subject: [PATCH 2/3] Require `Handle` in `SweepRegion` --- crates/fj-core/src/operations/sweep/region.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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, From d1bfc9bb3460d78ce33c73d0a65ccb92fd45df10 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 28 Feb 2024 12:31:49 +0100 Subject: [PATCH 3/3] Implement `TransformObject` for `Handle` --- .../fj-core/src/operations/transform/mod.rs | 14 +++++++++++++- .../src/operations/transform/surface.rs | 19 +++++++++++++------ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/crates/fj-core/src/operations/transform/mod.rs b/crates/fj-core/src/operations/transform/mod.rs index cb5d67ead..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,6 +101,18 @@ 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> { let map = self .0 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() } }