PlayRho  2.0.0
An interactive physics engine & library.
playrho::Interval< T > Class Template Reference

Interval template type. More...

#include <playrho/Interval.hpp>

Inheritance diagram for playrho::Interval< T >:
[legend]

Public Types

using value_type = T
 Value type. More...
 

Public Member Functions

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 IntervalExpand (const value_type &v) noexcept(noexcept(m_min+=v) &&noexcept(m_max+=v))
 Expands this interval. More...
 
constexpr IntervalExpandEqually (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 IntervalInclude (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 IntervalInclude (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 IntervalIntersect (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 IntervalMove (const value_type &v) noexcept(noexcept(*this+v) &&std::is_nothrow_copy_assignable_v< Interval >)
 Moves the interval by the given amount. More...
 

Static Public Member Functions

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

Related Functions

(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...
 

Detailed Description

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)

Member Typedef Documentation

◆ value_type

template<typename T >
using playrho::Interval< T >::value_type = T

Value type.

Alias for the type of the value that this class was template instantiated for.

Constructor & Destructor Documentation

◆ Interval() [1/4]

template<typename T >
constexpr playrho::Interval< T >::Interval ( ) const
constexprdefaultnoexcept

Default constructor.

Constructs an "unset" interval.

Postcondition
GetMin() returns the value of GetHighest().
GetMax() returns the value of GetLowest().

◆ Interval() [2/4]

template<typename T >
constexpr playrho::Interval< T >::Interval ( const value_type v)
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]

template<typename T >
constexpr playrho::Interval< T >::Interval ( const value_type a,
const value_type b 
)
inlineconstexprnoexcept

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]

template<typename T >
constexpr playrho::Interval< T >::Interval ( const std::initializer_list< T > &  ilist)
inlineconstexprnoexcept

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.

Member Function Documentation

◆ Expand()

template<typename T >
constexpr Interval& playrho::Interval< T >::Expand ( const value_type v)
inlineconstexprnoexcept

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
vAmount 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()

template<typename T >
constexpr Interval& playrho::Interval< T >::ExpandEqually ( const NonNegative< value_type > &  v)
inlineconstexprnoexcept

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
vAmount 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 >
static constexpr value_type playrho::Interval< T >::GetHighest ( )
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 >
static constexpr value_type playrho::Interval< T >::GetLowest ( )
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]

template<typename T >
constexpr Interval& playrho::Interval< T >::Include ( const Interval< T > &  v)
inlineconstexprnoexcept

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
vValue 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]

template<typename T >
constexpr Interval& playrho::Interval< T >::Include ( const value_type v)
inlineconstexprnoexcept

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
vValue to "include" into this value.
Postcondition
This value's "min" is the minimum of the given value and this value's "min".

◆ Intersect()

template<typename T >
constexpr Interval& playrho::Interval< T >::Intersect ( const Interval< T > &  v)
inlineconstexprnoexcept

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()

template<typename T >
constexpr Interval& playrho::Interval< T >::Move ( const value_type v)
inlineconstexprnoexcept

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.

Friends And Related Function Documentation

◆ 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!=()

template<typename T >
constexpr bool operator!= ( const Interval< T > &  a,
const Interval< T > &  b 
)
related

Inequality operator.

Note
Satisfies the EqualityComparable named requirement for Interval objects.
See also
https://en.cppreference.com/w/cpp/named_req/EqualityComparable

◆ operator<()

template<typename T >
constexpr bool operator< ( const Interval< T > &  lhs,
const Interval< T > &  rhs 
)
related

Less-than operator.

Note
Provides a "strict weak ordering" relation.
This is a lexicographical comparison.
Obeys the LessThanComparable named requirement: for all a, !(a < a); if (a < b) then !(b < a); if (a < b) and (b < c) then (a < c); with equiv = !(a < b) && !(b < a), if equiv(a, b) and equiv(b, c), then equiv(a, c).
See also
https://en.wikipedia.org/wiki/Weak_ordering#Strict_weak_orderings
https://en.cppreference.com/w/cpp/named_req/LessThanComparable

◆ operator<=()

template<typename T >
constexpr bool operator<= ( const Interval< T > &  lhs,
const Interval< T > &  rhs 
)
related

Less-than or equal-to operator.

Note
Provides a "strict weak ordering" relation.
This is a lexicographical comparison.
See also
https://en.wikipedia.org/wiki/Weak_ordering#Strict_weak_orderings

◆ operator==()

template<typename T >
constexpr bool operator== ( const Interval< T > &  a,
const Interval< T > &  b 
)
related

Equality operator.

Note
Satisfies the EqualityComparable named requirement for Interval objects.
See also
https://en.cppreference.com/w/cpp/named_req/EqualityComparable

◆ operator>()

template<typename T >
constexpr bool operator> ( const Interval< T > &  lhs,
const Interval< T > &  rhs 
)
related

Greater-than operator.

Note
Provides a "strict weak ordering" relation.
This is a lexicographical comparison.
See also
https://en.wikipedia.org/wiki/Weak_ordering#Strict_weak_orderings

◆ operator>=()

template<typename T >
constexpr bool operator>= ( const Interval< T > &  lhs,
const Interval< T > &  rhs 
)
related

Greater-than or equal-to operator.

Note
Provides a "strict weak ordering" relation.
This is a lexicographical comparison.
See also
https://en.wikipedia.org/wiki/Weak_ordering#Strict_weak_orderings

The documentation for this class was generated from the following files: