chiark / gitweb /
curveopt: wip
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 7 Apr 2018 21:40:33 +0000 (22:40 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 7 Apr 2018 21:40:33 +0000 (22:40 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
curveopt.py
findcurve.c

index 699e437158b5c30de5fa430b8a8436d11b98026c..ab02a8252426a5ab6229ca9578ba77bdd20269ef 100644 (file)
@@ -19,28 +19,31 @@ findcurve_subprocs = { }
 
 class OptimisedCurve():
   def __init__(oc, cp, nt):
-    db = DiscreteBezier(cp, nt, constructor=BezierSegment)
+    db = DiscreteBezier(cp, nt, bezier_constructor=BezierSegment)
+
     fc_input = map(db.point_at_it, range(0, nt+1))
+
     for end in (False,True):
-      ei = end ? nt : 0
-      fi = end ? nt-1 : 1
-      cp0i = end ? 0 : 3
-      cp1i = end ? 1 : 2
-      e = cp[cp0i]
-      ef_dirn =unit_v(cp[cp1i] - cp[cp0i])
-      ef_len = np.linalg.norm(fc_input[fi] - fc_input[ei])
+      ei = nt if end else 0
+      fi = nt-1 if end else 1
+      cp0i = 0 if end else 3
+      cp1i = 1 if end else 2
+      e = np.array(cp[cp0i])
+      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
       fc_input[ei] = e
       fc_input[fi] = f
 
-    findcurve_epsilon = dist_pq_plane * 0.01
+    findcurve_epsilon = 0.01
 
     try:
       subproc = findcurve_subprocs[nt]
     except KeyError:
-      dbg('STARTING FINDCURVE %d' % nt)
+      cl = ['./findcurve', '%d' % nt, '%.18g' % findcurve_epsilon]
+      dbg('STARTING FINDCURVE %s' % cl)
       subproc = subprocess.Popen(
-        ['./findcurve', '%d' % nt],
+        cl,
         bufsize=1,
         stdin=subprocess.PIPE,
         stdout=subprocess.PIPE,
@@ -51,20 +54,20 @@ class OptimisedCurve():
       )
       findcurve_subprocs[nt] = subproc
 
-    dbg(('RUNNING FINDCURVE')
+    dbg('RUNNING FINDCURVE')
 
-    findcurve_input = np.hstack(*findcurve_input)
-    s = ' '.join(map(str, findcurve_input))
+    fc_input = np.hstack(fc_input)
+    s = ' '.join(map(str, fc_input))
 
     dbg(('>> %s' % s))
 
-    print(s, file=findcurve_subproc.stdin)
-    findcurve_subproc.stdin.flush()
+    print(s, file=subproc.stdin)
+    subproc.stdin.flush()
 
     commentary = ''
 
     while True:
-      l = findcurve_subproc.stdout.readline()
+      l = subproc.stdout.readline()
       l = l.rstrip()
       dbg('<< ', l)
       if not l: vdbg().crashing('findcurve EOF')
@@ -83,5 +86,5 @@ class OptimisedCurve():
 
     oc._result = np.reshape(findcurve_result, (3,-1))
 
-  def point_at_ti(oc, ti):
-    return oc._result[ti]
+  def point_at_it(oc, it):
+    return oc._result[it]
index 077f31c06c5c6a8815fcb3b2246820846d21eee0..58f74720868a245ddbb811b7e176f1571a93c7c8 100644 (file)
@@ -102,6 +102,7 @@ int main(int argc, const char *const *argv) {
   int i;
 
   NP = atoi(argv[1]);
+  epsilon = atof(argv[2]);
 
   gsl_rng *rng = gsl_rng_alloc(gsl_rng_ranlxd2);
 
@@ -112,7 +113,6 @@ int main(int argc, const char *const *argv) {
     /* NINPUT + 1 doubles: startpoint, epsilon for residual */
     for (i=0; i<NINPUT; i++)
       INPUT[i] = scan1double();
-    epsilon = scan1double();
 
     gsl_rng_set(rng,0);