comparison nono.py @ 12:ede2551ae7d9

red-formatting fixed, margins improved, cols 3&4 not being filled in, why?
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Sun, 15 Mar 2020 19:08:44 +0000
parents 1b9daa849b0f
children 70993b538ddb
comparison
equal deleted inserted replaced
11:1b9daa849b0f 12:ede2551ae7d9
185 185
186 def checkNew(self,pos): 186 def checkNew(self,pos):
187 # New blob at pos, can we complete anything? 187 # New blob at pos, can we complete anything?
188 # Assuming @@ FTTB that it's never possible to definitively complete a 188 # Assuming @@ FTTB that it's never possible to definitively complete a
189 # non-marginal run, which is wrong if the length is unique and it's bounded... 189 # non-marginal run, which is wrong if the length is unique and it's bounded...
190 start0=0 if self.margin0==0 else self.margin0+1
191 startN=self.marginN if (self.marginN==self.n-1) else self.marginN-1
190 changed=False 192 changed=False
191 # First, find our boundaries: 193 # First, find our boundaries:
192 s=pos # start index of our run 194 s=pos # start index of our run
193 while s>self.margin0 and self[s-1].val is True: 195 while s>start0 and self[s-1].val is True:
194 s-=1 196 s-=1
195 f=pos # finish index of our run 197 f=pos # finish index of our run
196 while f<self.marginN and self[f+1].val is True: 198 while f<startN and self[f+1].val is True:
197 f+=1 199 f+=1
198 l=(f-s)+1 # our length 200 l=(f-s)+1 # our length
199 print('%s:%s,%s,%s,%s:<%s>'%(str(self.__class__.__name__)[0],s,f,l,self.runs,self)) 201 print('%s:%s,%s,%s,%s:<%s>'%(str(self.__class__.__name__)[0],s,f,l,self.runs,self))
200 c=self.runs.count(l) 202 c=self.runs.count(l)
201 if c==0: 203 if c==0:
202 # not big enough yet 204 # not big enough yet
203 dprint('x0') 205 dprint('x0')
204 return 206 return
205 if self.runs[0]==l: 207 if self.runs[0]==l:
206 # is it safely left marginal, i.e. no blobs or big enough gaps before us? 208 # is it safely left marginal, i.e. no blobs or big enough gaps before us?
207 if self.marginal(range(self.margin0,s),l): 209 if self.marginal(range(start0,s),l):
208 changed=True 210 changed=True
209 dprint('n1') 211 dprint('n1')
210 # mark our margins 212 # mark our margins
211 for i in range(self.margin0+1,s): 213 for i in range(start0,s):
212 if self[i].val is None: 214 if self[i].val is None:
213 self[i].setVal(False) 215 self[i].setVal(False)
214 if f<self.marginN-1: 216 if f<startN:
215 if self[f+1].val is None: 217 if self[f+1].val is None:
216 self[f+1].setVal(False) 218 self[f+1].setVal(False)
217 self.found0(f) # pull in the start margin at least to f+2 219 self.found0(f) # pull in the start margin at least to f+2
218 else: 220 else:
219 dprint('x1a') 221 dprint('x1a')
220 if not changed: 222 if not changed:
221 if self.runs[-1]==l: 223 if self.runs[-1]==l:
222 # is it safely _right_ marginal, i.e. no blobs or big enough gaps _after_ us? 224 # is it safely _right_ marginal, i.e. no blobs or big enough gaps _after_ us?
223 if self.marginal(range(self.marginN-1,f,-1),l): 225 if self.marginal(range(startN,f,-1),l):
224 changed=True 226 changed=True
225 dprint('n2') 227 dprint('n2')
226 # mark our margins 228 # mark our margins
227 for i in range(self.marginN-1,f,-1): 229 for i in range(startN,f,-1):
228 if self[i].val is None: 230 if self[i].val is None:
229 self[i].setVal(False) 231 self[i].setVal(False)
230 if s>self.margin0+1: 232 if s>start0:
231 if self[s-1].val is None: 233 if self[s-1].val is None:
232 self[s-1].setVal(False) 234 self[s-1].setVal(False)
233 self.foundN(s) # pull in the finish margin at least to s-2 235 self.foundN(s) # pull in the finish margin at least to s-2
234 else: 236 else:
235 dprint('x2a') 237 dprint('x2a')
290 292
291 def updateHeader(self,*,maxWidth=None,r=None,pre=None): 293 def updateHeader(self,*,maxWidth=None,r=None,pre=None):
292 if maxWidth is None: 294 if maxWidth is None:
293 # update 295 # update
294 if pre: 296 if pre:
295 self.infix+=(RedFmt%r)+" " 297 self.infix+=(RedFmt%r)+(" " if self.runs else "")
296 else: 298 else:
297 # post 299 # post
298 self.suffix=" "+RedFmt%r+self.suffix 300 self.suffix=" "+RedFmt%r+self.suffix
299 self.fmt="%s%s%%s%s|"%(self.prespace,self.infix,self.suffix) 301 self.fmt="%s%s%%s%s|"%(self.prespace,self.infix,self.suffix)
300 else: 302 else:
321 if maxHeight is None: 323 if maxHeight is None:
322 # update 324 # update
323 if pre: 325 if pre:
324 for rc in str(r): 326 for rc in str(r):
325 self.infix.append(RedFmt%rc) 327 self.infix.append(RedFmt%rc)
326 self.infix.append("-") 328 self.infix.append("-" if self.runs else "")
327 else: 329 else:
328 # post 330 # post
329 ins=["-"] 331 ins=["-"]
330 for rc in str(r): 332 for rc in str(r):
331 ins.append(RedFmt%r) 333 ins.append(RedFmt%r)