From 01db6eaa59c91c71428305abec6c4f6d4957d5b7 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 8 Apr 2018 14:14:31 +0100 Subject: [PATCH] curveopt: bespoke debugging Signed-off-by: Ian Jackson --- curveopt.py | 31 ++++++++++++++++++++----------- moedebug.py | 2 ++ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/curveopt.py b/curveopt.py index e07e725..067377a 100644 --- a/curveopt.py +++ b/curveopt.py @@ -18,11 +18,20 @@ from math import atan2, atan, sqrt import symbolic class OptimisedCurve(): + counter = 0 + + def _dbg(oc, s): + dbg('OC#%04d %s' % (oc._counter, s)) + def __init__(oc, cp, nt): + oc._counter = 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)) - dbg(repr(fc_input)) + oc._dbg(repr(fc_input)) for end in (False,True): ei = nt if end else 0 @@ -33,16 +42,16 @@ class OptimisedCurve(): ef_dirn = unit_v(cp[cp1i] - cp[cp0i]) ef_len = np.linalg.norm(np.array(fc_input[fi]) - np.array(fc_input[ei])) f = e + ef_dirn * ef_len - dbg(repr((end, e,f, ef_dirn, ef_len))) + oc._dbg(repr((end, e,f, ef_dirn, ef_len))) fc_input[ei] = e fc_input[fi] = f - dbg(repr(fc_input)) + oc._dbg(repr(fc_input)) findcurve_epsilon = 0.01 cl = ['./findcurve', '%d' % (nt+1), '%.18g' % findcurve_epsilon] - dbg('STARTING FINDCURVE %s' % cl) + oc._dbg('STARTING FINDCURVE %s' % cl) subproc = subprocess.Popen( cl, bufsize=1, @@ -54,12 +63,12 @@ class OptimisedCurve(): universal_newlines=True, ) - dbg('RUNNING FINDCURVE') + oc._dbg('RUNNING FINDCURVE') fc_input = np.hstack(fc_input) s = ' '.join(map(str, fc_input)) - dbg(('>> %s' % s)) + oc._dbg(('>> %s' % s)) print(s, file=subproc.stdin) subproc.stdin.flush() @@ -71,13 +80,13 @@ class OptimisedCurve(): subproc = oc.subproc if subproc is None: return - dbg('(awaiting)') + oc._dbg('(awaiting)') commentary = '' while True: l = subproc.stdout.readline() l = l.rstrip() - dbg('<< ', l) + oc._dbg('<< ' + l) if not l: vdbg().crashing('findcurve EOF') if not l.startswith('['): commentary += ' ' @@ -87,7 +96,7 @@ class OptimisedCurve(): l = eval(l) if not l: break - dbg('[%s] %s' % (l, commentary)) + oc._dbg('[%s] %s' % (l, commentary)) commentary = '' findcurve_result = l @@ -98,13 +107,13 @@ class OptimisedCurve(): oc.subproc = None oc._result = np.reshape(findcurve_result, (-1,3), 'C') - dbg(repr(oc._result)) + oc._dbg(repr(oc._result)) vdbg().curve( oc.point_at_t ) def point_at_it(oc, it): oc._await_subproc() - dbg(repr((it,))) + oc._dbg(repr((it,))) return oc._result[it] def point_at_t(oc, t): diff --git a/moedebug.py b/moedebug.py index f5e039e..a6d958a 100644 --- a/moedebug.py +++ b/moedebug.py @@ -18,6 +18,8 @@ def dbg(*args): print('// D ', l, file=f) f.flush() +def vec2dbg(v): return '[%6.3f %6.3f %6.3f]' % tuple(v) + class BaseVisdebug(): def line(vd, p0, p1, **kw): vd.curve(lambda t: p0 + t * (p1-p0), **kw) -- 2.30.2