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
use std::fmt;
use std::fmt::Debug;
use std::hash::Hash;
use std::ops::Deref;
pub trait ID: Clone + Eq + Copy + Ord + Hash + Debug + Deref<Target = u32> {
unsafe fn new(val: u32) -> Self;
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub struct VertexID(u32);
impl ID for VertexID {
unsafe fn new(val: u32) -> VertexID {
VertexID(val)
}
}
impl Deref for VertexID {
type Target = u32;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl fmt::Display for VertexID {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.0)
}
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub struct HalfEdgeID(u32);
impl ID for HalfEdgeID {
unsafe fn new(val: u32) -> HalfEdgeID {
HalfEdgeID(val)
}
}
impl Deref for HalfEdgeID {
type Target = u32;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl fmt::Display for HalfEdgeID {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.0)
}
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub struct FaceID(u32);
impl ID for FaceID {
unsafe fn new(val: u32) -> FaceID {
FaceID(val)
}
}
impl Deref for FaceID {
type Target = u32;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl fmt::Display for FaceID {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.0)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_equality() {
unsafe {
let v0 = VertexID::new(0);
let v1 = VertexID::new(1);
let v1_ = VertexID::new(1);
assert!(v0 != v1);
assert!(v1 == v1_);
}
}
}