Skip to content

Commit

Permalink
Merge pull request #1885 from hannobraun/reverse
Browse files Browse the repository at this point in the history
Clean up `Reverse`
  • Loading branch information
hannobraun authored Jun 13, 2023
2 parents d5c6502 + 8e6354d commit f028442
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 37 deletions.
1 change: 0 additions & 1 deletion crates/fj-core/src/algorithms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
24 changes: 0 additions & 24 deletions crates/fj-core/src/algorithms/reverse/face.rs

This file was deleted.

6 changes: 3 additions & 3 deletions crates/fj-core/src/algorithms/sweep/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -46,7 +46,7 @@ impl Sweep for Handle<Face> {
if is_negative_sweep {
self.clone()
} else {
self.clone().reverse(services)
self.clone().reverse(services).insert(services)
}
};
faces.push(bottom_face.clone());
Expand Down
2 changes: 2 additions & 0 deletions crates/fj-core/src/operations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
mod build;
mod insert;
mod join;
mod reverse;
mod update;

pub use self::{
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ use crate::{
objects::{Cycle, HalfEdge},
operations::Insert,
services::Services,
storage::Handle,
};

use super::Reverse;

impl Reverse for Handle<Cycle> {
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()
Expand All @@ -33,6 +32,6 @@ impl Reverse for Handle<Cycle> {

edges.reverse();

Cycle::new(edges).insert(services)
Cycle::new(edges)
}
}
28 changes: 28 additions & 0 deletions crates/fj-core/src/operations/reverse/face.rs
Original file line number Diff line number Diff line change
@@ -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::<Vec<_>>();

let region = Region::new(exterior, interiors, self.region().color())
.insert(services);

Face::new(self.surface().clone(), region)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
7 changes: 4 additions & 3 deletions crates/fj-core/src/validate/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down Expand Up @@ -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::<Vec<_>>();

let region = Region::new(
Expand Down

0 comments on commit f028442

Please sign in to comment.