X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=flower%2Finclude%2Finterval.tcc;h=72be6e81e92161984a74cfb6128902bb3d2ade31;hb=47db9a3883d726ca53e2133a3b2298f78dd6a32e;hp=3f5abc8b47945de2d3063b7e3dfbbb9700b9993e;hpb=a276a19dc6bd57832db3107f2f2cbb04cb4677b6;p=lilypond.git diff --git a/flower/include/interval.tcc b/flower/include/interval.tcc index 3f5abc8b47..72be6e81e9 100644 --- a/flower/include/interval.tcc +++ b/flower/include/interval.tcc @@ -1,9 +1,20 @@ /* - interval.tcc -- implement Interval_t + This file is part of LilyPond, the GNU music typesetter. - source file of the Flower Library + Copyright (C) 1996--2015 Han-Wen Nienhuys - (c) 1996--2007 Han-Wen Nienhuys + LilyPond is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LilyPond is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LilyPond. If not, see . */ #ifndef INTERVAL_TCC @@ -59,14 +70,14 @@ void Interval_t::set_empty () { at (LEFT) = (T) infinity (); - at (RIGHT) = (T) -infinity (); + at (RIGHT) = (T) - infinity (); } template void Interval_t::set_full () { - at (LEFT) = (T) -infinity (); + at (LEFT) = (T) - infinity (); at (RIGHT) = (T) infinity (); } @@ -96,6 +107,31 @@ Interval_t::unite (Interval_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 +void +Interval_t::unite_disjoint (Interval_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 +Interval_t +Interval_t::union_disjoint (Interval_t h, T padding, Direction d) const +{ + Interval_t iv = *this; + iv.unite_disjoint (h, padding, d); + return iv; +} + template void Interval_t::intersect (Interval_t h) @@ -113,7 +149,7 @@ Interval_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 @@ -123,7 +159,7 @@ Interval_t::contains (T r) const return r >= at (LEFT) && r <= at (RIGHT); } -#define INTERVAL__INSTANTIATE(T) struct Interval_t; \ +#define INTERVAL__INSTANTIATE(T) struct Interval_t; \ template int Interval__compare (const Interval_t &, Interval_t const &) #endif // INTERVAL_TCC