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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
use fj_interop::mesh::Color;
use fj_math::Triangle;
use crate::builder::FaceBuilder;
use super::{Cycle, Surface};
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct Face {
representation: Representation,
}
impl Face {
pub fn build(surface: Surface) -> FaceBuilder {
FaceBuilder::new(surface)
}
pub fn new(surface: Surface) -> Self {
Self {
representation: Representation::BRep(BRep {
surface,
exteriors: Vec::new(),
interiors: Vec::new(),
color: Color::default(),
}),
}
}
pub fn from_triangles(triangles: TriRep) -> Self {
Self {
representation: Representation::TriRep(triangles),
}
}
pub fn with_exteriors(
mut self,
exteriors: impl IntoIterator<Item = Cycle>,
) -> Self {
for exterior in exteriors.into_iter() {
self.brep_mut().exteriors.push(exterior);
}
self
}
pub fn with_interiors(
mut self,
interiors: impl IntoIterator<Item = Cycle>,
) -> Self {
for interior in interiors.into_iter() {
self.brep_mut().interiors.push(interior);
}
self
}
pub fn with_color(mut self, color: Color) -> Self {
self.brep_mut().color = color;
self
}
pub fn surface(&self) -> &Surface {
&self.brep().surface
}
pub fn exteriors(&self) -> impl Iterator<Item = &Cycle> + '_ {
self.brep().exteriors.iter()
}
pub fn interiors(&self) -> impl Iterator<Item = &Cycle> + '_ {
self.brep().interiors.iter()
}
pub fn all_cycles(&self) -> impl Iterator<Item = &Cycle> + '_ {
self.exteriors().chain(self.interiors())
}
pub fn color(&self) -> Color {
self.brep().color
}
pub fn triangles(&self) -> Option<&TriRep> {
if let Representation::TriRep(triangles) = &self.representation {
return Some(triangles);
}
None
}
fn brep(&self) -> &BRep {
if let Representation::BRep(face) = &self.representation {
return face;
}
unreachable!()
}
fn brep_mut(&mut self) -> &mut BRep {
if let Representation::BRep(face) = &mut self.representation {
return face;
}
unreachable!()
}
}
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
enum Representation {
BRep(BRep),
TriRep(TriRep),
}
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
struct BRep {
surface: Surface,
exteriors: Vec<Cycle>,
interiors: Vec<Cycle>,
color: Color,
}
type TriRep = Vec<(Triangle<3>, Color)>;