From b591bfa369129b54858d9d8937cc337d6cb5dfb1 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 16 Nov 2023 12:33:39 +0100 Subject: [PATCH 01/20] Move `sweep` into `operations` --- crates/fj-core/src/algorithms/mod.rs | 1 - crates/fj-core/src/operations/mod.rs | 1 + crates/fj-core/src/{algorithms => operations}/sweep/edge.rs | 0 crates/fj-core/src/{algorithms => operations}/sweep/face.rs | 0 crates/fj-core/src/{algorithms => operations}/sweep/mod.rs | 0 crates/fj-core/src/{algorithms => operations}/sweep/path.rs | 0 crates/fj-core/src/{algorithms => operations}/sweep/sketch.rs | 0 crates/fj-core/src/{algorithms => operations}/sweep/vertex.rs | 0 models/cuboid/src/lib.rs | 2 +- models/spacer/src/lib.rs | 2 +- models/split/src/lib.rs | 2 +- models/star/src/lib.rs | 2 +- 12 files changed, 5 insertions(+), 5 deletions(-) rename crates/fj-core/src/{algorithms => operations}/sweep/edge.rs (100%) rename crates/fj-core/src/{algorithms => operations}/sweep/face.rs (100%) rename crates/fj-core/src/{algorithms => operations}/sweep/mod.rs (100%) rename crates/fj-core/src/{algorithms => operations}/sweep/path.rs (100%) rename crates/fj-core/src/{algorithms => operations}/sweep/sketch.rs (100%) rename crates/fj-core/src/{algorithms => operations}/sweep/vertex.rs (100%) diff --git a/crates/fj-core/src/algorithms/mod.rs b/crates/fj-core/src/algorithms/mod.rs index 4c5f9ad38..6665e8ba5 100644 --- a/crates/fj-core/src/algorithms/mod.rs +++ b/crates/fj-core/src/algorithms/mod.rs @@ -13,6 +13,5 @@ pub mod approx; pub mod bounding_volume; pub mod intersect; -pub mod sweep; pub mod transform; pub mod triangulate; diff --git a/crates/fj-core/src/operations/mod.rs b/crates/fj-core/src/operations/mod.rs index ea218d6dd..405884c50 100644 --- a/crates/fj-core/src/operations/mod.rs +++ b/crates/fj-core/src/operations/mod.rs @@ -45,4 +45,5 @@ pub mod merge; pub mod replace; pub mod reverse; pub mod split; +pub mod sweep; pub mod update; diff --git a/crates/fj-core/src/algorithms/sweep/edge.rs b/crates/fj-core/src/operations/sweep/edge.rs similarity index 100% rename from crates/fj-core/src/algorithms/sweep/edge.rs rename to crates/fj-core/src/operations/sweep/edge.rs diff --git a/crates/fj-core/src/algorithms/sweep/face.rs b/crates/fj-core/src/operations/sweep/face.rs similarity index 100% rename from crates/fj-core/src/algorithms/sweep/face.rs rename to crates/fj-core/src/operations/sweep/face.rs diff --git a/crates/fj-core/src/algorithms/sweep/mod.rs b/crates/fj-core/src/operations/sweep/mod.rs similarity index 100% rename from crates/fj-core/src/algorithms/sweep/mod.rs rename to crates/fj-core/src/operations/sweep/mod.rs diff --git a/crates/fj-core/src/algorithms/sweep/path.rs b/crates/fj-core/src/operations/sweep/path.rs similarity index 100% rename from crates/fj-core/src/algorithms/sweep/path.rs rename to crates/fj-core/src/operations/sweep/path.rs diff --git a/crates/fj-core/src/algorithms/sweep/sketch.rs b/crates/fj-core/src/operations/sweep/sketch.rs similarity index 100% rename from crates/fj-core/src/algorithms/sweep/sketch.rs rename to crates/fj-core/src/operations/sweep/sketch.rs diff --git a/crates/fj-core/src/algorithms/sweep/vertex.rs b/crates/fj-core/src/operations/sweep/vertex.rs similarity index 100% rename from crates/fj-core/src/algorithms/sweep/vertex.rs rename to crates/fj-core/src/operations/sweep/vertex.rs diff --git a/models/cuboid/src/lib.rs b/models/cuboid/src/lib.rs index 8588c2b22..8f0497ee3 100644 --- a/models/cuboid/src/lib.rs +++ b/models/cuboid/src/lib.rs @@ -1,10 +1,10 @@ use fj::{ core::{ - algorithms::sweep::Sweep, objects::{Region, Sketch, Solid}, operations::{ build::{BuildRegion, BuildSketch}, insert::Insert, + sweep::Sweep, update::UpdateSketch, }, services::Services, diff --git a/models/spacer/src/lib.rs b/models/spacer/src/lib.rs index 253a2fc64..1ff668589 100644 --- a/models/spacer/src/lib.rs +++ b/models/spacer/src/lib.rs @@ -1,11 +1,11 @@ use fj::{ core::{ - algorithms::sweep::Sweep, objects::{Cycle, Region, Sketch, Solid}, operations::{ build::{BuildCycle, BuildRegion, BuildSketch}, insert::Insert, reverse::Reverse, + sweep::Sweep, update::{UpdateRegion, UpdateSketch}, }, services::Services, diff --git a/models/split/src/lib.rs b/models/split/src/lib.rs index f3d7c19ad..b3e6397c6 100644 --- a/models/split/src/lib.rs +++ b/models/split/src/lib.rs @@ -1,11 +1,11 @@ use fj::{ core::{ - algorithms::sweep::Sweep, objects::{Region, Sketch, Solid}, operations::{ build::{BuildRegion, BuildSketch}, insert::Insert, split::SplitFace, + sweep::Sweep, update::{UpdateSketch, UpdateSolid}, }, services::Services, diff --git a/models/star/src/lib.rs b/models/star/src/lib.rs index c6ce938c0..1831dd5d9 100644 --- a/models/star/src/lib.rs +++ b/models/star/src/lib.rs @@ -2,12 +2,12 @@ use std::f64::consts::PI; use fj::{ core::{ - algorithms::sweep::Sweep, objects::{Cycle, Region, Sketch, Solid}, operations::{ build::{BuildCycle, BuildRegion, BuildSketch}, insert::Insert, reverse::Reverse, + sweep::Sweep, update::{UpdateRegion, UpdateSketch}, }, services::Services, From 5ee6e39e44d1c740094c74bc78a8a81bf5c7b5f2 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 20 Nov 2023 12:13:49 +0100 Subject: [PATCH 02/20] Simplify return value of `Sweep` impl for `Vertex` Not all of the return value is actually being used. --- crates/fj-core/src/operations/sweep/edge.rs | 4 ++-- crates/fj-core/src/operations/sweep/vertex.rs | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/crates/fj-core/src/operations/sweep/edge.rs b/crates/fj-core/src/operations/sweep/edge.rs index fe227d26a..afd07d352 100644 --- a/crates/fj-core/src/operations/sweep/edge.rs +++ b/crates/fj-core/src/operations/sweep/edge.rs @@ -33,9 +33,9 @@ impl Sweep for (&HalfEdge, &Handle, &Surface, Option) { // the global vertices and edges. let (vertices, curves) = { let [a, b] = [edge.start_vertex(), next_vertex].map(Clone::clone); - let (curve_up, [_, c]) = + let (curve_up, c) = b.clone().sweep_with_cache(path, cache, services); - let (curve_down, [_, d]) = + let (curve_down, d) = a.clone().sweep_with_cache(path, cache, services); ( diff --git a/crates/fj-core/src/operations/sweep/vertex.rs b/crates/fj-core/src/operations/sweep/vertex.rs index 603583ffe..9dd9318e3 100644 --- a/crates/fj-core/src/operations/sweep/vertex.rs +++ b/crates/fj-core/src/operations/sweep/vertex.rs @@ -10,7 +10,7 @@ use crate::{ use super::{Sweep, SweepCache}; impl Sweep for Handle { - type Swept = (Handle, [Self; 2]); + type Swept = (Handle, Self); fn sweep_with_cache( self, @@ -24,14 +24,12 @@ impl Sweep for Handle { .or_insert_with(|| Curve::new().insert(services)) .clone(); - let a = self.clone(); let b = cache .vertices .entry(self.id()) .or_insert_with(|| Vertex::new().insert(services)) .clone(); - let vertices = [a, b]; - (curve, vertices) + (curve, b) } } From e9f6183cc58ad19790b50a02668c4dff1cc6b2b6 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 20 Nov 2023 12:14:34 +0100 Subject: [PATCH 03/20] Update variable name --- crates/fj-core/src/operations/sweep/vertex.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-core/src/operations/sweep/vertex.rs b/crates/fj-core/src/operations/sweep/vertex.rs index 9dd9318e3..f998d5907 100644 --- a/crates/fj-core/src/operations/sweep/vertex.rs +++ b/crates/fj-core/src/operations/sweep/vertex.rs @@ -24,12 +24,12 @@ impl Sweep for Handle { .or_insert_with(|| Curve::new().insert(services)) .clone(); - let b = cache + let vertex = cache .vertices .entry(self.id()) .or_insert_with(|| Vertex::new().insert(services)) .clone(); - (curve, b) + (curve, vertex) } } From 54035848e87288de0bfa68ef18f40569bf5bab2c Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 20 Nov 2023 12:19:48 +0100 Subject: [PATCH 04/20] Update module name --- crates/fj-core/src/operations/sweep/{edge.rs => half_edge.rs} | 0 crates/fj-core/src/operations/sweep/mod.rs | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename crates/fj-core/src/operations/sweep/{edge.rs => half_edge.rs} (100%) diff --git a/crates/fj-core/src/operations/sweep/edge.rs b/crates/fj-core/src/operations/sweep/half_edge.rs similarity index 100% rename from crates/fj-core/src/operations/sweep/edge.rs rename to crates/fj-core/src/operations/sweep/half_edge.rs diff --git a/crates/fj-core/src/operations/sweep/mod.rs b/crates/fj-core/src/operations/sweep/mod.rs index 04d808895..434379648 100644 --- a/crates/fj-core/src/operations/sweep/mod.rs +++ b/crates/fj-core/src/operations/sweep/mod.rs @@ -1,7 +1,7 @@ //! Sweeping objects along a path to create new objects -mod edge; mod face; +mod half_edge; mod path; mod sketch; mod vertex; From 32979f99df1733d51eae24519b2295e614df05ab Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 20 Nov 2023 12:54:08 +0100 Subject: [PATCH 05/20] Simplify return value of `SurfacePath` sweep fn --- crates/fj-core/src/operations/sweep/half_edge.rs | 5 +++-- crates/fj-core/src/operations/sweep/path.rs | 8 +++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/crates/fj-core/src/operations/sweep/half_edge.rs b/crates/fj-core/src/operations/sweep/half_edge.rs index afd07d352..f57101435 100644 --- a/crates/fj-core/src/operations/sweep/half_edge.rs +++ b/crates/fj-core/src/operations/sweep/half_edge.rs @@ -26,8 +26,9 @@ impl Sweep for (&HalfEdge, &Handle, &Surface, Option) { let (edge, next_vertex, surface, color) = self; let path = path.into(); - let surface = - (edge.path(), surface).sweep_with_cache(path, cache, services); + let surface = (edge.path(), surface) + .sweep_with_cache(path, cache, services) + .insert(services); // Next, we need to define the boundaries of the face. Let's start with // the global vertices and edges. diff --git a/crates/fj-core/src/operations/sweep/path.rs b/crates/fj-core/src/operations/sweep/path.rs index 2e1fc85e3..cb5caab04 100644 --- a/crates/fj-core/src/operations/sweep/path.rs +++ b/crates/fj-core/src/operations/sweep/path.rs @@ -3,21 +3,19 @@ use fj_math::{Circle, Line, Vector}; use crate::{ geometry::{GlobalPath, SurfaceGeometry, SurfacePath}, objects::Surface, - operations::insert::Insert, services::Services, - storage::Handle, }; use super::{Sweep, SweepCache}; impl Sweep for (SurfacePath, &Surface) { - type Swept = Handle; + type Swept = Surface; fn sweep_with_cache( self, path: impl Into>, _: &mut SweepCache, - services: &mut Services, + _: &mut Services, ) -> Self::Swept { let (curve, surface) = self; @@ -72,6 +70,6 @@ impl Sweep for (SurfacePath, &Surface) { } }; - Surface::new(SurfaceGeometry { u, v: path.into() }).insert(services) + Surface::new(SurfaceGeometry { u, v: path.into() }) } } From 00ee95b5eae09c81452947382595d9e7677cbce4 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 20 Nov 2023 13:14:36 +0100 Subject: [PATCH 06/20] Remove redundant comment --- crates/fj-core/src/operations/sweep/half_edge.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/fj-core/src/operations/sweep/half_edge.rs b/crates/fj-core/src/operations/sweep/half_edge.rs index f57101435..664489658 100644 --- a/crates/fj-core/src/operations/sweep/half_edge.rs +++ b/crates/fj-core/src/operations/sweep/half_edge.rs @@ -114,8 +114,6 @@ impl Sweep for (&HalfEdge, &Handle, &Surface, Option) { let face = Face::new(surface, region); - // And we're done creating the face! All that's left to do is build our - // return values. let face = face.insert(services); (face, edge_top) } From 27c0cd1038036fd6fb7688e0b32cf883a8445276 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 20 Nov 2023 13:16:08 +0100 Subject: [PATCH 07/20] Simplify return value of half-edge sweep operation --- crates/fj-core/src/operations/sweep/face.rs | 2 ++ crates/fj-core/src/operations/sweep/half_edge.rs | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/fj-core/src/operations/sweep/face.rs b/crates/fj-core/src/operations/sweep/face.rs index a08a5cb2c..b37eefc6d 100644 --- a/crates/fj-core/src/operations/sweep/face.rs +++ b/crates/fj-core/src/operations/sweep/face.rs @@ -71,6 +71,8 @@ impl Sweep for Handle { ) .sweep_with_cache(path, cache, services); + let side_face = side_face.insert(services); + faces.push(side_face); top_edges.push(( diff --git a/crates/fj-core/src/operations/sweep/half_edge.rs b/crates/fj-core/src/operations/sweep/half_edge.rs index 664489658..7e77b7146 100644 --- a/crates/fj-core/src/operations/sweep/half_edge.rs +++ b/crates/fj-core/src/operations/sweep/half_edge.rs @@ -15,7 +15,7 @@ use crate::{ use super::{Sweep, SweepCache}; impl Sweep for (&HalfEdge, &Handle, &Surface, Option) { - type Swept = (Handle, Handle); + type Swept = (Face, Handle); fn sweep_with_cache( self, @@ -114,7 +114,6 @@ impl Sweep for (&HalfEdge, &Handle, &Surface, Option) { let face = Face::new(surface, region); - let face = face.insert(services); (face, edge_top) } } From 7b68c532617d1dd48f41b075d5da751452c2e3cc Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 20 Nov 2023 13:18:31 +0100 Subject: [PATCH 08/20] Refactor to improve clarity --- crates/fj-core/src/operations/sweep/half_edge.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-core/src/operations/sweep/half_edge.rs b/crates/fj-core/src/operations/sweep/half_edge.rs index 7e77b7146..5fae57c34 100644 --- a/crates/fj-core/src/operations/sweep/half_edge.rs +++ b/crates/fj-core/src/operations/sweep/half_edge.rs @@ -4,7 +4,7 @@ use fj_math::{Point, Scalar, Vector}; use crate::{ objects::{Cycle, Face, HalfEdge, Region, Surface, Vertex}, operations::{ - build::BuildHalfEdge, + build::{BuildCycle, BuildHalfEdge}, insert::Insert, update::{UpdateCycle, UpdateHalfEdge}, }, @@ -76,7 +76,7 @@ impl Sweep for (&HalfEdge, &Handle, &Surface, Option) { [[a, b], [c, d], [b, a], [d, c]] }; - let mut exterior = Some(Cycle::new([])); + let mut exterior = Some(Cycle::empty()); // Armed with all of that, we're ready to create the edges. let [_edge_bottom, _edge_up, edge_top, _edge_down] = boundaries From 624ee08cc64214efb54047f94d67c02d67b0bebc Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 20 Nov 2023 13:19:23 +0100 Subject: [PATCH 09/20] Refactor to remove `unwrap`s --- crates/fj-core/src/operations/sweep/half_edge.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/crates/fj-core/src/operations/sweep/half_edge.rs b/crates/fj-core/src/operations/sweep/half_edge.rs index 5fae57c34..224f8e62f 100644 --- a/crates/fj-core/src/operations/sweep/half_edge.rs +++ b/crates/fj-core/src/operations/sweep/half_edge.rs @@ -76,7 +76,7 @@ impl Sweep for (&HalfEdge, &Handle, &Surface, Option) { [[a, b], [c, d], [b, a], [d, c]] }; - let mut exterior = Some(Cycle::empty()); + let mut exterior = Cycle::empty(); // Armed with all of that, we're ready to create the edges. let [_edge_bottom, _edge_up, edge_top, _edge_down] = boundaries @@ -102,15 +102,13 @@ impl Sweep for (&HalfEdge, &Handle, &Surface, Option) { edge.insert(services) }; - exterior = Some( - exterior.take().unwrap().add_half_edges([edge.clone()]), - ); + exterior = exterior.add_half_edges([edge.clone()]); edge }); - let region = Region::new(exterior.unwrap().insert(services), [], color) - .insert(services); + let region = + Region::new(exterior.insert(services), [], color).insert(services); let face = Face::new(surface, region); From 4341e8ad001d0ce9c1730822a22bacc4fb22fe0f Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 20 Nov 2023 13:30:40 +0100 Subject: [PATCH 10/20] Refactor to remove implicit `clone` --- crates/fj-core/src/operations/sweep/face.rs | 2 +- crates/fj-core/src/operations/sweep/half_edge.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/fj-core/src/operations/sweep/face.rs b/crates/fj-core/src/operations/sweep/face.rs index b37eefc6d..f80aacf90 100644 --- a/crates/fj-core/src/operations/sweep/face.rs +++ b/crates/fj-core/src/operations/sweep/face.rs @@ -65,7 +65,7 @@ impl Sweep for Handle { let (side_face, top_edge) = ( bottom_half_edge.deref(), - bottom_half_edge_next.start_vertex(), + bottom_half_edge_next.start_vertex().clone(), bottom_face.surface().deref(), bottom_face.region().color(), ) diff --git a/crates/fj-core/src/operations/sweep/half_edge.rs b/crates/fj-core/src/operations/sweep/half_edge.rs index 224f8e62f..72ee6d218 100644 --- a/crates/fj-core/src/operations/sweep/half_edge.rs +++ b/crates/fj-core/src/operations/sweep/half_edge.rs @@ -14,7 +14,7 @@ use crate::{ use super::{Sweep, SweepCache}; -impl Sweep for (&HalfEdge, &Handle, &Surface, Option) { +impl Sweep for (&HalfEdge, Handle, &Surface, Option) { type Swept = (Face, Handle); fn sweep_with_cache( @@ -33,7 +33,7 @@ impl Sweep for (&HalfEdge, &Handle, &Surface, Option) { // Next, we need to define the boundaries of the face. Let's start with // the global vertices and edges. let (vertices, curves) = { - let [a, b] = [edge.start_vertex(), next_vertex].map(Clone::clone); + let [a, b] = [edge.start_vertex().clone(), next_vertex]; let (curve_up, c) = b.clone().sweep_with_cache(path, cache, services); let (curve_down, d) = From 6226937d3784036069ba3021c91bd292eeedebf6 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 20 Nov 2023 13:33:00 +0100 Subject: [PATCH 11/20] Simplify formatting --- crates/fj-core/src/operations/sweep/half_edge.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/fj-core/src/operations/sweep/half_edge.rs b/crates/fj-core/src/operations/sweep/half_edge.rs index 72ee6d218..8ca1c19fe 100644 --- a/crates/fj-core/src/operations/sweep/half_edge.rs +++ b/crates/fj-core/src/operations/sweep/half_edge.rs @@ -109,7 +109,6 @@ impl Sweep for (&HalfEdge, Handle, &Surface, Option) { let region = Region::new(exterior.insert(services), [], color).insert(services); - let face = Face::new(surface, region); (face, edge_top) From a46311db3d7beffd345c36e8ee67e1cd0d22d558 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 20 Nov 2023 13:36:19 +0100 Subject: [PATCH 12/20] Refactor to improve clarity --- crates/fj-core/src/operations/sweep/half_edge.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-core/src/operations/sweep/half_edge.rs b/crates/fj-core/src/operations/sweep/half_edge.rs index 8ca1c19fe..77c5e3607 100644 --- a/crates/fj-core/src/operations/sweep/half_edge.rs +++ b/crates/fj-core/src/operations/sweep/half_edge.rs @@ -107,8 +107,8 @@ impl Sweep for (&HalfEdge, Handle, &Surface, Option) { edge }); - let region = - Region::new(exterior.insert(services), [], color).insert(services); + let exterior = exterior.insert(services); + let region = Region::new(exterior, [], color).insert(services); let face = Face::new(surface, region); (face, edge_top) From 9490899afc47cc6ef15963904614bfdd77819001 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 20 Nov 2023 13:48:52 +0100 Subject: [PATCH 13/20] Make variable name more clear --- crates/fj-core/src/operations/sweep/half_edge.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-core/src/operations/sweep/half_edge.rs b/crates/fj-core/src/operations/sweep/half_edge.rs index 77c5e3607..81c92b83d 100644 --- a/crates/fj-core/src/operations/sweep/half_edge.rs +++ b/crates/fj-core/src/operations/sweep/half_edge.rs @@ -23,7 +23,7 @@ impl Sweep for (&HalfEdge, Handle, &Surface, Option) { cache: &mut SweepCache, services: &mut Services, ) -> Self::Swept { - let (edge, next_vertex, surface, color) = self; + let (edge, end_vertex, surface, color) = self; let path = path.into(); let surface = (edge.path(), surface) @@ -33,7 +33,7 @@ impl Sweep for (&HalfEdge, Handle, &Surface, Option) { // Next, we need to define the boundaries of the face. Let's start with // the global vertices and edges. let (vertices, curves) = { - let [a, b] = [edge.start_vertex().clone(), next_vertex]; + let [a, b] = [edge.start_vertex().clone(), end_vertex]; let (curve_up, c) = b.clone().sweep_with_cache(path, cache, services); let (curve_down, d) = From 98214ffcfabc852a7971ab39cef0d4a9fca41b70 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 20 Nov 2023 13:56:08 +0100 Subject: [PATCH 14/20] Fix wording in panic message --- crates/fj-core/src/operations/sweep/face.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/fj-core/src/operations/sweep/face.rs b/crates/fj-core/src/operations/sweep/face.rs index f80aacf90..87b858ee7 100644 --- a/crates/fj-core/src/operations/sweep/face.rs +++ b/crates/fj-core/src/operations/sweep/face.rs @@ -115,7 +115,7 @@ fn bottom_face( let is_negative_sweep = { let u = match face.surface().geometry().u { GlobalPath::Circle(_) => todo!( - "Sweeping from faces defined in round surfaces is not \ + "Sweeping from faces defined in rounded surfaces is not \ supported" ), GlobalPath::Line(line) => line.direction(), From fa6d3b090cf932a0039ea4fb9dfad953f39822bf Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 20 Nov 2023 13:57:53 +0100 Subject: [PATCH 15/20] Simplify function signature --- crates/fj-core/src/operations/sweep/face.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/crates/fj-core/src/operations/sweep/face.rs b/crates/fj-core/src/operations/sweep/face.rs index 87b858ee7..f4efd359a 100644 --- a/crates/fj-core/src/operations/sweep/face.rs +++ b/crates/fj-core/src/operations/sweep/face.rs @@ -41,7 +41,7 @@ impl Sweep for Handle { let mut faces = Vec::new(); - let bottom_face = bottom_face(self, path, services); + let bottom_face = bottom_face(&self, path, services).insert(services); faces.push(bottom_face.clone()); let top_surface = @@ -107,11 +107,7 @@ impl Sweep for Handle { } } -fn bottom_face( - face: Handle, - path: Vector<3>, - services: &mut Services, -) -> Handle { +fn bottom_face(face: &Face, path: Vector<3>, services: &mut Services) -> Face { let is_negative_sweep = { let u = match face.surface().geometry().u { GlobalPath::Circle(_) => todo!( @@ -128,8 +124,8 @@ fn bottom_face( }; if is_negative_sweep { - face + face.clone() } else { - face.reverse(services).insert(services) + face.reverse(services) } } From f95c09b6a0fbf06ad34d5804b42137ad602a816f Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 20 Nov 2023 13:59:48 +0100 Subject: [PATCH 16/20] Simplify requirement of `Face`'s `Sweep` impl --- crates/fj-core/src/operations/sweep/face.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-core/src/operations/sweep/face.rs b/crates/fj-core/src/operations/sweep/face.rs index f4efd359a..a10a10144 100644 --- a/crates/fj-core/src/operations/sweep/face.rs +++ b/crates/fj-core/src/operations/sweep/face.rs @@ -15,7 +15,7 @@ use crate::{ use super::{Sweep, SweepCache}; -impl Sweep for Handle { +impl Sweep for &Face { type Swept = Handle; fn sweep_with_cache( @@ -41,7 +41,7 @@ impl Sweep for Handle { let mut faces = Vec::new(); - let bottom_face = bottom_face(&self, path, services).insert(services); + let bottom_face = bottom_face(self, path, services).insert(services); faces.push(bottom_face.clone()); let top_surface = From fa9b7829cd2c6ed88f88200b091f8fde4e4d131b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 20 Nov 2023 14:01:59 +0100 Subject: [PATCH 17/20] Simplify result of `Face` sweep implementation --- crates/fj-core/src/operations/sweep/face.rs | 5 ++--- crates/fj-core/src/operations/sweep/sketch.rs | 4 +++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/fj-core/src/operations/sweep/face.rs b/crates/fj-core/src/operations/sweep/face.rs index a10a10144..46ac6f3c3 100644 --- a/crates/fj-core/src/operations/sweep/face.rs +++ b/crates/fj-core/src/operations/sweep/face.rs @@ -10,13 +10,12 @@ use crate::{ build::BuildCycle, insert::Insert, join::JoinCycle, reverse::Reverse, }, services::Services, - storage::Handle, }; use super::{Sweep, SweepCache}; impl Sweep for &Face { - type Swept = Handle; + type Swept = Shell; fn sweep_with_cache( self, @@ -103,7 +102,7 @@ impl Sweep for &Face { let top_face = Face::new(top_surface, top_region).insert(services); faces.push(top_face); - Shell::new(faces).insert(services) + Shell::new(faces) } } diff --git a/crates/fj-core/src/operations/sweep/sketch.rs b/crates/fj-core/src/operations/sweep/sketch.rs index bf0e555b3..1643c5f26 100644 --- a/crates/fj-core/src/operations/sweep/sketch.rs +++ b/crates/fj-core/src/operations/sweep/sketch.rs @@ -25,7 +25,9 @@ impl Sweep for (Handle, Handle) { for region in sketch.regions() { let face = Face::new(surface.clone(), region.clone()).insert(services); - let shell = face.sweep_with_cache(path, cache, services); + let shell = face + .sweep_with_cache(path, cache, services) + .insert(services); shells.push(shell); } From 5ff9bc0056a5c8fc757b56ce3c0d4981185c78e0 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 20 Nov 2023 14:05:29 +0100 Subject: [PATCH 18/20] Simplify requirements of `Sketch`'s `Sweep` impl --- crates/fj-core/src/operations/sweep/sketch.rs | 2 +- models/cuboid/src/lib.rs | 4 +++- models/spacer/src/lib.rs | 4 +++- models/split/src/lib.rs | 4 +++- models/star/src/lib.rs | 4 ++-- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/crates/fj-core/src/operations/sweep/sketch.rs b/crates/fj-core/src/operations/sweep/sketch.rs index 1643c5f26..8a0f81079 100644 --- a/crates/fj-core/src/operations/sweep/sketch.rs +++ b/crates/fj-core/src/operations/sweep/sketch.rs @@ -9,7 +9,7 @@ use crate::{ use super::{Sweep, SweepCache}; -impl Sweep for (Handle, Handle) { +impl Sweep for (&Sketch, Handle) { type Swept = Handle; fn sweep_with_cache( diff --git a/models/cuboid/src/lib.rs b/models/cuboid/src/lib.rs index 8f0497ee3..87ecd7de0 100644 --- a/models/cuboid/src/lib.rs +++ b/models/cuboid/src/lib.rs @@ -1,3 +1,5 @@ +use std::ops::Deref; + use fj::{ core::{ objects::{Region, Sketch, Solid}, @@ -31,5 +33,5 @@ pub fn model(x: f64, y: f64, z: f64, services: &mut Services) -> Handle { let surface = services.objects.surfaces.xy_plane(); let path = Vector::from([0., 0., z]); - (sketch, surface).sweep(path, services) + (sketch.deref(), surface).sweep(path, services) } diff --git a/models/spacer/src/lib.rs b/models/spacer/src/lib.rs index 1ff668589..879d6aab4 100644 --- a/models/spacer/src/lib.rs +++ b/models/spacer/src/lib.rs @@ -1,3 +1,5 @@ +use std::ops::Deref; + use fj::{ core::{ objects::{Cycle, Region, Sketch, Solid}, @@ -36,5 +38,5 @@ pub fn model( let surface = services.objects.surfaces.xy_plane(); let path = Vector::from([0., 0., height]); - (sketch, surface).sweep(path, services) + (sketch.deref(), surface).sweep(path, services) } diff --git a/models/split/src/lib.rs b/models/split/src/lib.rs index b3e6397c6..75224ce5d 100644 --- a/models/split/src/lib.rs +++ b/models/split/src/lib.rs @@ -1,3 +1,5 @@ +use std::ops::Deref; + use fj::{ core::{ objects::{Region, Sketch, Solid}, @@ -36,7 +38,7 @@ pub fn model( let surface = services.objects.surfaces.xy_plane(); let path = Vector::from([0., 0., size]); - let solid = (sketch, surface).sweep(path, services); + let solid = (sketch.deref(), surface).sweep(path, services); solid .update_shell(solid.shells().only(), |shell| { diff --git a/models/star/src/lib.rs b/models/star/src/lib.rs index 1831dd5d9..42144f1f3 100644 --- a/models/star/src/lib.rs +++ b/models/star/src/lib.rs @@ -1,4 +1,4 @@ -use std::f64::consts::PI; +use std::{f64::consts::PI, ops::Deref}; use fj::{ core::{ @@ -55,5 +55,5 @@ pub fn model( let surface = services.objects.surfaces.xy_plane(); let path = Vector::from([0., 0., h]); - (sketch, surface).sweep(path, services) + (sketch.deref(), surface).sweep(path, services) } From ce10c4c480c117782bd86b3f8e5dab0b82177a47 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 20 Nov 2023 14:06:54 +0100 Subject: [PATCH 19/20] Simplify code of models --- models/cuboid/src/lib.rs | 28 ++++++++++++---------------- models/spacer/src/lib.rs | 20 ++++++-------------- models/split/src/lib.rs | 28 ++++++++++++---------------- models/star/src/lib.rs | 20 +++++++++----------- 4 files changed, 39 insertions(+), 57 deletions(-) diff --git a/models/cuboid/src/lib.rs b/models/cuboid/src/lib.rs index 87ecd7de0..efec47353 100644 --- a/models/cuboid/src/lib.rs +++ b/models/cuboid/src/lib.rs @@ -1,5 +1,3 @@ -use std::ops::Deref; - use fj::{ core::{ objects::{Region, Sketch, Solid}, @@ -16,22 +14,20 @@ use fj::{ }; pub fn model(x: f64, y: f64, z: f64, services: &mut Services) -> Handle { - 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, - ) - .insert(services), + 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, ) - .insert(services); + .insert(services), + ); let surface = services.objects.surfaces.xy_plane(); let path = Vector::from([0., 0., z]); - (sketch.deref(), surface).sweep(path, services) + (&sketch, surface).sweep(path, services) } diff --git a/models/spacer/src/lib.rs b/models/spacer/src/lib.rs index 879d6aab4..dae6b2193 100644 --- a/models/spacer/src/lib.rs +++ b/models/spacer/src/lib.rs @@ -1,5 +1,3 @@ -use std::ops::Deref; - use fj::{ core::{ objects::{Cycle, Region, Sketch, Solid}, @@ -22,21 +20,15 @@ pub fn model( height: f64, services: &mut Services, ) -> Handle { - let sketch = Sketch::empty() - .add_region( - Region::circle(Point::origin(), outer, services) - .add_interiors([Cycle::circle( - Point::origin(), - inner, - services, - ) + let sketch = Sketch::empty().add_region( + Region::circle(Point::origin(), outer, services) + .add_interiors([Cycle::circle(Point::origin(), inner, services) .reverse(services) .insert(services)]) - .insert(services), - ) - .insert(services); + .insert(services), + ); let surface = services.objects.surfaces.xy_plane(); let path = Vector::from([0., 0., height]); - (sketch.deref(), surface).sweep(path, services) + (&sketch, surface).sweep(path, services) } diff --git a/models/split/src/lib.rs b/models/split/src/lib.rs index 75224ce5d..3cbdaec53 100644 --- a/models/split/src/lib.rs +++ b/models/split/src/lib.rs @@ -1,5 +1,3 @@ -use std::ops::Deref; - use fj::{ core::{ objects::{Region, Sketch, Solid}, @@ -21,24 +19,22 @@ 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 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); + .insert(services), + ); let surface = services.objects.surfaces.xy_plane(); let path = Vector::from([0., 0., size]); - let solid = (sketch.deref(), surface).sweep(path, services); + let solid = (&sketch, surface).sweep(path, services); solid .update_shell(solid.shells().only(), |shell| { diff --git a/models/star/src/lib.rs b/models/star/src/lib.rs index 42144f1f3..80720d9f7 100644 --- a/models/star/src/lib.rs +++ b/models/star/src/lib.rs @@ -1,4 +1,4 @@ -use std::{f64::consts::PI, ops::Deref}; +use std::f64::consts::PI; use fj::{ core::{ @@ -43,17 +43,15 @@ pub fn model( inner_points.push([x / 2., y / 2.]); } - let sketch = Sketch::empty() - .add_region( - Region::polygon(outer_points, services) - .add_interiors([Cycle::polygon(inner_points, services) - .reverse(services) - .insert(services)]) - .insert(services), - ) - .insert(services); + let sketch = Sketch::empty().add_region( + Region::polygon(outer_points, services) + .add_interiors([Cycle::polygon(inner_points, services) + .reverse(services) + .insert(services)]) + .insert(services), + ); let surface = services.objects.surfaces.xy_plane(); let path = Vector::from([0., 0., h]); - (sketch.deref(), surface).sweep(path, services) + (&sketch, surface).sweep(path, services) } From e2df07364520ab7f967c0daf148e795894945ce5 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 20 Nov 2023 14:08:36 +0100 Subject: [PATCH 20/20] Simplify result of `Sketch`'s `Sweep` impl --- crates/fj-core/src/operations/sweep/sketch.rs | 4 ++-- models/cuboid/src/lib.rs | 2 +- models/spacer/src/lib.rs | 2 +- models/star/src/lib.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/fj-core/src/operations/sweep/sketch.rs b/crates/fj-core/src/operations/sweep/sketch.rs index 8a0f81079..f5cde015d 100644 --- a/crates/fj-core/src/operations/sweep/sketch.rs +++ b/crates/fj-core/src/operations/sweep/sketch.rs @@ -10,7 +10,7 @@ use crate::{ use super::{Sweep, SweepCache}; impl Sweep for (&Sketch, Handle) { - type Swept = Handle; + type Swept = Solid; fn sweep_with_cache( self, @@ -31,6 +31,6 @@ impl Sweep for (&Sketch, Handle) { shells.push(shell); } - Solid::new(shells).insert(services) + Solid::new(shells) } } diff --git a/models/cuboid/src/lib.rs b/models/cuboid/src/lib.rs index efec47353..2f6dcf305 100644 --- a/models/cuboid/src/lib.rs +++ b/models/cuboid/src/lib.rs @@ -29,5 +29,5 @@ pub fn model(x: f64, y: f64, z: f64, services: &mut Services) -> Handle { let surface = services.objects.surfaces.xy_plane(); let path = Vector::from([0., 0., z]); - (&sketch, surface).sweep(path, services) + (&sketch, surface).sweep(path, services).insert(services) } diff --git a/models/spacer/src/lib.rs b/models/spacer/src/lib.rs index dae6b2193..586bf0c4b 100644 --- a/models/spacer/src/lib.rs +++ b/models/spacer/src/lib.rs @@ -30,5 +30,5 @@ pub fn model( let surface = services.objects.surfaces.xy_plane(); let path = Vector::from([0., 0., height]); - (&sketch, surface).sweep(path, services) + (&sketch, surface).sweep(path, services).insert(services) } diff --git a/models/star/src/lib.rs b/models/star/src/lib.rs index 80720d9f7..b46e7b862 100644 --- a/models/star/src/lib.rs +++ b/models/star/src/lib.rs @@ -53,5 +53,5 @@ pub fn model( let surface = services.objects.surfaces.xy_plane(); let path = Vector::from([0., 0., h]); - (&sketch, surface).sweep(path, services) + (&sketch, surface).sweep(path, services).insert(services) }