diff --git a/Cargo.lock b/Cargo.lock index 66bd86951..4a11f3baf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -61,6 +61,7 @@ version = "0.1.0" dependencies = [ "cuboid", "fj", + "holes", "spacer", "split", "star", diff --git a/models/all/Cargo.toml b/models/all/Cargo.toml index 0d758a141..8963edec7 100644 --- a/models/all/Cargo.toml +++ b/models/all/Cargo.toml @@ -9,6 +9,9 @@ path = "../../crates/fj" [dependencies.cuboid] path = "../cuboid" +[dependencies.holes] +path = "../holes" + [dependencies.spacer] path = "../spacer" diff --git a/models/all/src/lib.rs b/models/all/src/lib.rs index 48d52156e..784a9b5cf 100644 --- a/models/all/src/lib.rs +++ b/models/all/src/lib.rs @@ -18,7 +18,7 @@ pub fn model(services: &mut Services) -> Handle { let axis = Vector::from([1., 1., 1.]).normalize(); let angle_rad = Scalar::PI / 6.; - let cuboid = cuboid::model(1., 2., 3., services) + let cuboid = cuboid::model([1., 2., 3.], services) .translate(offset * 1., services) .rotate(axis * angle_rad * 1., services); let spacer = spacer::model(2., 1., 1., services) @@ -27,13 +27,17 @@ pub fn model(services: &mut Services) -> Handle { let star = star::model(5, 2., 1., 1., services) .translate(offset * 3., services) .rotate(axis * angle_rad * 3., services); - let split = split::model(1., 0.5, services) + let split = split::model(1., 0.2, services) .translate(offset * 4., services) .rotate(axis * angle_rad * 4., services); + let holes = holes::model(0.5, services) + .translate(offset * 5., services) + .rotate(axis * angle_rad * 5., services); cuboid .merge(&spacer) .merge(&star) .merge(&split) + .merge(&holes) .insert(services) } diff --git a/models/cuboid/src/lib.rs b/models/cuboid/src/lib.rs index eebe7781e..8faba1bbe 100644 --- a/models/cuboid/src/lib.rs +++ b/models/cuboid/src/lib.rs @@ -10,10 +10,15 @@ use fj::{ services::Services, storage::Handle, }, - math::Vector, + math::{Scalar, Vector}, }; -pub fn model(x: f64, y: f64, z: f64, services: &mut Services) -> Handle { +pub fn model( + size: impl Into>, + services: &mut Services, +) -> Handle { + let [x, y, z] = size.into().components; + let sketch = Sketch::empty().add_region( Region::polygon( [ @@ -28,7 +33,7 @@ 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]); + let path = Vector::from([Scalar::ZERO, Scalar::ZERO, z]); sketch .sweep_sketch(surface, path, services) .insert(services) diff --git a/models/cuboid/src/main.rs b/models/cuboid/src/main.rs index 23edaa890..3a3836caf 100644 --- a/models/cuboid/src/main.rs +++ b/models/cuboid/src/main.rs @@ -2,7 +2,7 @@ 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); + let model = cuboid::model([3., 2., 1.], &mut services); handle_model(model, services)?; Ok(()) } diff --git a/models/holes/src/lib.rs b/models/holes/src/lib.rs index c896926c4..7867b17c7 100644 --- a/models/holes/src/lib.rs +++ b/models/holes/src/lib.rs @@ -1,28 +1,35 @@ -use fj::core::{ - objects::Solid, - operations::{holes::AddHole, insert::Insert, update::UpdateSolid}, - services::Services, - storage::Handle, +use fj::{ + core::{ + objects::Solid, + operations::{holes::AddHole, insert::Insert, update::UpdateSolid}, + services::Services, + storage::Handle, + }, + math::Scalar, }; -pub fn model(services: &mut Services) -> Handle { - let cuboid = cuboid::model(1., 1., 1., services); +pub fn model( + radius: impl Into, + services: &mut Services, +) -> Handle { + let radius = radius.into(); - let shell = cuboid.shells().first(); - let bottom_face = shell.faces().first(); - - let hole_position = [0., 0.]; - let hole_radius = 0.25; - let hole_path = [0., 0., 0.5]; + let size = radius * 4.; + let cuboid = cuboid::model([size, size, size], services); cuboid - .update_shell(shell, |shell| { + .update_shell(cuboid.shells().first(), |shell| { + let bottom_face = shell.faces().first(); + + let hole_position = [0., 0.]; + let depth = size / 2.; + shell .add_blind_hole( bottom_face, hole_position, - hole_radius, - hole_path, + radius, + [Scalar::ZERO, Scalar::ZERO, depth], services, ) .insert(services) diff --git a/models/holes/src/main.rs b/models/holes/src/main.rs index 9091143ec..6165441dd 100644 --- a/models/holes/src/main.rs +++ b/models/holes/src/main.rs @@ -2,7 +2,7 @@ use fj::{core::services::Services, handle_model}; fn main() -> fj::Result { let mut services = Services::new(); - let model = holes::model(&mut services); + let model = holes::model(0.25, &mut services); handle_model(model, services)?; Ok(()) }