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/cuboid/src/lib.rs b/models/cuboid/src/lib.rs index 8faba1bbe..d7b9aaf5e 100644 --- a/models/cuboid/src/lib.rs +++ b/models/cuboid/src/lib.rs @@ -19,22 +19,22 @@ pub fn model( ) -> Handle { let [x, y, z] = size.into().components; - 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 bottom_surface = services.objects.surfaces.xy_plane(); + let sweep_path = Vector::from([Scalar::ZERO, Scalar::ZERO, z]); - let surface = services.objects.surfaces.xy_plane(); - let path = Vector::from([Scalar::ZERO, Scalar::ZERO, z]); - sketch - .sweep_sketch(surface, path, 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), + ) + .sweep_sketch(bottom_surface, sweep_path, services) .insert(services) } 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.; diff --git a/models/spacer/src/lib.rs b/models/spacer/src/lib.rs index b45af3891..8c7bd9684 100644 --- a/models/spacer/src/lib.rs +++ b/models/spacer/src/lib.rs @@ -20,17 +20,21 @@ 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 bottom_surface = services.objects.surfaces.xy_plane(); + let sweep_path = Vector::from([0., 0., height]); + + Sketch::empty() + .add_region( + Region::circle(Point::origin(), outer, services) + .add_interiors([Cycle::circle( + Point::origin(), + inner, + services, + ) .reverse(services) .insert(services)]) - .insert(services), - ); - - let surface = services.objects.surfaces.xy_plane(); - let path = Vector::from([0., 0., height]); - sketch - .sweep_sketch(surface, path, services) + .insert(services), + ) + .sweep_sketch(bottom_surface, sweep_path, services) .insert(services) } 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..6e2173993 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,25 +13,10 @@ 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 cuboid = cuboid::model([size, size, size], services); - let surface = services.objects.surfaces.xy_plane(); - let path = Vector::from([0., 0., size]); - let solid = sketch.sweep_sketch(surface, path, 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(); diff --git a/models/star/src/lib.rs b/models/star/src/lib.rs index 10a7f49f6..ca1ad15ab 100644 --- a/models/star/src/lib.rs +++ b/models/star/src/lib.rs @@ -43,17 +43,17 @@ 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), - ); - - let surface = services.objects.surfaces.xy_plane(); - let path = Vector::from([0., 0., h]); - sketch - .sweep_sketch(surface, path, services) + let bottom_surface = services.objects.surfaces.xy_plane(); + let sweep_path = Vector::from([0., 0., h]); + + Sketch::empty() + .add_region( + Region::polygon(outer_points, services) + .add_interiors([Cycle::polygon(inner_points, services) + .reverse(services) + .insert(services)]) + .insert(services), + ) + .sweep_sketch(bottom_surface, sweep_path, services) .insert(services) }