Skip to content

Commit

Permalink
Merge pull request #1980 from hannobraun/reverse
Browse files Browse the repository at this point in the history
Add `ReverseCurveCoordinateSystems`
  • Loading branch information
hannobraun authored Aug 2, 2023
2 parents 554277b + 5235248 commit d36cfff
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 3 deletions.
16 changes: 15 additions & 1 deletion crates/fj-core/src/operations/reverse/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
}
18 changes: 18 additions & 0 deletions crates/fj-core/src/operations/reverse/edge.rs
Original file line number Diff line number Diff line change
@@ -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(),
)
}
}
46 changes: 45 additions & 1 deletion crates/fj-core/src/operations/reverse/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -30,3 +30,47 @@ impl<const D: usize> Reverse for Polygon<D, IsInsertedYes> {
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<const D: usize> ReverseCurveCoordinateSystems
for Polygon<D, IsInsertedNo>
{
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<const D: usize> ReverseCurveCoordinateSystems
for Polygon<D, IsInsertedYes>
{
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)
}
}
11 changes: 11 additions & 0 deletions crates/fj-core/src/operations/reverse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use crate::services::Services;

mod cycle;
mod edge;
mod face;
mod region;

Expand All @@ -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;
}
21 changes: 20 additions & 1 deletion crates/fj-core/src/operations/reverse/region.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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())
}
}

0 comments on commit d36cfff

Please sign in to comment.