1 package org.woehlke.computer.kurzweil.commons.model;
2
3 import lombok.EqualsAndHashCode;
4 import lombok.Getter;
5 import lombok.ToString;
6 import lombok.extern.log4j.Log4j2;
7
8 @Log4j2
9 @Getter
10 @ToString
11 @EqualsAndHashCode
12 public class LatticeNeighbourhood {
13
14 private final LatticeNeighbourhoodType neighbourhoodType;
15 private final int maxX;
16 private final int maxY;
17 private final int x;
18 private final int y;
19
20 private LatticePoint[] neighbourhood;
21
22 public LatticeNeighbourhood(
23 int maxX, int maxY, int x, int y,
24 LatticeNeighbourhoodType neighbourhoodType
25 ) {
26 this.neighbourhoodType = neighbourhoodType;
27 this.maxX = maxX;
28 this.maxY = maxY;
29 this.x = x;
30 this.y = y;
31 this.neighbourhood = getNeighbourhoodPoints();
32 }
33
34
35
36
37
38
39 private LatticePoint[] getNeighbourhoodPoints() {
40 LatticePointNeighbourhoodPosition[] positions = LatticePointNeighbourhoodPosition.getNeighbourhoodFor(neighbourhoodType);
41 this.neighbourhood = new LatticePoint[positions.length];
42 for(int i = 0; i < positions.length; i++){
43 this.neighbourhood[i] = new LatticePoint(
44 (x + maxX + positions[i].getX()) % maxX,
45 (y + maxY + positions[i].getY()) % maxY
46 );
47 }
48 return this.neighbourhood;
49 }
50
51 public static LatticePoint[] get(int worldX, int worldY, int myX, int myY) {
52 LatticeNeighbourhoodType neighbourhoodType = LatticeNeighbourhoodType.MOORE_NEIGHBORHOOD;
53 LatticeNeighbourhoodommons/model/LatticeNeighbourhood.html#LatticeNeighbourhood">LatticeNeighbourhood n = new LatticeNeighbourhood(worldX, worldY, myX, myY, neighbourhoodType);
54 return n.getNeighbourhoodPoints();
55 }
56
57 public static LatticePoint[] getMoore(int worldX, int worldY, int myX, int myY) {
58 LatticeNeighbourhoodType neighbourhoodType = LatticeNeighbourhoodType.MOORE_NEIGHBORHOOD;
59 LatticeNeighbourhoodommons/model/LatticeNeighbourhood.html#LatticeNeighbourhood">LatticeNeighbourhood n = new LatticeNeighbourhood(worldX, worldY, myX, myY, neighbourhoodType);
60 return n.getNeighbourhoodPoints();
61 }
62
63 public static LatticePoint[] getVonNeumann(int worldX, int worldY, int myX, int myY) {
64 LatticeNeighbourhoodType neighbourhoodType = LatticeNeighbourhoodType.VON_NEUMANN_NEIGHBORHOOD;
65 LatticeNeighbourhoodommons/model/LatticeNeighbourhood.html#LatticeNeighbourhood">LatticeNeighbourhood n = new LatticeNeighbourhood(worldX, worldY, myX, myY, neighbourhoodType);
66 return n.getNeighbourhoodPoints();
67 }
68
69 public static LatticePoint[] getWoehlke(int worldX, int worldY, int myX, int myY) {
70 LatticeNeighbourhoodType neighbourhoodType = LatticeNeighbourhoodType.WOEHLKE_NEIGHBORHOOD;
71 LatticeNeighbourhoodommons/model/LatticeNeighbourhood.html#LatticeNeighbourhood">LatticeNeighbourhood n = new LatticeNeighbourhood(worldX, worldY, myX, myY, neighbourhoodType);
72 return n.getNeighbourhoodPoints();
73 }
74
75 }