1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
use crate::{Angle, Shape, Shape2d};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[repr(C)]
pub enum Shape3d {
Group(Box<Group>),
Sweep(Sweep),
Transform(Box<Transform>),
}
impl From<Shape3d> for Shape {
fn from(shape: Shape3d) -> Self {
Self::Shape3d(shape)
}
}
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[repr(C)]
pub struct Group {
pub a: Shape3d,
pub b: Shape3d,
}
impl From<Group> for Shape {
fn from(shape: Group) -> Self {
Self::Shape3d(Shape3d::Group(Box::new(shape)))
}
}
impl From<Group> for Shape3d {
fn from(shape: Group) -> Self {
Self::Group(Box::new(shape))
}
}
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[repr(C)]
pub struct Transform {
pub shape: Shape3d,
pub axis: [f64; 3],
pub angle: Angle,
pub offset: [f64; 3],
}
impl From<Transform> for Shape {
fn from(shape: Transform) -> Self {
Self::Shape3d(Shape3d::Transform(Box::new(shape)))
}
}
impl From<Transform> for Shape3d {
fn from(shape: Transform) -> Self {
Self::Transform(Box::new(shape))
}
}
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[repr(C)]
pub struct Sweep {
shape: Shape2d,
path: [f64; 3],
}
impl Sweep {
pub fn from_path(shape: Shape2d, path: [f64; 3]) -> Self {
Self { shape, path }
}
pub fn shape(&self) -> &Shape2d {
&self.shape
}
pub fn path(&self) -> [f64; 3] {
self.path
}
}
impl From<Sweep> for Shape {
fn from(shape: Sweep) -> Self {
Self::Shape3d(shape.into())
}
}
impl From<Sweep> for Shape3d {
fn from(shape: Sweep) -> Self {
Self::Sweep(shape)
}
}