]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/skyline.cc
Merge with git+ssh://jneem@git.sv.gnu.org/srv/git/lilypond.git
[lilypond.git] / lily / skyline.cc
index 731652b50559f715f9af945169b28280c8f50816..e52a6277d50adfeeb44b6f9369944f8c4a900909 100644 (file)
@@ -153,12 +153,14 @@ Skyline::internal_merge_skyline (list<Building> *s1, list<Building> *s2,
 
       Building b = s1->front ();
       while (s2->front ().iv_[RIGHT] < b.iv_[RIGHT]
-            && s2->front ().end_height_ <= b.height (s2->front ().iv_[RIGHT]))
+            && s2->front ().end_height_ <= b.height (s2->front ().iv_[RIGHT]) + EPS)
        s2->pop_front ();
 
       /* the front of s2 either intersects with b or it ends after b */
       Real end = infinity_f;
-      if (s2->front ().end_height_ > b.height (s2->front ().iv_[RIGHT]))
+      Real s2_end_height = s2->front ().end_height_;
+      Real s1_end_height = b.height (s2->front ().iv_[RIGHT]);
+      if (s2_end_height > s1_end_height + EPS)
        end = b.intersection (s2->front ());
       end = min (end, b.iv_[RIGHT]);
       Real height = b.height (end);
@@ -267,10 +269,11 @@ void
 Skyline::insert (Box const &b, Axis a)
 {
   list<Building> other_bld;
-  list<Building> my_bld (buildings_);
+  list<Building> my_bld;
   Interval iv = b[a];
   Real height = sky_ * b[other_axis (a)][sky_];
 
+  my_bld.splice (my_bld.begin (), buildings_);
   single_skyline (Building (iv[LEFT], height, height, iv[RIGHT], max_slope_), &other_bld, max_slope_);
   internal_merge_skyline (&other_bld, &my_bld, &buildings_);
   assert (is_legal_skyline ());
@@ -297,14 +300,15 @@ Skyline::distance (Skyline const &other) const
   list<Building>::const_iterator j = other.buildings_.begin ();
 
   Real dist = -infinity_f;
-  for (; i != buildings_.end () && j != other.buildings_.end (); i++)
+  while (i != buildings_.end () && j != other.buildings_.end ())
     {
-      while (j->iv_[RIGHT] < i->iv_[LEFT])
-       j++;
-
       Interval iv = intersection (i->iv_, j->iv_);
       dist = max (dist, max (i->height (iv[LEFT]) + j->height (iv[LEFT]),
                             i->height (iv[RIGHT]) + j->height (iv[RIGHT])));
+      if (i->iv_[RIGHT] <= j->iv_[RIGHT])
+       i++;
+      else
+       j++;
     }
   return dist;
 }