+/// multiplication as a multiplicator, that is assume that the first vector
+/// represents a 4x4 diagonal matrix with the diagonal elements in the vector.
+/// Then the result is the product of that matrix times the second vector.
+template<typename T>
+inline
+SGVec4<T>
+mult(const SGVec4<T>& v1, const SGVec4<T>& v2)
+{ return SGVec4<T>(v1(0)*v2(0), v1(1)*v2(1), v1(2)*v2(2), v1(3)*v2(3)); }
+
+/// component wise min
+template<typename T>
+inline
+SGVec4<T>
+min(const SGVec4<T>& v1, const SGVec4<T>& v2)
+{
+ return SGVec4<T>(SGMisc<T>::min(v1(0), v2(0)),
+ SGMisc<T>::min(v1(1), v2(1)),
+ SGMisc<T>::min(v1(2), v2(2)),
+ SGMisc<T>::min(v1(3), v2(3)));
+}
+template<typename S, typename T>
+inline
+SGVec4<T>
+min(const SGVec4<T>& v, S s)
+{
+ return SGVec4<T>(SGMisc<T>::min(s, v(0)),
+ SGMisc<T>::min(s, v(1)),
+ SGMisc<T>::min(s, v(2)),
+ SGMisc<T>::min(s, v(3)));
+}
+template<typename S, typename T>
+inline
+SGVec4<T>
+min(S s, const SGVec4<T>& v)
+{
+ return SGVec4<T>(SGMisc<T>::min(s, v(0)),
+ SGMisc<T>::min(s, v(1)),
+ SGMisc<T>::min(s, v(2)),
+ SGMisc<T>::min(s, v(3)));
+}
+
+/// component wise max
+template<typename T>
+inline
+SGVec4<T>
+max(const SGVec4<T>& v1, const SGVec4<T>& v2)
+{
+ return SGVec4<T>(SGMisc<T>::max(v1(0), v2(0)),
+ SGMisc<T>::max(v1(1), v2(1)),
+ SGMisc<T>::max(v1(2), v2(2)),
+ SGMisc<T>::max(v1(3), v2(3)));
+}
+template<typename S, typename T>
+inline
+SGVec4<T>
+max(const SGVec4<T>& v, S s)
+{
+ return SGVec4<T>(SGMisc<T>::max(s, v(0)),
+ SGMisc<T>::max(s, v(1)),
+ SGMisc<T>::max(s, v(2)),
+ SGMisc<T>::max(s, v(3)));
+}
+template<typename S, typename T>
+inline
+SGVec4<T>
+max(S s, const SGVec4<T>& v)
+{
+ return SGVec4<T>(SGMisc<T>::max(s, v(0)),
+ SGMisc<T>::max(s, v(1)),
+ SGMisc<T>::max(s, v(2)),
+ SGMisc<T>::max(s, v(3)));
+}
+
+/// Add two vectors taking care of (integer) overflows. The values are limited
+/// to the respective minimum and maximum values.
+template<class T>
+SGVec4<T> addClipOverflow(SGVec4<T> const& lhs, SGVec4<T> const& rhs)
+{
+ return SGVec4<T>(
+ SGMisc<T>::addClipOverflow(lhs.x(), rhs.x()),
+ SGMisc<T>::addClipOverflow(lhs.y(), rhs.y()),
+ SGMisc<T>::addClipOverflow(lhs.z(), rhs.z()),
+ SGMisc<T>::addClipOverflow(lhs.w(), rhs.w())
+ );
+}
+