diff options
author | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2014-06-29 23:41:31 +0200 |
---|---|---|
committer | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2014-06-29 23:41:31 +0200 |
commit | 428cfb5c21ec5a35252b967eb306d6ba9b8e11b3 (patch) | |
tree | a0b3e28ea6d4b9deb4c063449afe7d5e78f38ff3 /src/Vector3.h | |
parent | An unification of code style (diff) | |
download | cuberite-428cfb5c21ec5a35252b967eb306d6ba9b8e11b3.tar cuberite-428cfb5c21ec5a35252b967eb306d6ba9b8e11b3.tar.gz cuberite-428cfb5c21ec5a35252b967eb306d6ba9b8e11b3.tar.bz2 cuberite-428cfb5c21ec5a35252b967eb306d6ba9b8e11b3.tar.lz cuberite-428cfb5c21ec5a35252b967eb306d6ba9b8e11b3.tar.xz cuberite-428cfb5c21ec5a35252b967eb306d6ba9b8e11b3.tar.zst cuberite-428cfb5c21ec5a35252b967eb306d6ba9b8e11b3.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Vector3.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/Vector3.h b/src/Vector3.h index 5faac1457..762fdfd71 100644 --- a/src/Vector3.h +++ b/src/Vector3.h @@ -274,6 +274,14 @@ public: return (a_X - x) / (a_OtherEnd.x - x); } + /** Clamps each value in the vector to within a specified range */ + inline void Clamp(T a_MinX, T a_MinY, T a_MinZ, T a_MaxX, T a_MaxY, T a_MaxZ) + { + x = Clamp(x, (T)copysign(a_MinX, x), (T)copysign(a_MaxX, x)); + y = Clamp(y, (T)copysign(a_MinY, y), (T)copysign(a_MaxY, y)); + z = Clamp(z, (T)copysign(a_MinZ, z), (T)copysign(a_MaxZ, z)); + } + /** The max difference between two coords for which the coords are assumed equal. */ static const double EPS; @@ -288,6 +296,12 @@ protected: { return (a_Value < 0) ? -a_Value : a_Value; } + + /** Clamp X to the specified range. */ + T Clamp(T a_Value, T a_Min, T a_Max) + { + return (a_Value < a_Min) ? a_Min : ((a_Value > a_Max) ? a_Max : a_Value); + } }; // tolua_end |