Skip to content

Commit

Permalink
Merge pull request #2206 from hannobraun/update
Browse files Browse the repository at this point in the history
Make `add_*` methods of `update` operation more convenient to call
  • Loading branch information
hannobraun authored Feb 12, 2024
2 parents 1b2d9d6 + a50f2f9 commit a78d90a
Show file tree
Hide file tree
Showing 23 changed files with 195 additions and 133 deletions.
6 changes: 2 additions & 4 deletions crates/fj-core/src/algorithms/intersect/curve_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ mod tests {
objects::{Cycle, Face},
operations::{
build::{BuildCycle, BuildFace},
insert::Insert,
update::{UpdateFace, UpdateRegion},
},
Instance,
Expand Down Expand Up @@ -195,11 +194,10 @@ mod tests {
|_, core| Cycle::polygon(exterior_points, core),
core,
)
.add_interiors([Cycle::polygon(
interior_points,
.add_interiors(
[Cycle::polygon(interior_points, core)],
core,
)
.insert(&mut core.services)])
},
&mut core,
);
Expand Down
4 changes: 1 addition & 3 deletions crates/fj-core/src/algorithms/triangulate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ mod tests {
objects::{Cycle, Face},
operations::{
build::{BuildCycle, BuildFace},
insert::Insert,
update::{UpdateFace, UpdateRegion},
},
Instance,
Expand Down Expand Up @@ -149,8 +148,7 @@ mod tests {
|_, core| Cycle::polygon([a, b, c, d], core),
core,
)
.add_interiors([Cycle::polygon([e, f, g, h], core)
.insert(&mut core.services)])
.add_interiors([Cycle::polygon([e, f, g, h], core)], core)
},
&mut core,
);
Expand Down
5 changes: 2 additions & 3 deletions crates/fj-core/src/operations/build/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ pub trait BuildCycle {
radius: impl Into<Scalar>,
core: &mut Instance,
) -> Cycle {
let circle =
HalfEdge::circle(center, radius, core).insert(&mut core.services);
Cycle::empty().add_half_edges([circle])
let circle = HalfEdge::circle(center, radius, core);
Cycle::empty().add_half_edges([circle], core)
}

/// Build a polygon
Expand Down
25 changes: 12 additions & 13 deletions crates/fj-core/src/operations/build/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,25 +99,24 @@ pub trait BuildShell {
)
.update_start_vertex(|_, _| vertex, core)
.update_curve(|_, _| curve, core)
.insert(&mut core.services)
})
};

Face::unbound(surface, core)
.update_region(
|region, core| {
region.update_exterior(
|cycle, _| cycle.add_half_edges(half_edges),
core,
)
},
core,
)
.insert(&mut core.services)
Face::unbound(surface, core).update_region(
|region, core| {
region.update_exterior(
|cycle, core| {
cycle.add_half_edges(half_edges, core)
},
core,
)
},
core,
)
})
.collect::<Vec<_>>();

Shell::empty().add_faces(faces)
Shell::empty().add_faces(faces, core)
}

/// Build a tetrahedron from the provided points
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-core/src/operations/build/solid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub trait BuildSolid {
core: &mut Instance,
) -> Tetrahedron {
let shell = Shell::tetrahedron(points, core).insert(&mut core.services);
let solid = Solid::empty().add_shells([shell.shell.clone()]);
let solid = Solid::empty().add_shells([shell.shell.clone()], core);

Tetrahedron { solid, shell }
}
Expand Down
42 changes: 20 additions & 22 deletions crates/fj-core/src/operations/holes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl AddHole for Shell {
.insert(&mut core.services);
let hole = Region::empty(core)
.update_exterior(
|_, _| Cycle::empty().add_half_edges([entry.clone()]),
|_, core| Cycle::empty().add_half_edges([entry.clone()], core),
core,
)
.sweep_region(
Expand All @@ -58,31 +58,31 @@ impl AddHole for Shell {
core,
)
.all_faces()
.map(|face| face.insert(&mut core.services))
.collect::<Vec<_>>();

self.update_face(
location.face,
|face, core| {
[face.update_region(
|region, core| {
region.add_interiors([Cycle::empty()
.add_joined_edges(
region.add_interiors(
[Cycle::empty().add_joined_edges(
[(
entry.clone(),
entry.path(),
entry.boundary(),
)],
core,
)
.insert(&mut core.services)])
)],
core,
)
},
core,
)]
},
core,
)
.add_faces(hole)
.add_faces(hole, core)
}

fn add_through_hole(
Expand Down Expand Up @@ -113,7 +113,7 @@ impl AddHole for Shell {

let swept_region = Region::empty(core)
.update_exterior(
|_, _| Cycle::empty().add_half_edges([entry.clone()]),
|_, core| Cycle::empty().add_half_edges([entry.clone()], core),
core,
)
.sweep_region(
Expand All @@ -123,11 +123,7 @@ impl AddHole for Shell {
core,
);

let hole = swept_region
.side_faces
.into_iter()
.map(|face| face.insert(&mut core.services))
.collect::<Vec<_>>();
let hole = swept_region.side_faces.into_iter().collect::<Vec<_>>();

let exit = swept_region
.top_face
Expand All @@ -141,16 +137,17 @@ impl AddHole for Shell {
|face, core| {
[face.update_region(
|region, core| {
region.add_interiors([Cycle::empty()
.add_joined_edges(
region.add_interiors(
[Cycle::empty().add_joined_edges(
[(
entry.clone(),
entry.path(),
entry.boundary(),
)],
core,
)
.insert(&mut core.services)])
)],
core,
)
},
core,
)]
Expand All @@ -162,19 +159,20 @@ impl AddHole for Shell {
|face, core| {
[face.update_region(
|region, core| {
region.add_interiors([Cycle::empty()
.add_joined_edges(
region.add_interiors(
[Cycle::empty().add_joined_edges(
[(exit.clone(), exit.path(), exit.boundary())],
core,
)
.insert(&mut core.services)])
)],
core,
)
},
core,
)]
},
core,
)
.add_faces(hole)
.add_faces(hole, core)
}
}

Expand Down
13 changes: 7 additions & 6 deletions crates/fj-core/src/operations/join/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::{
objects::{Cycle, HalfEdge},
operations::{
build::BuildHalfEdge,
insert::Insert,
update::{UpdateCycle, UpdateHalfEdge},
},
storage::Handle,
Expand Down Expand Up @@ -85,17 +84,19 @@ impl JoinCycle for Cycle {
>,
Es::IntoIter: Clone + ExactSizeIterator,
{
self.add_half_edges(edges.into_iter().circular_tuple_windows().map(
|((prev_half_edge, _, _), (half_edge, curve, boundary))| {
let half_edges = edges
.into_iter()
.circular_tuple_windows()
.map(|((prev_half_edge, _, _), (half_edge, curve, boundary))| {
HalfEdge::unjoined(curve, boundary, core)
.update_curve(|_, _| half_edge.curve().clone(), core)
.update_start_vertex(
|_, _| prev_half_edge.start_vertex().clone(),
core,
)
.insert(&mut core.services)
},
))
})
.collect::<Vec<_>>();
self.add_half_edges(half_edges, core)
}

fn join_to(
Expand Down
8 changes: 4 additions & 4 deletions crates/fj-core/src/operations/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
//! See [`Merge`], which is currently the only trait in this module, for more
//! information.
use crate::objects::Solid;
use crate::{objects::Solid, Instance};

use super::update::UpdateSolid;

/// Merge two [`Solid`]s
pub trait Merge {
/// Merge this solid with another
#[must_use]
fn merge(&self, other: &Self) -> Self;
fn merge(&self, other: &Self, core: &mut Instance) -> Self;
}

impl Merge for Solid {
fn merge(&self, other: &Self) -> Self {
self.add_shells(other.shells().iter().cloned())
fn merge(&self, other: &Self, core: &mut Instance) -> Self {
self.add_shells(other.shells().iter().cloned(), core)
}
}
30 changes: 20 additions & 10 deletions crates/fj-core/src/operations/split/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,11 @@ impl SplitFace for Shell {
None,
core,
)
.update_start_vertex(|_, _| b.start_vertex().clone(), core)
.insert(&mut core.services);
.update_start_vertex(|_, _| b.start_vertex().clone(), core);
let dividing_half_edge_c_to_b = HalfEdge::from_sibling(
&dividing_half_edge_a_to_d,
d.start_vertex().clone(),
)
.insert(&mut core.services);
);

let mut half_edges_of_face_starting_at_b =
updated_face_after_split_edges
Expand All @@ -134,10 +132,16 @@ impl SplitFace for Shell {
|region, core| {
let mut region = region
.update_exterior(
|cycle, _| {
|cycle, core| {
cycle
.add_half_edges(half_edges_b_to_c_inclusive)
.add_half_edges([dividing_half_edge_c_to_b])
.add_half_edges(
half_edges_b_to_c_inclusive,
core,
)
.add_half_edges(
[dividing_half_edge_c_to_b],
core,
)
},
core,
)
Expand Down Expand Up @@ -166,10 +170,16 @@ impl SplitFace for Shell {
|region, core| {
let mut region = region
.update_exterior(
|cycle, _| {
|cycle, core| {
cycle
.add_half_edges(half_edges_d_to_a_inclusive)
.add_half_edges([dividing_half_edge_a_to_d])
.add_half_edges(
half_edges_d_to_a_inclusive,
core,
)
.add_half_edges(
[dividing_half_edge_a_to_d],
core,
)
},
core,
)
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-core/src/operations/sweep/half_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl SweepHalfEdge for HalfEdge {
edge.insert(&mut core.services)
};

exterior = exterior.add_half_edges([edge.clone()]);
exterior = exterior.add_half_edges([edge.clone()], core);

edge
});
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-core/src/operations/sweep/shell_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ impl SweepFaceOfShell for Shell {
let faces = region
.sweep_region(face.surface(), path, &mut cache, core)
.all_faces()
.map(|face| face.insert(&mut core.services));
.collect::<Vec<_>>();

self.remove_face(&face).add_faces(faces)
self.remove_face(&face).add_faces(faces, core)
}
}
22 changes: 16 additions & 6 deletions crates/fj-core/src/operations/update/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ use crate::{
pub trait UpdateCycle {
/// Add edges to the cycle
#[must_use]
fn add_half_edges(
fn add_half_edges<T>(
&self,
half_edges: impl IntoIterator<Item = Handle<HalfEdge>>,
) -> Self;
half_edges: impl IntoIterator<Item = T>,
core: &mut Instance,
) -> Self
where
T: Insert<Inserted = Handle<HalfEdge>>;

/// Update an edge of the cycle
///
Expand All @@ -33,10 +36,17 @@ pub trait UpdateCycle {
}

impl UpdateCycle for Cycle {
fn add_half_edges(
fn add_half_edges<T>(
&self,
half_edges: impl IntoIterator<Item = Handle<HalfEdge>>,
) -> Self {
half_edges: impl IntoIterator<Item = T>,
core: &mut Instance,
) -> Self
where
T: Insert<Inserted = Handle<HalfEdge>>,
{
let half_edges = half_edges
.into_iter()
.map(|half_edge| half_edge.insert(&mut core.services));
let half_edges = self.half_edges().iter().cloned().chain(half_edges);
Cycle::new(half_edges)
}
Expand Down
Loading

0 comments on commit a78d90a

Please sign in to comment.