From ec6d03b633b6537beced420eab4a9e98a7ef63da Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 18 Mar 2024 13:18:12 +0100 Subject: [PATCH 1/4] Add `UpdateHalfEdgeGeometry` It is currently just a placeholder. --- crates/fj-core/src/operations/geometry/half_edge.rs | 2 ++ crates/fj-core/src/operations/geometry/mod.rs | 5 +++++ crates/fj-core/src/operations/mod.rs | 1 + 3 files changed, 8 insertions(+) create mode 100644 crates/fj-core/src/operations/geometry/half_edge.rs create mode 100644 crates/fj-core/src/operations/geometry/mod.rs diff --git a/crates/fj-core/src/operations/geometry/half_edge.rs b/crates/fj-core/src/operations/geometry/half_edge.rs new file mode 100644 index 000000000..04989a3a3 --- /dev/null +++ b/crates/fj-core/src/operations/geometry/half_edge.rs @@ -0,0 +1,2 @@ +/// Update the geometry of a [`HalfEdge`] +pub trait UpdateHalfEdgeGeometry {} diff --git a/crates/fj-core/src/operations/geometry/mod.rs b/crates/fj-core/src/operations/geometry/mod.rs new file mode 100644 index 000000000..5b34f8cd9 --- /dev/null +++ b/crates/fj-core/src/operations/geometry/mod.rs @@ -0,0 +1,5 @@ +//! Operations to update the geometry of objects + +mod half_edge; + +pub use self::half_edge::UpdateHalfEdgeGeometry; diff --git a/crates/fj-core/src/operations/mod.rs b/crates/fj-core/src/operations/mod.rs index 9645aa6ed..38b6c41a3 100644 --- a/crates/fj-core/src/operations/mod.rs +++ b/crates/fj-core/src/operations/mod.rs @@ -40,6 +40,7 @@ pub mod build; pub mod derive; +pub mod geometry; pub mod holes; pub mod insert; pub mod join; From 38129b10baf1aa0ba0352ba7d39a822eccdc8d0a Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 18 Mar 2024 13:20:34 +0100 Subject: [PATCH 2/4] Migrate `update_path` to `UpdateHalfEdgeGeometry` --- .../src/operations/geometry/half_edge.rs | 33 ++++++++++++++++++- .../src/operations/update/half_edge.rs | 26 +-------------- crates/fj-core/src/validate/shell.rs | 1 + 3 files changed, 34 insertions(+), 26 deletions(-) diff --git a/crates/fj-core/src/operations/geometry/half_edge.rs b/crates/fj-core/src/operations/geometry/half_edge.rs index 04989a3a3..9897abc1b 100644 --- a/crates/fj-core/src/operations/geometry/half_edge.rs +++ b/crates/fj-core/src/operations/geometry/half_edge.rs @@ -1,2 +1,33 @@ +use crate::{ + geometry::SurfacePath, objects::HalfEdge, operations::insert::Insert, + storage::Handle, Core, +}; + /// Update the geometry of a [`HalfEdge`] -pub trait UpdateHalfEdgeGeometry {} +pub trait UpdateHalfEdgeGeometry { + /// Update the path of the edge + #[must_use] + fn update_path( + &self, + update: impl FnOnce(SurfacePath) -> SurfacePath, + core: &mut Core, + ) -> Self; +} + +impl UpdateHalfEdgeGeometry for Handle { + fn update_path( + &self, + update: impl FnOnce(SurfacePath) -> SurfacePath, + core: &mut Core, + ) -> Self { + let path = update(self.path()); + + HalfEdge::new( + path, + self.boundary(), + self.curve().clone(), + self.start_vertex().clone(), + ) + .insert(core) + } +} diff --git a/crates/fj-core/src/operations/update/half_edge.rs b/crates/fj-core/src/operations/update/half_edge.rs index c8992c629..3f41a89fb 100644 --- a/crates/fj-core/src/operations/update/half_edge.rs +++ b/crates/fj-core/src/operations/update/half_edge.rs @@ -1,7 +1,7 @@ use fj_math::Point; use crate::{ - geometry::{CurveBoundary, SurfacePath}, + geometry::CurveBoundary, objects::{Curve, HalfEdge, Vertex}, operations::{derive::DeriveFrom, insert::Insert}, storage::Handle, @@ -10,14 +10,6 @@ use crate::{ /// Update a [`HalfEdge`] pub trait UpdateHalfEdge: Sized { - /// Update the path of the edge - #[must_use] - fn update_path( - &self, - update: impl FnOnce(SurfacePath) -> SurfacePath, - core: &mut Core, - ) -> Handle; - /// Update the boundary of the edge #[must_use] fn update_boundary( @@ -47,22 +39,6 @@ pub trait UpdateHalfEdge: Sized { } impl UpdateHalfEdge for HalfEdge { - fn update_path( - &self, - update: impl FnOnce(SurfacePath) -> SurfacePath, - core: &mut Core, - ) -> Handle { - let path = update(self.path()); - - HalfEdge::new( - path, - self.boundary(), - self.curve().clone(), - self.start_vertex().clone(), - ) - .insert(core) - } - fn update_boundary( &self, update: impl FnOnce(CurveBoundary>) -> CurveBoundary>, diff --git a/crates/fj-core/src/validate/shell.rs b/crates/fj-core/src/validate/shell.rs index ff062f243..67c924c70 100644 --- a/crates/fj-core/src/validate/shell.rs +++ b/crates/fj-core/src/validate/shell.rs @@ -403,6 +403,7 @@ mod tests { objects::{Curve, Shell}, operations::{ build::BuildShell, + geometry::UpdateHalfEdgeGeometry, update::{ UpdateCycle, UpdateFace, UpdateHalfEdge, UpdateRegion, UpdateShell, From 671def72bd2f7bb64a0f76cf66b9c16a28aa8399 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 18 Mar 2024 13:21:09 +0100 Subject: [PATCH 3/4] Remove unused trait bound --- crates/fj-core/src/operations/update/half_edge.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/fj-core/src/operations/update/half_edge.rs b/crates/fj-core/src/operations/update/half_edge.rs index 3f41a89fb..697d74fed 100644 --- a/crates/fj-core/src/operations/update/half_edge.rs +++ b/crates/fj-core/src/operations/update/half_edge.rs @@ -9,7 +9,7 @@ use crate::{ }; /// Update a [`HalfEdge`] -pub trait UpdateHalfEdge: Sized { +pub trait UpdateHalfEdge { /// Update the boundary of the edge #[must_use] fn update_boundary( From e51cd314fd999f22bbe3558b487bd3ca41ccd66b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 18 Mar 2024 13:22:15 +0100 Subject: [PATCH 4/4] Migrate `update_boundary` to new trait --- .../src/operations/geometry/half_edge.rs | 31 +++++++++++++++++-- .../src/operations/update/half_edge.rs | 22 ------------- crates/fj-core/src/validate/shell.rs | 7 +++-- 3 files changed, 33 insertions(+), 27 deletions(-) diff --git a/crates/fj-core/src/operations/geometry/half_edge.rs b/crates/fj-core/src/operations/geometry/half_edge.rs index 9897abc1b..54de2f73f 100644 --- a/crates/fj-core/src/operations/geometry/half_edge.rs +++ b/crates/fj-core/src/operations/geometry/half_edge.rs @@ -1,6 +1,11 @@ +use fj_math::Point; + use crate::{ - geometry::SurfacePath, objects::HalfEdge, operations::insert::Insert, - storage::Handle, Core, + geometry::{CurveBoundary, SurfacePath}, + objects::HalfEdge, + operations::insert::Insert, + storage::Handle, + Core, }; /// Update the geometry of a [`HalfEdge`] @@ -12,6 +17,14 @@ pub trait UpdateHalfEdgeGeometry { update: impl FnOnce(SurfacePath) -> SurfacePath, core: &mut Core, ) -> Self; + + /// Update the boundary of the edge + #[must_use] + fn update_boundary( + &self, + update: impl FnOnce(CurveBoundary>) -> CurveBoundary>, + core: &mut Core, + ) -> Self; } impl UpdateHalfEdgeGeometry for Handle { @@ -30,4 +43,18 @@ impl UpdateHalfEdgeGeometry for Handle { ) .insert(core) } + + fn update_boundary( + &self, + update: impl FnOnce(CurveBoundary>) -> CurveBoundary>, + core: &mut Core, + ) -> Self { + HalfEdge::new( + self.path(), + update(self.boundary()), + self.curve().clone(), + self.start_vertex().clone(), + ) + .insert(core) + } } diff --git a/crates/fj-core/src/operations/update/half_edge.rs b/crates/fj-core/src/operations/update/half_edge.rs index 697d74fed..f10ace4d6 100644 --- a/crates/fj-core/src/operations/update/half_edge.rs +++ b/crates/fj-core/src/operations/update/half_edge.rs @@ -1,7 +1,4 @@ -use fj_math::Point; - use crate::{ - geometry::CurveBoundary, objects::{Curve, HalfEdge, Vertex}, operations::{derive::DeriveFrom, insert::Insert}, storage::Handle, @@ -10,13 +7,6 @@ use crate::{ /// Update a [`HalfEdge`] pub trait UpdateHalfEdge { - /// Update the boundary of the edge - #[must_use] - fn update_boundary( - &self, - update: impl FnOnce(CurveBoundary>) -> CurveBoundary>, - ) -> Self; - /// Update the curve of the edge #[must_use] fn update_curve( @@ -39,18 +29,6 @@ pub trait UpdateHalfEdge { } impl UpdateHalfEdge for HalfEdge { - fn update_boundary( - &self, - update: impl FnOnce(CurveBoundary>) -> CurveBoundary>, - ) -> Self { - HalfEdge::new( - self.path(), - update(self.boundary()), - self.curve().clone(), - self.start_vertex().clone(), - ) - } - fn update_curve( &self, update: impl FnOnce(&Handle, &mut Core) -> T, diff --git a/crates/fj-core/src/validate/shell.rs b/crates/fj-core/src/validate/shell.rs index 67c924c70..48bf7a8cb 100644 --- a/crates/fj-core/src/validate/shell.rs +++ b/crates/fj-core/src/validate/shell.rs @@ -436,9 +436,10 @@ mod tests { |path| path.reverse(), core, ) - .update_boundary(|boundary| { - boundary.reverse() - })] + .update_boundary( + |boundary| boundary.reverse(), + core, + )] }, core, )