Skip to content

Commit

Permalink
Merge pull request hannobraun#2286 from hannobraun/geometry
Browse files Browse the repository at this point in the history
Simplify how half-edge geometry is set
  • Loading branch information
hannobraun authored Mar 23, 2024
2 parents a811b8b + 75fb280 commit 4b74964
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 64 deletions.
19 changes: 7 additions & 12 deletions crates/fj-core/src/operations/build/half_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,16 @@ pub trait BuildHalfEdge {
start_vertex: Handle<Vertex>,
core: &mut Core,
) -> Handle<HalfEdge> {
let half_edge = HalfEdge::new(
HalfEdge::new(
sibling.boundary().reverse(),
sibling.curve().clone(),
start_vertex,
)
.insert(core);

core.layers.geometry.define_half_edge(
half_edge.clone(),
HalfEdgeGeometry {
path: core.layers.geometry.of_half_edge(sibling).path,
},
);

half_edge
.insert(core)
.set_geometry(
core.layers.geometry.of_half_edge(sibling),
&mut core.layers.geometry,
)
}

/// Create an arc
Expand Down Expand Up @@ -112,7 +107,7 @@ pub trait BuildHalfEdge {

HalfEdge::unjoined(boundary, core)
.insert(core)
.set_path(path, &mut core.layers.geometry)
.set_geometry(HalfEdgeGeometry { path }, &mut core.layers.geometry)
}
}

Expand Down
5 changes: 2 additions & 3 deletions crates/fj-core/src/operations/build/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,10 @@ pub trait BuildShell {
.update_start_vertex(|_, _| vertex, core)
.update_curve(|_, _| curve, core)
.insert(core)
.set_path(
.set_geometry(
core.layers
.geometry
.of_half_edge(&half_edge)
.path,
.of_half_edge(&half_edge),
&mut core.layers.geometry,
)
})
Expand Down
16 changes: 8 additions & 8 deletions crates/fj-core/src/operations/geometry/half_edge.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
geometry::{Geometry, HalfEdgeGeometry, SurfacePath},
geometry::{Geometry, HalfEdgeGeometry},
layers::Layer,
objects::HalfEdge,
storage::Handle,
Expand All @@ -8,20 +8,20 @@ use crate::{
/// Update the geometry of a [`HalfEdge`]
pub trait UpdateHalfEdgeGeometry {
/// Set the path of the half-edge
fn set_path(
fn set_geometry(
self,
path: SurfacePath,
geometry: &mut Layer<Geometry>,
geometry: HalfEdgeGeometry,
layer: &mut Layer<Geometry>,
) -> Self;
}

impl UpdateHalfEdgeGeometry for Handle<HalfEdge> {
fn set_path(
fn set_geometry(
self,
path: SurfacePath,
geometry: &mut Layer<Geometry>,
geometry: HalfEdgeGeometry,
layer: &mut Layer<Geometry>,
) -> Self {
geometry.define_half_edge(self.clone(), HalfEdgeGeometry { path });
layer.define_half_edge(self.clone(), geometry);
self
}
}
17 changes: 9 additions & 8 deletions crates/fj-core/src/operations/join/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use fj_math::Point;
use itertools::Itertools;

use crate::{
geometry::{CurveBoundary, SurfacePath},
geometry::{CurveBoundary, HalfEdgeGeometry, SurfacePath},
objects::{Cycle, HalfEdge},
operations::{
build::BuildHalfEdge,
Expand Down Expand Up @@ -97,7 +97,10 @@ impl JoinCycle for Cycle {
core,
)
.insert(core)
.set_path(path, &mut core.layers.geometry)
.set_geometry(
HalfEdgeGeometry { path },
&mut core.layers.geometry,
)
})
.collect::<Vec<_>>();
self.add_half_edges(half_edges, core)
Expand Down Expand Up @@ -141,11 +144,10 @@ impl JoinCycle for Cycle {
core,
)
.insert(core)
.set_path(
.set_geometry(
core.layers
.geometry
.of_half_edge(half_edge)
.path,
.of_half_edge(half_edge),
&mut core.layers.geometry,
)]
},
Expand All @@ -160,11 +162,10 @@ impl JoinCycle for Cycle {
core,
)
.insert(core)
.set_path(
.set_geometry(
core.layers
.geometry
.of_half_edge(half_edge)
.path,
.of_half_edge(half_edge),
&mut core.layers.geometry,
)]
},
Expand Down
7 changes: 4 additions & 3 deletions crates/fj-core/src/operations/reverse/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ impl Reverse for Cycle {
.half_edges()
.pairs()
.map(|(current, next)| {
let path = core.layers.geometry.of_half_edge(current).path;

HalfEdge::new(
current.boundary().reverse(),
current.curve().clone(),
next.start_vertex().clone(),
)
.insert(core)
.derive_from(current, core)
.set_path(path, &mut core.layers.geometry)
.set_geometry(
core.layers.geometry.of_half_edge(current),
&mut core.layers.geometry,
)
})
.collect::<Vec<_>>();

Expand Down
4 changes: 2 additions & 2 deletions crates/fj-core/src/operations/split/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ impl SplitEdge for Shell {
core,
)
.insert(core)
.set_path(
core.layers.geometry.of_half_edge(&sibling_b).path,
.set_geometry(
core.layers.geometry.of_half_edge(&sibling_b),
&mut core.layers.geometry,
);

Expand Down
4 changes: 2 additions & 2 deletions crates/fj-core/src/operations/split/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ impl SplitFace for Shell {
half_edge
.update_start_vertex(|_, _| b.start_vertex().clone(), core)
.insert(core)
.set_path(
core.layers.geometry.of_half_edge(&half_edge).path,
.set_geometry(
core.layers.geometry.of_half_edge(&half_edge),
&mut core.layers.geometry,
)
};
Expand Down
9 changes: 2 additions & 7 deletions crates/fj-core/src/operations/split/half_edge.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use fj_math::Point;

use crate::{
geometry::HalfEdgeGeometry,
objects::{HalfEdge, Vertex},
operations::{derive::DeriveFrom, insert::Insert},
storage::Handle,
Expand Down Expand Up @@ -60,15 +59,11 @@ impl SplitHalfEdge for Handle<HalfEdge> {

core.layers.geometry.define_half_edge(
a.clone(),
HalfEdgeGeometry {
path: core.layers.geometry.of_half_edge(self).path,
},
core.layers.geometry.of_half_edge(self),
);
core.layers.geometry.define_half_edge(
b.clone(),
HalfEdgeGeometry {
path: core.layers.geometry.of_half_edge(self).path,
},
core.layers.geometry.of_half_edge(self),
);

[a, b]
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-core/src/operations/sweep/half_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ impl SweepHalfEdge for Handle<HalfEdge> {
half_edge
};

half_edge.insert(core).set_path(
core.layers.geometry.of_half_edge(&line_segment).path,
half_edge.insert(core).set_geometry(
core.layers.geometry.of_half_edge(&line_segment),
&mut core.layers.geometry,
)
};
Expand Down
13 changes: 5 additions & 8 deletions crates/fj-core/src/operations/transform/edge.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use fj_math::Transform;

use crate::{
geometry::HalfEdgeGeometry, objects::HalfEdge, operations::insert::Insert,
storage::Handle, Core,
objects::HalfEdge, operations::insert::Insert, storage::Handle, Core,
};

use super::{TransformCache, TransformObject};
Expand All @@ -14,9 +13,6 @@ impl TransformObject for Handle<HalfEdge> {
core: &mut Core,
cache: &mut TransformCache,
) -> Self {
// Don't need to transform the path, as that's defined in surface
// coordinates.
let path = core.layers.geometry.of_half_edge(self).path;
let boundary = self.boundary();
let curve = self
.curve()
Expand All @@ -30,9 +26,10 @@ impl TransformObject for Handle<HalfEdge> {
let half_edge =
HalfEdge::new(boundary, curve, start_vertex).insert(core);

core.layers
.geometry
.define_half_edge(half_edge.clone(), HalfEdgeGeometry { path });
core.layers.geometry.define_half_edge(
half_edge.clone(),
core.layers.geometry.of_half_edge(self),
);

half_edge
}
Expand Down
19 changes: 10 additions & 9 deletions crates/fj-core/src/validate/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,18 +445,20 @@ mod tests {
cycle.update_half_edge(
cycle.half_edges().nth_circular(0),
|half_edge, core| {
let mut geometry = core
.layers
.geometry
.of_half_edge(half_edge);
geometry.path = geometry.path.reverse();

[HalfEdge::new(
half_edge.boundary().reverse(),
half_edge.curve().clone(),
half_edge.start_vertex().clone(),
)
.insert(core)
.set_path(
core.layers
.geometry
.of_half_edge(half_edge)
.path
.reverse(),
.set_geometry(
geometry,
&mut core.layers.geometry,
)]
},
Expand Down Expand Up @@ -534,11 +536,10 @@ mod tests {
core,
)
.insert(core)
.set_path(
.set_geometry(
core.layers
.geometry
.of_half_edge(half_edge)
.path,
.of_half_edge(half_edge),
&mut core.layers.geometry,
)]
},
Expand Down

0 comments on commit 4b74964

Please sign in to comment.