#include <range.h>
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).
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)) |
Public Member Functions | |
constexpr | Range () |
constexpr | Range (const T &v) |
constexpr | Range (const T &rangeMin, const T &rangeMax) |
void | Reset () |
void | Set (const T &v) |
void | Set (const T &rangeMin, const T &rangeMax) |
void | Add (const T &p) |
void | Add (const T &rangeMin, const T &rangeMax) |
void | Add (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 |
T | GetMin () const |
T | GetMax () const |
T | GetCenter () const |
T | 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 | |
T | minValue |
T | maxValue |
using ScalarType = decltype(PrivateRangeValueTypeHelper<T>(OVERLOAD_MAX_RANK)) |
|
constexpr |
Constructs an empty range. min is set to the maximum possible value, max to the minimum possible value.
|
explicitconstexpr |
Constructs a singleton range containing exactly v.
[in] | v | Initial value for the range. |
|
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. |
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.
void Set | ( | const T & | v | ) |
Sets this range to a singleton range containing exactly v.
[in] | v | Singleton value for the range. |
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. |
void Add | ( | const T & | p | ) |
Extends this range if necessary so that it encloses p.
[in] | p | Value to include in this range. |
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. |
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. |
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. |
void Intersect | ( | const Range< T > & | range | ) |
Intersects this range with the other range.
[in] | range | Another range to intersect with. |
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. |
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. |
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. |
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. |
Tests if this range intersects with the other range
[in] | range | Another range to test the intersect with. |
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.
Bool IsPopulated | ( | ) | const |
Returns true if this range is populated.
T GetMin | ( | ) | const |
Returns the minimum boundary. For an empty range, this will return T(0).
T GetMax | ( | ) | const |
Returns the maximum boundary. For an empty range, this will return T(0).
T GetCenter | ( | ) | const |
Returns the center of the range. For an empty range, this will return T(0).
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.
Bool Contains | ( | const T & | value | ) | const |
Tests if the given value
is contained in this range.
[in] | value | Value to check. |
Tests if the given value
is contained in this range.
[in] | value | Value to check. |
SFINAEHelper<String, T>::type ToString | ( | const FormatStatement * | format = nullptr | ) | const |
T minValue |
The inclusive minimum boundary of this range.
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.