From fd52e932945cac0dd1d15be866865c0536eecf88 Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Sat, 30 Nov 2019 08:36:58 +0100 Subject: [PATCH] Document range --- src/sfizz/Range.h | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/sfizz/Range.h b/src/sfizz/Range.h index 78e3151c..2af64b4f 100644 --- a/src/sfizz/Range.h +++ b/src/sfizz/Range.h @@ -28,7 +28,11 @@ namespace sfz { - +/** + * @brief This class holds a range with functions to clamp and test if a value is in the range + * + * @tparam Type + */ template class Range { static_assert(std::is_arithmetic::value, "The Type should be arithmetic"); @@ -58,6 +62,11 @@ public: ~Range() = default; Type getStart() const noexcept { return _start; } Type getEnd() const noexcept { return _end; } + /** + * @brief Get the range as an std::pair of the endpoints + * + * @return std::pair + */ std::pair getPair() const noexcept { return std::make_pair(_start, _end); } Range(const Range& range) = default; Range(Range&& range) = default; @@ -75,9 +84,35 @@ public: if (end < _start) _start = end; } + /** + * @brief Clamp a value within the range including the endpoints + * + * @param value + * @return Type + */ Type clamp(Type value) const noexcept { return ::clamp(value, _start, _end); } + /** + * @brief Checks if a value is in the range, including the endpoints + * + * @param value + * @return true + * @return false + */ bool containsWithEnd(Type value) const noexcept { return (value >= _start && value <= _end); } + /** + * @brief Checks if a value is in the range, excluding the end of the range + * + * @param value + * @return true + * @return false + */ bool contains(Type value) const noexcept { return (value >= _start && value < _end); } + /** + * @brief Shrink the region if it is smaller than the provided start and end points + * + * @param start + * @param end + */ void shrinkIfSmaller(Type start, Type end) { if (start > end)