From 0fddae5cc702ab502ea26129c0d4f01bec3aa250 Mon Sep 17 00:00:00 2001 From: Daniel Brunner <0xFEEDC0DE64@gmail.com> Date: Sun, 20 Aug 2017 19:05:52 +0200 Subject: [PATCH] Implemented mirrorHorizontally() and mirrorVertically() --- fixedsizematrix.h | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/fixedsizematrix.h b/fixedsizematrix.h index 1f3749a..b38a52e 100644 --- a/fixedsizematrix.h +++ b/fixedsizematrix.h @@ -3,6 +3,7 @@ #include #include +#include template class FixedSizeMatrix @@ -108,19 +109,33 @@ void FixedSizeMatrix::rotateRight() template void FixedSizeMatrix::rotate180() { - //TODO + //for(unsigned int y = 0; y < height / 2; y++) + // for(unsigned int x = 0; x < width; x++) + // std::swap(m_data[height-y-1][width-x-1], m_data[y][x]); + + mirrorHorizontally(); + mirrorVertically(); } template void FixedSizeMatrix::mirrorHorizontally() { - //TODO + //for(unsigned int y = 0; y < height / 2; y++) + // for(unsigned int x = 0; x < width; x++) + // std::swap(m_data[height-y-1][x], m_data[y][x]); + + std::reverse(std::begin(m_data), std::end(m_data)); } template void FixedSizeMatrix::mirrorVertically() { - //TODO + //for(unsigned int y = 0; y < height; y++) + // for(unsigned int x = 0; x < width / 2; x++) + // std::swap(m_data[y][width-x-1], m_data[y][x]); + + for(unsigned int y = 0; y < height; y++) + std::reverse(std::begin(m_data[y]), std::end(m_data[y])); } template