Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require &mut Instance in replace traits #2197

Merged
merged 3 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 40 additions & 47 deletions crates/fj-core/src/operations/replace/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,7 +23,7 @@ pub trait ReplaceCurve: IsObject + Sized {
&self,
original: &Handle<Curve>,
replacement: Handle<Curve>,
services: &mut Services,
core: &mut Instance,
) -> ReplaceOutput<Self, Self::BareObject>;
}

Expand All @@ -32,7 +32,7 @@ impl ReplaceCurve for HalfEdge {
&self,
original: &Handle<Curve>,
replacement: Handle<Curve>,
_: &mut Services,
_: &mut Instance,
) -> ReplaceOutput<Self, Self::BareObject> {
if original.id() == self.curve().id() {
ReplaceOutput::Updated(self.update_curve(|_| replacement))
Expand All @@ -47,21 +47,18 @@ impl ReplaceCurve for Cycle {
&self,
original: &Handle<Curve>,
replacement: Handle<Curve>,
services: &mut Services,
core: &mut Instance,
) -> ReplaceOutput<Self, Self::BareObject> {
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(),
);
}
Expand All @@ -79,33 +76,31 @@ impl ReplaceCurve for Region {
&self,
original: &Handle<Curve>,
replacement: Handle<Curve>,
services: &mut Services,
core: &mut Instance,
) -> ReplaceOutput<Self, Self::BareObject> {
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(),
);
}

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(),
Expand All @@ -121,18 +116,18 @@ impl ReplaceCurve for Sketch {
&self,
original: &Handle<Curve>,
replacement: Handle<Curve>,
services: &mut Services,
core: &mut Instance,
) -> ReplaceOutput<Self, Self::BareObject> {
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(),
);
}
Expand All @@ -150,16 +145,15 @@ impl ReplaceCurve for Face {
&self,
original: &Handle<Curve>,
replacement: Handle<Curve>,
services: &mut Services,
core: &mut Instance,
) -> ReplaceOutput<Self, Self::BareObject> {
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 {
Expand All @@ -173,17 +167,16 @@ impl ReplaceCurve for Shell {
&self,
original: &Handle<Curve>,
replacement: Handle<Curve>,
services: &mut Services,
core: &mut Instance,
) -> ReplaceOutput<Self, Self::BareObject> {
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(),
);
}
Expand All @@ -201,18 +194,18 @@ impl ReplaceCurve for Solid {
&self,
original: &Handle<Curve>,
replacement: Handle<Curve>,
services: &mut Services,
core: &mut Instance,
) -> ReplaceOutput<Self, Self::BareObject> {
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(),
);
}
Expand All @@ -230,10 +223,10 @@ impl ReplaceCurve for Handle<HalfEdge> {
&self,
original: &Handle<Curve>,
replacement: Handle<Curve>,
services: &mut Services,
core: &mut Instance,
) -> ReplaceOutput<Self, Self::BareObject> {
self.deref()
.replace_curve(original, replacement, services)
.replace_curve(original, replacement, core)
.map_original(|_| self.clone())
}
}
Expand All @@ -243,10 +236,10 @@ impl ReplaceCurve for Handle<Cycle> {
&self,
original: &Handle<Curve>,
replacement: Handle<Curve>,
services: &mut Services,
core: &mut Instance,
) -> ReplaceOutput<Self, Self::BareObject> {
self.deref()
.replace_curve(original, replacement, services)
.replace_curve(original, replacement, core)
.map_original(|_| self.clone())
}
}
Expand All @@ -256,10 +249,10 @@ impl ReplaceCurve for Handle<Region> {
&self,
original: &Handle<Curve>,
replacement: Handle<Curve>,
services: &mut Services,
core: &mut Instance,
) -> ReplaceOutput<Self, Self::BareObject> {
self.deref()
.replace_curve(original, replacement, services)
.replace_curve(original, replacement, core)
.map_original(|_| self.clone())
}
}
Expand All @@ -269,10 +262,10 @@ impl ReplaceCurve for Handle<Sketch> {
&self,
original: &Handle<Curve>,
replacement: Handle<Curve>,
services: &mut Services,
core: &mut Instance,
) -> ReplaceOutput<Self, Self::BareObject> {
self.deref()
.replace_curve(original, replacement, services)
.replace_curve(original, replacement, core)
.map_original(|_| self.clone())
}
}
Expand All @@ -282,10 +275,10 @@ impl ReplaceCurve for Handle<Face> {
&self,
original: &Handle<Curve>,
replacement: Handle<Curve>,
services: &mut Services,
core: &mut Instance,
) -> ReplaceOutput<Self, Self::BareObject> {
self.deref()
.replace_curve(original, replacement, services)
.replace_curve(original, replacement, core)
.map_original(|_| self.clone())
}
}
Expand All @@ -295,10 +288,10 @@ impl ReplaceCurve for Handle<Shell> {
&self,
original: &Handle<Curve>,
replacement: Handle<Curve>,
services: &mut Services,
core: &mut Instance,
) -> ReplaceOutput<Self, Self::BareObject> {
self.deref()
.replace_curve(original, replacement, services)
.replace_curve(original, replacement, core)
.map_original(|_| self.clone())
}
}
Expand All @@ -308,10 +301,10 @@ impl ReplaceCurve for Handle<Solid> {
&self,
original: &Handle<Curve>,
replacement: Handle<Curve>,
services: &mut Services,
core: &mut Instance,
) -> ReplaceOutput<Self, Self::BareObject> {
self.deref()
.replace_curve(original, replacement, services)
.replace_curve(original, replacement, core)
.map_original(|_| self.clone())
}
}
Loading