From d7bb3a57658435a6463ddb578fa1c3dc6663195b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 17 Mar 2022 13:46:18 +0100 Subject: [PATCH 1/3] Restore alphabetic ordering in `syntax` module This makes things easier to find. --- fj/src/syntax.rs | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/fj/src/syntax.rs b/fj/src/syntax.rs index 7c809c713..63d08ee89 100644 --- a/fj/src/syntax.rs +++ b/fj/src/syntax.rs @@ -1,3 +1,24 @@ +pub trait Group { + fn group(&self, other: &Other) -> crate::Group + where + Other: Clone + Into; +} + +impl Group for T +where + T: Clone + Into, +{ + fn group(&self, other: &Other) -> crate::Group + where + Other: Clone + Into, + { + let a = self.clone().into(); + let b = other.clone().into(); + + crate::Group { a, b } + } +} + pub trait Rotate { /// Create a rotation /// @@ -69,24 +90,3 @@ where } } } - -pub trait Group { - fn group(&self, other: &Other) -> crate::Group - where - Other: Clone + Into; -} - -impl Group for T -where - T: Clone + Into, -{ - fn group(&self, other: &Other) -> crate::Group - where - Other: Clone + Into, - { - let a = self.clone().into(); - let b = other.clone().into(); - - crate::Group { a, b } - } -} From 222bb2877157c5b5bb8c71278d2fe4bc06659b68 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 17 Mar 2022 13:48:35 +0100 Subject: [PATCH 2/3] Add convenient syntax for `fj::Difference2d` --- fj/src/lib.rs | 3 ++- fj/src/syntax.rs | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/fj/src/lib.rs b/fj/src/lib.rs index 44f967bbc..2cf19969c 100644 --- a/fj/src/lib.rs +++ b/fj/src/lib.rs @@ -16,7 +16,8 @@ mod syntax; pub mod prelude { pub use crate::syntax::{ - Group as _, Rotate as _, Sketch as _, Sweep as _, Translate as _, + Difference as _, Group as _, Rotate as _, Sketch as _, Sweep as _, + Translate as _, }; } diff --git a/fj/src/syntax.rs b/fj/src/syntax.rs index 63d08ee89..e79696a08 100644 --- a/fj/src/syntax.rs +++ b/fj/src/syntax.rs @@ -1,3 +1,24 @@ +pub trait Difference { + fn difference(&self, other: &Other) -> crate::Difference2d + where + Other: Clone + Into; +} + +impl Difference for T +where + T: Clone + Into, +{ + fn difference(&self, other: &Other) -> crate::Difference2d + where + Other: Clone + Into, + { + let a = self.clone().into(); + let b = other.clone().into(); + + crate::Difference2d::from_objects(a, b) + } +} + pub trait Group { fn group(&self, other: &Other) -> crate::Group where From fea00dd52f503f43a24ad0b4bb9174f08b910238 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 17 Mar 2022 13:50:25 +0100 Subject: [PATCH 3/3] Use convenient syntax in spacer model --- models/spacer/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/models/spacer/src/lib.rs b/models/spacer/src/lib.rs index 46cdf27f1..16af20e4a 100644 --- a/models/spacer/src/lib.rs +++ b/models/spacer/src/lib.rs @@ -1,5 +1,7 @@ use std::collections::HashMap; +use fj::prelude::*; + #[no_mangle] pub extern "C" fn model(args: &HashMap) -> fj::Shape { let outer = args @@ -22,10 +24,8 @@ pub extern "C" fn model(args: &HashMap) -> fj::Shape { fj::Circle::from_radius(outer).with_color([0, 0, 255, 255]); let inner_edge = fj::Circle::from_radius(inner); - let footprint = - fj::Difference2d::from_objects(outer_edge.into(), inner_edge.into()); - - let spacer = fj::Sweep::from_shape_and_length(footprint.into(), height); + let footprint = outer_edge.difference(&inner_edge); + let spacer = footprint.sweep(height); spacer.into() }