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
// SPDX-License-Identifier: ISC
use crate::point::Point3;
use crate::value::GroupValue;
/// A 3DFACE entity — a filled 3- or 4-sided face.
#[derive(Debug, Clone, Copy, Default)]
pub struct Face3d {
/// First corner.
pub first_corner: Point3,
/// Second corner.
pub second_corner: Point3,
/// Third corner.
pub third_corner: Point3,
/// Fourth corner.
///
/// Copied from the third corner if only three vertices were given.
pub fourth_corner: Point3,
/// Invisible edge flags.
pub invisible_edge_flags: i16,
/// Whether the fourth corner was explicitly set.
has_fourth: bool,
}
impl Face3d {
pub(crate) fn feed(&mut self, code: u16, val: &GroupValue) {
if code == 70 {
if let Some(v) = val.as_i16() {
self.invisible_edge_flags = v;
}
return;
}
if let Some(v) = val.as_f64() {
match code {
10 => self.first_corner.x = v,
20 => self.first_corner.y = v,
30 => self.first_corner.z = v,
11 => self.second_corner.x = v,
21 => self.second_corner.y = v,
31 => self.second_corner.z = v,
12 => self.third_corner.x = v,
22 => self.third_corner.y = v,
32 => self.third_corner.z = v,
13 => {
self.fourth_corner.x = v;
self.has_fourth = true;
}
23 => {
self.fourth_corner.y = v;
self.has_fourth = true;
}
33 => {
self.fourth_corner.z = v;
self.has_fourth = true;
}
_ => {}
}
}
}
/// Finalizes the face: if only 3 vertices were given, copies the third to the fourth.
pub(crate) fn finish(&mut self) {
if !self.has_fourth {
self.fourth_corner = self.third_corner;
}
}
}