Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Privatize Sweep #342

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ pub extern "C" fn model(args: &HashMap<String, String>) -> 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()
}
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 @@ -26,10 +26,7 @@ pub extern "C" fn model(args: &HashMap<String, String>) -> 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()
}
5 changes: 1 addition & 4 deletions models/star/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ pub extern "C" fn model(args: &HashMap<String, String>) -> 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()
}
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
}
}