timerange: added functions to + and - rationals from timeranges

This commit is contained in:
itsmattkc
2020-05-21 02:17:47 +10:00
parent b6a42b812e
commit a2d68f6d9f
2 changed files with 36 additions and 2 deletions
+29 -1
View File
@@ -104,6 +104,34 @@ TimeRange TimeRange::Combine(const TimeRange &a, const TimeRange &b)
qMax(a.out(), b.out()));
}
TimeRange TimeRange::operator+(const rational &rhs) const
{
TimeRange answer(*this);
answer += rhs;
return answer;
}
TimeRange TimeRange::operator-(const rational &rhs) const
{
TimeRange answer(*this);
answer -= rhs;
return answer;
}
const TimeRange &TimeRange::operator+=(const rational &rhs)
{
set_range(in_ + rhs, out_ + rhs);
return *this;
}
const TimeRange &TimeRange::operator-=(const rational &rhs)
{
set_range(in_ - rhs, out_ - rhs);
return *this;
}
void TimeRange::normalize()
{
// If `out` is earlier than `in`, swap them
@@ -173,7 +201,7 @@ bool TimeRangeList::ContainsTimeRange(const TimeRange &range, bool in_inclusive,
return false;
}
TimeRangeList TimeRangeList::Intersects(const TimeRange &range)
TimeRangeList TimeRangeList::Intersects(const TimeRange &range) const
{
TimeRangeList intersect_list;
+7 -1
View File
@@ -47,6 +47,12 @@ public:
TimeRange CombineWith(const TimeRange& a) const;
static TimeRange Combine(const TimeRange &a, const TimeRange &b);
TimeRange operator+(const rational& rhs) const;
TimeRange operator-(const rational& rhs) const;
const TimeRange& operator+=(const rational &rhs);
const TimeRange& operator-=(const rational &rhs);
private:
void normalize();
@@ -66,7 +72,7 @@ public:
bool ContainsTimeRange(const TimeRange& range, bool in_inclusive = true, bool out_inclusive = true) const;
TimeRangeList Intersects(const TimeRange& range);
TimeRangeList Intersects(const TimeRange& range) const;
private:
void PrintTimeList();