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
use Construct;
use Count;
use ToIndex;
use ToPos;
use Zero;
impl<T, U> Construct for (T, U)
where T: Construct,
U: Construct
{
fn new() -> (T, U) {
(Construct::new(), Construct::new())
}
}
impl<T, U, V, W> Count<(V, W)> for (T, U)
where T: Construct + Count<V>,
U: Construct + Count<W>
{
fn count(&self, &(ref dim_t, ref dim_u): &(V, W)) -> usize {
let t: T = Construct::new();
let u: U = Construct::new();
t.count(dim_t) * u.count(dim_u)
}
}
impl<T, U, V, W, X, Y> Zero<(V, W), (X, Y)> for (T, U)
where T: Construct + Zero<V, X>,
U: Construct + Zero<W, Y>
{
fn zero(&self, &(ref dim_t, ref dim_u): &(V, W)) -> (X, Y) {
let t: T = Construct::new();
let u: U = Construct::new();
(t.zero(dim_t), u.zero(dim_u))
}
}
impl<T, U, V, W, X, Y> ToIndex<(V, W), (X, Y)> for (T, U)
where T: Construct + ToIndex<V, X>,
U: Construct + Count<W> + ToIndex<W, Y>
{
fn to_index(
&self,
&(ref dim_t, ref dim_u): &(V, W),
&(ref pt, ref pu): &(X, Y)
) -> usize {
let t: T = Construct::new();
let u: U = Construct::new();
let count = u.count(dim_u);
t.to_index(dim_t, pt) * count + u.to_index(dim_u, pu)
}
}
impl<T, U, V, W, X, Y> ToPos<(V, W), (X, Y)> for (T, U)
where T: Construct + ToPos<V, X>,
U: Construct + Count<W> + ToPos<W, Y>
{
fn to_pos(
&self,
&(ref dim_t, ref dim_u): &(V, W),
ind: usize,
&mut (ref mut pt, ref mut pu): &mut (X, Y)
) {
let t: T = Construct::new();
let u: U = Construct::new();
let count = u.count(dim_u);
let x = ind / count;
t.to_pos(dim_t, x, pt);
u.to_pos(dim_u, ind - x * count, pu);
}
}