moved timerange functions to timerange class
This commit is contained in:
@@ -48,6 +48,27 @@ bool TimeRange::operator==(const TimeRange &r) const
|
||||
return in() == r.in() && out() == r.out();
|
||||
}
|
||||
|
||||
bool TimeRange::OverlapsWith(const TimeRange &a) const
|
||||
{
|
||||
return Overlap(a, *this);
|
||||
}
|
||||
|
||||
TimeRange TimeRange::CombineWith(const TimeRange &a) const
|
||||
{
|
||||
return Combine(a, *this);
|
||||
}
|
||||
|
||||
bool TimeRange::Overlap(const TimeRange &a, const TimeRange &b)
|
||||
{
|
||||
return !(a.out() < b.in() || a.in() > b.out());
|
||||
}
|
||||
|
||||
TimeRange TimeRange::Combine(const TimeRange &a, const TimeRange &b)
|
||||
{
|
||||
return TimeRange(qMin(a.in(), b.in()),
|
||||
qMax(a.out(), b.out()));
|
||||
}
|
||||
|
||||
void TimeRange::normalize()
|
||||
{
|
||||
// If `out` is earlier than `in`, swap them
|
||||
|
||||
@@ -18,6 +18,12 @@ public:
|
||||
|
||||
bool operator==(const TimeRange& r) const;
|
||||
|
||||
bool OverlapsWith(const TimeRange& a) const;
|
||||
TimeRange CombineWith(const TimeRange& a) const;
|
||||
|
||||
static bool Overlap(const TimeRange& a, const TimeRange& b);
|
||||
static TimeRange Combine(const TimeRange &a, const TimeRange &b);
|
||||
|
||||
private:
|
||||
void normalize();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user