36 Range(const T _min, const T _max) noexcept;
40 Range(const std::pair<T, T>& _bounds) noexcept;
60 bool Contains(const U& _val, const
double _tolerance = 1e-8)
81 bool operator==(const
Range<T>& _other)
const {
82 return min == _other.min &&
max == _other.max;
100 void Resize(
const T _min,
const T _max) noexcept;
120 template <
typename T>
124 min(T(0)), max(T(0)) { }
127 template <
typename T>
130 Range(
const T _min,
const T _max) noexcept :
131 min(_min), max(_max) { }
134 template <
typename T>
137 Range(
const std::pair<T, T>& _bounds) noexcept :
138 min(_bounds.first), max(_bounds.second) { }
142 template <
typename T>
151 template <
typename T>
156 return (max + min) / T(2);
160 template <
typename T>
161 template <
typename U>
165 Contains(
const U& _val,
const double _tolerance)
const noexcept {
175 return min <= _val and _val <= max;
180 template <
typename T>
181 template <
typename U>
185 Clearance(
const U& _val)
const noexcept {
186 static_assert(!std::is_unsigned<T>::value,
"Can't compute clearance for "
187 "unsigned ranges as the return would be negative if the test value "
188 "lies outside the range.");
189 return std::min(_val - min, max - _val);
193 template <
typename T>
194 template <
typename U>
199 static_assert(!std::is_unsigned<T>::value,
"Can't compute clearance for "
200 "unsigned ranges as the return would be negative if the test value "
201 "lies outside the range.");
202 const T distToMin = std::abs(min - _val),
203 distToMax = std::abs(max - _val);
204 return distToMin < distToMax ? min : max;
208 template <
typename T>
213 return min + (max - min) *
DRand();
218 template <
typename T>
222 Resize(
const T _min,
const T _max) noexcept {
228 template <
typename T>
238 template <
typename T>
243 Translate(_t - Center());
247 template <
typename T>
252 min = std::min(min, _t);
253 max = std::max(max, _t);
258 template <
typename T>
261 return _os << _r.
min <<
":" << _r.
max;
265 template <
typename T>
269 return _is >> _r.
min >> std::skipws >> delim >> _r.
max;
double DRand()
Definition: MPUtils.cpp:8
std::ostream & operator<<(std::ostream &_os, const Range< T > &_r)
Definition: Range.h:260
std::istream & operator>>(std::istream &_is, Range< T > &_r)
Definition: Range.h:267
A range of numeric values.
Definition: Range.h:17
T ClearancePoint(const U &_val) const noexcept
Definition: Range.h:198
Range() noexcept
Construct a range over all values of T.
Definition: Range.h:123
void SetCenter(const T _t) noexcept
Definition: Range.h:242
T Center() const noexcept
Definition: Range.h:155
bool Contains(const U &_val, const double _tolerance=1e-8) const noexcept
Definition: Range.h:165
bool operator<(const Range< T > &_other) const
This only for placing in sets.
Definition: Range.h:86
T Sample() const noexcept
Sample the range for a random contained value with uniform probability.
Definition: Range.h:212
void Resize(const T _min, const T _max) noexcept
Definition: Range.h:222
void ExpandToInclude(const T _t) noexcept
Definition: Range.h:251
void Translate(const T _t) noexcept
Definition: Range.h:232
T Clearance(const U &_val) const noexcept
Definition: Range.h:185
T min
The lower bound on this range.
Definition: Range.h:23
T max
The upper bound on this range.
Definition: Range.h:24
T Length() const noexcept
Compute the length of this range.
Definition: Range.h:146