Skip to content

Conversation

@towzeur
Copy link

@towzeur towzeur commented May 17, 2021

Added two function

index_to_cubecoord : index to Cube coordinates (pointy) conversion
based only on its input (int index) and CubeCoord.directions

cubecoord_to_index : Cube coordinates (pointy) to index conversion
based only on its input (int x, int y, int z)

tested and verified

for (int i=0; i<37; i++){
    CubeCoord c = index_to_cubecoord(i);
    int j = cubecoord_to_index(c.x, c.y, c.z);
    System.out.println(String.format("%d -> (%d,%d,%d) -> %d", i, c.x, c.y, c.z, j));
    assert i == j;
 }
0 -> (0,0,0) -> 0
1 -> (1,-1,0) -> 1
2 -> (1,0,-1) -> 2
3 -> (0,1,-1) -> 3
4 -> (-1,1,0) -> 4
5 -> (-1,0,1) -> 5
6 -> (0,-1,1) -> 6
7 -> (2,-2,0) -> 7
8 -> (2,-1,-1) -> 8
9 -> (2,0,-2) -> 9
10 -> (1,1,-2) -> 10
11 -> (0,2,-2) -> 11
12 -> (-1,2,-1) -> 12
13 -> (-2,2,0) -> 13
14 -> (-2,1,1) -> 14
15 -> (-2,0,2) -> 15
16 -> (-1,-1,2) -> 16
17 -> (0,-2,2) -> 17
18 -> (1,-2,1) -> 18
19 -> (3,-3,0) -> 19
20 -> (3,-2,-1) -> 20
21 -> (3,-1,-2) -> 21
22 -> (3,0,-3) -> 22
23 -> (2,1,-3) -> 23
24 -> (1,2,-3) -> 24
25 -> (0,3,-3) -> 25
26 -> (-1,3,-2) -> 26
27 -> (-2,3,-1) -> 27
28 -> (-3,3,0) -> 28
29 -> (-3,2,1) -> 29
30 -> (-3,1,2) -> 30
31 -> (-3,0,3) -> 31
32 -> (-2,-1,3) -> 32
33 -> (-1,-2,3) -> 33
34 -> (0,-3,3) -> 34
35 -> (1,-3,2) -> 35
36 -> (2,-3,1) -> 36

towzeur added 2 commits May 18, 2021 01:30
Added two function

index_to_cubecoord : index to Cube coordinates (pointy) conversion
based only on its input (int index) and CubeCoord.directions

cubecoord_to_index : Cube coordinates (pointy)  to index conversion
based only on its input (int x, int y, int z)

tested and verified 
```java
for (int i=0; i<37; i++){
    CubeCoord c = index_to_cubecoord(i);
    int j = cubecoord_to_index(c.x, c.y, c.z);
    System.out.println(String.format("%d -> (%d,%d,%d) -> %d", i, c.x, c.y, c.z, j));
    assert i == j;
 }
```
```
0 -> (0,0,0) -> 0
1 -> (1,-1,0) -> 1
2 -> (1,0,-1) -> 2
3 -> (0,1,-1) -> 3
4 -> (-1,1,0) -> 4
5 -> (-1,0,1) -> 5
6 -> (0,-1,1) -> 6
7 -> (2,-2,0) -> 7
8 -> (2,-1,-1) -> 8
9 -> (2,0,-2) -> 9
10 -> (1,1,-2) -> 10
11 -> (0,2,-2) -> 11
12 -> (-1,2,-1) -> 12
13 -> (-2,2,0) -> 13
14 -> (-2,1,1) -> 14
15 -> (-2,0,2) -> 15
16 -> (-1,-1,2) -> 16
17 -> (0,-2,2) -> 17
18 -> (1,-2,1) -> 18
19 -> (3,-3,0) -> 19
20 -> (3,-2,-1) -> 20
21 -> (3,-1,-2) -> 21
22 -> (3,0,-3) -> 22
23 -> (2,1,-3) -> 23
24 -> (1,2,-3) -> 24
25 -> (0,3,-3) -> 25
26 -> (-1,3,-2) -> 26
27 -> (-2,3,-1) -> 27
28 -> (-3,3,0) -> 28
29 -> (-3,2,1) -> 29
30 -> (-3,1,2) -> 30
31 -> (-3,0,3) -> 31
32 -> (-2,-1,3) -> 32
33 -> (-1,-2,3) -> 33
34 -> (0,-3,3) -> 34
35 -> (1,-3,2) -> 35
36 -> (2,-3,1) -> 36
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant