From 98312c2c379cb9707914fe0484e2f6c0e08ead3d Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Wed, 11 Mar 2015 16:27:37 +1100 Subject: [PATCH] range: add interpolation accessor --- range.cpp | 9 +++++++++ range.hpp | 3 +++ 2 files changed, 12 insertions(+) diff --git a/range.cpp b/range.cpp index 4155a323..da6a8962 100644 --- a/range.cpp +++ b/range.cpp @@ -66,6 +66,15 @@ util::range::contains (const range &r) const } +//----------------------------------------------------------------------------- +template +T +util::range::at (float t) const +{ + return static_cast (min + (max - min) * t); +} + + //----------------------------------------------------------------------------- template T diff --git a/range.hpp b/range.hpp index ee056e67..21ad4cad 100644 --- a/range.hpp +++ b/range.hpp @@ -45,6 +45,9 @@ namespace util { /// Check whether a range falls partially within (inclusive) this range //bool includes (const range &r) const; + /// interpolate between min-max using the unit position + T at (float) const; + /// Return the closest number that falls within the range. T clamp (T val) const;