chiark / gitweb /
fix python incompatibilities
[moebius3.git] / curveopt.py
index ee14c5de54949cde43ff1c66d522e4e47952dc7f..234b2750417512bf3c0821b3523f2dd39d2ed5e3 100644 (file)
@@ -12,6 +12,7 @@ import math
 from moedebug import *
 from moenp import *
 from moebez import *
+from schequeue import ScheduledTask
 
 from math import atan2, atan, sqrt
 
@@ -21,16 +22,17 @@ class OptimisedCurve():
   counter = 0
 
   def _dbg(oc, s):
-    dbg('OC#%04d %s' % (oc._counter, s))
+    dbg('%s %s' % (oc._desc, s))
 
   def __init__(oc, cp, nt):
-    oc._counter = OptimisedCurve.counter
+    oc._desc = 'OC#%04d' % OptimisedCurve.counter
     OptimisedCurve.counter += 1
+
     oc._dbg('cp= ' + ' '.join(map(vec2dbg, cp)))
 
     db = DiscreteBezier(cp, nt, bezier_constructor=BezierSegment)
 
-    fc_input = map(db.point_at_it, range(0, nt+1))
+    fc_input = [ x for x in map(db.point_at_it, range(0, nt+1)) ]
     oc._dbg(repr(fc_input))
 
     for end in (False,True):
@@ -48,7 +50,10 @@ class OptimisedCurve():
 
     oc._dbg(repr(fc_input))
 
-    findcurve_epsilon = 0.0001
+    findcurve_epsilon = 0.01
+
+    oc.sched = ScheduledTask(oc._await_subproc, oc._desc)
+    oc.sched.pre_spawn()
 
     cl = ['./findcurve', '%d' % (nt+1), '%.18g' % findcurve_epsilon]
     oc._dbg('STARTING FINDCURVE %s' % cl)
@@ -76,6 +81,9 @@ class OptimisedCurve():
     oc.subproc = subproc
     oc.nt = nt
 
+    oc.sched.post_spawn()
+    #oc._await_subproc()
+
   def _await_subproc(oc):
     subproc = oc.subproc
     if subproc is None: return
@@ -85,9 +93,11 @@ class OptimisedCurve():
 
     while True:
       l = subproc.stdout.readline()
+      if not l:
+        oc._dbg('findcurve EOF')
+        vdbg().crashing('findcurve EOF')
       l = l.rstrip()
       oc._dbg('<< ' + l)
-      if not l: vdbg().crashing('findcurve EOF')
       if not l.startswith('['):
         commentary += ' '
         commentary += l
@@ -106,6 +116,8 @@ class OptimisedCurve():
     assert(subproc.returncode == 0)
     oc.subproc = None
 
+    oc.sched.post_reap()
+
     oc._result = np.reshape(findcurve_result, (-1,3), 'C')
     oc._dbg(repr(oc._result))