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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
use std::collections::{btree_set, BTreeSet};
use fj_interop::mesh::Color;
use fj_math::Winding;
use crate::builder::FaceBuilder;
use super::{Cycle, Surface};
#[derive(Clone, Debug, Default, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct Faces {
inner: BTreeSet<Face>,
}
impl Faces {
pub fn new() -> Self {
Self::default()
}
pub fn find(&self, face: &Face) -> Option<Face> {
for f in self {
if f == face {
return Some(f.clone());
}
}
None
}
}
impl Extend<Face> for Faces {
fn extend<T: IntoIterator<Item = Face>>(&mut self, iter: T) {
self.inner.extend(iter)
}
}
impl IntoIterator for Faces {
type Item = Face;
type IntoIter = btree_set::IntoIter<Face>;
fn into_iter(self) -> Self::IntoIter {
self.inner.into_iter()
}
}
impl<'a> IntoIterator for &'a Faces {
type Item = &'a Face;
type IntoIter = btree_set::Iter<'a, Face>;
fn into_iter(self) -> Self::IntoIter {
self.inner.iter()
}
}
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct Face {
surface: Surface,
exterior: Cycle,
interiors: Vec<Cycle>,
color: Color,
}
impl Face {
pub fn build(surface: Surface) -> FaceBuilder {
FaceBuilder::new(surface)
}
pub fn new(surface: Surface, exterior: Cycle) -> Self {
Self {
surface,
exterior,
interiors: Vec::new(),
color: Color::default(),
}
}
pub fn with_interiors(
mut self,
interiors: impl IntoIterator<Item = Cycle>,
) -> Self {
for cycle in interiors.into_iter() {
assert_eq!(
self.surface(),
cycle.surface(),
"Cycles that bound a face must be in face's surface"
);
self.interiors.push(cycle);
}
self
}
pub fn with_color(mut self, color: Color) -> Self {
self.color = color;
self
}
pub fn surface(&self) -> &Surface {
&self.surface
}
pub fn exterior(&self) -> &Cycle {
&self.exterior
}
pub fn interiors(&self) -> impl Iterator<Item = &Cycle> + '_ {
self.interiors.iter()
}
pub fn all_cycles(&self) -> impl Iterator<Item = &Cycle> + '_ {
[self.exterior()].into_iter().chain(self.interiors())
}
pub fn color(&self) -> Color {
self.color
}
pub fn coord_handedness(&self) -> Handedness {
match self.exterior().winding() {
Winding::Ccw => Handedness::RightHanded,
Winding::Cw => Handedness::LeftHanded,
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub enum Handedness {
LeftHanded,
RightHanded,
}