diff --git a/crates/fj-core/src/algorithms/mod.rs b/crates/fj-core/src/algorithms/mod.rs index 2786c3f95..c7fa369d4 100644 --- a/crates/fj-core/src/algorithms/mod.rs +++ b/crates/fj-core/src/algorithms/mod.rs @@ -6,7 +6,6 @@ pub mod approx; pub mod bounding_volume; pub mod intersect; -pub mod reverse; pub mod sweep; pub mod transform; pub mod triangulate; diff --git a/crates/fj-core/src/algorithms/reverse/face.rs b/crates/fj-core/src/algorithms/reverse/face.rs deleted file mode 100644 index 089964680..000000000 --- a/crates/fj-core/src/algorithms/reverse/face.rs +++ /dev/null @@ -1,24 +0,0 @@ -use crate::{ - objects::{Face, Region}, - operations::Insert, - services::Services, - storage::Handle, -}; - -use super::Reverse; - -impl Reverse for Handle { - fn reverse(self, services: &mut Services) -> Self { - let exterior = self.region().exterior().clone().reverse(services); - let interiors = self - .region() - .interiors() - .map(|cycle| cycle.clone().reverse(services)) - .collect::>(); - - let region = Region::new(exterior, interiors, self.region().color()) - .insert(services); - - Face::new(self.surface().clone(), region).insert(services) - } -} diff --git a/crates/fj-core/src/algorithms/sweep/face.rs b/crates/fj-core/src/algorithms/sweep/face.rs index 627dfc98e..4e1f5981a 100644 --- a/crates/fj-core/src/algorithms/sweep/face.rs +++ b/crates/fj-core/src/algorithms/sweep/face.rs @@ -4,10 +4,10 @@ use fj_math::{Scalar, Vector}; use itertools::Itertools; use crate::{ - algorithms::{reverse::Reverse, transform::TransformObject}, + algorithms::transform::TransformObject, geometry::curve::GlobalPath, objects::{Cycle, Face, Region, Shell}, - operations::{BuildCycle, Insert, JoinCycle}, + operations::{BuildCycle, Insert, JoinCycle, Reverse}, services::Services, storage::Handle, }; @@ -46,7 +46,7 @@ impl Sweep for Handle { if is_negative_sweep { self.clone() } else { - self.clone().reverse(services) + self.clone().reverse(services).insert(services) } }; faces.push(bottom_face.clone()); diff --git a/crates/fj-core/src/operations/mod.rs b/crates/fj-core/src/operations/mod.rs index 4bd694904..5d43064e4 100644 --- a/crates/fj-core/src/operations/mod.rs +++ b/crates/fj-core/src/operations/mod.rs @@ -3,6 +3,7 @@ mod build; mod insert; mod join; +mod reverse; mod update; pub use self::{ @@ -18,6 +19,7 @@ pub use self::{ }, insert::{Insert, IsInserted, IsInsertedNo, IsInsertedYes}, join::cycle::JoinCycle, + reverse::Reverse, update::{ cycle::UpdateCycle, edge::UpdateHalfEdge, face::UpdateFace, region::UpdateRegion, shell::UpdateShell, sketch::UpdateSketch, diff --git a/crates/fj-core/src/algorithms/reverse/cycle.rs b/crates/fj-core/src/operations/reverse/cycle.rs similarity index 83% rename from crates/fj-core/src/algorithms/reverse/cycle.rs rename to crates/fj-core/src/operations/reverse/cycle.rs index 5bef5fa7f..0db018408 100644 --- a/crates/fj-core/src/algorithms/reverse/cycle.rs +++ b/crates/fj-core/src/operations/reverse/cycle.rs @@ -4,13 +4,12 @@ use crate::{ objects::{Cycle, HalfEdge}, operations::Insert, services::Services, - storage::Handle, }; use super::Reverse; -impl Reverse for Handle { - fn reverse(self, services: &mut Services) -> Self { +impl Reverse for Cycle { + fn reverse(&self, services: &mut Services) -> Self { let mut edges = self .half_edges() .cloned() @@ -33,6 +32,6 @@ impl Reverse for Handle { edges.reverse(); - Cycle::new(edges).insert(services) + Cycle::new(edges) } } diff --git a/crates/fj-core/src/operations/reverse/face.rs b/crates/fj-core/src/operations/reverse/face.rs new file mode 100644 index 000000000..deee5c378 --- /dev/null +++ b/crates/fj-core/src/operations/reverse/face.rs @@ -0,0 +1,28 @@ +use crate::{ + objects::{Face, Region}, + operations::Insert, + services::Services, +}; + +use super::Reverse; + +impl Reverse for Face { + fn reverse(&self, services: &mut Services) -> Self { + let exterior = self + .region() + .exterior() + .clone() + .reverse(services) + .insert(services); + let interiors = self + .region() + .interiors() + .map(|cycle| cycle.clone().reverse(services).insert(services)) + .collect::>(); + + let region = Region::new(exterior, interiors, self.region().color()) + .insert(services); + + Face::new(self.surface().clone(), region) + } +} diff --git a/crates/fj-core/src/algorithms/reverse/mod.rs b/crates/fj-core/src/operations/reverse/mod.rs similarity index 72% rename from crates/fj-core/src/algorithms/reverse/mod.rs rename to crates/fj-core/src/operations/reverse/mod.rs index 76a1f74d9..bb99a3bd7 100644 --- a/crates/fj-core/src/algorithms/reverse/mod.rs +++ b/crates/fj-core/src/operations/reverse/mod.rs @@ -6,7 +6,7 @@ mod cycle; mod face; /// Reverse the direction/orientation of an object -pub trait Reverse: Sized { +pub trait Reverse { /// Reverse the direction/orientation of the object - fn reverse(self, services: &mut Services) -> Self; + fn reverse(&self, services: &mut Services) -> Self; } diff --git a/crates/fj-core/src/validate/face.rs b/crates/fj-core/src/validate/face.rs index cf4f57303..ba059e9c9 100644 --- a/crates/fj-core/src/validate/face.rs +++ b/crates/fj-core/src/validate/face.rs @@ -71,10 +71,11 @@ impl FaceValidationError { #[cfg(test)] mod tests { use crate::{ - algorithms::reverse::Reverse, assert_contains_err, objects::{Cycle, Face, Region}, - operations::{BuildCycle, BuildFace, Insert, UpdateFace, UpdateRegion}, + operations::{ + BuildCycle, BuildFace, Insert, Reverse, UpdateFace, UpdateRegion, + }, services::Services, validate::{FaceValidationError, Validate, ValidationError}, }; @@ -106,7 +107,7 @@ mod tests { .region() .interiors() .cloned() - .map(|cycle| cycle.reverse(&mut services)) + .map(|cycle| cycle.reverse(&mut services).insert(&mut services)) .collect::>(); let region = Region::new(