]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/beam-concave.cc
* lilypond/scm-option.cc (ly_option_usage): Add final newline.
[lilypond.git] / lily / beam-concave.cc
index 0f2cb2fb9c896174f4e3f2fa259d36dc310deef5..91c772a06b12fca6a5c6dcc0b0ac0aa2f338c884 100644 (file)
@@ -1,6 +1,6 @@
 /*
 /*
-   Determine whether a beam is concave.
- */
+  Determine whether a beam is concave.
+*/
 
 #include <math.h>
 
 
 #include <math.h>
 
@@ -20,38 +20,37 @@ is_concave_single_notes (Array<int> const &positions, Direction beam_dir)
   bool above = false;
   bool below = false;
   bool concave = false;
   bool above = false;
   bool below = false;
   bool concave = false;
-  
+
   /*
     notes above and below the interval covered by 1st and last note.
   /*
     notes above and below the interval covered by 1st and last note.
-   */
+  */
   for (int i = 1; i < positions.size () - 1; i++)
     {
       above = above || (positions[i] > covering[UP]);
       below = below || (positions[i] < covering[DOWN]);
     }
 
   for (int i = 1; i < positions.size () - 1; i++)
     {
       above = above || (positions[i] > covering[UP]);
       below = below || (positions[i] < covering[DOWN]);
     }
 
-
   concave = concave || (above && below);
   /*
     A note as close or closer to the beam than begin and end, but the
     note is reached in the opposite direction as the last-first dy
   concave = concave || (above && below);
   /*
     A note as close or closer to the beam than begin and end, but the
     note is reached in the opposite direction as the last-first dy
-   */
-  int dy = positions.top() - positions[0];
-  int closest = (beam_dir * positions.top()) >? (beam_dir *positions[0]);
+  */
+  int dy = positions.top () - positions[0];
+  int closest = (beam_dir * positions.top ()) >? (beam_dir * positions[0]);
   for (int i = 2; !concave && i < positions.size () - 1; i++)
     {
   for (int i = 2; !concave && i < positions.size () - 1; i++)
     {
-      int inner_dy = positions[i] - positions[i-1];
+      int inner_dy = positions[i] - positions[i - 1];
       if (sign (inner_dy) != sign (dy)
          && (beam_dir * positions[i] >= closest
       if (sign (inner_dy) != sign (dy)
          && (beam_dir * positions[i] >= closest
-             || beam_dir * positions[i-1] >= closest))
+             || beam_dir * positions[i - 1] >= closest))
        concave = true;
     }
        concave = true;
     }
-  
-  bool all_closer = true; 
-  for (int i = 1; all_closer && i < positions.size ()-1; i++)
+
+  bool all_closer = true;
+  for (int i = 1; all_closer && i < positions.size () - 1; i++)
     {
     {
-      all_closer = all_closer &&
-       (beam_dir * positions[i] > closest);
+      all_closer = all_closer
+       && (beam_dir * positions[i] > closest);
     }
 
   concave = concave || all_closer;
     }
 
   concave = concave || all_closer;
@@ -62,16 +61,16 @@ Real
 calc_concaveness (Array<int> const &positions, Direction beam_dir)
 {
   Real dy = positions.top () - positions[0];
 calc_concaveness (Array<int> const &positions, Direction beam_dir)
 {
   Real dy = positions.top () - positions[0];
-  Real slope = dy / Real (positions.size() - 1);
+  Real slope = dy / Real (positions.size () - 1);
   Real concaveness = 0.0;
   Real concaveness = 0.0;
-  for (int i = 1; i < positions.size() - 1; i++)
+  for (int i = 1; i < positions.size () - 1; i++)
     {
       Real line_y = slope * i + positions[0];
 
       concaveness += (beam_dir * (positions[i] - line_y)) >? 0.0;
     }
 
     {
       Real line_y = slope * i + positions[0];
 
       concaveness += (beam_dir * (positions[i] - line_y)) >? 0.0;
     }
 
-  concaveness /= positions.size () ;
+  concaveness /= positions.size ();
 
   /*
     Normalize. For dy = 0, the slope ends up as 0 anyway, so the
 
   /*
     Normalize. For dy = 0, the slope ends up as 0 anyway, so the
@@ -88,14 +87,14 @@ Beam::check_concave (SCM smob)
 {
   Grob *me = unsmob_grob (smob);
 
 {
   Grob *me = unsmob_grob (smob);
 
-  Link_array<Grob> stems = 
-    extract_grob_array (me, ly_symbol2scm ("stems"));
+  Link_array<Grob> stems
+    extract_grob_array (me, ly_symbol2scm ("stems"));
 
   if (is_knee (me))
     return SCM_UNSPECIFIED;
 
   if (is_knee (me))
     return SCM_UNSPECIFIED;
-  
+
   Direction beam_dir = CENTER;
   Direction beam_dir = CENTER;
-  for (int i = stems.size (); i--; )
+  for (int i = stems.size (); i--;)
     {
       if (Stem::is_invisible (stems[i]))
        stems.del (i);
     {
       if (Stem::is_invisible (stems[i]))
        stems.del (i);
@@ -105,11 +104,10 @@ Beam::check_concave (SCM smob)
            beam_dir = dir;
        }
     }
            beam_dir = dir;
        }
     }
-  
+
   if (stems.size () <= 2)
     return SCM_UNSPECIFIED;
 
   if (stems.size () <= 2)
     return SCM_UNSPECIFIED;
 
-
   Array<int> close_positions;
   Array<int> far_positions;
   for (int i = 0; i < stems.size (); i++)
   Array<int> close_positions;
   Array<int> far_positions;
   for (int i = 0; i < stems.size (); i++)
@@ -120,15 +118,15 @@ Beam::check_concave (SCM smob)
        Hmmm.. wait, for the beams in the last measure of morgenlied,
        this doesn't look so good. Let's try the heads farthest from
        the beam.
        Hmmm.. wait, for the beams in the last measure of morgenlied,
        this doesn't look so good. Let's try the heads farthest from
        the beam.
-       
-       */
+
+      */
       Interval posns = Stem::head_positions (stems[i]);
       Interval posns = Stem::head_positions (stems[i]);
-      
+
       close_positions.push ((int) rint (posns[beam_dir]));
       far_positions.push ((int) rint (posns[-beam_dir]));
     }
 
       close_positions.push ((int) rint (posns[beam_dir]));
       far_positions.push ((int) rint (posns[-beam_dir]));
     }
 
-  if (is_concave_single_notes (far_positions, beam_dir)) 
+  if (is_concave_single_notes (far_positions, beam_dir))
     {
       Drul_array<Real> pos = ly_scm2interval (me->get_property ("positions"));
       Real r = linear_combination (pos, 0.0);
     {
       Drul_array<Real> pos = ly_scm2interval (me->get_property ("positions"));
       Real r = linear_combination (pos, 0.0);
@@ -140,11 +138,10 @@ Beam::check_concave (SCM smob)
   else
     {
       Real concaveness = (calc_concaveness (far_positions, beam_dir)
   else
     {
       Real concaveness = (calc_concaveness (far_positions, beam_dir)
-                         + calc_concaveness (close_positions, beam_dir))/2;
-      
+                         + calc_concaveness (close_positions, beam_dir)) / 2;
 
       me->set_property ("concaveness", scm_from_double (concaveness));
     }
 
       me->set_property ("concaveness", scm_from_double (concaveness));
     }
-  
+
   return SCM_UNSPECIFIED;
 }
   return SCM_UNSPECIFIED;
 }