-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaps.go
69 lines (61 loc) · 1.52 KB
/
maps.go
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
64
65
66
67
68
69
package utilities
import (
"image"
"strings"
)
var CrossDelta = []image.Point{
{0, -1}, // up
{1, 0}, // right
{0, 1}, // down
{-1, 0}, // left
}
var FullDelta = []image.Point{
{-1, -1}, {0, -1}, {1, -1}, // up-left, up, up-right
{-1, 0}, {1, 0}, // left, right
{-1, 1}, {0, 1}, {1, 1}, // down-left, down, down-right
}
func MakeImagePointSquareBool(max int) (mapping map[image.Point]bool) {
mapping = make(map[image.Point]bool)
for x := 0; x < max; x++ {
for y := 0; y < max; y++ {
mapping[image.Point{x, y}] = false
}
}
return
}
func MakeImagePointMap(lines []string) (mapping map[image.Point]rune) {
mapping = make(map[image.Point]rune)
for y, s := range lines {
for x, r := range s {
mapping[image.Point{x, y}] = r
}
}
return
}
func MakeImagePointMapRect(lines []string) (mapping map[image.Point]rune, rect image.Rectangle) {
mapping = make(map[image.Point]rune)
for y, s := range lines {
for x, r := range s {
mapping[image.Point{x, y}] = r
}
}
rect = image.Rect(0, 0, len(lines[0])-1, len(lines)-1)
return
}
func MakeIntImagePointMap(lines []string) (mapping map[image.Point]int, rect image.Rectangle) {
mapping = MakeIntImagePoint(lines)
rect = image.Rect(0, 0, len(lines[0])-1, len(lines)-1)
return
}
func MakeIntImagePoint(lines []string) (mapping map[image.Point]int) {
mapping = make(map[image.Point]int)
for y, s := range lines {
for x, r := range strings.Split(s, "") {
mapping[image.Point{x, y}] = Atoi(r)
}
}
return
}
func Adj(p, d image.Point) image.Point {
return p.Add(d)
}