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

Implement SetColor for Handle<Region> instead of Region #2179

Merged
merged 2 commits into from
Jan 26, 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
13 changes: 8 additions & 5 deletions crates/fj-core/src/operations/presentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@

use fj_interop::Color;

use crate::objects::Region;
use crate::{
objects::{IsObject, Region},
storage::Handle,
};

/// Set the color of an object
pub trait SetColor {
pub trait SetColor: IsObject {
/// Set the color of the object
fn set_color(&self, color: impl Into<Color>) -> Self;
fn set_color(&self, color: impl Into<Color>) -> Self::BareObject;
}

impl SetColor for Region {
fn set_color(&self, color: impl Into<Color>) -> Self {
impl SetColor for Handle<Region> {
fn set_color(&self, color: impl Into<Color>) -> Self::BareObject {
Region::new(
self.exterior().clone(),
self.interiors().into_iter().cloned(),
Expand Down
36 changes: 20 additions & 16 deletions crates/fj-core/src/operations/split/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,20 @@ impl SplitFace for Shell {
services,
)
.update_region(|region| {
let mut region = region.update_exterior(|cycle| {
cycle
.add_half_edges(half_edges_b_to_c_inclusive)
.add_half_edges([dividing_half_edge_c_to_b])
.insert(services)
});
let mut region = region
.update_exterior(|cycle| {
cycle
.add_half_edges(half_edges_b_to_c_inclusive)
.add_half_edges([dividing_half_edge_c_to_b])
.insert(services)
})
.insert(services);

if let Some(color) = face.region().color() {
region = region.set_color(color);
region = region.set_color(color).insert(services);
}

region.insert(services)
region
})
.insert(services);

Expand All @@ -157,18 +159,20 @@ impl SplitFace for Shell {
services,
)
.update_region(|region| {
let mut region = region.update_exterior(|cycle| {
cycle
.add_half_edges(half_edges_d_to_a_inclusive)
.add_half_edges([dividing_half_edge_a_to_d])
.insert(services)
});
let mut region = region
.update_exterior(|cycle| {
cycle
.add_half_edges(half_edges_d_to_a_inclusive)
.add_half_edges([dividing_half_edge_a_to_d])
.insert(services)
})
.insert(services);

if let Some(color) = face.region().color() {
region = region.set_color(color);
region = region.set_color(color).insert(services);
}

region.insert(services)
region
})
.insert(services);

Expand Down