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

Add DeriveFrom #2219

Merged
merged 4 commits into from
Feb 16, 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
19 changes: 19 additions & 0 deletions crates/fj-core/src/operations/derive.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//! Mark a stored object as derived from another
//!
//! See [`DeriveFrom`].

use crate::{storage::Handle, Core};

/// Mark a store object as derived from another
pub trait DeriveFrom {
/// Mark this object as derived from the other object provided
fn derive_from(self, other: &Self, core: &mut Core) -> Self;
}

impl<T> DeriveFrom for Handle<T> {
fn derive_from(self, _other: &Self, _core: &mut Core) -> Self {
// This is currently a no-op. Eventually, it will trigger a command to
// the layers that this information is relevant for.
self
}
}
1 change: 1 addition & 0 deletions crates/fj-core/src/operations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
//! send a pull request!

pub mod build;
pub mod derive;
pub mod holes;
pub mod insert;
pub mod join;
Expand Down
78 changes: 55 additions & 23 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 @@ -52,13 +52,20 @@ impl ReplaceCurve for Cycle {
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(), core);
for original_half_edge in self.half_edges() {
let half_edge = original_half_edge.replace_curve(
original,
replacement.clone(),
core,
);
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 @@ -86,21 +93,28 @@ impl ReplaceCurve for Region {
replacement_happened |= exterior.was_updated();

let mut interiors = Vec::new();
for cycle in self.interiors() {
let cycle =
cycle.replace_curve(original, replacement.clone(), core);
for original_cycle in self.interiors() {
let cycle = original_cycle.replace_curve(
original,
replacement.clone(),
core,
);
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 All @@ -121,13 +135,18 @@ impl ReplaceCurve for Sketch {
let mut replacement_happened = false;

let mut regions = Vec::new();
for region in self.regions() {
let region =
region.replace_curve(original, replacement.clone(), core);
for original_region in self.regions() {
let region = original_region.replace_curve(
original,
replacement.clone(),
core,
);
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 @@ -153,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 @@ -172,12 +193,18 @@ impl ReplaceCurve for Shell {
let mut replacement_happened = false;

let mut faces = Vec::new();
for face in self.faces() {
let face = face.replace_curve(original, replacement.clone(), core);
for original_face in self.faces() {
let face = original_face.replace_curve(
original,
replacement.clone(),
core,
);
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 All @@ -199,13 +226,18 @@ impl ReplaceCurve for Solid {
let mut replacement_happened = false;

let mut shells = Vec::new();
for shell in self.shells() {
let shell =
shell.replace_curve(original, replacement.clone(), core);
for original_shell in self.shells() {
let shell = original_shell.replace_curve(
original,
replacement.clone(),
core,
);
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
64 changes: 44 additions & 20 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 @@ -59,21 +59,28 @@ impl ReplaceHalfEdge for Region {
replacement_happened |= exterior.was_updated();

let mut interiors = Vec::new();
for cycle in self.interiors() {
let cycle =
cycle.replace_half_edge(original, replacements.clone(), core);
for original_cycle in self.interiors() {
let cycle = original_cycle.replace_half_edge(
original,
replacements.clone(),
core,
);
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 All @@ -94,13 +101,18 @@ impl ReplaceHalfEdge for Sketch {
let mut replacement_happened = false;

let mut regions = Vec::new();
for region in self.regions() {
let region =
region.replace_half_edge(original, replacements.clone(), core);
for original_region in self.regions() {
let region = original_region.replace_half_edge(
original,
replacements.clone(),
core,
);
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 @@ -128,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 @@ -147,13 +161,18 @@ impl ReplaceHalfEdge for Shell {
let mut replacement_happened = false;

let mut faces = Vec::new();
for face in self.faces() {
let face =
face.replace_half_edge(original, replacements.clone(), core);
for original_face in self.faces() {
let face = original_face.replace_half_edge(
original,
replacements.clone(),
core,
);
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 All @@ -175,13 +194,18 @@ impl ReplaceHalfEdge for Solid {
let mut replacement_happened = false;

let mut shells = Vec::new();
for shell in self.shells() {
let shell =
shell.replace_half_edge(original, replacements.clone(), core);
for original_shell in self.shells() {
let shell = original_shell.replace_half_edge(
original,
replacements.clone(),
core,
);
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
Loading