]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/skyline.cc
* Documentation/user/music-glossary.tely: add @omf tags
[lilypond.git] / lily / skyline.cc
index cc47448ee9d07143d774ea586719a9cd9e3b0d24..65f267aa176b9e9529e1c49d1549c6dddfa959b9 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 2002--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
 #include "skyline.hh" 
@@ -26,7 +26,7 @@
   This file deals with building such skyline structure, and computing
   the minimum distance between two opposing skylines.
   
-  
+   
   Invariants for a skyline:
 
   skyline[...].width_ forms a partition of the real interval, where
@@ -38,6 +38,8 @@
  */
 
 
+const Real EPS = 1e-12;  
+
 /*
   TODO: avoid unnecessary fragmentation.
 
@@ -53,27 +55,33 @@ insert_extent_into_skyline (Array<Skyline_entry> *line, Box b, Axis line_axis,
     return;
   
   Real stick_out = b[other_axis (line_axis)][d];
-  
+
+  /*
+    Intersect each segment of LINE with EXTENT, and if non-empty, insert relevant segments. 
+   */
   for (int i = line->size(); i--;)
     {
       Interval w = line->elem(i).width_;
-      if (extent[LEFT] > w[RIGHT])
+      w.intersect (extent);
+
+      if (extent[LEFT] >= w[RIGHT])
        break;
       
-      w.intersect (extent);
       Real my_height = line->elem(i).height_;
 
-      if (!w.empty_b () && d* (my_height - stick_out) < 0)
+      if (!w.empty_b () &&
+         w.length() > EPS
+         && d* (my_height - stick_out) < 0)
        {
          Interval e1 (line->elem(i).width_[LEFT], extent[LEFT]);
          Interval e3 (extent[RIGHT], line->elem(i).width_[RIGHT]);
 
-         if (!e3.empty_b ())
+         if (!e3.empty_b () && e3.length() > EPS)
            line->insert (Skyline_entry (e3, my_height), i+1);
 
          line->elem_ref(i).height_ = stick_out;
          line->elem_ref(i).width_ = w;
-         if (!e1.empty_b ())
+         if (!e1.empty_b () && e1.length() > EPS)
            line->insert (Skyline_entry (e1, my_height), i );
        }