Skip to content

Commit

Permalink
mp_slipmap_util.py: tidy calculation of gridlines
Browse files Browse the repository at this point in the history
... by moving loop invariant calculations to outside loop
  • Loading branch information
peterbarker committed Oct 17, 2024
1 parent 2e2a701 commit 7490139
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions MAVProxy/modules/mavproxy_map/mp_slipmap_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,10 @@ def draw(self, img, pixmapper, bounds):
(lat,lon,w,h) = bounds
# note that w and h are in degrees
spacing = 1000
lat2 = mp_util.constrain(lat+h*0.5,-85,85)
lon2 = mp_util.wrap_180(lon+w)
dist = mp_util.gps_distance(lat2,lon,lat2,lon2)
while True:
start = mp_util.latlon_round((lat,lon), spacing)
lat2 = mp_util.constrain(lat+h*0.5,-85,85)
lon2 = mp_util.wrap_180(lon+w)
dist = mp_util.gps_distance(lat2,lon,lat2,lon2)
count = int(dist / spacing)
if count < 2:
spacing /= 10.0
Expand All @@ -372,6 +371,8 @@ def draw(self, img, pixmapper, bounds):

count += 10

start = mp_util.latlon_round((lat,lon), spacing)

for i in range(count):
# draw vertical lines of constant longitude
pos1 = mp_util.gps_newpos(start[0], start[1], 90, i*spacing)
Expand Down

0 comments on commit 7490139

Please sign in to comment.