]> git.mxchange.org Git - simgear.git/blobdiff - simgear/math/SGMisc.hxx
Refactor Canvas and add some helpers.
[simgear.git] / simgear / math / SGMisc.hxx
index a154d632b38c7baff1d9b31ab3bddb982a5ae388..8eaa124e27704eca149bf7f8c912fcd661670aba 100644 (file)
@@ -65,7 +65,7 @@ public:
       return min;
     T normalized = value - range*floor((value - min)/range);
     // two security checks that can only happen due to roundoff
-    if (value <= min)
+    if (normalized <= min)
       return min;
     if (max <= normalized)
       return min;
@@ -87,7 +87,11 @@ public:
   static int roundToInt(const T& v)
   { return int(round(v)); }
 
-#ifndef NDEBUG
+  // Linear interpolation between two arbitrary typed values
+  template<typename S>
+  static S lerp(const S& val0, const S& val1, const T& t)
+  { return val0*(T(1) - t) + val1*t; }
+
   /// Returns true if v is a NaN value
   /// Use with care: allways code that you do not need to use that!
   static bool isNaN(const T& v)
@@ -104,7 +108,6 @@ public:
     return !(v == v);
 #endif
   }
-#endif
 };
 
 #endif