Skip to content

Commit

Permalink
Merge pull request #2341 from hannobraun/geometry
Browse files Browse the repository at this point in the history
Set curve geometry in `JoinCycle::add_joined_edges`
  • Loading branch information
hannobraun authored May 3, 2024
2 parents eb6ac63 + 36056ee commit 992783e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 11 deletions.
3 changes: 3 additions & 0 deletions crates/fj-core/src/operations/holes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ impl AddHole for Shell {
entry.clone(),
*core.layers.geometry.of_half_edge(&entry),
)],
location.face.surface().clone(),
core,
)],
core,
Expand Down Expand Up @@ -150,6 +151,7 @@ impl AddHole for Shell {
entry.clone(),
*core.layers.geometry.of_half_edge(&entry),
)],
entry_location.face.surface().clone(),
core,
)],
core,
Expand All @@ -171,6 +173,7 @@ impl AddHole for Shell {
exit.clone(),
*core.layers.geometry.of_half_edge(exit),
)],
exit_location.face.surface().clone(),
core,
)],
core,
Expand Down
42 changes: 35 additions & 7 deletions crates/fj-core/src/operations/join/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,36 @@ use std::ops::RangeInclusive;
use itertools::Itertools;

use crate::{
geometry::HalfEdgeGeom,
geometry::{HalfEdgeGeom, LocalCurveGeom},
operations::{
build::BuildHalfEdge,
geometry::UpdateHalfEdgeGeometry,
insert::Insert,
update::{UpdateCycle, UpdateHalfEdge},
},
storage::Handle,
topology::{Cycle, HalfEdge},
topology::{Cycle, HalfEdge, Surface},
Core,
};

/// Join a [`Cycle`] to another
pub trait JoinCycle {
/// Add half-edges to the cycle that are joined to the provided ones
/// Add new half-edges to the cycle that are joined to the provided ones
///
/// This method creates a new half-edge for each half-edge that is provided,
/// joins the new half-edge to the provided one, and adds the new half-edge
/// to the cycle.
///
/// The geometry for each new half-edge needs to be provided as well.
///
/// Also requires the surface that the cycle is defined in.
#[must_use]
fn add_joined_edges<Es>(&self, edges: Es, core: &mut Core) -> Self
fn add_joined_edges<Es>(
&self,
edges: Es,
surface: Handle<Surface>,
core: &mut Core,
) -> Self
where
Es: IntoIterator<Item = (Handle<HalfEdge>, HalfEdgeGeom)>,
Es::IntoIter: Clone + ExactSizeIterator;
Expand Down Expand Up @@ -76,7 +89,12 @@ pub trait JoinCycle {
}

impl JoinCycle for Cycle {
fn add_joined_edges<Es>(&self, edges: Es, core: &mut Core) -> Self
fn add_joined_edges<Es>(
&self,
edges: Es,
surface: Handle<Surface>,
core: &mut Core,
) -> Self
where
Es: IntoIterator<Item = (Handle<HalfEdge>, HalfEdgeGeom)>,
Es::IntoIter: Clone + ExactSizeIterator,
Expand All @@ -85,14 +103,24 @@ impl JoinCycle for Cycle {
.into_iter()
.circular_tuple_windows()
.map(|((prev_half_edge, _), (half_edge, geometry))| {
HalfEdge::unjoined(core)
let half_edge = HalfEdge::unjoined(core)
.update_curve(|_, _| half_edge.curve().clone(), core)
.update_start_vertex(
|_, _| prev_half_edge.start_vertex().clone(),
core,
)
.insert(core)
.set_geometry(geometry, &mut core.layers.geometry)
.set_geometry(geometry, &mut core.layers.geometry);

core.layers.geometry.define_curve(
half_edge.curve().clone(),
surface.clone(),
LocalCurveGeom {
path: geometry.path,
},
);

half_edge
})
.collect::<Vec<_>>();
self.add_half_edges(half_edges, core)
Expand Down
9 changes: 6 additions & 3 deletions crates/fj-core/src/operations/sweep/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub trait SweepCycle {
fn sweep_cycle(
&self,
surface: Handle<Surface>,
top_surface: Handle<Surface>,
color: Option<Color>,
path: impl Into<Vector<3>>,
cache: &mut SweepCache,
Expand All @@ -50,6 +51,7 @@ impl SweepCycle for Cycle {
fn sweep_cycle(
&self,
surface: Handle<Surface>,
top_surface: Handle<Surface>,
color: Option<Color>,
path: impl Into<Vector<3>>,
cache: &mut SweepCache,
Expand All @@ -64,7 +66,7 @@ impl SweepCycle for Cycle {
let (bottom_half_edge, bottom_half_edge_next) =
bottom_half_edge_pair;

let (side_face, top_edge) = bottom_half_edge.sweep_half_edge(
let (side_face, top_half_edge) = bottom_half_edge.sweep_half_edge(
bottom_half_edge_next.start_vertex().clone(),
surface.clone(),
color,
Expand All @@ -76,12 +78,13 @@ impl SweepCycle for Cycle {
faces.push(side_face);

top_edges.push((
top_edge,
top_half_edge,
*core.layers.geometry.of_half_edge(bottom_half_edge),
));
}

let top_cycle = Cycle::empty().add_joined_edges(top_edges, core);
let top_cycle =
Cycle::empty().add_joined_edges(top_edges, top_surface, core);

SweptCycle { faces, top_cycle }
}
Expand Down
8 changes: 7 additions & 1 deletion crates/fj-core/src/operations/sweep/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ impl SweepRegion for Region {

let mut faces = Vec::new();

let top_surface = surface.translate(path, core).insert(core);

let top_exterior = sweep_cycle(
self.exterior(),
surface.clone(),
top_surface.clone(),
color,
&mut faces,
path,
Expand All @@ -69,6 +72,7 @@ impl SweepRegion for Region {
sweep_cycle(
bottom_cycle,
surface.clone(),
top_surface.clone(),
color,
&mut faces,
path,
Expand All @@ -79,7 +83,6 @@ impl SweepRegion for Region {
.collect::<Vec<_>>();

let top_face = {
let top_surface = surface.translate(path, core).insert(core);
let top_region =
Region::new(top_exterior, top_interiors).insert(core);

Expand All @@ -93,9 +96,11 @@ impl SweepRegion for Region {
}
}

#[allow(clippy::too_many_arguments)]
fn sweep_cycle(
bottom_cycle: &Cycle,
bottom_surface: Handle<Surface>,
top_surface: Handle<Surface>,
color: Option<Color>,
faces: &mut Vec<Face>,
path: Vector<3>,
Expand All @@ -104,6 +109,7 @@ fn sweep_cycle(
) -> Handle<Cycle> {
let swept_cycle = bottom_cycle.reverse(core).sweep_cycle(
bottom_surface,
top_surface,
color,
path,
cache,
Expand Down

0 comments on commit 992783e

Please sign in to comment.