Range.hpp

A simple way to track value ranges.

Note

Status: BETA

Functions

template<typename T, bool INCLUDE_UPPER = true>
Range<T, INCLUDE_UPPER> MakeRange(T _l, T _u)

Build a new range with auto-detected type.

template<bool INCLUDE_UPPER = true>
inline Range<int, INCLUDE_UPPER> IntRange(int _l, int _u)

Build a new range of type int.

template<bool INCLUDE_UPPER = true>
inline Range<double, INCLUDE_UPPER> DRange(double _l, double _u)

Build a new range of type double.

template<typename T, bool INCLUDE_UPPER = true>
class Range
#include <Range.hpp>

A range of values from a lower limit to and upper limit, of any provided type.

Public Functions

Range() = default
inline Range(T val)
inline Range(T _l, T _u)
Range(const Range&) = default
Range &operator=(const Range&) = default
bool operator==(const Range &_in) const = default
bool operator!=(const Range &_in) const = default
inline T GetLower() const
inline T GetUpper() const
inline T GetEpsilon() const
inline T GetMaxValue() const
inline T GetSize() const
inline String ToString() const
inline void SetLower(T l)
inline void SetUpper(T u)
inline void Set(T _l, T _u)
inline void ShiftDown(T shift)
inline void ShiftUp(T shift)
inline void Shift(T shift)
inline void SetMinLower()
inline void SetMaxUpper()
inline void Grow(T amount = 1)
inline T &Lower()
inline T &Upper()
inline const T &Lower() const noexcept
inline const T &Upper() const noexcept
inline bool Has(T value) const

Determine if a provided value is in the range INCLUSIVE of the endpoints.

inline bool Valid(T value) const
inline bool HasRange(this_t in_range)
inline bool IsConnected(this_t in) const

Will identify if two ranges are next to each other or overlapping.

inline bool HasOverlap(this_t in) const

Determine if there is overlap between two range. Similar to IsConnected, but cannot be merely adjacent.

inline T CalcOverlap(this_t in) const

Determine the amount of overlap between two range.

inline bool Expand(T val)

Expand this range to encompass a provided value.

Parameters:

val – Value to expand through.

Returns:

Whether the range has changed due to this expansion.

template<typename ...Ts>
inline bool Expand(T val1, T val2, Ts... args)

Expand this range to encompass all provided values.

Returns:

Whether the range has changed due to this expansion.

inline bool Merge(this_t in)

Merge this range with another. Must be adjacent or overlap (return false if not!)

inline bool Append(T val)

Add a specified value to the end of a range (or return false if failed).

inline T Clamp(T _in) const

Force a value into range.

inline T LimitValue(T _in) const
inline double ToFraction(T _in) const
inline T FromFraction(double frac) const
inline void LimitLower(T in)
inline void LimitUpper(T in)
inline size_t CalcBin(T value, size_t num_bins) const
inline vector<T> Spread(const size_t s) const

Produce a vector that spreads values evenly across the range.

Public Static Functions

static inline constexpr T MaxLimit()
static inline constexpr T MinLimit()

Public Static Attributes

static constexpr bool is_integral = std::is_integral<T>()

Private Types

using this_t = Range<T, INCLUDE_UPPER>

Private Members

T lower = std::numeric_limits<T>::lowest()

Beginning of range, inclusive.

T upper = std::numeric_limits<T>::max()

End of range, (included if INCLUDE_UPPER)