Added code for rotation piece data 90 degrees and 270 degrees.

This commit is contained in:
David Vereb 2023-04-03 20:45:59 -04:00
parent 9da2be773a
commit 59bd17a0ec

View File

@ -357,6 +357,7 @@ PieceData RotatePieceData(const PieceData &data, Rotation rotation)
break; break;
}; };
// Step 2: Move it:
switch(rotation) switch(rotation)
{ {
default: default:
@ -364,11 +365,17 @@ PieceData RotatePieceData(const PieceData &data, Rotation rotation)
rtn = data; rtn = data;
break; break;
case Rotation::ROTATION_90: case Rotation::ROTATION_90:
rtn = data; for(size_t row = 0; row < data.size(); ++row)
// TODO(dev): {
// TODO(dev): x's become y's size_t opposite_row = data.size() - row - 1;
// TODO(dev): y's become max x - x's for(size_t col = 0; col < data[row].size(); ++col)
// TODO(dev): {
size_t opposite_col = data[opposite_row].size() - col - 1;
// NOTE(dev): x's become y's
// NOTE(dev): y's become max x - x's
rtn[col][opposite_row] = data[row][col];
}
}
break; break;
case Rotation::ROTATION_180: case Rotation::ROTATION_180:
for(size_t row = 0; row < data.size(); ++row) for(size_t row = 0; row < data.size(); ++row)
@ -382,11 +389,17 @@ PieceData RotatePieceData(const PieceData &data, Rotation rotation)
} }
break; break;
case Rotation::ROTATION_270: case Rotation::ROTATION_270:
rtn = data; for(size_t row = 0; row < data.size(); ++row)
// TODO(dev): {
// TODO(dev): I mean we could just rotate 90 & then 180, size_t opposite_row = data.size() - row - 1;
// TODO(dev): but that seems like the cheap way out. for(size_t col = 0; col < data[row].size(); ++col)
// TODO(dev): {
size_t opposite_col = data[opposite_row].size() - col - 1;
// NOTE(dev): x's become max y - y's
// NOTE(dev): y's become x's
rtn[opposite_col][row] = data[row][col];
}
}
break; break;
}; };