-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdirection.rb
153 lines (129 loc) · 3.41 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
require_relative 'point2d'
class North
def right() East.new end
def left() West.new end
def reverse() South.new end
def vec() Point2D.new(0,-1) end
def reflect(mirror)
case mirror
when '/'; SouthWest.new
when '\\'; SouthEast.new
when '_'; South.new
when '|'; North.new
end
end
def ==(other) other.is_a?(North) end
def coerce(other) return self, other end
end
class NorthEast
def right() SouthEast.new end
def left() NorthWest.new end
def reverse() SouthWest.new end
def vec() Point2D.new(1,-1) end
def reflect(mirror)
case mirror
when '/'; South.new
when '\\'; East.new
when '_'; SouthEast.new
when '|'; NorthWest.new
end
end
def ==(other) other.is_a?(NorthEast) end
def coerce(other) return self, other end
end
class East
def right() South.new end
def left() North.new end
def reverse() West.new end
def vec() Point2D.new(1,0) end
def reflect(mirror)
case mirror
when '/'; SouthEast.new
when '\\'; NorthEast.new
when '_'; East.new
when '|'; West.new
end
end
def ==(other) other.is_a?(East) end
def coerce(other) return self, other end
end
class SouthEast
def right() SouthWest.new end
def left() NorthEast.new end
def reverse() NorthWest.new end
def vec() Point2D.new(1,1) end
def reflect(mirror)
case mirror
when '/'; East.new
when '\\'; North.new
when '_'; NorthEast.new
when '|'; SouthWest.new
end
end
def ==(other) other.is_a?(SouthEast) end
def coerce(other) return self, other end
end
class South
def right() West.new end
def left() East.new end
def reverse() North.new end
def vec() Point2D.new(0,1) end
def reflect(mirror)
case mirror
when '/'; NorthEast.new
when '\\'; NorthWest.new
when '_'; North.new
when '|'; South.new
end
end
def ==(other) other.is_a?(South) end
def coerce(other) return self, other end
end
class SouthWest
def right() NorthWest.new end
def left() SouthEast.new end
def reverse() NorthEast.new end
def vec() Point2D.new(-1,1) end
def reflect(mirror)
case mirror
when '/'; North.new
when '\\'; West.new
when '_'; NorthWest.new
when '|'; SouthEast.new
end
end
def ==(other) other.is_a?(SouthWest) end
def coerce(other) return self, other end
end
class West
def right() North.new end
def left() South.new end
def reverse() East.new end
def vec() Point2D.new(-1,0) end
def reflect(mirror)
case mirror
when '/'; NorthWest.new
when '\\'; SouthWest.new
when '_'; West.new
when '|'; East.new
end
end
def ==(other) other.is_a?(West) end
def coerce(other) return self, other end
end
class NorthWest
def right() NorthEast.new end
def left() SouthWest.new end
def reverse() SouthEast.new end
def vec() Point2D.new(-1,-1) end
def reflect(mirror)
case mirror
when '/'; West.new
when '\\'; South.new
when '_'; SouthWest.new
when '|'; NorthEast.new
end
end
def ==(other) other.is_a?(NorthWest) end
def coerce(other) return self, other end
end