diff --git a/crates/fj-core/src/algorithms/intersect/curve_face.rs b/crates/fj-core/src/algorithms/intersect/curve_face.rs index d7afca844c..4c2dc2d908 100644 --- a/crates/fj-core/src/algorithms/intersect/curve_face.rs +++ b/crates/fj-core/src/algorithms/intersect/curve_face.rs @@ -157,7 +157,6 @@ mod tests { objects::{Cycle, Face}, operations::{ build::{BuildCycle, BuildFace}, - insert::Insert, update::{UpdateFace, UpdateRegion}, }, Instance, @@ -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, ); diff --git a/crates/fj-core/src/algorithms/triangulate/mod.rs b/crates/fj-core/src/algorithms/triangulate/mod.rs index cdc60e6d72..e2c8bcc1dd 100644 --- a/crates/fj-core/src/algorithms/triangulate/mod.rs +++ b/crates/fj-core/src/algorithms/triangulate/mod.rs @@ -82,7 +82,6 @@ mod tests { objects::{Cycle, Face}, operations::{ build::{BuildCycle, BuildFace}, - insert::Insert, update::{UpdateFace, UpdateRegion}, }, Instance, @@ -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, ); diff --git a/crates/fj-core/src/operations/build/cycle.rs b/crates/fj-core/src/operations/build/cycle.rs index c31896d5d8..95390cc30c 100644 --- a/crates/fj-core/src/operations/build/cycle.rs +++ b/crates/fj-core/src/operations/build/cycle.rs @@ -24,9 +24,8 @@ pub trait BuildCycle { radius: impl Into, 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 diff --git a/crates/fj-core/src/operations/build/shell.rs b/crates/fj-core/src/operations/build/shell.rs index 1bca88c72d..e8c14f3748 100644 --- a/crates/fj-core/src/operations/build/shell.rs +++ b/crates/fj-core/src/operations/build/shell.rs @@ -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::>(); - Shell::empty().add_faces(faces) + Shell::empty().add_faces(faces, core) } /// Build a tetrahedron from the provided points diff --git a/crates/fj-core/src/operations/build/solid.rs b/crates/fj-core/src/operations/build/solid.rs index 7c7f70d9ae..f484dc0603 100644 --- a/crates/fj-core/src/operations/build/solid.rs +++ b/crates/fj-core/src/operations/build/solid.rs @@ -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 } } diff --git a/crates/fj-core/src/operations/holes.rs b/crates/fj-core/src/operations/holes.rs index 9d4e05a5c2..2ef720d34a 100644 --- a/crates/fj-core/src/operations/holes.rs +++ b/crates/fj-core/src/operations/holes.rs @@ -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( @@ -58,7 +58,6 @@ impl AddHole for Shell { core, ) .all_faces() - .map(|face| face.insert(&mut core.services)) .collect::>(); self.update_face( @@ -66,23 +65,24 @@ 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, )] }, core, ) - .add_faces(hole) + .add_faces(hole, core) } fn add_through_hole( @@ -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( @@ -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::>(); + let hole = swept_region.side_faces.into_iter().collect::>(); let exit = swept_region .top_face @@ -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, )] @@ -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) } } diff --git a/crates/fj-core/src/operations/join/cycle.rs b/crates/fj-core/src/operations/join/cycle.rs index e62b00dabe..da78d9bebf 100644 --- a/crates/fj-core/src/operations/join/cycle.rs +++ b/crates/fj-core/src/operations/join/cycle.rs @@ -8,7 +8,6 @@ use crate::{ objects::{Cycle, HalfEdge}, operations::{ build::BuildHalfEdge, - insert::Insert, update::{UpdateCycle, UpdateHalfEdge}, }, storage::Handle, @@ -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::>(); + self.add_half_edges(half_edges, core) } fn join_to( diff --git a/crates/fj-core/src/operations/merge.rs b/crates/fj-core/src/operations/merge.rs index b46a5d581b..fcf402bd7f 100644 --- a/crates/fj-core/src/operations/merge.rs +++ b/crates/fj-core/src/operations/merge.rs @@ -3,7 +3,7 @@ //! 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; @@ -11,11 +11,11 @@ use super::update::UpdateSolid; 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) } } diff --git a/crates/fj-core/src/operations/split/face.rs b/crates/fj-core/src/operations/split/face.rs index 70beb28b30..af424ee609 100644 --- a/crates/fj-core/src/operations/split/face.rs +++ b/crates/fj-core/src/operations/split/face.rs @@ -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 @@ -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, ) @@ -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, ) diff --git a/crates/fj-core/src/operations/sweep/half_edge.rs b/crates/fj-core/src/operations/sweep/half_edge.rs index 89a6291984..d1653d5948 100644 --- a/crates/fj-core/src/operations/sweep/half_edge.rs +++ b/crates/fj-core/src/operations/sweep/half_edge.rs @@ -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 }); diff --git a/crates/fj-core/src/operations/sweep/shell_face.rs b/crates/fj-core/src/operations/sweep/shell_face.rs index 696ab3fe77..885e034d04 100644 --- a/crates/fj-core/src/operations/sweep/shell_face.rs +++ b/crates/fj-core/src/operations/sweep/shell_face.rs @@ -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::>(); - self.remove_face(&face).add_faces(faces) + self.remove_face(&face).add_faces(faces, core) } } diff --git a/crates/fj-core/src/operations/update/cycle.rs b/crates/fj-core/src/operations/update/cycle.rs index e6a2640337..469fe7ac53 100644 --- a/crates/fj-core/src/operations/update/cycle.rs +++ b/crates/fj-core/src/operations/update/cycle.rs @@ -9,10 +9,13 @@ use crate::{ pub trait UpdateCycle { /// Add edges to the cycle #[must_use] - fn add_half_edges( + fn add_half_edges( &self, - half_edges: impl IntoIterator>, - ) -> Self; + half_edges: impl IntoIterator, + core: &mut Instance, + ) -> Self + where + T: Insert>; /// Update an edge of the cycle /// @@ -33,10 +36,17 @@ pub trait UpdateCycle { } impl UpdateCycle for Cycle { - fn add_half_edges( + fn add_half_edges( &self, - half_edges: impl IntoIterator>, - ) -> Self { + half_edges: impl IntoIterator, + core: &mut Instance, + ) -> Self + where + T: Insert>, + { + 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) } diff --git a/crates/fj-core/src/operations/update/region.rs b/crates/fj-core/src/operations/update/region.rs index bde6501574..5acfdcc8ed 100644 --- a/crates/fj-core/src/operations/update/region.rs +++ b/crates/fj-core/src/operations/update/region.rs @@ -19,10 +19,13 @@ pub trait UpdateRegion { /// Add the provided interiors to the region #[must_use] - fn add_interiors( + fn add_interiors( &self, - interiors: impl IntoIterator>, - ) -> Self; + interiors: impl IntoIterator, + core: &mut Instance, + ) -> Self + where + T: Insert>; /// Update an interior cycle of the region /// @@ -55,10 +58,17 @@ impl UpdateRegion for Region { Region::new(exterior, self.interiors().iter().cloned(), self.color()) } - fn add_interiors( + fn add_interiors( &self, - interiors: impl IntoIterator>, - ) -> Self { + interiors: impl IntoIterator, + core: &mut Instance, + ) -> Self + where + T: Insert>, + { + let interiors = interiors + .into_iter() + .map(|cycle| cycle.insert(&mut core.services)); let interiors = self.interiors().iter().cloned().chain(interiors); Region::new(self.exterior().clone(), interiors, self.color()) } diff --git a/crates/fj-core/src/operations/update/shell.rs b/crates/fj-core/src/operations/update/shell.rs index e4126042be..fcdc63a4e5 100644 --- a/crates/fj-core/src/operations/update/shell.rs +++ b/crates/fj-core/src/operations/update/shell.rs @@ -9,7 +9,13 @@ use crate::{ pub trait UpdateShell { /// Add faces to the shell #[must_use] - fn add_faces(&self, faces: impl IntoIterator>) -> Self; + fn add_faces( + &self, + faces: impl IntoIterator, + core: &mut Instance, + ) -> Self + where + T: Insert>; /// Update a face of the shell /// @@ -34,7 +40,17 @@ pub trait UpdateShell { } impl UpdateShell for Shell { - fn add_faces(&self, faces: impl IntoIterator>) -> Self { + fn add_faces( + &self, + faces: impl IntoIterator, + core: &mut Instance, + ) -> Self + where + T: Insert>, + { + let faces = faces + .into_iter() + .map(|face| face.insert(&mut core.services)); let faces = self.faces().iter().cloned().chain(faces); Shell::new(faces) } diff --git a/crates/fj-core/src/operations/update/sketch.rs b/crates/fj-core/src/operations/update/sketch.rs index 5e698c7666..cdeee9389a 100644 --- a/crates/fj-core/src/operations/update/sketch.rs +++ b/crates/fj-core/src/operations/update/sketch.rs @@ -9,10 +9,13 @@ use crate::{ pub trait UpdateSketch { /// Add a region to the sketch #[must_use] - fn add_regions( + fn add_regions( &self, - regions: impl IntoIterator>, - ) -> Self; + regions: impl IntoIterator, + core: &mut Instance, + ) -> Self + where + T: Insert>; /// Update a region of the sketch /// @@ -33,11 +36,19 @@ pub trait UpdateSketch { } impl UpdateSketch for Sketch { - fn add_regions( + fn add_regions( &self, - regions: impl IntoIterator>, - ) -> Self { - Sketch::new(self.regions().iter().cloned().chain(regions)) + regions: impl IntoIterator, + core: &mut Instance, + ) -> Self + where + T: Insert>, + { + let regions = regions + .into_iter() + .map(|region| region.insert(&mut core.services)); + let regions = self.regions().iter().cloned().chain(regions); + Sketch::new(regions) } fn update_region( diff --git a/crates/fj-core/src/operations/update/solid.rs b/crates/fj-core/src/operations/update/solid.rs index c2715cd0cc..3c4358b725 100644 --- a/crates/fj-core/src/operations/update/solid.rs +++ b/crates/fj-core/src/operations/update/solid.rs @@ -9,10 +9,13 @@ use crate::{ pub trait UpdateSolid { /// Add a shell to the solid #[must_use] - fn add_shells( + fn add_shells( &self, - shells: impl IntoIterator>, - ) -> Self; + shells: impl IntoIterator, + core: &mut Instance, + ) -> Self + where + T: Insert>; /// Update a shell of the solid /// @@ -33,10 +36,17 @@ pub trait UpdateSolid { } impl UpdateSolid for Solid { - fn add_shells( + fn add_shells( &self, - shells: impl IntoIterator>, - ) -> Self { + shells: impl IntoIterator, + core: &mut Instance, + ) -> Self + where + T: Insert>, + { + let shells = shells + .into_iter() + .map(|shell| shell.insert(&mut core.services)); let shells = self.shells().iter().cloned().chain(shells); Solid::new(shells) } diff --git a/crates/fj-core/src/validate/cycle.rs b/crates/fj-core/src/validate/cycle.rs index 168f0ce61d..9bb0f59e86 100644 --- a/crates/fj-core/src/validate/cycle.rs +++ b/crates/fj-core/src/validate/cycle.rs @@ -81,7 +81,6 @@ mod tests { objects::{Cycle, HalfEdge}, operations::{ build::{BuildCycle, BuildHalfEdge}, - insert::Insert, update::UpdateCycle, }, validate::{cycle::CycleValidationError, Validate, ValidationError}, @@ -102,9 +101,8 @@ mod tests { HalfEdge::line_segment([[0., 0.], [1., 0.]], None, &mut core), HalfEdge::line_segment([[0., 0.], [1., 0.]], None, &mut core), ]; - let edges = edges.map(|edge| edge.insert(&mut core.services)); - Cycle::empty().add_half_edges(edges) + Cycle::empty().add_half_edges(edges, &mut core) }; assert_contains_err!( diff --git a/crates/fj-core/src/validate/face.rs b/crates/fj-core/src/validate/face.rs index ead4f0c8a2..a787151765 100644 --- a/crates/fj-core/src/validate/face.rs +++ b/crates/fj-core/src/validate/face.rs @@ -107,12 +107,10 @@ mod tests { |region, core| { region.update_exterior( |cycle, core| { - cycle.add_half_edges([HalfEdge::circle( - [0., 0.], - 1., + cycle.add_half_edges( + [HalfEdge::circle([0., 0.], 1., core)], core, ) - .insert(&mut core.services)]) }, core, ) @@ -147,11 +145,13 @@ mod tests { }, core, ) - .add_interiors([Cycle::polygon( - [[1., 1.], [1., 2.], [2., 1.]], + .add_interiors( + [Cycle::polygon( + [[1., 1.], [1., 2.], [2., 1.]], + core, + )], core, ) - .insert(&mut core.services)]) }, &mut core, ); diff --git a/models/all/src/lib.rs b/models/all/src/lib.rs index d4f8e0c9ee..d0520cd327 100644 --- a/models/all/src/lib.rs +++ b/models/all/src/lib.rs @@ -36,7 +36,7 @@ pub fn model(core: &mut fj::core::Instance) -> Solid { .translate(offset * f, core) .rotate(axis * angle_rad * f, core); - all = all.merge(&model); + all = all.merge(&model, core); } all diff --git a/models/cuboid/src/lib.rs b/models/cuboid/src/lib.rs index 7493900d96..5e614a3ac0 100644 --- a/models/cuboid/src/lib.rs +++ b/models/cuboid/src/lib.rs @@ -3,7 +3,6 @@ use fj::{ objects::{Region, Sketch, Solid}, operations::{ build::{BuildRegion, BuildSketch}, - insert::Insert, sweep::SweepSketch, update::UpdateSketch, }, @@ -21,15 +20,17 @@ pub fn model( let sweep_path = Vector::from([Scalar::ZERO, Scalar::ZERO, z]); Sketch::empty() - .add_regions([Region::polygon( - [ - [-x / 2., -y / 2.], - [x / 2., -y / 2.], - [x / 2., y / 2.], - [-x / 2., y / 2.], - ], + .add_regions( + [Region::polygon( + [ + [-x / 2., -y / 2.], + [x / 2., -y / 2.], + [x / 2., y / 2.], + [-x / 2., y / 2.], + ], + core, + )], core, ) - .insert(&mut core.services)]) .sweep_sketch(bottom_surface, sweep_path, core) } diff --git a/models/spacer/src/lib.rs b/models/spacer/src/lib.rs index 92466858b1..baf0bf611a 100644 --- a/models/spacer/src/lib.rs +++ b/models/spacer/src/lib.rs @@ -3,7 +3,6 @@ use fj::{ objects::{Cycle, Region, Sketch, Solid}, operations::{ build::{BuildCycle, BuildRegion, BuildSketch}, - insert::Insert, reverse::Reverse, sweep::SweepSketch, update::{UpdateRegion, UpdateSketch}, @@ -22,10 +21,12 @@ pub fn model( let sweep_path = Vector::from([0., 0., height]); Sketch::empty() - .add_regions([Region::circle(Point::origin(), outer, core) - .add_interiors([Cycle::circle(Point::origin(), inner, core) - .reverse(core) - .insert(&mut core.services)]) - .insert(&mut core.services)]) + .add_regions( + [Region::circle(Point::origin(), outer, core).add_interiors( + [Cycle::circle(Point::origin(), inner, core).reverse(core)], + core, + )], + core, + ) .sweep_sketch(bottom_surface, sweep_path, core) } diff --git a/models/star/src/lib.rs b/models/star/src/lib.rs index 05baf6791c..4cf106ad6e 100644 --- a/models/star/src/lib.rs +++ b/models/star/src/lib.rs @@ -5,7 +5,6 @@ use fj::{ objects::{Cycle, Region, Sketch, Solid}, operations::{ build::{BuildCycle, BuildRegion, BuildSketch}, - insert::Insert, reverse::Reverse, sweep::SweepSketch, update::{UpdateRegion, UpdateSketch}, @@ -45,10 +44,12 @@ pub fn model( let sweep_path = Vector::from([0., 0., h]); Sketch::empty() - .add_regions([Region::polygon(outer_points, core) - .add_interiors([Cycle::polygon(inner_points, core) - .reverse(core) - .insert(&mut core.services)]) - .insert(&mut core.services)]) + .add_regions( + [Region::polygon(outer_points, core).add_interiors( + [Cycle::polygon(inner_points, core).reverse(core)], + core, + )], + core, + ) .sweep_sketch(bottom_surface, sweep_path, core) } diff --git a/models/vertices-indices/src/lib.rs b/models/vertices-indices/src/lib.rs index ec68a39357..638debb33a 100644 --- a/models/vertices-indices/src/lib.rs +++ b/models/vertices-indices/src/lib.rs @@ -2,16 +2,17 @@ use fj::core::{ objects::{Shell, Solid}, operations::{ build::{BuildShell, BuildSolid}, - insert::Insert, update::UpdateSolid, }, }; pub fn model(core: &mut fj::core::Instance) -> Solid { - Solid::empty().add_shells([Shell::from_vertices_and_indices( - [[0., 0., 0.], [1., 0., 0.], [0., 1., 0.], [0., 0., 1.]], - [[2, 1, 0], [0, 1, 3], [1, 2, 3], [2, 0, 3]], + Solid::empty().add_shells( + [Shell::from_vertices_and_indices( + [[0., 0., 0.], [1., 0., 0.], [0., 1., 0.], [0., 0., 1.]], + [[2, 1, 0], [0, 1, 3], [1, 2, 3], [2, 0, 3]], + core, + )], core, ) - .insert(&mut core.services)]) }