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,36 +410,19 @@ 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) }
{ else
// If the exclusion is entirely within the piece, then collapse. {
if (exclusion.start > piece.start && for (auto& result : subtractRanges (interval.range, {interval.range}, exclusions))
(exclusion.end < piece.end || {
piece.end.toEpoch () == 0)) Interval chunk {interval};
{ chunk.range = result;
for (auto& smaller_piece : piece.subtract (exclusion)) all.push_back (chunk);
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
{
split_pieces.push_back (piece);
}
}
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";