diff --git a/README.md b/README.md index ab063e3f5..316e095dd 100644 --- a/README.md +++ b/README.md @@ -62,10 +62,7 @@ pub extern "C" fn model(args: &HashMap) -> fj::Shape { b: inner_edge.into(), }; - let spacer = fj::Sweep { - shape: footprint.into(), - length: height, - }; + let spacer = fj::Sweep::from_shape_and_length(footprint.into(), height); spacer.into() } diff --git a/fj/src/shape_3d.rs b/fj/src/shape_3d.rs index c884b7db3..4d7d96f9e 100644 --- a/fj/src/shape_3d.rs +++ b/fj/src/shape_3d.rs @@ -62,15 +62,29 @@ impl From for Shape3d { #[repr(C)] pub struct Sweep { /// The 2-dimensional shape being swept - pub shape: Shape2d, + shape: Shape2d, /// The length of the sweep - pub length: f64, + length: f64, +} + +impl Sweep { + pub fn from_shape_and_length(shape: Shape2d, length: f64) -> Self { + Self { shape, length } + } + + pub fn shape(&self) -> &Shape2d { + &self.shape + } + + pub fn length(&self) -> f64 { + self.length + } } impl From for Shape { fn from(shape: Sweep) -> Self { - Self::Shape3d(Shape3d::Sweep(shape)) + Self::Shape3d(shape.into()) } } diff --git a/fj/src/syntax.rs b/fj/src/syntax.rs index 31e57d8a5..b62a693cf 100644 --- a/fj/src/syntax.rs +++ b/fj/src/syntax.rs @@ -44,7 +44,7 @@ where { fn sweep(&self, length: f64) -> crate::Sweep { let shape = self.clone().into(); - crate::Sweep { shape, length } + crate::Sweep::from_shape_and_length(shape, length) } } diff --git a/models/cuboid/src/lib.rs b/models/cuboid/src/lib.rs index e7146d90e..73046c55b 100644 --- a/models/cuboid/src/lib.rs +++ b/models/cuboid/src/lib.rs @@ -14,10 +14,7 @@ pub extern "C" fn model(args: &HashMap) -> fj::Shape { [-x / 2., y / 2.], ]); - let cuboid = fj::Sweep { - shape: rectangle.into(), - length: z, - }; + let cuboid = fj::Sweep::from_shape_and_length(rectangle.into(), z); cuboid.into() } diff --git a/models/spacer/src/lib.rs b/models/spacer/src/lib.rs index 3a84e8e98..5ab897c52 100644 --- a/models/spacer/src/lib.rs +++ b/models/spacer/src/lib.rs @@ -26,10 +26,7 @@ pub extern "C" fn model(args: &HashMap) -> fj::Shape { b: inner_edge.into(), }; - let spacer = fj::Sweep { - shape: footprint.into(), - length: height, - }; + let spacer = fj::Sweep::from_shape_and_length(footprint.into(), height); spacer.into() } diff --git a/models/star/src/lib.rs b/models/star/src/lib.rs index 8bfb958ad..58d9ec3a3 100644 --- a/models/star/src/lib.rs +++ b/models/star/src/lib.rs @@ -58,10 +58,7 @@ pub extern "C" fn model(args: &HashMap) -> fj::Shape { b: inner.into(), }; - let star = fj::Sweep { - shape: footprint.into(), - length: h, - }; + let star = fj::Sweep::from_shape_and_length(footprint.into(), h); star.into() } diff --git a/src/kernel/shapes/sweep.rs b/src/kernel/shapes/sweep.rs index 9b2c06e01..d9834a208 100644 --- a/src/kernel/shapes/sweep.rs +++ b/src/kernel/shapes/sweep.rs @@ -9,15 +9,15 @@ use super::ToShape; impl ToShape for fj::Sweep { fn to_shape(&self, tolerance: Scalar, debug_info: &mut DebugInfo) -> Shape { sweep_shape( - self.shape.to_shape(tolerance, debug_info), - Vector::from([0., 0., self.length]), + self.shape().to_shape(tolerance, debug_info), + Vector::from([0., 0., self.length()]), tolerance, ) } fn bounding_volume(&self) -> Aabb<3> { - let mut aabb = self.shape.bounding_volume(); - aabb.max.z = self.length.into(); + let mut aabb = self.shape().bounding_volume(); + aabb.max.z = self.length().into(); aabb } }