41#ifndef UFO_CORE_RANGE_HPP
42#define UFO_CORE_RANGE_HPP
107 using range_type = std::pair<T, T>;
108 using is_transparent = std::true_type;
110 [[nodiscard]]
constexpr bool operator()(
Range lhs,
Range rhs)
const noexcept
115 [[nodiscard]]
constexpr bool operator()(
Range lhs, range_type rhs)
const noexcept
118 return lhs.
lower < rhs.first && lhs.
upper < rhs.second;
120 [[nodiscard]]
constexpr bool operator()(range_type lhs,
Range rhs)
const noexcept
123 return lhs.first < rhs.
lower && lhs.second < rhs.
upper;
146 return lower <= other.lower && other.upper <=
upper;
157 return lower <= other.upper && other.lower <=
upper;
168 Range const& rhs)
noexcept =
default;
178 Range const& rhs)
noexcept
180 return lhs.upper < rhs.lower;
191 Range const& rhs)
noexcept
193 return lhs.upper <= rhs.lower;
204 Range const& rhs)
noexcept
206 return lhs.lower > rhs.upper;
217 Range const& rhs)
noexcept
219 return lhs.lower >= rhs.upper;
232 return lhs.lower == rhs && lhs.upper == rhs;
244 return lhs.upper < rhs;
257 return lhs.upper <= rhs;
269 return lhs.lower > rhs;
282 return lhs.lower >= rhs;
293 Range const& rhs)
noexcept
318 Range const& rhs)
noexcept
343 Range const& rhs)
noexcept
355struct std::formatter<
ufo::Range<T>> {
356 constexpr auto parse(std::format_parse_context& ctx)
const {
return ctx.begin(); }
358 auto format(
ufo::Range<T> const& r, std::format_context& ctx)
const
361 return std::format_to(ctx.out(),
"[{}]", +r.
lower);
362 }
else if constexpr (std::is_floating_point_v<T>) {
363 return std::format_to(ctx.out(),
"[{},{}]", +r.
lower, +r.
upper);
365 return std::format_to(ctx.out(),
"[{}..{}]", +r.
lower, +r.
upper);
387std::ostream& operator<<(std::ostream& out,
Range<T> const& r)
389 return out << std::format(
"{}", r);
All vision-related classes and functions.
Comparator for interval ordering in associative containers.
Represents a closed interval [lower, upper] of a scalar type.
friend constexpr bool operator>(Range const &lhs, value_type rhs) noexcept
Range-scalar ordering: [a, b] > t iff a > t.
friend constexpr bool operator<=(Range const &lhs, Range const &rhs) noexcept
Interval ordering: [a, b] <= [c, d] iff b <= c.
friend constexpr bool operator>=(Range const &lhs, value_type rhs) noexcept
Range-scalar ordering: [a, b] >= t iff a >= t.
value_type lower
Lower bound of the interval (inclusive).
friend constexpr bool operator>(Range const &lhs, Range const &rhs) noexcept
Interval ordering: [a, b] > [c, d] iff a > d.
friend constexpr bool operator<=(value_type lhs, Range const &rhs) noexcept
Scalar-range ordering: t <= [a, b] iff t <= a.
constexpr bool contains(Range const &other) const noexcept
Checks if another range is fully contained within this interval.
friend constexpr bool operator>=(Range const &lhs, Range const &rhs) noexcept
Interval ordering: [a, b] >= [c, d] iff a >= d.
value_type upper
Upper bound of the interval (inclusive).
friend constexpr bool operator>=(value_type lhs, Range const &rhs) noexcept
Scalar-range ordering: t >= [a, b] iff t >= b.
T value_type
Scalar type of the interval bounds.
friend constexpr bool operator==(Range const &lhs, value_type rhs) noexcept
Equality comparison with scalar: [a, b] == t iff a == t && b == t.
friend constexpr bool operator<(Range const &lhs, Range const &rhs) noexcept
Interval ordering: [a, b] < [c, d] iff b < c.
friend constexpr bool operator==(Range const &lhs, Range const &rhs) noexcept=default
Equality comparison.
friend constexpr bool operator==(value_type lhs, Range const &rhs) noexcept
Equality comparison with scalar: t == [a, b] iff t == a && t == b.
friend constexpr bool operator<=(Range const &lhs, value_type rhs) noexcept
Range-scalar ordering: [a, b] <= t iff b <= t.
friend constexpr bool operator>(value_type lhs, Range const &rhs) noexcept
Scalar-range ordering: t > [a, b] iff t > b.
friend constexpr bool operator<(Range const &lhs, value_type rhs) noexcept
Range-scalar ordering: [a, b] < t iff b < t.
friend constexpr bool operator<(value_type lhs, Range const &rhs) noexcept
Scalar-range ordering: t < [a, b] iff t < a.
constexpr bool overlaps(Range const &other) const noexcept
Checks if this interval overlaps with another range.
constexpr bool contains(value_type value) const noexcept
Checks if a value is contained within the interval.