From 398278399d449420defab0a278b7e831ed6d46e6 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 17 Jan 2024 10:01:40 +0100 Subject: [PATCH 1/4] Add `color` model --- Cargo.lock | 8 ++++++++ Cargo.toml | 1 + models/color/Cargo.toml | 11 +++++++++++ models/color/src/lib.rs | 35 +++++++++++++++++++++++++++++++++++ models/color/src/main.rs | 8 ++++++++ 5 files changed, 63 insertions(+) create mode 100644 models/color/Cargo.toml create mode 100644 models/color/src/lib.rs create mode 100644 models/color/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 636b359c3..d5e2b91c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -566,6 +566,14 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "color" +version = "0.1.0" +dependencies = [ + "cuboid", + "fj", +] + [[package]] name = "color_quant" version = "1.1.0" diff --git a/Cargo.toml b/Cargo.toml index 26b18ba89..62a9cea60 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ members = [ "crates/fj-window", "models/all", + "models/color", "models/cuboid", "models/holes", "models/spacer", diff --git a/models/color/Cargo.toml b/models/color/Cargo.toml new file mode 100644 index 000000000..ae3797e85 --- /dev/null +++ b/models/color/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "color" +version = "0.1.0" +edition = "2021" + + +[dependencies.cuboid] +path = "../cuboid" + +[dependencies.fj] +path = "../../crates/fj" diff --git a/models/color/src/lib.rs b/models/color/src/lib.rs new file mode 100644 index 000000000..de72ac883 --- /dev/null +++ b/models/color/src/lib.rs @@ -0,0 +1,35 @@ +use fj::{ + core::{ + objects::{Region, Solid}, + operations::{ + insert::Insert, + update::{UpdateFace, UpdateShell, UpdateSolid}, + }, + services::Services, + storage::Handle, + }, + interop::Color, +}; + +pub fn model(services: &mut Services) -> Handle { + 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::new( + region.exterior().clone(), + region.interiors().into_iter().cloned(), + Some(Color::from([0., 1., 0.])), + ) + .insert(services) + }) + .insert(services) + }) + .insert(services) + }) + .insert(services) +} diff --git a/models/color/src/main.rs b/models/color/src/main.rs new file mode 100644 index 000000000..5bfd32f15 --- /dev/null +++ b/models/color/src/main.rs @@ -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(()) +} From 5312f4c5d072450aab872b083810fa44587b21a5 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 17 Jan 2024 10:37:07 +0100 Subject: [PATCH 2/4] Add `SetColor` operations --- crates/fj-core/src/operations/mod.rs | 1 + crates/fj-core/src/operations/presentation.rs | 9 +++++++++ 2 files changed, 10 insertions(+) create mode 100644 crates/fj-core/src/operations/presentation.rs diff --git a/crates/fj-core/src/operations/mod.rs b/crates/fj-core/src/operations/mod.rs index 790384d17..15c69c85c 100644 --- a/crates/fj-core/src/operations/mod.rs +++ b/crates/fj-core/src/operations/mod.rs @@ -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; diff --git a/crates/fj-core/src/operations/presentation.rs b/crates/fj-core/src/operations/presentation.rs new file mode 100644 index 000000000..142a50249 --- /dev/null +++ b/crates/fj-core/src/operations/presentation.rs @@ -0,0 +1,9 @@ +//! Operations to control the presentation of objects + +use fj_interop::Color; + +/// Set the color of an object +pub trait SetColor { + /// Set the color of the object + fn set_color(&self, color: impl Into) -> Self; +} From 854e56139ab88517e651b38699ada33e1b8aa152 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 17 Jan 2024 10:37:54 +0100 Subject: [PATCH 3/4] Implement `SetColor` for `Region` --- crates/fj-core/src/operations/presentation.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/fj-core/src/operations/presentation.rs b/crates/fj-core/src/operations/presentation.rs index 142a50249..b2e9c9211 100644 --- a/crates/fj-core/src/operations/presentation.rs +++ b/crates/fj-core/src/operations/presentation.rs @@ -2,8 +2,20 @@ 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) -> Self; } + +impl SetColor for Region { + fn set_color(&self, color: impl Into) -> Self { + Region::new( + self.exterior().clone(), + self.interiors().into_iter().cloned(), + Some(color.into()), + ) + } +} From 814d156812ade7e7d0a518892fece4317f5c28dc Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 17 Jan 2024 10:38:39 +0100 Subject: [PATCH 4/4] Simplify `color` model --- models/color/src/lib.rs | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/models/color/src/lib.rs b/models/color/src/lib.rs index de72ac883..0bae8de02 100644 --- a/models/color/src/lib.rs +++ b/models/color/src/lib.rs @@ -1,14 +1,12 @@ -use fj::{ - core::{ - objects::{Region, Solid}, - operations::{ - insert::Insert, - update::{UpdateFace, UpdateShell, UpdateSolid}, - }, - services::Services, - storage::Handle, +use fj::core::{ + objects::Solid, + operations::{ + insert::Insert, + presentation::SetColor, + update::{UpdateFace, UpdateShell, UpdateSolid}, }, - interop::Color, + services::Services, + storage::Handle, }; pub fn model(services: &mut Services) -> Handle { @@ -20,12 +18,7 @@ pub fn model(services: &mut Services) -> Handle { shell .update_face(shell.faces().first(), |face| { face.update_region(|region| { - Region::new( - region.exterior().clone(), - region.interiors().into_iter().cloned(), - Some(Color::from([0., 1., 0.])), - ) - .insert(services) + region.set_color([0., 1., 0.]).insert(services) }) .insert(services) })