2
2
package cz .hartrik .sg2 .world ;
3
3
4
4
import java .io .Serializable ;
5
- import java .util .function .Consumer ;
6
5
7
6
/**
8
7
* Spravuje čtvercovou oblast elementů uvnitř {@link ElementArea}.
9
8
* Jeho hlavním úkolem je sdělovat, zda byl alespoň jeden z elementů uvnitř
10
9
* chunku během cyklu změněn.
11
10
*
12
- * @version 2016-06-21
11
+ * @version 2017-08-12
13
12
* @author Patrik Harag
14
13
*/
15
14
public class Chunk implements Serializable {
@@ -21,23 +20,20 @@ public class Chunk implements Serializable {
21
20
private final int x ; // horizontální souřadnice oblasti
22
21
private final int y ; // vertikální souřadnice oblasti
23
22
24
- private final ElementArea elementArea ;
25
-
26
- private final int startX , startY ;
27
- private final int endX , endY ;
23
+ private final int topLeftX , topLeftY ;
24
+ private final int bottomRightX , bottomRightY ;
28
25
29
26
private volatile boolean changed = true ;
30
27
31
- public Chunk (ElementArea elementArea , int size , int x , int y ) {
32
- this .elementArea = elementArea ;
28
+ public Chunk (int size , int x , int y ) {
33
29
this .size = size ;
34
30
this .x = x ;
35
31
this .y = y ;
36
32
37
- this .startX = x * size ;
38
- this .startY = y * size ;
39
- this .endX = startX + size - 1 ;
40
- this .endY = startY + size - 1 ;
33
+ this .topLeftX = x * size ;
34
+ this .topLeftY = y * size ;
35
+ this .bottomRightX = topLeftX + size - 1 ;
36
+ this .bottomRightY = topLeftY + size - 1 ;
41
37
}
42
38
43
39
public int getSize () {
@@ -48,30 +44,16 @@ public int getSize() {
48
44
public final void change (boolean b ) { changed = b ; }
49
45
public final boolean isChanged () { return changed ; }
50
46
51
- public final int getX () { return x ; }
52
- public final int getY () { return y ; }
47
+ public final int getChunkX () { return x ; }
48
+ public final int getChunkY () { return y ; }
53
49
54
- public final int getBoundMaxX () { return endX ; }
55
- public final int getBoundMinX () { return startX ; }
56
- public final int getBoundMaxY () { return endY ; }
57
- public final int getBoundMinY () { return startY ; }
50
+ public final int getTopLeftX () { return topLeftX ; }
51
+ public final int getTopLeftY () { return topLeftY ; }
52
+ public final int getBottomRightX () { return bottomRightX ; }
53
+ public final int getBottomRightY () { return bottomRightY ; }
58
54
59
55
public final boolean contains (int x , int y ) {
60
- return x >= startX && x <= endX && y >= startY && y <= endY ;
61
- }
62
-
63
- // iterátory
64
-
65
- public void forEach (PointConsumer iterator ) {
66
- for (int nY = startY ; nY < endY ; nY ++)
67
- for (int nX = startX ; nX < endX ; nX ++)
68
- iterator .accept (nX , nY );
69
- }
70
-
71
- public void forEach (Consumer <Element > consumer ) {
72
- for (int nY = startY ; nY < endY ; nY ++)
73
- for (int nX = startX ; nX < endX ; nX ++)
74
- consumer .accept (elementArea .get (x , y ));
56
+ return x >= topLeftX && x <= bottomRightX && y >= topLeftY && y <= bottomRightY ;
75
57
}
76
58
77
59
}
0 commit comments