From e9f6eaa145158833336417362b9279688af89619 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 7 Feb 2024 10:48:23 +0100 Subject: [PATCH 1/3] Require `&mut Instance` in `ReplaceCurve` --- .../fj-core/src/operations/replace/curve.rs | 87 +++++++++---------- 1 file changed, 40 insertions(+), 47 deletions(-) diff --git a/crates/fj-core/src/operations/replace/curve.rs b/crates/fj-core/src/operations/replace/curve.rs index f817452e8..4ec5b1000 100644 --- a/crates/fj-core/src/operations/replace/curve.rs +++ b/crates/fj-core/src/operations/replace/curve.rs @@ -5,8 +5,8 @@ use crate::{ Curve, Cycle, Face, HalfEdge, IsObject, Region, Shell, Sketch, Solid, }, operations::{insert::Insert, update::UpdateHalfEdge}, - services::Services, storage::Handle, + Instance, }; use super::ReplaceOutput; @@ -23,7 +23,7 @@ pub trait ReplaceCurve: IsObject + Sized { &self, original: &Handle, replacement: Handle, - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput; } @@ -32,7 +32,7 @@ impl ReplaceCurve for HalfEdge { &self, original: &Handle, replacement: Handle, - _: &mut Services, + _: &mut Instance, ) -> ReplaceOutput { if original.id() == self.curve().id() { ReplaceOutput::Updated(self.update_curve(|_| replacement)) @@ -47,21 +47,18 @@ impl ReplaceCurve for Cycle { &self, original: &Handle, replacement: Handle, - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { let mut replacement_happened = false; let mut half_edges = Vec::new(); for half_edge in self.half_edges() { - let half_edge = half_edge.replace_curve( - original, - replacement.clone(), - services, - ); + let half_edge = + half_edge.replace_curve(original, replacement.clone(), core); replacement_happened |= half_edge.was_updated(); half_edges.push( half_edge - .map_updated(|updated| updated.insert(services)) + .map_updated(|updated| updated.insert(&mut core.services)) .into_inner(), ); } @@ -79,25 +76,23 @@ impl ReplaceCurve for Region { &self, original: &Handle, replacement: Handle, - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { let mut replacement_happened = false; - let exterior = self.exterior().replace_curve( - original, - replacement.clone(), - services, - ); + let exterior = + self.exterior() + .replace_curve(original, replacement.clone(), core); replacement_happened |= exterior.was_updated(); let mut interiors = Vec::new(); for cycle in self.interiors() { let cycle = - cycle.replace_curve(original, replacement.clone(), services); + cycle.replace_curve(original, replacement.clone(), core); replacement_happened |= cycle.was_updated(); interiors.push( cycle - .map_updated(|updated| updated.insert(services)) + .map_updated(|updated| updated.insert(&mut core.services)) .into_inner(), ); } @@ -105,7 +100,7 @@ impl ReplaceCurve for Region { if replacement_happened { ReplaceOutput::Updated(Region::new( exterior - .map_updated(|updated| updated.insert(services)) + .map_updated(|updated| updated.insert(&mut core.services)) .into_inner(), interiors, self.color(), @@ -121,18 +116,18 @@ impl ReplaceCurve for Sketch { &self, original: &Handle, replacement: Handle, - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { let mut replacement_happened = false; let mut regions = Vec::new(); for region in self.regions() { let region = - region.replace_curve(original, replacement.clone(), services); + region.replace_curve(original, replacement.clone(), core); replacement_happened |= region.was_updated(); regions.push( region - .map_updated(|updated| updated.insert(services)) + .map_updated(|updated| updated.insert(&mut core.services)) .into_inner(), ); } @@ -150,16 +145,15 @@ impl ReplaceCurve for Face { &self, original: &Handle, replacement: Handle, - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { - let region = - self.region().replace_curve(original, replacement, services); + let region = self.region().replace_curve(original, replacement, core); if region.was_updated() { ReplaceOutput::Updated(Face::new( self.surface().clone(), region - .map_updated(|updated| updated.insert(services)) + .map_updated(|updated| updated.insert(&mut core.services)) .into_inner(), )) } else { @@ -173,17 +167,16 @@ impl ReplaceCurve for Shell { &self, original: &Handle, replacement: Handle, - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { let mut replacement_happened = false; let mut faces = Vec::new(); for face in self.faces() { - let face = - face.replace_curve(original, replacement.clone(), services); + let face = face.replace_curve(original, replacement.clone(), core); replacement_happened |= face.was_updated(); faces.push( - face.map_updated(|updated| updated.insert(services)) + face.map_updated(|updated| updated.insert(&mut core.services)) .into_inner(), ); } @@ -201,18 +194,18 @@ impl ReplaceCurve for Solid { &self, original: &Handle, replacement: Handle, - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { let mut replacement_happened = false; let mut shells = Vec::new(); for shell in self.shells() { let shell = - shell.replace_curve(original, replacement.clone(), services); + shell.replace_curve(original, replacement.clone(), core); replacement_happened |= shell.was_updated(); shells.push( shell - .map_updated(|updated| updated.insert(services)) + .map_updated(|updated| updated.insert(&mut core.services)) .into_inner(), ); } @@ -230,10 +223,10 @@ impl ReplaceCurve for Handle { &self, original: &Handle, replacement: Handle, - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { self.deref() - .replace_curve(original, replacement, services) + .replace_curve(original, replacement, core) .map_original(|_| self.clone()) } } @@ -243,10 +236,10 @@ impl ReplaceCurve for Handle { &self, original: &Handle, replacement: Handle, - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { self.deref() - .replace_curve(original, replacement, services) + .replace_curve(original, replacement, core) .map_original(|_| self.clone()) } } @@ -256,10 +249,10 @@ impl ReplaceCurve for Handle { &self, original: &Handle, replacement: Handle, - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { self.deref() - .replace_curve(original, replacement, services) + .replace_curve(original, replacement, core) .map_original(|_| self.clone()) } } @@ -269,10 +262,10 @@ impl ReplaceCurve for Handle { &self, original: &Handle, replacement: Handle, - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { self.deref() - .replace_curve(original, replacement, services) + .replace_curve(original, replacement, core) .map_original(|_| self.clone()) } } @@ -282,10 +275,10 @@ impl ReplaceCurve for Handle { &self, original: &Handle, replacement: Handle, - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { self.deref() - .replace_curve(original, replacement, services) + .replace_curve(original, replacement, core) .map_original(|_| self.clone()) } } @@ -295,10 +288,10 @@ impl ReplaceCurve for Handle { &self, original: &Handle, replacement: Handle, - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { self.deref() - .replace_curve(original, replacement, services) + .replace_curve(original, replacement, core) .map_original(|_| self.clone()) } } @@ -308,10 +301,10 @@ impl ReplaceCurve for Handle { &self, original: &Handle, replacement: Handle, - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { self.deref() - .replace_curve(original, replacement, services) + .replace_curve(original, replacement, core) .map_original(|_| self.clone()) } } From 08937f38d9d2aa0207fdabe926338844bbff251e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 7 Feb 2024 10:50:33 +0100 Subject: [PATCH 2/3] Expect `&mut Instance` in `ReplaceHalfEdge` --- .../src/operations/replace/half_edge.rs | 84 ++++++++----------- crates/fj-core/src/operations/split/edge.rs | 4 +- 2 files changed, 38 insertions(+), 50 deletions(-) diff --git a/crates/fj-core/src/operations/replace/half_edge.rs b/crates/fj-core/src/operations/replace/half_edge.rs index 55c1864ae..029f866d8 100644 --- a/crates/fj-core/src/operations/replace/half_edge.rs +++ b/crates/fj-core/src/operations/replace/half_edge.rs @@ -3,8 +3,8 @@ use std::ops::Deref; use crate::{ objects::{Cycle, Face, HalfEdge, IsObject, Region, Shell, Sketch, Solid}, operations::insert::Insert, - services::Services, storage::Handle, + Instance, }; use super::ReplaceOutput; @@ -21,7 +21,7 @@ pub trait ReplaceHalfEdge: IsObject + Sized { &self, original: &Handle, replacements: [Handle; N], - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput; } @@ -30,7 +30,7 @@ impl ReplaceHalfEdge for Cycle { &self, original: &Handle, replacements: [Handle; N], - _: &mut Services, + _: &mut Instance, ) -> ReplaceOutput { if let Some(half_edges) = self.half_edges().replace(original, replacements) @@ -47,28 +47,25 @@ impl ReplaceHalfEdge for Region { &self, original: &Handle, replacements: [Handle; N], - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { let mut replacement_happened = false; let exterior = self.exterior().replace_half_edge( original, replacements.clone(), - services, + core, ); replacement_happened |= exterior.was_updated(); let mut interiors = Vec::new(); for cycle in self.interiors() { - let cycle = cycle.replace_half_edge( - original, - replacements.clone(), - services, - ); + let cycle = + cycle.replace_half_edge(original, replacements.clone(), core); replacement_happened |= cycle.was_updated(); interiors.push( cycle - .map_updated(|updated| updated.insert(services)) + .map_updated(|updated| updated.insert(&mut core.services)) .into_inner(), ); } @@ -76,7 +73,7 @@ impl ReplaceHalfEdge for Region { if replacement_happened { ReplaceOutput::Updated(Region::new( exterior - .map_updated(|updated| updated.insert(services)) + .map_updated(|updated| updated.insert(&mut core.services)) .into_inner(), interiors, self.color(), @@ -92,21 +89,18 @@ impl ReplaceHalfEdge for Sketch { &self, original: &Handle, replacements: [Handle; N], - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { let mut replacement_happened = false; let mut regions = Vec::new(); for region in self.regions() { - let region = region.replace_half_edge( - original, - replacements.clone(), - services, - ); + let region = + region.replace_half_edge(original, replacements.clone(), core); replacement_happened |= region.was_updated(); regions.push( region - .map_updated(|updated| updated.insert(services)) + .map_updated(|updated| updated.insert(&mut core.services)) .into_inner(), ); } @@ -124,17 +118,17 @@ impl ReplaceHalfEdge for Face { &self, original: &Handle, replacements: [Handle; N], - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { let region = self.region() - .replace_half_edge(original, replacements, services); + .replace_half_edge(original, replacements, core); if region.was_updated() { ReplaceOutput::Updated(Face::new( self.surface().clone(), region - .map_updated(|updated| updated.insert(services)) + .map_updated(|updated| updated.insert(&mut core.services)) .into_inner(), )) } else { @@ -148,20 +142,17 @@ impl ReplaceHalfEdge for Shell { &self, original: &Handle, replacements: [Handle; N], - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { let mut replacement_happened = false; let mut faces = Vec::new(); for face in self.faces() { - let face = face.replace_half_edge( - original, - replacements.clone(), - services, - ); + let face = + face.replace_half_edge(original, replacements.clone(), core); replacement_happened |= face.was_updated(); faces.push( - face.map_updated(|updated| updated.insert(services)) + face.map_updated(|updated| updated.insert(&mut core.services)) .into_inner(), ); } @@ -179,21 +170,18 @@ impl ReplaceHalfEdge for Solid { &self, original: &Handle, replacements: [Handle; N], - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { let mut replacement_happened = false; let mut shells = Vec::new(); for shell in self.shells() { - let shell = shell.replace_half_edge( - original, - replacements.clone(), - services, - ); + let shell = + shell.replace_half_edge(original, replacements.clone(), core); replacement_happened |= shell.was_updated(); shells.push( shell - .map_updated(|updated| updated.insert(services)) + .map_updated(|updated| updated.insert(&mut core.services)) .into_inner(), ); } @@ -211,10 +199,10 @@ impl ReplaceHalfEdge for Handle { &self, original: &Handle, replacements: [Handle; N], - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { self.deref() - .replace_half_edge(original, replacements, services) + .replace_half_edge(original, replacements, core) .map_original(|_| self.clone()) } } @@ -224,10 +212,10 @@ impl ReplaceHalfEdge for Handle { &self, original: &Handle, replacements: [Handle; N], - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { self.deref() - .replace_half_edge(original, replacements, services) + .replace_half_edge(original, replacements, core) .map_original(|_| self.clone()) } } @@ -237,10 +225,10 @@ impl ReplaceHalfEdge for Handle { &self, original: &Handle, replacements: [Handle; N], - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { self.deref() - .replace_half_edge(original, replacements, services) + .replace_half_edge(original, replacements, core) .map_original(|_| self.clone()) } } @@ -250,10 +238,10 @@ impl ReplaceHalfEdge for Handle { &self, original: &Handle, replacements: [Handle; N], - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { self.deref() - .replace_half_edge(original, replacements, services) + .replace_half_edge(original, replacements, core) .map_original(|_| self.clone()) } } @@ -263,10 +251,10 @@ impl ReplaceHalfEdge for Handle { &self, original: &Handle, replacements: [Handle; N], - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { self.deref() - .replace_half_edge(original, replacements, services) + .replace_half_edge(original, replacements, core) .map_original(|_| self.clone()) } } @@ -276,10 +264,10 @@ impl ReplaceHalfEdge for Handle { &self, original: &Handle, replacements: [Handle; N], - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { self.deref() - .replace_half_edge(original, replacements, services) + .replace_half_edge(original, replacements, core) .map_original(|_| self.clone()) } } diff --git a/crates/fj-core/src/operations/split/edge.rs b/crates/fj-core/src/operations/split/edge.rs index 724857083..4a3d17d36 100644 --- a/crates/fj-core/src/operations/split/edge.rs +++ b/crates/fj-core/src/operations/split/edge.rs @@ -56,10 +56,10 @@ impl SplitEdge for Shell { .replace_half_edge( half_edge, [half_edge_a.clone(), half_edge_b.clone()], - &mut core.services, + core, ) .into_inner() - .replace_half_edge(&sibling, siblings.clone(), &mut core.services) + .replace_half_edge(&sibling, siblings.clone(), core) .into_inner(); (shell, [[half_edge_a, half_edge_b], siblings]) From cd86dc70866dbf629c3845bee793b9ade277562b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 7 Feb 2024 10:52:21 +0100 Subject: [PATCH 3/3] Expect `&mut Instance` in `ReplaceVertex` --- .../fj-core/src/operations/replace/vertex.rs | 90 +++++++++---------- 1 file changed, 41 insertions(+), 49 deletions(-) diff --git a/crates/fj-core/src/operations/replace/vertex.rs b/crates/fj-core/src/operations/replace/vertex.rs index fad7ad591..c42554a2b 100644 --- a/crates/fj-core/src/operations/replace/vertex.rs +++ b/crates/fj-core/src/operations/replace/vertex.rs @@ -5,8 +5,8 @@ use crate::{ Cycle, Face, HalfEdge, IsObject, Region, Shell, Sketch, Solid, Vertex, }, operations::{insert::Insert, update::UpdateHalfEdge}, - services::Services, storage::Handle, + Instance, }; use super::ReplaceOutput; @@ -23,7 +23,7 @@ pub trait ReplaceVertex: IsObject + Sized { &self, original: &Handle, replacement: Handle, - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput; } @@ -32,7 +32,7 @@ impl ReplaceVertex for HalfEdge { &self, original: &Handle, replacement: Handle, - _: &mut Services, + _: &mut Instance, ) -> ReplaceOutput { if original.id() == self.start_vertex().id() { ReplaceOutput::Updated(self.update_start_vertex(|_| replacement)) @@ -47,21 +47,18 @@ impl ReplaceVertex for Cycle { &self, original: &Handle, replacement: Handle, - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { let mut replacement_happened = false; let mut half_edges = Vec::new(); for half_edge in self.half_edges() { - let half_edge = half_edge.replace_vertex( - original, - replacement.clone(), - services, - ); + let half_edge = + half_edge.replace_vertex(original, replacement.clone(), core); replacement_happened |= half_edge.was_updated(); half_edges.push( half_edge - .map_updated(|updated| updated.insert(services)) + .map_updated(|updated| updated.insert(&mut core.services)) .into_inner(), ); } @@ -79,25 +76,23 @@ impl ReplaceVertex for Region { &self, original: &Handle, replacement: Handle, - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { let mut replacement_happened = false; - let exterior = self.exterior().replace_vertex( - original, - replacement.clone(), - services, - ); + let exterior = + self.exterior() + .replace_vertex(original, replacement.clone(), core); replacement_happened |= exterior.was_updated(); let mut interiors = Vec::new(); for cycle in self.interiors() { let cycle = - cycle.replace_vertex(original, replacement.clone(), services); + cycle.replace_vertex(original, replacement.clone(), core); replacement_happened |= cycle.was_updated(); interiors.push( cycle - .map_updated(|updated| updated.insert(services)) + .map_updated(|updated| updated.insert(&mut core.services)) .into_inner(), ); } @@ -105,7 +100,7 @@ impl ReplaceVertex for Region { if replacement_happened { ReplaceOutput::Updated(Region::new( exterior - .map_updated(|updated| updated.insert(services)) + .map_updated(|updated| updated.insert(&mut core.services)) .into_inner(), interiors, self.color(), @@ -121,18 +116,18 @@ impl ReplaceVertex for Sketch { &self, original: &Handle, replacement: Handle, - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { let mut replacement_happened = false; let mut regions = Vec::new(); for region in self.regions() { let region = - region.replace_vertex(original, replacement.clone(), services); + region.replace_vertex(original, replacement.clone(), core); replacement_happened |= region.was_updated(); regions.push( region - .map_updated(|updated| updated.insert(services)) + .map_updated(|updated| updated.insert(&mut core.services)) .into_inner(), ); } @@ -150,17 +145,15 @@ impl ReplaceVertex for Face { &self, original: &Handle, replacement: Handle, - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { - let region = - self.region() - .replace_vertex(original, replacement, services); + let region = self.region().replace_vertex(original, replacement, core); if region.was_updated() { ReplaceOutput::Updated(Face::new( self.surface().clone(), region - .map_updated(|updated| updated.insert(services)) + .map_updated(|updated| updated.insert(&mut core.services)) .into_inner(), )) } else { @@ -174,17 +167,16 @@ impl ReplaceVertex for Shell { &self, original: &Handle, replacement: Handle, - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { let mut replacement_happened = false; let mut faces = Vec::new(); for face in self.faces() { - let face = - face.replace_vertex(original, replacement.clone(), services); + let face = face.replace_vertex(original, replacement.clone(), core); replacement_happened |= face.was_updated(); faces.push( - face.map_updated(|updated| updated.insert(services)) + face.map_updated(|updated| updated.insert(&mut core.services)) .into_inner(), ); } @@ -202,18 +194,18 @@ impl ReplaceVertex for Solid { &self, original: &Handle, replacement: Handle, - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { let mut replacement_happened = false; let mut shells = Vec::new(); for shell in self.shells() { let shell = - shell.replace_vertex(original, replacement.clone(), services); + shell.replace_vertex(original, replacement.clone(), core); replacement_happened |= shell.was_updated(); shells.push( shell - .map_updated(|updated| updated.insert(services)) + .map_updated(|updated| updated.insert(&mut core.services)) .into_inner(), ); } @@ -231,10 +223,10 @@ impl ReplaceVertex for Handle { &self, original: &Handle, replacement: Handle, - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { self.deref() - .replace_vertex(original, replacement, services) + .replace_vertex(original, replacement, core) .map_original(|_| self.clone()) } } @@ -244,10 +236,10 @@ impl ReplaceVertex for Handle { &self, original: &Handle, replacement: Handle, - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { self.deref() - .replace_vertex(original, replacement, services) + .replace_vertex(original, replacement, core) .map_original(|_| self.clone()) } } @@ -257,10 +249,10 @@ impl ReplaceVertex for Handle { &self, original: &Handle, replacement: Handle, - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { self.deref() - .replace_vertex(original, replacement, services) + .replace_vertex(original, replacement, core) .map_original(|_| self.clone()) } } @@ -270,18 +262,18 @@ impl ReplaceVertex for Handle { &self, original: &Handle, replacement: Handle, - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { let mut replacement_happened = false; let mut regions = Vec::new(); for region in self.regions() { let region = - region.replace_vertex(original, replacement.clone(), services); + region.replace_vertex(original, replacement.clone(), core); replacement_happened |= region.was_updated(); regions.push( region - .map_updated(|updated| updated.insert(services)) + .map_updated(|updated| updated.insert(&mut core.services)) .into_inner(), ); } @@ -299,10 +291,10 @@ impl ReplaceVertex for Handle { &self, original: &Handle, replacement: Handle, - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { self.deref() - .replace_vertex(original, replacement, services) + .replace_vertex(original, replacement, core) .map_original(|_| self.clone()) } } @@ -312,10 +304,10 @@ impl ReplaceVertex for Handle { &self, original: &Handle, replacement: Handle, - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { self.deref() - .replace_vertex(original, replacement, services) + .replace_vertex(original, replacement, core) .map_original(|_| self.clone()) } } @@ -325,10 +317,10 @@ impl ReplaceVertex for Handle { &self, original: &Handle, replacement: Handle, - services: &mut Services, + core: &mut Instance, ) -> ReplaceOutput { self.deref() - .replace_vertex(original, replacement, services) + .replace_vertex(original, replacement, core) .map_original(|_| self.clone()) } }