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
use super::{AttribDict, AttribValueCache};
use crate::mesh::topology::*;
pub trait AttribIndex<M>
where
Self: std::marker::Sized + Clone,
{
fn attrib_size(mesh: &M) -> usize;
fn attrib_dict(mesh: &M) -> &AttribDict<Self>;
fn attrib_dict_mut(mesh: &mut M) -> &mut AttribDict<Self>;
fn attrib_dict_and_cache_mut(
mesh: &mut M,
) -> (&mut AttribDict<Self>, Option<&mut AttribValueCache>);
}
macro_rules! impl_attrib_index {
($topo_attrib:ident, $type:ty) => {
pub trait $topo_attrib {
fn topo_attrib_size(&self) -> usize;
fn topo_attrib_dict(&self) -> &AttribDict<$type>;
fn topo_attrib_dict_mut(&mut self) -> &mut AttribDict<$type>;
fn topo_attrib_dict_and_cache_mut(
&mut self,
) -> (&mut AttribDict<$type>, Option<&mut AttribValueCache>);
}
impl<M: $topo_attrib> AttribIndex<M> for $type {
#[inline]
fn attrib_size(mesh: &M) -> usize {
mesh.topo_attrib_size()
}
#[inline]
fn attrib_dict(mesh: &M) -> &AttribDict<Self> {
mesh.topo_attrib_dict()
}
#[inline]
fn attrib_dict_mut(mesh: &mut M) -> &mut AttribDict<Self> {
mesh.topo_attrib_dict_mut()
}
#[inline]
fn attrib_dict_and_cache_mut(
mesh: &mut M,
) -> (&mut AttribDict<Self>, Option<&mut AttribValueCache>) {
mesh.topo_attrib_dict_and_cache_mut()
}
}
};
}
impl_attrib_index!(MeshAttrib, MeshIndex);
impl_attrib_index!(VertexAttrib, VertexIndex);
impl_attrib_index!(EdgeAttrib, EdgeIndex);
impl_attrib_index!(FaceAttrib, FaceIndex);
impl_attrib_index!(CellAttrib, CellIndex);
impl_attrib_index!(EdgeVertexAttrib, EdgeVertexIndex);
impl_attrib_index!(FaceVertexAttrib, FaceVertexIndex);
impl_attrib_index!(FaceEdgeAttrib, FaceEdgeIndex);
impl_attrib_index!(CellVertexAttrib, CellVertexIndex);
impl_attrib_index!(CellEdgeAttrib, CellEdgeIndex);
impl_attrib_index!(CellFaceAttrib, CellFaceIndex);
impl_attrib_index!(VertexEdgeAttrib, VertexEdgeIndex);
impl_attrib_index!(VertexFaceAttrib, VertexFaceIndex);
impl_attrib_index!(VertexCellAttrib, VertexCellIndex);
impl_attrib_index!(EdgeFaceAttrib, EdgeFaceIndex);
impl_attrib_index!(EdgeCellAttrib, EdgeCellIndex);
impl_attrib_index!(FaceCellAttrib, FaceCellIndex);