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 SetColor operation #2167

Merged
merged 4 commits into from
Jan 17, 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
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(())
}