2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2004--2010 Han-Wen Nienhuys <hanwen@xs4all.nl>
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.
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.
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/>.
20 #include "interval-set.hh"
23 A union of intervals in the real line.
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
30 Interval_set::Interval_set ()
36 Interval_set::set_full ()
38 allowed_regions_
.clear ();
41 allowed_regions_
.push_back (s
);
45 Interval_set::remove_interval (Interval rm
)
47 for (vsize i
= 0; i
< allowed_regions_
.size ();)
51 s
.intersect (allowed_regions_
[i
]);
55 Interval before
= allowed_regions_
[i
];
56 Interval after
= allowed_regions_
[i
];
58 before
[RIGHT
] = s
[LEFT
];
59 after
[LEFT
] = s
[RIGHT
];
61 if (!before
.is_empty () && before
.length () > 0.0)
63 allowed_regions_
.insert (allowed_regions_
.begin () + i
, before
);
66 allowed_regions_
.erase (allowed_regions_
.begin () + i
);
67 if (!after
.is_empty () && after
.length () > 0.0)
69 allowed_regions_
.insert (allowed_regions_
.begin () + i
, after
);