From 56991b1822672482692804b360e8dbc65f5f6fca Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 12 Feb 2024 13:05:46 +0100 Subject: [PATCH 01/15] Refactor to improve clarity --- crates/fj-core/src/operations/join/cycle.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/fj-core/src/operations/join/cycle.rs b/crates/fj-core/src/operations/join/cycle.rs index e62b00dab..c275d60a5 100644 --- a/crates/fj-core/src/operations/join/cycle.rs +++ b/crates/fj-core/src/operations/join/cycle.rs @@ -85,7 +85,7 @@ impl JoinCycle for Cycle { >, Es::IntoIter: Clone + ExactSizeIterator, { - self.add_half_edges(edges.into_iter().circular_tuple_windows().map( + 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) @@ -95,7 +95,8 @@ impl JoinCycle for Cycle { ) .insert(&mut core.services) }, - )) + ); + self.add_half_edges(half_edges) } fn join_to( From e036192410d5bc1ebc584389f2bb57ea9a5b2436 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 12 Feb 2024 13:06:31 +0100 Subject: [PATCH 02/15] Refactor to prepare for follow-on change --- crates/fj-core/src/operations/join/cycle.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/fj-core/src/operations/join/cycle.rs b/crates/fj-core/src/operations/join/cycle.rs index c275d60a5..80c0c3193 100644 --- a/crates/fj-core/src/operations/join/cycle.rs +++ b/crates/fj-core/src/operations/join/cycle.rs @@ -85,8 +85,10 @@ impl JoinCycle for Cycle { >, Es::IntoIter: Clone + ExactSizeIterator, { - let 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( @@ -94,8 +96,8 @@ impl JoinCycle for Cycle { core, ) .insert(&mut core.services) - }, - ); + }) + .collect::>(); self.add_half_edges(half_edges) } From 94438abb2c83c2f592191742223edeb548701317 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 12 Feb 2024 13:07:36 +0100 Subject: [PATCH 03/15] Expect `Instance` in `UpdateCycle::add_half_edges` --- crates/fj-core/src/operations/build/cycle.rs | 2 +- crates/fj-core/src/operations/build/shell.rs | 4 +++- crates/fj-core/src/operations/holes.rs | 4 ++-- crates/fj-core/src/operations/join/cycle.rs | 2 +- crates/fj-core/src/operations/split/face.rs | 24 ++++++++++++++----- .../fj-core/src/operations/sweep/half_edge.rs | 2 +- crates/fj-core/src/operations/update/cycle.rs | 2 ++ crates/fj-core/src/validate/cycle.rs | 2 +- crates/fj-core/src/validate/face.rs | 7 +++--- 9 files changed, 32 insertions(+), 17 deletions(-) diff --git a/crates/fj-core/src/operations/build/cycle.rs b/crates/fj-core/src/operations/build/cycle.rs index c31896d5d..7c3cab335 100644 --- a/crates/fj-core/src/operations/build/cycle.rs +++ b/crates/fj-core/src/operations/build/cycle.rs @@ -26,7 +26,7 @@ pub trait BuildCycle { ) -> Cycle { let circle = HalfEdge::circle(center, radius, core).insert(&mut core.services); - Cycle::empty().add_half_edges([circle]) + 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 1bca88c72..0d97a17fb 100644 --- a/crates/fj-core/src/operations/build/shell.rs +++ b/crates/fj-core/src/operations/build/shell.rs @@ -107,7 +107,9 @@ pub trait BuildShell { .update_region( |region, core| { region.update_exterior( - |cycle, _| cycle.add_half_edges(half_edges), + |cycle, core| { + cycle.add_half_edges(half_edges, core) + }, core, ) }, diff --git a/crates/fj-core/src/operations/holes.rs b/crates/fj-core/src/operations/holes.rs index 9d4e05a5c..e7354c7fd 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( @@ -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( diff --git a/crates/fj-core/src/operations/join/cycle.rs b/crates/fj-core/src/operations/join/cycle.rs index 80c0c3193..b2cdb0200 100644 --- a/crates/fj-core/src/operations/join/cycle.rs +++ b/crates/fj-core/src/operations/join/cycle.rs @@ -98,7 +98,7 @@ impl JoinCycle for Cycle { .insert(&mut core.services) }) .collect::>(); - self.add_half_edges(half_edges) + self.add_half_edges(half_edges, core) } fn join_to( diff --git a/crates/fj-core/src/operations/split/face.rs b/crates/fj-core/src/operations/split/face.rs index 70beb28b3..6bd73c0fa 100644 --- a/crates/fj-core/src/operations/split/face.rs +++ b/crates/fj-core/src/operations/split/face.rs @@ -134,10 +134,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 +172,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 89a629198..d1653d594 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/update/cycle.rs b/crates/fj-core/src/operations/update/cycle.rs index e6a264033..ad15de4f2 100644 --- a/crates/fj-core/src/operations/update/cycle.rs +++ b/crates/fj-core/src/operations/update/cycle.rs @@ -12,6 +12,7 @@ pub trait UpdateCycle { fn add_half_edges( &self, half_edges: impl IntoIterator>, + core: &mut Instance, ) -> Self; /// Update an edge of the cycle @@ -36,6 +37,7 @@ impl UpdateCycle for Cycle { fn add_half_edges( &self, half_edges: impl IntoIterator>, + _: &mut Instance, ) -> Self { let half_edges = self.half_edges().iter().cloned().chain(half_edges); Cycle::new(half_edges) diff --git a/crates/fj-core/src/validate/cycle.rs b/crates/fj-core/src/validate/cycle.rs index 168f0ce61..8a6818997 100644 --- a/crates/fj-core/src/validate/cycle.rs +++ b/crates/fj-core/src/validate/cycle.rs @@ -104,7 +104,7 @@ mod tests { ]; 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 ead4f0c8a..ed564fddd 100644 --- a/crates/fj-core/src/validate/face.rs +++ b/crates/fj-core/src/validate/face.rs @@ -107,12 +107,11 @@ 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) + .insert(&mut core.services)], core, ) - .insert(&mut core.services)]) }, core, ) From 0521844a54510c9ee79e111f2c675f0b0c40fcd9 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 12 Feb 2024 13:15:20 +0100 Subject: [PATCH 04/15] Make `add_half_edges` more convenient to call --- crates/fj-core/src/operations/build/cycle.rs | 3 +-- crates/fj-core/src/operations/build/shell.rs | 1 - crates/fj-core/src/operations/join/cycle.rs | 2 -- crates/fj-core/src/operations/split/face.rs | 6 ++--- crates/fj-core/src/operations/update/cycle.rs | 22 +++++++++++++------ crates/fj-core/src/validate/cycle.rs | 2 -- crates/fj-core/src/validate/face.rs | 3 +-- 7 files changed, 19 insertions(+), 20 deletions(-) diff --git a/crates/fj-core/src/operations/build/cycle.rs b/crates/fj-core/src/operations/build/cycle.rs index 7c3cab335..95390cc30 100644 --- a/crates/fj-core/src/operations/build/cycle.rs +++ b/crates/fj-core/src/operations/build/cycle.rs @@ -24,8 +24,7 @@ pub trait BuildCycle { radius: impl Into, core: &mut Instance, ) -> Cycle { - let circle = - HalfEdge::circle(center, radius, core).insert(&mut core.services); + let circle = HalfEdge::circle(center, radius, core); Cycle::empty().add_half_edges([circle], core) } diff --git a/crates/fj-core/src/operations/build/shell.rs b/crates/fj-core/src/operations/build/shell.rs index 0d97a17fb..691426e32 100644 --- a/crates/fj-core/src/operations/build/shell.rs +++ b/crates/fj-core/src/operations/build/shell.rs @@ -99,7 +99,6 @@ pub trait BuildShell { ) .update_start_vertex(|_, _| vertex, core) .update_curve(|_, _| curve, core) - .insert(&mut core.services) }) }; diff --git a/crates/fj-core/src/operations/join/cycle.rs b/crates/fj-core/src/operations/join/cycle.rs index b2cdb0200..da78d9beb 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, @@ -95,7 +94,6 @@ impl JoinCycle for Cycle { |_, _| prev_half_edge.start_vertex().clone(), core, ) - .insert(&mut core.services) }) .collect::>(); self.add_half_edges(half_edges, core) diff --git a/crates/fj-core/src/operations/split/face.rs b/crates/fj-core/src/operations/split/face.rs index 6bd73c0fa..af424ee60 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 diff --git a/crates/fj-core/src/operations/update/cycle.rs b/crates/fj-core/src/operations/update/cycle.rs index ad15de4f2..469fe7ac5 100644 --- a/crates/fj-core/src/operations/update/cycle.rs +++ b/crates/fj-core/src/operations/update/cycle.rs @@ -9,11 +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>, + half_edges: impl IntoIterator, core: &mut Instance, - ) -> Self; + ) -> Self + where + T: Insert>; /// Update an edge of the cycle /// @@ -34,11 +36,17 @@ pub trait UpdateCycle { } impl UpdateCycle for Cycle { - fn add_half_edges( + fn add_half_edges( &self, - half_edges: impl IntoIterator>, - _: &mut Instance, - ) -> 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/validate/cycle.rs b/crates/fj-core/src/validate/cycle.rs index 8a6818997..9bb0f59e8 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,7 +101,6 @@ 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, &mut core) }; diff --git a/crates/fj-core/src/validate/face.rs b/crates/fj-core/src/validate/face.rs index ed564fddd..e769f0dab 100644 --- a/crates/fj-core/src/validate/face.rs +++ b/crates/fj-core/src/validate/face.rs @@ -108,8 +108,7 @@ mod tests { region.update_exterior( |cycle, core| { cycle.add_half_edges( - [HalfEdge::circle([0., 0.], 1., core) - .insert(&mut core.services)], + [HalfEdge::circle([0., 0.], 1., core)], core, ) }, From 638b5c31dffaecb0ac78248679a0186aa96bb3ac Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 12 Feb 2024 13:17:43 +0100 Subject: [PATCH 05/15] Expect `&mut Instance` in `add_interiors` --- .../src/algorithms/intersect/curve_face.rs | 6 +- .../fj-core/src/algorithms/triangulate/mod.rs | 7 +- crates/fj-core/src/operations/holes.rs | 65 +++++++++++-------- .../fj-core/src/operations/update/region.rs | 2 + crates/fj-core/src/validate/face.rs | 9 ++- models/spacer/src/lib.rs | 9 ++- models/star/src/lib.rs | 9 ++- 7 files changed, 67 insertions(+), 40 deletions(-) diff --git a/crates/fj-core/src/algorithms/intersect/curve_face.rs b/crates/fj-core/src/algorithms/intersect/curve_face.rs index d7afca844..051586654 100644 --- a/crates/fj-core/src/algorithms/intersect/curve_face.rs +++ b/crates/fj-core/src/algorithms/intersect/curve_face.rs @@ -195,11 +195,11 @@ mod tests { |_, core| Cycle::polygon(exterior_points, core), core, ) - .add_interiors([Cycle::polygon( - interior_points, + .add_interiors( + [Cycle::polygon(interior_points, core) + .insert(&mut core.services)], 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 cdc60e6d7..439d66ddb 100644 --- a/crates/fj-core/src/algorithms/triangulate/mod.rs +++ b/crates/fj-core/src/algorithms/triangulate/mod.rs @@ -149,8 +149,11 @@ 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) + .insert(&mut core.services)], + core, + ) }, &mut core, ); diff --git a/crates/fj-core/src/operations/holes.rs b/crates/fj-core/src/operations/holes.rs index e7354c7fd..53f326872 100644 --- a/crates/fj-core/src/operations/holes.rs +++ b/crates/fj-core/src/operations/holes.rs @@ -66,16 +66,19 @@ impl AddHole for Shell { |face, core| { [face.update_region( |region, core| { - region.add_interiors([Cycle::empty() - .add_joined_edges( - [( - entry.clone(), - entry.path(), - entry.boundary(), - )], - core, - ) - .insert(&mut core.services)]) + region.add_interiors( + [Cycle::empty() + .add_joined_edges( + [( + entry.clone(), + entry.path(), + entry.boundary(), + )], + core, + ) + .insert(&mut core.services)], + core, + ) }, core, )] @@ -141,16 +144,19 @@ impl AddHole for Shell { |face, core| { [face.update_region( |region, core| { - region.add_interiors([Cycle::empty() - .add_joined_edges( - [( - entry.clone(), - entry.path(), - entry.boundary(), - )], - core, - ) - .insert(&mut core.services)]) + region.add_interiors( + [Cycle::empty() + .add_joined_edges( + [( + entry.clone(), + entry.path(), + entry.boundary(), + )], + core, + ) + .insert(&mut core.services)], + core, + ) }, core, )] @@ -162,12 +168,19 @@ impl AddHole for Shell { |face, core| { [face.update_region( |region, core| { - region.add_interiors([Cycle::empty() - .add_joined_edges( - [(exit.clone(), exit.path(), exit.boundary())], - core, - ) - .insert(&mut core.services)]) + region.add_interiors( + [Cycle::empty() + .add_joined_edges( + [( + exit.clone(), + exit.path(), + exit.boundary(), + )], + core, + ) + .insert(&mut core.services)], + core, + ) }, core, )] diff --git a/crates/fj-core/src/operations/update/region.rs b/crates/fj-core/src/operations/update/region.rs index bde650157..a22082b4e 100644 --- a/crates/fj-core/src/operations/update/region.rs +++ b/crates/fj-core/src/operations/update/region.rs @@ -22,6 +22,7 @@ pub trait UpdateRegion { fn add_interiors( &self, interiors: impl IntoIterator>, + core: &mut Instance, ) -> Self; /// Update an interior cycle of the region @@ -58,6 +59,7 @@ impl UpdateRegion for Region { fn add_interiors( &self, interiors: impl IntoIterator>, + _: &mut Instance, ) -> Self { let interiors = self.interiors().iter().cloned().chain(interiors); Region::new(self.exterior().clone(), interiors, self.color()) diff --git a/crates/fj-core/src/validate/face.rs b/crates/fj-core/src/validate/face.rs index e769f0dab..2128814f8 100644 --- a/crates/fj-core/src/validate/face.rs +++ b/crates/fj-core/src/validate/face.rs @@ -145,11 +145,14 @@ mod tests { }, core, ) - .add_interiors([Cycle::polygon( - [[1., 1.], [1., 2.], [2., 1.]], + .add_interiors( + [Cycle::polygon( + [[1., 1.], [1., 2.], [2., 1.]], + core, + ) + .insert(&mut core.services)], core, ) - .insert(&mut core.services)]) }, &mut core, ); diff --git a/models/spacer/src/lib.rs b/models/spacer/src/lib.rs index 92466858b..e2ec0f5c3 100644 --- a/models/spacer/src/lib.rs +++ b/models/spacer/src/lib.rs @@ -23,9 +23,12 @@ pub fn model( Sketch::empty() .add_regions([Region::circle(Point::origin(), outer, core) - .add_interiors([Cycle::circle(Point::origin(), inner, core) - .reverse(core) - .insert(&mut core.services)]) + .add_interiors( + [Cycle::circle(Point::origin(), inner, core) + .reverse(core) + .insert(&mut core.services)], + core, + ) .insert(&mut core.services)]) .sweep_sketch(bottom_surface, sweep_path, core) } diff --git a/models/star/src/lib.rs b/models/star/src/lib.rs index 05baf6791..9c0e44fe8 100644 --- a/models/star/src/lib.rs +++ b/models/star/src/lib.rs @@ -46,9 +46,12 @@ pub fn model( Sketch::empty() .add_regions([Region::polygon(outer_points, core) - .add_interiors([Cycle::polygon(inner_points, core) - .reverse(core) - .insert(&mut core.services)]) + .add_interiors( + [Cycle::polygon(inner_points, core) + .reverse(core) + .insert(&mut core.services)], + core, + ) .insert(&mut core.services)]) .sweep_sketch(bottom_surface, sweep_path, core) } From 575ff5da77d3835fc24a454a85f0e0553c2231de Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 12 Feb 2024 13:21:12 +0100 Subject: [PATCH 06/15] Make `add_interiors` more convenient to call --- .../src/algorithms/intersect/curve_face.rs | 4 +- .../fj-core/src/algorithms/triangulate/mod.rs | 7 +-- crates/fj-core/src/operations/holes.rs | 50 ++++++++----------- .../fj-core/src/operations/update/region.rs | 22 +++++--- crates/fj-core/src/validate/face.rs | 3 +- models/spacer/src/lib.rs | 4 +- models/star/src/lib.rs | 4 +- 7 files changed, 40 insertions(+), 54 deletions(-) diff --git a/crates/fj-core/src/algorithms/intersect/curve_face.rs b/crates/fj-core/src/algorithms/intersect/curve_face.rs index 051586654..4c2dc2d90 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, @@ -196,8 +195,7 @@ mod tests { core, ) .add_interiors( - [Cycle::polygon(interior_points, core) - .insert(&mut core.services)], + [Cycle::polygon(interior_points, core)], core, ) }, diff --git a/crates/fj-core/src/algorithms/triangulate/mod.rs b/crates/fj-core/src/algorithms/triangulate/mod.rs index 439d66ddb..e2c8bcc1d 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,11 +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)], - core, - ) + .add_interiors([Cycle::polygon([e, f, g, h], core)], core) }, &mut core, ); diff --git a/crates/fj-core/src/operations/holes.rs b/crates/fj-core/src/operations/holes.rs index 53f326872..999639525 100644 --- a/crates/fj-core/src/operations/holes.rs +++ b/crates/fj-core/src/operations/holes.rs @@ -67,16 +67,14 @@ impl AddHole for Shell { [face.update_region( |region, core| { region.add_interiors( - [Cycle::empty() - .add_joined_edges( - [( - entry.clone(), - entry.path(), - entry.boundary(), - )], - core, - ) - .insert(&mut core.services)], + [Cycle::empty().add_joined_edges( + [( + entry.clone(), + entry.path(), + entry.boundary(), + )], + core, + )], core, ) }, @@ -145,16 +143,14 @@ impl AddHole for Shell { [face.update_region( |region, core| { region.add_interiors( - [Cycle::empty() - .add_joined_edges( - [( - entry.clone(), - entry.path(), - entry.boundary(), - )], - core, - ) - .insert(&mut core.services)], + [Cycle::empty().add_joined_edges( + [( + entry.clone(), + entry.path(), + entry.boundary(), + )], + core, + )], core, ) }, @@ -169,16 +165,10 @@ impl AddHole for Shell { [face.update_region( |region, core| { region.add_interiors( - [Cycle::empty() - .add_joined_edges( - [( - exit.clone(), - exit.path(), - exit.boundary(), - )], - core, - ) - .insert(&mut core.services)], + [Cycle::empty().add_joined_edges( + [(exit.clone(), exit.path(), exit.boundary())], + core, + )], core, ) }, diff --git a/crates/fj-core/src/operations/update/region.rs b/crates/fj-core/src/operations/update/region.rs index a22082b4e..5acfdcc8e 100644 --- a/crates/fj-core/src/operations/update/region.rs +++ b/crates/fj-core/src/operations/update/region.rs @@ -19,11 +19,13 @@ pub trait UpdateRegion { /// Add the provided interiors to the region #[must_use] - fn add_interiors( + fn add_interiors( &self, - interiors: impl IntoIterator>, + interiors: impl IntoIterator, core: &mut Instance, - ) -> Self; + ) -> Self + where + T: Insert>; /// Update an interior cycle of the region /// @@ -56,11 +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>, - _: &mut Instance, - ) -> 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/validate/face.rs b/crates/fj-core/src/validate/face.rs index 2128814f8..a78715176 100644 --- a/crates/fj-core/src/validate/face.rs +++ b/crates/fj-core/src/validate/face.rs @@ -149,8 +149,7 @@ mod tests { [Cycle::polygon( [[1., 1.], [1., 2.], [2., 1.]], core, - ) - .insert(&mut core.services)], + )], core, ) }, diff --git a/models/spacer/src/lib.rs b/models/spacer/src/lib.rs index e2ec0f5c3..4fdc6b1df 100644 --- a/models/spacer/src/lib.rs +++ b/models/spacer/src/lib.rs @@ -24,9 +24,7 @@ pub fn model( Sketch::empty() .add_regions([Region::circle(Point::origin(), outer, core) .add_interiors( - [Cycle::circle(Point::origin(), inner, core) - .reverse(core) - .insert(&mut core.services)], + [Cycle::circle(Point::origin(), inner, core).reverse(core)], core, ) .insert(&mut core.services)]) diff --git a/models/star/src/lib.rs b/models/star/src/lib.rs index 9c0e44fe8..305ee6348 100644 --- a/models/star/src/lib.rs +++ b/models/star/src/lib.rs @@ -47,9 +47,7 @@ pub fn model( Sketch::empty() .add_regions([Region::polygon(outer_points, core) .add_interiors( - [Cycle::polygon(inner_points, core) - .reverse(core) - .insert(&mut core.services)], + [Cycle::polygon(inner_points, core).reverse(core)], core, ) .insert(&mut core.services)]) From 1e8ccf24f5dd09f32fd5f0ff0cbc99e01d88a000 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 12 Feb 2024 13:23:04 +0100 Subject: [PATCH 07/15] Refactor to prepare for follow-on change --- crates/fj-core/src/operations/sweep/shell_face.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/fj-core/src/operations/sweep/shell_face.rs b/crates/fj-core/src/operations/sweep/shell_face.rs index 696ab3fe7..d2463f6c9 100644 --- a/crates/fj-core/src/operations/sweep/shell_face.rs +++ b/crates/fj-core/src/operations/sweep/shell_face.rs @@ -61,7 +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)); + .map(|face| face.insert(&mut core.services)) + .collect::>(); self.remove_face(&face).add_faces(faces) } From 30fa62597acc07d2b9926fb2bb2e1f56c992c793 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 12 Feb 2024 13:23:30 +0100 Subject: [PATCH 08/15] Require `Instance` in `UpdateShell::add_faces` --- crates/fj-core/src/operations/build/shell.rs | 2 +- crates/fj-core/src/operations/holes.rs | 4 ++-- crates/fj-core/src/operations/sweep/shell_face.rs | 2 +- crates/fj-core/src/operations/update/shell.rs | 12 ++++++++++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/crates/fj-core/src/operations/build/shell.rs b/crates/fj-core/src/operations/build/shell.rs index 691426e32..a65eecf69 100644 --- a/crates/fj-core/src/operations/build/shell.rs +++ b/crates/fj-core/src/operations/build/shell.rs @@ -118,7 +118,7 @@ pub trait BuildShell { }) .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/holes.rs b/crates/fj-core/src/operations/holes.rs index 999639525..ab2470edc 100644 --- a/crates/fj-core/src/operations/holes.rs +++ b/crates/fj-core/src/operations/holes.rs @@ -83,7 +83,7 @@ impl AddHole for Shell { }, core, ) - .add_faces(hole) + .add_faces(hole, core) } fn add_through_hole( @@ -177,7 +177,7 @@ impl AddHole for Shell { }, core, ) - .add_faces(hole) + .add_faces(hole, core) } } diff --git a/crates/fj-core/src/operations/sweep/shell_face.rs b/crates/fj-core/src/operations/sweep/shell_face.rs index d2463f6c9..06621c3ed 100644 --- a/crates/fj-core/src/operations/sweep/shell_face.rs +++ b/crates/fj-core/src/operations/sweep/shell_face.rs @@ -64,6 +64,6 @@ impl SweepFaceOfShell for Shell { .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/shell.rs b/crates/fj-core/src/operations/update/shell.rs index e4126042b..70c56430f 100644 --- a/crates/fj-core/src/operations/update/shell.rs +++ b/crates/fj-core/src/operations/update/shell.rs @@ -9,7 +9,11 @@ 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; /// Update a face of the shell /// @@ -34,7 +38,11 @@ pub trait UpdateShell { } impl UpdateShell for Shell { - fn add_faces(&self, faces: impl IntoIterator>) -> Self { + fn add_faces( + &self, + faces: impl IntoIterator>, + _: &mut Instance, + ) -> Self { let faces = self.faces().iter().cloned().chain(faces); Shell::new(faces) } From 411c43e2a91912e9d4fd63b8991f85cfa55b54ee Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 12 Feb 2024 13:25:43 +0100 Subject: [PATCH 09/15] Update `add_faces` more convenient to call --- crates/fj-core/src/operations/build/shell.rs | 24 +++++++++---------- crates/fj-core/src/operations/holes.rs | 7 +----- .../src/operations/sweep/shell_face.rs | 1 - crates/fj-core/src/operations/update/shell.rs | 22 +++++++++++------ 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/crates/fj-core/src/operations/build/shell.rs b/crates/fj-core/src/operations/build/shell.rs index a65eecf69..e8c14f374 100644 --- a/crates/fj-core/src/operations/build/shell.rs +++ b/crates/fj-core/src/operations/build/shell.rs @@ -102,19 +102,17 @@ pub trait BuildShell { }) }; - Face::unbound(surface, core) - .update_region( - |region, core| { - region.update_exterior( - |cycle, core| { - cycle.add_half_edges(half_edges, core) - }, - 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::>(); diff --git a/crates/fj-core/src/operations/holes.rs b/crates/fj-core/src/operations/holes.rs index ab2470edc..2ef720d34 100644 --- a/crates/fj-core/src/operations/holes.rs +++ b/crates/fj-core/src/operations/holes.rs @@ -58,7 +58,6 @@ impl AddHole for Shell { core, ) .all_faces() - .map(|face| face.insert(&mut core.services)) .collect::>(); self.update_face( @@ -124,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 diff --git a/crates/fj-core/src/operations/sweep/shell_face.rs b/crates/fj-core/src/operations/sweep/shell_face.rs index 06621c3ed..885e034d0 100644 --- a/crates/fj-core/src/operations/sweep/shell_face.rs +++ b/crates/fj-core/src/operations/sweep/shell_face.rs @@ -61,7 +61,6 @@ 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, core) diff --git a/crates/fj-core/src/operations/update/shell.rs b/crates/fj-core/src/operations/update/shell.rs index 70c56430f..fcdc63a4e 100644 --- a/crates/fj-core/src/operations/update/shell.rs +++ b/crates/fj-core/src/operations/update/shell.rs @@ -9,11 +9,13 @@ use crate::{ pub trait UpdateShell { /// Add faces to the shell #[must_use] - fn add_faces( + fn add_faces( &self, - faces: impl IntoIterator>, + faces: impl IntoIterator, core: &mut Instance, - ) -> Self; + ) -> Self + where + T: Insert>; /// Update a face of the shell /// @@ -38,11 +40,17 @@ pub trait UpdateShell { } impl UpdateShell for Shell { - fn add_faces( + fn add_faces( &self, - faces: impl IntoIterator>, - _: &mut Instance, - ) -> 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) } From e40fc9e940e45679bc345c5737a40b9e0db82f4c Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 12 Feb 2024 13:47:24 +0100 Subject: [PATCH 10/15] Expect `Instance` in `UpdateSketch::add_regions` --- .../fj-core/src/operations/update/sketch.rs | 2 ++ models/cuboid/src/lib.rs | 19 +++++++++++-------- models/spacer/src/lib.rs | 15 +++++++++------ models/star/src/lib.rs | 15 +++++++++------ 4 files changed, 31 insertions(+), 20 deletions(-) diff --git a/crates/fj-core/src/operations/update/sketch.rs b/crates/fj-core/src/operations/update/sketch.rs index 5e698c766..1cac619dd 100644 --- a/crates/fj-core/src/operations/update/sketch.rs +++ b/crates/fj-core/src/operations/update/sketch.rs @@ -12,6 +12,7 @@ pub trait UpdateSketch { fn add_regions( &self, regions: impl IntoIterator>, + core: &mut Instance, ) -> Self; /// Update a region of the sketch @@ -36,6 +37,7 @@ impl UpdateSketch for Sketch { fn add_regions( &self, regions: impl IntoIterator>, + _: &mut Instance, ) -> Self { Sketch::new(self.regions().iter().cloned().chain(regions)) } diff --git a/models/cuboid/src/lib.rs b/models/cuboid/src/lib.rs index 7493900d9..201058cb3 100644 --- a/models/cuboid/src/lib.rs +++ b/models/cuboid/src/lib.rs @@ -21,15 +21,18 @@ 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, + ) + .insert(&mut core.services)], 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 4fdc6b1df..d751eb1e3 100644 --- a/models/spacer/src/lib.rs +++ b/models/spacer/src/lib.rs @@ -22,11 +22,14 @@ 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)], - core, - ) - .insert(&mut core.services)]) + .add_regions( + [Region::circle(Point::origin(), outer, core) + .add_interiors( + [Cycle::circle(Point::origin(), inner, core).reverse(core)], + core, + ) + .insert(&mut core.services)], + core, + ) .sweep_sketch(bottom_surface, sweep_path, core) } diff --git a/models/star/src/lib.rs b/models/star/src/lib.rs index 305ee6348..2d78df8d8 100644 --- a/models/star/src/lib.rs +++ b/models/star/src/lib.rs @@ -45,11 +45,14 @@ 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)], - core, - ) - .insert(&mut core.services)]) + .add_regions( + [Region::polygon(outer_points, core) + .add_interiors( + [Cycle::polygon(inner_points, core).reverse(core)], + core, + ) + .insert(&mut core.services)], + core, + ) .sweep_sketch(bottom_surface, sweep_path, core) } From d1fe857696e5ef880fcd85067bd296fce774f076 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 12 Feb 2024 13:48:08 +0100 Subject: [PATCH 11/15] Refactor to improve clarity --- crates/fj-core/src/operations/update/sketch.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/fj-core/src/operations/update/sketch.rs b/crates/fj-core/src/operations/update/sketch.rs index 1cac619dd..3fbbdc76d 100644 --- a/crates/fj-core/src/operations/update/sketch.rs +++ b/crates/fj-core/src/operations/update/sketch.rs @@ -39,7 +39,8 @@ impl UpdateSketch for Sketch { regions: impl IntoIterator>, _: &mut Instance, ) -> Self { - Sketch::new(self.regions().iter().cloned().chain(regions)) + let regions = self.regions().iter().cloned().chain(regions); + Sketch::new(regions) } fn update_region( From 73869626a15f1911f89deabf0e82ad36ddc6c515 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 12 Feb 2024 14:03:51 +0100 Subject: [PATCH 12/15] Make `add_regions` more convenient to call --- .../fj-core/src/operations/update/sketch.rs | 22 +++++++++++++------ models/cuboid/src/lib.rs | 4 +--- models/spacer/src/lib.rs | 11 ++++------ models/star/src/lib.rs | 11 ++++------ 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/crates/fj-core/src/operations/update/sketch.rs b/crates/fj-core/src/operations/update/sketch.rs index 3fbbdc76d..cdeee9389 100644 --- a/crates/fj-core/src/operations/update/sketch.rs +++ b/crates/fj-core/src/operations/update/sketch.rs @@ -9,11 +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>, + regions: impl IntoIterator, core: &mut Instance, - ) -> Self; + ) -> Self + where + T: Insert>; /// Update a region of the sketch /// @@ -34,11 +36,17 @@ pub trait UpdateSketch { } impl UpdateSketch for Sketch { - fn add_regions( + fn add_regions( &self, - regions: impl IntoIterator>, - _: &mut Instance, - ) -> Self { + 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) } diff --git a/models/cuboid/src/lib.rs b/models/cuboid/src/lib.rs index 201058cb3..5e614a3ac 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, }, @@ -30,8 +29,7 @@ pub fn model( [-x / 2., y / 2.], ], core, - ) - .insert(&mut core.services)], + )], core, ) .sweep_sketch(bottom_surface, sweep_path, core) diff --git a/models/spacer/src/lib.rs b/models/spacer/src/lib.rs index d751eb1e3..baf0bf611 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}, @@ -23,12 +22,10 @@ pub fn model( Sketch::empty() .add_regions( - [Region::circle(Point::origin(), outer, core) - .add_interiors( - [Cycle::circle(Point::origin(), inner, core).reverse(core)], - core, - ) - .insert(&mut core.services)], + [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 2d78df8d8..4cf106ad6 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}, @@ -46,12 +45,10 @@ pub fn model( Sketch::empty() .add_regions( - [Region::polygon(outer_points, core) - .add_interiors( - [Cycle::polygon(inner_points, core).reverse(core)], - core, - ) - .insert(&mut core.services)], + [Region::polygon(outer_points, core).add_interiors( + [Cycle::polygon(inner_points, core).reverse(core)], + core, + )], core, ) .sweep_sketch(bottom_surface, sweep_path, core) From 71b370438a42c1591e202c77392dbf61d3447278 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 12 Feb 2024 14:06:10 +0100 Subject: [PATCH 13/15] Require `&mut Instance` in `Merge::merge` --- crates/fj-core/src/operations/merge.rs | 6 +++--- models/all/src/lib.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/fj-core/src/operations/merge.rs b/crates/fj-core/src/operations/merge.rs index b46a5d581..f8ac900e8 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 { + fn merge(&self, other: &Self, _: &mut Instance) -> Self { self.add_shells(other.shells().iter().cloned()) } } diff --git a/models/all/src/lib.rs b/models/all/src/lib.rs index d4f8e0c9e..d0520cd32 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 From 77e845257748d0e3ea769893a8f74642fb9b40c8 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 12 Feb 2024 14:07:59 +0100 Subject: [PATCH 14/15] Require `Instance` in `UpdateSolid::add_shells` --- crates/fj-core/src/operations/build/solid.rs | 2 +- crates/fj-core/src/operations/merge.rs | 4 ++-- crates/fj-core/src/operations/update/solid.rs | 2 ++ models/vertices-indices/src/lib.rs | 11 +++++++---- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/crates/fj-core/src/operations/build/solid.rs b/crates/fj-core/src/operations/build/solid.rs index 7c7f70d9a..f484dc060 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/merge.rs b/crates/fj-core/src/operations/merge.rs index f8ac900e8..fcf402bd7 100644 --- a/crates/fj-core/src/operations/merge.rs +++ b/crates/fj-core/src/operations/merge.rs @@ -15,7 +15,7 @@ pub trait Merge { } impl Merge for Solid { - fn merge(&self, other: &Self, _: &mut Instance) -> 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/update/solid.rs b/crates/fj-core/src/operations/update/solid.rs index c2715cd0c..a98f9a78c 100644 --- a/crates/fj-core/src/operations/update/solid.rs +++ b/crates/fj-core/src/operations/update/solid.rs @@ -12,6 +12,7 @@ pub trait UpdateSolid { fn add_shells( &self, shells: impl IntoIterator>, + core: &mut Instance, ) -> Self; /// Update a shell of the solid @@ -36,6 +37,7 @@ impl UpdateSolid for Solid { fn add_shells( &self, shells: impl IntoIterator>, + _: &mut Instance, ) -> Self { let shells = self.shells().iter().cloned().chain(shells); Solid::new(shells) diff --git a/models/vertices-indices/src/lib.rs b/models/vertices-indices/src/lib.rs index ec68a3935..d592540f8 100644 --- a/models/vertices-indices/src/lib.rs +++ b/models/vertices-indices/src/lib.rs @@ -8,10 +8,13 @@ use fj::core::{ }; 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, + ) + .insert(&mut core.services)], core, ) - .insert(&mut core.services)]) } From a50f2f9888487e772aef307a0a3e05ed47c15642 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 12 Feb 2024 14:12:36 +0100 Subject: [PATCH 15/15] Make `add_shells` more convenient to call --- crates/fj-core/src/operations/update/solid.rs | 22 +++++++++++++------ models/vertices-indices/src/lib.rs | 4 +--- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/crates/fj-core/src/operations/update/solid.rs b/crates/fj-core/src/operations/update/solid.rs index a98f9a78c..3c4358b72 100644 --- a/crates/fj-core/src/operations/update/solid.rs +++ b/crates/fj-core/src/operations/update/solid.rs @@ -9,11 +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>, + shells: impl IntoIterator, core: &mut Instance, - ) -> Self; + ) -> Self + where + T: Insert>; /// Update a shell of the solid /// @@ -34,11 +36,17 @@ pub trait UpdateSolid { } impl UpdateSolid for Solid { - fn add_shells( + fn add_shells( &self, - shells: impl IntoIterator>, - _: &mut Instance, - ) -> 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/models/vertices-indices/src/lib.rs b/models/vertices-indices/src/lib.rs index d592540f8..638debb33 100644 --- a/models/vertices-indices/src/lib.rs +++ b/models/vertices-indices/src/lib.rs @@ -2,7 +2,6 @@ use fj::core::{ objects::{Shell, Solid}, operations::{ build::{BuildShell, BuildSolid}, - insert::Insert, update::UpdateSolid, }, }; @@ -13,8 +12,7 @@ pub fn model(core: &mut fj::core::Instance) -> Solid { [[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, - ) - .insert(&mut core.services)], + )], core, ) }