Mercurial > hg > python
comparison 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 |
comparison
equal
deleted
inserted
replaced
25:0bbeb01a7681 | 26:5488b5d3ba10 |
---|---|
1 '''Utility fns for dealing with block .tsv files''' | |
2 import math,re | |
3 | |
4 IPAT=re.compile('-?[0-9][0-9]*$') | |
5 PPAT=re.compile('[ ,;\[\]]') | |
6 | |
7 Red='[31m' | |
8 eRed='[39m' | |
9 RedFmt=Red+'%s'+eRed | |
10 | |
11 def intsMaybe(ii): | |
12 return (int(i) for i in ii if IPAT.match(i)) | |
13 | |
14 def readHeaders(host,infile,skipColHdrs=True): | |
15 l=infile.readline().rstrip() | |
16 ff=PPAT.split(l) | |
17 (host.nr,host.ox,host.oy,host.oz)=intsMaybe(ff) | |
18 host.et=ff[9] | |
19 l=infile.readline().rstrip() | |
20 (host.orad,host.ymin,host.ymax)=intsMaybe(PPAT.split(l)) | |
21 if skipColHdrs: | |
22 _=infile.readline() | |
23 | |
24 def d(p1,p2): | |
25 dx=p1[0]-p2[0] | |
26 dz=p1[1]-p2[1] | |
27 dy=p1[2]-p2[2] | |
28 return math.sqrt((dx*dx)+(dy*dy)+(dz*dz)) |