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 some cleanups in fj API #412

Merged
merged 6 commits into from
Mar 29, 2022
Merged
Changes from 1 commit
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
Next Next commit
Merge transformation syntax traits
  • Loading branch information
hannobraun committed Mar 29, 2022
commit 0a26f04637369261843b50fa6d9b7f87cb264198
46 changes: 18 additions & 28 deletions fj/src/syntax.rs
Original file line number Diff line number Diff line change
@@ -53,32 +53,6 @@ where
}
}

/// Convenient syntax to create an [`fj::Transform`]
///
/// [`fj::Transform`]: crate::Transform
pub trait Rotate {
/// Create a rotation
///
/// Create a rotation that rotates `shape` by `angle` around an axis defined
/// by `axis`.
fn rotate(&self, axis: [f64; 3], angle: f64) -> crate::Transform;
}

impl<T> Rotate for T
where
T: Clone + Into<crate::Shape3d>,
{
fn rotate(&self, axis: [f64; 3], angle: f64) -> crate::Transform {
let shape = self.clone().into();
crate::Transform {
shape,
axis,
angle,
offset: [0.; 3],
}
}
}

/// Convenient syntax to create an [`fj::Sketch`]
///
/// [`fj::Sketch`]: crate::Sketch
@@ -120,17 +94,33 @@ where
/// Convenient syntax to create an [`fj::Transform`]
///
/// [`fj::Transform`]: crate::Transform
pub trait Translate {
pub trait Transform {
/// Create a rotation
///
/// Create a rotation that rotates `shape` by `angle` around an axis defined
/// by `axis`.
fn rotate(&self, axis: [f64; 3], angle: f64) -> crate::Transform;

/// Create a translation
///
/// Create a translation that translates `shape` by `offset`.
fn translate(&self, offset: [f64; 3]) -> crate::Transform;
}

impl<T> Translate for T
impl<T> Transform for T
where
T: Clone + Into<crate::Shape3d>,
{
fn rotate(&self, axis: [f64; 3], angle: f64) -> crate::Transform {
let shape = self.clone().into();
crate::Transform {
shape,
axis,
angle,
offset: [0.; 3],
}
}

fn translate(&self, offset: [f64; 3]) -> crate::Transform {
let shape = self.clone().into();
crate::Transform {