Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement TransformObject for Handle<Surface> #2245

Merged
merged 3 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/fj-core/src/operations/sweep/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub trait SweepRegion {
/// operation's scope.
fn sweep_region(
&self,
surface: &Surface,
surface: &Handle<Surface>,
color: Option<Color>,
path: impl Into<Vector<3>>,
cache: &mut SweepCache,
Expand All @@ -43,7 +43,7 @@ pub trait SweepRegion {
impl SweepRegion for Region {
fn sweep_region(
&self,
surface: &Surface,
surface: &Handle<Surface>,
color: Option<Color>,
path: impl Into<Vector<3>>,
cache: &mut SweepCache,
Expand Down
20 changes: 13 additions & 7 deletions crates/fj-core/src/operations/transform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -101,10 +101,19 @@ where
pub struct TransformCache(TypeMap);

impl TransformCache {
fn entry<T: 'static>(
&mut self,
key: &Handle<T>,
) -> btree_map::Entry<ObjectId, Handle<T>> {
let map = self
.0
.entry::<BTreeMap<ObjectId, Handle<T>>>()
.or_insert_with(BTreeMap::new);

map.entry(key.id())
}

fn get<T: 'static>(&mut self, key: &Handle<T>) -> Option<&Handle<T>> {
// 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::<BTreeMap<ObjectId, Handle<T>>>()
Expand All @@ -114,9 +123,6 @@ impl TransformCache {
}

fn insert<T: 'static>(&mut self, key: Handle<T>, value: Handle<T>) {
// 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::<BTreeMap<ObjectId, Handle<T>>>()
Expand Down
19 changes: 13 additions & 6 deletions crates/fj-core/src/operations/transform/surface.rs
Original file line number Diff line number Diff line change
@@ -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<Surface> {
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()
}
}