diff options
Diffstat (limited to 'extern/mantaflow/helper/util')
-rw-r--r-- | extern/mantaflow/helper/util/vectorbase.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/extern/mantaflow/helper/util/vectorbase.h b/extern/mantaflow/helper/util/vectorbase.h index 9ccf445f42c..9b4d9c83f0b 100644 --- a/extern/mantaflow/helper/util/vectorbase.h +++ b/extern/mantaflow/helper/util/vectorbase.h @@ -439,6 +439,36 @@ inline Real normSquare(const int v) return square(v); } +//! Compute sum of all components, allow use of int, Real too +template<class S> inline S sum(const S v) +{ + return v; +} +template<class S> inline S sum(const Vector3D<S> &v) +{ + return v.x + v.y + v.z; +} + +//! Get absolute representation of vector, allow use of int, Real too +inline Real abs(const Real v) +{ + return std::fabs(v); +} +inline int abs(const int v) +{ + return std::abs(v); +} + +template<class S> inline Vector3D<S> abs(const Vector3D<S> &v) +{ + Vector3D<S> cp(v.x, v.y, v.z); + for (int i = 0; i < 3; ++i) { + if (cp[i] < 0) + cp[i] *= (-1.0); + } + return cp; +} + //! Returns a normalized vector template<class S> inline Vector3D<S> getNormalized(const Vector3D<S> &v) { |