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 std::marker::PhantomData;
use std::ops::Range;
pub trait SharedVertex<V>: Sized {
fn shared_vertex(&self, i: usize) -> V;
fn shared_vertex_count(&self) -> usize;
fn shared_vertex_iter<'a>(&'a self) -> SharedVertexIterator<'a, Self, V> {
SharedVertexIterator {
base: self,
idx: 0..self.shared_vertex_count(),
phantom_v: PhantomData,
}
}
}
pub struct SharedVertexIterator<'a, T: 'a, V> {
base: &'a T,
idx: Range<usize>,
phantom_v: PhantomData<V>,
}
impl<'a, T: SharedVertex<V>, V> Iterator for SharedVertexIterator<'a, T, V> {
type Item = V;
fn size_hint(&self) -> (usize, Option<usize>) {
self.idx.size_hint()
}
fn next(&mut self) -> Option<V> {
self.idx.next().map(|idx| self.base.shared_vertex(idx))
}
}
pub trait IndexedPolygon<V>: Sized {
fn indexed_polygon(&self, i: usize) -> V;
fn indexed_polygon_count(&self) -> usize;
fn indexed_polygon_iter<'a>(&'a self) -> IndexedPolygonIterator<'a, Self, V> {
IndexedPolygonIterator {
base: self,
idx: 0..self.indexed_polygon_count(),
phantom_v: PhantomData,
}
}
}
pub struct IndexedPolygonIterator<'a, T: 'a, V> {
base: &'a T,
idx: Range<usize>,
phantom_v: PhantomData<V>,
}
impl<'a, T: IndexedPolygon<V>, V> Iterator for IndexedPolygonIterator<'a, T, V> {
type Item = V;
fn size_hint(&self) -> (usize, Option<usize>) {
self.idx.size_hint()
}
fn next(&mut self) -> Option<V> {
self.idx.next().map(|idx| self.base.indexed_polygon(idx))
}
}