]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/line-interface.cc
Doc-es: various updates.
[lilypond.git] / lily / line-interface.cc
index 1e2dd53c6bd1ca9cd25029e711660ff9ef6fd7b8..9c16ece4106f956af5cb3a30cb4fc667065abab8 100644 (file)
@@ -1,7 +1,7 @@
 /*
   This file is part of LilyPond, the GNU music typesetter.
 
-  Copyright (C) 2004--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
+  Copyright (C) 2004--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
 
   LilyPond is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -30,7 +30,7 @@ Line_interface::make_arrow (Offset begin, Offset end,
                             Real thick,
                             Real length, Real width)
 {
-  Real angle = (end - begin).arg ();
+  Offset dir = (end - begin).direction ();
   vector<Offset> points;
 
   points.push_back (Offset (0, 0));
@@ -38,7 +38,7 @@ Line_interface::make_arrow (Offset begin, Offset end,
   points.push_back (Offset (-length, -width));
 
   for (vsize i = 0; i < points.size (); i++)
-    points[i] = points[i] * complex_exp (Offset (0, angle)) + end;
+    points[i] = points[i] * dir + end;
 
   return Lookup::round_filled_polygon (points, thick);
 }
@@ -70,7 +70,7 @@ Line_interface::make_trill_line (Grob *me,
     }
   while (len + elt_len < dz.length ());
 
-  line.rotate (dz.arg (), Offset (LEFT, CENTER));
+  line.rotate (dz.angle_degrees (), Offset (LEFT, CENTER));
   line.translate (from);
 
   return line;
@@ -95,7 +95,7 @@ Line_interface::make_zigzag_line (Grob *me,
   Real l = robust_scm2double (me->get_property ("zigzag-length"), 1) * w;
   Real h = l > w / 2 ? sqrt (l * l - w * w / 4) : 0;
 
-  Offset rotation_factor = complex_exp (Offset (0, dz.arg ()));
+  Offset rotation_factor = dz.direction ();
 
   Offset points[3];
   points[0] = Offset (0, -h / 2);
@@ -123,7 +123,7 @@ Line_interface::make_dashed_line (Real thick, Offset from, Offset to,
                                   Real dash_period, Real dash_fraction)
 {
   dash_fraction = min (max (dash_fraction, 0.0), 1.0);
-  Real on = dash_fraction * dash_period + thick;
+  Real on = dash_fraction * dash_period;
   Real off = max (0.0, dash_period - on);
 
   SCM at = scm_list_n (ly_symbol2scm ("dashed-line"),
@@ -200,20 +200,21 @@ Line_interface::line (Grob *me, Offset from, Offset to)
                * robust_scm2double (me->get_property ("thickness"), 1);
 
   SCM type = me->get_property ("style");
-  if (type == ly_symbol2scm ("zigzag"))
+  if (scm_is_eq (type, ly_symbol2scm ("zigzag")))
     return make_zigzag_line (me, from, to);
-  else if (type == ly_symbol2scm ("trill"))
+  else if (scm_is_eq (type, ly_symbol2scm ("trill")))
     return make_trill_line (me, from, to);
-  else if (type == ly_symbol2scm ("none"))
+  else if (scm_is_eq (type, ly_symbol2scm ("none")))
     return Stencil ();
 
   Stencil stencil;
 
-  if (type == ly_symbol2scm ("dashed-line") || type == ly_symbol2scm ("dotted-line"))
+  if (scm_is_eq (type, ly_symbol2scm ("dashed-line"))
+      || scm_is_eq (type, ly_symbol2scm ("dotted-line")))
     {
 
       Real fraction
-        = type == ly_symbol2scm ("dotted-line")
+        = scm_is_eq (type, ly_symbol2scm ("dotted-line"))
           ? 0.0
           : robust_scm2double (me->get_property ("dash-fraction"), 0.4);
 
@@ -225,16 +226,21 @@ Line_interface::line (Grob *me, Offset from, Offset to)
         return Stencil ();
 
       Real len = (to - from).length ();
-
-      int n = (int) rint ((len - period * fraction) / period);
-      n = max (0, n);
-      if (n > 0)
+      /*
+        Dashed lines should begin and end with a dash.  Therefore,
+        there will be one more dash than complete dash + whitespace
+        units (full periods).
+      */
+      int full_period_count =
+        (int) rint ((len - period * fraction) / period);
+      full_period_count = max (0, full_period_count);
+      if (full_period_count > 0)
         {
           /*
             TODO: figure out something intelligent for really short
             sections.
-           */
-          period = ((to - from).length () - period * fraction) / n;
+          */
+          period = len / (fraction + full_period_count);
         }
       stencil = make_dashed_line (thick, from, to, period, fraction);
     }