Skip to content

Commit

Permalink
working calculation of direction of the rail system
Browse files Browse the repository at this point in the history
  • Loading branch information
arruda committed Dec 8, 2014
1 parent 0f88a18 commit d0dfcb5
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 8 deletions.
44 changes: 37 additions & 7 deletions minepybs/buildings.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,10 @@ class TwoWaysRailSystem(object):
"""

DIRECTIONS = {
1: "north_south",
2: "west_east",
3: "south_north",
4: "east_west",
"north_south": 1,
"west_east": 2,
"south_north": 3,
"east_west": 4,
}

def __init__(self, level, point_a, point_b):
Expand All @@ -275,14 +275,44 @@ def calculate_direction(self):
set the correct direction,
"""

point_dif = [
point_diff = [
self.point_a[0] - self.point_b[0],
self.point_a[1] - self.point_b[1],
self.point_a[2] - self.point_b[2]
]



most_diff_coord = 0

# work with positive values for the comparisons
mod = lambda x: x if x > 0 else x*-1

# dont compare Y for now, not sure it will be any different
# if mod(point_diff[1]) > mod(point_diff[most_diff_coord]):
# most_diff_coord = 1
if mod(point_diff[2]) > mod(point_diff[most_diff_coord]):
most_diff_coord = 2


# check for the minimun distance for this Rail System
# if mod(point_diff[most_diff_coord]) < MINIMUM:

# is either a North-South or East-West case
if point_diff[most_diff_coord] < 0:
# it's East-west
if most_diff_coord == 0:
self.direction = self.DIRECTIONS['east_west']
# it's North-South
else:
self.direction = self.DIRECTIONS['north_south']

# is either a South-North or West-East case
elif point_diff[most_diff_coord] > 0:
# it's West-East
if most_diff_coord == 0:
self.direction = self.DIRECTIONS['west_east']
# it's South-North
else:
self.direction = self.DIRECTIONS['south_north']

def generate_pa_rail_station(self):
"""
Expand Down
23 changes: 22 additions & 1 deletion tests/test_buildings.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,28 @@ def test_calculate_direction_on_north_sount(self):
point_b = [2, 1, 3]
rail_system = buildings.TwoWaysRailSystem('level', point_a, point_b)
rail_system.calculate_direction()
self.assertEquals(rail_system.direction, 1)
self.assertEquals(rail_system.direction, rail_system.DIRECTIONS['north_south'])

def test_calculate_direction_on_south_north(self):
point_a = [2, 1, 3]
point_b = [0, 0, 0]
rail_system = buildings.TwoWaysRailSystem('level', point_a, point_b)
rail_system.calculate_direction()
self.assertEquals(rail_system.direction, rail_system.DIRECTIONS['south_north'])

def test_calculate_direction_on_east_west(self):
point_a = [0, 0, 0]
point_b = [3, 1, 2]
rail_system = buildings.TwoWaysRailSystem('level', point_a, point_b)
rail_system.calculate_direction()
self.assertEquals(rail_system.direction, rail_system.DIRECTIONS['east_west'])

def test_calculate_direction_on_west_east(self):
point_a = [3, 1, 2]
point_b = [0, 0, 0]
rail_system = buildings.TwoWaysRailSystem('level', point_a, point_b)
rail_system.calculate_direction()
self.assertEquals(rail_system.direction, rail_system.DIRECTIONS['west_east'])

def tearDown(self):
# ensure the file locks are closed
Expand Down

0 comments on commit d0dfcb5

Please sign in to comment.