added rotate to Layer
This commit is contained in:
parent
ca79714e8d
commit
be89ca12bd
@ -39,4 +39,26 @@ abstract Layer(Array<Array<Block>>) from Array<Array<Block>> {
|
|||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function rotate():Layer {
|
||||||
|
// Transpose the matrix (swap rows and columns)
|
||||||
|
var transposedMatrix:Array<Array<Block>> = [];
|
||||||
|
for (columnIndex in 0...width()) {
|
||||||
|
var newRow:Array<Block> = [];
|
||||||
|
for (rowIndex in 0...height()) {
|
||||||
|
newRow.push(get(columnIndex, rowIndex));
|
||||||
|
}
|
||||||
|
transposedMatrix.push(newRow);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reverse the order of the columns
|
||||||
|
var rotatedMatrix:Array<Array<Block>> = [];
|
||||||
|
for (row in transposedMatrix) {
|
||||||
|
var rev = row.copy();
|
||||||
|
rev.reverse();
|
||||||
|
rotatedMatrix.push(rev);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rotatedMatrix;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user