interval: add extend and intersect
Some checks failed
Doxygen Action / build (push) Has been cancelled

Signed-off-by: Simon Rozman <simon.rozman@amebis.si>
This commit is contained in:
2025-12-16 17:41:58 +01:00
parent 9e9209c55b
commit 97e781778c

View File

@@ -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>>>