Interval template type.
More...
#include <playrho/Interval.hpp>
|
constexpr | Interval () noexcept(noexcept(std::is_nothrow_move_constructible_v< T >))=default |
| Default constructor. More...
|
|
constexpr | Interval (const std::initializer_list< T > &ilist) noexcept(noexcept(Interval{std::minmax(ilist)})) |
| Initializing constructor. More...
|
|
constexpr | Interval (const value_type &a, const value_type &b) noexcept(noexcept(Interval{std::minmax(a, b)})) |
| Initializing constructor. More...
|
|
constexpr | Interval (const value_type &v) noexcept(noexcept(Interval{pair_type{v, v}})) |
| Initializing constructor. More...
|
|
constexpr Interval & | Expand (const value_type &v) noexcept(noexcept(m_min+=v) &&noexcept(m_max+=v)) |
| Expands this interval. More...
|
|
constexpr Interval & | ExpandEqually (const NonNegative< value_type > &v) noexcept(noexcept(Interval{pair_type{m_min - value_type{v}, m_max+value_type{v}}}) &&std::is_nothrow_move_assignable_v< Interval >) |
| Expands equally both ends of this interval. More...
|
|
constexpr value_type | GetMax () const noexcept |
| Gets the maximum value of this range.
|
|
constexpr value_type | GetMin () const noexcept |
| Gets the minimum value of this range.
|
|
constexpr Interval & | Include (const Interval &v) noexcept(noexcept(Interval{pair_type{std::min(v.GetMin(), GetMin()), std::max(v.GetMax(), GetMax())}}) &&std::is_nothrow_move_assignable_v< Interval >) |
| Includes the given interval into this interval. More...
|
|
constexpr Interval & | Include (const value_type &v) noexcept(noexcept(Interval{pair_type{std::min(v, GetMin()), std::max(v, GetMax())}}) &&std::is_nothrow_move_assignable_v< Interval >) |
| Includes the given value into this interval. More...
|
|
constexpr Interval & | Intersect (const Interval &v) noexcept(noexcept(Interval{pair_type{std::max(v.GetMin(), GetMin()), std::min(v.GetMax(), GetMax())}}) &&std::is_nothrow_move_assignable_v< Interval >) |
| Intersects this interval with the given interval. More...
|
|
constexpr Interval & | Move (const value_type &v) noexcept(noexcept(*this+v) &&std::is_nothrow_copy_assignable_v< Interval >) |
| Moves the interval by the given amount. More...
|
|
|
static constexpr value_type | GetHighest () noexcept(noexcept(limits::infinity()) &&noexcept(limits::max())) |
| Gets the "highest" value supported by the value_type . More...
|
|
static constexpr value_type | GetLowest () noexcept(noexcept(limits::infinity()) &&noexcept(limits::lowest())) |
| Gets the "lowest" value supported by the value_type . More...
|
|
|
(Note that these are not member functions.)
|
template<typename T , typename U = decltype(Interval<T>{}, ((T{} + T{}) / 2))> |
constexpr auto | GetCenter (const Interval< T > &v) noexcept(noexcept((v.GetMin()+v.GetMax())/2)) |
| Gets the center of the given interval. More...
|
|
template<typename T > |
constexpr Interval< T > | GetIntersection (Interval< T > a, const Interval< T > &b) noexcept |
| Gets the intersecting interval of two given ranges.
|
|
template<typename T , typename U = decltype(Interval<T>{}, T{} < T{}, T{} >= T{})> |
constexpr bool | IsIntersecting (const Interval< T > &a, const Interval< T > &b) noexcept(noexcept(T{}< T{}) &&noexcept(T{} >=T{})) |
| Checks whether two value ranges have any intersection/overlap at all. More...
|
|
using | LengthInterval = Interval< Length > |
| Length Interval alias.
|
|
template<typename T > |
constexpr bool | operator!= (const Interval< T > &a, const Interval< T > &b) noexcept |
| Inequality operator. More...
|
|
template<typename T > |
constexpr bool | operator< (const Interval< T > &lhs, const Interval< T > &rhs) noexcept |
| Less-than operator. More...
|
|
template<typename T > |
constexpr bool | operator<= (const Interval< T > &lhs, const Interval< T > &rhs) noexcept |
| Less-than or equal-to operator. More...
|
|
template<typename T > |
constexpr bool | operator== (const Interval< T > &a, const Interval< T > &b) noexcept |
| Equality operator. More...
|
|
template<typename T > |
constexpr bool | operator> (const Interval< T > &lhs, const Interval< T > &rhs) noexcept |
| Greater-than operator. More...
|
|
template<typename T > |
constexpr bool | operator>= (const Interval< T > &lhs, const Interval< T > &rhs) noexcept |
| Greater-than or equal-to operator. More...
|
|
template<typename T>
class playrho::Interval< T >
Interval template type.
This type encapsulates an interval as a min-max value range relationship.
- Invariant
- The min and max values can only be the result of
std::minmax(a, b)
or the special values of the "highest" and "lowest" values supported by the type for this class respectively indicating the "unset" value.
- See also
- https://en.wikipedia.org/wiki/Interval_(mathematics)
◆ value_type
Value type.
Alias for the type of the value that this class was template instantiated for.
◆ Interval() [1/4]
◆ Interval() [2/4]
template<typename T >
|
inlineexplicitconstexprnoexcept |
Initializing constructor.
Constructs an interval of a single value.
- Postcondition
GetMin()
returns the value of v
.
-
GetMax()
returns the value of v
.
◆ Interval() [3/4]
Initializing constructor.
Constructs an interval of two values.
- Postcondition
GetMin()
returns min of a
and b
.
-
GetMax()
returns max of a
and b
.
◆ Interval() [4/4]
Initializing constructor.
Constructs an interval of the min and max of a list of values.
- Postcondition
GetMin()
returns min of ilist
.
-
GetMax()
returns max of ilist
.
◆ Expand()
Expands this interval.
Expands this interval by decreasing the min value if the given value is negative, or by increasing the max value if the given value is positive.
- Parameters
-
v | Amount to expand this interval by. |
- Note
- This function is either non-throwing or offers the "strong exception guarantee". It has no effect on the interval if it throws.
- Warning
- Behavior is not specified if expanding the range by the given amount overflows the range of the
value_type
,
◆ ExpandEqually()
Expands equally both ends of this interval.
Expands equally this interval by decreasing the min value and by increasing the max value by the given amount.
- Note
- This operation has no effect if this interval is "unset".
- Parameters
-
v | Amount to expand both ends of this interval by. |
- Note
- This function is either non-throwing or offers the "strong exception guarantee". It has no effect on the interval if it throws.
- Warning
- Behavior is not specified if expanding the range by the given amount overflows the range of the
value_type
,
◆ GetHighest()
template<typename T >
|
inlinestaticconstexprnoexcept |
Gets the "highest" value supported by the value_type
.
- Returns
- Positive infinity if supported by the value type, limits::max() otherwise.
◆ GetLowest()
template<typename T >
|
inlinestaticconstexprnoexcept |
Gets the "lowest" value supported by the value_type
.
- Returns
- Negative infinity if supported by the value type, limits::lowest() otherwise.
◆ Include() [1/2]
Includes the given interval into this interval.
- Note
- If this value is the "unset" value then the result of this operation will be the given value.
-
This function is either non-throwing or offers the "strong exception guarantee". It has no effect on the interval if it throws.
- Parameters
-
v | Value to "include" into this value. |
- Postcondition
- This value's "min" is the minimum of the given value's "min" and this value's "min".
◆ Include() [2/2]
Includes the given value into this interval.
- Note
- This function is either non-throwing or offers the "strong exception guarantee". It has no effect on the interval if it throws.
-
If this value is the "unset" value then the result of this operation will be the given value.
- Parameters
-
v | Value to "include" into this value. |
- Postcondition
- This value's "min" is the minimum of the given value and this value's "min".
◆ Intersect()
Intersects this interval with the given interval.
- Note
- This function is either non-throwing or offers the "strong exception guarantee". It has no effect on the interval if it throws.
◆ Move()
Moves the interval by the given amount.
- Note
- This function is either non-throwing or offers the "strong exception guarantee". It has no effect on the interval if it throws.
◆ GetCenter()
template<typename T , typename U = decltype(Interval<T>{}, ((T{} + T{}) / 2))>
constexpr auto GetCenter |
( |
const Interval< T > & |
v | ) |
|
|
related |
Gets the center of the given interval.
- Warning
- Behavior is not specified if the difference between the given range's max and min values overflows the range of the
Interval::value_type
.
◆ IsIntersecting()
template<typename T , typename U = decltype(Interval<T>{}, T{} < T{}, T{} >= T{})>
constexpr bool IsIntersecting |
( |
const Interval< T > & |
a, |
|
|
const Interval< T > & |
b |
|
) |
| |
|
related |
Checks whether two value ranges have any intersection/overlap at all.
- Note
a
intersects with b
if and only if any value of a
is also a value of b
.
◆ operator!=()
◆ operator<()
template<typename T >
constexpr bool operator< |
( |
const Interval< T > & |
lhs, |
|
|
const Interval< T > & |
rhs |
|
) |
| |
|
related |
◆ operator<=()
template<typename T >
constexpr bool operator<= |
( |
const Interval< T > & |
lhs, |
|
|
const Interval< T > & |
rhs |
|
) |
| |
|
related |
◆ operator==()
◆ operator>()
template<typename T >
constexpr bool operator> |
( |
const Interval< T > & |
lhs, |
|
|
const Interval< T > & |
rhs |
|
) |
| |
|
related |
◆ operator>=()
template<typename T >
constexpr bool operator>= |
( |
const Interval< T > & |
lhs, |
|
|
const Interval< T > & |
rhs |
|
) |
| |
|
related |
The documentation for this class was generated from the following files: