From be0426ff24def41d20ce2046d549298ba45f8dd2 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 22 May 2012 14:12:06 +1000 Subject: [PATCH] Add range expansion method --- range.cpp | 8 ++++++++ range.hpp | 3 +++ 2 files changed, 11 insertions(+) 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;