]> 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 68e74c1736a874fb6b06549c49057d993b3e9bd1..1ed150d82f4428f194359b61f8e6135cc093f414 100644 (file)
@@ -18,6 +18,8 @@
 #ifndef SGVec2_H
 #define SGVec2_H
 
+#include <iosfwd>
+
 /// 2D Vector Class
 template<typename T>
 class SGVec2 {
@@ -194,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