2020-07-01 14:02:47 -04:00
|
|
|
package d2cof
|
|
|
|
|
2020-07-18 00:02:45 -04:00
|
|
|
type directionCount int
|
|
|
|
|
|
|
|
const (
|
|
|
|
four directionCount = 4 << iota
|
|
|
|
eight
|
|
|
|
sixteen
|
|
|
|
thirtyTwo
|
|
|
|
sixtyFour
|
|
|
|
)
|
|
|
|
|
2020-07-01 14:02:47 -04:00
|
|
|
// Dir64ToCof returns the cof direction based on the actual direction
|
|
|
|
func Dir64ToCof(direction, numDirections int) int {
|
|
|
|
var dir4 = [64]int{
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2,
|
|
|
|
2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
|
|
|
|
3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0}
|
|
|
|
|
|
|
|
var dir8 = [64]int{
|
|
|
|
0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2,
|
|
|
|
2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4,
|
|
|
|
4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6,
|
|
|
|
6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 0, 0, 0, 0}
|
|
|
|
|
|
|
|
var dir16 = [64]int{
|
|
|
|
0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4,
|
|
|
|
4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8,
|
|
|
|
8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12,
|
|
|
|
12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 0, 0}
|
|
|
|
|
|
|
|
var dir32 = [64]int{
|
|
|
|
0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8,
|
|
|
|
8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16,
|
|
|
|
16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24,
|
|
|
|
24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 30, 30, 31, 31, 0}
|
|
|
|
|
|
|
|
var dir64 = [64]int{
|
|
|
|
0, 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, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63}
|
|
|
|
|
2020-07-18 00:02:45 -04:00
|
|
|
switch directionCount(numDirections) {
|
|
|
|
case four:
|
2020-07-01 14:02:47 -04:00
|
|
|
return dir4[direction]
|
2020-07-18 00:02:45 -04:00
|
|
|
case eight:
|
2020-07-01 14:02:47 -04:00
|
|
|
return dir8[direction]
|
2020-07-18 00:02:45 -04:00
|
|
|
case sixteen:
|
2020-07-01 14:02:47 -04:00
|
|
|
return dir16[direction]
|
2020-07-18 00:02:45 -04:00
|
|
|
case thirtyTwo:
|
2020-07-01 14:02:47 -04:00
|
|
|
return dir32[direction]
|
2020-07-18 00:02:45 -04:00
|
|
|
case sixtyFour:
|
2020-07-01 14:02:47 -04:00
|
|
|
return dir64[direction]
|
|
|
|
default:
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|