diff --git a/range.cpp b/range.cpp index 83e51d74..4155a323 100644 --- a/range.cpp +++ b/range.cpp @@ -29,7 +29,7 @@ #include -//----------------------------------------------------------------------------- +/////////////////////////////////////////////////////////////////////////////// template util::range::range (T _min, T _max): min (_min), @@ -39,7 +39,16 @@ util::range::range (T _min, T _max): } -//----------------------------------------------------------------------------- +/////////////////////////////////////////////////////////////////////////////// +template +T +util::range::magnitude (void) const +{ + return max - min; +} + + +/////////////////////////////////////////////////////////////////////////////// template bool util::range::contains (T val) const @@ -57,28 +66,6 @@ util::range::contains (const range &r) const } -//----------------------------------------------------------------------------- -template -void -util::range::sanity (void) const -{ - CHECK (min <= max); -} - - -//----------------------------------------------------------------------------- -namespace util { - template <> - void - range::sanity (void) const - { - if (std::isnan (min) || std::isnan (max)) - return; - CHECK (min <= max); - } -} - - //----------------------------------------------------------------------------- template T @@ -100,7 +87,7 @@ util::range::expand (T val) } -//----------------------------------------------------------------------------- +/////////////////////////////////////////////////////////////////////////////// template util::range& util::range::operator*= (T val) @@ -121,7 +108,7 @@ util::range::operator* (T val) const } -//----------------------------------------------------------------------------- +/////////////////////////////////////////////////////////////////////////////// namespace util { template <> double @@ -150,7 +137,7 @@ util::range::random (void) const } -//----------------------------------------------------------------------------- +/////////////////////////////////////////////////////////////////////////////// namespace util { template <> bool @@ -180,7 +167,7 @@ util::range::operator ==(const util::range &rhs) const } -//----------------------------------------------------------------------------- +/////////////////////////////////////////////////////////////////////////////// template const util::range util::range::UNLIMITED (std::numeric_limits::has_infinity ? -std::numeric_limits::infinity () : @@ -201,6 +188,28 @@ const util::range util::range::UNIT (0.0, 1.0); +/////////////////////////////////////////////////////////////////////////////// +template +void +util::range::sanity (void) const +{ + CHECK (min <= max); +} + + +//----------------------------------------------------------------------------- +namespace util { + template <> + void + range::sanity (void) const + { + if (std::isnan (min) || std::isnan (max)) + return; + CHECK (min <= max); + } +} + + //----------------------------------------------------------------------------- namespace util { template struct range; diff --git a/range.hpp b/range.hpp index 62082698..d8910182 100644 --- a/range.hpp +++ b/range.hpp @@ -36,6 +36,8 @@ namespace util { range (T _min, T _max); + T magnitude (void) const; + /// Check whether value falls within this range (inclusive) bool contains (T val) const; /// Check whether a range falls completely within (inclusive) this range