]> git.mxchange.org Git - simgear.git/blobdiff - simgear/math/SGVec2.hxx
Canvas: fix element mouse hit detection with OSG 3.3.2.
[simgear.git] / simgear / math / SGVec2.hxx
index 7b9ec15ef890e343a5bc00464f09a42125175a21..1ed150d82f4428f194359b61f8e6135cc093f414 100644 (file)
 #ifndef SGVec2_H
 #define SGVec2_H
 
-#include "SGLimits.hxx"
-#include "SGMathFwd.hxx"
-#include "SGMisc.hxx"
-
 #include <iosfwd>
 
 /// 2D Vector Class
@@ -200,6 +196,17 @@ SGVec2<T>
 max(S s, const SGVec2<T>& v)
 { return SGVec2<T>(SGMisc<T>::max(s, v(0)), SGMisc<T>::max(s, v(1))); }
 
+/// Add two vectors taking care of (integer) overflows. The values are limited
+/// to the respective minimum and maximum values.
+template<class T>
+SGVec2<T> addClipOverflow(SGVec2<T> const& lhs, SGVec2<T> const& rhs)
+{
+  return SGVec2<T>(
+    SGMisc<T>::addClipOverflow(lhs.x(), rhs.x()),
+    SGMisc<T>::addClipOverflow(lhs.y(), rhs.y())
+  );
+}
+
 /// Scalar dot product
 template<typename T>
 inline