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
135
136
137
138
139
140
141
142
use crate::{Shape, Shape2d};
#[derive(Clone, Debug)]
#[repr(C)]
pub enum Shape3d {
Difference(Box<Difference>),
Sweep(Sweep),
Transform(Box<Transform>),
Union(Box<Union>),
}
impl From<Shape3d> for Shape {
fn from(shape: Shape3d) -> Self {
Self::Shape3d(shape.into())
}
}
#[derive(Clone, Debug)]
#[repr(C)]
pub struct Difference {
pub a: Shape3d,
pub b: Shape3d,
}
impl From<Difference> for Shape {
fn from(shape: Difference) -> Self {
Self::Shape3d(Shape3d::Difference(Box::new(shape)))
}
}
impl From<Difference> for Shape3d {
fn from(shape: Difference) -> Self {
Self::Difference(Box::new(shape))
}
}
#[derive(Clone, Debug)]
#[repr(C)]
pub struct Transform {
pub shape: Shape3d,
pub axis: [f64; 3],
pub angle: f64,
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)]
#[repr(C)]
pub struct Sweep {
pub shape: Shape2d,
pub length: f64,
}
impl From<Sweep> for Shape {
fn from(shape: Sweep) -> Self {
Self::Shape3d(Shape3d::Sweep(shape))
}
}
impl From<Sweep> for Shape3d {
fn from(shape: Sweep) -> Self {
Self::Sweep(shape)
}
}
#[derive(Clone, Debug)]
#[repr(C)]
pub struct Union {
pub a: Shape3d,
pub b: Shape3d,
}
impl From<Union> for Shape {
fn from(shape: Union) -> Self {
Self::Shape3d(Shape3d::Union(Box::new(shape)))
}
}
impl From<Union> for Shape3d {
fn from(shape: Union) -> Self {
Self::Union(Box::new(shape))
}
}