package model.world; import javafx.geometry.Pos; public class Position { public final int x, y; public Position(int i, int j) { x = i; y = j; } /** * Comparison betwen two positions * Return * * @param pos - the Positon to compare to * @return -1 if this is more topLeft than other position. 0 if equals and 1 otherwise */ public int compareTo(Position pos) { int i = Integer.compare(this.x, pos.x); if (i == 0) { return Integer.compare(pos.y, this.y); } return i; } public Position add(Position position) { return new Position(this.x + position.x, this.y + position.y); } public static int distance(Position one, Position two) { return Math.abs(one.x - two.x) + Math.abs(one.y - two.y); } public Direction getDirection(Position p2){ switch (p2.x-this.x){ case 1: return Direction.RIGHT; case -1: return Direction.LEFT; } switch (p2.y-this.y){ case 1: return Direction.BOT; case -1: return Direction.TOP; } //neverReached return null; } }