From 9a86312caea43dcbd624a938d475b5ed9322c45a Mon Sep 17 00:00:00 2001 From: Hemal Varambhia Date: Mon, 30 Oct 2023 11:30:05 +0000 Subject: [PATCH] Refactor/Rename Method - clarified the name of the method to instead using polar coordinates language. --- lib/map.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/map.rb b/lib/map.rb index ef083f6d..3378b7b0 100644 --- a/lib/map.rb +++ b/lib/map.rb @@ -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 @@ -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 @@ -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 @@ -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 @@ -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