]> git.mxchange.org Git - simgear.git/blobdiff - simgear/math/SGVec3.hxx
canvas::Layout: support for contents margins.
[simgear.git] / simgear / math / SGVec3.hxx
index 56775d3ede34ba6affc15d8fa37076c684311875..b0f6b20625c54b1bb9bce07cb8750ada27657022 100644 (file)
@@ -18,6 +18,8 @@
 #ifndef SGVec3_H
 #define SGVec3_H
 
+#include <iosfwd>
+
 /// 3D Vector Class
 template<typename T>
 class SGVec3 {
@@ -286,6 +288,18 @@ max(S s, const SGVec3<T>& v)
                    SGMisc<T>::max(s, v(2)));
 }
 
+/// Add two vectors taking care of (integer) overflows. The values are limited
+/// to the respective minimum and maximum values.
+template<class T>
+SGVec3<T> addClipOverflow(SGVec3<T> const& lhs, SGVec3<T> const& rhs)
+{
+  return SGVec3<T>(
+    SGMisc<T>::addClipOverflow(lhs.x(), rhs.x()),
+    SGMisc<T>::addClipOverflow(lhs.y(), rhs.y()),
+    SGMisc<T>::addClipOverflow(lhs.z(), rhs.z())
+  );
+}
+
 /// Scalar dot product
 template<typename T>
 inline