mirror of
https://github.com/hannobraun/Fornjot
synced 2025-02-25 16:45:52 +00:00
Merge pull request #372 from hannobraun/diff
Add convenient syntax for `fj::Difference2d`
This commit is contained in:
commit
e05119e61c
@ -16,7 +16,8 @@ mod syntax;
|
|||||||
|
|
||||||
pub mod prelude {
|
pub mod prelude {
|
||||||
pub use crate::syntax::{
|
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 _,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,45 @@
|
|||||||
|
pub trait Difference {
|
||||||
|
fn difference<Other>(&self, other: &Other) -> crate::Difference2d
|
||||||
|
where
|
||||||
|
Other: Clone + Into<crate::Shape2d>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Difference for T
|
||||||
|
where
|
||||||
|
T: Clone + Into<crate::Shape2d>,
|
||||||
|
{
|
||||||
|
fn difference<Other>(&self, other: &Other) -> crate::Difference2d
|
||||||
|
where
|
||||||
|
Other: Clone + Into<crate::Shape2d>,
|
||||||
|
{
|
||||||
|
let a = self.clone().into();
|
||||||
|
let b = other.clone().into();
|
||||||
|
|
||||||
|
crate::Difference2d::from_objects(a, b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait Group {
|
||||||
|
fn group<Other>(&self, other: &Other) -> crate::Group
|
||||||
|
where
|
||||||
|
Other: Clone + Into<crate::Shape3d>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Group for T
|
||||||
|
where
|
||||||
|
T: Clone + Into<crate::Shape3d>,
|
||||||
|
{
|
||||||
|
fn group<Other>(&self, other: &Other) -> crate::Group
|
||||||
|
where
|
||||||
|
Other: Clone + Into<crate::Shape3d>,
|
||||||
|
{
|
||||||
|
let a = self.clone().into();
|
||||||
|
let b = other.clone().into();
|
||||||
|
|
||||||
|
crate::Group { a, b }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub trait Rotate {
|
pub trait Rotate {
|
||||||
/// Create a rotation
|
/// Create a rotation
|
||||||
///
|
///
|
||||||
@ -69,24 +111,3 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Group {
|
|
||||||
fn group<Other>(&self, other: &Other) -> crate::Group
|
|
||||||
where
|
|
||||||
Other: Clone + Into<crate::Shape3d>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> Group for T
|
|
||||||
where
|
|
||||||
T: Clone + Into<crate::Shape3d>,
|
|
||||||
{
|
|
||||||
fn group<Other>(&self, other: &Other) -> crate::Group
|
|
||||||
where
|
|
||||||
Other: Clone + Into<crate::Shape3d>,
|
|
||||||
{
|
|
||||||
let a = self.clone().into();
|
|
||||||
let b = other.clone().into();
|
|
||||||
|
|
||||||
crate::Group { a, b }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use fj::prelude::*;
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn model(args: &HashMap<String, String>) -> fj::Shape {
|
pub extern "C" fn model(args: &HashMap<String, String>) -> fj::Shape {
|
||||||
let outer = args
|
let outer = args
|
||||||
@ -22,10 +24,8 @@ pub extern "C" fn model(args: &HashMap<String, String>) -> fj::Shape {
|
|||||||
fj::Circle::from_radius(outer).with_color([0, 0, 255, 255]);
|
fj::Circle::from_radius(outer).with_color([0, 0, 255, 255]);
|
||||||
let inner_edge = fj::Circle::from_radius(inner);
|
let inner_edge = fj::Circle::from_radius(inner);
|
||||||
|
|
||||||
let footprint =
|
let footprint = outer_edge.difference(&inner_edge);
|
||||||
fj::Difference2d::from_objects(outer_edge.into(), inner_edge.into());
|
let spacer = footprint.sweep(height);
|
||||||
|
|
||||||
let spacer = fj::Sweep::from_shape_and_length(footprint.into(), height);
|
|
||||||
|
|
||||||
spacer.into()
|
spacer.into()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user