-
-
Notifications
You must be signed in to change notification settings - Fork 119
/
face.rs
82 lines (74 loc) · 2.89 KB
/
face.rs
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
use fj_math::Winding;
use crate::{
objects::{Region, Surface},
storage::Handle,
};
/// A face of a shape
///
/// A `Face` is a bounded area of a [`Surface`], the [`Surface`] itself being an
/// infinite 2-dimensional object in 3D space. `Face`s are bound by one exterior
/// cycle, which defines the outer boundary, and an arbitrary number of interior
/// cycles (i.e. holes).
///
/// `Face` has a defined orientation, a front and a back side. When faces are
/// combined into [`Shell`]s, the face orientation defines what is inside and
/// outside of the shell. This stands in contrast to [`Surface`], which has no
/// defined orientation.
///
/// You can look at a `Face` from two directions: front and back. The winding of
/// the exterior cycle will be clockwise or counter-clockwise, depending on your
/// perspective. The front side of the face, is the side where from which the
/// exterior cycle appear counter-clockwise.
///
/// Interior cycles must have the opposite winding of the exterior cycle,
/// meaning on the front side of the face, they must appear clockwise. This
/// means that all [`HalfEdge`]s that bound a `Face` have the interior of the
/// face on their left side (on the face's front side).
///
/// [`HalfEdge`]: crate::objects::HalfEdge
/// [`Shell`]: crate::objects::Shell
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct Face {
surface: Handle<Surface>,
region: Handle<Region>,
}
impl Face {
/// Construct an instance of `Face`
pub fn new(surface: Handle<Surface>, region: Handle<Region>) -> Self {
Self { surface, region }
}
/// Access the surface of the face
pub fn surface(&self) -> &Handle<Surface> {
&self.surface
}
/// Access the region of the face
pub fn region(&self) -> &Handle<Region> {
&self.region
}
/// Determine handed-ness of the face's front-side coordinate system
///
/// A face is defined on a surface, which has a coordinate system. Since
/// surfaces aren't considered to have an orientation, their coordinate
/// system can be considered to be left-handed or right-handed, depending on
/// which side of the surface you're looking at.
///
/// Faces *do* have an orientation, meaning they have definite front and
/// back sides. The front side is the side, where the face's exterior cycle
/// is wound counter-clockwise.
pub fn coord_handedness(&self) -> Handedness {
match self.region.exterior().winding() {
Winding::Ccw => Handedness::RightHanded,
Winding::Cw => Handedness::LeftHanded,
}
}
}
/// The handedness of a face's coordinate system
///
/// See [`Face::coord_handedness`].
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub enum Handedness {
/// The face's coordinate system is left-handed
LeftHanded,
/// The face's coordinate system is right-handed
RightHanded,
}