X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fmath%2FSGVec4.hxx;h=4339dfd9b79879a3fab0da2b59a5cca747cc5578;hb=584ee1364f25e5c3795f9ff4633a792cba39bfc7;hp=6e42d957d8710f9a3a56c85cfa9d0b3ddf41f0bd;hpb=2cc5e776b335e2d18573270bbe9ded1f834ea3d1;p=simgear.git diff --git a/simgear/math/SGVec4.hxx b/simgear/math/SGVec4.hxx index 6e42d957..4339dfd9 100644 --- a/simgear/math/SGVec4.hxx +++ b/simgear/math/SGVec4.hxx @@ -18,6 +18,8 @@ #ifndef SGVec4_H #define SGVec4_H +#include + /// 4D Vector Class template class SGVec4 { @@ -242,6 +244,19 @@ max(S s, const SGVec4& v) SGMisc::max(s, v(3))); } +/// Add two vectors taking care of (integer) overflows. The values are limited +/// to the respective minimum and maximum values. +template +SGVec4 addClipOverflow(SGVec4 const& lhs, SGVec4 const& rhs) +{ + return SGVec4( + SGMisc::addClipOverflow(lhs.x(), rhs.x()), + SGMisc::addClipOverflow(lhs.y(), rhs.y()), + SGMisc::addClipOverflow(lhs.z(), rhs.z()), + SGMisc::addClipOverflow(lhs.w(), rhs.w()) + ); +} + /// Scalar dot product template inline