diff --git a/crates/fj/src/handle_model.rs b/crates/fj/src/handle_model.rs index 407c456e1..53c1ed1ee 100644 --- a/crates/fj/src/handle_model.rs +++ b/crates/fj/src/handle_model.rs @@ -1,9 +1,12 @@ use std::ops::Deref; -use fj_core::algorithms::{ - approx::{InvalidTolerance, Tolerance}, - bounding_volume::BoundingVolume, - triangulate::Triangulate, +use fj_core::{ + algorithms::{ + approx::{InvalidTolerance, Tolerance}, + bounding_volume::BoundingVolume, + triangulate::Triangulate, + }, + services::Services, }; use fj_interop::model::Model; use fj_math::{Aabb, Point, Scalar}; @@ -18,13 +21,21 @@ 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) -> Result +pub fn handle_model( + model: impl Deref, + services: Services, +) -> Result where for<'r> (&'r M, Tolerance): Triangulate, M: BoundingVolume<3>, { let args = Args::parse(); + // Dropping `Services` will cause a panic, if there are any unhandled + // validation errors. It would be better to return an error, but this will + // do for now. + drop(services); + let aabb = model.aabb().unwrap_or(Aabb { min: Point::origin(), max: Point::origin(), diff --git a/models/all/src/main.rs b/models/all/src/main.rs index 27e7d3073..d41417248 100644 --- a/models/all/src/main.rs +++ b/models/all/src/main.rs @@ -1,7 +1,8 @@ use fj::{core::services::Services, handle_model}; fn main() -> fj::Result { - let model = all::model(&mut Services::new()); - handle_model(model)?; + let mut services = Services::new(); + let model = all::model(&mut services); + handle_model(model, services)?; Ok(()) } diff --git a/models/cuboid/src/main.rs b/models/cuboid/src/main.rs index 6b9fdc21f..23edaa890 100644 --- a/models/cuboid/src/main.rs +++ b/models/cuboid/src/main.rs @@ -1,7 +1,8 @@ use fj::{core::services::Services, handle_model}; fn main() -> fj::Result { - let model = cuboid::model(3., 2., 1., &mut Services::new()); - handle_model(model)?; + let mut services = Services::new(); + let model = cuboid::model(3., 2., 1., &mut services); + handle_model(model, services)?; Ok(()) } diff --git a/models/spacer/src/main.rs b/models/spacer/src/main.rs index 18bf6af09..64ed2d1d4 100644 --- a/models/spacer/src/main.rs +++ b/models/spacer/src/main.rs @@ -1,7 +1,8 @@ use fj::{core::services::Services, handle_model}; fn main() -> fj::Result { - let model = spacer::model(1., 0.5, 1., &mut Services::new()); - handle_model(model)?; + let mut services = Services::new(); + let model = spacer::model(1., 0.5, 1., &mut services); + handle_model(model, services)?; Ok(()) } diff --git a/models/star/src/main.rs b/models/star/src/main.rs index 32a8f8a8d..6022870fe 100644 --- a/models/star/src/main.rs +++ b/models/star/src/main.rs @@ -1,7 +1,8 @@ use fj::{core::services::Services, handle_model}; fn main() -> fj::Result { - let model = star::model(5, 1., 2., 1., &mut Services::new()); - handle_model(model)?; + let mut services = Services::new(); + let model = star::model(5, 1., 2., 1., &mut services); + handle_model(model, services)?; Ok(()) }