]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/skyline.cc
release commit
[lilypond.git] / lily / skyline.cc
index bbbf7f55808b15939c796546ee6d341a166cbbd2..4392cd617a15dbf402ded25824ab108a79a955ed 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 2002--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 2002--2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
 */
 
 #include "skyline.hh"
   A skyline is a shape of the form:
 
 
-  ----
-  |  |
-  ---------|  |
-  |          |
-  |          |
-  |          |______
-  --------|                 |___
-
-
+  *                  ----
+  *                  |  |
+  *         ---------|  |
+  *         |           |
+  *         |           |
+  *         |          |______
+  * --------|                |___
+  *
 
   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
@@ -68,7 +66,7 @@ insert_extent_into_skyline (Array<Skyline_entry> *line, Box b, Axis line_axis,
 
       if (!w.is_empty ()
          && w.length () > EPS
-         && d* (my_height - stick_out) < 0)
+         && d * (my_height - stick_out) < 0)
        {
          Interval e1 (line->elem (i).width_[LEFT], extent[LEFT]);
          Interval e3 (extent[RIGHT], line->elem (i).width_[RIGHT]);
@@ -81,12 +79,11 @@ insert_extent_into_skyline (Array<Skyline_entry> *line, Box b, Axis line_axis,
          if (!e1.is_empty () && e1.length () > EPS)
            line->insert (Skyline_entry (e1, my_height), i);
        }
-
     }
 }
 
 void
-merge_skyline (Array<Skyline_entry> * a1,
+merge_skyline (Array<Skyline_entry> *a1,
               Array<Skyline_entry> const &a2,
               Direction dir)
 {
@@ -156,16 +153,12 @@ skyline_meshing_distance (Array<Skyline_entry> const &buildings,
       w.intersect (clouds[j].width_);
 
       if (!w.is_empty ())
-       distance = distance >? (buildings[i].height_ - clouds[j].height_);
+       distance = max (distance, (buildings[i].height_ - clouds[j].height_));
 
       if (i > 0 && buildings[i].width_[LEFT] >= clouds[j].width_[LEFT])
-       {
-         i--;
-       }
+       i--;
       else if (j > 0 && buildings[i].width_[LEFT] <= clouds[j].width_[LEFT])
-       {
-         j--;
-       }
+       j--;
     }
 
   return distance;
@@ -180,7 +173,6 @@ Skyline_entry::Skyline_entry (Interval i, Real r)
 {
   width_ = i;
   height_ = r;
-
 }
 
 void
@@ -189,3 +181,22 @@ heighten_skyline (Array<Skyline_entry> *buildings, Real ground)
   for (int i = 0; i < buildings->size (); i++)
     buildings->elem_ref (i).height_ += ground;
 }
+
+Real
+skyline_height (Array<Skyline_entry> const &buildings,
+               Real airplane,
+               Direction sky_dir)
+{
+  Real h = - sky_dir * infinity_f;
+
+  /*
+    Ugh! linear, should be O(log n).
+   */
+  for (int i = 0; i < buildings.size (); i++)
+    if (buildings[i].width_.contains (airplane))
+      h = sky_dir * max (sky_dir * h,
+                        sky_dir * buildings[i].height_);
+  
+  return h;
+}
+