Skip to content

Commit d71d917

Browse files
Teighan MillerTeighan Miller
authored andcommitted
Fixes based on feedback
1 parent 72e0c10 commit d71d917

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

modules/bootcamp/decision_waypoint_landing_pads.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
Travel to designated waypoint and then land at a nearby landing pad.
55
"""
66

7-
from math import sqrt
87
from .. import commands
98
from .. import drone_report
109

@@ -40,11 +39,12 @@ def __init__(self, waypoint: location.Location, acceptance_radius: float) -> Non
4039

4140
# Add your own
4241
self.target = None
42+
self.tol = 0.0001
4343

4444
# ============
4545
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑
4646
# ============
47-
47+
4848
def run(
4949
self, report: drone_report.DroneReport, landing_pad_locations: "list[location.Location]"
5050
) -> commands.Command:
@@ -100,8 +100,9 @@ def run(
100100

101101
return command
102102

103+
@staticmethod
103104
def distance(
104-
self, current_location: location.Location, destination_list: "list[location.Location]"
105+
current_location: location.Location, destination_list: "list[location.Location]"
105106
) -> location.Location:
106107
"""
107108
Takes the current location and a list of possible destinations and calculates the
@@ -114,15 +115,15 @@ def distance(
114115
Returns:
115116
location.Location: class implementation of a location defined by x and y
116117
"""
117-
destination = location.Location(1000000000, 1000000000)
118-
for landing_pad in destination_list:
119-
if sqrt(
120-
(landing_pad.location_x - current_location.location_x) ** 2
121-
+ (landing_pad.location_y - current_location.location_y) ** 2
122-
) < sqrt(
123-
(destination.location_x - current_location.location_x) ** 2
124-
+ (destination.location_y - current_location.location_y) ** 2
125-
):
126-
destination = landing_pad
127-
118+
if len(destination_list) > 0:
119+
destination = location.Location(float('inf'), float('inf'))
120+
for landing_pad in destination_list:
121+
landing_pad_distance = (landing_pad.location_x - current_location.location_x) ** 2 + (landing_pad.location_y - current_location.location_y) ** 2
122+
destination_distance = (destination.location_x - current_location.location_x) ** 2 + (destination.location_y - current_location.location_y) ** 2
123+
if landing_pad_distance < destination_distance:
124+
destination = landing_pad
125+
else:
126+
destination = location.Location(0, 0)
128127
return destination
128+
129+

0 commit comments

Comments
 (0)