updated to current pyEDSM
… and now making full use of the new `distanceTo` stuff :)
This commit is contained in:
parent
06f4ba643b
commit
5ff0557956
3 changed files with 10 additions and 15 deletions
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
|
|
2
pyEDSM
2
pyEDSM
|
@ -1 +1 @@
|
|||
Subproject commit 3909728056f06836e77f92c31b36c58e59f89360
|
||||
Subproject commit ef36127bb92786f8460a14f8c34039104bbd873b
|
Loading…
Reference in a new issue