interval: add extend and intersect
Some checks failed
Doxygen Action / build (push) Has been cancelled
Some checks failed
Doxygen Action / build (push) Has been cancelled
Signed-off-by: Simon Rozman <simon.rozman@amebis.si>
This commit is contained in:
@@ -227,6 +227,54 @@ namespace stdex
|
||||
{
|
||||
return !operator ==(other);
|
||||
}
|
||||
|
||||
///
|
||||
/// Extends the interval to another interval
|
||||
///
|
||||
/// \note Makes a union of two intervals, so it covers [min(start, other.start), max(end, other.end)).
|
||||
/// When either of the intervals is empty, the result is the non-empty one.
|
||||
/// When both intervals are empty, the result is an empty interval.
|
||||
///
|
||||
/// \param[in] other Interval to extend to
|
||||
///
|
||||
/// \returns Resulting interval
|
||||
///
|
||||
interval extend(_In_ const interval& other)
|
||||
{
|
||||
if (other.empty())
|
||||
return *this;
|
||||
if (empty())
|
||||
return *this = other;
|
||||
if (other.start < start)
|
||||
start = other.start;
|
||||
if (end < other.end)
|
||||
end = other.end;
|
||||
return *this;
|
||||
}
|
||||
|
||||
///
|
||||
/// Intersects the interval with another interval
|
||||
///
|
||||
/// \note Makes an intersection of two intervals, so it covers [max(start, other.start), min(end, other.end)).
|
||||
/// When intervals do not interlap, the result is an invalid interval.
|
||||
/// When any of the intervals is empty, the result is an invalid (and empty by definition) interval.
|
||||
///
|
||||
/// \param[in] other Interval to intersect with
|
||||
///
|
||||
/// \returns Resulting interval
|
||||
///
|
||||
interval intersect(_In_ const interval& other)
|
||||
{
|
||||
if (empty() || other.empty()) {
|
||||
invalidate();
|
||||
return *this;
|
||||
}
|
||||
if (start < other.start)
|
||||
start = other.start;
|
||||
if (other.end < end)
|
||||
end = other.end;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class AX = std::allocator<interval<T>>>
|
||||
|
||||
Reference in New Issue
Block a user