diff options
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/utils')
-rw-r--r-- | src/main/java/kr/syeyoung/dungeonsguide/utils/ArrayUtils.java | 22 | ||||
-rw-r--r-- | src/main/java/kr/syeyoung/dungeonsguide/utils/ShortUtils.java | 8 |
2 files changed, 26 insertions, 4 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/utils/ArrayUtils.java b/src/main/java/kr/syeyoung/dungeonsguide/utils/ArrayUtils.java new file mode 100644 index 00000000..7b9e8b59 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/utils/ArrayUtils.java @@ -0,0 +1,22 @@ +package kr.syeyoung.dungeonsguide.utils; + +public class ArrayUtils { + public static int[][] rotateCounterClockwise(int[][] arr) { + int[][] res = new int[arr[0].length][arr.length]; + for(int y=0; y<arr.length; y++) { + for (int x = 0; x< arr[0].length; x++) { + res[res.length - x - 1][y] = arr[y][x]; + } + } + return res; + } + public static int[][] rotateClockwise(int[][] arr) { + int[][] res = new int[arr[0].length][arr.length]; + for(int y=0; y<arr.length; y++) { + for (int x = 0; x< arr[0].length; x++) { + res[x][res[0].length - y - 1] = arr[y][x]; + } + } + return res; + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/utils/ShortUtils.java b/src/main/java/kr/syeyoung/dungeonsguide/utils/ShortUtils.java index d7ce60c5..ffe306a4 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/utils/ShortUtils.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/utils/ShortUtils.java @@ -1,21 +1,21 @@ package kr.syeyoung.dungeonsguide.utils; public class ShortUtils { - public static short rotateClockwise(short integer) { + public static short rotateCounterClockwise(short integer) { int res = 0; for(int i=0; i<16; i++){ int x = i % 4; int y = i / 4; - res |= (integer >> i & 0x1) << (x*4 + y); + res |= (integer >> i & 0x1) << ((4-x-1)*4 + y); } return (short) (res & 0xFFFF); } - public static short rotateCounterClockwise(short integer) { + public static short rotateClockwise(short integer) { int res = 0; for(int i=0; i<16; i++){ int x = i % 4; int y = i / 4; - res |= (integer >> i & 0x1) << ((4-x-1) *4 +(4 - y - 1)); + res |= (integer >> i & 0x1) << (x *4 +(4 - y - 1)); } return (short) (res & 0xFFFF); } |