-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmatrix.hpp
More file actions
70 lines (55 loc) · 1.36 KB
/
matrix.hpp
File metadata and controls
70 lines (55 loc) · 1.36 KB
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
#ifndef __MATRIX_HPP__
#define __MATRIX_HPP__
template <typename M>
struct base;
template <typename M1, typename M2>
struct mat_mat_add : public base<mat_mat_add<M1, M2> >
{
const M1 &m1;
const M2 &m2;
mat_mat_add(const M1 &m1_, const M2 &m2_) : m1(m1_), m2(m2_)
{ }
float operator()(unsigned int row, unsigned int col) const
{
return m1(row, col) + m2(row, col);
}
};
template <typename M1, typename M2>
struct mat_mat_sub : public base<mat_mat_sub<M1, M2> >
{
const M1 &m1;
const M2 &m2;
mat_mat_sub(const M1 &m1_, const M2 &m2_) : m1(m1_), m2(m2_)
{ }
float operator()(unsigned int row, unsigned int col) const
{
return m1(row, col) - m2(row, col);
}
};
template <typename M>
struct base
{
typedef M CHILD_TYPE;
template <typename OTHER_TYPE>
mat_mat_add<CHILD_TYPE, OTHER_TYPE> operator+(const OTHER_TYPE &other)
{
return mat_mat_add<CHILD_TYPE, OTHER_TYPE>(static_cast<CHILD_TYPE&>(*this), other);
}
template <typename OTHER_TYPE>
mat_mat_sub<CHILD_TYPE, OTHER_TYPE> operator-(const OTHER_TYPE &other)
{
return mat_mat_sub<CHILD_TYPE, OTHER_TYPE>(static_cast<CHILD_TYPE&>(*this), other);
}
};
struct matrix : public base<matrix>
{
float *data;
matrix(float *data_) : data(data_)
{
}
float operator()(unsigned int row, unsigned int col) const
{
return data[row * 3 + col];
}
};
#endif