diff --git a/README.md b/README.md index e7cf595577..4d084ad79e 100644 --- a/README.md +++ b/README.md @@ -59,10 +59,7 @@ pub extern "C" fn model(args: &HashMap) -> fj::Shape { let footprint = fj::Difference2d::from_objects(outer_edge.into(), 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 c884b7db3e..4d7d96f9ee 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 31e57d8a53..b62a693cfa 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 e7146d90e6..73046c55b9 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 6c9e6d1bce..45d1a9af7b 100644 --- a/models/spacer/src/lib.rs +++ b/models/spacer/src/lib.rs @@ -23,10 +23,7 @@ pub extern "C" fn model(args: &HashMap) -> fj::Shape { let footprint = fj::Difference2d::from_objects(outer_edge.into(), 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 c8eeaa9f20..9193483201 100644 --- a/models/star/src/lib.rs +++ b/models/star/src/lib.rs @@ -55,10 +55,7 @@ pub extern "C" fn model(args: &HashMap) -> fj::Shape { let footprint = fj::Difference2d::from_objects(outer.into(), 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 9b2c06e010..d9834a208e 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 } }