added mirror function to structure

This commit is contained in:
Niklas Kapelle 2023-11-19 01:43:58 +01:00
parent 9bb6b8bf2b
commit 1d2a43155a
Signed by: niklas
GPG Key ID: 4EB651B36D841D16

View File

@ -14,6 +14,14 @@ abstract Structure(Array<Layer>) from Array<Layer> {
public function rotate():Structure { public function rotate():Structure {
return [for (i in 0...height()) this[i].rotate()]; return [for (i in 0...height()) this[i].rotate()];
} }
public function mirrorX():Structure {
return [for (i in 0...height()) this[i].mirrorX()];
}
public function mirrorY():Structure {
return [for (i in 0...height()) this[i].mirrorY()];
}
} }
abstract Layer(Array<Array<Block>>) from Array<Array<Block>> { abstract Layer(Array<Array<Block>>) from Array<Array<Block>> {
@ -65,4 +73,28 @@ abstract Layer(Array<Array<Block>>) from Array<Array<Block>> {
return rotatedMatrix; return rotatedMatrix;
} }
public function mirrorX():Layer {
var rtn = [];
for (y in 0...height()) {
var rev = this[y].copy();
rev.reverse();
rtn.push(rev);
}
return rtn;
}
public function mirrorY():Layer {
var rtn = [for (_ in 0...height()) []];
for (y in 0...height()) {
for (x in 0...width()) {
rtn[height() - 1 - y][x] = get(x, y);
}
}
return rtn;
}
} }