From 2b24a288b03fa5c68ccf52e7047088b7359a9f00 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 17 Jan 2024 11:53:58 +0100 Subject: [PATCH 1/4] Implement `TransformObject` for `Region` --- .../fj-core/src/algorithms/transform/face.rs | 18 ++----------- .../fj-core/src/algorithms/transform/mod.rs | 1 + .../src/algorithms/transform/region.rs | 25 +++++++++++++++++++ 3 files changed, 28 insertions(+), 16 deletions(-) create mode 100644 crates/fj-core/src/algorithms/transform/region.rs diff --git a/crates/fj-core/src/algorithms/transform/face.rs b/crates/fj-core/src/algorithms/transform/face.rs index 2629269e1..4685016e1 100644 --- a/crates/fj-core/src/algorithms/transform/face.rs +++ b/crates/fj-core/src/algorithms/transform/face.rs @@ -1,10 +1,6 @@ use fj_math::Transform; -use crate::{ - objects::{Face, Region}, - operations::insert::Insert, - services::Services, -}; +use crate::{objects::Face, services::Services}; use super::{TransformCache, TransformObject}; @@ -15,24 +11,14 @@ impl TransformObject for Face { services: &mut Services, cache: &mut TransformCache, ) -> Self { - // Color does not need to be transformed. - let color = self.region().color(); - let surface = self .surface() .clone() .transform_with_cache(transform, services, cache); - let exterior = self + let region = self .region() - .exterior() .clone() .transform_with_cache(transform, services, cache); - let interiors = - self.region().interiors().iter().cloned().map(|interior| { - interior.transform_with_cache(transform, services, cache) - }); - - let region = Region::new(exterior, interiors, color).insert(services); Self::new(surface, region) } diff --git a/crates/fj-core/src/algorithms/transform/mod.rs b/crates/fj-core/src/algorithms/transform/mod.rs index cec204432..233afebca 100644 --- a/crates/fj-core/src/algorithms/transform/mod.rs +++ b/crates/fj-core/src/algorithms/transform/mod.rs @@ -4,6 +4,7 @@ mod curve; mod cycle; mod edge; mod face; +mod region; mod shell; mod solid; mod surface; diff --git a/crates/fj-core/src/algorithms/transform/region.rs b/crates/fj-core/src/algorithms/transform/region.rs new file mode 100644 index 000000000..8ade96a69 --- /dev/null +++ b/crates/fj-core/src/algorithms/transform/region.rs @@ -0,0 +1,25 @@ +use crate::objects::Region; + +use super::TransformObject; + +impl TransformObject for Region { + fn transform_with_cache( + self, + transform: &fj_math::Transform, + services: &mut crate::services::Services, + cache: &mut super::TransformCache, + ) -> Self { + // Color does not need to be transformed. + let color = self.color(); + + let exterior = self + .exterior() + .clone() + .transform_with_cache(transform, services, cache); + let interiors = self.interiors().iter().cloned().map(|interior| { + interior.transform_with_cache(transform, services, cache) + }); + + Region::new(exterior, interiors, color) + } +} From b1b840478d926a557ab42aa03b99e368b3445dab Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 17 Jan 2024 11:56:57 +0100 Subject: [PATCH 2/4] Only require `&self` in `transform_with_cache` --- crates/fj-core/src/algorithms/transform/curve.rs | 2 +- crates/fj-core/src/algorithms/transform/cycle.rs | 2 +- crates/fj-core/src/algorithms/transform/edge.rs | 2 +- crates/fj-core/src/algorithms/transform/face.rs | 2 +- crates/fj-core/src/algorithms/transform/mod.rs | 6 +++--- crates/fj-core/src/algorithms/transform/region.rs | 2 +- crates/fj-core/src/algorithms/transform/shell.rs | 2 +- crates/fj-core/src/algorithms/transform/solid.rs | 2 +- crates/fj-core/src/algorithms/transform/surface.rs | 2 +- crates/fj-core/src/algorithms/transform/vertex.rs | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/crates/fj-core/src/algorithms/transform/curve.rs b/crates/fj-core/src/algorithms/transform/curve.rs index d7209c7a9..0651e69dd 100644 --- a/crates/fj-core/src/algorithms/transform/curve.rs +++ b/crates/fj-core/src/algorithms/transform/curve.rs @@ -6,7 +6,7 @@ use super::{TransformCache, TransformObject}; impl TransformObject for Curve { fn transform_with_cache( - self, + &self, _: &Transform, _: &mut Services, _: &mut TransformCache, diff --git a/crates/fj-core/src/algorithms/transform/cycle.rs b/crates/fj-core/src/algorithms/transform/cycle.rs index e9b886939..66e2938ef 100644 --- a/crates/fj-core/src/algorithms/transform/cycle.rs +++ b/crates/fj-core/src/algorithms/transform/cycle.rs @@ -6,7 +6,7 @@ use super::{TransformCache, TransformObject}; impl TransformObject for Cycle { fn transform_with_cache( - self, + &self, transform: &Transform, services: &mut Services, cache: &mut TransformCache, diff --git a/crates/fj-core/src/algorithms/transform/edge.rs b/crates/fj-core/src/algorithms/transform/edge.rs index 11526bff0..3ccba88cc 100644 --- a/crates/fj-core/src/algorithms/transform/edge.rs +++ b/crates/fj-core/src/algorithms/transform/edge.rs @@ -6,7 +6,7 @@ use super::{TransformCache, TransformObject}; impl TransformObject for HalfEdge { fn transform_with_cache( - self, + &self, transform: &Transform, services: &mut Services, cache: &mut TransformCache, diff --git a/crates/fj-core/src/algorithms/transform/face.rs b/crates/fj-core/src/algorithms/transform/face.rs index 4685016e1..684271bb5 100644 --- a/crates/fj-core/src/algorithms/transform/face.rs +++ b/crates/fj-core/src/algorithms/transform/face.rs @@ -6,7 +6,7 @@ use super::{TransformCache, TransformObject}; impl TransformObject for Face { fn transform_with_cache( - self, + &self, transform: &Transform, services: &mut Services, cache: &mut TransformCache, diff --git a/crates/fj-core/src/algorithms/transform/mod.rs b/crates/fj-core/src/algorithms/transform/mod.rs index 233afebca..4f827a29f 100644 --- a/crates/fj-core/src/algorithms/transform/mod.rs +++ b/crates/fj-core/src/algorithms/transform/mod.rs @@ -39,7 +39,7 @@ pub trait TransformObject: Sized { /// Transform the object using the provided cache fn transform_with_cache( - self, + &self, transform: &Transform, services: &mut Services, cache: &mut TransformCache, @@ -73,12 +73,12 @@ where T: Clone + Insert> + TransformObject + 'static, { fn transform_with_cache( - self, + &self, transform: &Transform, services: &mut Services, cache: &mut TransformCache, ) -> Self { - if let Some(object) = cache.get(&self) { + if let Some(object) = cache.get(self) { return object.clone(); } diff --git a/crates/fj-core/src/algorithms/transform/region.rs b/crates/fj-core/src/algorithms/transform/region.rs index 8ade96a69..3cef63d47 100644 --- a/crates/fj-core/src/algorithms/transform/region.rs +++ b/crates/fj-core/src/algorithms/transform/region.rs @@ -4,7 +4,7 @@ use super::TransformObject; impl TransformObject for Region { fn transform_with_cache( - self, + &self, transform: &fj_math::Transform, services: &mut crate::services::Services, cache: &mut super::TransformCache, diff --git a/crates/fj-core/src/algorithms/transform/shell.rs b/crates/fj-core/src/algorithms/transform/shell.rs index 835299209..bb7cfba46 100644 --- a/crates/fj-core/src/algorithms/transform/shell.rs +++ b/crates/fj-core/src/algorithms/transform/shell.rs @@ -6,7 +6,7 @@ use super::{TransformCache, TransformObject}; impl TransformObject for Shell { fn transform_with_cache( - self, + &self, transform: &Transform, services: &mut Services, cache: &mut TransformCache, diff --git a/crates/fj-core/src/algorithms/transform/solid.rs b/crates/fj-core/src/algorithms/transform/solid.rs index 976b6bed2..b0a77e2a8 100644 --- a/crates/fj-core/src/algorithms/transform/solid.rs +++ b/crates/fj-core/src/algorithms/transform/solid.rs @@ -6,7 +6,7 @@ use super::{TransformCache, TransformObject}; impl TransformObject for Solid { fn transform_with_cache( - self, + &self, transform: &Transform, services: &mut Services, cache: &mut TransformCache, diff --git a/crates/fj-core/src/algorithms/transform/surface.rs b/crates/fj-core/src/algorithms/transform/surface.rs index 9d7cf7ca3..5ae5fa21d 100644 --- a/crates/fj-core/src/algorithms/transform/surface.rs +++ b/crates/fj-core/src/algorithms/transform/surface.rs @@ -6,7 +6,7 @@ use super::{TransformCache, TransformObject}; impl TransformObject for Surface { fn transform_with_cache( - self, + &self, transform: &Transform, _: &mut Services, _: &mut TransformCache, diff --git a/crates/fj-core/src/algorithms/transform/vertex.rs b/crates/fj-core/src/algorithms/transform/vertex.rs index 95601597e..02854d44f 100644 --- a/crates/fj-core/src/algorithms/transform/vertex.rs +++ b/crates/fj-core/src/algorithms/transform/vertex.rs @@ -6,7 +6,7 @@ use super::{TransformCache, TransformObject}; impl TransformObject for Vertex { fn transform_with_cache( - self, + &self, _: &Transform, _: &mut Services, _: &mut TransformCache, From 167831ba94b14b946e539a3b80a528c8061533bf Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 17 Jan 2024 11:56:57 +0100 Subject: [PATCH 3/4] Only require `&self` in rest of `TransformObject` --- crates/fj-core/src/algorithms/transform/mod.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/fj-core/src/algorithms/transform/mod.rs b/crates/fj-core/src/algorithms/transform/mod.rs index 4f827a29f..e37de3d59 100644 --- a/crates/fj-core/src/algorithms/transform/mod.rs +++ b/crates/fj-core/src/algorithms/transform/mod.rs @@ -32,7 +32,11 @@ use crate::{ /// hasn't been done so far, is that no one has put in the work yet. pub trait TransformObject: Sized { /// Transform the object - fn transform(self, transform: &Transform, services: &mut Services) -> Self { + fn transform( + &self, + transform: &Transform, + services: &mut Services, + ) -> Self { let mut cache = TransformCache::default(); self.transform_with_cache(transform, services, &mut cache) } @@ -49,7 +53,7 @@ pub trait TransformObject: Sized { /// /// Convenience wrapper around [`TransformObject::transform`]. fn translate( - self, + &self, offset: impl Into>, services: &mut Services, ) -> Self { @@ -60,7 +64,7 @@ pub trait TransformObject: Sized { /// /// Convenience wrapper around [`TransformObject::transform`]. fn rotate( - self, + &self, axis_angle: impl Into>, services: &mut Services, ) -> Self { From b280a9ce6387ffa7038b23854089a93cb0af593b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 17 Jan 2024 12:02:18 +0100 Subject: [PATCH 4/4] Move `transform` to `operations` --- crates/fj-core/src/algorithms/intersect/ray_face.rs | 9 +++------ .../fj-core/src/algorithms/intersect/surface_surface.rs | 2 +- crates/fj-core/src/algorithms/mod.rs | 1 - crates/fj-core/src/operations/mod.rs | 1 + crates/fj-core/src/operations/sweep/region.rs | 5 +++-- .../src/{algorithms => operations}/transform/curve.rs | 0 .../src/{algorithms => operations}/transform/cycle.rs | 0 .../src/{algorithms => operations}/transform/edge.rs | 0 .../src/{algorithms => operations}/transform/face.rs | 0 .../src/{algorithms => operations}/transform/mod.rs | 0 .../src/{algorithms => operations}/transform/region.rs | 0 .../src/{algorithms => operations}/transform/shell.rs | 0 .../src/{algorithms => operations}/transform/solid.rs | 0 .../src/{algorithms => operations}/transform/surface.rs | 0 .../src/{algorithms => operations}/transform/vertex.rs | 0 models/all/src/lib.rs | 5 +++-- 16 files changed, 11 insertions(+), 12 deletions(-) rename crates/fj-core/src/{algorithms => operations}/transform/curve.rs (100%) rename crates/fj-core/src/{algorithms => operations}/transform/cycle.rs (100%) rename crates/fj-core/src/{algorithms => operations}/transform/edge.rs (100%) rename crates/fj-core/src/{algorithms => operations}/transform/face.rs (100%) rename crates/fj-core/src/{algorithms => operations}/transform/mod.rs (100%) rename crates/fj-core/src/{algorithms => operations}/transform/region.rs (100%) rename crates/fj-core/src/{algorithms => operations}/transform/shell.rs (100%) rename crates/fj-core/src/{algorithms => operations}/transform/solid.rs (100%) rename crates/fj-core/src/{algorithms => operations}/transform/surface.rs (100%) rename crates/fj-core/src/{algorithms => operations}/transform/vertex.rs (100%) diff --git a/crates/fj-core/src/algorithms/intersect/ray_face.rs b/crates/fj-core/src/algorithms/intersect/ray_face.rs index 24ce26c20..ebe426c99 100644 --- a/crates/fj-core/src/algorithms/intersect/ray_face.rs +++ b/crates/fj-core/src/algorithms/intersect/ray_face.rs @@ -145,17 +145,14 @@ mod tests { use fj_math::Point; use crate::{ - algorithms::{ - intersect::{ - ray_face::RayFaceIntersection, HorizontalRayToTheRight, - Intersect, - }, - transform::TransformObject, + algorithms::intersect::{ + ray_face::RayFaceIntersection, HorizontalRayToTheRight, Intersect, }, objects::{Cycle, Face}, operations::{ build::{BuildCycle, BuildFace}, insert::Insert, + transform::TransformObject, update::{UpdateFace, UpdateRegion}, }, services::Services, diff --git a/crates/fj-core/src/algorithms/intersect/surface_surface.rs b/crates/fj-core/src/algorithms/intersect/surface_surface.rs index 0b2022e02..8349a599e 100644 --- a/crates/fj-core/src/algorithms/intersect/surface_surface.rs +++ b/crates/fj-core/src/algorithms/intersect/surface_surface.rs @@ -76,7 +76,7 @@ mod tests { use pretty_assertions::assert_eq; use crate::{ - algorithms::transform::TransformObject, geometry::SurfacePath, + geometry::SurfacePath, operations::transform::TransformObject, services::Services, }; diff --git a/crates/fj-core/src/algorithms/mod.rs b/crates/fj-core/src/algorithms/mod.rs index 6665e8ba5..62c8b82a8 100644 --- a/crates/fj-core/src/algorithms/mod.rs +++ b/crates/fj-core/src/algorithms/mod.rs @@ -13,5 +13,4 @@ pub mod approx; pub mod bounding_volume; pub mod intersect; -pub mod transform; pub mod triangulate; diff --git a/crates/fj-core/src/operations/mod.rs b/crates/fj-core/src/operations/mod.rs index 15c69c85c..730f3ded7 100644 --- a/crates/fj-core/src/operations/mod.rs +++ b/crates/fj-core/src/operations/mod.rs @@ -48,4 +48,5 @@ pub mod replace; pub mod reverse; pub mod split; pub mod sweep; +pub mod transform; pub mod update; diff --git a/crates/fj-core/src/operations/sweep/region.rs b/crates/fj-core/src/operations/sweep/region.rs index 121cdd8ef..30eea7c3d 100644 --- a/crates/fj-core/src/operations/sweep/region.rs +++ b/crates/fj-core/src/operations/sweep/region.rs @@ -2,9 +2,10 @@ use fj_interop::Color; use fj_math::Vector; use crate::{ - algorithms::transform::TransformObject, objects::{Cycle, Face, Region, Surface}, - operations::{insert::Insert, reverse::Reverse}, + operations::{ + insert::Insert, reverse::Reverse, transform::TransformObject, + }, services::Services, storage::Handle, }; diff --git a/crates/fj-core/src/algorithms/transform/curve.rs b/crates/fj-core/src/operations/transform/curve.rs similarity index 100% rename from crates/fj-core/src/algorithms/transform/curve.rs rename to crates/fj-core/src/operations/transform/curve.rs diff --git a/crates/fj-core/src/algorithms/transform/cycle.rs b/crates/fj-core/src/operations/transform/cycle.rs similarity index 100% rename from crates/fj-core/src/algorithms/transform/cycle.rs rename to crates/fj-core/src/operations/transform/cycle.rs diff --git a/crates/fj-core/src/algorithms/transform/edge.rs b/crates/fj-core/src/operations/transform/edge.rs similarity index 100% rename from crates/fj-core/src/algorithms/transform/edge.rs rename to crates/fj-core/src/operations/transform/edge.rs diff --git a/crates/fj-core/src/algorithms/transform/face.rs b/crates/fj-core/src/operations/transform/face.rs similarity index 100% rename from crates/fj-core/src/algorithms/transform/face.rs rename to crates/fj-core/src/operations/transform/face.rs diff --git a/crates/fj-core/src/algorithms/transform/mod.rs b/crates/fj-core/src/operations/transform/mod.rs similarity index 100% rename from crates/fj-core/src/algorithms/transform/mod.rs rename to crates/fj-core/src/operations/transform/mod.rs diff --git a/crates/fj-core/src/algorithms/transform/region.rs b/crates/fj-core/src/operations/transform/region.rs similarity index 100% rename from crates/fj-core/src/algorithms/transform/region.rs rename to crates/fj-core/src/operations/transform/region.rs diff --git a/crates/fj-core/src/algorithms/transform/shell.rs b/crates/fj-core/src/operations/transform/shell.rs similarity index 100% rename from crates/fj-core/src/algorithms/transform/shell.rs rename to crates/fj-core/src/operations/transform/shell.rs diff --git a/crates/fj-core/src/algorithms/transform/solid.rs b/crates/fj-core/src/operations/transform/solid.rs similarity index 100% rename from crates/fj-core/src/algorithms/transform/solid.rs rename to crates/fj-core/src/operations/transform/solid.rs diff --git a/crates/fj-core/src/algorithms/transform/surface.rs b/crates/fj-core/src/operations/transform/surface.rs similarity index 100% rename from crates/fj-core/src/algorithms/transform/surface.rs rename to crates/fj-core/src/operations/transform/surface.rs diff --git a/crates/fj-core/src/algorithms/transform/vertex.rs b/crates/fj-core/src/operations/transform/vertex.rs similarity index 100% rename from crates/fj-core/src/algorithms/transform/vertex.rs rename to crates/fj-core/src/operations/transform/vertex.rs diff --git a/models/all/src/lib.rs b/models/all/src/lib.rs index 784a9b5cf..fccf189b7 100644 --- a/models/all/src/lib.rs +++ b/models/all/src/lib.rs @@ -1,8 +1,9 @@ use fj::{ core::{ - algorithms::transform::TransformObject, objects::Solid, - operations::{insert::Insert, merge::Merge}, + operations::{ + insert::Insert, merge::Merge, transform::TransformObject, + }, services::Services, storage::Handle, },