helper: Added splitInterval

This commit is contained in:
Paul Beckingham 2016-04-27 23:27:51 -04:00
parent 3b45e90c5e
commit 75414b50ca
2 changed files with 32 additions and 0 deletions

View file

@ -583,3 +583,34 @@ int quantizeTo15Minutes (const int minutes)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
std::vector <Interval> splitInterval (
const Interval& interval,
const std::vector <Range>& exclusions)
{
std::vector <Interval> all;
// Start with a single range from the interval, from which to subtract.
std::vector <Range> intervalFragments {interval.range};
for (auto& exclusion : exclusions)
{
std::vector <Range> brokenFragments;
for (auto& fragment : intervalFragments)
for (auto& broken : fragment.subtract (exclusion))
brokenFragments.push_back (broken);
intervalFragments = brokenFragments;
}
// Return all the fragments as intervals.
for (auto& fragment : intervalFragments)
{
// Clone the interval, set the new range.
Interval clipped {interval};
clipped.range = fragment;
all.push_back (clipped);
}
return all;
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -60,6 +60,7 @@ std::vector <Range> combineHolidaysAndExclusions (const Range&, const Rules&, co
Palette createPalette (const Rules&); Palette createPalette (const Rules&);
std::map <std::string, Color> createTagColorMap (const Rules&, Palette&, const std::vector <Interval>&); std::map <std::string, Color> createTagColorMap (const Rules&, Palette&, const std::vector <Interval>&);
int quantizeTo15Minutes (const int); int quantizeTo15Minutes (const int);
std::vector <Interval> splitInterval (const Interval&, const std::vector <Range>&);
// utiŀ.cpp // utiŀ.cpp
std::string osName (); std::string osName ();