Skip to content

Commit

Permalink
Merge pull request #2353 from hannobraun/geometry
Browse files Browse the repository at this point in the history
Set curve geometry when reverting curve coordinate systems
  • Loading branch information
hannobraun committed May 8, 2024
2 parents b7c8432 + 1476fc4 commit b0ed3c6
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 29 deletions.
17 changes: 9 additions & 8 deletions crates/fj-core/src/operations/build/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,10 @@ pub trait BuildShell {
.update_half_edge(
cycle.half_edges().nth_circular(0),
|edge, core| {
[edge.reverse_curve_coordinate_systems(
core,
)]
[(edge, bad.face.surface())
.reverse_curve_coordinate_systems(
core,
)]
},
core,
)
Expand Down Expand Up @@ -207,7 +208,7 @@ pub trait BuildShell {
.update_half_edge(
cycle.half_edges().nth_circular(1),
|edge, core| {
[edge
[(edge, dac.face.surface())
.reverse_curve_coordinate_systems(core)]
},
core,
Expand All @@ -222,7 +223,7 @@ pub trait BuildShell {
.update_half_edge(
cycle.half_edges().nth_circular(0),
|edge, core| {
[edge
[(edge, dac.face.surface())
.reverse_curve_coordinate_systems(core)]
},
core,
Expand Down Expand Up @@ -252,23 +253,23 @@ pub trait BuildShell {
.update_half_edge(
cycle.half_edges().nth_circular(0),
|edge, core| {
[edge
[(edge, cbd.face.surface())
.reverse_curve_coordinate_systems(core)]
},
core,
)
.update_half_edge(
cycle.half_edges().nth_circular(1),
|edge, core| {
[edge
[(edge, cbd.face.surface())
.reverse_curve_coordinate_systems(core)]
},
core,
)
.update_half_edge(
cycle.half_edges().nth_circular(2),
|edge, core| {
[edge
[(edge, cbd.face.surface())
.reverse_curve_coordinate_systems(core)]
},
core,
Expand Down
54 changes: 54 additions & 0 deletions crates/fj-core/src/operations/reverse/curve.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use crate::{
operations::{derive::DeriveFrom, insert::Insert},
storage::Handle,
topology::{Curve, Surface},
Core,
};

use super::ReverseCurveCoordinateSystems;

impl ReverseCurveCoordinateSystems for (&Handle<Curve>, &Handle<Surface>) {
type Reversed = Handle<Curve>;

fn reverse_curve_coordinate_systems(
self,
core: &mut Core,
) -> Self::Reversed {
// We don't *actually* need a surface here, because *all* local
// definitions need to be reversed in sync anyway. However, then this
// method couldn't be called in `HalfEdge`'s implementation, meaning the
// way this trait works had to change completely.
//
// At this point it's probably not worth it to re-architect the trait,
// since eventually, redundant geometry definitions shouldn't exist any
// more, and then the existence of this trait, at least in its current
// form, is in question anyway.
//
// Once the dust has settled, we can figure out what needs to happen
// here. In the meantime, we can have this weird implementation, and
// rely on the callers to make sure everything stays consistent.
//
// [1]: https://github.com/hannobraun/fornjot/issues/2290
let (curve, surface) = self;

let mut curve_geom = core
.layers
.geometry
.of_curve(curve)
.unwrap()
.local_on(surface)
.unwrap()
.clone();
curve_geom.path = curve_geom.path.reverse();

let curve = Curve::new().insert(core).derive_from(curve, core);

core.layers.geometry.define_curve(
curve.clone(),
surface.clone(),
curve_geom,
);

curve
}
}
11 changes: 7 additions & 4 deletions crates/fj-core/src/operations/reverse/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use crate::{
operations::{
derive::DeriveFrom, geometry::UpdateHalfEdgeGeometry, insert::Insert,
},
topology::{Cycle, HalfEdge},
storage::Handle,
topology::{Cycle, HalfEdge, Surface},
Core,
};

Expand Down Expand Up @@ -33,17 +34,19 @@ impl Reverse for Cycle {
}
}

impl ReverseCurveCoordinateSystems for &Cycle {
impl ReverseCurveCoordinateSystems for (&Cycle, &Handle<Surface>) {
type Reversed = Cycle;

fn reverse_curve_coordinate_systems(
self,
core: &mut Core,
) -> Self::Reversed {
let edges = self
let (cycle, surface) = self;

let edges = cycle
.half_edges()
.iter()
.map(|edge| edge.reverse_curve_coordinate_systems(core));
.map(|edge| (edge, surface).reverse_curve_coordinate_systems(core));

Cycle::new(edges)
}
Expand Down
5 changes: 2 additions & 3 deletions crates/fj-core/src/operations/reverse/face.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::borrow::Borrow;
use std::{borrow::Borrow, ops::Deref};

use crate::{
operations::{
Expand Down Expand Up @@ -49,8 +49,7 @@ impl ReverseCurveCoordinateSystems for &Face {
self,
core: &mut Core,
) -> Self::Reversed {
let region = self
.region()
let region = (self.region().deref(), self.surface())
.reverse_curve_coordinate_systems(core)
.insert(core)
.derive_from(self.region(), core);
Expand Down
18 changes: 11 additions & 7 deletions crates/fj-core/src/operations/reverse/half_edge.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
use crate::{
operations::{derive::DeriveFrom, insert::Insert},
storage::Handle,
topology::HalfEdge,
topology::{HalfEdge, Surface},
Core,
};

use super::ReverseCurveCoordinateSystems;

impl ReverseCurveCoordinateSystems for &Handle<HalfEdge> {
impl ReverseCurveCoordinateSystems for (&Handle<HalfEdge>, &Handle<Surface>) {
type Reversed = Handle<HalfEdge>;

fn reverse_curve_coordinate_systems(
self,
core: &mut Core,
) -> Self::Reversed {
let mut half_edge_geom = *core.layers.geometry.of_half_edge(self);
let (half_edge, surface) = self;

let mut half_edge_geom = *core.layers.geometry.of_half_edge(half_edge);
half_edge_geom.path = half_edge_geom.path.reverse();
half_edge_geom.boundary = half_edge_geom.boundary.reverse();

let half_edge =
HalfEdge::new(self.curve().clone(), self.start_vertex().clone())
.insert(core)
.derive_from(self, core);
let curve =
(half_edge.curve(), surface).reverse_curve_coordinate_systems(core);

let half_edge = HalfEdge::new(curve, half_edge.start_vertex().clone())
.insert(core)
.derive_from(half_edge, core);

core.layers
.geometry
Expand Down
1 change: 1 addition & 0 deletions crates/fj-core/src/operations/reverse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use crate::Core;

mod curve;
mod cycle;
mod face;
mod half_edge;
Expand Down
18 changes: 11 additions & 7 deletions crates/fj-core/src/operations/reverse/region.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::ops::Deref;

use crate::{
operations::{derive::DeriveFrom, insert::Insert},
topology::Region,
storage::Handle,
topology::{Region, Surface},
Core,
};

Expand All @@ -21,20 +24,21 @@ impl Reverse for Region {
}
}

impl ReverseCurveCoordinateSystems for &Region {
impl ReverseCurveCoordinateSystems for (&Region, &Handle<Surface>) {
type Reversed = Region;

fn reverse_curve_coordinate_systems(
self,
core: &mut Core,
) -> Self::Reversed {
let exterior = self
.exterior()
let (region, surface) = self;

let exterior = (region.exterior().deref(), surface)
.reverse_curve_coordinate_systems(core)
.insert(core)
.derive_from(self.exterior(), core);
let interiors = self.interiors().iter().map(|cycle| {
cycle
.derive_from(region.exterior(), core);
let interiors = region.interiors().iter().map(|cycle| {
(cycle.deref(), surface)
.reverse_curve_coordinate_systems(core)
.insert(core)
.derive_from(cycle, core)
Expand Down

0 comments on commit b0ed3c6

Please sign in to comment.