#ifndef FIXEDSIZEMATRIX_H #define FIXEDSIZEMATRIX_H #include #include template class FixedSizeMatrix { public: FixedSizeMatrix(); FixedSizeMatrix(const std::array, height> &data); FixedSizeMatrix(const FixedSizeMatrix &other); FixedSizeMatrix& operator=(const FixedSizeMatrix& other); FixedSizeMatrix& operator=(const std::array, height> &data); bool operator==(const FixedSizeMatrix& other) const; bool operator!=(const FixedSizeMatrix& other) const; T& operator()(unsigned int x, unsigned int y); const T& operator()(unsigned int x, unsigned int y) const; const T& at(unsigned int x, unsigned int y); void set(unsigned int x, unsigned int y, const T &value); FixedSizeMatrix rotatedLeft() const; FixedSizeMatrix rotatedRight() const; FixedSizeMatrix rotated180() const; private: std::array, height> m_data; }; template FixedSizeMatrix::FixedSizeMatrix() {} template FixedSizeMatrix::FixedSizeMatrix(const std::array, height> &data) : m_data(data) {} template FixedSizeMatrix::FixedSizeMatrix(const FixedSizeMatrix &other) : m_data(other.m_data) {} template FixedSizeMatrix &FixedSizeMatrix::operator=(const FixedSizeMatrix &other) { if(&other != this) m_data = other.m_data; return *this; } template FixedSizeMatrix &FixedSizeMatrix::operator=(const std::array, height> &data) { m_data = data; return *this; } template bool FixedSizeMatrix::operator==(const FixedSizeMatrix &other) const { return m_data == other.m_data; } template bool FixedSizeMatrix::operator!=(const FixedSizeMatrix &other) const { return m_data != other.m_data; } template T &FixedSizeMatrix::operator()(unsigned int x, unsigned int y) { assert(x < width); assert(y < height); return m_data[y][x]; } template const T &FixedSizeMatrix::operator()(unsigned int x, unsigned int y) const { assert(x < width); assert(y < height); return m_data[y][x]; } template const T &FixedSizeMatrix::at(unsigned int x, unsigned int y) { assert(x < width); assert(y < height); return m_data[y][x]; } template void FixedSizeMatrix::set(unsigned int x, unsigned int y, const T &value) { assert(x < width); assert(y < height); m_data[y][x] = value; } template FixedSizeMatrix FixedSizeMatrix::rotatedLeft() const { std::array, width> data; for(unsigned int y = 0; y < height; y++) for(unsigned int x = 0; x < width; x++) data[width-x-1][y] = m_data[y][x]; return FixedSizeMatrix(data); } template FixedSizeMatrix FixedSizeMatrix::rotatedRight() const { std::array, width> data; for(unsigned int y = 0; y < height; y++) for(unsigned int x = 0; x < width; x++) data[x][height-y-1] = m_data[y][x]; return FixedSizeMatrix(data); } template FixedSizeMatrix FixedSizeMatrix::rotated180() const { std::array, height> data; for(unsigned int y = 0; y < height; y++) for(unsigned int x = 0; x < width; x++) data[height-y-1][width-x-1] = m_data[y][x]; return FixedSizeMatrix(data); } #endif // FIXEDSIZEMATRIX_H