package dev.llan.model.board.generation;
import dev.llan.model.board.Point;
public enum Direction {
UP(true, 0, 0, -1),
DOWN(true, 1, 0, 1),
LEFT(false, 2, -1, 0),
RIGHT(false, 3, 1, 0);
private boolean isVertical;
private int xCol;
private int yRow;
private int index;
Direction(boolean isVertical, int index, int xCol, int yRow) {
this.isVertical = isVertical;
this.index = index;
this.xCol = xCol;
this.yRow = yRow;
}
public boolean isVertical() {
return isVertical;
}
public int getIndex() {
return index;
}
public Direction rotate90Clockwise() {
return switch(this) {
case LEFT -> Direction.UP;
case UP -> Direction.RIGHT;
case RIGHT -> Direction.DOWN;
case DOWN -> Direction.LEFT;
};
}
public Direction invert() {
return switch(this) {
case LEFT -> Direction.RIGHT;
case RIGHT -> Direction.LEFT;
case UP -> Direction.DOWN;
case DOWN -> Direction.UP;
};
}
public int getY() {
return yRow;
}
public int getX() {
return xCol;
}
public static Direction getFromTranslation(Point from, Point to) {
assert from.getRow() == to.getRow() || from.getCol() == to.getCol();
if(from.getRow() == to.getRow()) {
double diff = to.getCol() - from.getCol();
if(diff > 0) {
return Direction.RIGHT;
} else {
return Direction.LEFT;
}
} else {
double diff = to.getRow() - from.getRow();
if(diff > 0) {
return Direction.DOWN;
} else {
return Direction.UP;
}
}
}
}