-
Notifications
You must be signed in to change notification settings - Fork 1
/
direction.rb
41 lines (33 loc) · 938 Bytes
/
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
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 ==(other) other.is_a?(North) 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 ==(other) other.is_a?(East) 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 ==(other) other.is_a?(South) 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 ==(other) other.is_a?(West) end
def coerce(other) return self, other end
end