Skip to content

Commit

Permalink
Privatize Sweep
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Egger <[email protected]>
  • Loading branch information
therealprof committed Mar 13, 2022
1 parent 7167dca commit 50fa038
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 24 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ pub extern "C" fn model(args: &HashMap<String, String>) -> 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()
}
Expand Down
20 changes: 17 additions & 3 deletions fj/src/shape_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,29 @@ impl From<Transform> 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<Sweep> for Shape {
fn from(shape: Sweep) -> Self {
Self::Shape3d(Shape3d::Sweep(shape))
Self::Shape3d(shape.into())
}
}

Expand Down
2 changes: 1 addition & 1 deletion fj/src/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
5 changes: 1 addition & 4 deletions models/cuboid/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ pub extern "C" fn model(args: &HashMap<String, String>) -> 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()
}
5 changes: 1 addition & 4 deletions models/spacer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ pub extern "C" fn model(args: &HashMap<String, String>) -> 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()
}
5 changes: 1 addition & 4 deletions models/star/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ pub extern "C" fn model(args: &HashMap<String, String>) -> 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()
}
8 changes: 4 additions & 4 deletions src/kernel/shapes/sweep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 50fa038

Please sign in to comment.