diff --git a/edsm-getnearest.py b/edsm-getnearest.py index 8f720d6..a769db1 100755 --- a/edsm-getnearest.py +++ b/edsm-getnearest.py @@ -10,15 +10,10 @@ from pyEDSM.edsm.models import Commander, System # ================================================================================= -def distance (coords1, coords2): - return math.sqrt( (coords1['x']-coords2['x'])**2 - + (coords1['y']-coords2['y'])**2 - + (coords1['z']-coords2['z'])**2 ) - -def getDistances (system, cmdrs): +def getDistances (system, cmdrs, roundTo=2): distances = {} for cmdr in cmdrs: - distances[cmdr] = round(distance(cmdr.currentPosition, system.coords)) + distances[cmdr] = system.distanceTo(cmdr, roundTo=roundTo) return distances # ================================================================================= @@ -68,8 +63,12 @@ def outputGui(): # ================================================================================= def outputText(): + if shortOutput: + roundTo=0 + else: + roundTo=2 try: - distances = getDistances(system, cmdrs) + distances = getDistances(system, cmdrs, roundTo=roundTo) except CommanderNotFoundError as e: print(e) sys.exit(1) @@ -85,7 +84,7 @@ def outputText(): nearestCmdr = min(distances,key=distances.get) if shortOutput: print('nearest commander: {} ({} ly).'.format(nearestCmdr.name, - distances[nearestCmdr])) + int(distances[nearestCmdr]))) else: print('nearest CMDR: {} ({} ly from {}).'.format(nearestCmdr.name, distances[nearestCmdr], system.name)) diff --git a/explorationtools.py b/explorationtools.py index 32ea660..267d9e2 100755 --- a/explorationtools.py +++ b/explorationtools.py @@ -13,11 +13,7 @@ def getBodyCount(system): return System(system).bodyCount def distanceBetween(system1, system2): - coords1 = System(system1).coords - coords2 = System(system2).coords - return int(round(math.sqrt( (coords1['x']-coords2['x'])**2 - + (coords1['y']-coords2['y'])**2 - + (coords1['z']-coords2['z'])**2 ),0)) + return System(system1).distanceTo(System(system2)) def getCommanderPosition(name, apikey): coords = Commander(name, apikey).currentPosition diff --git a/pyEDSM b/pyEDSM index 3909728..ef36127 160000 --- a/pyEDSM +++ b/pyEDSM @@ -1 +1 @@ -Subproject commit 3909728056f06836e77f92c31b36c58e59f89360 +Subproject commit ef36127bb92786f8460a14f8c34039104bbd873b