Commits

Barry Schwartz committed ccef366

Remove the "with" from namespace declarations, to make code folding in Emacs work better.

Comments (0)

Files changed (4)

fontdesign/bezier.pure

 using math;
 
-namespace fontdesign with
+namespace fontdesign;
 
-  // Hodograph (derivative curve) of a bezier.
-  bezhodo ctrlpoints =
-    [n*(ctrlpoints!(i + 1) - ctrlpoints!i) | i = 0..(n - 1)]
-   when
-     n = #ctrlpoints - 1;
-   end;
+// Hodograph (derivative curve) of a bezier.
+bezhodo ctrlpoints =
+  [n*(ctrlpoints!(i + 1) - ctrlpoints!i) | i = 0..(n - 1)]
+ when
+   n = #ctrlpoints - 1;
+ end;
 
-  // Interpolate once between bezier control points.
-  bezstep [p0,p1] t = [p0*(1.0 - t) + p1*t];
-  bezstep (p0:p1:tail) t = (p0*(1.0 - t) + p1*t) : (bezstep (p1:tail) t);
+// Interpolate once between bezier control points.
+bezstep [p0,p1] t = [p0*(1.0 - t) + p1*t];
+bezstep (p0:p1:tail) t = (p0*(1.0 - t) + p1*t) : (bezstep (p1:tail) t);
 
-  // Return the value of a bezier at time t.
-  bezpt [p0] _ = p0;
-  bezpt ctrlpoints t = bezpt (bezstep ctrlpoints t) t;
+// Return the value of a bezier at time t.
+bezpt [p0] _ = p0;
+bezpt ctrlpoints t = bezpt (bezstep ctrlpoints t) t;
 
-  // Return the value of the derivative of a bezier at time t.
-  bezderiv ctrlpoints t = bezpt (bezhodo ctrlpoints) t;
+// Return the value of the derivative of a bezier at time t.
+bezderiv ctrlpoints t = bezpt (bezhodo ctrlpoints) t;
 
-  // Cut a bezier in two.
-  bezcut [p0] _ = ([p0],[p0]);
-  bezcut ctrlpoints t = ([head ctrlpoints] + subcut!0,
-                         subcut!1 + [last ctrlpoints])
-   when
-     subcut = bezcut (bezstep ctrlpoints t) t;
-   end;
+// Cut a bezier in two.
+bezcut [p0] _ = ([p0],[p0]);
+bezcut ctrlpoints t = ([head ctrlpoints] + subcut!0,
+                       subcut!1 + [last ctrlpoints])
+ when
+   subcut = bezcut (bezstep ctrlpoints t) t;
+ end;
 
-  // Direction of a complex-valued bezier.
-  bezdir ctrlpoints t =
-    (if t == 1 then
-       -(bezdir (reverse ctrlpoints) 0)
-     else if 0 < abs v then
-       1<:(arg v)
-     else if hodopoints ~= [] then
-       bezdir hodopoints t
-     else
-       0)                        // Or should this throw an exception?
-   when
-     hodopoints = bezhodo ctrlpoints;
-     v = bezpt hodopoints t;
-   end;
+// Direction of a complex-valued bezier.
+bezdir ctrlpoints t =
+  (if t == 1 then
+     -(bezdir (reverse ctrlpoints) 0)
+   else if 0 < abs v then
+     1<:(arg v)
+   else if hodopoints ~= [] then
+     bezdir hodopoints t
+   else
+     0)                        // Or should this throw an exception?
+ when
+   hodopoints = bezhodo ctrlpoints;
+   v = bezpt hodopoints t;
+ end;
 
-  // Tagged bezier curves.
-  type bezier (Bezier p::list);
-  ctrlpoints (Bezier p::list) = p;
-  order c::bezier = #(ctrlpoints c) - 1;
-  hodo c::bezier = bezhodo (ctrlpoints c);
-  point c::bezier t = bezpt (ctrlpoints c) t;
-  deriv c::bezier t = bezderiv (ctrlpoints c) t;
-  cut c::bezier t = bezcut (ctrlpoints c) t;
-  dir c::bezier t = bezdir (ctrlpoints c) t;
-
-end;
+// Tagged bezier curves.
+type bezier (Bezier p::list);
+ctrlpoints (Bezier p::list) = p;
+order c::bezier = #(ctrlpoints c) - 1;
+hodo c::bezier = bezhodo (ctrlpoints c);
+point c::bezier t = bezpt (ctrlpoints c) t;
+deriv c::bezier t = bezderiv (ctrlpoints c) t;
+cut c::bezier t = bezcut (ctrlpoints c) t;
+dir c::bezier t = bezdir (ctrlpoints c) t;

fontdesign/hobby.pure

 using line_intersection;
 using math;
 
-namespace fontdesign with
+namespace fontdesign;
 
-  private root2;
-  private root5;
-  const root2 = sqrt 2.0;
-  const root5 = sqrt 5.0;
+private root2;
+private root5;
+const root2 = sqrt 2.0;
+const root5 = sqrt 5.0;
 
-  // A function (or factor) due to John Hobby. See the METAFONTbook.
-  f_hobby theta phi = top/bottom
-    when
-      sintheta = sin theta;
-      costheta = cos theta;
-      sinphi = sin phi;
-      cosphi = cos phi;
-      top = 2.0 + root2 * (sintheta - sinphi / 16.0) * (sinphi - sintheta / 16.0) * (costheta - cosphi);
-      bottom = 3.0 * (1.0 + 0.5 * (root5 - 1.0) * costheta + 0.5 * (3.0 - root5) * cosphi);
-    end;
+// A function (or factor) due to John Hobby. See the METAFONTbook.
+f_hobby theta phi = top/bottom
+  when
+    sintheta = sin theta;
+    costheta = cos theta;
+    sinphi = sin phi;
+    cosphi = cos phi;
+    top = 2.0 + root2 * (sintheta - sinphi / 16.0) * (sinphi - sintheta / 16.0) * (costheta - cosphi);
+    bottom = 3.0 * (1.0 + 0.5 * (root5 - 1.0) * costheta + 0.5 * (3.0 - root5) * cosphi);
+  end;
 
-  // Find off-curve control points of a cubic bezier, given on-curve
-  // points, directions, and tensions.
-  tensions_to_controls p0 p3 dir0 dir1 tension0 tension1 = (p1,p2)
-    when
-      chord = p3 - p0;
-      theta = arg (dir0 / chord);
-      phi = arg (chord / dir1);
-      p1 = p0 + (1<:theta) * chord * ((f_hobby theta phi) / tension0);
-      p2 = p3 - (1<:(-phi)) * chord * ((f_hobby phi theta) / tension1);
-    end;
+// Find off-curve control points of a cubic bezier, given on-curve
+// points, directions, and tensions.
+tensions_to_controls p0 p3 dir0 dir1 tension0 tension1 = (p1,p2)
+  when
+    chord = p3 - p0;
+    theta = arg (dir0 / chord);
+    phi = arg (chord / dir1);
+    p1 = p0 + (1<:theta) * chord * ((f_hobby theta phi) / tension0);
+    p2 = p3 - (1<:(-phi)) * chord * ((f_hobby phi theta) / tension1);
+  end;
 
-  tensions_to_ctrlpoints p0 p3 dir0 dir1 tension0 tension1 = [p0,q!0,q!1,p3]
-    when
-      q = tensions_to_controls p0 p3 dir0 dir1 tension0 tension1;
-    end;
+tensions_to_ctrlpoints p0 p3 dir0 dir1 tension0 tension1 = [p0,q!0,q!1,p3]
+  when
+    q = tensions_to_controls p0 p3 dir0 dir1 tension0 tension1;
+  end;
 
-  tensions_to_bezier p0 p3 dir0 dir1 tension0 tension1 =
-    Bezier (tensions_to_ctrlpoints p0 p3 dir0 dir1 tension0 tension1);
+tensions_to_bezier p0 p3 dir0 dir1 tension0 tension1 =
+  Bezier (tensions_to_ctrlpoints p0 p3 dir0 dir1 tension0 tension1);
 
-  // Make a cubic bezier inflectionless (by increasing tensions if
-  // necessary).
-  remove_inflection (Bezier ctrlpoints) = Bezier (remove_inflection ctrlpoints);
-  remove_inflection [p0,p1,p2,p3] = [p0,q1,q2,p3]
-    when
-      new_points = find_intersection_of_lines true true p0 p1 p3 p2;
-      pa = new_points!0;
-      pb = new_points!1;
-      q1 = (if (abs pa) < inf then pa else p1);
-      q2 = (if (abs pb) < inf then pb else p2);
-    end;
-
-end;
+// Make a cubic bezier inflectionless (by increasing tensions if
+// necessary).
+remove_inflection (Bezier ctrlpoints) = Bezier (remove_inflection ctrlpoints);
+remove_inflection [p0,p1,p2,p3] = [p0,q1,q2,p3]
+  when
+    new_points = find_intersection_of_lines true true p0 p1 p3 p2;
+    pa = new_points!0;
+    pb = new_points!1;
+    q1 = (if (abs pa) < inf then pa else p1);
+    q2 = (if (abs pb) < inf then pb else p2);
+  end;

fontdesign/line_intersection.pure

 using math;
 
-namespace fontdesign with
+namespace fontdesign;
 
-  // See http://paulbourke.net/geometry/lineline2d/ --
-  // "Intersection point of two lines (2 dimensions)"
+// See http://paulbourke.net/geometry/lineline2d/ --
+// "Intersection point of two lines (2 dimensions)"
 
-  find_intersection_of_lines first_is_segment second_is_segment p1 p2 p3 p4 =
-    (pa,pb)
-   when
-     x1 = re p1;
-     y1 = im p1;
-     x2 = re p2;
-     y2 = im p2;
-     x3 = re p3;
-     y3 = im p3;
-     x4 = re p4;
-     y4 = im p4;
-     denom = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
-     numer_a = (x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3);
-     numer_b = (x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3);
-     ua = numer_a / denom;
-     ub = numer_b / denom;
-     x = x1 + ua * (x2 - x1);
-     y = y1 + ua * (y2 - y1);
-     pa =
-       (if first_is_segment then
-          (if 0.0 <= ua && ua <= 1.0 then x+:y else nan+:nan)
-        else
-          x+:y);
-     pb =
-       (if second_is_segment then
-          (if 0.0 <= ub && ub <= 1.0 then x+:y else nan+:nan)
-        else
-          x+:y);
-   end;
-
-end;
+find_intersection_of_lines first_is_segment second_is_segment p1 p2 p3 p4 =
+  (pa,pb)
+ when
+   x1 = re p1;
+   y1 = im p1;
+   x2 = re p2;
+   y2 = im p2;
+   x3 = re p3;
+   y3 = im p3;
+   x4 = re p4;
+   y4 = im p4;
+   denom = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
+   numer_a = (x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3);
+   numer_b = (x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3);
+   ua = numer_a / denom;
+   ub = numer_b / denom;
+   x = x1 + ua * (x2 - x1);
+   y = y1 + ua * (y2 - y1);
+   pa =
+     (if first_is_segment then
+        (if 0.0 <= ua && ua <= 1.0 then x+:y else nan+:nan)
+      else
+        x+:y);
+   pb =
+     (if second_is_segment then
+        (if 0.0 <= ub && ub <= 1.0 then x+:y else nan+:nan)
+      else
+        x+:y);
+ end;

fontdesign/piecewise.pure

 
 using math;
 
-namespace fontdesign with
+namespace fontdesign;
 
-  private floatmod;
-  floatmod a b = (q - floor q)*b when q = (double a)/b end;
+private floatmod;
+floatmod a b = (q - floor q)*b when q = (double a)/b end;
 
-  type piecewise (Piecewise pieces::list cyclic::int);
+type piecewise (Piecewise pieces::list cyclic::int);
 
-  pieces (Piecewise p::list _::int) = p;
-  is_cyclic (Piecewise _::list cyclic::int) = cyclic;
-  set_cyclic (Piecewise p::list _::int) cyclic = Piecewise p cyclic;
+pieces (Piecewise p::list _::int) = p;
+is_cyclic (Piecewise _::list cyclic::int) = cyclic;
+set_cyclic (Piecewise p::list _::int) cyclic = Piecewise p cyclic;
 
-  length pwise::piecewise = #(pieces pwise);
+length pwise::piecewise = #(pieces pwise);
 
-  evaluate funct pwise@(Piecewise p::list cyclic::int) t
-  = evaluate funct pwise (floatmod t (#p)) if cyclic && (t < 0 || #p <= t);
-  = funct (head p) 0.0 if ~cyclic && t < 0;
-  = funct (last p) 1.0 if ~cyclic && #p <= t;
-  = funct (p!(int i)) q
-   when
-     i = floor t;
-     q = t - i;
-   end otherwise;
+evaluate funct pwise@(Piecewise p::list cyclic::int) t
+= evaluate funct pwise (floatmod t (#p)) if cyclic && (t < 0 || #p <= t);
+= funct (head p) 0.0 if ~cyclic && t < 0;
+= funct (last p) 1.0 if ~cyclic && #p <= t;
+= funct (p!(int i)) q
+ when
+   i = floor t;
+   q = t - i;
+ end otherwise;
 
-  point pwise::piecewise t = evaluate point pwise t;
-  deriv pwise::piecewise t = evaluate deriv pwise t;
-  dir pwise::piecewise t = evaluate dir pwise t;
+point pwise::piecewise t = evaluate point pwise t;
+deriv pwise::piecewise t = evaluate deriv pwise t;
+dir pwise::piecewise t = evaluate dir pwise t;
 
-  // Hodograph (piecewise derivative curve).
-  hodo (Piecewise p::list cyclic::int) = Piecewise (map hodo p) cyclic;
-
-end;
+// Hodograph (piecewise derivative curve).
+hodo (Piecewise p::list cyclic::int) = Piecewise (map hodo p) cyclic;