PlayRho  1.1.0
An Interactive Real-Time-Oriented C++ Physics Engine & Library
playrho::Interval< T > Class Template Reference

Interval template type. More...

#include <Interval.hpp>

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

Public Types

using value_type = T
 Value type. More...
 
using limits = std::numeric_limits< value_type >
 Limits alias for the value_type.
 

Public Member Functions

constexpr Interval ()=default
 Default constructor. More...
 
constexpr Interval (const Interval &other)=default
 Copy constructor. More...
 
constexpr Interval (Interval &&other)=default
 Move constructor. More...
 
constexpr Interval (const value_type &v) noexcept
 Initializing constructor. More...
 
constexpr Interval (const value_type &a, const value_type &b) noexcept
 Initializing constructor.
 
constexpr Interval (const std::initializer_list< T > ilist) noexcept
 Initializing constructor.
 
Intervaloperator= (const Interval &other)=default
 Copy assignment operator. More...
 
Intervaloperator= (Interval &&other)=default
 Move assignment operator. More...
 
constexpr IntervalMove (const value_type &v) noexcept
 Moves the interval by the given amount. More...
 
constexpr value_type GetMin () const noexcept
 Gets the minimum value of this range.
 
constexpr value_type GetMax () const noexcept
 Gets the maximum value of this range.
 
constexpr IntervalInclude (const value_type &v) noexcept
 Includes the given value into this interval. More...
 
constexpr IntervalInclude (const Interval &v) noexcept
 Includes the given interval into this interval. More...
 
constexpr IntervalIntersect (const Interval &v) noexcept
 Intersects this interval with the given interval.
 
constexpr IntervalExpand (const value_type &v) noexcept
 Expands this interval. More...
 
constexpr IntervalExpandEqually (const NonNegative< value_type > &v) noexcept
 Expands equally both ends of this interval. More...
 

Static Public Member Functions

static constexpr value_type GetLowest () noexcept
 Gets the "lowest" value supported by the value_type. More...
 
static constexpr value_type GetHighest () noexcept
 Gets the "highest" value supported by the value_type. More...
 

Private Types

using pair_type = std::pair< value_type, value_type >
 Internal pair type. More...
 

Private Member Functions

constexpr Interval (pair_type pair) noexcept
 Internal pair type accepting constructor.
 

Private Attributes

value_type m_min = GetHighest()
 Min value.
 
value_type m_max = GetLowest()
 Max value.
 

Related Functions

(Note that these are not member functions.)

using LengthInterval = Interval< Length >
 Length Interval alias.
 
template<typename T >
constexpr T GetCenter (const Interval< T > &v) noexcept
 Gets the center of the given interval. More...
 
template<typename T >
constexpr bool IsIntersecting (const Interval< T > &a, const Interval< T > &b) noexcept
 Checks whether two value ranges have any intersection/overlap at all.
 
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 >
constexpr bool operator== (const Interval< T > &a, const Interval< T > &b) noexcept
 Equality operator. More...
 
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 > &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

◆ pair_type

template<typename T >
using playrho::Interval< T >::pair_type = std::pair<value_type, value_type>
private

Internal pair type.

Note
Uses std::pair since it's the most natural type given that std::minmax returns it.

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

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 Interval< T > &  other)
constexprdefault

Copy constructor.

Postcondition
GetMin() returns the value of other.GetMin().
GetMax() returns the value of other.GetMax().

◆ Interval() [3/4]

template<typename T >
constexpr playrho::Interval< T >::Interval ( Interval< T > &&  other)
constexprdefault

Move constructor.

Postcondition
GetMin() returns the value of other.GetMin().
GetMax() returns the value of other.GetMax().

◆ Interval() [4/4]

template<typename T >
constexpr playrho::Interval< T >::Interval ( const value_type v)
inlineexplicitconstexprnoexcept

Initializing constructor.

Postcondition
GetMin() returns the value of v.
GetMax() returns the value of v.

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.
Warning
Behavior is undefined 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.
Warning
Behavior is undefined 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.
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
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".

◆ Move()

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

Moves the interval by the given amount.

Warning
Behavior is undefined if incrementing the min or max value by the given amount overflows the finite range of the value_type,

◆ operator=() [1/2]

template<typename T >
Interval& playrho::Interval< T >::operator= ( const Interval< T > &  other)
default

Copy assignment operator.

Postcondition
GetMin() returns the value of other.GetMin().
GetMax() returns the value of other.GetMax().

◆ operator=() [2/2]

template<typename T >
Interval& playrho::Interval< T >::operator= ( Interval< T > &&  other)
default

Move assignment operator.

Postcondition
GetMin() returns the value of other.GetMin().
GetMax() returns the value of other.GetMax().

Friends And Related Function Documentation

◆ GetCenter()

template<typename T >
constexpr T GetCenter ( const Interval< T > &  v)
related

Gets the center of the given interval.

Warning
Behavior is undefined if the difference between the given range's max and min values overflows the range of the Interval::value_type.

◆ 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: