From 3c7014724e64a1acfeda0980b2549b30e468a549 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 30 Jan 2024 11:12:21 +0100 Subject: [PATCH 1/4] Refactor to reduce redundancy --- models/all/src/lib.rs | 46 ++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/models/all/src/lib.rs b/models/all/src/lib.rs index d50aab1c3..4a303e082 100644 --- a/models/all/src/lib.rs +++ b/models/all/src/lib.rs @@ -1,7 +1,9 @@ use fj::{ core::{ objects::Solid, - operations::{merge::Merge, transform::TransformObject}, + operations::{ + build::BuildSolid, merge::Merge, transform::TransformObject, + }, services::Services, }, math::{Scalar, Vector}, @@ -16,25 +18,25 @@ pub fn model(services: &mut Services) -> Solid { let axis = Vector::from([1., 1., 1.]).normalize(); let angle_rad = Scalar::PI / 6.; - let cuboid = cuboid::model([1., 2., 3.], services) - .translate(offset * 1., services) - .rotate(axis * angle_rad * 1., services); - let spacer = spacer::model(2., 1., 1., services) - .translate(offset * 2., services) - .rotate(axis * angle_rad * 2., services); - let star = star::model(5, 2., 1., 1., services) - .translate(offset * 3., services) - .rotate(axis * angle_rad * 3., services); - let split = split::model(1., 0.2, services) - .translate(offset * 4., services) - .rotate(axis * angle_rad * 4., services); - let holes = holes::model(0.5, services) - .translate(offset * 5., services) - .rotate(axis * angle_rad * 5., services); - - cuboid - .merge(&spacer) - .merge(&star) - .merge(&split) - .merge(&holes) + let models = [ + cuboid::model([1., 2., 3.], services), + spacer::model(2., 1., 1., services), + star::model(5, 2., 1., 1., services), + split::model(1., 0.2, services), + holes::model(0.5, services), + ]; + + let mut all = Solid::empty(); + + for (i, model) in models.into_iter().enumerate() { + let f = i as f64; + + let model = model + .translate(offset * f, services) + .rotate(axis * angle_rad * f, services); + + all = all.merge(&model); + } + + all } From 16f34c666881388226b5bc6c58cc824a76b5e936 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 30 Jan 2024 11:12:55 +0100 Subject: [PATCH 2/4] Update order of models in `all` Sorting them alphabetically means that their order matches the order they are typically displayed in within the `models/` directory. This makes it easier to see, if any are missing. --- models/all/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/all/src/lib.rs b/models/all/src/lib.rs index 4a303e082..47d9cf644 100644 --- a/models/all/src/lib.rs +++ b/models/all/src/lib.rs @@ -20,10 +20,10 @@ pub fn model(services: &mut Services) -> Solid { let models = [ cuboid::model([1., 2., 3.], services), + holes::model(0.5, services), spacer::model(2., 1., 1., services), - star::model(5, 2., 1., 1., services), split::model(1., 0.2, services), - holes::model(0.5, services), + star::model(5, 2., 1., 1., services), ]; let mut all = Solid::empty(); From 86084730051d28e2c73b2f091f0f1394ae82a981 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 30 Jan 2024 10:59:28 +0100 Subject: [PATCH 3/4] Integrate `color` model into `all` --- Cargo.lock | 1 + models/all/Cargo.toml | 3 +++ models/all/src/lib.rs | 1 + 3 files changed, 5 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index e428d2605..92139a4e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -59,6 +59,7 @@ dependencies = [ name = "all" version = "0.1.0" dependencies = [ + "color", "cuboid", "fj", "holes", diff --git a/models/all/Cargo.toml b/models/all/Cargo.toml index 8963edec7..db94c03e3 100644 --- a/models/all/Cargo.toml +++ b/models/all/Cargo.toml @@ -6,6 +6,9 @@ edition = "2021" [dependencies.fj] path = "../../crates/fj" +[dependencies.color] +path = "../color" + [dependencies.cuboid] path = "../cuboid" diff --git a/models/all/src/lib.rs b/models/all/src/lib.rs index 47d9cf644..df07a2efd 100644 --- a/models/all/src/lib.rs +++ b/models/all/src/lib.rs @@ -19,6 +19,7 @@ pub fn model(services: &mut Services) -> Solid { let angle_rad = Scalar::PI / 6.; let models = [ + color::model(services), cuboid::model([1., 2., 3.], services), holes::model(0.5, services), spacer::model(2., 1., 1., services), From aa295022916550cf10159ce6e824e112d711420c Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 30 Jan 2024 11:15:59 +0100 Subject: [PATCH 4/4] Integrate `vertices-indices` model into `all` --- Cargo.lock | 1 + models/all/Cargo.toml | 3 +++ models/all/src/lib.rs | 1 + 3 files changed, 5 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 92139a4e2..2768effd3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -66,6 +66,7 @@ dependencies = [ "spacer", "split", "star", + "vertices-indices", ] [[package]] diff --git a/models/all/Cargo.toml b/models/all/Cargo.toml index db94c03e3..4e46b4fb2 100644 --- a/models/all/Cargo.toml +++ b/models/all/Cargo.toml @@ -23,3 +23,6 @@ path = "../split" [dependencies.star] path = "../star" + +[dependencies.vertices-indices] +path = "../vertices-indices" diff --git a/models/all/src/lib.rs b/models/all/src/lib.rs index df07a2efd..59e1c5c7b 100644 --- a/models/all/src/lib.rs +++ b/models/all/src/lib.rs @@ -25,6 +25,7 @@ pub fn model(services: &mut Services) -> Solid { spacer::model(2., 1., 1., services), split::model(1., 0.2, services), star::model(5, 2., 1., 1., services), + vertices_indices::model(services), ]; let mut all = Solid::empty();