]> git.donarmstrong.com Git - lilypond.git/blob - flower/interval-set.cc
Make distributed tarball from Git file list
[lilypond.git] / flower / interval-set.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2004--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "interval-set.hh"
21
22 /*
23   A union of intervals in the real line.
24
25   Abysmal performance (quadratic) for large N, hopefully we don't have
26   that large N. In any case, this should probably be rewritten to use
27   a balanced tree.
28 */
29
30 Interval_set::Interval_set ()
31 {
32   set_full ();
33 }
34
35 void
36 Interval_set::set_full ()
37 {
38   allowed_regions_.clear ();
39   Interval s;
40   s.set_full ();
41   allowed_regions_.push_back (s);
42 }
43
44 void
45 Interval_set::remove_interval (Interval rm)
46 {
47   for (vsize i = 0; i < allowed_regions_.size ();)
48     {
49       Interval s = rm;
50
51       s.intersect (allowed_regions_[i]);
52
53       if (!s.is_empty ())
54         {
55           Interval before = allowed_regions_[i];
56           Interval after = allowed_regions_[i];
57
58           before[RIGHT] = s[LEFT];
59           after[LEFT] = s[RIGHT];
60
61           if (!before.is_empty () && before.length () > 0.0)
62             {
63               allowed_regions_.insert (allowed_regions_.begin () + (long)i, before);
64               i++;
65             }
66           allowed_regions_.erase (allowed_regions_.begin () + (long)i);
67           if (!after.is_empty () && after.length () > 0.0)
68             {
69               allowed_regions_.insert (allowed_regions_.begin () + (long)i, after);
70               i++;
71             }
72         }
73       else
74         i++;
75     }
76 }