Mercurial > hg > python
changeset 34:668d788cac47
handle unbounded Y, landing below target elevation
author | Henry Thompson <ht@markup.co.uk> |
---|---|
date | Sat, 12 Jun 2021 17:25:13 +0100 |
parents | 5488b5d3ba10 |
children | 447b9346453b |
files | cluster.py safe.py util.py |
diffstat | 3 files changed, 80 insertions(+), 63 deletions(-) [+] |
line wrap: on
line diff
--- a/cluster.py Mon May 31 15:01:38 2021 +0100 +++ b/cluster.py Sat Jun 12 17:25:13 2021 +0100 @@ -40,7 +40,12 @@ et=ff[9] l=infile.readline().rstrip() print(l,file=outfile) - (orad,ymin,ymax)=intsMaybe(PPAT.split(l)) + l2=PPAT.split(l) + if l2[-1]=='bounded': + orad=int(l2[1]) + ymin=ymax=-1 + else: + (orad,ymin,ymax)=intsMaybe(l2) _=infile.readline() for l in infile: found=False
--- a/safe.py Mon May 31 15:01:38 2021 +0100 +++ b/safe.py Sat Jun 12 17:25:13 2021 +0100 @@ -13,17 +13,6 @@ air.tsv with the same settings as the cluster input, and lava.tsv with a lower-bound on Y of 0""") -n=10.0 -if len(sys.argv)>1: - if sys.argv[1]=='-d': - sys.argv.pop() - n=float(sys.argv.pop(1)) - -if len(sys.argv)>1: - infile=open(sys.argv.pop(1)) -else: - infile=sys.stdin - class Block: '''Shared by Air and Lava, holds points and columns. @@ -75,13 +64,10 @@ class Air(Block): pass -A=Air('air.tsv') class Lava(Block): pass -L=Lava('lava.tsv') - def d(p1,p2): dx=p1[0]-p2[0] dz=p1[1]-p2[1] @@ -90,53 +76,74 @@ def safety(p): ka=[((a[0],a[2]),d(a,p)) for a in A.points if d(a,p)<=n] - return [(k,A.columns[k[0]],L.columns[k[0]]) for k in ka if k[0] in L.columns] + return [(k,A.columns[k[0]],L.columns.get(k[0],None)) for k in ka] + +if __name__=='__main__': + n=10.0 + if len(sys.argv)>1: + if sys.argv[1]=='-d': + sys.argv.pop(1) + n=float(sys.argv.pop(1)) + + if len(sys.argv)>1: + infile=open(sys.argv.pop(1)) + else: + infile=sys.stdin + + A=Air('air.tsv') + + L=Lava('lava.tsv') + + readHeaders(sys.modules['__main__'],infile,False) -readHeaders(sys.modules['__main__'],infile,False) -for l in infile: - c=eval(l) - ss=[] - hits={} - misses=[] - for p in c: - ss=safety(p) - if ss: - for (k,a,l) in ss: - try: - (aa,ll)=hits[k] - aa.update(a) - ll.update(l) - except KeyError: - hits[k]=(a,l) + for l in infile: + c=eval(l) + ss=[] + hits={} + misses=[] + for p in c: + ss=safety(p) + if ss: + for (k,a,l) in ss: + try: + (aa,ll)=hits[k] + aa.update(a) + if l is not None: + ll.update(l) + except KeyError: + hits[k]=(a,l) + else: + misses.append(p) + print(c) + if hits: + print(' %s nearby landing columns'%len(hits)) + done={} + for k in sorted(hits.keys(),key=lambda k:k[1]): + if k[0] not in done: + done[k[0]]=1 + aa,ll=hits[k] + laa=sorted(list(aa)) + lowAir=laa[0][0] + j=-1 + if ll is not None: + lll=sorted(list(ll)) + highLava=-1 + for i,(_,h) in enumerate(lll): + if h>highLava and h<lowAir: + highLava=h + if h+1==lowAir: + j=i + break + if j>-1: + lava='['+','.join(str(e) if i!=j else \ + "(%s,%s)"%(e[0],RedFmt%e[1]) for i,e in enumerate(lll))+']' + lowAir=RedFmt%lowAir + else: + lava=None + print("%s(%s %s %s)@%0.1f: %s %s"%(' ' if j>-1 else '', + k[0][0],lowAir,k[0][1],k[1],laa,lava)) else: - misses.append(p) - print(c) - if hits: - print(' %s nearby landing columns'%len(hits)) - done={} - for k in sorted(hits.keys(),key=lambda k:k[1]): - if k[0] not in done: - done[k[0]]=1 - aa,ll=hits[k] - laa=sorted(list(aa)) - lll=sorted(list(ll)) - lowAir=laa[0][0] - highLava=-1 - j=-1 - for i,(_,h) in enumerate(lll): - if h>highLava and h<lowAir: - highLava=h - if h+1==lowAir: - j=i - break - if j>-1: - lava='['+','.join(str(e) if i!=j else \ - "(%s,%s)"%(e[0],RedFmt%e[1]) for i,e in enumerate(lll))+']' - lowAir=RedFmt%lowAir - print("%s(%s %s %s)@%0.1f: %s %s"%(' ' if j>-1 else '', - k[0][0],lowAir,k[0][1],k[1],laa,lava)) - else: - print(' No nearby landing zones') + print(' No nearby landing zones') -if infile!=sys.stdin: - infile.close() + if infile!=sys.stdin: + infile.close()
--- a/util.py Mon May 31 15:01:38 2021 +0100 +++ b/util.py Sat Jun 12 17:25:13 2021 +0100 @@ -17,7 +17,12 @@ (host.nr,host.ox,host.oy,host.oz)=intsMaybe(ff) host.et=ff[9] l=infile.readline().rstrip() - (host.orad,host.ymin,host.ymax)=intsMaybe(PPAT.split(l)) + l2=PPAT.split(l) + if l2[-1]=='bounded': + host.orad=int(l2[1]) + host.ymin=host.ymax=-1 + else: + (host.orad,host.ymin,host.ymax)=intsMaybe(PPAT.split(l)) if skipColHdrs: _=infile.readline()