diff --git a/crates/fj-core/src/operations/reverse/cycle.rs b/crates/fj-core/src/operations/reverse/cycle.rs index 7d2fdc3af..e998dde11 100644 --- a/crates/fj-core/src/operations/reverse/cycle.rs +++ b/crates/fj-core/src/operations/reverse/cycle.rs @@ -4,7 +4,7 @@ use crate::{ services::Services, }; -use super::Reverse; +use super::{Reverse, ReverseCurveCoordinateSystems}; impl Reverse for Cycle { fn reverse(&self, services: &mut Services) -> Self { @@ -27,3 +27,17 @@ impl Reverse for Cycle { Cycle::new(edges) } } + +impl ReverseCurveCoordinateSystems for Cycle { + fn reverse_curve_coordinate_systems( + &self, + services: &mut Services, + ) -> Self { + let edges = self.half_edges().map(|edge| { + edge.reverse_curve_coordinate_systems(services) + .insert(services) + }); + + Cycle::new(edges) + } +} diff --git a/crates/fj-core/src/operations/reverse/edge.rs b/crates/fj-core/src/operations/reverse/edge.rs new file mode 100644 index 000000000..7d53ee4c9 --- /dev/null +++ b/crates/fj-core/src/operations/reverse/edge.rs @@ -0,0 +1,18 @@ +use crate::{objects::HalfEdge, services::Services}; + +use super::ReverseCurveCoordinateSystems; + +impl ReverseCurveCoordinateSystems for HalfEdge { + fn reverse_curve_coordinate_systems(&self, _: &mut Services) -> Self { + let path = self.path().reverse(); + let boundary = self.boundary().reverse(); + + HalfEdge::new( + path, + boundary, + self.curve().clone(), + self.start_vertex().clone(), + self.global_form().clone(), + ) + } +} diff --git a/crates/fj-core/src/operations/reverse/face.rs b/crates/fj-core/src/operations/reverse/face.rs index 801acafa6..12abfa420 100644 --- a/crates/fj-core/src/operations/reverse/face.rs +++ b/crates/fj-core/src/operations/reverse/face.rs @@ -6,7 +6,7 @@ use crate::{ services::Services, }; -use super::Reverse; +use super::{Reverse, ReverseCurveCoordinateSystems}; impl Reverse for Face { fn reverse(&self, services: &mut Services) -> Self { @@ -30,3 +30,47 @@ impl Reverse for Polygon { self.replace_face(face) } } + +impl ReverseCurveCoordinateSystems for Face { + fn reverse_curve_coordinate_systems( + &self, + services: &mut Services, + ) -> Self { + let region = self + .region() + .reverse_curve_coordinate_systems(services) + .insert(services); + Face::new(self.surface().clone(), region) + } +} + +impl ReverseCurveCoordinateSystems + for Polygon +{ + fn reverse_curve_coordinate_systems( + &self, + services: &mut Services, + ) -> Self { + let face = self + .face + .borrow() + .reverse_curve_coordinate_systems(services); + self.replace_face(face) + } +} + +impl ReverseCurveCoordinateSystems + for Polygon +{ + fn reverse_curve_coordinate_systems( + &self, + services: &mut Services, + ) -> Self { + let face: &Face = self.face.borrow(); + let face = face + .reverse_curve_coordinate_systems(services) + .insert(services); + + self.replace_face(face) + } +} diff --git a/crates/fj-core/src/operations/reverse/mod.rs b/crates/fj-core/src/operations/reverse/mod.rs index 235ac707c..b705492b3 100644 --- a/crates/fj-core/src/operations/reverse/mod.rs +++ b/crates/fj-core/src/operations/reverse/mod.rs @@ -3,6 +3,7 @@ use crate::services::Services; mod cycle; +mod edge; mod face; mod region; @@ -12,3 +13,13 @@ pub trait Reverse { #[must_use] fn reverse(&self, services: &mut Services) -> Self; } + +/// Reverse the direction of the curve coordinate systems within an object +pub trait ReverseCurveCoordinateSystems { + /// Reverse the direction of the curve coordinate systems within an object + /// + /// This will not have any effect on object positions in global coordinates. + #[must_use] + fn reverse_curve_coordinate_systems(&self, services: &mut Services) + -> Self; +} diff --git a/crates/fj-core/src/operations/reverse/region.rs b/crates/fj-core/src/operations/reverse/region.rs index cb1b0c09a..9c1c3026f 100644 --- a/crates/fj-core/src/operations/reverse/region.rs +++ b/crates/fj-core/src/operations/reverse/region.rs @@ -1,6 +1,6 @@ use crate::{objects::Region, operations::Insert, services::Services}; -use super::Reverse; +use super::{Reverse, ReverseCurveCoordinateSystems}; impl Reverse for Region { fn reverse(&self, services: &mut Services) -> Self { @@ -12,3 +12,22 @@ impl Reverse for Region { Region::new(exterior, interiors, self.color()) } } + +impl ReverseCurveCoordinateSystems for Region { + fn reverse_curve_coordinate_systems( + &self, + services: &mut Services, + ) -> Self { + let exterior = self + .exterior() + .reverse_curve_coordinate_systems(services) + .insert(services); + let interiors = self.interiors().map(|cycle| { + cycle + .reverse_curve_coordinate_systems(services) + .insert(services) + }); + + Region::new(exterior, interiors, self.color()) + } +}