triangulate/outputs/
fan.rs

1/// A triangle fan with vertices of type `V`
2pub trait Fan<V> {
3    /// Initialize the fan with a single triangle.
4    fn new(v0: V, v1: V, v2: V) -> Self;
5
6    /// Add another triangle to the fan, specifying only the newly added vertex `v`
7    fn push(&mut self, v: V);
8}
9
10impl<V> Fan<V> for Vec<V> {
11    fn new(v0: V, v1: V, v2: V) -> Self {
12        vec![v0, v1, v2]
13    }
14
15    fn push(&mut self, v: V) {
16        self.push(v)
17    }
18}
19
20/// A collection of multiple [Fan]s.
21pub trait Fans {
22    /// The type of the individual [Fan]s
23    type Fan;
24
25    /// The number of [Fan]s
26    fn len(&self) -> usize;
27
28    /// Remove newly added [Fan]s until there are only `len` remaining
29    fn truncate(&mut self, len: usize);
30
31    /// Add a new [Fan]
32    fn push(&mut self, fan: Self::Fan);
33
34    /// Returns `true` if the collection contains no [Fan]s
35    fn is_empty(&self) -> bool {
36        self.len() == 0
37    }
38}
39
40impl<F> Fans for Vec<F> {
41    type Fan = F;
42
43    fn len(&self) -> usize {
44        self.len()
45    }
46
47    fn truncate(&mut self, len: usize) {
48        self.truncate(len)
49    }
50
51    fn push(&mut self, fan: Self::Fan) {
52        self.push(fan)
53    }
54}
55
56impl<FS: Fans> Fans for &mut FS {
57    type Fan = FS::Fan;
58
59    fn len(&self) -> usize {
60        (**self).len()
61    }
62
63    fn truncate(&mut self, len: usize) {
64        (**self).truncate(len)
65    }
66
67    fn push(&mut self, fan: Self::Fan) {
68        (**self).push(fan)
69    }
70}