From 2dc6df6c1bae48894bd3488f17dd9adf00c740a9 Mon Sep 17 00:00:00 2001 From: Guyslain <guyslain.naves@lis-lab.fr> Date: Mon, 23 Oct 2023 15:41:59 +0200 Subject: [PATCH] =?UTF-8?q?section=202=20Coordinate=20termin=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/datastruct/Coordinate.java | 37 ++++++++++++++---------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/main/java/datastruct/Coordinate.java b/src/main/java/datastruct/Coordinate.java index f7f7e22..55222b9 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 -- GitLab