Skip to content

Commit

Permalink
Merge pull request #2167 from hannobraun/color
Browse files Browse the repository at this point in the history
Add `SetColor` operation
  • Loading branch information
hannobraun authored Jan 17, 2024
2 parents a9c15d9 + 814d156 commit edab216
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ members = [
"crates/fj-window",

"models/all",
"models/color",
"models/cuboid",
"models/holes",
"models/spacer",
Expand Down
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 @@ -43,6 +43,7 @@ pub mod holes;
pub mod insert;
pub mod join;
pub mod merge;
pub mod presentation;
pub mod replace;
pub mod reverse;
pub mod split;
Expand Down
21 changes: 21 additions & 0 deletions crates/fj-core/src/operations/presentation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! Operations to control the presentation of objects
use fj_interop::Color;

use crate::objects::Region;

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

impl SetColor for Region {
fn set_color(&self, color: impl Into<Color>) -> Self {
Region::new(
self.exterior().clone(),
self.interiors().into_iter().cloned(),
Some(color.into()),
)
}
}
11 changes: 11 additions & 0 deletions models/color/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "color"
version = "0.1.0"
edition = "2021"


[dependencies.cuboid]
path = "../cuboid"

[dependencies.fj]
path = "../../crates/fj"
28 changes: 28 additions & 0 deletions models/color/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use fj::core::{
objects::Solid,
operations::{
insert::Insert,
presentation::SetColor,
update::{UpdateFace, UpdateShell, UpdateSolid},
},
services::Services,
storage::Handle,
};

pub fn model(services: &mut Services) -> Handle<Solid> {
let size = 1.;
let cuboid = cuboid::model([size, size, size], services);

cuboid
.update_shell(cuboid.shells().only(), |shell| {
shell
.update_face(shell.faces().first(), |face| {
face.update_region(|region| {
region.set_color([0., 1., 0.]).insert(services)
})
.insert(services)
})
.insert(services)
})
.insert(services)
}
8 changes: 8 additions & 0 deletions models/color/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use fj::{core::services::Services, handle_model};

fn main() -> fj::Result {
let mut services = Services::new();
let model = color::model(&mut services);
handle_model(model, services)?;
Ok(())
}

0 comments on commit edab216

Please sign in to comment.