-
Notifications
You must be signed in to change notification settings - Fork 45
/
index.go
54 lines (42 loc) · 1004 Bytes
/
index.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
package goat
// Index represents a position within an ASCII diagram.
type Index struct {
// units of cells
X, Y int
}
// pixel represents the CSS-pixel coordinates for an Index.
type pixel Index // XX different units -- create separate base type?
func (i *Index) asPixel() pixel {
// TODO define constants rather than hard-wire width and height of cell
return pixel{
X: i.X * 8,
Y: i.Y * 16}
}
func (i *Index) asPixelXY() (int, int) {
p := i.asPixel()
return p.X, p.Y
}
func (i *Index) east() Index {
return Index{i.X + 1, i.Y}
}
func (i *Index) west() Index {
return Index{i.X - 1, i.Y}
}
func (i *Index) north() Index {
return Index{i.X, i.Y - 1}
}
func (i *Index) south() Index {
return Index{i.X, i.Y + 1}
}
func (i *Index) nWest() Index {
return Index{i.X - 1, i.Y - 1}
}
func (i *Index) nEast() Index {
return Index{i.X + 1, i.Y - 1}
}
func (i *Index) sWest() Index {
return Index{i.X - 1, i.Y + 1}
}
func (i *Index) sEast() Index {
return Index{i.X + 1, i.Y + 1}
}