/
axis.go
45 lines (39 loc) · 936 Bytes
/
axis.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
package cube
// Axis represents the axis that a block may be directed in. Most blocks do not have an axis, but blocks such
// as logs or pillars do.
type Axis int
const (
// Y represents the vertical Y axis.
Y Axis = iota
// Z represents the horizontal Z axis.
Z
// X represents the horizontal X axis.
X
)
// String converts an Axis into either x, y or z, depending on which axis it is.
func (a Axis) String() string {
if a == X {
return "x"
} else if a == Y {
return "y"
}
return "z"
}
// RotateLeft rotates an Axis from X to Z or from Z to X.
func (a Axis) RotateLeft() Axis {
if a == X {
return Z
} else if a == Z {
return X
}
return 0
}
// RotateRight rotates an Axis from X to Z or from Z to X.
func (a Axis) RotateRight() Axis {
// No difference in rotating left or right for an Axis.
return a.RotateLeft()
}
// Axes return all possible axes. (x, y, z)
func Axes() []Axis {
return []Axis{X, Y, Z}
}