Range< T > Class Template Reference Math Library

#include <range.h>

详细描述

template<typename T>
class maxon::Range< T >

A Range represents a closed interval of values min ... max (both bounds are inclusive). If T is a vector type, this is actually a multi-dimensional interval such as a rectangle for two-dimensional vectors or an axis-aligned (bounding) box in three dimensions.

To compare T values, range uses a.LessThanOrEqual(b) if possible, otherwise a <= b . The corresponding order may be a partial order (as it is the case for vectors).

Template Parameters
T The underlying datatype, either a scalar type, or a vector type where T::ValueType specifies the type of the vector elements.

Public Types

using  ScalarType = decltype( PrivateRangeValueTypeHelper < T >( OVERLOAD_MAX_RANK ))

公共成员函数

constexpr  Range ()
constexpr  Range (const T &v)
constexpr  Range (const T &rangeMin, const T &rangeMax)
void  重置 ()
void  Set (const T &v)
void  Set (const T &rangeMin, const T &rangeMax)
void  添加 (const T &p)
void  添加 (const T &rangeMin, const T &rangeMax)
void  添加 (const Range &range)
void  Intersect (const T &rangeMin, const T &rangeMax)
void  Intersect (const Range &range)
Range operator+= (const T &shift)
Range operator-= (const T &shift)
Range   operator+ (const T &shift) const
Range   operator- (const T &shift) const
Bool   IsIntersecting (const Range &range) const
Bool   IsEmpty () const
Bool   IsPopulated () const
GetMin () const
GetMax () const
GetCenter () const
GetDimension () const
Bool   Contains (const T &value) const
Bool   Contains (const Range < T > &value) const
  MAXON_OPERATOR_EQUALITY_HASHCODE ( Range , _minValue , _maxValue )
SFINAEHelper < String , T >::type  ToString (const FormatStatement *format=nullptr) const

Public Attributes

_minValue
_maxValue

Member Typedef Documentation

◆  ScalarType

using ScalarType = decltype( PrivateRangeValueTypeHelper <T>( OVERLOAD_MAX_RANK ))

构造函数 & 析构函数文档编制

◆  Range() [1/3]

constexpr Range ( )
constexpr

Constructs an empty range. min is set to the maximum possible value, max to the minimum possible value.

◆  Range() [2/3]

constexpr Range ( const T &  v )
explicit constexpr

Constructs a singleton range containing exactly v.

参数
[in] v Initial value for the range.

◆  Range() [3/3]

constexpr Range ( const T &  rangeMin ,
const T &  rangeMax  
)
constexpr

Constructs the range rangeMin ... rangeMax. If rangeMin is not less than or equal to rangeMax, the range will be empty.

参数
[in] rangeMin Initial minimum value for the range.
[in] rangeMax Initial maximum value for the range.

成员函数文档编制

◆  Reset()

void Reset ( )

Resets the range to its initial state, i.e., to an empty range where min is set to the maximum possible value, max to the minimum possible value.

◆  Set() [1/2]

void Set ( const T &  v )

Sets this range to a singleton range containing exactly v.

参数
[in] v Singleton value for the range.

◆  Set() [2/2]

void Set ( const T &  rangeMin ,
const T &  rangeMax  
)

Sets this range to rangeMin ... rangeMax. If rangeMin is not less than or equal to rangeMax, the range will be empty.

参数
[in] rangeMin Minimum value for the range.
[in] rangeMax Maximum value for the range.

◆  Add() [1/3]

void Add ( const T &  p )

Extends this range if necessary so that it encloses p.

参数
[in] p Value to include in this range.

◆  Add() [2/3]

void Add ( const T &  rangeMin ,
const T &  rangeMax  
)

Extends this range if necessary so that it encloses the range given by rangeMin ... rangeMax. It that range is empty, nothing happens.

参数
[in] rangeMin Minimum value of the other range to include.
[in] rangeMax Maximum value of the other range to include.

◆  Add() [3/3]

void Add ( const Range < T > &  range )

Extends this range if necessary so that it encloses the other range. It that range is empty, nothing happens.

参数
[in] range Another range to include in this range.

◆  Intersect() [1/2]

void Intersect ( const T &  rangeMin ,
const T &  rangeMax  
)

Intersects this range with the range given by rangeMin ... rangeMax.

参数
[in] rangeMin Minimum value of the other range for intersection.
[in] rangeMax Maximum value of the other range for intersection.

◆  Intersect() [2/2]

void Intersect ( const Range < T > &  range )

Intersects this range with the other range.

参数
[in] range Another range to intersect with.

◆  operator+=()

Range & operator+= ( const T &  shift )

Shifts this range by #shift. The value of #shift is added to the minimum and maximum value.

参数
[in] shift Value to add to the bounds.

◆  operator-=()

Range & operator-= ( const T &  shift )

Shifts this range by #shift. The value of #shift is substracted from the minimum and maximum value.

参数
[in] shift Value to subtract from the bounds.

◆  operator+()

Range operator+ ( const T &  shift ) const

Returns a new range which is given by this range, shifted by #shift. The value of #shift is added to the minimum and maximum value.

参数
[in] shift Value to add to the bounds.
返回
New range with shifted bounds.

◆  operator-()

Range operator- ( const T &  shift ) const

Returns a new range which is given by this range, shifted by #shift. The value of #shift is subtracted from the minimum and maximum value.

参数
[in] shift Value to subtract from the bounds.
返回
New range with shifted bounds.

◆  IsIntersecting()

Bool IsIntersecting ( const Range < T > &  range ) const

Tests if this range intersects with the other range

参数
[in] range Another range to test the intersect with.
返回
Return true if the ranges intersect, false otherwise

◆  IsEmpty()

Bool IsEmpty ( ) const

Returns true if this range is empty. In that case GetMin() , GetMax() , GetCenter() , GetDimension() will return a guaranteed, but incorrect value of 0.

返回
True if range is empty.

◆  IsPopulated()

Bool IsPopulated ( ) const

Returns true if this range is populated.

返回
True if range is not empty.

◆  GetMin()

T GetMin ( ) const

Returns the minimum boundary. For an empty range, this will return T(0).

返回
Minimum boundary, or T(0) for an empty range.

◆  GetMax()

T GetMax ( ) const

Returns the maximum boundary. For an empty range, this will return T(0).

返回
Maximum boundary, or T(0) for an empty range.

◆  GetCenter()

T GetCenter ( ) const

Returns the center of the range. For an empty range, this will return T(0).

返回
Center of the range, or T(0) for an empty range.

◆  GetDimension()

T GetDimension ( ) const

Returns the dimension of range. For an empty range, this will return T(0), otherwise the difference of maximum and minimum value. Note that for integral datatypes this does not calculate the number of elements (which is _maxValue - _minValue + 1). To do so you need to add 1 manually.

返回
Dimension of the range, or T(0) for an empty range.

◆  Contains() [1/2]

Bool Contains ( const T &  value ) const

Tests if the given value is contained in this range.

参数
[in] value Value to check.
返回
True if the value is contained in the range.

◆  Contains() [2/2]

Bool Contains ( const Range < T > &  value ) const

Tests if the given value is contained in this range.

参数
[in] value Value to check.
返回
True if the value is contained in the range.

◆  MAXON_OPERATOR_EQUALITY_HASHCODE()

MAXON_OPERATOR_EQUALITY_HASHCODE ( Range < T >  ,
_minValue   ,
_maxValue    
)

◆  ToString()

SFINAEHelper < String , T>::type ToString ( const FormatStatement format = nullptr ) const

Member Data Documentation

◆  _minValue

T _minValue

The inclusive minimum boundary of this range.

◆  _maxValue

T _maxValue

The inclusive maximum boundary of this range. If the minimum boundary is not less than or equal to this, the range is empty.