From a684ebdeb7b9b5847caa0c10307b6ed286f10310 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 12 Dec 2023 11:21:53 +0100 Subject: [PATCH 01/15] Refactor to prepare for follow-on change --- models/holes/src/lib.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/models/holes/src/lib.rs b/models/holes/src/lib.rs index c896926c4..c7461fe3c 100644 --- a/models/holes/src/lib.rs +++ b/models/holes/src/lib.rs @@ -9,14 +9,16 @@ pub fn model(services: &mut Services) -> Handle { let cuboid = cuboid::model(1., 1., 1., services); let shell = cuboid.shells().first(); - let bottom_face = shell.faces().first(); - let hole_position = [0., 0.]; let hole_radius = 0.25; - let hole_path = [0., 0., 0.5]; cuboid .update_shell(shell, |shell| { + let bottom_face = shell.faces().first(); + + let hole_position = [0., 0.]; + let hole_path = [0., 0., 0.5]; + shell .add_blind_hole( bottom_face, From 33d466862cc2f6e678f430f9fee7a556db8b376b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 12 Dec 2023 11:22:07 +0100 Subject: [PATCH 02/15] Inline redundant variable --- models/holes/src/lib.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/models/holes/src/lib.rs b/models/holes/src/lib.rs index c7461fe3c..e0c1ec527 100644 --- a/models/holes/src/lib.rs +++ b/models/holes/src/lib.rs @@ -8,12 +8,10 @@ use fj::core::{ pub fn model(services: &mut Services) -> Handle { let cuboid = cuboid::model(1., 1., 1., services); - let shell = cuboid.shells().first(); - let hole_radius = 0.25; cuboid - .update_shell(shell, |shell| { + .update_shell(cuboid.shells().first(), |shell| { let bottom_face = shell.faces().first(); let hole_position = [0., 0.]; From eabee1d52497b8c562b2c6ae2be8e111195e253b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 12 Dec 2023 11:43:28 +0100 Subject: [PATCH 03/15] Simplify variable name --- models/holes/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/holes/src/lib.rs b/models/holes/src/lib.rs index e0c1ec527..e29746284 100644 --- a/models/holes/src/lib.rs +++ b/models/holes/src/lib.rs @@ -8,7 +8,7 @@ use fj::core::{ pub fn model(services: &mut Services) -> Handle { let cuboid = cuboid::model(1., 1., 1., services); - let hole_radius = 0.25; + let radius = 0.25; cuboid .update_shell(cuboid.shells().first(), |shell| { @@ -21,7 +21,7 @@ pub fn model(services: &mut Services) -> Handle { .add_blind_hole( bottom_face, hole_position, - hole_radius, + radius, hole_path, services, ) From 32e8a178ed8d088ace43a8dce065543df36da478 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 12 Dec 2023 11:50:02 +0100 Subject: [PATCH 04/15] Refactor to prepare for follow-on change --- models/holes/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/holes/src/lib.rs b/models/holes/src/lib.rs index e29746284..39b004b08 100644 --- a/models/holes/src/lib.rs +++ b/models/holes/src/lib.rs @@ -6,10 +6,10 @@ use fj::core::{ }; pub fn model(services: &mut Services) -> Handle { - let cuboid = cuboid::model(1., 1., 1., services); - let radius = 0.25; + let cuboid = cuboid::model(1., 1., 1., services); + cuboid .update_shell(cuboid.shells().first(), |shell| { let bottom_face = shell.faces().first(); From 05403207237ceda4ba52079d89f1df0ee1aa7cde Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 12 Dec 2023 11:50:39 +0100 Subject: [PATCH 05/15] Refactor to prepare for follow-on change --- models/holes/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/models/holes/src/lib.rs b/models/holes/src/lib.rs index 39b004b08..7369c1797 100644 --- a/models/holes/src/lib.rs +++ b/models/holes/src/lib.rs @@ -8,7 +8,8 @@ use fj::core::{ pub fn model(services: &mut Services) -> Handle { let radius = 0.25; - let cuboid = cuboid::model(1., 1., 1., services); + let size = 1.; + let cuboid = cuboid::model(size, size, size, services); cuboid .update_shell(cuboid.shells().first(), |shell| { From 40ba5e8f08d0404f430cdd9558599ce51be4b94f Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 12 Dec 2023 11:51:09 +0100 Subject: [PATCH 06/15] Make size dependant on hole radius --- models/holes/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/holes/src/lib.rs b/models/holes/src/lib.rs index 7369c1797..c2c866f81 100644 --- a/models/holes/src/lib.rs +++ b/models/holes/src/lib.rs @@ -8,7 +8,7 @@ use fj::core::{ pub fn model(services: &mut Services) -> Handle { let radius = 0.25; - let size = 1.; + let size = radius * 4.; let cuboid = cuboid::model(size, size, size, services); cuboid From feeabb982eeffd9531b104b1ccaf2315854d1f92 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 12 Dec 2023 11:52:11 +0100 Subject: [PATCH 07/15] Refactor to prepare for follow-on change --- models/holes/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/models/holes/src/lib.rs b/models/holes/src/lib.rs index c2c866f81..d245fe986 100644 --- a/models/holes/src/lib.rs +++ b/models/holes/src/lib.rs @@ -16,7 +16,8 @@ pub fn model(services: &mut Services) -> Handle { let bottom_face = shell.faces().first(); let hole_position = [0., 0.]; - let hole_path = [0., 0., 0.5]; + let depth = 0.5; + let hole_path = [0., 0., depth]; shell .add_blind_hole( From 0bfcaff5a9b2eb0b0657d9434242aa5fa7f832bd Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 12 Dec 2023 11:52:24 +0100 Subject: [PATCH 08/15] Inline redundant variable --- models/holes/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/models/holes/src/lib.rs b/models/holes/src/lib.rs index d245fe986..00c0d48ab 100644 --- a/models/holes/src/lib.rs +++ b/models/holes/src/lib.rs @@ -17,14 +17,13 @@ pub fn model(services: &mut Services) -> Handle { let hole_position = [0., 0.]; let depth = 0.5; - let hole_path = [0., 0., depth]; shell .add_blind_hole( bottom_face, hole_position, radius, - hole_path, + [0., 0., depth], services, ) .insert(services) From d018367423052f5b644157b647bd9d1e59b8124a Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 12 Dec 2023 11:53:02 +0100 Subject: [PATCH 09/15] Make hole depth dependant on size --- models/holes/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/holes/src/lib.rs b/models/holes/src/lib.rs index 00c0d48ab..17375f30a 100644 --- a/models/holes/src/lib.rs +++ b/models/holes/src/lib.rs @@ -16,7 +16,7 @@ pub fn model(services: &mut Services) -> Handle { let bottom_face = shell.faces().first(); let hole_position = [0., 0.]; - let depth = 0.5; + let depth = size / 2.; shell .add_blind_hole( From d60910b8690fe4e1e961cd4f318dffd0ce42836d Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 12 Dec 2023 11:56:07 +0100 Subject: [PATCH 10/15] Refactor to prepare for follow-on change --- models/all/src/lib.rs | 2 +- models/cuboid/src/lib.rs | 2 +- models/cuboid/src/main.rs | 2 +- models/holes/src/lib.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/models/all/src/lib.rs b/models/all/src/lib.rs index 48d52156e..1f838204c 100644 --- a/models/all/src/lib.rs +++ b/models/all/src/lib.rs @@ -18,7 +18,7 @@ pub fn model(services: &mut Services) -> Handle { let axis = Vector::from([1., 1., 1.]).normalize(); let angle_rad = Scalar::PI / 6.; - let cuboid = cuboid::model(1., 2., 3., services) + 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) diff --git a/models/cuboid/src/lib.rs b/models/cuboid/src/lib.rs index eebe7781e..8988abd0e 100644 --- a/models/cuboid/src/lib.rs +++ b/models/cuboid/src/lib.rs @@ -13,7 +13,7 @@ use fj::{ math::Vector, }; -pub fn model(x: f64, y: f64, z: f64, services: &mut Services) -> Handle { +pub fn model([x, y, z]: [f64; 3], services: &mut Services) -> Handle { let sketch = Sketch::empty().add_region( Region::polygon( [ diff --git a/models/cuboid/src/main.rs b/models/cuboid/src/main.rs index 23edaa890..3a3836caf 100644 --- a/models/cuboid/src/main.rs +++ b/models/cuboid/src/main.rs @@ -2,7 +2,7 @@ use fj::{core::services::Services, handle_model}; fn main() -> fj::Result { let mut services = Services::new(); - let model = cuboid::model(3., 2., 1., &mut services); + let model = cuboid::model([3., 2., 1.], &mut services); handle_model(model, services)?; Ok(()) } diff --git a/models/holes/src/lib.rs b/models/holes/src/lib.rs index 17375f30a..49d1c06f7 100644 --- a/models/holes/src/lib.rs +++ b/models/holes/src/lib.rs @@ -9,7 +9,7 @@ pub fn model(services: &mut Services) -> Handle { let radius = 0.25; let size = radius * 4.; - let cuboid = cuboid::model(size, size, size, services); + let cuboid = cuboid::model([size, size, size], services); cuboid .update_shell(cuboid.shells().first(), |shell| { From cfb2e8a80f8af489cca4f2cc19d33b01b03cb47a Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 12 Dec 2023 11:58:47 +0100 Subject: [PATCH 11/15] Improve arguments of `cuboid` model --- models/cuboid/src/lib.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/models/cuboid/src/lib.rs b/models/cuboid/src/lib.rs index 8988abd0e..8faba1bbe 100644 --- a/models/cuboid/src/lib.rs +++ b/models/cuboid/src/lib.rs @@ -10,10 +10,15 @@ use fj::{ services::Services, storage::Handle, }, - math::Vector, + math::{Scalar, Vector}, }; -pub fn model([x, y, z]: [f64; 3], services: &mut Services) -> Handle { +pub fn model( + size: impl Into>, + services: &mut Services, +) -> Handle { + let [x, y, z] = size.into().components; + let sketch = Sketch::empty().add_region( Region::polygon( [ @@ -28,7 +33,7 @@ pub fn model([x, y, z]: [f64; 3], services: &mut Services) -> Handle { ); let surface = services.objects.surfaces.xy_plane(); - let path = Vector::from([0., 0., z]); + let path = Vector::from([Scalar::ZERO, Scalar::ZERO, z]); sketch .sweep_sketch(surface, path, services) .insert(services) From cf525bbc12b01c08dc58a2863260da2ff70d7eea Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 12 Dec 2023 12:17:31 +0100 Subject: [PATCH 12/15] Refactor to prepare for follow-on change --- models/holes/src/lib.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/models/holes/src/lib.rs b/models/holes/src/lib.rs index 49d1c06f7..a530e3811 100644 --- a/models/holes/src/lib.rs +++ b/models/holes/src/lib.rs @@ -1,12 +1,15 @@ -use fj::core::{ - objects::Solid, - operations::{holes::AddHole, insert::Insert, update::UpdateSolid}, - services::Services, - storage::Handle, +use fj::{ + core::{ + objects::Solid, + operations::{holes::AddHole, insert::Insert, update::UpdateSolid}, + services::Services, + storage::Handle, + }, + math::Scalar, }; pub fn model(services: &mut Services) -> Handle { - let radius = 0.25; + let radius = Scalar::from(0.25); let size = radius * 4.; let cuboid = cuboid::model([size, size, size], services); @@ -23,7 +26,7 @@ pub fn model(services: &mut Services) -> Handle { bottom_face, hole_position, radius, - [0., 0., depth], + [Scalar::ZERO, Scalar::ZERO, depth], services, ) .insert(services) From 814099b6fa803da80dc22409b2ba91291e397e7c Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 12 Dec 2023 12:17:56 +0100 Subject: [PATCH 13/15] Improve arguments of `holes` model --- models/holes/src/lib.rs | 7 +++++-- models/holes/src/main.rs | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/models/holes/src/lib.rs b/models/holes/src/lib.rs index a530e3811..7867b17c7 100644 --- a/models/holes/src/lib.rs +++ b/models/holes/src/lib.rs @@ -8,8 +8,11 @@ use fj::{ math::Scalar, }; -pub fn model(services: &mut Services) -> Handle { - let radius = Scalar::from(0.25); +pub fn model( + radius: impl Into, + services: &mut Services, +) -> Handle { + let radius = radius.into(); let size = radius * 4.; let cuboid = cuboid::model([size, size, size], services); diff --git a/models/holes/src/main.rs b/models/holes/src/main.rs index 9091143ec..6165441dd 100644 --- a/models/holes/src/main.rs +++ b/models/holes/src/main.rs @@ -2,7 +2,7 @@ use fj::{core::services::Services, handle_model}; fn main() -> fj::Result { let mut services = Services::new(); - let model = holes::model(&mut services); + let model = holes::model(0.25, &mut services); handle_model(model, services)?; Ok(()) } From de4fe9158038e18e55741a39263787d799708d7b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 12 Dec 2023 11:45:56 +0100 Subject: [PATCH 14/15] Include `holes` model in `all` model --- Cargo.lock | 1 + models/all/Cargo.toml | 3 +++ models/all/src/lib.rs | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 66bd86951..4a11f3baf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -61,6 +61,7 @@ version = "0.1.0" dependencies = [ "cuboid", "fj", + "holes", "spacer", "split", "star", diff --git a/models/all/Cargo.toml b/models/all/Cargo.toml index 0d758a141..8963edec7 100644 --- a/models/all/Cargo.toml +++ b/models/all/Cargo.toml @@ -9,6 +9,9 @@ path = "../../crates/fj" [dependencies.cuboid] path = "../cuboid" +[dependencies.holes] +path = "../holes" + [dependencies.spacer] path = "../spacer" diff --git a/models/all/src/lib.rs b/models/all/src/lib.rs index 1f838204c..ecb356f2a 100644 --- a/models/all/src/lib.rs +++ b/models/all/src/lib.rs @@ -30,10 +30,14 @@ pub fn model(services: &mut Services) -> Handle { let split = split::model(1., 0.5, 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) .insert(services) } From b422299388e1dbc8178b499172afbfa6a274f566 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 12 Dec 2023 11:46:45 +0100 Subject: [PATCH 15/15] Use more interesting parameter in `all` model --- models/all/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/all/src/lib.rs b/models/all/src/lib.rs index ecb356f2a..784a9b5cf 100644 --- a/models/all/src/lib.rs +++ b/models/all/src/lib.rs @@ -27,7 +27,7 @@ pub fn model(services: &mut Services) -> Handle { 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.5, 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)