From 0ea99f87ee3da3c57e0feef250f44b3604d3df13 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 30 May 2023 13:08:21 +0200 Subject: [PATCH 1/2] Use `BuildCycle` to simplify `cuboid` --- models/cuboid/src/lib.rs | 41 ++++++++++++---------------------------- 1 file changed, 12 insertions(+), 29 deletions(-) diff --git a/models/cuboid/src/lib.rs b/models/cuboid/src/lib.rs index d0e6024ba..bdf2f3506 100644 --- a/models/cuboid/src/lib.rs +++ b/models/cuboid/src/lib.rs @@ -1,44 +1,27 @@ use fj_kernel::{ algorithms::sweep::Sweep, geometry::region::Region, - objects::{Cycle, HalfEdge, Sketch, Solid}, - operations::{BuildCycle, BuildHalfEdge, Insert, UpdateCycle}, + objects::{Cycle, Sketch, Solid}, + operations::{BuildCycle, Insert}, services::Services, storage::Handle, }; -use fj_math::{Point, Vector}; -use itertools::Itertools; +use fj_math::Vector; pub fn cuboid(x: f64, y: f64, z: f64) -> Handle { let mut services = Services::new(); let sketch = { - let exterior = { - #[rustfmt::skip] - let rectangle = [ + let exterior = Cycle::polygon( + [ [-x / 2., -y / 2.], - [ x / 2., -y / 2.], - [ x / 2., y / 2.], - [-x / 2., y / 2.], - ]; - - let mut cycle = Cycle::empty(); - - let segments = rectangle - .into_iter() - .map(Point::from) - .circular_tuple_windows(); - - for (start, end) in segments { - let half_edge = - HalfEdge::line_segment([start, end], None, &mut services) - .insert(&mut services); - - cycle = cycle.add_half_edges([half_edge]); - } - - cycle.insert(&mut services) - }; + [x / 2., -y / 2.], + [x / 2., y / 2.], + [-x / 2., y / 2.], + ], + &mut services, + ) + .insert(&mut services); let region = Region::new(exterior, Vec::new(), None); From 08f522a4028dc43320991335a977152193bc9386 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 30 May 2023 13:13:41 +0200 Subject: [PATCH 2/2] Simplify `cuboid` using `BuildSketch` --- models/cuboid/src/lib.rs | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/models/cuboid/src/lib.rs b/models/cuboid/src/lib.rs index bdf2f3506..5fbde0a80 100644 --- a/models/cuboid/src/lib.rs +++ b/models/cuboid/src/lib.rs @@ -1,8 +1,7 @@ use fj_kernel::{ algorithms::sweep::Sweep, - geometry::region::Region, - objects::{Cycle, Sketch, Solid}, - operations::{BuildCycle, Insert}, + objects::{Sketch, Solid}, + operations::{BuildSketch, Insert}, services::Services, storage::Handle, }; @@ -11,22 +10,16 @@ use fj_math::Vector; pub fn cuboid(x: f64, y: f64, z: f64) -> Handle { let mut services = Services::new(); - let sketch = { - let exterior = Cycle::polygon( - [ - [-x / 2., -y / 2.], - [x / 2., -y / 2.], - [x / 2., y / 2.], - [-x / 2., y / 2.], - ], - &mut services, - ) - .insert(&mut services); - - let region = Region::new(exterior, Vec::new(), None); - - Sketch::new([region]).insert(&mut services) - }; + let sketch = Sketch::polygon( + [ + [-x / 2., -y / 2.], + [x / 2., -y / 2.], + [x / 2., y / 2.], + [-x / 2., y / 2.], + ], + &mut services, + ) + .insert(&mut services); let surface = services.objects.surfaces.xy_plane();