]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/skyline-pair.cc
Improvements in vertical skyline approximations (issue 2148).
[lilypond.git] / lily / skyline-pair.cc
index 6f6b4e1b889b5bf0529c0069cfd374bfe507e98a..6175d1e27580655aca34bae9ec9d8acaebddbe3f 100644 (file)
@@ -28,13 +28,23 @@ Skyline_pair::Skyline_pair ()
 {
 }
 
-Skyline_pair::Skyline_pair (vector<Box> const &boxes, Real padding, Axis a)
-  : skylines_ (Skyline (boxes, padding, a, DOWN), Skyline (boxes, padding, a, UP))
+Skyline_pair::Skyline_pair (vector<Box> const &boxes, Axis a)
+  : skylines_ (Skyline (boxes, a, DOWN), Skyline (boxes, a, UP))
 {
 }
 
-Skyline_pair::Skyline_pair (Box const &b, Real padding, Axis a)
-  : skylines_ (Skyline (b, padding, a, DOWN), Skyline (b, padding, a, UP))
+Skyline_pair::Skyline_pair (vector<Drul_array<Offset> > const &buildings, Axis a)
+  : skylines_ (Skyline (buildings, a, DOWN), Skyline (buildings, a, UP))
+{
+}
+
+Skyline_pair::Skyline_pair (vector<Skyline_pair> const &skypairs)
+  : skylines_ (Skyline (skypairs, DOWN), Skyline (skypairs, UP))
+{
+}
+
+Skyline_pair::Skyline_pair (Box const &b, Axis a)
+  : skylines_ (Skyline (b, a, DOWN), Skyline (b, a, UP))
 {
 }
 
@@ -45,6 +55,13 @@ Skyline_pair::raise (Real r)
   skylines_[DOWN].raise (r);
 }
 
+void
+Skyline_pair::deholify ()
+{
+  skylines_[UP].deholify ();
+  skylines_[DOWN].deholify ();
+}
+
 void
 Skyline_pair::shift (Real r)
 {
@@ -53,10 +70,56 @@ Skyline_pair::shift (Real r)
 }
 
 void
-Skyline_pair::insert (Box const &b, Real padding, Axis a)
+Skyline_pair::insert (Box const &b, Axis a)
 {
-  skylines_[UP].insert (b, padding, a);
-  skylines_[DOWN].insert (b, padding, a);
+  skylines_[UP].insert (b, a);
+  skylines_[DOWN].insert (b, a);
+}
+
+Real
+Skyline_pair::left () const
+{
+  return min (skylines_[UP].left (), skylines_[DOWN].left ());
+}
+
+Real
+Skyline_pair::right () const
+{
+  return max (skylines_[UP].right (), skylines_[DOWN].right ());
+}
+
+// This function comes with the same caveats as smallest_shift:
+// if the skylines are not contiguous, we may report false
+// intersections.
+bool
+Skyline_pair::intersects (Skyline_pair const &other) const
+{
+  return skylines_[UP].distance (other[DOWN]) > 0
+         && other[UP].distance (skylines_[DOWN]) > 0;
+}
+
+Real
+Skyline_pair::smallest_shift (Skyline_pair const &other, Direction d,
+                              Real h_pad, Real v_pad)
+{
+  // If skylines_[UP] avoids other[DOWN] or skylines_[DOWN] avoids
+  // other[UP] then we will not intersect.
+  // Note that this is not guaranteed to return the smallest shift
+  // if one Skyline_pair is not connected: the smallest_shift left
+  // in the case of
+  // AAA
+  // BBBBBB
+  //    AAA
+  // will result in
+  //    AAA
+  // BBBBBB
+  //       AAA
+  // even though the originals did not collide.  If it becomes necessary,
+  // this case could be handled by splitting the Skyline_pairs up into
+  // their connected components.
+
+  return d * min (d * skylines_[UP].smallest_shift (other[DOWN], d, h_pad, v_pad),
+                  d * skylines_[DOWN].smallest_shift (other[UP], d, h_pad, v_pad));
 }
 
 void
@@ -76,8 +139,8 @@ Skyline_pair::print () const
 void
 Skyline_pair::print_points () const
 {
-  skylines_[UP].print ();
-  skylines_[DOWN].print ();
+  skylines_[UP].print_points ();
+  skylines_[DOWN].print_points ();
 }
 
 bool
@@ -87,6 +150,13 @@ Skyline_pair::is_empty () const
          && skylines_[DOWN].is_empty ();
 }
 
+bool
+Skyline_pair::is_singleton () const
+{
+  return skylines_[UP].is_singleton ()
+         && skylines_[DOWN].is_singleton ();
+}
+
 Skyline &
 Skyline_pair::operator [] (Direction d)
 {