]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/lookup.cc
* lily/main.cc (setup_guile_env): new function. Set GC min_yields
[lilypond.git] / lily / lookup.cc
index 57d668fe7313d3eb975fad01d5222a824b1f46de..2e1164ce504f48404b96f61c4d68fbe9e95f6662 100644 (file)
@@ -27,9 +27,9 @@ Stencil
 Lookup::dot (Offset p, Real radius)
 {
   SCM at = (scm_list_n (ly_symbol2scm ("dot"),
-                       scm_make_real (p[X_AXIS]),
-                       scm_make_real (p[Y_AXIS]),
-                       scm_make_real (radius),
+                       scm_from_double (p[X_AXIS]),
+                       scm_from_double (p[Y_AXIS]),
+                       scm_from_double (radius),
                        SCM_UNDEFINED));
   Box box;
   box.add_point (p - Offset (radius, radius));
@@ -37,40 +37,57 @@ Lookup::dot (Offset p, Real radius)
   return Stencil (box, at);
 }
 
-/*
- * Horizontal Slope:
- *
- *            /|   ^
- *           / |   |
- *          /  |   | height
- *         /   |   |
- *        /    |   v
- *       |    /
- *       |   /
- * (0, 0)x  /slope = dy/dx
- *       | /
- *       |/
- *
- *       <----->
- *        width
- */
 Stencil
 Lookup::beam (Real slope, Real width, Real thick, Real blot)
 {
-  Real height = slope * width;
-  Real min_y = min (0., height) - thick / 2;
-  Real max_y = max (0., height) + thick / 2;
-
-  Box b (Interval (0, width),
-        Interval (min_y, max_y));
-
-  SCM at = scm_list_n (ly_symbol2scm ("beam"),
-                      scm_make_real (width),
-                      scm_make_real (slope),
-                      scm_make_real (thick),
-                      scm_make_real (blot),
-                      SCM_UNDEFINED);
-  return Stencil (b, at);
+  Box b;
+
+  Offset p;
+
+  p = Offset (0, thick/2);
+  b.add_point (p);
+  p += Offset (1,-1) * (blot/2);
+
+  SCM points = SCM_EOL;
+  
+  points = scm_cons (scm_from_double (p[X_AXIS]),
+                    scm_cons (scm_from_double (p[Y_AXIS]),
+                              points));
+  
+  
+  p = Offset (0, -thick/2);
+  b.add_point (p);
+  p += Offset (1,1) * (blot/2);
+
+  points = scm_cons (scm_from_double (p[X_AXIS]),
+                    scm_cons (scm_from_double (p[Y_AXIS]),
+                              points));
+  
+  
+  p = Offset (width, width * slope - thick/2);
+  b.add_point (p);
+  p += Offset (-1, 1) * (blot/2);
+
+  points = scm_cons (scm_from_double (p[X_AXIS]),
+                    scm_cons (scm_from_double (p[Y_AXIS]),
+                              points));
+  
+  
+  p = Offset (width, width * slope + thick/2);
+  b.add_point (p);
+  p += Offset (-1, -1) * (blot/2);
+
+  points = scm_cons (scm_from_double (p[X_AXIS]),
+                    scm_cons (scm_from_double (p[Y_AXIS]),
+                              points));
+  
+  SCM expr = scm_list_n (ly_symbol2scm ("polygon"),
+                        ly_quote_scm (points),
+                        scm_from_double (blot),
+                        SCM_BOOL_T,
+                        SCM_UNDEFINED);
+  
+  return Stencil (b, expr);
 }
 
 Stencil
@@ -87,9 +104,9 @@ Lookup::dashed_slur (Bezier b, Real thick, Real dash_period, Real dash_fraction)
     }
 
   SCM at = (scm_list_n (ly_symbol2scm ("dashed-slur"),
-                       scm_make_real (thick),
-                       scm_make_real (on),
-                       scm_make_real (off),
+                       scm_from_double (thick),
+                       scm_from_double (on),
+                       scm_from_double (off),
                        ly_quote_scm (l),
                        SCM_UNDEFINED));
 
@@ -100,10 +117,12 @@ Lookup::dashed_slur (Bezier b, Real thick, Real dash_period, Real dash_fraction)
 Stencil
 Lookup::horizontal_line (Interval w, Real th)
 {
-  SCM at = scm_list_n (ly_symbol2scm ("horizontal-line"),
-                      scm_make_real (w[LEFT]),
-                      scm_make_real (w[RIGHT]),
-                      scm_make_real (th),
+  SCM at = scm_list_n (ly_symbol2scm ("draw-line"),
+                      scm_from_double (th),
+                      scm_from_double (w[LEFT]),
+                      scm_from_double (0),
+                      scm_from_double (w[RIGHT]),
+                      scm_from_double (0),
                       SCM_UNDEFINED);
 
   Box box;
@@ -122,14 +141,7 @@ Lookup::blank (Box b)
 Stencil
 Lookup::filled_box (Box b)
 {
-  SCM at = (scm_list_n (ly_symbol2scm ("filledbox"),
-                       scm_make_real (-b[X_AXIS][LEFT]),
-                       scm_make_real (b[X_AXIS][RIGHT]),
-                       scm_make_real (-b[Y_AXIS][DOWN]),
-                       scm_make_real (b[Y_AXIS][UP]),
-                       SCM_UNDEFINED));
-
-  return Stencil (b, at);
+  return round_filled_box (b, 0.0);
 }
 
 /*
@@ -172,11 +184,11 @@ Lookup::round_filled_box (Box b, Real blotdiameter)
     }
 
   SCM at = (scm_list_n (ly_symbol2scm ("round-filled-box"),
-                       scm_make_real (-b[X_AXIS][LEFT]),
-                       scm_make_real (b[X_AXIS][RIGHT]),
-                       scm_make_real (-b[Y_AXIS][DOWN]),
-                       scm_make_real (b[Y_AXIS][UP]),
-                       scm_make_real (blotdiameter),
+                       scm_from_double (-b[X_AXIS][LEFT]),
+                       scm_from_double (b[X_AXIS][RIGHT]),
+                       scm_from_double (-b[Y_AXIS][DOWN]),
+                       scm_from_double (b[Y_AXIS][UP]),
+                       scm_from_double (blotdiameter),
                        SCM_UNDEFINED));
 
   return Stencil (b, at);
@@ -223,24 +235,26 @@ Lookup::round_filled_box (Box b, Real blotdiameter)
  * shrinked polygon). --jr
  */
 Stencil
-Lookup::round_filled_polygon (Array<Offset> points, Real blotdiameter)
+Lookup::round_filled_polygon (Array<Offset> const &points,
+                             Real blotdiameter)
 {
   /* TODO: Maybe print a warning if one of the above limitations
      applies to the given polygon.  However, this is quite complicated
      to check. */
 
-  /* remove consecutive duplicate points */
   const Real epsilon = 0.01;
-  for (int i = 0; i < points.size ();)
+
+#ifndef NDEBUG
+  /* remove consecutive duplicate points */
+  for (int i = 0; i < points.size (); i++)
     {
       int next_i = (i + 1) % points.size ();
       Real d = (points[i] - points[next_i]).length ();
       if (d < epsilon)
-       points.del (next_i);
-      else
-       i++;
+       programming_error ("Polygon should not have duplicate points");
     }
-
+#endif
+  
   /* special cases: degenerated polygons */
   if (points.size () == 0)
     return Stencil ();
@@ -250,8 +264,8 @@ Lookup::round_filled_polygon (Array<Offset> points, Real blotdiameter)
     return Line_interface::make_line (blotdiameter, points[0], points[1]);
 
   /* shrink polygon in size by 0.5 * blotdiameter */
-  Array<Offset> shrinked_points;
-  shrinked_points.set_size (points.size ());
+  Array<Offset> shrunk_points;
+  shrunk_points.set_size (points.size ());
   bool ccw = 1; // true, if three adjacent points are counterclockwise ordered
   for (int i = 0; i < points.size (); i++)
     {
@@ -292,26 +306,27 @@ Lookup::round_filled_polygon (Array<Offset> points, Real blotdiameter)
        }
       else
        p13 = (0.5 * blotdiameter / d) * p13n;
-      shrinked_points[i1] = p1 + ((ccw) ? p13 : -p13);
+      shrunk_points[i1] = p1 + ((ccw) ? p13 : -p13);
     }
 
   /* build scm expression and bounding box */
-  SCM shrinked_points_scm = SCM_EOL;
+  SCM shrunk_points_scm = SCM_EOL;
   Box box;
-  for (int i = 0; i < shrinked_points.size (); i++)
+  for (int i = 0; i < shrunk_points.size (); i++)
     {
-      SCM x = scm_make_real (shrinked_points[i][X_AXIS]);
-      SCM y = scm_make_real (shrinked_points[i][Y_AXIS]);
-      shrinked_points_scm = scm_cons (x, scm_cons (y, shrinked_points_scm));
+      SCM x = scm_from_double (shrunk_points[i][X_AXIS]);
+      SCM y = scm_from_double (shrunk_points[i][Y_AXIS]);
+      shrunk_points_scm = scm_cons (x, scm_cons (y, shrunk_points_scm));
       box.add_point (points[i]);
     }
   SCM polygon_scm = scm_list_n (ly_symbol2scm ("polygon"),
-                               ly_quote_scm (shrinked_points_scm),
-                               scm_make_real (blotdiameter),
+                               ly_quote_scm (shrunk_points_scm),
+                               scm_from_double (blotdiameter),
+                               SCM_BOOL_T,
                                SCM_UNDEFINED);
 
   Stencil polygon = Stencil (box, polygon_scm);
-  shrinked_points.clear ();
+  shrunk_points.clear ();
   return polygon;
 }
 
@@ -375,7 +390,7 @@ Lookup::slur (Bezier curve, Real curvethick, Real linethick)
 
   SCM at = (scm_list_n (ly_symbol2scm ("bezier-sandwich"),
                        ly_quote_scm (list),
-                       scm_make_real (linethick),
+                       scm_from_double (linethick),
                        SCM_UNDEFINED));
   Box b (curve.extent (X_AXIS),
         curve.extent (Y_AXIS));
@@ -427,7 +442,7 @@ Lookup::bezier_sandwich (Bezier top_curve, Bezier bottom_curve)
 
   SCM horizontal_bend = scm_list_n (ly_symbol2scm ("bezier-sandwich"),
                                    ly_quote_scm (list),
-                                   scm_make_real (0.0),
+                                   scm_from_double (0.0),
                                    SCM_UNDEFINED);
 
   Interval x_extent = top_curve.extent (X_AXIS);
@@ -643,9 +658,22 @@ Lookup::accordion (SCM s, Real staff_space, Font_metric *fm)
 Stencil
 Lookup::repeat_slash (Real w, Real s, Real t)
 {
-  SCM wid = scm_make_real (w);
-  SCM sl = scm_make_real (s);
-  SCM thick = scm_make_real (t);
+#if 0
+  // TODO
+  Array<Offset> points ;
+  Real blotdiameter = 0.0;
+
+  Offset p1(0, 0);
+  Offset p2(w, w*s);
+  
+  
+  
+  return Lookup::round_filled_polygon (points, blotdiameter);
+#endif
+  
+  SCM wid = scm_from_double (w);
+  SCM sl = scm_from_double (s);
+  SCM thick = scm_from_double (t);
   SCM slashnodot = scm_list_n (ly_symbol2scm ("repeat-slash"),
                               wid, sl, thick, SCM_UNDEFINED);