summaryrefslogtreecommitdiffstats
path: root/Common/interface
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-12-23 02:25:56 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-12-23 02:25:56 +0000
commit022210bbb4bac4f8d6620aac64565dad146f3c75 (patch)
tree81f52d6a0ab2a67ceec8b3d04525b43e7b9ebcc0 /Common/interface
parentMinor update to basic math lib (diff)
downloadDiligentCore-022210bbb4bac4f8d6620aac64565dad146f3c75.tar.gz
DiligentCore-022210bbb4bac4f8d6620aac64565dad146f3c75.zip
Added clamp() function to math lib
Diffstat (limited to 'Common/interface')
-rw-r--r--Common/interface/BasicMath.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/Common/interface/BasicMath.h b/Common/interface/BasicMath.h
index 7add1f39..ab633357 100644
--- a/Common/interface/BasicMath.h
+++ b/Common/interface/BasicMath.h
@@ -863,6 +863,37 @@ Vector4<T> abs(const Vector4<T> &a)
}
+template<typename T>
+T clamp(T val, T _min, T _max)
+{
+ return val < _min ? _min : (val > _max ? _max : val);
+}
+
+template <class T>
+Vector2<T> clamp(const Vector2<T> &a, const Vector2<T> &_min, const Vector2<T> &_max)
+{
+ return Vector2<T>( clamp(a.x, _min.x, _max.x),
+ clamp(a.y, _min.y, _max.y));
+}
+
+template <class T>
+Vector3<T> clamp(const Vector3<T> &a, const Vector3<T> &_min, const Vector3<T> &_max)
+{
+ return Vector3<T>( clamp(a.x, _min.x, _max.x),
+ clamp(a.y, _min.y, _max.y),
+ clamp(a.z, _min.z, _max.z));
+}
+
+template <class T>
+Vector4<T> clamp(const Vector4<T> &a, const Vector4<T> &_min, const Vector4<T> &_max)
+{
+ return Vector4<T>( clamp(a.x, _min.x, _max.x),
+ clamp(a.y, _min.y, _max.y),
+ clamp(a.z, _min.z, _max.z),
+ clamp(a.w, _min.w, _max.w));
+}
+
+
template <class T>
Vector3<T> cross(const Vector3<T> &a, const Vector3<T> &b)
{