From fb1d1cf7c57cfd707432c10279c94d7414b1e810 Mon Sep 17 00:00:00 2001 From: malop <malo.poussardin@etu.univ-amu.fr> Date: Fri, 8 Nov 2024 16:09:56 +0100 Subject: [PATCH] =?UTF-8?q?=C3=A9tape=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/matrix/Coordinate.java | 32 ++++++++++---------- src/main/java/matrix/CoordinateIterator.java | 24 ++++++++++----- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/src/main/java/matrix/Coordinate.java b/src/main/java/matrix/Coordinate.java index f3e5ac0..9d4c77a 100644 --- a/src/main/java/matrix/Coordinate.java +++ b/src/main/java/matrix/Coordinate.java @@ -15,8 +15,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); } /** @@ -25,8 +24,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(x-1, y); } /** @@ -35,8 +33,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(x+1, y); } /** @@ -45,8 +42,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(x, y+1); } /** @@ -55,8 +51,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(x, y-1); } /** @@ -73,8 +68,7 @@ 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(left(), right(), above(), below()); } /** @@ -92,8 +86,11 @@ 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( + new Coordinate(x-1, y-1), + new Coordinate(x+1, y-1), + new Coordinate(x-1, y+1), + new Coordinate(x+1, y+1)); } /** @@ -111,8 +108,11 @@ 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(); + return List.of(left(), right(), above(), below(), + new Coordinate(x-1, y-1), + new Coordinate(x+1, y-1), + new Coordinate(x-1, y+1), + new Coordinate(x+1, y+1)); } @Override diff --git a/src/main/java/matrix/CoordinateIterator.java b/src/main/java/matrix/CoordinateIterator.java index 810b712..345a0d2 100644 --- a/src/main/java/matrix/CoordinateIterator.java +++ b/src/main/java/matrix/CoordinateIterator.java @@ -8,7 +8,10 @@ import java.util.NoSuchElementException; * height range. */ class CoordinateIterator implements Iterator<Coordinate> { - + private int width; + private int height; + private int curretentx=0; + private int currenty=0; /** * Creates a new {@link CoordinateIterator} with the specified width and height. * @@ -16,8 +19,8 @@ class CoordinateIterator implements Iterator<Coordinate> { * @param height The height of the coordinate range. */ public CoordinateIterator(int width, int height) { - // TODO: à compléter - } + this.width = width; + this.height = height; } /** * Checks if there are more {@link Coordinate}s to iterate over. @@ -26,8 +29,7 @@ class CoordinateIterator implements Iterator<Coordinate> { */ @Override public boolean hasNext() { - // TODO: à compléter - return false; + return currenty < height; } /** @@ -38,7 +40,15 @@ class CoordinateIterator implements Iterator<Coordinate> { */ @Override public Coordinate next() { - // TODO: à compléter - return null; + if (!hasNext()) { + throw new NoSuchElementException("No more Elements"); + } + Coordinate coordinates = new Coordinate(curretentx,currenty); + curretentx++; + if (curretentx >= width) { + curretentx=0; + currenty++; + } + return coordinates; } } -- GitLab