Skip to content

Commit

Permalink
Make a and b fields of Difference2d private
Browse files Browse the repository at this point in the history
This adds access functions and fixes all users as well as README.md

Signed-off-by: Daniel Egger <[email protected]>
  • Loading branch information
therealprof committed Mar 12, 2022
1 parent 1c19673 commit 7167dca
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
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::from_radius(outer);
let inner_edge = fj::Circle::from_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 @@ -51,15 +51,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::from_radius(outer);
let inner_edge = fj::Circle::from_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()
}
}

0 comments on commit 7167dca

Please sign in to comment.