Skip to content

Commit

Permalink
Use DeriveFrom where appropriate
Browse files Browse the repository at this point in the history
This might not be all the places where it's needed, but I've been pretty
careful about looking. If I forgot something, it might show up as a
color being reset after an operation later.
  • Loading branch information
hannobraun committed Feb 16, 2024
1 parent ad31e5f commit cb123b8
Show file tree
Hide file tree
Showing 19 changed files with 193 additions and 72 deletions.
34 changes: 25 additions & 9 deletions crates/fj-core/src/operations/replace/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
objects::{
Curve, Cycle, Face, HalfEdge, IsObject, Region, Shell, Sketch, Solid,
},
operations::{insert::Insert, update::UpdateHalfEdge},
operations::{derive::DeriveFrom, insert::Insert, update::UpdateHalfEdge},
storage::Handle,
Core,
};
Expand Down Expand Up @@ -61,7 +61,11 @@ impl ReplaceCurve for Cycle {
replacement_happened |= half_edge.was_updated();
half_edges.push(
half_edge
.map_updated(|updated| updated.insert(core))
.map_updated(|updated| {
updated
.insert(core)
.derive_from(original_half_edge, core)
})
.into_inner(),
);
}
Expand Down Expand Up @@ -98,15 +102,19 @@ impl ReplaceCurve for Region {
replacement_happened |= cycle.was_updated();
interiors.push(
cycle
.map_updated(|updated| updated.insert(core))
.map_updated(|updated| {
updated.insert(core).derive_from(original_cycle, core)
})
.into_inner(),
);
}

if replacement_happened {
ReplaceOutput::Updated(Region::new(
exterior
.map_updated(|updated| updated.insert(core))
.map_updated(|updated| {
updated.insert(core).derive_from(self.exterior(), core)
})
.into_inner(),
interiors,
self.color(),
Expand Down Expand Up @@ -136,7 +144,9 @@ impl ReplaceCurve for Sketch {
replacement_happened |= region.was_updated();
regions.push(
region
.map_updated(|updated| updated.insert(core))
.map_updated(|updated| {
updated.insert(core).derive_from(original_region, core)
})
.into_inner(),
);
}
Expand All @@ -162,7 +172,9 @@ impl ReplaceCurve for Face {
ReplaceOutput::Updated(Face::new(
self.surface().clone(),
region
.map_updated(|updated| updated.insert(core))
.map_updated(|updated| {
updated.insert(core).derive_from(self.region(), core)
})
.into_inner(),
))
} else {
Expand All @@ -189,8 +201,10 @@ impl ReplaceCurve for Shell {
);
replacement_happened |= face.was_updated();
faces.push(
face.map_updated(|updated| updated.insert(core))
.into_inner(),
face.map_updated(|updated| {
updated.insert(core).derive_from(original_face, core)
})
.into_inner(),
);
}

Expand Down Expand Up @@ -221,7 +235,9 @@ impl ReplaceCurve for Solid {
replacement_happened |= shell.was_updated();
shells.push(
shell
.map_updated(|updated| updated.insert(core))
.map_updated(|updated| {
updated.insert(core).derive_from(original_shell, core)
})
.into_inner(),
);
}
Expand Down
28 changes: 20 additions & 8 deletions crates/fj-core/src/operations/replace/half_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::ops::Deref;

use crate::{
objects::{Cycle, Face, HalfEdge, IsObject, Region, Shell, Sketch, Solid},
operations::insert::Insert,
operations::{derive::DeriveFrom, insert::Insert},
storage::Handle,
Core,
};
Expand Down Expand Up @@ -68,15 +68,19 @@ impl ReplaceHalfEdge for Region {
replacement_happened |= cycle.was_updated();
interiors.push(
cycle
.map_updated(|updated| updated.insert(core))
.map_updated(|updated| {
updated.insert(core).derive_from(original_cycle, core)
})
.into_inner(),
);
}

if replacement_happened {
ReplaceOutput::Updated(Region::new(
exterior
.map_updated(|updated| updated.insert(core))
.map_updated(|updated| {
updated.insert(core).derive_from(self.exterior(), core)
})
.into_inner(),
interiors,
self.color(),
Expand Down Expand Up @@ -106,7 +110,9 @@ impl ReplaceHalfEdge for Sketch {
replacement_happened |= region.was_updated();
regions.push(
region
.map_updated(|updated| updated.insert(core))
.map_updated(|updated| {
updated.insert(core).derive_from(original_region, core)
})
.into_inner(),
);
}
Expand Down Expand Up @@ -134,7 +140,9 @@ impl ReplaceHalfEdge for Face {
ReplaceOutput::Updated(Face::new(
self.surface().clone(),
region
.map_updated(|updated| updated.insert(core))
.map_updated(|updated| {
updated.insert(core).derive_from(self.region(), core)
})
.into_inner(),
))
} else {
Expand All @@ -161,8 +169,10 @@ impl ReplaceHalfEdge for Shell {
);
replacement_happened |= face.was_updated();
faces.push(
face.map_updated(|updated| updated.insert(core))
.into_inner(),
face.map_updated(|updated| {
updated.insert(core).derive_from(original_face, core)
})
.into_inner(),
);
}

Expand Down Expand Up @@ -193,7 +203,9 @@ impl ReplaceHalfEdge for Solid {
replacement_happened |= shell.was_updated();
shells.push(
shell
.map_updated(|updated| updated.insert(core))
.map_updated(|updated| {
updated.insert(core).derive_from(original_shell, core)
})
.into_inner(),
);
}
Expand Down
38 changes: 28 additions & 10 deletions crates/fj-core/src/operations/replace/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
objects::{
Cycle, Face, HalfEdge, IsObject, Region, Shell, Sketch, Solid, Vertex,
},
operations::{insert::Insert, update::UpdateHalfEdge},
operations::{derive::DeriveFrom, insert::Insert, update::UpdateHalfEdge},
storage::Handle,
Core,
};
Expand Down Expand Up @@ -63,7 +63,11 @@ impl ReplaceVertex for Cycle {
replacement_happened |= half_edge.was_updated();
half_edges.push(
half_edge
.map_updated(|updated| updated.insert(core))
.map_updated(|updated| {
updated
.insert(core)
.derive_from(original_half_edge, core)
})
.into_inner(),
);
}
Expand Down Expand Up @@ -100,15 +104,19 @@ impl ReplaceVertex for Region {
replacement_happened |= cycle.was_updated();
interiors.push(
cycle
.map_updated(|updated| updated.insert(core))
.map_updated(|updated| {
updated.insert(core).derive_from(original_cycle, core)
})
.into_inner(),
);
}

if replacement_happened {
ReplaceOutput::Updated(Region::new(
exterior
.map_updated(|updated| updated.insert(core))
.map_updated(|updated| {
updated.insert(core).derive_from(self.exterior(), core)
})
.into_inner(),
interiors,
self.color(),
Expand Down Expand Up @@ -138,7 +146,9 @@ impl ReplaceVertex for Sketch {
replacement_happened |= region.was_updated();
regions.push(
region
.map_updated(|updated| updated.insert(core))
.map_updated(|updated| {
updated.insert(core).derive_from(original_region, core)
})
.into_inner(),
);
}
Expand All @@ -164,7 +174,9 @@ impl ReplaceVertex for Face {
ReplaceOutput::Updated(Face::new(
self.surface().clone(),
region
.map_updated(|updated| updated.insert(core))
.map_updated(|updated| {
updated.insert(core).derive_from(self.region(), core)
})
.into_inner(),
))
} else {
Expand All @@ -191,8 +203,10 @@ impl ReplaceVertex for Shell {
);
replacement_happened |= face.was_updated();
faces.push(
face.map_updated(|updated| updated.insert(core))
.into_inner(),
face.map_updated(|updated| {
updated.insert(core).derive_from(original_face, core)
})
.into_inner(),
);
}

Expand Down Expand Up @@ -223,7 +237,9 @@ impl ReplaceVertex for Solid {
replacement_happened |= shell.was_updated();
shells.push(
shell
.map_updated(|updated| updated.insert(core))
.map_updated(|updated| {
updated.insert(core).derive_from(original_shell, core)
})
.into_inner(),
);
}
Expand Down Expand Up @@ -294,7 +310,9 @@ impl ReplaceVertex for Handle<Sketch> {
replacement_happened |= region.was_updated();
regions.push(
region
.map_updated(|updated| updated.insert(core))
.map_updated(|updated| {
updated.insert(core).derive_from(original_region, core)
})
.into_inner(),
);
}
Expand Down
7 changes: 5 additions & 2 deletions crates/fj-core/src/operations/reverse/cycle.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
objects::{Cycle, HalfEdge},
operations::insert::Insert,
operations::{derive::DeriveFrom, insert::Insert},
Core,
};

Expand All @@ -19,6 +19,7 @@ impl Reverse for Cycle {
next.start_vertex().clone(),
)
.insert(core)
.derive_from(current, core)
})
.collect::<Vec<_>>();

Expand All @@ -31,7 +32,9 @@ impl Reverse for Cycle {
impl ReverseCurveCoordinateSystems for Cycle {
fn reverse_curve_coordinate_systems(&self, core: &mut Core) -> Self {
let edges = self.half_edges().iter().map(|edge| {
edge.reverse_curve_coordinate_systems(core).insert(core)
edge.reverse_curve_coordinate_systems(core)
.insert(core)
.derive_from(edge, core)
});

Cycle::new(edges)
Expand Down
20 changes: 16 additions & 4 deletions crates/fj-core/src/operations/reverse/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
objects::Face,
operations::{
build::Polygon,
derive::DeriveFrom,
insert::{Insert, IsInsertedNo, IsInsertedYes},
},
Core,
Expand All @@ -13,7 +14,11 @@ use super::{Reverse, ReverseCurveCoordinateSystems};

impl Reverse for Face {
fn reverse(&self, core: &mut Core) -> Self {
let region = self.region().reverse(core).insert(core);
let region = self
.region()
.reverse(core)
.insert(core)
.derive_from(self.region(), core);
Face::new(self.surface().clone(), region)
}
}
Expand All @@ -28,7 +33,10 @@ impl<const D: usize> Reverse for Polygon<D, IsInsertedNo> {
impl<const D: usize> Reverse for Polygon<D, IsInsertedYes> {
fn reverse(&self, core: &mut Core) -> Self {
let face: &Face = self.face.borrow();
let face = face.reverse(core).insert(core);
let face = face
.reverse(core)
.insert(core)
.derive_from(&self.face, core);

self.replace_face(face)
}
Expand All @@ -39,7 +47,8 @@ impl ReverseCurveCoordinateSystems for Face {
let region = self
.region()
.reverse_curve_coordinate_systems(core)
.insert(core);
.insert(core)
.derive_from(self.region(), core);
Face::new(self.surface().clone(), region)
}
}
Expand All @@ -58,7 +67,10 @@ impl<const D: usize> ReverseCurveCoordinateSystems
{
fn reverse_curve_coordinate_systems(&self, core: &mut Core) -> Self {
let face: &Face = self.face.borrow();
let face = face.reverse_curve_coordinate_systems(core).insert(core);
let face = face
.reverse_curve_coordinate_systems(core)
.insert(core)
.derive_from(&self.face, core);

self.replace_face(face)
}
Expand Down
27 changes: 19 additions & 8 deletions crates/fj-core/src/operations/reverse/region.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
use crate::{objects::Region, operations::insert::Insert, Core};
use crate::{
objects::Region,
operations::{derive::DeriveFrom, insert::Insert},
Core,
};

use super::{Reverse, ReverseCurveCoordinateSystems};

impl Reverse for Region {
fn reverse(&self, core: &mut Core) -> Self {
let exterior = self.exterior().reverse(core).insert(core);
let interiors = self
.interiors()
.iter()
.map(|cycle| cycle.reverse(core).insert(core));
let exterior = self
.exterior()
.reverse(core)
.insert(core)
.derive_from(self.exterior(), core);
let interiors = self.interiors().iter().map(|cycle| {
cycle.reverse(core).insert(core).derive_from(cycle, core)
});

Region::new(exterior, interiors, self.color())
}
Expand All @@ -19,9 +26,13 @@ impl ReverseCurveCoordinateSystems for Region {
let exterior = self
.exterior()
.reverse_curve_coordinate_systems(core)
.insert(core);
.insert(core)
.derive_from(self.exterior(), core);
let interiors = self.interiors().iter().map(|cycle| {
cycle.reverse_curve_coordinate_systems(core).insert(core)
cycle
.reverse_curve_coordinate_systems(core)
.insert(core)
.derive_from(cycle, core)
});

Region::new(exterior, interiors, self.color())
Expand Down
Loading

0 comments on commit cb123b8

Please sign in to comment.