Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package datastruct;
import java.util.ArrayList;
import java.util.List;
public record Coordinate(int x, int y) {
public static Coordinate of(int x, int y) {
return new Coordinate(x,y);
}
public Coordinate left() {
return new Coordinate(x-1,y);
}
public Coordinate right() {
return new Coordinate(x+1,y);
}
public Coordinate above() {
return new Coordinate(x,y+1);
}
public Coordinate below() {
return new Coordinate(x, y-1);
}
public List<Coordinate> orthogonalNeighbours() {
return List.of(
this.right(),
this.left(),
this.above(),
this.below()
);
}
public List<Coordinate> diagonalNeighbours() {
return List.of(
this.right().above(),
this.left().above(),
this.left().below(),
this.right().below()
);
}
public List<Coordinate> orthodiagonalNeighbours() {
List<Coordinate> neighbours = new ArrayList<>(this.orthogonalNeighbours());
neighbours.addAll(this.diagonalNeighbours());
return neighbours;
}
}