From 0e6b4037a443236fe7d844e6b67f69ab97dde47b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 14 Dec 2023 12:51:01 +0100 Subject: [PATCH 01/15] Refactor to prepare for follow-on change --- models/cuboid/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/models/cuboid/src/lib.rs b/models/cuboid/src/lib.rs index 8faba1bbe..c66b424fb 100644 --- a/models/cuboid/src/lib.rs +++ b/models/cuboid/src/lib.rs @@ -19,6 +19,9 @@ pub fn model( ) -> Handle { let [x, y, z] = size.into().components; + let surface = services.objects.surfaces.xy_plane(); + let path = Vector::from([Scalar::ZERO, Scalar::ZERO, z]); + let sketch = Sketch::empty().add_region( Region::polygon( [ @@ -32,8 +35,6 @@ pub fn model( .insert(services), ); - let surface = services.objects.surfaces.xy_plane(); - let path = Vector::from([Scalar::ZERO, Scalar::ZERO, z]); sketch .sweep_sketch(surface, path, services) .insert(services) From 051c47d09ab71ec5779d9fe4eabc757d8b8ef523 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 14 Dec 2023 12:52:18 +0100 Subject: [PATCH 02/15] Inline redundant variable --- models/cuboid/src/lib.rs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/models/cuboid/src/lib.rs b/models/cuboid/src/lib.rs index c66b424fb..bbd5663e7 100644 --- a/models/cuboid/src/lib.rs +++ b/models/cuboid/src/lib.rs @@ -22,20 +22,19 @@ pub fn model( let surface = services.objects.surfaces.xy_plane(); let path = Vector::from([Scalar::ZERO, Scalar::ZERO, z]); - let sketch = Sketch::empty().add_region( - Region::polygon( - [ - [-x / 2., -y / 2.], - [x / 2., -y / 2.], - [x / 2., y / 2.], - [-x / 2., y / 2.], - ], - services, + Sketch::empty() + .add_region( + Region::polygon( + [ + [-x / 2., -y / 2.], + [x / 2., -y / 2.], + [x / 2., y / 2.], + [-x / 2., y / 2.], + ], + services, + ) + .insert(services), ) - .insert(services), - ); - - sketch .sweep_sketch(surface, path, services) .insert(services) } From 31b51ca20b0bfeb974138864858408c2f146d804 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 14 Dec 2023 12:52:47 +0100 Subject: [PATCH 03/15] Rename variable to improve clarity --- models/cuboid/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/cuboid/src/lib.rs b/models/cuboid/src/lib.rs index bbd5663e7..758f76e18 100644 --- a/models/cuboid/src/lib.rs +++ b/models/cuboid/src/lib.rs @@ -20,7 +20,7 @@ pub fn model( let [x, y, z] = size.into().components; let surface = services.objects.surfaces.xy_plane(); - let path = Vector::from([Scalar::ZERO, Scalar::ZERO, z]); + let sweep_path = Vector::from([Scalar::ZERO, Scalar::ZERO, z]); Sketch::empty() .add_region( @@ -35,6 +35,6 @@ pub fn model( ) .insert(services), ) - .sweep_sketch(surface, path, services) + .sweep_sketch(surface, sweep_path, services) .insert(services) } From 26833c0da5e997ade640ac9ed49fe23e63704dc8 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 14 Dec 2023 12:53:13 +0100 Subject: [PATCH 04/15] Rename variable to increase clarity --- models/cuboid/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/cuboid/src/lib.rs b/models/cuboid/src/lib.rs index 758f76e18..d7b9aaf5e 100644 --- a/models/cuboid/src/lib.rs +++ b/models/cuboid/src/lib.rs @@ -19,7 +19,7 @@ pub fn model( ) -> Handle { let [x, y, z] = size.into().components; - let surface = services.objects.surfaces.xy_plane(); + let bottom_surface = services.objects.surfaces.xy_plane(); let sweep_path = Vector::from([Scalar::ZERO, Scalar::ZERO, z]); Sketch::empty() @@ -35,6 +35,6 @@ pub fn model( ) .insert(services), ) - .sweep_sketch(surface, sweep_path, services) + .sweep_sketch(bottom_surface, sweep_path, services) .insert(services) } From bb9e8d4daab281fab95a96e0a016e5237a569b9b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 14 Dec 2023 12:54:20 +0100 Subject: [PATCH 05/15] Be more explicit about selecting shell --- 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 b090a0d7b..937319f45 100644 --- a/models/holes/src/lib.rs +++ b/models/holes/src/lib.rs @@ -22,7 +22,7 @@ pub fn model( let cuboid = cuboid::model([size * 2., size, size], services); cuboid - .update_shell(cuboid.shells().first(), |shell| { + .update_shell(cuboid.shells().only(), |shell| { let bottom_face = shell.faces().first(); let offset = size / 2.; let depth = size / 2.; From d3c7924f6bb24f404c5a40f5bbfc3e2878567e62 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 14 Dec 2023 12:59:56 +0100 Subject: [PATCH 06/15] Refactor to prepare for follow-on change --- models/spacer/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/models/spacer/src/lib.rs b/models/spacer/src/lib.rs index b45af3891..aaf9800c4 100644 --- a/models/spacer/src/lib.rs +++ b/models/spacer/src/lib.rs @@ -20,6 +20,9 @@ pub fn model( height: f64, services: &mut Services, ) -> Handle { + let surface = services.objects.surfaces.xy_plane(); + let path = Vector::from([0., 0., height]); + let sketch = Sketch::empty().add_region( Region::circle(Point::origin(), outer, services) .add_interiors([Cycle::circle(Point::origin(), inner, services) @@ -28,8 +31,6 @@ pub fn model( .insert(services), ); - let surface = services.objects.surfaces.xy_plane(); - let path = Vector::from([0., 0., height]); sketch .sweep_sketch(surface, path, services) .insert(services) From faf5fbb882bcfe550b73896ce26a1a6539d7f853 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 14 Dec 2023 13:00:36 +0100 Subject: [PATCH 07/15] Inline redundant variable --- models/spacer/src/lib.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/models/spacer/src/lib.rs b/models/spacer/src/lib.rs index aaf9800c4..e9dfa6965 100644 --- a/models/spacer/src/lib.rs +++ b/models/spacer/src/lib.rs @@ -23,15 +23,18 @@ pub fn model( let surface = services.objects.surfaces.xy_plane(); let path = Vector::from([0., 0., height]); - let sketch = Sketch::empty().add_region( - Region::circle(Point::origin(), outer, services) - .add_interiors([Cycle::circle(Point::origin(), inner, services) + Sketch::empty() + .add_region( + Region::circle(Point::origin(), outer, services) + .add_interiors([Cycle::circle( + Point::origin(), + inner, + services, + ) .reverse(services) .insert(services)]) - .insert(services), - ); - - sketch + .insert(services), + ) .sweep_sketch(surface, path, services) .insert(services) } From b60ce3b93e079b817627728209722174a2e67701 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 14 Dec 2023 13:00:53 +0100 Subject: [PATCH 08/15] Rename variable to increase clarity --- models/spacer/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/spacer/src/lib.rs b/models/spacer/src/lib.rs index e9dfa6965..8b56473a9 100644 --- a/models/spacer/src/lib.rs +++ b/models/spacer/src/lib.rs @@ -20,7 +20,7 @@ pub fn model( height: f64, services: &mut Services, ) -> Handle { - let surface = services.objects.surfaces.xy_plane(); + let bottom_surface = services.objects.surfaces.xy_plane(); let path = Vector::from([0., 0., height]); Sketch::empty() @@ -35,6 +35,6 @@ pub fn model( .insert(services)]) .insert(services), ) - .sweep_sketch(surface, path, services) + .sweep_sketch(bottom_surface, path, services) .insert(services) } From 4aaacc2af3c409ad6c515cadb5a86889e7121023 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 14 Dec 2023 13:01:29 +0100 Subject: [PATCH 09/15] Rename variable to increase clarity --- models/spacer/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/spacer/src/lib.rs b/models/spacer/src/lib.rs index 8b56473a9..8c7bd9684 100644 --- a/models/spacer/src/lib.rs +++ b/models/spacer/src/lib.rs @@ -21,7 +21,7 @@ pub fn model( services: &mut Services, ) -> Handle { let bottom_surface = services.objects.surfaces.xy_plane(); - let path = Vector::from([0., 0., height]); + let sweep_path = Vector::from([0., 0., height]); Sketch::empty() .add_region( @@ -35,6 +35,6 @@ pub fn model( .insert(services)]) .insert(services), ) - .sweep_sketch(bottom_surface, path, services) + .sweep_sketch(bottom_surface, sweep_path, services) .insert(services) } From c1d2fc1f1e590d4c66c7721240ee8c119c4ab247 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 14 Dec 2023 13:03:21 +0100 Subject: [PATCH 10/15] Re-use `cuboid` model in `split` model --- Cargo.lock | 1 + models/split/Cargo.toml | 4 ++++ models/split/src/lib.rs | 37 ++++++++----------------------------- 3 files changed, 13 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6701bb7d0..30f5c5219 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2989,6 +2989,7 @@ dependencies = [ name = "split" version = "0.1.0" dependencies = [ + "cuboid", "fj", ] diff --git a/models/split/Cargo.toml b/models/split/Cargo.toml index ea5cc981e..6948733d9 100644 --- a/models/split/Cargo.toml +++ b/models/split/Cargo.toml @@ -3,5 +3,9 @@ name = "split" version = "0.1.0" edition = "2021" + [dependencies.fj] path = "../../crates/fj" + +[dependencies.cuboid] +path = "../cuboid" diff --git a/models/split/src/lib.rs b/models/split/src/lib.rs index d58003683..a17fbdb8a 100644 --- a/models/split/src/lib.rs +++ b/models/split/src/lib.rs @@ -1,17 +1,11 @@ -use fj::{ - core::{ - objects::{Region, Sketch, Solid}, - operations::{ - build::{BuildRegion, BuildSketch}, - insert::Insert, - split::SplitFace, - sweep::{SweepFaceOfShell, SweepSketch}, - update::{UpdateSketch, UpdateSolid}, - }, - services::Services, - storage::Handle, +use fj::core::{ + objects::Solid, + operations::{ + insert::Insert, split::SplitFace, sweep::SweepFaceOfShell, + update::UpdateSolid, }, - math::Vector, + services::Services, + storage::Handle, }; pub fn model( @@ -19,22 +13,7 @@ pub fn model( split_pos: f64, services: &mut Services, ) -> Handle { - let sketch = Sketch::empty().add_region( - Region::polygon( - [ - [-size / 2., -size / 2.], - [size / 2., -size / 2.], - [size / 2., size / 2.], - [-size / 2., size / 2.], - ], - services, - ) - .insert(services), - ); - - let surface = services.objects.surfaces.xy_plane(); - let path = Vector::from([0., 0., size]); - let solid = sketch.sweep_sketch(surface, path, services); + let solid = cuboid::model([size, size, size], services); solid .update_shell(solid.shells().only(), |shell| { From 21d7ddd781f594efdaec50e95dd34afc57578cf1 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 14 Dec 2023 13:03:47 +0100 Subject: [PATCH 11/15] Rename variable to increase clarity --- models/split/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/split/src/lib.rs b/models/split/src/lib.rs index a17fbdb8a..6e2173993 100644 --- a/models/split/src/lib.rs +++ b/models/split/src/lib.rs @@ -13,10 +13,10 @@ pub fn model( split_pos: f64, services: &mut Services, ) -> Handle { - let solid = cuboid::model([size, size, size], services); + let cuboid = cuboid::model([size, size, size], services); - solid - .update_shell(solid.shells().only(), |shell| { + cuboid + .update_shell(cuboid.shells().only(), |shell| { let face = shell.faces().first(); let cycle = face.region().exterior(); From a99b99ec215f103049a1f252f02f87841cb591c4 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 14 Dec 2023 13:18:14 +0100 Subject: [PATCH 12/15] Refactor to prepare for follow-on change --- models/star/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/models/star/src/lib.rs b/models/star/src/lib.rs index 10a7f49f6..758210e38 100644 --- a/models/star/src/lib.rs +++ b/models/star/src/lib.rs @@ -43,6 +43,9 @@ pub fn model( inner_points.push([x / 2., y / 2.]); } + let surface = services.objects.surfaces.xy_plane(); + let path = Vector::from([0., 0., h]); + let sketch = Sketch::empty().add_region( Region::polygon(outer_points, services) .add_interiors([Cycle::polygon(inner_points, services) @@ -51,8 +54,6 @@ pub fn model( .insert(services), ); - let surface = services.objects.surfaces.xy_plane(); - let path = Vector::from([0., 0., h]); sketch .sweep_sketch(surface, path, services) .insert(services) From 19ad4456dd6152754fe620948ff8486c42e8993b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 14 Dec 2023 13:18:44 +0100 Subject: [PATCH 13/15] Inline redundant variable --- models/star/src/lib.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/models/star/src/lib.rs b/models/star/src/lib.rs index 758210e38..936c7a3cf 100644 --- a/models/star/src/lib.rs +++ b/models/star/src/lib.rs @@ -46,15 +46,14 @@ pub fn model( let surface = services.objects.surfaces.xy_plane(); let path = Vector::from([0., 0., h]); - let sketch = Sketch::empty().add_region( - Region::polygon(outer_points, services) - .add_interiors([Cycle::polygon(inner_points, services) - .reverse(services) - .insert(services)]) - .insert(services), - ); - - sketch + Sketch::empty() + .add_region( + Region::polygon(outer_points, services) + .add_interiors([Cycle::polygon(inner_points, services) + .reverse(services) + .insert(services)]) + .insert(services), + ) .sweep_sketch(surface, path, services) .insert(services) } From ea9c5f1b834fea76d035fc25eb50e693f0d20977 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 14 Dec 2023 13:19:00 +0100 Subject: [PATCH 14/15] Rename variable to increase clarity --- models/star/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/star/src/lib.rs b/models/star/src/lib.rs index 936c7a3cf..1e74957aa 100644 --- a/models/star/src/lib.rs +++ b/models/star/src/lib.rs @@ -43,7 +43,7 @@ pub fn model( inner_points.push([x / 2., y / 2.]); } - let surface = services.objects.surfaces.xy_plane(); + let bottom_surface = services.objects.surfaces.xy_plane(); let path = Vector::from([0., 0., h]); Sketch::empty() @@ -54,6 +54,6 @@ pub fn model( .insert(services)]) .insert(services), ) - .sweep_sketch(surface, path, services) + .sweep_sketch(bottom_surface, path, services) .insert(services) } From 71054ea2275a8e77f94e9b225e8033bf575e02d5 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 14 Dec 2023 13:19:22 +0100 Subject: [PATCH 15/15] Rename variable to increase clarity --- models/star/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/star/src/lib.rs b/models/star/src/lib.rs index 1e74957aa..ca1ad15ab 100644 --- a/models/star/src/lib.rs +++ b/models/star/src/lib.rs @@ -44,7 +44,7 @@ pub fn model( } let bottom_surface = services.objects.surfaces.xy_plane(); - let path = Vector::from([0., 0., h]); + let sweep_path = Vector::from([0., 0., h]); Sketch::empty() .add_region( @@ -54,6 +54,6 @@ pub fn model( .insert(services)]) .insert(services), ) - .sweep_sketch(bottom_surface, path, services) + .sweep_sketch(bottom_surface, sweep_path, services) .insert(services) }