-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdirection.rb
155 lines (118 loc) · 4.05 KB
/
direction.rb
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# coding: utf-8
require_relative 'point2d'
class NorthEast
def right() East.new end
def left() NorthWest.new end
def reflect_sw_ne() NorthEast.new end
def reflect_nw_se() West.new end
def reflect_w_e() SouthEast.new end
def reflect_n_s() NorthWest.new end
def reflect_boundary(pos) (pos.up? ? West.new : SouthEast.new) end
def reverse() SouthWest.new end
def vec() Point2D.new(1,-1) end
def step from
from + (from.up? ? Point2D.new(1, 0) : Point2D.new(0, -1))
end
def strafe from
from + (from.up? ? Point2D.new(-1, 0) : Point2D.new(1, 0))
end
def ==(other) other.is_a?(NorthEast) end
def coerce(other) return self, other end
def to_s() "North East" end
end
class NorthWest
def right() NorthEast.new end
def left() West.new end
def reflect_sw_ne() East.new end
def reflect_nw_se() NorthWest.new end
def reflect_w_e() SouthWest.new end
def reflect_n_s() NorthEast.new end
def reflect_boundary(pos) (pos.up? ? East.new : SouthWest.new) end
def reverse() SouthEast.new end
def vec() Point2D.new(-1,-1) end
def step from
from + (from.up? ? Point2D.new(-1, 0) : Point2D.new(0, -1))
end
def strafe from
from + (from.up? ? Point2D.new(1, 0) : Point2D.new(-1, 0))
end
def ==(other) other.is_a?(NorthWest) end
def coerce(other) return self, other end
def to_s() "North West" end
end
class West
def right() NorthWest.new end
def left() SouthWest.new end
def reflect_sw_ne() SouthEast.new end
def reflect_nw_se() NorthEast.new end
def reflect_w_e() West.new end
def reflect_n_s() East.new end
def reflect_boundary(pos) (pos.up? ? SouthEast.new : NorthEast.new) end
def reverse() East.new end
def vec() Point2D.new(-1,0) end
def step(from) from + Point2D.new(-1, 0) end
def strafe from
from + (from.up? ? Point2D.new(0, 1) : Point2D.new(0, -1))
end
def ==(other) other.is_a?(West) end
def coerce(other) return self, other end
def to_s() "West" end
end
class SouthWest
def right() West.new end
def left() SouthEast.new end
def reflect_sw_ne() SouthWest.new end
def reflect_nw_se() East.new end
def reflect_w_e() NorthWest.new end
def reflect_n_s() SouthEast.new end
def reflect_boundary(pos) (pos.up? ? NorthWest.new : East.new) end
def reverse() NorthEast.new end
def vec() Point2D.new(-1,1) end
def step from
from + (from.up? ? Point2D.new(0, 1) : Point2D.new(-1, 0))
end
def strafe from
from + (from.up? ? Point2D.new(-1, 0) : Point2D.new(1, 0))
end
def ==(other) other.is_a?(SouthWest) end
def coerce(other) return self, other end
def to_s() "South West" end
end
class SouthEast
def right() SouthWest.new end
def left() East.new end
def reflect_sw_ne() West.new end
def reflect_nw_se() SouthEast.new end
def reflect_w_e() NorthEast.new end
def reflect_n_s() SouthWest.new end
def reflect_boundary(pos) (pos.up? ? NorthEast.new : West.new) end
def reverse() NorthWest.new end
def vec() Point2D.new(1,1) end
def step from
from + (from.up? ? Point2D.new(0, 1) : Point2D.new(1, 0))
end
def strafe from
from + (from.up? ? Point2D.new(1, 0) : Point2D.new(-1, 0))
end
def ==(other) other.is_a?(SouthEast) end
def coerce(other) return self, other end
def to_s() "South East" end
end
class East
def right() SouthEast.new end
def left() NorthEast.new end
def reflect_sw_ne() NorthWest.new end
def reflect_nw_se() SouthWest.new end
def reflect_w_e() East.new end
def reflect_n_s() West.new end
def reflect_boundary(pos) (pos.up? ? SouthWest.new : NorthWest.new) end
def reverse() West.new end
def vec() Point2D.new(1,0) end
def step(from) from + Point2D.new(1, 0) end
def strafe from
from + (from.up? ? Point2D.new(0, 1) : Point2D.new(0, -1))
end
def ==(other) other.is_a?(East) end
def coerce(other) return self, other end
def to_s() "East" end
end