From 1d2a43155a11767b7311b5157fd955176ca1c405 Mon Sep 17 00:00:00 2001 From: Niklas Kapelle Date: Sun, 19 Nov 2023 01:43:58 +0100 Subject: [PATCH] added mirror function to structure --- src/lib/turtle/Structure.hx | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/lib/turtle/Structure.hx b/src/lib/turtle/Structure.hx index 74756ca..2b47d9c 100644 --- a/src/lib/turtle/Structure.hx +++ b/src/lib/turtle/Structure.hx @@ -14,6 +14,14 @@ abstract Structure(Array) from Array { public function rotate():Structure { 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>) from Array> { @@ -65,4 +73,28 @@ abstract Layer(Array>) from Array> { 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; + } }