]> git.donarmstrong.com Git - lilypond.git/blobdiff - flower/include/interval.tcc
Run grand replace for 2015.
[lilypond.git] / flower / include / interval.tcc
index 5cd938fd0853fc14d9a68e85c7e8b9d2c4b2807b..72be6e81e92161984a74cfb6128902bb3d2ade31 100644 (file)
@@ -1,7 +1,7 @@
 /*
   This file is part of LilyPond, the GNU music typesetter.
 
-  Copyright (C) 1996--2010 Han-Wen Nienhuys <hanwen@xs4all.nl>
+  Copyright (C) 1996--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
 
   LilyPond is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -70,14 +70,14 @@ void
 Interval_t<T>::set_empty ()
 {
   at (LEFT) = (T) infinity ();
-  at (RIGHT) = (T) -infinity ();
+  at (RIGHT) = (T) - infinity ();
 }
 
 template<class T>
 void
 Interval_t<T>::set_full ()
 {
-  at (LEFT) = (T) -infinity ();
+  at (LEFT) = (T) - infinity ();
   at (RIGHT) = (T) infinity ();
 }
 
@@ -107,6 +107,31 @@ Interval_t<T>::unite (Interval_t<T> h)
   at (RIGHT) = max (h.at (RIGHT), at (RIGHT));
 }
 
+/* Unites h and this interval, but in such a way
+   that h will lie in a particular direction from this
+   interval, with a minimum amount of space in between.
+   (That is, h will be translated before we unite, if
+   that is necessary to prevent overlap. */
+template<class T>
+void
+Interval_t<T>::unite_disjoint (Interval_t<T> h, T padding, Direction d)
+{
+  T dir = d;
+  T translation = dir * (at (d) + dir * padding - h.at (-d));
+  if (translation > (T) 0)
+    h.translate (translation);
+  unite (h);
+}
+
+template<class T>
+Interval_t<T>
+Interval_t<T>::union_disjoint (Interval_t<T> h, T padding, Direction d) const
+{
+  Interval_t<T> iv = *this;
+  iv.unite_disjoint (h, padding, d);
+  return iv;
+}
+
 template<class T>
 void
 Interval_t<T>::intersect (Interval_t<T> h)
@@ -124,7 +149,7 @@ Interval_t<T>::to_string () const
   string s ("[");
 
   return (s + T_to_string (at (LEFT)) + string (",")
-         + T_to_string (at (RIGHT)) + string ("]"));
+          + T_to_string (at (RIGHT)) + string ("]"));
 }
 
 template<class T>
@@ -134,7 +159,7 @@ Interval_t<T>::contains (T r) const
   return r >= at (LEFT) && r <= at (RIGHT);
 }
 
-#define INTERVAL__INSTANTIATE(T) struct Interval_t<T>;                 \
+#define INTERVAL__INSTANTIATE(T) struct Interval_t<T>;                  \
   template int Interval__compare (const Interval_t<T> &, Interval_t<T> const &)
 
 #endif // INTERVAL_TCC