diff --git a/src/main/java/datastruct/Coordinate.java b/src/main/java/datastruct/Coordinate.java index f7f7e22f440efd4cb15793ca3d1b4ecc8d5bda0c..55222b93bef5972a472252ea68d9038699566de4 100644 --- a/src/main/java/datastruct/Coordinate.java +++ b/src/main/java/datastruct/Coordinate.java @@ -16,8 +16,7 @@ public record Coordinate(int x, int y) { * @return A new {@link Coordinate} instance. */ public static Coordinate of(int x, int y) { - // TODO: compléter ce fabriquant - return null; + return new Coordinate(x,y); } /** @@ -26,8 +25,7 @@ public record Coordinate(int x, int y) { * @return The left adjacent {@link Coordinate}. */ public Coordinate left() { - // TODO: à compléter - return null; + return new Coordinate(this.x - 1, this.y); } /** @@ -36,8 +34,7 @@ public record Coordinate(int x, int y) { * @return The right adjacent {@link Coordinate}. */ public Coordinate right() { - // TODO: à compléter - return null; + return new Coordinate(this.x + 1, this.y); } /** @@ -46,8 +43,7 @@ public record Coordinate(int x, int y) { * @return The above adjacent {@link Coordinate}. */ public Coordinate above() { - // TODO: à compléter - return null; + return new Coordinate(this.x, this.y + 1); } /** @@ -56,8 +52,7 @@ public record Coordinate(int x, int y) { * @return The below adjacent {@link Coordinate}. */ public Coordinate below() { - // TODO: à compléter - return null; + return new Coordinate(this.x, this.y - 1); } /** @@ -66,8 +61,12 @@ public record Coordinate(int x, int y) { * @return A list of orthogonal neighboring {@link Coordinate}s. */ public List<Coordinate> orthogonalNeighbours() { - // TODO: à compléter - return List.of(); + return List.of( + this.right(), + this.above(), + this.left(), + this.below() + ); } /** @@ -76,8 +75,12 @@ public record Coordinate(int x, int y) { * @return A list of diagonal neighboring {@link Coordinate}s. */ public List<Coordinate> diagonalNeighbours() { - // TODO: à compléter - return List.of(); + return List.of( + this.right().above(), + this.left().above(), + this.left().below(), + this.right().below() + ); } /** @@ -86,8 +89,10 @@ public record Coordinate(int x, int y) { * @return A list of all neighboring {@link Coordinate}s. */ public List<Coordinate> orthodiagonalNeighbours() { - // TODO: à compléter - return List.of(); + List<Coordinate> neighbours = new ArrayList<>(); + neighbours.addAll(this.orthogonalNeighbours()); + neighbours.addAll(this.diagonalNeighbours()); + return neighbours; } @Override