From da4705fe742c0913f8b77baaedfb7f987957b7e6 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 11 Oct 2022 14:36:34 +0200 Subject: [PATCH 1/7] Remove attribute that does nothing In addition, the comment attached to it seems to be wrong. --- crates/fj/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/fj/src/lib.rs b/crates/fj/src/lib.rs index 100a9b6b5..294bbb85a 100644 --- a/crates/fj/src/lib.rs +++ b/crates/fj/src/lib.rs @@ -40,7 +40,6 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, PartialEq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[repr(C)] -#[allow(improper_ctypes)] // Box isn't FFI-safe pub enum Shape { /// A group of two 3-dimensional shapes Group(Box), From 58eaff523f9e37334c04982efe8395b0d959a969 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 11 Oct 2022 14:40:19 +0200 Subject: [PATCH 2/7] Simplify imports --- crates/fj/src/angle.rs | 4 +--- crates/fj/src/group.rs | 5 +---- crates/fj/src/lib.rs | 4 +--- crates/fj/src/shape_2d.rs | 22 ++++++++++------------ crates/fj/src/sweep.rs | 5 +---- crates/fj/src/transform.rs | 5 +---- 6 files changed, 15 insertions(+), 30 deletions(-) diff --git a/crates/fj/src/angle.rs b/crates/fj/src/angle.rs index 9911b959e..437a305bb 100644 --- a/crates/fj/src/angle.rs +++ b/crates/fj/src/angle.rs @@ -1,5 +1,3 @@ -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; use std::f64::consts::{PI, TAU}; // One gon in radians @@ -7,7 +5,7 @@ const GON_RAD: f64 = PI / 200.; /// An angle #[derive(Copy, Clone, Debug, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Angle { // The value of the angle in radians rad: f64, diff --git a/crates/fj/src/group.rs b/crates/fj/src/group.rs index 4921cedc8..8bcdf2389 100644 --- a/crates/fj/src/group.rs +++ b/crates/fj/src/group.rs @@ -1,6 +1,3 @@ -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; - use crate::Shape; /// A group of two 3-dimensional shapes @@ -12,7 +9,7 @@ use crate::Shape; /// /// Whether the shapes in the group touch or overlap is not currently checked. #[derive(Clone, Debug, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[repr(C)] pub struct Group { /// The first of the shapes diff --git a/crates/fj/src/lib.rs b/crates/fj/src/lib.rs index 294bbb85a..60fc7788d 100644 --- a/crates/fj/src/lib.rs +++ b/crates/fj/src/lib.rs @@ -33,12 +33,10 @@ pub use self::{ angle::*, group::Group, shape_2d::*, sweep::Sweep, transform::Transform, }; pub use fj_proc::*; -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; /// A shape #[derive(Clone, Debug, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[repr(C)] pub enum Shape { /// A group of two 3-dimensional shapes diff --git a/crates/fj/src/shape_2d.rs b/crates/fj/src/shape_2d.rs index e1d3a43e4..1063fdcde 100644 --- a/crates/fj/src/shape_2d.rs +++ b/crates/fj/src/shape_2d.rs @@ -1,5 +1,3 @@ -#[cfg(feature = "serde")] -use serde::{de, ser, Deserialize, Serialize}; use std::mem; use std::sync::atomic; @@ -7,7 +5,7 @@ use crate::Shape; /// A 2-dimensional shape #[derive(Clone, Debug, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[repr(C)] pub enum Shape2d { /// A difference between two shapes @@ -29,7 +27,7 @@ impl Shape2d { /// A difference between two shapes #[derive(Clone, Debug, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[repr(C)] pub struct Difference2d { shapes: [Shape2d; 2], @@ -74,7 +72,7 @@ impl From for Shape2d { /// that the edges are non-overlapping. If you create a `Sketch` with /// overlapping edges, you're on your own. #[derive(Clone, Debug, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[repr(C)] pub struct Sketch { chain: Chain, @@ -119,7 +117,7 @@ impl Sketch { /// A chain of elements that is part of a [`Sketch`] #[derive(Clone, Debug, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[repr(C)] pub enum Chain { /// The chain is a circle @@ -131,7 +129,7 @@ pub enum Chain { /// A circle that is part of a [`Sketch`] #[derive(Clone, Debug, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[repr(C)] pub struct Circle { /// The radius of the circle @@ -267,10 +265,10 @@ impl Drop for PolyChain { unsafe impl Send for PolyChain {} #[cfg(feature = "serde")] -impl ser::Serialize for PolyChain { +impl serde::ser::Serialize for PolyChain { fn serialize(&self, serializer: S) -> Result where - S: ser::Serializer, + S: serde::ser::Serializer, { let serde_sketch = PolyChainSerde { points: self.to_points(), @@ -281,10 +279,10 @@ impl ser::Serialize for PolyChain { } #[cfg(feature = "serde")] -impl<'de> de::Deserialize<'de> for PolyChain { +impl<'de> serde::de::Deserialize<'de> for PolyChain { fn deserialize(deserializer: D) -> Result where - D: de::Deserializer<'de>, + D: serde::de::Deserializer<'de>, { PolyChainSerde::deserialize(deserializer) .map(|serde_sketch| PolyChain::from_points(serde_sketch.points)) @@ -302,7 +300,7 @@ impl<'de> de::Deserialize<'de> for PolyChain { /// [`PolyChain`]. If de/serialization turns out to be a bottleneck, a more /// complete implementation will be required. #[cfg(feature = "serde")] -#[derive(Serialize, Deserialize)] +#[derive(serde::Serialize, serde::Deserialize)] #[serde(rename = "Polyline")] struct PolyChainSerde { points: Vec<[f64; 2]>, diff --git a/crates/fj/src/sweep.rs b/crates/fj/src/sweep.rs index 32153a016..5e13cd078 100644 --- a/crates/fj/src/sweep.rs +++ b/crates/fj/src/sweep.rs @@ -1,11 +1,8 @@ -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; - use crate::{Shape, Shape2d}; /// A sweep of a 2-dimensional shape along straight path #[derive(Clone, Debug, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[repr(C)] pub struct Sweep { /// The 2-dimensional shape being swept diff --git a/crates/fj/src/transform.rs b/crates/fj/src/transform.rs index aebc14646..c86a22a22 100644 --- a/crates/fj/src/transform.rs +++ b/crates/fj/src/transform.rs @@ -1,6 +1,3 @@ -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; - use crate::{Angle, Shape}; /// A transformed 3-dimensional shape @@ -13,7 +10,7 @@ use crate::{Angle, Shape}; /// See issue: /// #[derive(Clone, Debug, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[repr(C)] pub struct Transform { /// The shape being transformed From 8a231eee9199874b0d023d38b8605a1e204f799d Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 11 Oct 2022 14:48:44 +0200 Subject: [PATCH 3/7] Document convenient syntax for `fj::Group` --- crates/fj/src/group.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/crates/fj/src/group.rs b/crates/fj/src/group.rs index 8bcdf2389..d675e2761 100644 --- a/crates/fj/src/group.rs +++ b/crates/fj/src/group.rs @@ -5,6 +5,19 @@ use crate::Shape; /// A group is a collection of disjoint shapes. It is not a union, in that the /// shapes in the group are not allowed to touch or overlap. /// +/// # Examples +/// +/// Convenient syntax for this operation is available through [`crate::syntax`]. +/// +/// ``` rust +/// # let a = fj::Sketch::from_points(vec![[0., 0.], [1., 0.], [0., 1.]]); +/// # let b = fj::Sketch::from_points(vec![[2., 0.], [3., 0.], [2., 1.]]); +/// use fj::syntax::*; +/// +/// // `a` and `b` can be anything that converts to `fj::Shape` +/// let group = a.group(&b); +/// ``` +/// /// # Limitations /// /// Whether the shapes in the group touch or overlap is not currently checked. From 7f1bba7e981ec373796a82f0871f86861f9fd814 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 11 Oct 2022 14:50:55 +0200 Subject: [PATCH 4/7] Document convenient syntax of `fj::Sweep` --- crates/fj/src/sweep.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/fj/src/sweep.rs b/crates/fj/src/sweep.rs index 5e13cd078..14b805ebb 100644 --- a/crates/fj/src/sweep.rs +++ b/crates/fj/src/sweep.rs @@ -1,6 +1,18 @@ use crate::{Shape, Shape2d}; /// A sweep of a 2-dimensional shape along straight path +/// +/// # Examples +/// +/// Convenient syntax for this operation is available through [`crate::syntax`]. +/// +/// ``` rust +/// # let shape = fj::Sketch::from_points(vec![[0., 0.], [1., 0.], [0., 1.]]); +/// use fj::syntax::*; +/// +/// // `shape` can be anything that converts to `fj::Shape2d` +/// let group = shape.sweep([0., 0., 1.]); +/// ``` #[derive(Clone, Debug, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[repr(C)] From 5013127e17fa48b1a032f71757ecb6c5c3c73191 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 11 Oct 2022 14:52:12 +0200 Subject: [PATCH 5/7] Document convenient syntax for `fj::Difference2d` --- crates/fj/src/shape_2d.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/crates/fj/src/shape_2d.rs b/crates/fj/src/shape_2d.rs index 1063fdcde..b632c2fa2 100644 --- a/crates/fj/src/shape_2d.rs +++ b/crates/fj/src/shape_2d.rs @@ -26,6 +26,19 @@ impl Shape2d { } /// A difference between two shapes +/// +/// # Examples +/// +/// Convenient syntax for this operation is available through [`crate::syntax`]. +/// +/// ``` rust +/// # let a = fj::Sketch::from_points(vec![[0., 0.], [1., 0.], [0., 1.]]); +/// # let b = fj::Sketch::from_points(vec![[2., 0.], [3., 0.], [2., 1.]]); +/// use fj::syntax::*; +/// +/// // `a` and `b` can be anything that converts to `fj::Shape2d` +/// let difference = a.difference(&b); +/// ``` #[derive(Clone, Debug, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[repr(C)] From a9d5afdcbd7f55a7478a2461c0756f3c200d9d88 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 11 Oct 2022 14:53:24 +0200 Subject: [PATCH 6/7] Document convenient syntax for `fj::Sketch` --- crates/fj/src/shape_2d.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/fj/src/shape_2d.rs b/crates/fj/src/shape_2d.rs index b632c2fa2..eace76646 100644 --- a/crates/fj/src/shape_2d.rs +++ b/crates/fj/src/shape_2d.rs @@ -84,6 +84,17 @@ impl From for Shape2d { /// Nothing about these edges is checked right now, but algorithms might assume /// that the edges are non-overlapping. If you create a `Sketch` with /// overlapping edges, you're on your own. +/// +/// # Examples +/// +/// Convenient syntax for this operation is available through [`crate::syntax`]. +/// +/// ``` rust +/// use fj::syntax::*; +/// +/// // `a` and `b` can be anything that converts to `fj::Shape` +/// let sketch = [[0., 0.], [1., 0.], [0., 1.]].sketch(); +/// ``` #[derive(Clone, Debug, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[repr(C)] From 0c0c6c155f2e812986ff5b162fd4cbbbe99fff35 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 11 Oct 2022 14:55:46 +0200 Subject: [PATCH 7/7] Document convenient syntax for `fj::Transform` --- crates/fj/src/transform.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/crates/fj/src/transform.rs b/crates/fj/src/transform.rs index c86a22a22..c388d141c 100644 --- a/crates/fj/src/transform.rs +++ b/crates/fj/src/transform.rs @@ -2,6 +2,19 @@ use crate::{Angle, Shape}; /// A transformed 3-dimensional shape /// +/// # Examples +/// +/// Convenient syntax for this operation is available through [`crate::syntax`]. +/// +/// ``` rust +/// # let shape = fj::Sketch::from_points(vec![[0., 0.], [1., 0.], [0., 1.]]); +/// use fj::syntax::*; +/// +/// // `shape` can be anything that converts to `fj::Shape` +/// let rotated = shape.rotate([0., 0., 1.], fj::Angle::from_rev(0.5)); +/// let translated = shape.translate([1., 2., 3.]); +/// ``` +/// /// # Limitations /// /// Transformations are currently limited to a rotation, followed by a