Skip to content

Commit

Permalink
refactor: lets reverse_gear and reverse_steering return new objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Becker committed Jul 29, 2021
1 parent de356da commit c01a966
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
17 changes: 7 additions & 10 deletions reeds_shepp.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ def __repr__(self):
return s

def reverse_steering(self):
self.steering = Steering(-self.steering.value)
steering = Steering(-self.steering.value)
return replace(self, steering=steering)

def reverse_gear(self):
self.gear = Gear(-self.gear.value)
gear = Gear(-self.gear.value)
return replace(self, gear=gear)


def path_length(path):
Expand All @@ -70,6 +72,7 @@ def get_optimal_path(start, end):
L_min, i_min = L, i
return paths[i_min]


def get_all_paths(start, end):
"""
Return a list of all the paths from start to end generated by the
Expand Down Expand Up @@ -103,24 +106,18 @@ def timeflip(path):
"""
timeflip transform described around the end of the article
"""
new_path = [replace(e) for e in path]
for e in new_path:
e.reverse_gear()
new_path = [e.reverse_gear() for e in path]
return new_path


def reflect(path):
"""
reflect transform described around the end of the article
"""
new_path = [replace(e) for e in path]
for e in new_path:
e.reverse_steering()
new_path = [e.reverse_steering() for e in path]
return new_path




def path1(x, y, phi):
"""
Formula 8.1: CSC (same turns)
Expand Down
6 changes: 2 additions & 4 deletions test_reeds_shepp.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@ def test_repr(self):
)

def test_reverse_gear(self):
self.element.reverse_gear()
self.assertEqual(
self.element.gear,
self.element.reverse_gear().gear,
Gear.BACKWARD
)

def test_reverse_steering(self):
self.element.reverse_steering()
self.assertEqual(
self.element.steering,
self.element.reverse_steering().steering,
Steering.RIGHT
)

Expand Down

0 comments on commit c01a966

Please sign in to comment.