data: Fixed bug in flatten which yielded multiple intervals

This commit is contained in:
Paul Beckingham 2016-05-10 20:00:33 -04:00
parent 0d0bb19b35
commit 5952652e67

View file

@ -410,37 +410,20 @@ std::vector <Interval> flatten (
{ {
std::vector <Interval> all; std::vector <Interval> all;
// Start with a single range from the interval, from which to subtract. if (! interval.range.ended ())
std::vector <Range> pieces {interval.range};
for (auto& exclusion : exclusions)
{ {
std::vector <Range> split_pieces; all.push_back (interval);
for (auto& piece : pieces)
{
// If the exclusion is entirely within the piece, then collapse.
if (exclusion.start > piece.start &&
(exclusion.end < piece.end ||
piece.end.toEpoch () == 0))
{
for (auto& smaller_piece : piece.subtract (exclusion))
split_pieces.push_back (smaller_piece);
} }
// If the exclusion merely overlap the piece, do nothing. This is because
// tracked time start and end is not clipped, but recorded faithfully.
else else
{ {
split_pieces.push_back (piece); for (auto& result : subtractRanges (interval.range, {interval.range}, exclusions))
{
Interval chunk {interval};
chunk.range = result;
all.push_back (chunk);
} }
} }
pieces = split_pieces;
}
// Return all the fragments as clipped intervals.
for (auto& piece : pieces)
all.push_back (clip (interval, piece));
/* /*
std::cout << "# results:\n"; std::cout << "# results:\n";
for (auto& i : all) for (auto& i : all)