-
Notifications
You must be signed in to change notification settings - Fork 402
/
orientation.go
104 lines (91 loc) · 1.55 KB
/
orientation.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package geo
type Orientation int
const (
TopLeft Orientation = iota
TopRight
BottomLeft
BottomRight
Top
Right
Bottom
Left
NONE
)
func (o Orientation) ToString() string {
switch o {
case TopLeft:
return "TopLeft"
case TopRight:
return "TopRight"
case BottomLeft:
return "BottomLeft"
case BottomRight:
return "BottomRight"
case Top:
return "Top"
case Right:
return "Right"
case Bottom:
return "Bottom"
case Left:
return "Left"
default:
return ""
}
}
func (o1 Orientation) SameSide(o2 Orientation) bool {
sides := [][]Orientation{
{TopLeft, Top, TopRight},
{BottomLeft, Bottom, BottomRight},
{Left, TopLeft, BottomLeft},
{Right, TopRight, BottomRight},
}
for _, sameSides := range sides {
isO1 := false
for _, side := range sameSides {
if side == o1 {
isO1 = true
break
}
}
if isO1 {
for _, side := range sameSides {
if side == o2 {
return true
}
}
}
}
return false
}
func (o Orientation) IsDiagonal() bool {
return o == TopLeft || o == TopRight || o == BottomLeft || o == BottomRight
}
func (o Orientation) IsHorizontal() bool {
return o == Left || o == Right
}
func (o Orientation) IsVertical() bool {
return o == Top || o == Bottom
}
func (o Orientation) GetOpposite() Orientation {
switch o {
case TopLeft:
return BottomRight
case TopRight:
return BottomLeft
case BottomLeft:
return TopRight
case BottomRight:
return TopLeft
case Top:
return Bottom
case Bottom:
return Top
case Right:
return Left
case Left:
return Right
default:
return o
}
}