diff --git a/app/common/timerange.cpp b/app/common/timerange.cpp index d5202a5e8..6edc2ccb0 100644 --- a/app/common/timerange.cpp +++ b/app/common/timerange.cpp @@ -84,7 +84,7 @@ bool TimeRange::OverlapsWith(const TimeRange &a, bool in_inclusive, bool out_inc return !(overlaps_in || overlaps_out); } -TimeRange TimeRange::CombineWith(const TimeRange &a) const +TimeRange TimeRange::Combined(const TimeRange &a) const { return Combine(a, *this); } @@ -98,12 +98,28 @@ bool TimeRange::Contains(const TimeRange &compare, bool in_inclusive, bool out_i return contains_in && contains_out; } +bool TimeRange::Contains(const rational &r) const +{ + return r >= in_ && r < out_; +} + TimeRange TimeRange::Combine(const TimeRange &a, const TimeRange &b) { return TimeRange(qMin(a.in(), b.in()), qMax(a.out(), b.out())); } +TimeRange TimeRange::Intersected(const TimeRange &a) const +{ + return Intersect(a, *this); +} + +TimeRange TimeRange::Intersect(const TimeRange &a, const TimeRange &b) +{ + return TimeRange(qMax(a.in(), b.in()), + qMin(a.out(), b.out())); +} + TimeRange TimeRange::operator+(const rational &rhs) const { TimeRange answer(*this); @@ -162,22 +178,27 @@ void TimeRangeList::InsertTimeRange(const TimeRange &range) void TimeRangeList::RemoveTimeRange(const TimeRange &remove) { - RemoveTimeRange(this, remove); -} + int sz = this->size(); -void TimeRangeList::RemoveTimeRange(QList *list, const TimeRange &remove) -{ - for (int i=0;isize();i++) { - TimeRange& compare = (*list)[i]; + for (int i=0;iremoveAt(i); + this->removeAt(i); i--; + sz--; } else if (compare.Contains(remove, false, false)) { // The remove range is within this element, only choice is to split the element into two - list->append(TimeRange(remove.out(), compare.out())); - compare.set_out(remove.in()); + TimeRange before(compare.in(), remove.in()); + TimeRange after(remove.out(), compare.out()); + + this->removeAt(i); + i--; + sz--; + + InsertTimeRange(before); + InsertTimeRange(after); } else if (compare.in() < remove.in() && compare.out() > remove.in()) { // This element's out point overlaps the range's in, we'll trim it compare.set_out(remove.in()); diff --git a/app/common/timerange.h b/app/common/timerange.h index 42fdea34a..22b8317fb 100644 --- a/app/common/timerange.h +++ b/app/common/timerange.h @@ -43,9 +43,12 @@ public: bool OverlapsWith(const TimeRange& a, bool in_inclusive = true, bool out_inclusive = true) const; bool Contains(const TimeRange& a, bool in_inclusive = true, bool out_inclusive = true) const; + bool Contains(const rational& r) const; - TimeRange CombineWith(const TimeRange& a) const; + TimeRange Combined(const TimeRange& a) const; static TimeRange Combine(const TimeRange &a, const TimeRange &b); + TimeRange Intersected(const TimeRange& a) const; + static TimeRange Intersect(const TimeRange &a, const TimeRange &b); TimeRange operator+(const rational& rhs) const; TimeRange operator-(const rational& rhs) const; @@ -75,8 +78,6 @@ public: void RemoveTimeRange(const TimeRange& remove); - static void RemoveTimeRange(QList* list, const TimeRange& remove); - bool ContainsTimeRange(const TimeRange& range, bool in_inclusive = true, bool out_inclusive = true) const; TimeRangeList Intersects(const TimeRange& range) const;