-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdirection.py
More file actions
67 lines (53 loc) · 1.95 KB
/
direction.py
File metadata and controls
67 lines (53 loc) · 1.95 KB
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
class Rotation(object):
CLOCKWISE = -1
COUNTER = 1
R3D1 = 1
R3D2 = 2
R3D3 = 3
R3D4 = 4
class Direction(object):
def __init__(self, dx, dy, dz):
self.dx = dx
self.dy = dy
self.dz = dz
def step(self, point):
#returns a new point after taking a step in current direction
newpoint = (point[0] + self.dx, point[1] + self.dy, point[2] + self.dz)
return newpoint
def turn(self, angle):
#changes internal direction, returns nothing
#print "Turn: " , self, angle
if self.dx ==1 or self.dx == -1:
if angle == 1:
self.dx, self.dy, self.dz = 0, self.dx, 0
elif angle == 2:
self.dx, self.dy, self.dz = 0, 0, -self.dx
elif angle == 3:
self.dx, self.dy, self.dz = 0, -self.dx, 0
else:
self.dx, self.dy, self.dz = 0, 0, self.dx
elif self.dy == 1 or self.dy == -1:
if angle == 1:
self.dx, self.dy, self.dz = self.dy, 0, 0
elif angle == 2:
self.dx, self.dy, self.dz = 0, 0, -self.dy
elif angle == 3:
self.dx, self.dy, self.dz = -self.dy, 0, 0
else:
self.dx, self.dy, self.dz = 0, 0, self.dy
elif self.dz == 1 or self.dz == -1:
if angle == 1:
self.dx, self.dy, self.dz = self.dz, 0, 0
elif angle == 2:
self.dx, self.dy, self.dz = 0, self.dz, 0
elif angle == 3:
self.dx, self.dy, self.dz = -self.dz, 0, 0
else:
self.dx, self.dy, self.dz = 0, -self.dz, 0
#if angle == Rotation.CLOCKWISE:
# self.dx, self.dy = self.dy, -self.dx
#else:
# self.dx, self.dy = - self.dy, self.dx
#print "result: ", self
def __str__(self):
return "Direction({0},{1},{2})".format(self.dx, self.dy, self.dz)