Skip to content

Commit

Permalink
Merge pull request #2179 from hannobraun/color
Browse files Browse the repository at this point in the history
Implement `SetColor` for `Handle<Region>` instead of `Region`
  • Loading branch information
hannobraun authored Jan 26, 2024
2 parents cbdf03f + 2bfb010 commit e1ad4fa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
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

0 comments on commit e1ad4fa

Please sign in to comment.