timerange: added functions to + and - rationals from timeranges
This commit is contained in:
@@ -104,6 +104,34 @@ TimeRange TimeRange::Combine(const TimeRange &a, const TimeRange &b)
|
|||||||
qMax(a.out(), b.out()));
|
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()
|
void TimeRange::normalize()
|
||||||
{
|
{
|
||||||
// If `out` is earlier than `in`, swap them
|
// If `out` is earlier than `in`, swap them
|
||||||
@@ -173,7 +201,7 @@ bool TimeRangeList::ContainsTimeRange(const TimeRange &range, bool in_inclusive,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
TimeRangeList TimeRangeList::Intersects(const TimeRange &range)
|
TimeRangeList TimeRangeList::Intersects(const TimeRange &range) const
|
||||||
{
|
{
|
||||||
TimeRangeList intersect_list;
|
TimeRangeList intersect_list;
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,12 @@ public:
|
|||||||
TimeRange CombineWith(const TimeRange& a) const;
|
TimeRange CombineWith(const TimeRange& a) const;
|
||||||
static TimeRange Combine(const TimeRange &a, const TimeRange &b);
|
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:
|
private:
|
||||||
void normalize();
|
void normalize();
|
||||||
|
|
||||||
@@ -66,7 +72,7 @@ public:
|
|||||||
|
|
||||||
bool ContainsTimeRange(const TimeRange& range, bool in_inclusive = true, bool out_inclusive = true) const;
|
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:
|
private:
|
||||||
void PrintTimeList();
|
void PrintTimeList();
|
||||||
|
|||||||
Reference in New Issue
Block a user