Simplify imports

This commit is contained in:
Hanno Braun 2022-10-11 14:40:19 +02:00
parent da4705fe74
commit 58eaff523f
6 changed files with 15 additions and 30 deletions

View File

@ -1,5 +1,3 @@
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use std::f64::consts::{PI, TAU}; use std::f64::consts::{PI, TAU};
// One gon in radians // One gon in radians
@ -7,7 +5,7 @@ const GON_RAD: f64 = PI / 200.;
/// An angle /// An angle
#[derive(Copy, Clone, Debug, PartialEq)] #[derive(Copy, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Angle { pub struct Angle {
// The value of the angle in radians // The value of the angle in radians
rad: f64, rad: f64,

View File

@ -1,6 +1,3 @@
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use crate::Shape; use crate::Shape;
/// A group of two 3-dimensional shapes /// 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. /// Whether the shapes in the group touch or overlap is not currently checked.
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(C)] #[repr(C)]
pub struct Group { pub struct Group {
/// The first of the shapes /// The first of the shapes

View File

@ -33,12 +33,10 @@ pub use self::{
angle::*, group::Group, shape_2d::*, sweep::Sweep, transform::Transform, angle::*, group::Group, shape_2d::*, sweep::Sweep, transform::Transform,
}; };
pub use fj_proc::*; pub use fj_proc::*;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
/// A shape /// A shape
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(C)] #[repr(C)]
pub enum Shape { pub enum Shape {
/// A group of two 3-dimensional shapes /// A group of two 3-dimensional shapes

View File

@ -1,5 +1,3 @@
#[cfg(feature = "serde")]
use serde::{de, ser, Deserialize, Serialize};
use std::mem; use std::mem;
use std::sync::atomic; use std::sync::atomic;
@ -7,7 +5,7 @@ use crate::Shape;
/// A 2-dimensional shape /// A 2-dimensional shape
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(C)] #[repr(C)]
pub enum Shape2d { pub enum Shape2d {
/// A difference between two shapes /// A difference between two shapes
@ -29,7 +27,7 @@ impl Shape2d {
/// A difference between two shapes /// A difference between two shapes
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(C)] #[repr(C)]
pub struct Difference2d { pub struct Difference2d {
shapes: [Shape2d; 2], shapes: [Shape2d; 2],
@ -74,7 +72,7 @@ impl From<Difference2d> for Shape2d {
/// that the edges are non-overlapping. If you create a `Sketch` with /// that the edges are non-overlapping. If you create a `Sketch` with
/// overlapping edges, you're on your own. /// overlapping edges, you're on your own.
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(C)] #[repr(C)]
pub struct Sketch { pub struct Sketch {
chain: Chain, chain: Chain,
@ -119,7 +117,7 @@ impl Sketch {
/// A chain of elements that is part of a [`Sketch`] /// A chain of elements that is part of a [`Sketch`]
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(C)] #[repr(C)]
pub enum Chain { pub enum Chain {
/// The chain is a circle /// The chain is a circle
@ -131,7 +129,7 @@ pub enum Chain {
/// A circle that is part of a [`Sketch`] /// A circle that is part of a [`Sketch`]
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(C)] #[repr(C)]
pub struct Circle { pub struct Circle {
/// The radius of the circle /// The radius of the circle
@ -267,10 +265,10 @@ impl Drop for PolyChain {
unsafe impl Send for PolyChain {} unsafe impl Send for PolyChain {}
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
impl ser::Serialize for PolyChain { impl serde::ser::Serialize for PolyChain {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where where
S: ser::Serializer, S: serde::ser::Serializer,
{ {
let serde_sketch = PolyChainSerde { let serde_sketch = PolyChainSerde {
points: self.to_points(), points: self.to_points(),
@ -281,10 +279,10 @@ impl ser::Serialize for PolyChain {
} }
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
impl<'de> de::Deserialize<'de> for PolyChain { impl<'de> serde::de::Deserialize<'de> for PolyChain {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where where
D: de::Deserializer<'de>, D: serde::de::Deserializer<'de>,
{ {
PolyChainSerde::deserialize(deserializer) PolyChainSerde::deserialize(deserializer)
.map(|serde_sketch| PolyChain::from_points(serde_sketch.points)) .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 /// [`PolyChain`]. If de/serialization turns out to be a bottleneck, a more
/// complete implementation will be required. /// complete implementation will be required.
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
#[derive(Serialize, Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]
#[serde(rename = "Polyline")] #[serde(rename = "Polyline")]
struct PolyChainSerde { struct PolyChainSerde {
points: Vec<[f64; 2]>, points: Vec<[f64; 2]>,

View File

@ -1,11 +1,8 @@
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use crate::{Shape, Shape2d}; use crate::{Shape, Shape2d};
/// A sweep of a 2-dimensional shape along straight path /// A sweep of a 2-dimensional shape along straight path
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(C)] #[repr(C)]
pub struct Sweep { pub struct Sweep {
/// The 2-dimensional shape being swept /// The 2-dimensional shape being swept

View File

@ -1,6 +1,3 @@
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use crate::{Angle, Shape}; use crate::{Angle, Shape};
/// A transformed 3-dimensional shape /// A transformed 3-dimensional shape
@ -13,7 +10,7 @@ use crate::{Angle, Shape};
/// See issue: /// See issue:
/// <https://github.com/hannobraun/Fornjot/issues/101> /// <https://github.com/hannobraun/Fornjot/issues/101>
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(C)] #[repr(C)]
pub struct Transform { pub struct Transform {
/// The shape being transformed /// The shape being transformed