diff --git a/range.cpp b/range.cpp index 665dee91..7d1cdf9a 100644 --- a/range.cpp +++ b/range.cpp @@ -77,6 +77,14 @@ range::clamp (T val) const { return std::max (min, std::min (val, max)); } +template +T +range::expand (T val) { + min = std::min (min, val); + max = std::max (max, val); +} + + template double range::normalise (T val) const { diff --git a/range.hpp b/range.hpp index 1767197a..5ce67d83 100644 --- a/range.hpp +++ b/range.hpp @@ -46,6 +46,9 @@ namespace util { /// Return the closest number that falls within the range. T clamp (T val) const; + /// Expand the range to include this value if necessary + T expand (T val); + /// Normalise a number to [0, 1] within the range. Does not check bounds. double normalise (T val) const;