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

Make a and b fields of Difference2d private #341

Closed
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 @@ -57,10 +57,7 @@ pub extern "C" fn model(args: &HashMap<String, String>) -> fj::Shape {
let outer_edge = fj::Circle { radius: outer };
let inner_edge = fj::Circle { radius: inner };

let footprint = fj::Difference {
a: outer_edge.into(),
b: inner_edge.into(),
};
let footprint = fj::Difference2d::from_objects(outer_edge.into(), inner_edge.into());

let spacer = fj::Sweep {
shape: footprint.into(),
Expand Down
20 changes: 17 additions & 3 deletions fj/src/shape_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,29 @@ impl From<Circle> for Shape2d {
#[repr(C)]
pub struct Difference2d {
/// The original shape
pub a: Shape2d,
a: Shape2d,

/// The shape being subtracted
pub b: Shape2d,
b: Shape2d,
}

impl Difference2d {
pub fn from_objects(a: Shape2d, b: Shape2d) -> Self {
Self { a, b }
}

pub fn a(&self) -> &Shape2d {
&self.a
}

pub fn b(&self) -> &Shape2d {
&self.b
}
}

impl From<Difference2d> for Shape {
fn from(shape: Difference2d) -> Self {
Self::Shape2d(Shape2d::Difference(Box::new(shape)))
Self::Shape2d(shape.into())
}
}

Expand Down
5 changes: 1 addition & 4 deletions models/spacer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ pub extern "C" fn model(args: &HashMap<String, String>) -> fj::Shape {
let outer_edge = fj::Circle { radius: outer };
let inner_edge = fj::Circle { radius: inner };

let footprint = fj::Difference2d {
a: outer_edge.into(),
b: inner_edge.into(),
};
let footprint = fj::Difference2d::from_objects(outer_edge.into(), inner_edge.into());

let spacer = fj::Sweep {
shape: footprint.into(),
Expand Down
5 changes: 1 addition & 4 deletions models/star/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ pub extern "C" fn model(args: &HashMap<String, String>) -> fj::Shape {
let outer = fj::Sketch::from_points(outer);
let inner = fj::Sketch::from_points(inner);

let footprint = fj::Difference2d {
a: outer.into(),
b: inner.into(),
};
let footprint = fj::Difference2d::from_objects(outer.into(), inner.into());

let star = fj::Sweep {
shape: footprint.into(),
Expand Down
4 changes: 2 additions & 2 deletions src/kernel/shapes/difference_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl ToShape for fj::Difference2d {

let mut shape = Shape::new();

let [mut a, mut b] = [&self.a, &self.b]
let [mut a, mut b] = [&self.a(), &self.b()]
.map(|shape| shape.to_shape(tolerance, debug_info));

for shape in [&mut a, &mut b] {
Expand Down Expand Up @@ -105,6 +105,6 @@ impl ToShape for fj::Difference2d {
// This is a conservative estimate of the bounding box: It's never going
// to be bigger than the bounding box of the original shape that another
// is being subtracted from.
self.a.bounding_volume()
self.a().bounding_volume()
}
}