diff options
Diffstat (limited to 'src/math/vector.h')
-rw-r--r-- | src/math/vector.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/math/vector.h b/src/math/vector.h index eb54a5b..222d0cd 100644 --- a/src/math/vector.h +++ b/src/math/vector.h @@ -267,4 +267,14 @@ inline float Distance(const Math::Vector &a, const Math::Vector &b) (a.z-b.z)*(a.z-b.z) ); } +//! Clamps the vector \a vec to range between \a min and \a max +inline Vector Clamp(const Vector &vec, const Vector &min, const Vector &max) +{ + Vector clamped; + clamped.x = Min(Max(min.x, vec.x), max.x); + clamped.y = Min(Max(min.y, vec.y), max.y); + clamped.z = Min(Max(min.z, vec.z), max.z); + return clamped; +} + }; // namespace Math |