init versie
This commit is contained in:
+33
@@ -0,0 +1,33 @@
|
||||
#ifndef MATRIX2D_H
|
||||
#define MATRIX2D_H
|
||||
|
||||
|
||||
template <typename T>
|
||||
class Matrix2D {
|
||||
std::vector<T> data;
|
||||
unsigned int sizeX, sizeY;
|
||||
public:
|
||||
Matrix2D (unsigned int x, unsigned int y)
|
||||
: sizeX (x), sizeY (y) {
|
||||
data.resize (sizeX*sizeY);
|
||||
}
|
||||
|
||||
T& operator()( int x, int y) {
|
||||
if (x >= (int) sizeX )
|
||||
x-= sizeX;
|
||||
if (x < 0 )
|
||||
x+= sizeX;
|
||||
if (y<0) y=0;
|
||||
if (y >= (int) sizeY )
|
||||
y =sizeY-1;
|
||||
//if (y>= sizeY || y<0)
|
||||
// throw std::out_of_range("OOB access"); // Throw something more appropriate
|
||||
return data[sizeX*y + x]; // Stride-aware access
|
||||
}
|
||||
|
||||
T* row(unsigned int y) {
|
||||
if (y >= sizeY) y = sizeY - 1;
|
||||
return &data[sizeX * y];
|
||||
}
|
||||
};
|
||||
#endif // MATRIX2D_H
|
||||
Reference in New Issue
Block a user