diff util.py @ 26:5488b5d3ba10

use indentation and colour to differentiate safe from unsafe landing place
author Henry Thompson <ht@markup.co.uk>
date Mon, 31 May 2021 15:01:38 +0100
parents
children 668d788cac47
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/util.py	Mon May 31 15:01:38 2021 +0100
@@ -0,0 +1,28 @@
+'''Utility fns for dealing with block .tsv files'''
+import math,re
+
+IPAT=re.compile('-?[0-9][0-9]*$')
+PPAT=re.compile('[ ,;\[\]]')
+
+Red=''
+eRed=''
+RedFmt=Red+'%s'+eRed
+
+def intsMaybe(ii):
+  return (int(i) for i in ii if IPAT.match(i))
+
+def readHeaders(host,infile,skipColHdrs=True):
+    l=infile.readline().rstrip()
+    ff=PPAT.split(l)
+    (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))
+    if skipColHdrs:
+      _=infile.readline()
+
+def d(p1,p2):
+  dx=p1[0]-p2[0]
+  dz=p1[1]-p2[1]
+  dy=p1[2]-p2[2]
+  return math.sqrt((dx*dx)+(dy*dy)+(dz*dz))