Skip to content

Commit

Permalink
Refactor/Rename Method - clarified the name of the method to
Browse files Browse the repository at this point in the history
instead using polar coordinates language.
  • Loading branch information
hemalvarambhia committed Oct 30, 2023
1 parent 0630595 commit 9a86312
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def initialize(x_domain:, y_domain:, obstacles: [])
def next_location_forwards(location:)
case location.direction
when 'N'
next_y = at_top_edge?(location.coordinates) ? @y_domain.begin : location.coordinates.y + 1
next_y = at_north_pole?(location.coordinates) ? @y_domain.begin : location.coordinates.y + 1
Location.new(
coordinates: Coordinates.new(x: location.coordinates.x, y: next_y),
direction: location.direction
Expand All @@ -19,7 +19,7 @@ def next_location_forwards(location:)
direction: location.direction
)
when 'S'
next_y = at_bottom_edge?(location.coordinates) ? @y_domain.end : location.coordinates.y - 1
next_y = at_south_pole?(location.coordinates) ? @y_domain.end : location.coordinates.y - 1
Location.new(
coordinates: Coordinates.new(x: location.coordinates.x, y: next_y),
direction: location.direction
Expand All @@ -36,7 +36,7 @@ def next_location_forwards(location:)
def next_location_backwards(location:)
case location.direction
when 'N'
next_y = at_bottom_edge?(location.coordinates) ? @y_domain.end : location.coordinates.y - 1
next_y = at_south_pole?(location.coordinates) ? @y_domain.end : location.coordinates.y - 1
Location.new(
coordinates: Coordinates.new(x: location.coordinates.x, y: next_y),
direction: location.direction
Expand All @@ -48,7 +48,7 @@ def next_location_backwards(location:)
direction: location.direction
)
when 'S'
next_y = at_top_edge?(location.coordinates) ? @y_domain.begin : location.coordinates.y + 1
next_y = at_north_pole?(location.coordinates) ? @y_domain.begin : location.coordinates.y + 1
Location.new(
coordinates: Coordinates.new(x: location.coordinates.x, y: next_y),
direction: location.direction
Expand All @@ -64,11 +64,11 @@ def next_location_backwards(location:)

private

def at_top_edge?(current_position)
def at_north_pole?(current_position)
current_position.y == @y_domain.end
end

def at_bottom_edge?(current_position)
def at_south_pole?(current_position)
current_position.y == @y_domain.begin
end

Expand Down

0 comments on commit 9a86312

Please sign in to comment.