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
#![warn(missing_docs)]
pub mod shape_processor;
mod difference_2d;
mod group;
mod sketch;
mod sweep;
mod transform;
use fj_interop::debug::DebugInfo;
use fj_kernel::{
algorithms::Tolerance,
objects::{Face, Sketch},
validation::{validate, Validated, ValidationConfig, ValidationError},
};
use fj_math::Aabb;
pub trait Shape {
type Brep;
fn compute_brep(
&self,
config: &ValidationConfig,
tolerance: Tolerance,
debug_info: &mut DebugInfo,
) -> Result<Validated<Self::Brep>, ValidationError>;
fn bounding_volume(&self) -> Aabb<3>;
}
impl Shape for fj::Shape {
type Brep = Vec<Face>;
fn compute_brep(
&self,
config: &ValidationConfig,
tolerance: Tolerance,
debug_info: &mut DebugInfo,
) -> Result<Validated<Self::Brep>, ValidationError> {
match self {
Self::Shape2d(shape) => validate(
shape
.compute_brep(config, tolerance, debug_info)?
.into_inner()
.into_faces()
.collect(),
config,
),
Self::Group(shape) => {
shape.compute_brep(config, tolerance, debug_info)
}
Self::Sweep(shape) => validate(
shape
.compute_brep(config, tolerance, debug_info)?
.into_inner()
.into_faces()
.collect(),
config,
),
Self::Transform(shape) => {
shape.compute_brep(config, tolerance, debug_info)
}
}
}
fn bounding_volume(&self) -> Aabb<3> {
match self {
Self::Shape2d(shape) => shape.bounding_volume(),
Self::Group(shape) => shape.bounding_volume(),
Self::Sweep(shape) => shape.bounding_volume(),
Self::Transform(shape) => shape.bounding_volume(),
}
}
}
impl Shape for fj::Shape2d {
type Brep = Sketch;
fn compute_brep(
&self,
config: &ValidationConfig,
tolerance: Tolerance,
debug_info: &mut DebugInfo,
) -> Result<Validated<Self::Brep>, ValidationError> {
match self {
Self::Difference(shape) => {
shape.compute_brep(config, tolerance, debug_info)
}
Self::Sketch(shape) => {
shape.compute_brep(config, tolerance, debug_info)
}
}
}
fn bounding_volume(&self) -> Aabb<3> {
match self {
Self::Difference(shape) => shape.bounding_volume(),
Self::Sketch(shape) => shape.bounding_volume(),
}
}
}