diff --git a/crates/fj/src/handle_model.rs b/crates/fj/src/handle_model.rs index 0db6adb56..7d8f1e1fb 100644 --- a/crates/fj/src/handle_model.rs +++ b/crates/fj/src/handle_model.rs @@ -1,4 +1,4 @@ -use std::{error::Error as _, fmt, mem, ops::Deref}; +use std::{error::Error as _, fmt, mem}; use fj_core::{ algorithms::{ @@ -23,10 +23,7 @@ use crate::Args; /// /// This function is used by Fornjot's own testing infrastructure, but is useful /// beyond that, when using Fornjot directly to define a model. -pub fn handle_model( - model: impl Deref, - services: Services, -) -> Result +pub fn handle_model(model: &M, services: Services) -> Result where for<'r> (&'r M, Tolerance): Triangulate, M: BoundingVolume<3>, @@ -68,7 +65,7 @@ where Some(user_defined_tolerance) => user_defined_tolerance, }; - let mesh = (model.deref(), tolerance).triangulate(); + let mesh = (model, tolerance).triangulate(); if let Some(path) = args.export { crate::export::export(&mesh, &path)?; diff --git a/models/all/src/lib.rs b/models/all/src/lib.rs index fccf189b7..d50aab1c3 100644 --- a/models/all/src/lib.rs +++ b/models/all/src/lib.rs @@ -1,16 +1,13 @@ use fj::{ core::{ objects::Solid, - operations::{ - insert::Insert, merge::Merge, transform::TransformObject, - }, + operations::{merge::Merge, transform::TransformObject}, services::Services, - storage::Handle, }, math::{Scalar, Vector}, }; -pub fn model(services: &mut Services) -> Handle { +pub fn model(services: &mut Services) -> Solid { // Just combine all the other models using offsets/rotations that won't // result in neat vertex positions or axis-aligned edges/faces. This is // useful for testing. @@ -40,5 +37,4 @@ pub fn model(services: &mut Services) -> Handle { .merge(&star) .merge(&split) .merge(&holes) - .insert(services) } diff --git a/models/all/src/main.rs b/models/all/src/main.rs index d41417248..b0615721c 100644 --- a/models/all/src/main.rs +++ b/models/all/src/main.rs @@ -3,6 +3,6 @@ use fj::{core::services::Services, handle_model}; fn main() -> fj::Result { let mut services = Services::new(); let model = all::model(&mut services); - handle_model(model, services)?; + handle_model(&model, services)?; Ok(()) } diff --git a/models/color/src/lib.rs b/models/color/src/lib.rs index 565a87b7d..eb4e5943e 100644 --- a/models/color/src/lib.rs +++ b/models/color/src/lib.rs @@ -7,40 +7,37 @@ use fj::core::{ update::{UpdateFace, UpdateShell, UpdateSolid}, }, services::Services, - storage::Handle, }; -pub fn model(services: &mut Services) -> Handle { +pub fn model(services: &mut Services) -> Solid { let size = 1.; let cuboid = cuboid::model([size, size, size], services); - cuboid - .update_shell(cuboid.shells().only(), |shell| { - let shell = shell.update_face(shell.faces().first(), |face| { - face.update_region(|region| { - region.set_color([0., 1., 0.]).insert(services) - }) - .insert(services) - }); + cuboid.update_shell(cuboid.shells().only(), |shell| { + let shell = shell.update_face(shell.faces().first(), |face| { + face.update_region(|region| { + region.set_color([0., 1., 0.]).insert(services) + }) + .insert(services) + }); - // Split colored face, to make sure the same color is applied to the - // two derived faces. - let shell = { - let face = shell.faces().first(); - let line = { - let cycle = face.region().exterior(); + // Split colored face, to make sure the same color is applied to the + // two derived faces. + let shell = { + let face = shell.faces().first(); + let line = { + let cycle = face.region().exterior(); - [ - (cycle.half_edges().nth(0).unwrap(), [0.2]), - (cycle.half_edges().nth(2).unwrap(), [0.2]), - ] - }; - - let (shell, _) = shell.split_face(face, line, services); - shell + [ + (cycle.half_edges().nth(0).unwrap(), [0.2]), + (cycle.half_edges().nth(2).unwrap(), [0.2]), + ] }; - shell.insert(services) - }) - .insert(services) + let (shell, _) = shell.split_face(face, line, services); + shell + }; + + shell.insert(services) + }) } diff --git a/models/color/src/main.rs b/models/color/src/main.rs index 5bfd32f15..01318089b 100644 --- a/models/color/src/main.rs +++ b/models/color/src/main.rs @@ -3,6 +3,6 @@ use fj::{core::services::Services, handle_model}; fn main() -> fj::Result { let mut services = Services::new(); let model = color::model(&mut services); - handle_model(model, services)?; + handle_model(&model, services)?; Ok(()) } diff --git a/models/cuboid/src/lib.rs b/models/cuboid/src/lib.rs index d7b9aaf5e..2b1a02431 100644 --- a/models/cuboid/src/lib.rs +++ b/models/cuboid/src/lib.rs @@ -8,15 +8,11 @@ use fj::{ update::UpdateSketch, }, services::Services, - storage::Handle, }, math::{Scalar, Vector}, }; -pub fn model( - size: impl Into>, - services: &mut Services, -) -> Handle { +pub fn model(size: impl Into>, services: &mut Services) -> Solid { let [x, y, z] = size.into().components; let bottom_surface = services.objects.surfaces.xy_plane(); @@ -36,5 +32,4 @@ pub fn model( .insert(services), ) .sweep_sketch(bottom_surface, sweep_path, services) - .insert(services) } diff --git a/models/cuboid/src/main.rs b/models/cuboid/src/main.rs index 3a3836caf..2a501021f 100644 --- a/models/cuboid/src/main.rs +++ b/models/cuboid/src/main.rs @@ -3,6 +3,6 @@ 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); - handle_model(model, services)?; + handle_model(&model, services)?; Ok(()) } diff --git a/models/holes/src/lib.rs b/models/holes/src/lib.rs index 937319f45..9da1c5ce5 100644 --- a/models/holes/src/lib.rs +++ b/models/holes/src/lib.rs @@ -7,58 +7,52 @@ use fj::{ update::UpdateSolid, }, services::Services, - storage::Handle, }, math::Scalar, }; -pub fn model( - radius: impl Into, - services: &mut Services, -) -> Handle { +pub fn model(radius: impl Into, services: &mut Services) -> Solid { let radius = radius.into(); let size = radius * 4.; let cuboid = cuboid::model([size * 2., size, size], services); - cuboid - .update_shell(cuboid.shells().only(), |shell| { - let bottom_face = shell.faces().first(); - let offset = size / 2.; - let depth = size / 2.; + cuboid.update_shell(cuboid.shells().only(), |shell| { + let bottom_face = shell.faces().first(); + let offset = size / 2.; + let depth = size / 2.; - let shell = shell.add_blind_hole( - HoleLocation { - face: bottom_face, - position: [-offset, Scalar::ZERO].into(), - }, - radius, - [Scalar::ZERO, Scalar::ZERO, depth], - services, - ); + let shell = shell.add_blind_hole( + HoleLocation { + face: bottom_face, + position: [-offset, Scalar::ZERO].into(), + }, + radius, + [Scalar::ZERO, Scalar::ZERO, depth], + services, + ); - let bottom_face = shell.faces().first(); - let top_face = shell - .faces() - .nth(5) - .expect("Expected shell to have top face"); + let bottom_face = shell.faces().first(); + let top_face = shell + .faces() + .nth(5) + .expect("Expected shell to have top face"); - shell - .add_through_hole( - [ - HoleLocation { - face: bottom_face, - position: [offset, Scalar::ZERO].into(), - }, - HoleLocation { - face: top_face, - position: [offset, Scalar::ZERO].into(), - }, - ], - radius, - services, - ) - .insert(services) - }) - .insert(services) + shell + .add_through_hole( + [ + HoleLocation { + face: bottom_face, + position: [offset, Scalar::ZERO].into(), + }, + HoleLocation { + face: top_face, + position: [offset, Scalar::ZERO].into(), + }, + ], + radius, + services, + ) + .insert(services) + }) } diff --git a/models/holes/src/main.rs b/models/holes/src/main.rs index 6165441dd..1a5c7d1ff 100644 --- a/models/holes/src/main.rs +++ b/models/holes/src/main.rs @@ -3,6 +3,6 @@ use fj::{core::services::Services, handle_model}; fn main() -> fj::Result { let mut services = Services::new(); let model = holes::model(0.25, &mut services); - handle_model(model, services)?; + handle_model(&model, services)?; Ok(()) } diff --git a/models/spacer/src/lib.rs b/models/spacer/src/lib.rs index 8c7bd9684..d5a0afe63 100644 --- a/models/spacer/src/lib.rs +++ b/models/spacer/src/lib.rs @@ -9,7 +9,6 @@ use fj::{ update::{UpdateRegion, UpdateSketch}, }, services::Services, - storage::Handle, }, math::{Point, Vector}, }; @@ -19,7 +18,7 @@ pub fn model( inner: f64, height: f64, services: &mut Services, -) -> Handle { +) -> Solid { let bottom_surface = services.objects.surfaces.xy_plane(); let sweep_path = Vector::from([0., 0., height]); @@ -36,5 +35,4 @@ pub fn model( .insert(services), ) .sweep_sketch(bottom_surface, sweep_path, services) - .insert(services) } diff --git a/models/spacer/src/main.rs b/models/spacer/src/main.rs index 64ed2d1d4..2a81481e8 100644 --- a/models/spacer/src/main.rs +++ b/models/spacer/src/main.rs @@ -3,6 +3,6 @@ use fj::{core::services::Services, handle_model}; fn main() -> fj::Result { let mut services = Services::new(); let model = spacer::model(1., 0.5, 1., &mut services); - handle_model(model, services)?; + handle_model(&model, services)?; Ok(()) } diff --git a/models/split/src/lib.rs b/models/split/src/lib.rs index 6e2173993..d8cec9e39 100644 --- a/models/split/src/lib.rs +++ b/models/split/src/lib.rs @@ -5,31 +5,24 @@ use fj::core::{ update::UpdateSolid, }, services::Services, - storage::Handle, }; -pub fn model( - size: f64, - split_pos: f64, - services: &mut Services, -) -> Handle { +pub fn model(size: f64, split_pos: f64, services: &mut Services) -> Solid { let cuboid = cuboid::model([size, size, size], services); - cuboid - .update_shell(cuboid.shells().only(), |shell| { - let face = shell.faces().first(); - let cycle = face.region().exterior(); + cuboid.update_shell(cuboid.shells().only(), |shell| { + let face = shell.faces().first(); + let cycle = face.region().exterior(); - let line = [ - (cycle.half_edges().nth(0).unwrap(), [split_pos]), - (cycle.half_edges().nth(2).unwrap(), [split_pos]), - ]; + let line = [ + (cycle.half_edges().nth(0).unwrap(), [split_pos]), + (cycle.half_edges().nth(2).unwrap(), [split_pos]), + ]; - let (shell, [face, _]) = shell.split_face(face, line, services); + let (shell, [face, _]) = shell.split_face(face, line, services); - shell - .sweep_face_of_shell(face, [0., 0., -size / 2.], services) - .insert(services) - }) - .insert(services) + shell + .sweep_face_of_shell(face, [0., 0., -size / 2.], services) + .insert(services) + }) } diff --git a/models/split/src/main.rs b/models/split/src/main.rs index 5c4a412ed..b5f4c7440 100644 --- a/models/split/src/main.rs +++ b/models/split/src/main.rs @@ -3,6 +3,6 @@ use fj::{core::services::Services, handle_model}; fn main() -> fj::Result { let mut services = Services::new(); let model = split::model(1.0, 0.2, &mut services); - handle_model(model, services)?; + handle_model(&model, services)?; Ok(()) } diff --git a/models/star/src/lib.rs b/models/star/src/lib.rs index ca1ad15ab..87787e4ac 100644 --- a/models/star/src/lib.rs +++ b/models/star/src/lib.rs @@ -11,7 +11,6 @@ use fj::{ update::{UpdateRegion, UpdateSketch}, }, services::Services, - storage::Handle, }, math::Vector, }; @@ -22,7 +21,7 @@ pub fn model( r2: f64, h: f64, services: &mut Services, -) -> Handle { +) -> Solid { let num_vertices = num_points * 2; let vertex_iter = (0..num_vertices).map(|i| { let angle_rad = 2. * PI / num_vertices as f64 * i as f64; @@ -55,5 +54,4 @@ pub fn model( .insert(services), ) .sweep_sketch(bottom_surface, sweep_path, services) - .insert(services) } diff --git a/models/star/src/main.rs b/models/star/src/main.rs index 6022870fe..c91ba4bc0 100644 --- a/models/star/src/main.rs +++ b/models/star/src/main.rs @@ -3,6 +3,6 @@ use fj::{core::services::Services, handle_model}; fn main() -> fj::Result { let mut services = Services::new(); let model = star::model(5, 1., 2., 1., &mut services); - handle_model(model, services)?; + handle_model(&model, services)?; Ok(()) } diff --git a/models/vertices-indices/src/lib.rs b/models/vertices-indices/src/lib.rs index 15050e57e..f4727cbeb 100644 --- a/models/vertices-indices/src/lib.rs +++ b/models/vertices-indices/src/lib.rs @@ -6,16 +6,13 @@ use fj::core::{ update::UpdateSolid, }, services::Services, - storage::Handle, }; -pub fn model(services: &mut Services) -> Handle { - Solid::empty() - .add_shells([Shell::from_vertices_and_indices( - [[0., 0., 0.], [1., 0., 0.], [0., 1., 0.], [0., 0., 1.]], - [[2, 1, 0], [0, 1, 3], [1, 2, 3], [2, 0, 3]], - services, - ) - .insert(services)]) - .insert(services) +pub fn model(services: &mut Services) -> Solid { + Solid::empty().add_shells([Shell::from_vertices_and_indices( + [[0., 0., 0.], [1., 0., 0.], [0., 1., 0.], [0., 0., 1.]], + [[2, 1, 0], [0, 1, 3], [1, 2, 3], [2, 0, 3]], + services, + ) + .insert(services)]) } diff --git a/models/vertices-indices/src/main.rs b/models/vertices-indices/src/main.rs index 2587df58c..87fa9c58a 100644 --- a/models/vertices-indices/src/main.rs +++ b/models/vertices-indices/src/main.rs @@ -3,6 +3,6 @@ use fj::{core::services::Services, handle_model}; fn main() -> fj::Result { let mut services = Services::new(); let model = vertices_indices::model(&mut services); - handle_model(model, services)?; + handle_model(&model, services)?; Ok(()) }