Skip to content
Snippets Groups Projects
Commit 2dc6df6c authored by Guyslain's avatar Guyslain
Browse files

section 2 Coordinate terminée

parent ac3e3620
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment