43 static_assert(std::is_arithmetic<T>::value,
"Template argument of Interval must be arithmetic.");
59 constexpr RangeT(T minimum, T maximum, T increment)
61 , m_increment{ increment }
63 if (increment > maximum - minimum)
93 PEAK_COMMON_NO_DISCARD
constexpr T
Constrain(T value)
const
98 if (!IsIncrementEqualToZero<T>() && value > minimum)
100 value = RoundToIncrement(value);
103 return detail::Clamp(value, minimum, maximum);
131 return !(rhs == *
this);
154 PEAK_COMMON_NO_DISCARD std::string
ToString()
const
156 std::ostringstream ss;
164 friend detail::BackendAccessor<RangeT<T>>;
166 template <
typename U = T,
typename std::enable_if<has_c_type_of<RangeT<U>>::value,
bool>::type = false>
168 :
RangeT<U>(range.minimum, range.maximum, range.increment)
171 template <
typename U = T,
typename std::enable_if<has_c_type_of<RangeT<U>>::value,
bool>::type = false>
172 constexpr explicit operator detail::c_type_of_t<RangeT<U>>()
const
177 template <typename V = T, std::enable_if_t<std::is_integral<V>::value,
int> = 0>
178 PEAK_COMMON_NO_DISCARD
constexpr bool IsIncrementEqualToZero()
const
180 return m_increment == 0;
183 template <typename V = T, std::enable_if_t<std::is_floating_point<V>::value,
int> = 0>
184 PEAK_COMMON_NO_DISCARD
constexpr bool IsIncrementEqualToZero()
const
187 constexpr uint32_t ulp = 4;
191 template<typename V = T, std::enable_if_t<std::is_integral<V>::value,
int> = 0>
192 PEAK_COMMON_NO_DISCARD
constexpr V RoundToIncrement(V value)
const
195 const auto step = (offset + m_increment / 2) / m_increment;
199 template<typename V = T, std::enable_if_t<std::is_floating_point<V>::value,
int> = 0>
200 PEAK_COMMON_NO_DISCARD
constexpr V RoundToIncrement(V value)
const
Thrown when a function receives an invalid parameter.
Definition peak_common_exceptions.hpp:53
Represents a continuous numeric interval with inclusive lower and upper bounds.
Definition peak_common_interval.hpp:39
constexpr T GetMinimum() const
Returns the lower boundary of the interval.
Definition peak_common_interval.hpp:72
constexpr IntervalT(double minimum, double maximum)
Definition peak_common_interval.hpp:56
constexpr bool operator==(const IntervalT< H > &rhs) const
Compares two intervals for equality (integral types).
Definition peak_common_interval.hpp:121
constexpr T GetMaximum() const
Returns the upper boundary of the interval.
Definition peak_common_interval.hpp:83
Represents a numeric range with defined boundaries and a fixed increment.
Definition peak_common_range.hpp:40
std::string ToString() const
Returns a string representation of the range.
Definition peak_common_range.hpp:154
constexpr bool operator==(const RangeT &rhs) const
Compares this range with another for equality.
Definition peak_common_range.hpp:116
constexpr T Constrain(T value) const
Returns a value that is constrained to this range.
Definition peak_common_range.hpp:93
constexpr T GetIncrement() const
Retrieves the increment value associated with this range.
Definition peak_common_range.hpp:76
constexpr RangeT(T minimum, T maximum, T increment)
Constructs a range with specified minimum, maximum, and increment values.
Definition peak_common_range.hpp:59
friend std::ostream & operator<<(std::ostream &os, RangeT range)
Outputs the range as a human-readable string to a stream.
Definition peak_common_range.hpp:142
constexpr bool operator!=(const RangeT &rhs) const
Compares this range with another for inequality.
Definition peak_common_range.hpp:129
constexpr bool AreAlmostEqual(H lhs, H rhs, uint32_t ulp)
Compares two floating-point values for approximate equality using a ULP-based tolerance.
Definition peak_common_math.hpp:45
detail::RangeT< int32_t > Range
Alias for a range of 32-bit signed integers.
Definition peak_common_range.hpp:237
detail::RangeT< double > RangeD
Alias for a range of double-precision floating-point numbers.
Definition peak_common_range.hpp:282
detail::RangeT< float > RangeF
Alias for a range of floating-point numbers.
Definition peak_common_range.hpp:267
detail::RangeT< uint8_t > RangeU8
Alias for a range of 8-bit unsigned integers.
Definition peak_common_range.hpp:297
detail::RangeT< int64_t > Range64
Alias for a range of 64-bit signed integers.
Definition peak_common_range.hpp:252
detail::RangeT< uint32_t > RangeU
Alias for a range of 32-bit unsigned integers.
Definition peak_common_range.hpp:222
Namespace for internal implementation details and low-level types.
Definition peak_common_math.hpp:19
Root namespace for common types and interfaces shared across multiple libraries.
Definition peak_common_math.hpp:17